@revealui/db 0.2.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/LICENSE +22 -0
- package/README.md +137 -0
- package/dist/audit-store.d.ts +56 -0
- package/dist/audit-store.d.ts.map +1 -0
- package/dist/audit-store.js +120 -0
- package/dist/audit-store.js.map +1 -0
- package/dist/client/index.d.ts +214 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +396 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +109 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +10 -0
- package/dist/client/types.js.map +1 -0
- package/dist/crypto.d.ts +27 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +68 -0
- package/dist/crypto.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/log-transport.d.ts +20 -0
- package/dist/log-transport.d.ts.map +1 -0
- package/dist/log-transport.js +49 -0
- package/dist/log-transport.js.map +1 -0
- package/dist/pool.d.ts +36 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +218 -0
- package/dist/pool.js.map +1 -0
- package/dist/queries/boards.d.ts +138 -0
- package/dist/queries/boards.d.ts.map +1 -0
- package/dist/queries/boards.js +87 -0
- package/dist/queries/boards.js.map +1 -0
- package/dist/queries/code-provenance.d.ts +250 -0
- package/dist/queries/code-provenance.d.ts.map +1 -0
- package/dist/queries/code-provenance.js +130 -0
- package/dist/queries/code-provenance.js.map +1 -0
- package/dist/queries/optimized-queries.d.ts +89 -0
- package/dist/queries/optimized-queries.d.ts.map +1 -0
- package/dist/queries/optimized-queries.js +371 -0
- package/dist/queries/optimized-queries.js.map +1 -0
- package/dist/queries/ticket-comments.d.ts +37 -0
- package/dist/queries/ticket-comments.d.ts.map +1 -0
- package/dist/queries/ticket-comments.js +52 -0
- package/dist/queries/ticket-comments.js.map +1 -0
- package/dist/queries/ticket-labels.d.ts +69 -0
- package/dist/queries/ticket-labels.d.ts.map +1 -0
- package/dist/queries/ticket-labels.js +51 -0
- package/dist/queries/ticket-labels.js.map +1 -0
- package/dist/queries/tickets.d.ts +301 -0
- package/dist/queries/tickets.d.ts.map +1 -0
- package/dist/queries/tickets.js +89 -0
- package/dist/queries/tickets.js.map +1 -0
- package/dist/queries/todos.d.ts +37 -0
- package/dist/queries/todos.d.ts.map +1 -0
- package/dist/queries/todos.js +37 -0
- package/dist/queries/todos.js.map +1 -0
- package/dist/schema/agents.d.ts +1413 -0
- package/dist/schema/agents.d.ts.map +1 -0
- package/dist/schema/agents.js +207 -0
- package/dist/schema/agents.js.map +1 -0
- package/dist/schema/api-keys.d.ts +298 -0
- package/dist/schema/api-keys.d.ts.map +1 -0
- package/dist/schema/api-keys.js +53 -0
- package/dist/schema/api-keys.js.map +1 -0
- package/dist/schema/app-logs.d.ts +168 -0
- package/dist/schema/app-logs.d.ts.map +1 -0
- package/dist/schema/app-logs.js +25 -0
- package/dist/schema/app-logs.js.map +1 -0
- package/dist/schema/audit-log.d.ts +174 -0
- package/dist/schema/audit-log.d.ts.map +1 -0
- package/dist/schema/audit-log.js +37 -0
- package/dist/schema/audit-log.js.map +1 -0
- package/dist/schema/cms.d.ts +1015 -0
- package/dist/schema/cms.d.ts.map +1 -0
- package/dist/schema/cms.js +137 -0
- package/dist/schema/cms.js.map +1 -0
- package/dist/schema/code-provenance.d.ts +488 -0
- package/dist/schema/code-provenance.d.ts.map +1 -0
- package/dist/schema/code-provenance.js +72 -0
- package/dist/schema/code-provenance.js.map +1 -0
- package/dist/schema/collab-edits.d.ts +165 -0
- package/dist/schema/collab-edits.d.ts.map +1 -0
- package/dist/schema/collab-edits.js +21 -0
- package/dist/schema/collab-edits.js.map +1 -0
- package/dist/schema/crdt-operations.d.ts +153 -0
- package/dist/schema/crdt-operations.d.ts.map +1 -0
- package/dist/schema/crdt-operations.js +30 -0
- package/dist/schema/crdt-operations.js.map +1 -0
- package/dist/schema/error-events.d.ts +223 -0
- package/dist/schema/error-events.d.ts.map +1 -0
- package/dist/schema/error-events.js +44 -0
- package/dist/schema/error-events.js.map +1 -0
- package/dist/schema/index.d.ts +130 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +310 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/licenses.d.ts +189 -0
- package/dist/schema/licenses.d.ts.map +1 -0
- package/dist/schema/licenses.js +39 -0
- package/dist/schema/licenses.js.map +1 -0
- package/dist/schema/node-ids.d.ts +122 -0
- package/dist/schema/node-ids.d.ts.map +1 -0
- package/dist/schema/node-ids.js +25 -0
- package/dist/schema/node-ids.js.map +1 -0
- package/dist/schema/pages.d.ts +488 -0
- package/dist/schema/pages.d.ts.map +1 -0
- package/dist/schema/pages.js +70 -0
- package/dist/schema/pages.js.map +1 -0
- package/dist/schema/password-reset-tokens.d.ts +137 -0
- package/dist/schema/password-reset-tokens.d.ts.map +1 -0
- package/dist/schema/password-reset-tokens.js +26 -0
- package/dist/schema/password-reset-tokens.js.map +1 -0
- package/dist/schema/query.d.ts +11 -0
- package/dist/schema/query.d.ts.map +1 -0
- package/dist/schema/query.js +11 -0
- package/dist/schema/query.js.map +1 -0
- package/dist/schema/rate-limits.d.ts +212 -0
- package/dist/schema/rate-limits.d.ts.map +1 -0
- package/dist/schema/rate-limits.js +38 -0
- package/dist/schema/rate-limits.js.map +1 -0
- package/dist/schema/rest.d.ts +31 -0
- package/dist/schema/rest.d.ts.map +1 -0
- package/dist/schema/rest.js +37 -0
- package/dist/schema/rest.js.map +1 -0
- package/dist/schema/sites.d.ts +365 -0
- package/dist/schema/sites.d.ts.map +1 -0
- package/dist/schema/sites.js +62 -0
- package/dist/schema/sites.js.map +1 -0
- package/dist/schema/tickets.d.ts +1118 -0
- package/dist/schema/tickets.d.ts.map +1 -0
- package/dist/schema/tickets.js +150 -0
- package/dist/schema/tickets.js.map +1 -0
- package/dist/schema/todos.d.ts +98 -0
- package/dist/schema/todos.d.ts.map +1 -0
- package/dist/schema/todos.js +12 -0
- package/dist/schema/todos.js.map +1 -0
- package/dist/schema/users.d.ts +503 -0
- package/dist/schema/users.d.ts.map +1 -0
- package/dist/schema/users.js +75 -0
- package/dist/schema/users.js.map +1 -0
- package/dist/schema/vector.d.ts +9 -0
- package/dist/schema/vector.d.ts.map +1 -0
- package/dist/schema/vector.js +9 -0
- package/dist/schema/vector.js.map +1 -0
- package/dist/schema/waitlist.d.ts +151 -0
- package/dist/schema/waitlist.d.ts.map +1 -0
- package/dist/schema/waitlist.js +17 -0
- package/dist/schema/waitlist.js.map +1 -0
- package/dist/schema/yjs-documents.d.ts +116 -0
- package/dist/schema/yjs-documents.d.ts.map +1 -0
- package/dist/schema/yjs-documents.js +15 -0
- package/dist/schema/yjs-documents.js.map +1 -0
- package/dist/types/database.d.ts +740 -0
- package/dist/types/database.d.ts.map +1 -0
- package/dist/types/database.js +151 -0
- package/dist/types/database.js.map +1 -0
- package/dist/types/discover.d.ts +83 -0
- package/dist/types/discover.d.ts.map +1 -0
- package/dist/types/discover.js +271 -0
- package/dist/types/discover.js.map +1 -0
- package/dist/types/extract-relationships.d.ts +115 -0
- package/dist/types/extract-relationships.d.ts.map +1 -0
- package/dist/types/extract-relationships.js +455 -0
- package/dist/types/extract-relationships.js.map +1 -0
- package/dist/types/generate-contracts.d.ts +19 -0
- package/dist/types/generate-contracts.d.ts.map +1 -0
- package/dist/types/generate-contracts.js +128 -0
- package/dist/types/generate-contracts.js.map +1 -0
- package/dist/types/generate-zod-schemas.d.ts +20 -0
- package/dist/types/generate-zod-schemas.d.ts.map +1 -0
- package/dist/types/generate-zod-schemas.js +128 -0
- package/dist/types/generate-zod-schemas.js.map +1 -0
- package/dist/types/generate.d.ts +17 -0
- package/dist/types/generate.d.ts.map +1 -0
- package/dist/types/generate.js +298 -0
- package/dist/types/generate.js.map +1 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/introspect.d.ts +75 -0
- package/dist/types/introspect.d.ts.map +1 -0
- package/dist/types/introspect.js +187 -0
- package/dist/types/introspect.js.map +1 -0
- package/dist/types/stripe-schema.d.ts +893 -0
- package/dist/types/stripe-schema.d.ts.map +1 -0
- package/dist/types/stripe-schema.js +112 -0
- package/dist/types/stripe-schema.js.map +1 -0
- package/package.json +154 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 RevealUI Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# @revealui/db
|
|
2
|
+
|
|
3
|
+
**Status:** 🟡 Active Development | ⚠️ NOT Production Ready
|
|
4
|
+
|
|
5
|
+
See [Project Status](../../docs/PROJECT_STATUS.md) for framework readiness.
|
|
6
|
+
|
|
7
|
+
Database schemas and Drizzle ORM integration for RevealUI.
|
|
8
|
+
|
|
9
|
+
> **Test Coverage:** ~60% (best coverage in project, but still needs improvement)
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Drizzle ORM**: Type-safe database queries with Drizzle
|
|
14
|
+
- **Schema Management**: Database schema definitions for all RevealUI tables
|
|
15
|
+
- **Multiple Providers**: Works with Neon, Supabase, and Vercel Postgres
|
|
16
|
+
- **Type Generation**: Auto-generate TypeScript types from database schema
|
|
17
|
+
- **Migrations**: Database migration management with Drizzle Kit
|
|
18
|
+
- **Type-safe**: Full TypeScript support with inferred types
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add @revealui/db
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Import Database Client
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { createClient } from '@revealui/db/client'
|
|
32
|
+
|
|
33
|
+
const db = createClient({
|
|
34
|
+
connectionString: process.env.POSTGRES_URL!
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Import Schemas
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
// Import all schemas
|
|
42
|
+
import * as schema from '@revealui/db/schema'
|
|
43
|
+
|
|
44
|
+
// Import specific schemas
|
|
45
|
+
import { users } from '@revealui/db/schema/users'
|
|
46
|
+
import { posts } from '@revealui/db/schema/cms'
|
|
47
|
+
import { agentContexts } from '@revealui/db/schema/agents'
|
|
48
|
+
import { vectorMemory } from '@revealui/db/schema/vector'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Query Database
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { createClient } from '@revealui/db/client'
|
|
55
|
+
import { users } from '@revealui/db/schema/users'
|
|
56
|
+
import { eq } from 'drizzle-orm'
|
|
57
|
+
|
|
58
|
+
const db = createClient({ connectionString: process.env.POSTGRES_URL! })
|
|
59
|
+
|
|
60
|
+
// Query users
|
|
61
|
+
const allUsers = await db.select().from(users)
|
|
62
|
+
|
|
63
|
+
// Query with filter
|
|
64
|
+
const user = await db.select().from(users).where(eq(users.email, 'user@example.com'))
|
|
65
|
+
|
|
66
|
+
// Insert user
|
|
67
|
+
await db.insert(users).values({
|
|
68
|
+
email: 'newuser@example.com',
|
|
69
|
+
name: 'New User'
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Available Exports
|
|
74
|
+
|
|
75
|
+
- `@revealui/db` - Main export with database client
|
|
76
|
+
- `@revealui/db/client` - Database client factory
|
|
77
|
+
- `@revealui/db/schema` - All database schemas
|
|
78
|
+
- `@revealui/db/schema/agents` - Agent-related tables
|
|
79
|
+
- `@revealui/db/schema/cms` - CMS tables (posts, pages, media)
|
|
80
|
+
- `@revealui/db/schema/users` - User and authentication tables
|
|
81
|
+
- `@revealui/db/schema/vector` - Vector memory tables
|
|
82
|
+
- `@revealui/db/schema/crdt-operations` - CRDT operation log
|
|
83
|
+
- `@revealui/db/schema/node-ids` - Node ID mapping
|
|
84
|
+
- `@revealui/db/schema/rate-limits` - Rate limiting tables
|
|
85
|
+
- `@revealui/db/schema/sites` - Site configuration tables
|
|
86
|
+
- `@revealui/db/types` - TypeScript types for database entities
|
|
87
|
+
|
|
88
|
+
## Database Management
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Generate types from schema
|
|
92
|
+
pnpm --filter @revealui/db generate:types
|
|
93
|
+
|
|
94
|
+
# Generate migration files
|
|
95
|
+
pnpm --filter @revealui/db db:generate
|
|
96
|
+
|
|
97
|
+
# Run migrations
|
|
98
|
+
pnpm --filter @revealui/db db:migrate
|
|
99
|
+
|
|
100
|
+
# Push schema changes (development only)
|
|
101
|
+
pnpm --filter @revealui/db db:push
|
|
102
|
+
|
|
103
|
+
# Open Drizzle Studio (database GUI)
|
|
104
|
+
pnpm --filter @revealui/db db:studio
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Type Safety
|
|
108
|
+
|
|
109
|
+
All database operations are fully type-safe:
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { createClient } from '@revealui/db/client'
|
|
113
|
+
import { users } from '@revealui/db/schema/users'
|
|
114
|
+
|
|
115
|
+
const db = createClient({ connectionString: process.env.POSTGRES_URL! })
|
|
116
|
+
|
|
117
|
+
// TypeScript knows the shape of user rows
|
|
118
|
+
const allUsers = await db.select().from(users)
|
|
119
|
+
// allUsers: { id: string, email: string, name: string | null, ... }[]
|
|
120
|
+
|
|
121
|
+
// Insert is type-checked
|
|
122
|
+
await db.insert(users).values({
|
|
123
|
+
email: 'test@example.com',
|
|
124
|
+
name: 'Test User'
|
|
125
|
+
// TypeScript error if you add invalid fields
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Related Documentation
|
|
130
|
+
|
|
131
|
+
- [Database Guide](../../docs/DATABASE.md) - Complete database setup and configuration
|
|
132
|
+
- [Database Management](../../docs/DATABASE_MANAGEMENT.md) - Operations and maintenance
|
|
133
|
+
- [Drizzle ORM Docs](https://orm.drizzle.team/) - Official Drizzle documentation
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle Audit Store
|
|
3
|
+
*
|
|
4
|
+
* Persistent implementation of the AuditStore interface from @revealui/ai.
|
|
5
|
+
* Stores audit entries in the audit_log PostgreSQL table via Drizzle ORM.
|
|
6
|
+
* Append-only — no update or delete operations.
|
|
7
|
+
*
|
|
8
|
+
* Types are defined locally to avoid a circular dependency on @revealui/ai.
|
|
9
|
+
* They mirror AuditEntry and AuditFilter from @revealui/ai/audit/types.
|
|
10
|
+
*/
|
|
11
|
+
import type { Database } from './client/index.js';
|
|
12
|
+
/** Audit entry stored in the database */
|
|
13
|
+
export interface AuditEntry {
|
|
14
|
+
id: string;
|
|
15
|
+
timestamp: Date;
|
|
16
|
+
eventType: string;
|
|
17
|
+
severity: string;
|
|
18
|
+
agentId: string;
|
|
19
|
+
taskId?: string;
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
payload: Record<string, unknown>;
|
|
22
|
+
policyViolations: string[];
|
|
23
|
+
}
|
|
24
|
+
/** Filters for querying audit entries */
|
|
25
|
+
export interface AuditFilter {
|
|
26
|
+
agentId?: string;
|
|
27
|
+
taskId?: string;
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
eventTypes?: string[];
|
|
30
|
+
severity?: string[];
|
|
31
|
+
startTime?: Date;
|
|
32
|
+
endTime?: Date;
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* PostgreSQL-backed audit store using Drizzle ORM.
|
|
38
|
+
* Implements the AuditStore interface for production use.
|
|
39
|
+
*
|
|
40
|
+
* All writes are append-only. The table has no UPDATE or DELETE operations.
|
|
41
|
+
*/
|
|
42
|
+
export declare class DrizzleAuditStore {
|
|
43
|
+
private readonly db;
|
|
44
|
+
constructor(db: Database);
|
|
45
|
+
/** Append a single entry to the audit log */
|
|
46
|
+
append(entry: AuditEntry): Promise<void>;
|
|
47
|
+
/** Append multiple entries atomically in a single INSERT */
|
|
48
|
+
appendBatch(entries: AuditEntry[]): Promise<void>;
|
|
49
|
+
/** Query entries with filters (human-side only) */
|
|
50
|
+
query(filter: AuditFilter): Promise<AuditEntry[]>;
|
|
51
|
+
/** Get total entry count (optionally filtered by agent) */
|
|
52
|
+
count(agentId?: string): Promise<number>;
|
|
53
|
+
/** Get entries since a given timestamp */
|
|
54
|
+
since(timestamp: Date, limit?: number): Promise<AuditEntry[]>;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=audit-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-store.d.ts","sourceRoot":"","sources":["../src/audit-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAMjD,yCAAyC;AACzC,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,IAAI,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,gBAAgB,EAAE,MAAM,EAAE,CAAA;CAC3B;AAED,yCAAyC;AACzC,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAID;;;;;GAKG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,QAAQ;IAEzC,6CAA6C;IACvC,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAc9C,4DAA4D;IACtD,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBvD,mDAAmD;IAC7C,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAoCvD,2DAA2D;IACrD,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ9C,0CAA0C;IACpC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,SAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CAUlE"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drizzle Audit Store
|
|
3
|
+
*
|
|
4
|
+
* Persistent implementation of the AuditStore interface from @revealui/ai.
|
|
5
|
+
* Stores audit entries in the audit_log PostgreSQL table via Drizzle ORM.
|
|
6
|
+
* Append-only — no update or delete operations.
|
|
7
|
+
*
|
|
8
|
+
* Types are defined locally to avoid a circular dependency on @revealui/ai.
|
|
9
|
+
* They mirror AuditEntry and AuditFilter from @revealui/ai/audit/types.
|
|
10
|
+
*/
|
|
11
|
+
import { and, count, desc, eq, gte, inArray, lte } from 'drizzle-orm';
|
|
12
|
+
import { auditLog } from './schema/audit-log.js';
|
|
13
|
+
// ─── Drizzle Audit Store ────────────────────────────────────────────────────
|
|
14
|
+
/**
|
|
15
|
+
* PostgreSQL-backed audit store using Drizzle ORM.
|
|
16
|
+
* Implements the AuditStore interface for production use.
|
|
17
|
+
*
|
|
18
|
+
* All writes are append-only. The table has no UPDATE or DELETE operations.
|
|
19
|
+
*/
|
|
20
|
+
export class DrizzleAuditStore {
|
|
21
|
+
db;
|
|
22
|
+
constructor(db) {
|
|
23
|
+
this.db = db;
|
|
24
|
+
}
|
|
25
|
+
/** Append a single entry to the audit log */
|
|
26
|
+
async append(entry) {
|
|
27
|
+
await this.db.insert(auditLog).values({
|
|
28
|
+
id: entry.id,
|
|
29
|
+
timestamp: entry.timestamp,
|
|
30
|
+
eventType: entry.eventType,
|
|
31
|
+
severity: entry.severity,
|
|
32
|
+
agentId: entry.agentId,
|
|
33
|
+
taskId: entry.taskId ?? null,
|
|
34
|
+
sessionId: entry.sessionId ?? null,
|
|
35
|
+
payload: entry.payload,
|
|
36
|
+
policyViolations: entry.policyViolations,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Append multiple entries atomically in a single INSERT */
|
|
40
|
+
async appendBatch(entries) {
|
|
41
|
+
if (entries.length === 0)
|
|
42
|
+
return;
|
|
43
|
+
await this.db.insert(auditLog).values(entries.map((entry) => ({
|
|
44
|
+
id: entry.id,
|
|
45
|
+
timestamp: entry.timestamp,
|
|
46
|
+
eventType: entry.eventType,
|
|
47
|
+
severity: entry.severity,
|
|
48
|
+
agentId: entry.agentId,
|
|
49
|
+
taskId: entry.taskId ?? null,
|
|
50
|
+
sessionId: entry.sessionId ?? null,
|
|
51
|
+
payload: entry.payload,
|
|
52
|
+
policyViolations: entry.policyViolations,
|
|
53
|
+
})));
|
|
54
|
+
}
|
|
55
|
+
/** Query entries with filters (human-side only) */
|
|
56
|
+
async query(filter) {
|
|
57
|
+
const conditions = [];
|
|
58
|
+
if (filter.agentId) {
|
|
59
|
+
conditions.push(eq(auditLog.agentId, filter.agentId));
|
|
60
|
+
}
|
|
61
|
+
if (filter.taskId) {
|
|
62
|
+
conditions.push(eq(auditLog.taskId, filter.taskId));
|
|
63
|
+
}
|
|
64
|
+
if (filter.sessionId) {
|
|
65
|
+
conditions.push(eq(auditLog.sessionId, filter.sessionId));
|
|
66
|
+
}
|
|
67
|
+
if (filter.eventTypes && filter.eventTypes.length > 0) {
|
|
68
|
+
conditions.push(inArray(auditLog.eventType, filter.eventTypes));
|
|
69
|
+
}
|
|
70
|
+
if (filter.severity && filter.severity.length > 0) {
|
|
71
|
+
conditions.push(inArray(auditLog.severity, filter.severity));
|
|
72
|
+
}
|
|
73
|
+
if (filter.startTime) {
|
|
74
|
+
conditions.push(gte(auditLog.timestamp, filter.startTime));
|
|
75
|
+
}
|
|
76
|
+
if (filter.endTime) {
|
|
77
|
+
conditions.push(lte(auditLog.timestamp, filter.endTime));
|
|
78
|
+
}
|
|
79
|
+
const rows = await this.db
|
|
80
|
+
.select()
|
|
81
|
+
.from(auditLog)
|
|
82
|
+
.where(conditions.length > 0 ? and(...conditions) : undefined)
|
|
83
|
+
.orderBy(desc(auditLog.timestamp))
|
|
84
|
+
.limit(filter.limit ?? 1000)
|
|
85
|
+
.offset(filter.offset ?? 0);
|
|
86
|
+
return rows.map(rowToEntry);
|
|
87
|
+
}
|
|
88
|
+
/** Get total entry count (optionally filtered by agent) */
|
|
89
|
+
async count(agentId) {
|
|
90
|
+
const condition = agentId ? eq(auditLog.agentId, agentId) : undefined;
|
|
91
|
+
const result = await this.db.select({ value: count() }).from(auditLog).where(condition);
|
|
92
|
+
return result[0]?.value ?? 0;
|
|
93
|
+
}
|
|
94
|
+
/** Get entries since a given timestamp */
|
|
95
|
+
async since(timestamp, limit = 1000) {
|
|
96
|
+
const rows = await this.db
|
|
97
|
+
.select()
|
|
98
|
+
.from(auditLog)
|
|
99
|
+
.where(gte(auditLog.timestamp, timestamp))
|
|
100
|
+
.orderBy(desc(auditLog.timestamp))
|
|
101
|
+
.limit(limit);
|
|
102
|
+
return rows.map(rowToEntry);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// ─── Row Mapping ────────────────────────────────────────────────────────────
|
|
106
|
+
/** Convert a database row to an AuditEntry */
|
|
107
|
+
function rowToEntry(row) {
|
|
108
|
+
return {
|
|
109
|
+
id: row.id,
|
|
110
|
+
timestamp: row.timestamp,
|
|
111
|
+
eventType: row.eventType,
|
|
112
|
+
severity: row.severity,
|
|
113
|
+
agentId: row.agentId,
|
|
114
|
+
taskId: row.taskId ?? undefined,
|
|
115
|
+
sessionId: row.sessionId ?? undefined,
|
|
116
|
+
payload: (row.payload ?? {}),
|
|
117
|
+
policyViolations: (row.policyViolations ?? []),
|
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AAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QAEvF,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAA;IAC9B,CAAC;IAED,0CAA0C;IAC1C,KAAK,CAAC,KAAK,CAAC,SAAe,EAAE,KAAK,GAAG,IAAI;QACvC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,EAAE;aACvB,MAAM,EAAE;aACR,IAAI,CAAC,QAAQ,CAAC;aACd,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;aACzC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;aACjC,KAAK,CAAC,KAAK,CAAC,CAAA;QAEf,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAC7B,CAAC;CACF;AAED,+EAA+E;AAE/E,8CAA8C;AAC9C,SAAS,UAAU,CAAC,GAAiC;IACnD,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAoC;QACnD,QAAQ,EAAE,GAAG,CAAC,QAAkC;QAChD,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,SAAS;QAC/B,SAAS,EAAE,GAAG,CAAC,SAAS,IAAI,SAAS;QACrC,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAA4B;QACvD,gBAAgB,EAAE,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAa;KAC3D,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @revealui/db - Database Client
|
|
3
|
+
*
|
|
4
|
+
* Provides a configured Drizzle ORM client for PostgreSQL databases.
|
|
5
|
+
* Supports dual database architecture:
|
|
6
|
+
* - REST Database (NeonDB): Uses @neondatabase/serverless with drizzle-orm/neon-http
|
|
7
|
+
* - Vector Database (Supabase): Uses postgres-js with drizzle-orm/postgres-js
|
|
8
|
+
*
|
|
9
|
+
* This dual-driver approach avoids the Neon driver's compatibility issue with Supabase,
|
|
10
|
+
* where it incorrectly transforms Supabase hostnames (aws-0-*.pooler.supabase.com → api.pooler.supabase.com).
|
|
11
|
+
*
|
|
12
|
+
* Connection String Format:
|
|
13
|
+
* - NeonDB: postgresql://...@neon.tech/...
|
|
14
|
+
* - Supabase: postgresql://...@*.supabase.co:6543/postgres (transaction pooler)
|
|
15
|
+
* - Supabase: postgresql://...@*.supabase.co:5432/postgres (direct/session pooler)
|
|
16
|
+
*
|
|
17
|
+
* Reference:
|
|
18
|
+
* - Neon: https://orm.drizzle.team/docs/connect-neon
|
|
19
|
+
* - Supabase: https://orm.drizzle.team/docs/tutorials/drizzle-with-supabase
|
|
20
|
+
*/
|
|
21
|
+
import { type NeonHttpDatabase } from 'drizzle-orm/neon-http';
|
|
22
|
+
import { type NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
23
|
+
import * as schema from '../schema/index.js';
|
|
24
|
+
import * as restSchema from '../schema/rest.js';
|
|
25
|
+
import * as vectorSchema from '../schema/vector.js';
|
|
26
|
+
export interface PoolMetrics {
|
|
27
|
+
/** Total connections in pool */
|
|
28
|
+
totalCount: number;
|
|
29
|
+
/** Idle connections */
|
|
30
|
+
idleCount: number;
|
|
31
|
+
/** Waiting requests */
|
|
32
|
+
waitingCount: number;
|
|
33
|
+
/** Pool name/identifier */
|
|
34
|
+
name: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Database type selector for dual database architecture
|
|
38
|
+
* - 'rest': NeonDB for transactional REST API operations
|
|
39
|
+
* - 'vector': Supabase for vector search operations
|
|
40
|
+
*/
|
|
41
|
+
export type DatabaseType = 'rest' | 'vector';
|
|
42
|
+
/**
|
|
43
|
+
* Database client type (Drizzle ORM client)
|
|
44
|
+
*
|
|
45
|
+
* This is the actual database client returned by createClient/getClient.
|
|
46
|
+
* For the centralized Database type matching Supabase structure, see @revealui/db/types
|
|
47
|
+
*
|
|
48
|
+
* Note: This is a union type to support both Neon (REST) and Postgres (Vector) drivers.
|
|
49
|
+
* The actual type will be NeonHttpDatabase for REST and PgDatabase for Vector.
|
|
50
|
+
*/
|
|
51
|
+
export type Database = NeonHttpDatabase<typeof schema> | NodePgDatabase<typeof schema>;
|
|
52
|
+
export interface DatabaseConfig {
|
|
53
|
+
connectionString: string;
|
|
54
|
+
logger?: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates a Drizzle database client, automatically selecting the appropriate driver:
|
|
58
|
+
* - Supabase/localhost connections: Uses node-postgres with drizzle-orm/node-postgres
|
|
59
|
+
* - NeonDB connections: Uses @neondatabase/serverless with drizzle-orm/neon-http
|
|
60
|
+
*
|
|
61
|
+
* This dual-driver approach fixes the Neon driver's compatibility issue with Supabase,
|
|
62
|
+
* where it incorrectly transforms Supabase hostnames. It also enables local testing
|
|
63
|
+
* with localhost PostgreSQL databases.
|
|
64
|
+
*
|
|
65
|
+
* @param config - Database configuration
|
|
66
|
+
* @param dbSchema - Optional schema to use (defaults to full schema for backward compatibility)
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import { createClient } from '@revealui/db/client'
|
|
71
|
+
*
|
|
72
|
+
* // Automatically uses node-postgres for Supabase
|
|
73
|
+
* const supabaseDb = createClient({
|
|
74
|
+
* connectionString: process.env.DATABASE_URL!, // Supabase URL
|
|
75
|
+
* })
|
|
76
|
+
*
|
|
77
|
+
* // Automatically uses node-postgres for localhost (testing)
|
|
78
|
+
* const testDb = createClient({
|
|
79
|
+
* connectionString: 'postgresql://test:test@localhost:5432/test',
|
|
80
|
+
* })
|
|
81
|
+
*
|
|
82
|
+
* // Automatically uses Neon driver for NeonDB
|
|
83
|
+
* const neonDb = createClient({
|
|
84
|
+
* connectionString: process.env.POSTGRES_URL!, // NeonDB URL
|
|
85
|
+
* })
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function createClient(config: DatabaseConfig, dbSchema?: typeof restSchema | typeof vectorSchema | typeof schema): Database;
|
|
89
|
+
/**
|
|
90
|
+
* Gets or creates a global database client.
|
|
91
|
+
* Supports dual database architecture with separate clients for REST and Vector operations.
|
|
92
|
+
* Uses config module if available, otherwise falls back to process.env for backward compatibility.
|
|
93
|
+
*
|
|
94
|
+
* @param typeOrConnectionString - Database type ('rest' | 'vector') or connection string (legacy API)
|
|
95
|
+
* @returns Database client instance
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import { getClient } from '@revealui/db/client'
|
|
100
|
+
*
|
|
101
|
+
* // New API: Specify database type
|
|
102
|
+
* const restDb = getClient('rest')
|
|
103
|
+
* const vectorDb = getClient('vector')
|
|
104
|
+
*
|
|
105
|
+
* // Legacy API: Still supported for backward compatibility
|
|
106
|
+
* const db = getClient() // defaults to 'rest'
|
|
107
|
+
* const db2 = getClient('postgresql://...') // uses provided connection string as 'rest'
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function getClient(typeOrConnectionString?: DatabaseType | string): Database;
|
|
111
|
+
/**
|
|
112
|
+
* Gets or creates the REST database client (NeonDB).
|
|
113
|
+
* Convenience function for accessing the REST database.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* import { getRestClient } from '@revealui/db/client'
|
|
118
|
+
*
|
|
119
|
+
* const db = getRestClient()
|
|
120
|
+
* const users = await db.query.users.findMany()
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function getRestClient(): Database;
|
|
124
|
+
/**
|
|
125
|
+
* Gets or creates the Vector database client (Supabase).
|
|
126
|
+
* Convenience function for accessing the vector database.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* import { getVectorClient } from '@revealui/db/client'
|
|
131
|
+
*
|
|
132
|
+
* const db = getVectorClient()
|
|
133
|
+
* const memories = await db.query.agentMemories.findMany()
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export declare function getVectorClient(): Database;
|
|
137
|
+
/**
|
|
138
|
+
* Resets the global clients (useful for testing).
|
|
139
|
+
* Clears both REST and Vector client instances.
|
|
140
|
+
*/
|
|
141
|
+
export declare function resetClient(): void;
|
|
142
|
+
/**
|
|
143
|
+
* Gets metrics for all active database connection pools.
|
|
144
|
+
*
|
|
145
|
+
* @returns Array of pool metrics
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* import { getPoolMetrics } from '@revealui/db/client'
|
|
150
|
+
*
|
|
151
|
+
* const metrics = getPoolMetrics()
|
|
152
|
+
* for (const pool of metrics) {
|
|
153
|
+
* // Log pool statistics
|
|
154
|
+
* logger.info(`${pool.name}: ${pool.totalCount} total, ${pool.idleCount} idle`)
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function getPoolMetrics(): PoolMetrics[];
|
|
159
|
+
/**
|
|
160
|
+
* Closes all active database connection pools.
|
|
161
|
+
* This should be called during graceful shutdown.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import { closeAllPools } from '@revealui/db/client'
|
|
166
|
+
*
|
|
167
|
+
* process.on('SIGTERM', async () => {
|
|
168
|
+
* await closeAllPools()
|
|
169
|
+
* process.exit(0)
|
|
170
|
+
* })
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export declare function closeAllPools(): Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Execute a database transaction with automatic BEGIN/COMMIT/ROLLBACK.
|
|
176
|
+
*
|
|
177
|
+
* ⚠️ IMPORTANT: Transaction support depends on the database driver:
|
|
178
|
+
* - ✅ Supabase/localhost (pg Pool): Full transaction support
|
|
179
|
+
* - ❌ NeonDB (HTTP driver): Transactions NOT supported
|
|
180
|
+
*
|
|
181
|
+
* The Neon HTTP driver (@neondatabase/serverless with neon-http) does not support
|
|
182
|
+
* transactions because it uses stateless HTTP requests. Each query is independent.
|
|
183
|
+
*
|
|
184
|
+
* For transaction support, use:
|
|
185
|
+
* 1. Supabase with connection pooling (recommended for production)
|
|
186
|
+
* 2. Localhost PostgreSQL (for development/testing)
|
|
187
|
+
* 3. Neon with WebSocket driver (coming in future versions)
|
|
188
|
+
*
|
|
189
|
+
* @param db - Database client (must be created with pg Pool driver)
|
|
190
|
+
* @param fn - Transaction callback that receives a transaction context
|
|
191
|
+
* @returns Result from the transaction callback
|
|
192
|
+
* @throws {Error} If using Neon HTTP driver (no transaction support)
|
|
193
|
+
* @throws {Error} If transaction fails (automatic ROLLBACK is performed)
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* // ✅ Works with Supabase/localhost (pg Pool driver)
|
|
198
|
+
* const supabaseDb = getClient('vector') // Uses pg Pool
|
|
199
|
+
* const result = await withTransaction(supabaseDb, async (tx) => {
|
|
200
|
+
* const site = await tx.insert(sites).values({ ... }).returning()
|
|
201
|
+
* await tx.insert(pages).values({ siteId: site[0].id, ... })
|
|
202
|
+
* return site[0]
|
|
203
|
+
* })
|
|
204
|
+
*
|
|
205
|
+
* // ❌ Throws error with NeonDB (HTTP driver)
|
|
206
|
+
* const neonDb = getClient('rest') // Uses Neon HTTP
|
|
207
|
+
* await withTransaction(neonDb, async (tx) => { ... }) // Error!
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export declare function withTransaction<T>(db: Database, fn: (tx: Database) => Promise<T>): Promise<T>;
|
|
211
|
+
export { schema };
|
|
212
|
+
export type { AgentAction, AgentContext, AgentMemory, Conversation, CRDTOperation, GlobalFooter, GlobalHeader, GlobalSettings, Media, NewAgentAction, NewAgentContext, NewAgentMemory, NewConversation, NewCRDTOperation, NewGlobalFooter, NewGlobalHeader, NewGlobalSettings, NewMedia, NewNodeIdMapping, NewPage, NewPageRevision, NewPost, NewSession, NewSite, NewSiteCollaborator, NewUser, NodeIdMapping, Page, PageRevision, Post, Session, Site, SiteCollaborator, User, } from '../schema/index.js';
|
|
213
|
+
export type { Database as DatabaseSchema, DatabaseClient, QueryResult, QueryResults, RelatedTables, TableRelationships, Transaction, } from './types.js';
|
|
214
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAQH,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACrF,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAErF,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAA;AAoBnD,MAAM,WAAW,WAAW;IAC1B,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAA;IAClB,uBAAuB;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,uBAAuB;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAA;CACb;AAMD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE5C;;;;;;;;GAQG;AACH,MAAM,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,MAAM,CAAC,GAAG,cAAc,CAAC,OAAO,MAAM,CAAC,CAAA;AAEtF,MAAM,WAAW,cAAc;IAC7B,gBAAgB,EAAE,MAAM,CAAA;IACxB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AA0CD;;;;;;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