@boltic/sdk 0.0.4 → 0.0.6

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.
@@ -1692,6 +1692,7 @@ class TableResource extends BaseResource {
1692
1692
  const config = client.getConfig();
1693
1693
  this.tablesApiClient = new TablesApiClient(config.apiKey, {
1694
1694
  environment: config.environment,
1695
+ region: config.region,
1695
1696
  timeout: config.timeout,
1696
1697
  debug: config.debug,
1697
1698
  retryAttempts: config.retryAttempts,
@@ -1986,6 +1987,7 @@ class ColumnResource extends BaseResource {
1986
1987
  const config = client.getConfig();
1987
1988
  this.columnsApiClient = new ColumnsApiClient(config.apiKey, {
1988
1989
  environment: config.environment,
1990
+ region: config.region,
1989
1991
  timeout: config.timeout,
1990
1992
  debug: config.debug,
1991
1993
  retryAttempts: config.retryAttempts,
@@ -1994,6 +1996,7 @@ class ColumnResource extends BaseResource {
1994
1996
  });
1995
1997
  this.tablesApiClient = new TablesApiClient(config.apiKey, {
1996
1998
  environment: config.environment,
1999
+ region: config.region,
1997
2000
  timeout: config.timeout,
1998
2001
  debug: config.debug,
1999
2002
  retryAttempts: config.retryAttempts,
@@ -2352,6 +2355,210 @@ class ColumnResource extends BaseResource {
2352
2355
  return (tableInfo == null ? void 0 : tableInfo.id) || null;
2353
2356
  }
2354
2357
  }
2358
+ const INDEX_ENDPOINTS = {
2359
+ create: {
2360
+ path: "/tables/indexes/{table_id}",
2361
+ method: "POST",
2362
+ authenticated: true
2363
+ },
2364
+ list: {
2365
+ path: "/tables/indexes/{table_id}/list",
2366
+ method: "POST",
2367
+ authenticated: true
2368
+ },
2369
+ delete: {
2370
+ path: "/tables/indexes/{table_id}",
2371
+ method: "DELETE",
2372
+ authenticated: true
2373
+ }
2374
+ };
2375
+ const buildIndexEndpointPath = (endpoint, params = {}) => {
2376
+ let path = endpoint.path;
2377
+ Object.entries(params).forEach(([key, value]) => {
2378
+ path = path.replace(`{${key}}`, encodeURIComponent(value));
2379
+ });
2380
+ const unreplacedParams = path.match(/\{([^}]+)\}/g);
2381
+ if (unreplacedParams) {
2382
+ throw new Error(`Missing path parameters: ${unreplacedParams.join(", ")}`);
2383
+ }
2384
+ return path;
2385
+ };
2386
+ class IndexesApiClient {
2387
+ constructor(apiKey, config = {}) {
2388
+ this.config = { apiKey, ...config };
2389
+ this.httpAdapter = createHttpAdapter();
2390
+ const environment = config.environment || "prod";
2391
+ const region = config.region || "asia-south1";
2392
+ this.baseURL = this.getBaseURL(environment, region);
2393
+ }
2394
+ getBaseURL(environment, region) {
2395
+ const regionConfig = REGION_CONFIGS[region];
2396
+ if (!regionConfig) {
2397
+ throw new Error(`Unsupported region: ${region}`);
2398
+ }
2399
+ const envConfig = regionConfig[environment];
2400
+ if (!envConfig) {
2401
+ throw new Error(
2402
+ `Unsupported environment: ${environment} for region: ${region}`
2403
+ );
2404
+ }
2405
+ return `${envConfig.baseURL}/v1`;
2406
+ }
2407
+ async addIndex(tableId, request) {
2408
+ try {
2409
+ const endpoint = INDEX_ENDPOINTS.create;
2410
+ const url = `${this.baseURL}${buildIndexEndpointPath(endpoint, { table_id: tableId })}`;
2411
+ const response = await this.httpAdapter.request({
2412
+ url,
2413
+ method: endpoint.method,
2414
+ headers: this.buildHeaders(),
2415
+ data: request,
2416
+ timeout: this.config.timeout
2417
+ });
2418
+ return response.data;
2419
+ } catch (error) {
2420
+ return this.formatErrorResponse(error);
2421
+ }
2422
+ }
2423
+ async listIndexes(tableId, query) {
2424
+ try {
2425
+ const endpoint = INDEX_ENDPOINTS.list;
2426
+ const url = `${this.baseURL}${buildIndexEndpointPath(endpoint, { table_id: tableId })}`;
2427
+ const response = await this.httpAdapter.request({
2428
+ url,
2429
+ method: endpoint.method,
2430
+ headers: this.buildHeaders(),
2431
+ data: query,
2432
+ timeout: this.config.timeout
2433
+ });
2434
+ return response.data;
2435
+ } catch (error) {
2436
+ return this.formatErrorResponse(error);
2437
+ }
2438
+ }
2439
+ async deleteIndex(tableId, request) {
2440
+ try {
2441
+ const endpoint = INDEX_ENDPOINTS.delete;
2442
+ const url = `${this.baseURL}${buildIndexEndpointPath(endpoint, { table_id: tableId })}`;
2443
+ const response = await this.httpAdapter.request({
2444
+ url,
2445
+ method: endpoint.method,
2446
+ headers: this.buildHeaders(),
2447
+ data: request,
2448
+ timeout: this.config.timeout
2449
+ });
2450
+ return response.data;
2451
+ } catch (error) {
2452
+ return this.formatErrorResponse(error);
2453
+ }
2454
+ }
2455
+ buildHeaders() {
2456
+ return {
2457
+ "Content-Type": "application/json",
2458
+ Accept: "application/json",
2459
+ "x-boltic-token": this.config.apiKey
2460
+ };
2461
+ }
2462
+ formatErrorResponse(error) {
2463
+ var _a, _b, _c;
2464
+ if (this.config.debug) {
2465
+ console.error("Indexes API Error:", error);
2466
+ }
2467
+ if (error && typeof error === "object" && "response" in error) {
2468
+ const apiError = error;
2469
+ if ((_b = (_a = apiError.response) == null ? void 0 : _a.data) == null ? void 0 : _b.error) {
2470
+ return apiError.response.data;
2471
+ }
2472
+ return {
2473
+ error: {
2474
+ code: "API_ERROR",
2475
+ message: error.message || "Unknown API error",
2476
+ meta: [`Status: ${((_c = apiError.response) == null ? void 0 : _c.status) || "unknown"}`]
2477
+ }
2478
+ };
2479
+ }
2480
+ if (error && typeof error === "object" && "message" in error) {
2481
+ return {
2482
+ error: {
2483
+ code: "CLIENT_ERROR",
2484
+ message: error.message,
2485
+ meta: ["Client-side error occurred"]
2486
+ }
2487
+ };
2488
+ }
2489
+ return {
2490
+ error: {
2491
+ code: "UNKNOWN_ERROR",
2492
+ message: "An unexpected error occurred",
2493
+ meta: ["Unknown error type"]
2494
+ }
2495
+ };
2496
+ }
2497
+ }
2498
+ class IndexResource {
2499
+ constructor(client) {
2500
+ this.client = client;
2501
+ const config = client.getConfig();
2502
+ this.apiClient = new IndexesApiClient(config.apiKey, {
2503
+ environment: config.environment,
2504
+ region: config.region,
2505
+ timeout: config.timeout,
2506
+ debug: config.debug,
2507
+ retryAttempts: config.retryAttempts,
2508
+ retryDelay: config.retryDelay,
2509
+ headers: config.headers
2510
+ });
2511
+ this.tableResource = new TableResource(client);
2512
+ }
2513
+ async resolveTableId(tableName) {
2514
+ const tableResult = await this.tableResource.findByName(tableName);
2515
+ if (!tableResult.data) throw new Error(`Table not found: ${tableName}`);
2516
+ return tableResult.data.id;
2517
+ }
2518
+ async addIndex(tableName, request) {
2519
+ try {
2520
+ const tableId = await this.resolveTableId(tableName);
2521
+ return await this.apiClient.addIndex(tableId, request);
2522
+ } catch (error) {
2523
+ return {
2524
+ error: {
2525
+ code: "CLIENT_ERROR",
2526
+ message: (error == null ? void 0 : error.message) || "Failed to add index",
2527
+ meta: ["IndexResource.addIndex"]
2528
+ }
2529
+ };
2530
+ }
2531
+ }
2532
+ async listIndexes(tableName, query) {
2533
+ try {
2534
+ const tableId = await this.resolveTableId(tableName);
2535
+ return await this.apiClient.listIndexes(tableId, query);
2536
+ } catch (error) {
2537
+ return {
2538
+ error: {
2539
+ code: "CLIENT_ERROR",
2540
+ message: (error == null ? void 0 : error.message) || "Failed to list indexes",
2541
+ meta: ["IndexResource.listIndexes"]
2542
+ }
2543
+ };
2544
+ }
2545
+ }
2546
+ async deleteIndex(tableName, indexName) {
2547
+ try {
2548
+ const tableId = await this.resolveTableId(tableName);
2549
+ const request = { index_name: indexName };
2550
+ return await this.apiClient.deleteIndex(tableId, request);
2551
+ } catch (error) {
2552
+ return {
2553
+ error: {
2554
+ code: "CLIENT_ERROR",
2555
+ message: (error == null ? void 0 : error.message) || "Failed to delete index",
2556
+ meta: ["IndexResource.deleteIndex"]
2557
+ }
2558
+ };
2559
+ }
2560
+ }
2561
+ }
2355
2562
  const RECORD_ENDPOINTS = {
2356
2563
  insert: {
2357
2564
  path: "/tables/{table_id}/records",
@@ -2727,11 +2934,13 @@ class RecordResource {
2727
2934
  this.client = client;
2728
2935
  this.apiClient = new RecordsApiClient(client.getConfig().apiKey, {
2729
2936
  environment: client.getConfig().environment,
2937
+ region: client.getConfig().region,
2730
2938
  timeout: client.getConfig().timeout,
2731
2939
  debug: client.getConfig().debug
2732
2940
  });
2733
2941
  this.tablesApiClient = new TablesApiClient(client.getConfig().apiKey, {
2734
2942
  environment: client.getConfig().environment,
2943
+ region: client.getConfig().region,
2735
2944
  timeout: client.getConfig().timeout,
2736
2945
  debug: client.getConfig().debug
2737
2946
  });
@@ -3818,6 +4027,7 @@ class BolticClient {
3818
4027
  this.columnResource = new ColumnResource(this.baseClient);
3819
4028
  this.recordResource = new RecordResource(this.baseClient);
3820
4029
  this.sqlResource = new SqlResource(this.baseClient);
4030
+ this.indexResource = new IndexResource(this.baseClient);
3821
4031
  this.currentDatabase = {
3822
4032
  databaseName: "Default"
3823
4033
  };
@@ -3851,6 +4061,14 @@ class BolticClient {
3851
4061
  delete: (tableName, columnName) => this.columnResource.delete(tableName, columnName)
3852
4062
  };
3853
4063
  }
4064
+ // Direct index operations
4065
+ get indexes() {
4066
+ return {
4067
+ addIndex: (tableName, payload) => this.indexResource.addIndex(tableName, payload),
4068
+ listIndexes: (tableName, query) => this.indexResource.listIndexes(tableName, query),
4069
+ deleteIndex: (tableName, indexName) => this.indexResource.deleteIndex(tableName, indexName)
4070
+ };
4071
+ }
3854
4072
  // Fluent table operations
3855
4073
  table(name) {
3856
4074
  const tableBuilder = createTableBuilder({ name });
@@ -3883,6 +4101,12 @@ class BolticClient {
3883
4101
  record: () => createRecordBuilder({
3884
4102
  tableName,
3885
4103
  recordResource: this.recordResource
4104
+ }),
4105
+ // Indexes - Method 2: Function chaining under from(tableName)
4106
+ indexes: () => ({
4107
+ addIndex: (payload) => this.indexResource.addIndex(tableName, payload),
4108
+ listIndexes: (query) => this.indexResource.listIndexes(tableName, query),
4109
+ deleteIndex: (indexName) => this.indexResource.deleteIndex(tableName, indexName)
3886
4110
  })
3887
4111
  };
3888
4112
  }
@@ -3993,6 +4217,7 @@ class BolticClient {
3993
4217
  this.columnResource = new ColumnResource(this.baseClient);
3994
4218
  this.recordResource = new RecordResource(this.baseClient);
3995
4219
  this.sqlResource = new SqlResource(this.baseClient);
4220
+ this.indexResource = new IndexResource(this.baseClient);
3996
4221
  }
3997
4222
  // Security methods to prevent API key exposure
3998
4223
  toString() {
@@ -4044,9 +4269,9 @@ export {
4044
4269
  SqlResource as S,
4045
4270
  ValidationError as V,
4046
4271
  isListResponse as a,
4047
- buildApiFilters as b,
4048
- createFilter as c,
4049
- FilterBuilder as d,
4272
+ FilterBuilder as b,
4273
+ buildApiFilters as c,
4274
+ createFilter as d,
4050
4275
  mapWhereToFilters as e,
4051
4276
  createRecordBuilder as f,
4052
4277
  createTableBuilder as g,
@@ -4061,4 +4286,4 @@ export {
4061
4286
  createMockResponse as p,
4062
4287
  createTestClient as q
4063
4288
  };
4064
- //# sourceMappingURL=test-client-BffJwqJq.mjs.map
4289
+ //# sourceMappingURL=test-client-rQ1AmTo6.mjs.map