@agentuity/db 1.0.54
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/AGENTS.md +37 -0
- package/README.md +56 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
- package/src/index.ts +140 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Agent Guidelines for @agentuity/db
|
|
2
|
+
|
|
3
|
+
## Package Overview
|
|
4
|
+
|
|
5
|
+
Standalone package for the Agentuity Database service. Provides a simple, ergonomic client for querying databases and viewing query logs.
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
- **Build**: `bun run build`
|
|
10
|
+
- **Typecheck**: `bun run typecheck`
|
|
11
|
+
- **Clean**: `rm -rf dist`
|
|
12
|
+
|
|
13
|
+
## Architecture
|
|
14
|
+
|
|
15
|
+
- **Runtime**: Node.js and Bun compatible
|
|
16
|
+
- **Exports**: DBClient and all types from @agentuity/core/db
|
|
17
|
+
- **Dependencies**: @agentuity/core, @agentuity/server, zod
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { DBClient } from '@agentuity/db';
|
|
23
|
+
|
|
24
|
+
const client = new DBClient();
|
|
25
|
+
|
|
26
|
+
// Query the database
|
|
27
|
+
const result = await client.query('SELECT * FROM users LIMIT 10');
|
|
28
|
+
console.log(result.rows);
|
|
29
|
+
|
|
30
|
+
// Get table schemas
|
|
31
|
+
const tables = await client.tables();
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Publishing
|
|
35
|
+
|
|
36
|
+
1. Run `bun run build`
|
|
37
|
+
2. Must publish **after** @agentuity/core
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @agentuity/db
|
|
2
|
+
|
|
3
|
+
A standalone package for the Agentuity Database service.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @agentuity/db
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { DBClient } from '@agentuity/db';
|
|
15
|
+
|
|
16
|
+
const client = new DBClient();
|
|
17
|
+
|
|
18
|
+
// Query the database
|
|
19
|
+
const result = await client.query('SELECT * FROM users LIMIT 10');
|
|
20
|
+
for (const row of result.rows) {
|
|
21
|
+
console.log(row);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Get table schemas
|
|
25
|
+
const tables = await client.tables();
|
|
26
|
+
for (const table of tables) {
|
|
27
|
+
console.log(`${table.name}: ${table.columns.length} columns`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// View query logs
|
|
31
|
+
const logs = await client.logs({ limit: 100 });
|
|
32
|
+
for (const log of logs.logs) {
|
|
33
|
+
console.log(`${log.query}: ${log.duration}ms`);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const client = new DBClient({
|
|
41
|
+
apiKey: 'your-api-key',
|
|
42
|
+
url: 'https://api.agentuity.com',
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Environment Variables
|
|
47
|
+
|
|
48
|
+
| Variable | Description | Default |
|
|
49
|
+
|----------|-------------|---------|
|
|
50
|
+
| `AGENTUITY_SDK_KEY` | API key for authentication | Required |
|
|
51
|
+
| `AGENTUITY_REGION` | Region for API endpoints | `usc` |
|
|
52
|
+
| `AGENTUITY_DB_URL` | Override DB API URL | Auto-detected |
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { dbQuery, type QueryColumn, QueryColumnSchema, type QueryResult, QueryResultSchema, QueryResponseSchema, } from '@agentuity/core/db';
|
|
2
|
+
export { dbTables, generateCreateTableSQL, type TableColumn, TableColumnSchema, type TableSchema, TableSchemaSchema, TablesResponseSchema, } from '@agentuity/core/db';
|
|
3
|
+
export { dbLogs, type DbQueryLog, DbQueryLogSchema, type DbQueryLogs, DbLogsAPIResponseSchema, DbLogsRequestSchema, DbLogsResponseSchema, } from '@agentuity/core/db';
|
|
4
|
+
export { dbLogStats, type DbLogStatsResponse, type DbLogStatsSummary, type DbLogStatsCommandBreakdown, type DbLogStatsQueryPattern, type DbLogStatsTimeSeriesPoint, DbLogStatsAPIResponseSchema, DbLogStatsCommandBreakdownSchema, DbLogStatsQueryPatternSchema, DbLogStatsRequestSchema, DbLogStatsResponseSchema, DbLogStatsSummarySchema, DbLogStatsTimeSeriesPointSchema, } from '@agentuity/core/db';
|
|
5
|
+
export { DbInvalidArgumentError, DbResponseError } from '@agentuity/core/db';
|
|
6
|
+
import { type Logger } from '@agentuity/core';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { type QueryResult, type TableSchema, type DbQueryLogs, type DbLogStatsResponse } from '@agentuity/core/db';
|
|
9
|
+
export declare const DBClientOptionsSchema: z.ZodObject<{
|
|
10
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
11
|
+
url: z.ZodOptional<z.ZodString>;
|
|
12
|
+
database: z.ZodString;
|
|
13
|
+
orgId: z.ZodString;
|
|
14
|
+
region: z.ZodOptional<z.ZodString>;
|
|
15
|
+
logger: z.ZodOptional<z.ZodCustom<Logger, Logger>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export type DBClientOptions = z.infer<typeof DBClientOptionsSchema>;
|
|
18
|
+
export declare class DBClient {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(options: DBClientOptions);
|
|
21
|
+
query(sql: string): Promise<QueryResult>;
|
|
22
|
+
tables(): Promise<TableSchema[]>;
|
|
23
|
+
logs(params?: {
|
|
24
|
+
startDate?: string;
|
|
25
|
+
endDate?: string;
|
|
26
|
+
limit?: number;
|
|
27
|
+
}): Promise<DbQueryLogs>;
|
|
28
|
+
stats(params: {
|
|
29
|
+
startDate: string;
|
|
30
|
+
endDate: string;
|
|
31
|
+
}): Promise<DbLogStatsResponse>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EACP,KAAK,WAAW,EAChB,iBAAiB,EACjB,KAAK,WAAW,EAChB,iBAAiB,EACjB,mBAAmB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,QAAQ,EACR,sBAAsB,EACtB,KAAK,WAAW,EAChB,iBAAiB,EACjB,KAAK,WAAW,EAChB,iBAAiB,EACjB,oBAAoB,GACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,MAAM,EACN,KAAK,UAAU,EACf,gBAAgB,EAChB,KAAK,WAAW,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,2BAA2B,EAC3B,gCAAgC,EAChC,4BAA4B,EAC5B,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,+BAA+B,GAC/B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EAAuB,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAKN,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,qBAAqB;;;;;;;iBAOhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,qBAAa,QAAQ;;gBAMR,OAAO,EAAE,eAAe;IAsB9B,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IASxC,MAAM,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAQhC,IAAI,CAAC,MAAM,CAAC,EAAE;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC,WAAW,CAAC;IASlB,KAAK,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAQxF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export { dbQuery, QueryColumnSchema, QueryResultSchema, QueryResponseSchema, } from '@agentuity/core/db';
|
|
2
|
+
export { dbTables, generateCreateTableSQL, TableColumnSchema, TableSchemaSchema, TablesResponseSchema, } from '@agentuity/core/db';
|
|
3
|
+
export { dbLogs, DbQueryLogSchema, DbLogsAPIResponseSchema, DbLogsRequestSchema, DbLogsResponseSchema, } from '@agentuity/core/db';
|
|
4
|
+
export { dbLogStats, DbLogStatsAPIResponseSchema, DbLogStatsCommandBreakdownSchema, DbLogStatsQueryPatternSchema, DbLogStatsRequestSchema, DbLogStatsResponseSchema, DbLogStatsSummarySchema, DbLogStatsTimeSeriesPointSchema, } from '@agentuity/core/db';
|
|
5
|
+
export { DbInvalidArgumentError, DbResponseError } from '@agentuity/core/db';
|
|
6
|
+
import { APIClient } from '@agentuity/core/api';
|
|
7
|
+
import { createMinimalLogger } from '@agentuity/core';
|
|
8
|
+
import { getEnv } from '@agentuity/core';
|
|
9
|
+
import { getServiceUrls } from '@agentuity/core/config';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { dbQuery, dbTables, dbLogs, dbLogStats, } from '@agentuity/core/db';
|
|
12
|
+
export const DBClientOptionsSchema = z.object({
|
|
13
|
+
apiKey: z.string().optional().describe('API key for authentication'),
|
|
14
|
+
url: z.string().optional().describe('Base URL for the DB API'),
|
|
15
|
+
database: z.string().describe('Database name'),
|
|
16
|
+
orgId: z.string().describe('Organization ID'),
|
|
17
|
+
region: z.string().optional().describe('Cloud region'),
|
|
18
|
+
logger: z.custom().optional().describe('Custom logger instance'),
|
|
19
|
+
});
|
|
20
|
+
export class DBClient {
|
|
21
|
+
#client;
|
|
22
|
+
#database;
|
|
23
|
+
#orgId;
|
|
24
|
+
#region;
|
|
25
|
+
constructor(options) {
|
|
26
|
+
if (!options.database) {
|
|
27
|
+
throw new Error('database is required for DBClient');
|
|
28
|
+
}
|
|
29
|
+
if (!options.orgId) {
|
|
30
|
+
throw new Error('orgId is required for DBClient');
|
|
31
|
+
}
|
|
32
|
+
const apiKey = options.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
|
|
33
|
+
const region = options.region || (getEnv('AGENTUITY_REGION') ?? 'usc');
|
|
34
|
+
const serviceUrls = getServiceUrls(region);
|
|
35
|
+
const url = options.url || getEnv('AGENTUITY_DB_URL') || serviceUrls.catalyst;
|
|
36
|
+
const logger = options.logger ?? createMinimalLogger();
|
|
37
|
+
this.#client = new APIClient(url, logger, apiKey ?? '');
|
|
38
|
+
this.#database = options.database;
|
|
39
|
+
this.#orgId = options.orgId;
|
|
40
|
+
this.#region = region;
|
|
41
|
+
}
|
|
42
|
+
async query(sql) {
|
|
43
|
+
return dbQuery(this.#client, {
|
|
44
|
+
database: this.#database,
|
|
45
|
+
query: sql,
|
|
46
|
+
orgId: this.#orgId,
|
|
47
|
+
region: this.#region,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async tables() {
|
|
51
|
+
return dbTables(this.#client, {
|
|
52
|
+
database: this.#database,
|
|
53
|
+
orgId: this.#orgId,
|
|
54
|
+
region: this.#region,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async logs(params) {
|
|
58
|
+
return dbLogs(this.#client, {
|
|
59
|
+
database: this.#database,
|
|
60
|
+
orgId: this.#orgId,
|
|
61
|
+
region: this.#region,
|
|
62
|
+
...params,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async stats(params) {
|
|
66
|
+
return dbLogStats(this.#client, {
|
|
67
|
+
database: this.#database,
|
|
68
|
+
orgId: this.#orgId,
|
|
69
|
+
region: this.#region,
|
|
70
|
+
...params,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EAEP,iBAAiB,EAEjB,iBAAiB,EACjB,mBAAmB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,QAAQ,EACR,sBAAsB,EAEtB,iBAAiB,EAEjB,iBAAiB,EACjB,oBAAoB,GACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,MAAM,EAEN,gBAAgB,EAEhB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,UAAU,EAMV,2BAA2B,EAC3B,gCAAgC,EAChC,4BAA4B,EAC5B,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,+BAA+B,GAC/B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,o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;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAIV;QACA,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE;YAC3B,QAAQ,EAAE,IAAI,CAAC,SAAS;YACxB,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,GAAG,MAAM;SACT,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,MAA8C;QACzD,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE;YAC/B,QAAQ,EAAE,IAAI,CAAC,SAAS;YACxB,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,GAAG,MAAM;SACT,CAAC,CAAC;IACJ,CAAC;CACD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentuity/db",
|
|
3
|
+
"version": "1.0.54",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"author": "Agentuity employees and contributors",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"AGENTS.md",
|
|
11
|
+
"README.md",
|
|
12
|
+
"src",
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
23
|
+
"build": "bunx tsc --build --force",
|
|
24
|
+
"typecheck": "bunx tsc --noEmit",
|
|
25
|
+
"prepublishOnly": "bun run clean && bun run build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@agentuity/core": "1.0.54",
|
|
29
|
+
"@agentuity/server": "1.0.54",
|
|
30
|
+
"zod": "^4.3.5"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/bun": "latest",
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
35
|
+
"bun-types": "latest",
|
|
36
|
+
"typescript": "^5.9.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"sideEffects": false
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export {
|
|
2
|
+
dbQuery,
|
|
3
|
+
type QueryColumn,
|
|
4
|
+
QueryColumnSchema,
|
|
5
|
+
type QueryResult,
|
|
6
|
+
QueryResultSchema,
|
|
7
|
+
QueryResponseSchema,
|
|
8
|
+
} from '@agentuity/core/db';
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
dbTables,
|
|
12
|
+
generateCreateTableSQL,
|
|
13
|
+
type TableColumn,
|
|
14
|
+
TableColumnSchema,
|
|
15
|
+
type TableSchema,
|
|
16
|
+
TableSchemaSchema,
|
|
17
|
+
TablesResponseSchema,
|
|
18
|
+
} from '@agentuity/core/db';
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
dbLogs,
|
|
22
|
+
type DbQueryLog,
|
|
23
|
+
DbQueryLogSchema,
|
|
24
|
+
type DbQueryLogs,
|
|
25
|
+
DbLogsAPIResponseSchema,
|
|
26
|
+
DbLogsRequestSchema,
|
|
27
|
+
DbLogsResponseSchema,
|
|
28
|
+
} from '@agentuity/core/db';
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
dbLogStats,
|
|
32
|
+
type DbLogStatsResponse,
|
|
33
|
+
type DbLogStatsSummary,
|
|
34
|
+
type DbLogStatsCommandBreakdown,
|
|
35
|
+
type DbLogStatsQueryPattern,
|
|
36
|
+
type DbLogStatsTimeSeriesPoint,
|
|
37
|
+
DbLogStatsAPIResponseSchema,
|
|
38
|
+
DbLogStatsCommandBreakdownSchema,
|
|
39
|
+
DbLogStatsQueryPatternSchema,
|
|
40
|
+
DbLogStatsRequestSchema,
|
|
41
|
+
DbLogStatsResponseSchema,
|
|
42
|
+
DbLogStatsSummarySchema,
|
|
43
|
+
DbLogStatsTimeSeriesPointSchema,
|
|
44
|
+
} from '@agentuity/core/db';
|
|
45
|
+
|
|
46
|
+
export { DbInvalidArgumentError, DbResponseError } from '@agentuity/core/db';
|
|
47
|
+
|
|
48
|
+
import { APIClient } from '@agentuity/core/api';
|
|
49
|
+
import { createMinimalLogger, type Logger } from '@agentuity/core';
|
|
50
|
+
import { getEnv } from '@agentuity/core';
|
|
51
|
+
import { getServiceUrls } from '@agentuity/core/config';
|
|
52
|
+
import { z } from 'zod';
|
|
53
|
+
import {
|
|
54
|
+
dbQuery,
|
|
55
|
+
dbTables,
|
|
56
|
+
dbLogs,
|
|
57
|
+
dbLogStats,
|
|
58
|
+
type QueryResult,
|
|
59
|
+
type TableSchema,
|
|
60
|
+
type DbQueryLogs,
|
|
61
|
+
type DbLogStatsResponse,
|
|
62
|
+
} from '@agentuity/core/db';
|
|
63
|
+
|
|
64
|
+
export const DBClientOptionsSchema = z.object({
|
|
65
|
+
apiKey: z.string().optional().describe('API key for authentication'),
|
|
66
|
+
url: z.string().optional().describe('Base URL for the DB API'),
|
|
67
|
+
database: z.string().describe('Database name'),
|
|
68
|
+
orgId: z.string().describe('Organization ID'),
|
|
69
|
+
region: z.string().optional().describe('Cloud region'),
|
|
70
|
+
logger: z.custom<Logger>().optional().describe('Custom logger instance'),
|
|
71
|
+
});
|
|
72
|
+
export type DBClientOptions = z.infer<typeof DBClientOptionsSchema>;
|
|
73
|
+
|
|
74
|
+
export class DBClient {
|
|
75
|
+
readonly #client: APIClient;
|
|
76
|
+
readonly #database: string;
|
|
77
|
+
readonly #orgId: string;
|
|
78
|
+
readonly #region: string;
|
|
79
|
+
|
|
80
|
+
constructor(options: DBClientOptions) {
|
|
81
|
+
if (!options.database) {
|
|
82
|
+
throw new Error('database is required for DBClient');
|
|
83
|
+
}
|
|
84
|
+
if (!options.orgId) {
|
|
85
|
+
throw new Error('orgId is required for DBClient');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const apiKey = options.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
|
|
89
|
+
const region = options.region || (getEnv('AGENTUITY_REGION') ?? 'usc');
|
|
90
|
+
const serviceUrls = getServiceUrls(region);
|
|
91
|
+
|
|
92
|
+
const url = options.url || getEnv('AGENTUITY_DB_URL') || serviceUrls.catalyst;
|
|
93
|
+
|
|
94
|
+
const logger = options.logger ?? createMinimalLogger();
|
|
95
|
+
|
|
96
|
+
this.#client = new APIClient(url, logger, apiKey ?? '');
|
|
97
|
+
this.#database = options.database;
|
|
98
|
+
this.#orgId = options.orgId;
|
|
99
|
+
this.#region = region;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async query(sql: string): Promise<QueryResult> {
|
|
103
|
+
return dbQuery(this.#client, {
|
|
104
|
+
database: this.#database,
|
|
105
|
+
query: sql,
|
|
106
|
+
orgId: this.#orgId,
|
|
107
|
+
region: this.#region,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async tables(): Promise<TableSchema[]> {
|
|
112
|
+
return dbTables(this.#client, {
|
|
113
|
+
database: this.#database,
|
|
114
|
+
orgId: this.#orgId,
|
|
115
|
+
region: this.#region,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async logs(params?: {
|
|
120
|
+
startDate?: string;
|
|
121
|
+
endDate?: string;
|
|
122
|
+
limit?: number;
|
|
123
|
+
}): Promise<DbQueryLogs> {
|
|
124
|
+
return dbLogs(this.#client, {
|
|
125
|
+
database: this.#database,
|
|
126
|
+
orgId: this.#orgId,
|
|
127
|
+
region: this.#region,
|
|
128
|
+
...params,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async stats(params: { startDate: string; endDate: string }): Promise<DbLogStatsResponse> {
|
|
133
|
+
return dbLogStats(this.#client, {
|
|
134
|
+
database: this.#database,
|
|
135
|
+
orgId: this.#orgId,
|
|
136
|
+
region: this.#region,
|
|
137
|
+
...params,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|