@boltic/sdk 0.0.3 → 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 +224 -0
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.mjs +224 -0
- package/dist/sdk.mjs.map +1 -1
- package/dist/types/index.d.ts +68 -0
- package/package.json +2 -5
- 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
package/dist/sdk.mjs
CHANGED
|
@@ -1634,6 +1634,7 @@ class TableResource extends BaseResource {
|
|
|
1634
1634
|
const config = client.getConfig();
|
|
1635
1635
|
this.tablesApiClient = new TablesApiClient(config.apiKey, {
|
|
1636
1636
|
environment: config.environment,
|
|
1637
|
+
region: config.region,
|
|
1637
1638
|
timeout: config.timeout,
|
|
1638
1639
|
debug: config.debug,
|
|
1639
1640
|
retryAttempts: config.retryAttempts,
|
|
@@ -1927,6 +1928,7 @@ class ColumnResource extends BaseResource {
|
|
|
1927
1928
|
const config = client.getConfig();
|
|
1928
1929
|
this.columnsApiClient = new ColumnsApiClient(config.apiKey, {
|
|
1929
1930
|
environment: config.environment,
|
|
1931
|
+
region: config.region,
|
|
1930
1932
|
timeout: config.timeout,
|
|
1931
1933
|
debug: config.debug,
|
|
1932
1934
|
retryAttempts: config.retryAttempts,
|
|
@@ -1935,6 +1937,7 @@ class ColumnResource extends BaseResource {
|
|
|
1935
1937
|
});
|
|
1936
1938
|
this.tablesApiClient = new TablesApiClient(config.apiKey, {
|
|
1937
1939
|
environment: config.environment,
|
|
1940
|
+
region: config.region,
|
|
1938
1941
|
timeout: config.timeout,
|
|
1939
1942
|
debug: config.debug,
|
|
1940
1943
|
retryAttempts: config.retryAttempts,
|
|
@@ -2293,6 +2296,209 @@ class ColumnResource extends BaseResource {
|
|
|
2293
2296
|
return tableInfo?.id || null;
|
|
2294
2297
|
}
|
|
2295
2298
|
}
|
|
2299
|
+
const INDEX_ENDPOINTS = {
|
|
2300
|
+
create: {
|
|
2301
|
+
path: "/tables/indexes/{table_id}",
|
|
2302
|
+
method: "POST",
|
|
2303
|
+
authenticated: true
|
|
2304
|
+
},
|
|
2305
|
+
list: {
|
|
2306
|
+
path: "/tables/indexes/{table_id}/list",
|
|
2307
|
+
method: "POST",
|
|
2308
|
+
authenticated: true
|
|
2309
|
+
},
|
|
2310
|
+
delete: {
|
|
2311
|
+
path: "/tables/indexes/{table_id}",
|
|
2312
|
+
method: "DELETE",
|
|
2313
|
+
authenticated: true
|
|
2314
|
+
}
|
|
2315
|
+
};
|
|
2316
|
+
const buildIndexEndpointPath = (endpoint, params = {}) => {
|
|
2317
|
+
let path = endpoint.path;
|
|
2318
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
2319
|
+
path = path.replace(`{${key}}`, encodeURIComponent(value));
|
|
2320
|
+
});
|
|
2321
|
+
const unreplacedParams = path.match(/\{([^}]+)\}/g);
|
|
2322
|
+
if (unreplacedParams) {
|
|
2323
|
+
throw new Error(`Missing path parameters: ${unreplacedParams.join(", ")}`);
|
|
2324
|
+
}
|
|
2325
|
+
return path;
|
|
2326
|
+
};
|
|
2327
|
+
class IndexesApiClient {
|
|
2328
|
+
constructor(apiKey, config = {}) {
|
|
2329
|
+
this.config = { apiKey, ...config };
|
|
2330
|
+
this.httpAdapter = createHttpAdapter();
|
|
2331
|
+
const environment = config.environment || "prod";
|
|
2332
|
+
const region = config.region || "asia-south1";
|
|
2333
|
+
this.baseURL = this.getBaseURL(environment, region);
|
|
2334
|
+
}
|
|
2335
|
+
getBaseURL(environment, region) {
|
|
2336
|
+
const regionConfig = REGION_CONFIGS[region];
|
|
2337
|
+
if (!regionConfig) {
|
|
2338
|
+
throw new Error(`Unsupported region: ${region}`);
|
|
2339
|
+
}
|
|
2340
|
+
const envConfig = regionConfig[environment];
|
|
2341
|
+
if (!envConfig) {
|
|
2342
|
+
throw new Error(
|
|
2343
|
+
`Unsupported environment: ${environment} for region: ${region}`
|
|
2344
|
+
);
|
|
2345
|
+
}
|
|
2346
|
+
return `${envConfig.baseURL}/v1`;
|
|
2347
|
+
}
|
|
2348
|
+
async addIndex(tableId, request) {
|
|
2349
|
+
try {
|
|
2350
|
+
const endpoint = INDEX_ENDPOINTS.create;
|
|
2351
|
+
const url = `${this.baseURL}${buildIndexEndpointPath(endpoint, { table_id: tableId })}`;
|
|
2352
|
+
const response = await this.httpAdapter.request({
|
|
2353
|
+
url,
|
|
2354
|
+
method: endpoint.method,
|
|
2355
|
+
headers: this.buildHeaders(),
|
|
2356
|
+
data: request,
|
|
2357
|
+
timeout: this.config.timeout
|
|
2358
|
+
});
|
|
2359
|
+
return response.data;
|
|
2360
|
+
} catch (error) {
|
|
2361
|
+
return this.formatErrorResponse(error);
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
async listIndexes(tableId, query) {
|
|
2365
|
+
try {
|
|
2366
|
+
const endpoint = INDEX_ENDPOINTS.list;
|
|
2367
|
+
const url = `${this.baseURL}${buildIndexEndpointPath(endpoint, { table_id: tableId })}`;
|
|
2368
|
+
const response = await this.httpAdapter.request({
|
|
2369
|
+
url,
|
|
2370
|
+
method: endpoint.method,
|
|
2371
|
+
headers: this.buildHeaders(),
|
|
2372
|
+
data: query,
|
|
2373
|
+
timeout: this.config.timeout
|
|
2374
|
+
});
|
|
2375
|
+
return response.data;
|
|
2376
|
+
} catch (error) {
|
|
2377
|
+
return this.formatErrorResponse(error);
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
async deleteIndex(tableId, request) {
|
|
2381
|
+
try {
|
|
2382
|
+
const endpoint = INDEX_ENDPOINTS.delete;
|
|
2383
|
+
const url = `${this.baseURL}${buildIndexEndpointPath(endpoint, { table_id: tableId })}`;
|
|
2384
|
+
const response = await this.httpAdapter.request({
|
|
2385
|
+
url,
|
|
2386
|
+
method: endpoint.method,
|
|
2387
|
+
headers: this.buildHeaders(),
|
|
2388
|
+
data: request,
|
|
2389
|
+
timeout: this.config.timeout
|
|
2390
|
+
});
|
|
2391
|
+
return response.data;
|
|
2392
|
+
} catch (error) {
|
|
2393
|
+
return this.formatErrorResponse(error);
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
buildHeaders() {
|
|
2397
|
+
return {
|
|
2398
|
+
"Content-Type": "application/json",
|
|
2399
|
+
Accept: "application/json",
|
|
2400
|
+
"x-boltic-token": this.config.apiKey
|
|
2401
|
+
};
|
|
2402
|
+
}
|
|
2403
|
+
formatErrorResponse(error) {
|
|
2404
|
+
if (this.config.debug) {
|
|
2405
|
+
console.error("Indexes API Error:", error);
|
|
2406
|
+
}
|
|
2407
|
+
if (error && typeof error === "object" && "response" in error) {
|
|
2408
|
+
const apiError = error;
|
|
2409
|
+
if (apiError.response?.data?.error) {
|
|
2410
|
+
return apiError.response.data;
|
|
2411
|
+
}
|
|
2412
|
+
return {
|
|
2413
|
+
error: {
|
|
2414
|
+
code: "API_ERROR",
|
|
2415
|
+
message: error.message || "Unknown API error",
|
|
2416
|
+
meta: [`Status: ${apiError.response?.status || "unknown"}`]
|
|
2417
|
+
}
|
|
2418
|
+
};
|
|
2419
|
+
}
|
|
2420
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
2421
|
+
return {
|
|
2422
|
+
error: {
|
|
2423
|
+
code: "CLIENT_ERROR",
|
|
2424
|
+
message: error.message,
|
|
2425
|
+
meta: ["Client-side error occurred"]
|
|
2426
|
+
}
|
|
2427
|
+
};
|
|
2428
|
+
}
|
|
2429
|
+
return {
|
|
2430
|
+
error: {
|
|
2431
|
+
code: "UNKNOWN_ERROR",
|
|
2432
|
+
message: "An unexpected error occurred",
|
|
2433
|
+
meta: ["Unknown error type"]
|
|
2434
|
+
}
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
class IndexResource {
|
|
2439
|
+
constructor(client) {
|
|
2440
|
+
this.client = client;
|
|
2441
|
+
const config = client.getConfig();
|
|
2442
|
+
this.apiClient = new IndexesApiClient(config.apiKey, {
|
|
2443
|
+
environment: config.environment,
|
|
2444
|
+
region: config.region,
|
|
2445
|
+
timeout: config.timeout,
|
|
2446
|
+
debug: config.debug,
|
|
2447
|
+
retryAttempts: config.retryAttempts,
|
|
2448
|
+
retryDelay: config.retryDelay,
|
|
2449
|
+
headers: config.headers
|
|
2450
|
+
});
|
|
2451
|
+
this.tableResource = new TableResource(client);
|
|
2452
|
+
}
|
|
2453
|
+
async resolveTableId(tableName) {
|
|
2454
|
+
const tableResult = await this.tableResource.findByName(tableName);
|
|
2455
|
+
if (!tableResult.data) throw new Error(`Table not found: ${tableName}`);
|
|
2456
|
+
return tableResult.data.id;
|
|
2457
|
+
}
|
|
2458
|
+
async addIndex(tableName, request) {
|
|
2459
|
+
try {
|
|
2460
|
+
const tableId = await this.resolveTableId(tableName);
|
|
2461
|
+
return await this.apiClient.addIndex(tableId, request);
|
|
2462
|
+
} catch (error) {
|
|
2463
|
+
return {
|
|
2464
|
+
error: {
|
|
2465
|
+
code: "CLIENT_ERROR",
|
|
2466
|
+
message: error?.message || "Failed to add index",
|
|
2467
|
+
meta: ["IndexResource.addIndex"]
|
|
2468
|
+
}
|
|
2469
|
+
};
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
async listIndexes(tableName, query) {
|
|
2473
|
+
try {
|
|
2474
|
+
const tableId = await this.resolveTableId(tableName);
|
|
2475
|
+
return await this.apiClient.listIndexes(tableId, query);
|
|
2476
|
+
} catch (error) {
|
|
2477
|
+
return {
|
|
2478
|
+
error: {
|
|
2479
|
+
code: "CLIENT_ERROR",
|
|
2480
|
+
message: error?.message || "Failed to list indexes",
|
|
2481
|
+
meta: ["IndexResource.listIndexes"]
|
|
2482
|
+
}
|
|
2483
|
+
};
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
async deleteIndex(tableName, indexName) {
|
|
2487
|
+
try {
|
|
2488
|
+
const tableId = await this.resolveTableId(tableName);
|
|
2489
|
+
const request = { index_name: indexName };
|
|
2490
|
+
return await this.apiClient.deleteIndex(tableId, request);
|
|
2491
|
+
} catch (error) {
|
|
2492
|
+
return {
|
|
2493
|
+
error: {
|
|
2494
|
+
code: "CLIENT_ERROR",
|
|
2495
|
+
message: error?.message || "Failed to delete index",
|
|
2496
|
+
meta: ["IndexResource.deleteIndex"]
|
|
2497
|
+
}
|
|
2498
|
+
};
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2296
2502
|
const RECORD_ENDPOINTS = {
|
|
2297
2503
|
insert: {
|
|
2298
2504
|
path: "/tables/{table_id}/records",
|
|
@@ -2667,11 +2873,13 @@ class RecordResource {
|
|
|
2667
2873
|
this.client = client;
|
|
2668
2874
|
this.apiClient = new RecordsApiClient(client.getConfig().apiKey, {
|
|
2669
2875
|
environment: client.getConfig().environment,
|
|
2876
|
+
region: client.getConfig().region,
|
|
2670
2877
|
timeout: client.getConfig().timeout,
|
|
2671
2878
|
debug: client.getConfig().debug
|
|
2672
2879
|
});
|
|
2673
2880
|
this.tablesApiClient = new TablesApiClient(client.getConfig().apiKey, {
|
|
2674
2881
|
environment: client.getConfig().environment,
|
|
2882
|
+
region: client.getConfig().region,
|
|
2675
2883
|
timeout: client.getConfig().timeout,
|
|
2676
2884
|
debug: client.getConfig().debug
|
|
2677
2885
|
});
|
|
@@ -3757,6 +3965,7 @@ class BolticClient {
|
|
|
3757
3965
|
this.columnResource = new ColumnResource(this.baseClient);
|
|
3758
3966
|
this.recordResource = new RecordResource(this.baseClient);
|
|
3759
3967
|
this.sqlResource = new SqlResource(this.baseClient);
|
|
3968
|
+
this.indexResource = new IndexResource(this.baseClient);
|
|
3760
3969
|
this.currentDatabase = {
|
|
3761
3970
|
databaseName: "Default"
|
|
3762
3971
|
};
|
|
@@ -3790,6 +3999,14 @@ class BolticClient {
|
|
|
3790
3999
|
delete: (tableName, columnName) => this.columnResource.delete(tableName, columnName)
|
|
3791
4000
|
};
|
|
3792
4001
|
}
|
|
4002
|
+
// Direct index operations
|
|
4003
|
+
get indexes() {
|
|
4004
|
+
return {
|
|
4005
|
+
addIndex: (tableName, payload) => this.indexResource.addIndex(tableName, payload),
|
|
4006
|
+
listIndexes: (tableName, query) => this.indexResource.listIndexes(tableName, query),
|
|
4007
|
+
deleteIndex: (tableName, indexName) => this.indexResource.deleteIndex(tableName, indexName)
|
|
4008
|
+
};
|
|
4009
|
+
}
|
|
3793
4010
|
// Fluent table operations
|
|
3794
4011
|
table(name) {
|
|
3795
4012
|
const tableBuilder = createTableBuilder({ name });
|
|
@@ -3822,6 +4039,12 @@ class BolticClient {
|
|
|
3822
4039
|
record: () => createRecordBuilder({
|
|
3823
4040
|
tableName,
|
|
3824
4041
|
recordResource: this.recordResource
|
|
4042
|
+
}),
|
|
4043
|
+
// Indexes - Method 2: Function chaining under from(tableName)
|
|
4044
|
+
indexes: () => ({
|
|
4045
|
+
addIndex: (payload) => this.indexResource.addIndex(tableName, payload),
|
|
4046
|
+
listIndexes: (query) => this.indexResource.listIndexes(tableName, query),
|
|
4047
|
+
deleteIndex: (indexName) => this.indexResource.deleteIndex(tableName, indexName)
|
|
3825
4048
|
})
|
|
3826
4049
|
};
|
|
3827
4050
|
}
|
|
@@ -3932,6 +4155,7 @@ class BolticClient {
|
|
|
3932
4155
|
this.columnResource = new ColumnResource(this.baseClient);
|
|
3933
4156
|
this.recordResource = new RecordResource(this.baseClient);
|
|
3934
4157
|
this.sqlResource = new SqlResource(this.baseClient);
|
|
4158
|
+
this.indexResource = new IndexResource(this.baseClient);
|
|
3935
4159
|
}
|
|
3936
4160
|
// Security methods to prevent API key exposure
|
|
3937
4161
|
toString() {
|