@takyonic/sdk 1.0.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 +295 -0
- package/dist/admin-client.d.ts +64 -0
- package/dist/admin-client.d.ts.map +1 -0
- package/dist/admin-client.js +126 -0
- package/dist/admin-client.js.map +1 -0
- package/dist/client.d.ts +102 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +229 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +47 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +97 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/table-builder.d.ts +159 -0
- package/dist/table-builder.d.ts.map +1 -0
- package/dist/table-builder.js +251 -0
- package/dist/table-builder.js.map +1 -0
- package/dist/types.d.ts +148 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# @takyonic/sdk
|
|
2
|
+
|
|
3
|
+
Official Node.js SDK for Takyonic - A high-performance caching engine.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Fluent/Chainable API** - Intuitive query building with method chaining
|
|
8
|
+
- **Type Safety** - Full TypeScript support with generics
|
|
9
|
+
- **Automatic URL Encoding** - Query parameters are automatically encoded
|
|
10
|
+
- **Bulk Write Batching** - Large datasets are automatically chunked into optimal batches
|
|
11
|
+
- **Zero Dependencies** - Uses native `fetch` (Node.js 18+)
|
|
12
|
+
- **Comprehensive Error Handling** - Typed error classes for different failure scenarios
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @takyonic/sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
- Node.js 18.0.0 or higher (for native `fetch` support)
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { TakyonicClient } from '@takyonic/sdk';
|
|
28
|
+
|
|
29
|
+
// Initialize the client
|
|
30
|
+
const db = new TakyonicClient({
|
|
31
|
+
endpoint: 'http://localhost:8080',
|
|
32
|
+
token: 'your-api-token'
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Query with filters
|
|
36
|
+
const logs = await db.table('logs')
|
|
37
|
+
.where('severity', '>', 4)
|
|
38
|
+
.get();
|
|
39
|
+
|
|
40
|
+
// Find a single record
|
|
41
|
+
const user = await db.table('users').findById('user-123');
|
|
42
|
+
|
|
43
|
+
// Insert a record
|
|
44
|
+
await db.table('users').insert({
|
|
45
|
+
id: 'user-456',
|
|
46
|
+
name: 'Jane Doe',
|
|
47
|
+
email: 'jane@example.com'
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API Reference
|
|
52
|
+
|
|
53
|
+
### TakyonicClient
|
|
54
|
+
|
|
55
|
+
The main entry point for interacting with the Takyonic engine.
|
|
56
|
+
|
|
57
|
+
#### Constructor
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const db = new TakyonicClient({
|
|
61
|
+
endpoint: 'http://localhost:8080', // Required: Takyonic server URL
|
|
62
|
+
token: 'your-api-token', // Required: Bearer token for auth
|
|
63
|
+
timeout: 30000 // Optional: Request timeout in ms (default: 30000)
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### Methods
|
|
68
|
+
|
|
69
|
+
##### `table<T>(name: string): TableBuilder<T>`
|
|
70
|
+
|
|
71
|
+
Creates a TableBuilder for the specified table.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const builder = db.table('logs');
|
|
75
|
+
const typedBuilder = db.table<LogRecord>('logs');
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
##### `stats(): Promise<ServerStats>`
|
|
79
|
+
|
|
80
|
+
Fetches server statistics.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const stats = await db.stats();
|
|
84
|
+
console.log(`Cache hits: ${stats.cache_hits}`);
|
|
85
|
+
console.log(`Cache misses: ${stats.cache_misses}`);
|
|
86
|
+
console.log(`Total requests: ${stats.total_requests}`);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
##### `schema(): Promise<SchemaResponse>`
|
|
90
|
+
|
|
91
|
+
Fetches the database schema.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const schema = await db.schema();
|
|
95
|
+
for (const table of schema.tables) {
|
|
96
|
+
console.log(`Table: ${table.name}`);
|
|
97
|
+
for (const col of table.columns) {
|
|
98
|
+
console.log(` - ${col.name}: ${col.data_type}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### TableBuilder
|
|
104
|
+
|
|
105
|
+
Provides a fluent API for querying and modifying table data.
|
|
106
|
+
|
|
107
|
+
#### Query Methods
|
|
108
|
+
|
|
109
|
+
##### `where(column, operator, value): TableBuilder`
|
|
110
|
+
|
|
111
|
+
Adds a filter condition. Multiple `where()` calls are combined with AND.
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const results = await db.table('logs')
|
|
115
|
+
.where('severity', '>=', 3)
|
|
116
|
+
.where('event', '=', 'login')
|
|
117
|
+
.get();
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Supported operators:** `>`, `<`, `>=`, `<=`, `=`, `!=`
|
|
121
|
+
|
|
122
|
+
##### `search(column: string, query: string): TableBuilder`
|
|
123
|
+
|
|
124
|
+
Adds a full-text search filter using PostgreSQL FTS with GIN indexes.
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// Find logs containing "critical" in the event field
|
|
128
|
+
const logs = await db.table('logs')
|
|
129
|
+
.search('event', 'critical')
|
|
130
|
+
.get();
|
|
131
|
+
|
|
132
|
+
// Multi-word search (words are combined with AND)
|
|
133
|
+
const errors = await db.table('logs')
|
|
134
|
+
.search('event', 'database connection')
|
|
135
|
+
.get();
|
|
136
|
+
|
|
137
|
+
// Combine FTS with regular filters
|
|
138
|
+
const criticalErrors = await db.table('logs')
|
|
139
|
+
.search('event', 'critical')
|
|
140
|
+
.where('severity', '>=', 4)
|
|
141
|
+
.get();
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
##### `get(): Promise<T[]>`
|
|
145
|
+
|
|
146
|
+
Executes the query and returns matching records.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
const logs = await db.table('logs')
|
|
150
|
+
.where('severity', '>', 4)
|
|
151
|
+
.get();
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
##### `findById(id: string): Promise<T | null>`
|
|
155
|
+
|
|
156
|
+
Fetches a single record by ID. Returns `null` if not found.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const user = await db.table('users').findById('user-123');
|
|
160
|
+
if (user) {
|
|
161
|
+
console.log(user.name);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### Write Methods
|
|
166
|
+
|
|
167
|
+
##### `insert(data: T): Promise<WriteResult>`
|
|
168
|
+
|
|
169
|
+
Inserts a new record or updates an existing one (upsert).
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
await db.table('users').insert({
|
|
173
|
+
id: 'user-123',
|
|
174
|
+
name: 'John Doe',
|
|
175
|
+
email: 'john@example.com'
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
##### `upsert(data: T): Promise<WriteResult>`
|
|
180
|
+
|
|
181
|
+
Alias for `insert()`.
|
|
182
|
+
|
|
183
|
+
##### `insertMany(records: T[]): Promise<BulkInsertResult>`
|
|
184
|
+
|
|
185
|
+
Inserts multiple records with automatic batching. Large arrays are automatically chunked into batches of 1000 records.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
const logs = Array.from({ length: 5000 }, (_, i) => ({
|
|
189
|
+
id: `log-${i}`,
|
|
190
|
+
message: `Log entry ${i}`,
|
|
191
|
+
severity: Math.floor(Math.random() * 5)
|
|
192
|
+
}));
|
|
193
|
+
|
|
194
|
+
const result = await db.table('logs').insertMany(logs);
|
|
195
|
+
console.log(`Inserted ${result.totalInserted} records`);
|
|
196
|
+
console.log(`Processed ${result.batchesProcessed} batches`);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### Cache Methods
|
|
200
|
+
|
|
201
|
+
##### `invalidateCache(id: string): Promise<void>`
|
|
202
|
+
|
|
203
|
+
Invalidates the cache for a specific record.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
await db.table('users').invalidateCache('user-123');
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Error Handling
|
|
210
|
+
|
|
211
|
+
The SDK provides typed error classes for different failure scenarios:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import {
|
|
215
|
+
TakyonicError,
|
|
216
|
+
AuthenticationError,
|
|
217
|
+
NotFoundError,
|
|
218
|
+
ValidationError,
|
|
219
|
+
ServerError,
|
|
220
|
+
NetworkError
|
|
221
|
+
} from '@takyonic/sdk';
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
await db.table('users').findById('user-123');
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (error instanceof AuthenticationError) {
|
|
227
|
+
console.error('Invalid API token');
|
|
228
|
+
} else if (error instanceof NotFoundError) {
|
|
229
|
+
console.error('Record not found');
|
|
230
|
+
} else if (error instanceof ValidationError) {
|
|
231
|
+
console.error('Invalid request:', error.message);
|
|
232
|
+
} else if (error instanceof NetworkError) {
|
|
233
|
+
console.error('Network error:', error.message);
|
|
234
|
+
} else if (error instanceof TakyonicError) {
|
|
235
|
+
console.error(`Error ${error.statusCode}: ${error.message}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## TypeScript Support
|
|
241
|
+
|
|
242
|
+
The SDK is written in TypeScript and provides full type definitions.
|
|
243
|
+
|
|
244
|
+
### Generic Types
|
|
245
|
+
|
|
246
|
+
Use generics to type your table records:
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
interface User {
|
|
250
|
+
id: string;
|
|
251
|
+
name: string;
|
|
252
|
+
email: string;
|
|
253
|
+
age: number;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Typed queries
|
|
257
|
+
const users = await db.table<User>('users')
|
|
258
|
+
.where('age', '>=', 18)
|
|
259
|
+
.get();
|
|
260
|
+
|
|
261
|
+
// users is typed as User[]
|
|
262
|
+
|
|
263
|
+
const user = await db.table<User>('users').findById('user-123');
|
|
264
|
+
// user is typed as User | null
|
|
265
|
+
|
|
266
|
+
// Typed inserts
|
|
267
|
+
await db.table<User>('users').insert({
|
|
268
|
+
id: 'user-456',
|
|
269
|
+
name: 'Jane',
|
|
270
|
+
email: 'jane@example.com',
|
|
271
|
+
age: 25
|
|
272
|
+
});
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Available Types
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
import type {
|
|
279
|
+
TakyonicConfig,
|
|
280
|
+
ComparisonOperator,
|
|
281
|
+
Filter,
|
|
282
|
+
BaseRecord,
|
|
283
|
+
WriteResult,
|
|
284
|
+
BulkInsertResult,
|
|
285
|
+
ServerStats,
|
|
286
|
+
SchemaResponse,
|
|
287
|
+
TableSchema,
|
|
288
|
+
ColumnSchema
|
|
289
|
+
} from '@takyonic/sdk';
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## License
|
|
293
|
+
|
|
294
|
+
MIT
|
|
295
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { AdminConfig, TableSchema, MigrationResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Admin Client - For privileged administrative operations on the Takyonic engine.
|
|
4
|
+
*
|
|
5
|
+
* This client uses the admin secret (not the regular API key) and provides
|
|
6
|
+
* access to admin-only endpoints like schema migrations.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const admin = new AdminClient({
|
|
11
|
+
* endpoint: 'http://localhost:8080',
|
|
12
|
+
* adminSecret: 'your-admin-secret'
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Run a migration
|
|
16
|
+
* const result = await admin.migrate([
|
|
17
|
+
* { name: 'users', columns: [...] }
|
|
18
|
+
* ]);
|
|
19
|
+
*
|
|
20
|
+
* console.log(`Created tables: ${result.tables_created.join(', ')}`);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class AdminClient {
|
|
24
|
+
private readonly endpoint;
|
|
25
|
+
private readonly adminSecret;
|
|
26
|
+
private readonly timeout;
|
|
27
|
+
constructor(config: AdminConfig);
|
|
28
|
+
/**
|
|
29
|
+
* Executes a schema migration on the Takyonic server.
|
|
30
|
+
*
|
|
31
|
+
* This is a non-destructive operation that:
|
|
32
|
+
* - Creates new tables if they don't exist
|
|
33
|
+
* - Adds new columns to existing tables
|
|
34
|
+
* - Does NOT delete tables or columns
|
|
35
|
+
*
|
|
36
|
+
* @param schema - Array of table schemas to migrate
|
|
37
|
+
* @returns Promise resolving to the migration result
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const result = await admin.migrate([
|
|
42
|
+
* {
|
|
43
|
+
* name: 'logs',
|
|
44
|
+
* columns: [
|
|
45
|
+
* { name: 'id', data_type: 'text', nullable: false },
|
|
46
|
+
* { name: 'message', data_type: 'text', nullable: true },
|
|
47
|
+
* { name: 'severity', data_type: 'integer', nullable: false }
|
|
48
|
+
* ]
|
|
49
|
+
* }
|
|
50
|
+
* ]);
|
|
51
|
+
*
|
|
52
|
+
* if (result.tables_created.length > 0) {
|
|
53
|
+
* console.log('Created tables:', result.tables_created);
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
migrate(schema: TableSchema[]): Promise<MigrationResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the configured endpoint URL.
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
getEndpoint(): string;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=admin-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin-client.d.ts","sourceRoot":"","sources":["../src/admin-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,eAAe,EAEhB,MAAM,SAAS,CAAC;AAOjB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,WAAW;IAO/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;IAwD9D;;;OAGG;IACH,WAAW,IAAI,MAAM;CAGtB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdminClient = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
/**
|
|
6
|
+
* Default configuration values
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
9
|
+
/**
|
|
10
|
+
* Admin Client - For privileged administrative operations on the Takyonic engine.
|
|
11
|
+
*
|
|
12
|
+
* This client uses the admin secret (not the regular API key) and provides
|
|
13
|
+
* access to admin-only endpoints like schema migrations.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const admin = new AdminClient({
|
|
18
|
+
* endpoint: 'http://localhost:8080',
|
|
19
|
+
* adminSecret: 'your-admin-secret'
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Run a migration
|
|
23
|
+
* const result = await admin.migrate([
|
|
24
|
+
* { name: 'users', columns: [...] }
|
|
25
|
+
* ]);
|
|
26
|
+
*
|
|
27
|
+
* console.log(`Created tables: ${result.tables_created.join(', ')}`);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
class AdminClient {
|
|
31
|
+
endpoint;
|
|
32
|
+
adminSecret;
|
|
33
|
+
timeout;
|
|
34
|
+
constructor(config) {
|
|
35
|
+
// Remove trailing slash from endpoint
|
|
36
|
+
this.endpoint = config.endpoint.replace(/\/+$/, '');
|
|
37
|
+
this.adminSecret = config.adminSecret;
|
|
38
|
+
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Executes a schema migration on the Takyonic server.
|
|
42
|
+
*
|
|
43
|
+
* This is a non-destructive operation that:
|
|
44
|
+
* - Creates new tables if they don't exist
|
|
45
|
+
* - Adds new columns to existing tables
|
|
46
|
+
* - Does NOT delete tables or columns
|
|
47
|
+
*
|
|
48
|
+
* @param schema - Array of table schemas to migrate
|
|
49
|
+
* @returns Promise resolving to the migration result
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const result = await admin.migrate([
|
|
54
|
+
* {
|
|
55
|
+
* name: 'logs',
|
|
56
|
+
* columns: [
|
|
57
|
+
* { name: 'id', data_type: 'text', nullable: false },
|
|
58
|
+
* { name: 'message', data_type: 'text', nullable: true },
|
|
59
|
+
* { name: 'severity', data_type: 'integer', nullable: false }
|
|
60
|
+
* ]
|
|
61
|
+
* }
|
|
62
|
+
* ]);
|
|
63
|
+
*
|
|
64
|
+
* if (result.tables_created.length > 0) {
|
|
65
|
+
* console.log('Created tables:', result.tables_created);
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
async migrate(schema) {
|
|
70
|
+
const url = `${this.endpoint}/v1/admin/migrate`;
|
|
71
|
+
const fetchOptions = {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: {
|
|
74
|
+
'Content-Type': 'application/json',
|
|
75
|
+
'Authorization': `Bearer ${this.adminSecret}`,
|
|
76
|
+
},
|
|
77
|
+
body: JSON.stringify(schema),
|
|
78
|
+
};
|
|
79
|
+
// Create abort controller for timeout
|
|
80
|
+
const controller = new AbortController();
|
|
81
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
82
|
+
fetchOptions.signal = controller.signal;
|
|
83
|
+
try {
|
|
84
|
+
const response = await fetch(url, fetchOptions);
|
|
85
|
+
clearTimeout(timeoutId);
|
|
86
|
+
// Handle non-OK responses
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
let errorResponse;
|
|
89
|
+
try {
|
|
90
|
+
errorResponse = await response.json();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Response body might not be valid JSON
|
|
94
|
+
}
|
|
95
|
+
throw (0, errors_1.createErrorFromStatus)(response.status, errorResponse);
|
|
96
|
+
}
|
|
97
|
+
return await response.json();
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
clearTimeout(timeoutId);
|
|
101
|
+
// Re-throw TakyonicError instances
|
|
102
|
+
if (error instanceof Error && error.name.includes('Error') && 'statusCode' in error) {
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
// Handle abort (timeout)
|
|
106
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
107
|
+
throw new errors_1.NetworkError(`Request timed out after ${this.timeout}ms`);
|
|
108
|
+
}
|
|
109
|
+
// Handle network errors
|
|
110
|
+
if (error instanceof TypeError) {
|
|
111
|
+
throw new errors_1.NetworkError(`Network request failed: ${error.message}`);
|
|
112
|
+
}
|
|
113
|
+
// Re-throw unknown errors
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets the configured endpoint URL.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
getEndpoint() {
|
|
122
|
+
return this.endpoint;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.AdminClient = AdminClient;
|
|
126
|
+
//# sourceMappingURL=admin-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin-client.js","sourceRoot":"","sources":["../src/admin-client.ts"],"names":[],"mappings":";;;AAAA,qCAA+D;AAQ/D;;GAEG;AACH,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,WAAW;IACL,QAAQ,CAAS;IACjB,WAAW,CAAS;IACpB,OAAO,CAAS;IAEjC,YAAY,MAAmB;QAC7B,sCAAsC;QACtC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,eAAe,CAAC;IACnD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,KAAK,CAAC,OAAO,CAAC,MAAqB;QACjC,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,QAAQ,mBAAmB,CAAC;QAEhD,MAAM,YAAY,GAAgB;YAChC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,eAAe,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;aAC9C;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;SAC7B,CAAC;QAEF,sCAAsC;QACtC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACrE,YAAY,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;QAExC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YAChD,YAAY,CAAC,SAAS,CAAC,CAAC;YAExB,0BAA0B;YAC1B,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,IAAI,aAAwC,CAAC;gBAC7C,IAAI,CAAC;oBACH,aAAa,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAmB,CAAC;gBACzD,CAAC;gBAAC,MAAM,CAAC;oBACP,wCAAwC;gBAC1C,CAAC;gBACD,MAAM,IAAA,8BAAqB,EAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;YAC9D,CAAC;YAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAqB,CAAC;QAClD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,YAAY,CAAC,SAAS,CAAC,CAAC;YAExB,mCAAmC;YACnC,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,YAAY,IAAI,KAAK,EAAE,CAAC;gBACpF,MAAM,KAAK,CAAC;YACd,CAAC;YAED,yBAAyB;YACzB,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC1D,MAAM,IAAI,qBAAY,CAAC,2BAA2B,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;YACtE,CAAC;YAED,wBAAwB;YACxB,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;gBAC/B,MAAM,IAAI,qBAAY,CAAC,2BAA2B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACrE,CAAC;YAED,0BAA0B;YAC1B,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAxGD,kCAwGC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { TableBuilder } from './table-builder';
|
|
2
|
+
import type { TakyonicConfig, RequestOptions, ServerStats, SchemaResponse } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Takyonic Client - The main entry point for interacting with the Takyonic engine.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const db = new TakyonicClient({
|
|
9
|
+
* endpoint: 'http://localhost:8080',
|
|
10
|
+
* token: 'your-api-token'
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* // Query a table
|
|
14
|
+
* const logs = await db.table('logs').where('severity', '>', 4).get();
|
|
15
|
+
*
|
|
16
|
+
* // Insert a record
|
|
17
|
+
* await db.table('users').insert({ id: 'user-1', name: 'John' });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class TakyonicClient {
|
|
21
|
+
private readonly endpoint;
|
|
22
|
+
private readonly token;
|
|
23
|
+
private readonly timeout;
|
|
24
|
+
constructor(config: TakyonicConfig);
|
|
25
|
+
/**
|
|
26
|
+
* Creates a TableBuilder for the specified table.
|
|
27
|
+
* This is the starting point for all table operations.
|
|
28
|
+
*
|
|
29
|
+
* @param name - The name of the table to query
|
|
30
|
+
* @returns A TableBuilder instance for fluent query building
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const results = await db.table('logs')
|
|
35
|
+
* .where('severity', '>=', 3)
|
|
36
|
+
* .get();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
table<T extends {
|
|
40
|
+
id: string;
|
|
41
|
+
} = {
|
|
42
|
+
id: string;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}>(name: string): TableBuilder<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Fetches server statistics including cache hits, misses, and performance metrics.
|
|
47
|
+
*
|
|
48
|
+
* @returns Promise resolving to server statistics
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const stats = await db.stats();
|
|
53
|
+
* console.log(`Cache hit rate: ${stats.cache_hits / stats.total_requests * 100}%`);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
stats(): Promise<ServerStats>;
|
|
57
|
+
/**
|
|
58
|
+
* Fetches the database schema including all tables, columns, and relationships.
|
|
59
|
+
*
|
|
60
|
+
* @returns Promise resolving to the schema information
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const schema = await db.schema();
|
|
65
|
+
* for (const table of schema.tables) {
|
|
66
|
+
* console.log(`Table: ${table.name}, Columns: ${table.columns.length}`);
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
schema(): Promise<SchemaResponse>;
|
|
71
|
+
/**
|
|
72
|
+
* Fetches the database schema as a formatted .takyonic DSL string.
|
|
73
|
+
* This is the authoritative format from the Rust backend.
|
|
74
|
+
*
|
|
75
|
+
* @returns Promise resolving to the DSL string content
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const dsl = await db.schemaDsl();
|
|
80
|
+
* fs.writeFileSync('.takyonic', dsl);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
schemaDsl(): Promise<string>;
|
|
84
|
+
/**
|
|
85
|
+
* Internal method to make HTTP requests to the Takyonic server.
|
|
86
|
+
* Handles authentication, error handling, and response parsing.
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
91
|
+
/**
|
|
92
|
+
* Gets the configured endpoint URL.
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
getEndpoint(): string;
|
|
96
|
+
/**
|
|
97
|
+
* Gets the configured timeout.
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
getTimeout(): number;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,WAAW,EACX,cAAc,EAGf,MAAM,SAAS,CAAC;AAOjB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,cAAc;IAOlC;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,CAAC,SAAS;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC;IAIvG;;;;;;;;;;OAUG;IACG,KAAK,IAAI,OAAO,CAAC,WAAW,CAAC;IAOnC;;;;;;;;;;;;OAYG;IACG,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC;IAQvC;;;;;;;;;;;OAWG;IACG,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IA8ClC;;;;;OAKG;IACG,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IA4ErD;;;OAGG;IACH,WAAW,IAAI,MAAM;IAIrB;;;OAGG;IACH,UAAU,IAAI,MAAM;CAGrB"}
|