@boltic/sdk 0.0.4 → 0.0.5
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/dist/databases/index.d.ts +72 -0
- package/dist/databases/index.js +1 -1
- package/dist/databases/index.js.map +1 -1
- package/dist/databases/index.mjs +5 -5
- package/dist/databases/index.mjs.map +1 -1
- package/dist/databases/test-client-DfOmma3t.js +2 -0
- package/dist/databases/test-client-DfOmma3t.js.map +1 -0
- package/dist/databases/{test-client-BffJwqJq.mjs → test-client-rQ1AmTo6.mjs} +229 -4
- package/dist/databases/test-client-rQ1AmTo6.mjs.map +1 -0
- package/dist/databases/testing.d.ts +68 -0
- package/dist/databases/testing.js +1 -1
- package/dist/databases/testing.mjs +1 -1
- package/dist/sdk.js +219 -0
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.mjs +219 -0
- package/dist/sdk.mjs.map +1 -1
- package/dist/types/index.d.ts +68 -0
- package/package.json +1 -1
- package/dist/databases/test-client-BI3VkYA6.js +0 -2
- package/dist/databases/test-client-BI3VkYA6.js.map +0 -1
- package/dist/databases/test-client-BffJwqJq.mjs.map +0 -1
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
declare interface AddIndexRequest {
|
|
2
|
+
field_names: string[];
|
|
3
|
+
method: 'btree' | 'hash' | 'spgist' | 'gin' | 'brin';
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare interface AddIndexResponse {
|
|
7
|
+
index_name: string;
|
|
8
|
+
method: string;
|
|
9
|
+
fields: string[];
|
|
10
|
+
field_ids?: string[];
|
|
11
|
+
created_at?: string;
|
|
12
|
+
created_by?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
1
15
|
declare type AlignmentType = 'left' | 'center' | 'right';
|
|
2
16
|
|
|
3
17
|
/**
|
|
@@ -64,6 +78,7 @@ declare class BolticClient {
|
|
|
64
78
|
private columnResource;
|
|
65
79
|
private recordResource;
|
|
66
80
|
private sqlResource;
|
|
81
|
+
private indexResource;
|
|
67
82
|
private currentDatabase;
|
|
68
83
|
private clientOptions;
|
|
69
84
|
constructor(apiKey: string, options?: ClientOptions);
|
|
@@ -96,6 +111,11 @@ declare class BolticClient {
|
|
|
96
111
|
message?: string | undefined;
|
|
97
112
|
}>>;
|
|
98
113
|
};
|
|
114
|
+
get indexes(): {
|
|
115
|
+
addIndex: (tableName: string, payload: AddIndexRequest) => Promise<BolticErrorResponse_2 | BolticSuccessResponse<AddIndexResponse>>;
|
|
116
|
+
listIndexes: (tableName: string, query: ListIndexesQuery) => Promise<BolticErrorResponse_2 | BolticSuccessResponse<ListIndexesResponse>>;
|
|
117
|
+
deleteIndex: (tableName: string, indexName: string) => Promise<BolticErrorResponse_2 | BolticSuccessResponse<DeleteIndexResponse>>;
|
|
118
|
+
};
|
|
99
119
|
table(name: string): TableBuilder;
|
|
100
120
|
from(tableName: string): {
|
|
101
121
|
columns: () => {
|
|
@@ -124,6 +144,11 @@ declare class BolticClient {
|
|
|
124
144
|
}>>;
|
|
125
145
|
};
|
|
126
146
|
record: () => RecordBuilder;
|
|
147
|
+
indexes: () => {
|
|
148
|
+
addIndex: (payload: AddIndexRequest) => Promise<BolticErrorResponse_2 | BolticSuccessResponse<AddIndexResponse>>;
|
|
149
|
+
listIndexes: (query: ListIndexesQuery) => Promise<BolticErrorResponse_2 | BolticSuccessResponse<ListIndexesResponse>>;
|
|
150
|
+
deleteIndex: (indexName: string) => Promise<BolticErrorResponse_2 | BolticSuccessResponse<DeleteIndexResponse>>;
|
|
151
|
+
};
|
|
127
152
|
};
|
|
128
153
|
get records(): {
|
|
129
154
|
insert: (tableName: string, data: RecordData) => Promise<BolticErrorResponse_2 | BolticSuccessResponse<RecordWithId>>;
|
|
@@ -397,6 +422,10 @@ declare const DateFormatEnum: Readonly<{
|
|
|
397
422
|
|
|
398
423
|
declare type DecimalType = '00' | '0.0' | '0.00' | '0.000' | '0.0000' | '0.00000' | '0.000000';
|
|
399
424
|
|
|
425
|
+
declare interface DeleteIndexResponse {
|
|
426
|
+
message?: string;
|
|
427
|
+
}
|
|
428
|
+
|
|
400
429
|
declare type Environment = 'local' | 'sit' | 'uat' | 'prod';
|
|
401
430
|
|
|
402
431
|
declare interface EnvironmentConfig {
|
|
@@ -492,6 +521,20 @@ declare interface HttpResponse<T = unknown> {
|
|
|
492
521
|
headers: Record<string, string>;
|
|
493
522
|
}
|
|
494
523
|
|
|
524
|
+
declare interface IndexListItem {
|
|
525
|
+
schemaname?: string;
|
|
526
|
+
relname?: string;
|
|
527
|
+
indexrelname: string;
|
|
528
|
+
method?: string;
|
|
529
|
+
idx_scan?: number;
|
|
530
|
+
idx_tup_read?: number;
|
|
531
|
+
idx_tup_fetch?: number;
|
|
532
|
+
field_ids?: string[];
|
|
533
|
+
fields?: string[];
|
|
534
|
+
created_at?: string;
|
|
535
|
+
created_by?: string;
|
|
536
|
+
}
|
|
537
|
+
|
|
495
538
|
declare interface InterceptorManager {
|
|
496
539
|
request: {
|
|
497
540
|
use(interceptor: RequestInterceptor): number;
|
|
@@ -520,6 +563,31 @@ declare class InterceptorManagerImpl implements InterceptorManager {
|
|
|
520
563
|
executeErrorInterceptors(error: unknown): Promise<unknown>;
|
|
521
564
|
}
|
|
522
565
|
|
|
566
|
+
declare interface ListIndexesQuery {
|
|
567
|
+
page?: {
|
|
568
|
+
page_no: number;
|
|
569
|
+
page_size: number;
|
|
570
|
+
};
|
|
571
|
+
filters?: Array<{
|
|
572
|
+
field: string;
|
|
573
|
+
operator: string;
|
|
574
|
+
values: unknown[];
|
|
575
|
+
}>;
|
|
576
|
+
sort?: Array<{
|
|
577
|
+
field: string;
|
|
578
|
+
direction: 'asc' | 'desc';
|
|
579
|
+
}>;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
declare interface ListIndexesResponse {
|
|
583
|
+
items: IndexListItem[];
|
|
584
|
+
page?: {
|
|
585
|
+
page_no: number;
|
|
586
|
+
page_size: number;
|
|
587
|
+
total?: number;
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
|
|
523
591
|
export declare interface MockClientOptions {
|
|
524
592
|
apiKey?: string;
|
|
525
593
|
environment?: 'local' | 'sit' | 'uat' | 'prod';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./test-client-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./test-client-DfOmma3t.js");class t{static async*fromSSE(e){if(!e.body)throw new Error("Response body is null");const t=e.body.getReader(),s=new TextDecoder;try{for(;;){const{done:e,value:o}=await t.read();if(e)break;const r=s.decode(o,{stream:!0}).split("\n");for(const t of r)if(t.startsWith("data: ")){const e=t.slice(6);"[DONE]"!==e&&(yield e)}}}finally{t.releaseLock()}}static async*fromChunked(e){if(!e.body)throw new Error("Response body is null");const t=e.body.getReader(),s=new TextDecoder;try{for(;;){const{done:e,value:o}=await t.read();if(e)break;const r=s.decode(o,{stream:!0});yield r}}finally{t.releaseLock()}}static async collectAll(e){let t="";for await(const s of e)t+=s;return t}static async*fromString(e,t=10){for(let s=0;s<e.length;s+=t)yield e.slice(s,s+t),await new Promise(e=>setTimeout(e,50))}static async*map(e,t){for await(const s of e)yield await t(s)}static async*filter(e,t){for await(const s of e)await t(s)&&(yield s)}static async*take(e,t){let s=0;for await(const o of e){if(s>=t)break;yield o,s++}}}exports.createErrorResponse=e.createErrorResponse,exports.createMockResponse=e.createMockResponse,exports.createTestClient=e.createTestClient,exports.SqlTestClient=class{constructor(e){this.sql=e}async generateSQL(e,s){const o=await this.sql.textToSQL(e,s);return t.collectAll(o)}async executeSQL(e){return this.sql.executeSQL(e)}async*simulateStreamingSQL(e,t=10,s=50){for(let o=0;o<e.length;o+=t)yield e.slice(o,o+t),await new Promise(e=>setTimeout(e,s))}},exports.TEST_UTILS_VERSION="1.0.0";
|
|
2
2
|
//# sourceMappingURL=testing.js.map
|
package/dist/sdk.js
CHANGED
|
@@ -2298,6 +2298,209 @@ class ColumnResource extends BaseResource {
|
|
|
2298
2298
|
return tableInfo?.id || null;
|
|
2299
2299
|
}
|
|
2300
2300
|
}
|
|
2301
|
+
const INDEX_ENDPOINTS = {
|
|
2302
|
+
create: {
|
|
2303
|
+
path: "/tables/indexes/{table_id}",
|
|
2304
|
+
method: "POST",
|
|
2305
|
+
authenticated: true
|
|
2306
|
+
},
|
|
2307
|
+
list: {
|
|
2308
|
+
path: "/tables/indexes/{table_id}/list",
|
|
2309
|
+
method: "POST",
|
|
2310
|
+
authenticated: true
|
|
2311
|
+
},
|
|
2312
|
+
delete: {
|
|
2313
|
+
path: "/tables/indexes/{table_id}",
|
|
2314
|
+
method: "DELETE",
|
|
2315
|
+
authenticated: true
|
|
2316
|
+
}
|
|
2317
|
+
};
|
|
2318
|
+
const buildIndexEndpointPath = (endpoint, params = {}) => {
|
|
2319
|
+
let path = endpoint.path;
|
|
2320
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
2321
|
+
path = path.replace(`{${key}}`, encodeURIComponent(value));
|
|
2322
|
+
});
|
|
2323
|
+
const unreplacedParams = path.match(/\{([^}]+)\}/g);
|
|
2324
|
+
if (unreplacedParams) {
|
|
2325
|
+
throw new Error(`Missing path parameters: ${unreplacedParams.join(", ")}`);
|
|
2326
|
+
}
|
|
2327
|
+
return path;
|
|
2328
|
+
};
|
|
2329
|
+
class IndexesApiClient {
|
|
2330
|
+
constructor(apiKey, config = {}) {
|
|
2331
|
+
this.config = { apiKey, ...config };
|
|
2332
|
+
this.httpAdapter = createHttpAdapter();
|
|
2333
|
+
const environment = config.environment || "prod";
|
|
2334
|
+
const region = config.region || "asia-south1";
|
|
2335
|
+
this.baseURL = this.getBaseURL(environment, region);
|
|
2336
|
+
}
|
|
2337
|
+
getBaseURL(environment, region) {
|
|
2338
|
+
const regionConfig = REGION_CONFIGS[region];
|
|
2339
|
+
if (!regionConfig) {
|
|
2340
|
+
throw new Error(`Unsupported region: ${region}`);
|
|
2341
|
+
}
|
|
2342
|
+
const envConfig = regionConfig[environment];
|
|
2343
|
+
if (!envConfig) {
|
|
2344
|
+
throw new Error(
|
|
2345
|
+
`Unsupported environment: ${environment} for region: ${region}`
|
|
2346
|
+
);
|
|
2347
|
+
}
|
|
2348
|
+
return `${envConfig.baseURL}/v1`;
|
|
2349
|
+
}
|
|
2350
|
+
async addIndex(tableId, request) {
|
|
2351
|
+
try {
|
|
2352
|
+
const endpoint = INDEX_ENDPOINTS.create;
|
|
2353
|
+
const url = `${this.baseURL}${buildIndexEndpointPath(endpoint, { table_id: tableId })}`;
|
|
2354
|
+
const response = await this.httpAdapter.request({
|
|
2355
|
+
url,
|
|
2356
|
+
method: endpoint.method,
|
|
2357
|
+
headers: this.buildHeaders(),
|
|
2358
|
+
data: request,
|
|
2359
|
+
timeout: this.config.timeout
|
|
2360
|
+
});
|
|
2361
|
+
return response.data;
|
|
2362
|
+
} catch (error) {
|
|
2363
|
+
return this.formatErrorResponse(error);
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
async listIndexes(tableId, query) {
|
|
2367
|
+
try {
|
|
2368
|
+
const endpoint = INDEX_ENDPOINTS.list;
|
|
2369
|
+
const url = `${this.baseURL}${buildIndexEndpointPath(endpoint, { table_id: tableId })}`;
|
|
2370
|
+
const response = await this.httpAdapter.request({
|
|
2371
|
+
url,
|
|
2372
|
+
method: endpoint.method,
|
|
2373
|
+
headers: this.buildHeaders(),
|
|
2374
|
+
data: query,
|
|
2375
|
+
timeout: this.config.timeout
|
|
2376
|
+
});
|
|
2377
|
+
return response.data;
|
|
2378
|
+
} catch (error) {
|
|
2379
|
+
return this.formatErrorResponse(error);
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
async deleteIndex(tableId, request) {
|
|
2383
|
+
try {
|
|
2384
|
+
const endpoint = INDEX_ENDPOINTS.delete;
|
|
2385
|
+
const url = `${this.baseURL}${buildIndexEndpointPath(endpoint, { table_id: tableId })}`;
|
|
2386
|
+
const response = await this.httpAdapter.request({
|
|
2387
|
+
url,
|
|
2388
|
+
method: endpoint.method,
|
|
2389
|
+
headers: this.buildHeaders(),
|
|
2390
|
+
data: request,
|
|
2391
|
+
timeout: this.config.timeout
|
|
2392
|
+
});
|
|
2393
|
+
return response.data;
|
|
2394
|
+
} catch (error) {
|
|
2395
|
+
return this.formatErrorResponse(error);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
buildHeaders() {
|
|
2399
|
+
return {
|
|
2400
|
+
"Content-Type": "application/json",
|
|
2401
|
+
Accept: "application/json",
|
|
2402
|
+
"x-boltic-token": this.config.apiKey
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
formatErrorResponse(error) {
|
|
2406
|
+
if (this.config.debug) {
|
|
2407
|
+
console.error("Indexes API Error:", error);
|
|
2408
|
+
}
|
|
2409
|
+
if (error && typeof error === "object" && "response" in error) {
|
|
2410
|
+
const apiError = error;
|
|
2411
|
+
if (apiError.response?.data?.error) {
|
|
2412
|
+
return apiError.response.data;
|
|
2413
|
+
}
|
|
2414
|
+
return {
|
|
2415
|
+
error: {
|
|
2416
|
+
code: "API_ERROR",
|
|
2417
|
+
message: error.message || "Unknown API error",
|
|
2418
|
+
meta: [`Status: ${apiError.response?.status || "unknown"}`]
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
}
|
|
2422
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
2423
|
+
return {
|
|
2424
|
+
error: {
|
|
2425
|
+
code: "CLIENT_ERROR",
|
|
2426
|
+
message: error.message,
|
|
2427
|
+
meta: ["Client-side error occurred"]
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
}
|
|
2431
|
+
return {
|
|
2432
|
+
error: {
|
|
2433
|
+
code: "UNKNOWN_ERROR",
|
|
2434
|
+
message: "An unexpected error occurred",
|
|
2435
|
+
meta: ["Unknown error type"]
|
|
2436
|
+
}
|
|
2437
|
+
};
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
class IndexResource {
|
|
2441
|
+
constructor(client) {
|
|
2442
|
+
this.client = client;
|
|
2443
|
+
const config = client.getConfig();
|
|
2444
|
+
this.apiClient = new IndexesApiClient(config.apiKey, {
|
|
2445
|
+
environment: config.environment,
|
|
2446
|
+
region: config.region,
|
|
2447
|
+
timeout: config.timeout,
|
|
2448
|
+
debug: config.debug,
|
|
2449
|
+
retryAttempts: config.retryAttempts,
|
|
2450
|
+
retryDelay: config.retryDelay,
|
|
2451
|
+
headers: config.headers
|
|
2452
|
+
});
|
|
2453
|
+
this.tableResource = new TableResource(client);
|
|
2454
|
+
}
|
|
2455
|
+
async resolveTableId(tableName) {
|
|
2456
|
+
const tableResult = await this.tableResource.findByName(tableName);
|
|
2457
|
+
if (!tableResult.data) throw new Error(`Table not found: ${tableName}`);
|
|
2458
|
+
return tableResult.data.id;
|
|
2459
|
+
}
|
|
2460
|
+
async addIndex(tableName, request) {
|
|
2461
|
+
try {
|
|
2462
|
+
const tableId = await this.resolveTableId(tableName);
|
|
2463
|
+
return await this.apiClient.addIndex(tableId, request);
|
|
2464
|
+
} catch (error) {
|
|
2465
|
+
return {
|
|
2466
|
+
error: {
|
|
2467
|
+
code: "CLIENT_ERROR",
|
|
2468
|
+
message: error?.message || "Failed to add index",
|
|
2469
|
+
meta: ["IndexResource.addIndex"]
|
|
2470
|
+
}
|
|
2471
|
+
};
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
async listIndexes(tableName, query) {
|
|
2475
|
+
try {
|
|
2476
|
+
const tableId = await this.resolveTableId(tableName);
|
|
2477
|
+
return await this.apiClient.listIndexes(tableId, query);
|
|
2478
|
+
} catch (error) {
|
|
2479
|
+
return {
|
|
2480
|
+
error: {
|
|
2481
|
+
code: "CLIENT_ERROR",
|
|
2482
|
+
message: error?.message || "Failed to list indexes",
|
|
2483
|
+
meta: ["IndexResource.listIndexes"]
|
|
2484
|
+
}
|
|
2485
|
+
};
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
async deleteIndex(tableName, indexName) {
|
|
2489
|
+
try {
|
|
2490
|
+
const tableId = await this.resolveTableId(tableName);
|
|
2491
|
+
const request = { index_name: indexName };
|
|
2492
|
+
return await this.apiClient.deleteIndex(tableId, request);
|
|
2493
|
+
} catch (error) {
|
|
2494
|
+
return {
|
|
2495
|
+
error: {
|
|
2496
|
+
code: "CLIENT_ERROR",
|
|
2497
|
+
message: error?.message || "Failed to delete index",
|
|
2498
|
+
meta: ["IndexResource.deleteIndex"]
|
|
2499
|
+
}
|
|
2500
|
+
};
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2301
2504
|
const RECORD_ENDPOINTS = {
|
|
2302
2505
|
insert: {
|
|
2303
2506
|
path: "/tables/{table_id}/records",
|
|
@@ -3764,6 +3967,7 @@ class BolticClient {
|
|
|
3764
3967
|
this.columnResource = new ColumnResource(this.baseClient);
|
|
3765
3968
|
this.recordResource = new RecordResource(this.baseClient);
|
|
3766
3969
|
this.sqlResource = new SqlResource(this.baseClient);
|
|
3970
|
+
this.indexResource = new IndexResource(this.baseClient);
|
|
3767
3971
|
this.currentDatabase = {
|
|
3768
3972
|
databaseName: "Default"
|
|
3769
3973
|
};
|
|
@@ -3797,6 +4001,14 @@ class BolticClient {
|
|
|
3797
4001
|
delete: (tableName, columnName) => this.columnResource.delete(tableName, columnName)
|
|
3798
4002
|
};
|
|
3799
4003
|
}
|
|
4004
|
+
// Direct index operations
|
|
4005
|
+
get indexes() {
|
|
4006
|
+
return {
|
|
4007
|
+
addIndex: (tableName, payload) => this.indexResource.addIndex(tableName, payload),
|
|
4008
|
+
listIndexes: (tableName, query) => this.indexResource.listIndexes(tableName, query),
|
|
4009
|
+
deleteIndex: (tableName, indexName) => this.indexResource.deleteIndex(tableName, indexName)
|
|
4010
|
+
};
|
|
4011
|
+
}
|
|
3800
4012
|
// Fluent table operations
|
|
3801
4013
|
table(name) {
|
|
3802
4014
|
const tableBuilder = createTableBuilder({ name });
|
|
@@ -3829,6 +4041,12 @@ class BolticClient {
|
|
|
3829
4041
|
record: () => createRecordBuilder({
|
|
3830
4042
|
tableName,
|
|
3831
4043
|
recordResource: this.recordResource
|
|
4044
|
+
}),
|
|
4045
|
+
// Indexes - Method 2: Function chaining under from(tableName)
|
|
4046
|
+
indexes: () => ({
|
|
4047
|
+
addIndex: (payload) => this.indexResource.addIndex(tableName, payload),
|
|
4048
|
+
listIndexes: (query) => this.indexResource.listIndexes(tableName, query),
|
|
4049
|
+
deleteIndex: (indexName) => this.indexResource.deleteIndex(tableName, indexName)
|
|
3832
4050
|
})
|
|
3833
4051
|
};
|
|
3834
4052
|
}
|
|
@@ -3939,6 +4157,7 @@ class BolticClient {
|
|
|
3939
4157
|
this.columnResource = new ColumnResource(this.baseClient);
|
|
3940
4158
|
this.recordResource = new RecordResource(this.baseClient);
|
|
3941
4159
|
this.sqlResource = new SqlResource(this.baseClient);
|
|
4160
|
+
this.indexResource = new IndexResource(this.baseClient);
|
|
3942
4161
|
}
|
|
3943
4162
|
// Security methods to prevent API key exposure
|
|
3944
4163
|
toString() {
|