@onchaindb/sdk 1.0.0 → 2.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.
Files changed (45) hide show
  1. package/dist/client.d.ts +3 -4
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +61 -71
  4. package/dist/client.js.map +1 -1
  5. package/dist/index.d.ts +6 -6
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +4 -4
  8. package/dist/index.js.map +1 -1
  9. package/dist/query-sdk/OnDB.d.ts +27 -0
  10. package/dist/query-sdk/OnDB.d.ts.map +1 -0
  11. package/dist/query-sdk/OnDB.js +191 -0
  12. package/dist/query-sdk/OnDB.js.map +1 -0
  13. package/dist/query-sdk/index.d.ts +1 -1
  14. package/dist/query-sdk/index.d.ts.map +1 -1
  15. package/dist/query-sdk/index.js +3 -3
  16. package/dist/query-sdk/index.js.map +1 -1
  17. package/dist/types.d.ts +6 -35
  18. package/dist/types.d.ts.map +1 -1
  19. package/dist/types.js +8 -8
  20. package/dist/types.js.map +1 -1
  21. package/dist/x402/types.d.ts +1 -1
  22. package/dist/x402/types.d.ts.map +1 -1
  23. package/dist/x402/utils.js +2 -2
  24. package/dist/x402/utils.js.map +1 -1
  25. package/package.json +1 -1
  26. package/src/batch.d.ts +3 -3
  27. package/src/batch.js +1 -1
  28. package/src/client.ts +73 -106
  29. package/src/database.d.ts +1 -1
  30. package/src/database.js +4 -4
  31. package/src/database.ts +2 -2
  32. package/src/index.d.ts +18 -18
  33. package/src/index.js +16 -16
  34. package/src/index.ts +7 -8
  35. package/src/query-sdk/{OnChainDB.ts → OnDB.ts} +1 -1
  36. package/src/query-sdk/README.md +8 -8
  37. package/src/query-sdk/index.ts +1 -1
  38. package/src/tests/client-requests.test.ts +3 -3
  39. package/src/tests/client-validation.test.ts +5 -5
  40. package/src/types.d.ts +6 -6
  41. package/src/types.js +8 -8
  42. package/src/types.ts +10 -46
  43. package/src/x402/types.ts +3 -3
  44. package/src/x402/utils.ts +3 -3
  45. package/examples/blob-upload-example.ts +0 -140
package/src/client.ts CHANGED
@@ -4,10 +4,9 @@ import {
4
4
  CreateCollectionResult,
5
5
  IndexRequest,
6
6
  IndexResponse,
7
- OnChainDBConfig,
8
- OnChainDBError,
7
+ OnDBConfig,
8
+ OnDBError,
9
9
  PricingQuoteRequest,
10
- PricingQuoteResponse,
11
10
  RelationRequest,
12
11
  RelationResponse,
13
12
  RetrieveBlobRequest,
@@ -58,22 +57,22 @@ import {
58
57
  } from './x402';
59
58
 
60
59
  /**
61
- * OnChainDB TypeScript SDK
60
+ * OnDB TypeScript SDK
62
61
  *
63
- * Provides a complete interface for storing and querying data on OnChainDB,
62
+ * Provides a complete interface for storing and querying data on OnDB,
64
63
  * built on Celestia blockchain with automatic transaction management.
65
64
  *
66
65
  * @example
67
66
  * ```typescript
68
67
  * // Initialize with app key (for writes)
69
- * const db = new OnChainDBClient({
68
+ * const db = new OnDBClient({
70
69
  * endpoint: 'http://localhost:9092',
71
70
  * appId: 'app_abc123',
72
71
  * appKey: 'app_xxx...', // Required for write operations (X-App-Key header)
73
72
  * });
74
73
  *
75
74
  * // Agent Key: autonomous agent that pays other apps inline via USDC (EIP-3009)
76
- * const agent = new OnChainDBClient({
75
+ * const agent = new OnDBClient({
77
76
  * endpoint: 'http://localhost:9092',
78
77
  * appId: 'app_abc123',
79
78
  * agentKey: 'agent_zzz...', // X-Agent-Key header — key must have Pay permission
@@ -81,7 +80,7 @@ import {
81
80
  *
82
81
  * // Store data (requires appKey)
83
82
  * const result = await db.store({
84
- * data: [{ message: 'Hello OnChainDB!', user: 'alice' }],
83
+ * data: [{ message: 'Hello OnDB!', user: 'alice' }],
85
84
  * collection: 'messages'
86
85
  * });
87
86
  *
@@ -89,13 +88,13 @@ import {
89
88
  * const messages = await db.query({ collection: 'messages' });
90
89
  *
91
90
  * // Backwards compatible: legacy apiKey maps to appKey
92
- * const legacyDb = new OnChainDBClient({
91
+ * const legacyDb = new OnDBClient({
93
92
  * endpoint: 'http://localhost:9092',
94
93
  * apiKey: 'app_xxx...' // Still works, maps to appKey
95
94
  * });
96
95
  * ```
97
96
  */
98
- export class OnChainDBClient extends EventEmitter<TransactionEvents> {
97
+ export class OnDBClient extends EventEmitter<TransactionEvents> {
99
98
  /**
100
99
  * Base fields that are automatically indexed when useBaseFields is true
101
100
  */
@@ -106,10 +105,10 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
106
105
  deletedAt: {type: 'date', index: true}
107
106
  };
108
107
  private http: AxiosInstance;
109
- private config: Required<Omit<OnChainDBConfig, 'appId'>> & { appId?: string; appKey?: string; userKey?: string; agentKey?: string };
108
+ private config: Required<Omit<OnDBConfig, 'appId'>> & { appId?: string; appKey?: string; userKey?: string; agentKey?: string };
110
109
  private _database?: DatabaseManager;
111
110
 
112
- constructor(config: OnChainDBConfig) {
111
+ constructor(config: OnDBConfig) {
113
112
  super();
114
113
 
115
114
  // Support legacy apiKey for backwards compatibility (maps to appKey)
@@ -227,7 +226,7 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
227
226
  try {
228
227
  x402Response = parseX402Response(response.data);
229
228
  } catch (e) {
230
- throw new OnChainDBError(
229
+ throw new OnDBError(
231
230
  `Invalid x402 response: ${e instanceof Error ? e.message : String(e)}`,
232
231
  'PAYMENT_ERROR',
233
232
  402
@@ -251,7 +250,7 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
251
250
 
252
251
  // Call payment callback if provided
253
252
  if (!paymentCallback) {
254
- throw new OnChainDBError(
253
+ throw new OnDBError(
255
254
  'Payment required but no payment callback provided. Please provide a payment callback to handle x402.',
256
255
  'PAYMENT_REQUIRED',
257
256
  402,
@@ -275,7 +274,7 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
275
274
  );
276
275
 
277
276
  if (!selectedRequirement) {
278
- throw new OnChainDBError(
277
+ throw new OnDBError(
279
278
  `Payment callback returned network '${facilitatorPayment.network}' but no matching payment option found`,
280
279
  'PAYMENT_ERROR'
281
280
  );
@@ -295,7 +294,7 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
295
294
  transaction: facilitatorPayment.solanaAuthorization.transaction,
296
295
  });
297
296
  } else {
298
- throw new OnChainDBError(
297
+ throw new OnDBError(
299
298
  'Facilitator payment missing authorization data',
300
299
  'PAYMENT_ERROR'
301
300
  );
@@ -330,11 +329,11 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
330
329
  }
331
330
  }
332
331
 
333
- throw new OnChainDBError('No ticket_id in response after payment', 'STORE_ERROR');
332
+ throw new OnDBError('No ticket_id in response after payment', 'STORE_ERROR');
334
333
  }
335
334
 
336
335
  /**
337
- * Store data on OnChainDB using the new root-based API with broker payment
336
+ * Store data on OnDB using the new root-based API with broker payment
338
337
  *
339
338
  * @param request - Store request with root (app::collection) and data array
340
339
  * @param paymentOptions - Payment configuration for broker fees
@@ -405,7 +404,7 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
405
404
  });
406
405
  return result;
407
406
  } else {
408
- throw new OnChainDBError('Task completed but no storage results found', 'STORE_ERROR');
407
+ throw new OnDBError('Task completed but no storage results found', 'STORE_ERROR');
409
408
  }
410
409
  } else {
411
410
  return { id: serverResult.ticket_id, block_height: 0, transaction_hash: '', celestia_height: 0, namespace: '', confirmed: false, ticket_id: serverResult.ticket_id } as StoreResponse;
@@ -415,7 +414,7 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
415
414
  // Legacy response format (if server returns old format)
416
415
  const firstResult = serverResult.results?.[0];
417
416
  if (!firstResult) {
418
- throw new OnChainDBError('No results returned from server', 'STORE_ERROR');
417
+ throw new OnDBError('No results returned from server', 'STORE_ERROR');
419
418
  }
420
419
 
421
420
  const result = this.buildStoreResult(firstResult);
@@ -450,12 +449,12 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
450
449
  }
451
450
  }
452
451
 
453
- throw new OnChainDBError(JSON.stringify(err.response?.data), 'STORE_ERROR');
452
+ throw new OnDBError(JSON.stringify(err.response?.data), 'STORE_ERROR');
454
453
  }
455
454
 
456
455
  console.error(error)
457
- const dbError = error instanceof OnChainDBError ? error :
458
- new OnChainDBError(error.message, 'STORE_ERROR');
456
+ const dbError = error instanceof OnDBError ? error :
457
+ new OnDBError(error.message, 'STORE_ERROR');
459
458
  this.emit('error', dbError);
460
459
  throw dbError;
461
460
  }
@@ -475,8 +474,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
475
474
  const response = await this.http.post<IndexResponse>(`/api/apps/${appId}/indexes`, request);
476
475
  return response.data;
477
476
  } catch (error) {
478
- throw error instanceof OnChainDBError ? error :
479
- new OnChainDBError('Failed to create index', 'INDEX_ERROR');
477
+ throw error instanceof OnDBError ? error :
478
+ new OnDBError('Failed to create index', 'INDEX_ERROR');
480
479
  }
481
480
  }
482
481
 
@@ -524,7 +523,7 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
524
523
  const allFields: Record<string, SimpleFieldDefinition> = {};
525
524
 
526
525
  if (schema.useBaseFields !== false) {
527
- Object.assign(allFields, OnChainDBClient.BASE_FIELDS);
526
+ Object.assign(allFields, OnDBClient.BASE_FIELDS);
528
527
  }
529
528
 
530
529
  Object.assign(allFields, schema.fields);
@@ -642,7 +641,7 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
642
641
  // Merge base fields if enabled (default: true)
643
642
  const allFields: Record<string, SimpleFieldDefinition> = {};
644
643
  if (schema.useBaseFields !== false) {
645
- Object.assign(allFields, OnChainDBClient.BASE_FIELDS);
644
+ Object.assign(allFields, OnDBClient.BASE_FIELDS);
646
645
  }
647
646
  Object.assign(allFields, schema.fields);
648
647
 
@@ -721,8 +720,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
721
720
  sharding
722
721
  );
723
722
  } catch (error) {
724
- throw error instanceof OnChainDBError ? error :
725
- new OnChainDBError('Failed to setup sharding', 'SHARDING_ERROR');
723
+ throw error instanceof OnDBError ? error :
724
+ new OnDBError('Failed to setup sharding', 'SHARDING_ERROR');
726
725
  }
727
726
  }
728
727
 
@@ -733,8 +732,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
733
732
  const response = await this.http.delete(`/api/apps/${appId}/collections/${collection}`);
734
733
  return response.data;
735
734
  } catch (error) {
736
- throw error instanceof OnChainDBError ? error :
737
- new OnChainDBError('Failed to delete collection', 'COLLECTION_ERROR');
735
+ throw error instanceof OnDBError ? error :
736
+ new OnDBError('Failed to delete collection', 'COLLECTION_ERROR');
738
737
  }
739
738
  }
740
739
 
@@ -745,8 +744,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
745
744
  const response = await this.http.patch(`/api/apps/${appId}/collections/${collection}`, updates);
746
745
  return response.data;
747
746
  } catch (error) {
748
- throw error instanceof OnChainDBError ? error :
749
- new OnChainDBError('Failed to update collection', 'COLLECTION_ERROR');
747
+ throw error instanceof OnDBError ? error :
748
+ new OnDBError('Failed to update collection', 'COLLECTION_ERROR');
750
749
  }
751
750
  }
752
751
 
@@ -757,8 +756,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
757
756
  const response = await this.http.get(`/api/apps/${appId}/collections/${collection}/retention`);
758
757
  return response.data;
759
758
  } catch (error) {
760
- throw error instanceof OnChainDBError ? error :
761
- new OnChainDBError('Failed to get retention config', 'RETENTION_ERROR');
759
+ throw error instanceof OnDBError ? error :
760
+ new OnDBError('Failed to get retention config', 'RETENTION_ERROR');
762
761
  }
763
762
  }
764
763
 
@@ -769,8 +768,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
769
768
  const response = await this.http.post(`/api/apps/${appId}/collections/${collection}/retention`, request);
770
769
  return response.data;
771
770
  } catch (error) {
772
- throw error instanceof OnChainDBError ? error :
773
- new OnChainDBError('Failed to set retention config', 'RETENTION_ERROR');
771
+ throw error instanceof OnDBError ? error :
772
+ new OnDBError('Failed to set retention config', 'RETENTION_ERROR');
774
773
  }
775
774
  }
776
775
 
@@ -781,8 +780,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
781
780
  const response = await this.http.get(`/api/apps/${appId}/retention/cost`);
782
781
  return response.data;
783
782
  } catch (error) {
784
- throw error instanceof OnChainDBError ? error :
785
- new OnChainDBError('Failed to get retention cost', 'RETENTION_ERROR');
783
+ throw error instanceof OnDBError ? error :
784
+ new OnDBError('Failed to get retention cost', 'RETENTION_ERROR');
786
785
  }
787
786
  }
788
787
 
@@ -793,8 +792,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
793
792
  const response = await this.http.post('/query/sql', body);
794
793
  return response.data;
795
794
  } catch (error) {
796
- throw error instanceof OnChainDBError ? error :
797
- new OnChainDBError('SQL query failed', 'SQL_ERROR');
795
+ throw error instanceof OnDBError ? error :
796
+ new OnDBError('SQL query failed', 'SQL_ERROR');
798
797
  }
799
798
  }
800
799
 
@@ -804,8 +803,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
804
803
  const response = await this.http.post('/insert/sql', body);
805
804
  return response.data;
806
805
  } catch (error) {
807
- throw error instanceof OnChainDBError ? error :
808
- new OnChainDBError('SQL insert failed', 'SQL_ERROR');
806
+ throw error instanceof OnDBError ? error :
807
+ new OnDBError('SQL insert failed', 'SQL_ERROR');
809
808
  }
810
809
  }
811
810
 
@@ -816,8 +815,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
816
815
  const response = await this.http.get(`/apps/${appId}/queries`);
817
816
  return response.data.queries ?? response.data;
818
817
  } catch (error) {
819
- throw error instanceof OnChainDBError ? error :
820
- new OnChainDBError('Failed to list predefined queries', 'QUERY_ERROR');
818
+ throw error instanceof OnDBError ? error :
819
+ new OnDBError('Failed to list predefined queries', 'QUERY_ERROR');
821
820
  }
822
821
  }
823
822
 
@@ -828,8 +827,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
828
827
  const response = await this.http.post(`/apps/${appId}/queries`, request);
829
828
  return response.data;
830
829
  } catch (error) {
831
- throw error instanceof OnChainDBError ? error :
832
- new OnChainDBError('Failed to create predefined query', 'QUERY_ERROR');
830
+ throw error instanceof OnDBError ? error :
831
+ new OnDBError('Failed to create predefined query', 'QUERY_ERROR');
833
832
  }
834
833
  }
835
834
 
@@ -840,8 +839,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
840
839
  const response = await this.http.get(`/apps/${appId}/queries/${name}`);
841
840
  return response.data;
842
841
  } catch (error) {
843
- throw error instanceof OnChainDBError ? error :
844
- new OnChainDBError('Failed to get predefined query', 'QUERY_ERROR');
842
+ throw error instanceof OnDBError ? error :
843
+ new OnDBError('Failed to get predefined query', 'QUERY_ERROR');
845
844
  }
846
845
  }
847
846
 
@@ -852,8 +851,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
852
851
  const response = await this.http.delete(`/apps/${appId}/queries/${name}`);
853
852
  return response.data;
854
853
  } catch (error) {
855
- throw error instanceof OnChainDBError ? error :
856
- new OnChainDBError('Failed to delete predefined query', 'QUERY_ERROR');
854
+ throw error instanceof OnDBError ? error :
855
+ new OnDBError('Failed to delete predefined query', 'QUERY_ERROR');
857
856
  }
858
857
  }
859
858
 
@@ -866,8 +865,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
866
865
  const response = await this.http.get(`/api/queries/${appId}/${name}/data`, { params: queryParams });
867
866
  return response.data;
868
867
  } catch (error) {
869
- throw error instanceof OnChainDBError ? error :
870
- new OnChainDBError('Failed to execute predefined query', 'QUERY_ERROR');
868
+ throw error instanceof OnDBError ? error :
869
+ new OnDBError('Failed to execute predefined query', 'QUERY_ERROR');
871
870
  }
872
871
  }
873
872
 
@@ -887,8 +886,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
887
886
  const response = await this.http.get(`/api/apps/${appId}/collections/${collectionId}`);
888
887
  return response.data;
889
888
  } catch (error) {
890
- throw error instanceof OnChainDBError ? error :
891
- new OnChainDBError('Failed to get collection info', 'COLLECTION_ERROR');
889
+ throw error instanceof OnDBError ? error :
890
+ new OnDBError('Failed to get collection info', 'COLLECTION_ERROR');
892
891
  }
893
892
  }
894
893
 
@@ -933,13 +932,13 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
933
932
  const response = await this.http.post<RelationResponse>(`/api/apps/${appId}/relations`, request);
934
933
  return response.data;
935
934
  } catch (error) {
936
- throw error instanceof OnChainDBError ? error :
937
- new OnChainDBError('Failed to create relation', 'RELATION_ERROR');
935
+ throw error instanceof OnDBError ? error :
936
+ new OnDBError('Failed to create relation', 'RELATION_ERROR');
938
937
  }
939
938
  }
940
939
 
941
940
  /**
942
- * Get health status of OnChainDB service
941
+ * Get health status of OnDB service
943
942
  *
944
943
  * @returns Health check response
945
944
  */
@@ -948,42 +947,10 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
948
947
  const response = await this.http.get('/');
949
948
  return response.data;
950
949
  } catch (error) {
951
- throw new OnChainDBError('Health check failed', 'HEALTH_ERROR');
950
+ throw new OnDBError('Health check failed', 'HEALTH_ERROR');
952
951
  }
953
952
  }
954
953
 
955
- /**
956
- * Get pricing quote for an operation before executing it
957
- *
958
- * Use this to estimate costs before committing to a store operation,
959
- * especially useful for large files or high-volume scenarios.
960
- *
961
- * @param request - Pricing quote request with app_id, operation type, size, and collection
962
- * @returns Pricing quote with detailed cost breakdown
963
- *
964
- * @example
965
- * ```typescript
966
- * const quote = await db.getPricingQuote({
967
- * app_id: 'my_app',
968
- * operation_type: 'write',
969
- * size_kb: 50,
970
- * collection: 'users',
971
- * monthly_volume_kb: 1000
972
- * });
973
- *
974
- * console.log(`Total cost: ${quote.total_cost_utia} utia`);
975
- * console.log(`Indexing costs:`, quote.indexing_costs_utia);
976
- * ```
977
- */
978
- async getPricingQuote(request: PricingQuoteRequest): Promise<PricingQuoteResponse> {
979
- try {
980
- const response = await this.http.post('/api/pricing/quote', request);
981
- return response.data;
982
- } catch (error) {
983
- throw error instanceof OnChainDBError ? error :
984
- new OnChainDBError('Failed to get pricing quote', 'PRICING_QUOTE_ERROR');
985
- }
986
- }
987
954
 
988
955
  /**
989
956
  * Create a fluent query builder instance
@@ -1023,8 +990,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
1023
990
  const response = await this.http.get(`/task/${ticketId}`);
1024
991
  return response.data;
1025
992
  } catch (error) {
1026
- throw error instanceof OnChainDBError ? error :
1027
- new OnChainDBError('Failed to get task status', 'TASK_STATUS_ERROR');
993
+ throw error instanceof OnDBError ? error :
994
+ new OnDBError('Failed to get task status', 'TASK_STATUS_ERROR');
1028
995
  }
1029
996
  }
1030
997
 
@@ -1061,13 +1028,13 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
1061
1028
  if (typeof taskInfo.status === 'object' && 'Failed' in taskInfo.status) {
1062
1029
  const error = (taskInfo.status as { Failed: { error: string } }).Failed.error;
1063
1030
  console.error(`🚫 Task ${ticketId} failed: ${error}`);
1064
- throw new OnChainDBError(`Task failed: ${error}`, 'TASK_FAILED');
1031
+ throw new OnDBError(`Task failed: ${error}`, 'TASK_FAILED');
1065
1032
  }
1066
1033
 
1067
1034
  // Check for any other error-like statuses
1068
1035
  if (typeof taskInfo.status === 'string' && taskInfo.status.toLowerCase().includes('error')) {
1069
1036
  console.error(`🚫 Task ${ticketId} has error status: ${taskInfo.status}`);
1070
- throw new OnChainDBError(`Task error: ${taskInfo.status}`, 'TASK_FAILED');
1037
+ throw new OnDBError(`Task error: ${taskInfo.status}`, 'TASK_FAILED');
1071
1038
  }
1072
1039
 
1073
1040
  // Task still in progress, wait and check again
@@ -1077,8 +1044,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
1077
1044
  console.error(`❌ Error polling task ${ticketId}:`, error);
1078
1045
 
1079
1046
  // Check if this is a permanent error (like 404, 400, etc.) that shouldn't be retried
1080
- if (error instanceof OnChainDBError) {
1081
- // OnChainDB errors with specific codes should stop polling
1047
+ if (error instanceof OnDBError) {
1048
+ // OnDB errors with specific codes should stop polling
1082
1049
  if (error.code === 'TASK_FAILED' || error.statusCode === 404 || error.statusCode === 400) {
1083
1050
  console.error(`🚫 Stopping polling due to permanent error: ${error.message}`);
1084
1051
  throw error;
@@ -1087,7 +1054,7 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
1087
1054
 
1088
1055
  // For network/temporary errors, check if we've exceeded max wait time
1089
1056
  if (Date.now() - startTime >= maxWaitTime) {
1090
- throw new OnChainDBError(
1057
+ throw new OnDBError(
1091
1058
  `Task completion timeout after ${maxWaitTime}ms. Last error: ${error instanceof Error ? error.message : String(error)}`,
1092
1059
  'TASK_TIMEOUT'
1093
1060
  );
@@ -1099,14 +1066,14 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
1099
1066
  }
1100
1067
  }
1101
1068
 
1102
- throw new OnChainDBError(
1069
+ throw new OnDBError(
1103
1070
  `Task completion timeout after ${maxWaitTime}ms`,
1104
1071
  'TASK_TIMEOUT'
1105
1072
  );
1106
1073
  }
1107
1074
 
1108
1075
  /**
1109
- * Upload a blob (binary file) to OnChainDB with optional custom metadata fields
1076
+ * Upload a blob (binary file) to OnDB with optional custom metadata fields
1110
1077
  *
1111
1078
  * Supports images, videos, documents, and any binary data up to 2MB.
1112
1079
  * Automatically handles multipart/form-data upload and returns a ticket for tracking.
@@ -1183,7 +1150,7 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
1183
1150
  const quote = requirementToQuote(requirement, x402Response.accepts);
1184
1151
 
1185
1152
  if (!paymentCallback) {
1186
- throw new OnChainDBError(
1153
+ throw new OnDBError(
1187
1154
  'Payment required but no payment callback provided',
1188
1155
  'PAYMENT_REQUIRED',
1189
1156
  402,
@@ -1205,13 +1172,13 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
1205
1172
  throw error;
1206
1173
  }
1207
1174
  } catch (error) {
1208
- throw error instanceof OnChainDBError ? error :
1209
- new OnChainDBError('Failed to upload blob', 'BLOB_UPLOAD_ERROR');
1175
+ throw error instanceof OnDBError ? error :
1176
+ new OnDBError('Failed to upload blob', 'BLOB_UPLOAD_ERROR');
1210
1177
  }
1211
1178
  }
1212
1179
 
1213
1180
  /**
1214
- * Retrieve a blob (binary file) from OnChainDB by blob_id
1181
+ * Retrieve a blob (binary file) from OnDB by blob_id
1215
1182
  *
1216
1183
  * Returns the raw blob data with proper Content-Type headers.
1217
1184
  * Can be used to serve images, videos, documents, etc.
@@ -1263,8 +1230,8 @@ export class OnChainDBClient extends EventEmitter<TransactionEvents> {
1263
1230
  return Buffer.from(response.data);
1264
1231
  }
1265
1232
  } catch (error) {
1266
- throw error instanceof OnChainDBError ? error :
1267
- new OnChainDBError('Failed to retrieve blob', 'BLOB_RETRIEVAL_ERROR');
1233
+ throw error instanceof OnDBError ? error :
1234
+ new OnDBError('Failed to retrieve blob', 'BLOB_RETRIEVAL_ERROR');
1268
1235
  }
1269
1236
  }
1270
1237
 
package/src/database.d.ts CHANGED
@@ -107,7 +107,7 @@ export interface BatchResult {
107
107
  error?: string;
108
108
  }
109
109
  /**
110
- * Comprehensive database management client for OnChainDB
110
+ * Comprehensive database management client for OnDB
111
111
  *
112
112
  * Provides full CRUD operations for collections, indexes, and schemas
113
113
  * with advanced features like query planning, batch operations, and statistics
package/src/database.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
- // Database Management Client for OnChainDB SDK
2
+ // Database Management Client for OnDB SDK
3
3
  // Provides comprehensive collection and index management capabilities
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.DatabaseManager = void 0;
6
6
  exports.createDatabaseManager = createDatabaseManager;
7
7
  const types_1 = require("./types");
8
8
  /**
9
- * Comprehensive database management client for OnChainDB
9
+ * Comprehensive database management client for OnDB
10
10
  *
11
11
  * Provides full CRUD operations for collections, indexes, and schemas
12
12
  * with advanced features like query planning, batch operations, and statistics
@@ -96,9 +96,9 @@ class DatabaseManager {
96
96
  console.log(`📊 Index cost: ${costInUtia} utia`);
97
97
  // Request payment
98
98
  console.log('💳 Requesting user payment via Keplr...');
99
- const paymentResult = await paymentOptions.userWallet.signAndBroadcast(paymentOptions.brokerAddress, `${costInUtia}utia`, `OnChainDB index creation - ${indexDefinition.field_name}`);
99
+ const paymentResult = await paymentOptions.userWallet.signAndBroadcast(paymentOptions.brokerAddress, `${costInUtia}utia`, `OnDB index creation - ${indexDefinition.field_name}`);
100
100
  if (!paymentResult.success) {
101
- throw new types_1.OnChainDBError(`Payment failed: ${paymentResult.error}`, 'PAYMENT_ERROR');
101
+ throw new types_1.OnDBError(`Payment failed: ${paymentResult.error}`, 'PAYMENT_ERROR');
102
102
  }
103
103
  console.log(`✅ Payment successful: ${paymentResult.txHash}`);
104
104
  // Add payment proof
package/src/database.ts CHANGED
@@ -1,8 +1,8 @@
1
- // Database Management Client for OnChainDB SDK
1
+ // Database Management Client for OnDB SDK
2
2
 
3
3
  import { AxiosInstance } from 'axios';
4
4
  import {
5
- OnChainDBError,
5
+ OnDBError,
6
6
  SqlCreateViewRequest,
7
7
  ViewDataResponse,
8
8
  ViewQueryRequest,
package/src/index.d.ts CHANGED
@@ -1,21 +1,21 @@
1
- export { OnChainDBClient } from './client';
1
+ export { OnDBClient } from './client';
2
2
  export { BatchOperations, BulkBuilder } from './batch';
3
3
  export { QueryBuilder, SelectionBuilder, FieldConditionBuilder, LogicalOperator } from './query-sdk';
4
4
  export { DatabaseManager, createDatabaseManager } from './database';
5
- export type { OnChainDBConfig, StoreRequest, StoreResponse, TransactionStatus, QueryRequest, QueryResponse, TransactionEvents, IndexRequest, IndexResponse, AdvancedQueryRequest, IndexPaymentProof, IndexCostEstimate, StorageCostEstimate } from './types';
5
+ export type { OnDBConfig, StoreRequest, StoreResponse, TransactionStatus, QueryRequest, QueryResponse, TransactionEvents, IndexRequest, IndexResponse, AdvancedQueryRequest, IndexPaymentProof, IndexCostEstimate, StorageCostEstimate } from './types';
6
6
  export type { SelectionMap, QueryRequest as RawQuery, QueryResponse as OnChainQueryResponse, QueryValue, Val } from './query-sdk';
7
7
  export type { Condition } from './query-sdk';
8
8
  export type { Collection, CollectionSchema, FieldDefinition, FieldValidation, Relationship, Index, IndexOptions, IndexStatus, IndexStatistics, CollectionMetadata, DatabaseStats, QueryPlan, BatchOperation, BatchResult } from './database';
9
- export { OnChainDBError, TransactionError, ValidationError, PaymentRequiredError, PaymentVerificationError } from './types';
10
- import { OnChainDBConfig } from './types';
11
- import { OnChainDBClient } from './client';
12
- export declare function createClient(config: OnChainDBConfig): OnChainDBClient;
9
+ export { OnDBError, TransactionError, ValidationError, PaymentRequiredError, PaymentVerificationError } from './types';
10
+ import { OnDBConfig } from './types';
11
+ import { OnDBClient } from './client';
12
+ export declare function createClient(config: OnDBConfig): OnDBClient;
13
13
  export { AxiosHttpClient, FetchHttpClient, NodeHttpClient, createHttpClient } from './query-sdk';
14
14
  export declare const VERSION = "1.0.0";
15
15
  /**
16
- * OnChainDB TypeScript SDK
16
+ * OnDB TypeScript SDK
17
17
  *
18
- * A complete TypeScript SDK for OnChainDB - the decentralized database
18
+ * A complete TypeScript SDK for OnDB - the decentralized database
19
19
  * built on Celestia blockchain.
20
20
  *
21
21
  * Features:
@@ -32,7 +32,7 @@ export declare const VERSION = "1.0.0";
32
32
  *
33
33
  * @example Basic Usage
34
34
  * ```typescript
35
- * import { createClient } from '@onchaindb/sdk';
35
+ * import { createClient } from '@ondb/sdk';
36
36
  *
37
37
  * const db = createClient({
38
38
  * endpoint: 'http://localhost:9092',
@@ -41,7 +41,7 @@ export declare const VERSION = "1.0.0";
41
41
  *
42
42
  * // Store data
43
43
  * const result = await db.store({
44
- * data: { message: 'Hello OnChainDB!', user: 'alice' },
44
+ * data: { message: 'Hello OnDB!', user: 'alice' },
45
45
  * collection: 'messages'
46
46
  * });
47
47
  *
@@ -59,9 +59,9 @@ export declare const VERSION = "1.0.0";
59
59
  *
60
60
  * @example Advanced Usage with Events
61
61
  * ```typescript
62
- * import { OnChainDBClient } from '@onchaindb/sdk';
62
+ * import { OnDBClient } from '@ondb/sdk';
63
63
  *
64
- * const db = new OnChainDBClient({
64
+ * const db = new OnDBClient({
65
65
  * endpoint: 'http://localhost:9092'
66
66
  * });
67
67
  *
@@ -83,9 +83,9 @@ export declare const VERSION = "1.0.0";
83
83
  *
84
84
  * @example Batch Operations
85
85
  * ```typescript
86
- * import { OnChainDBClient, BulkBuilder } from '@onchaindb/sdk';
86
+ * import { OnDBClient, BulkBuilder } from '@ondb/sdk';
87
87
  *
88
- * const db = new OnChainDBClient({ endpoint: 'http://localhost:9092' });
88
+ * const db = new OnDBClient({ endpoint: 'http://localhost:9092' });
89
89
  * const batch = db.batch();
90
90
  *
91
91
  * // Build bulk operation
@@ -107,7 +107,7 @@ export declare const VERSION = "1.0.0";
107
107
  *
108
108
  * @example Database Management
109
109
  * ```typescript
110
- * import { createClient } from '@onchaindb/sdk';
110
+ * import { createClient } from '@ondb/sdk';
111
111
  *
112
112
  * const client = createClient({
113
113
  * endpoint: 'http://localhost:9092',
@@ -143,7 +143,7 @@ export declare const VERSION = "1.0.0";
143
143
  *
144
144
  * @example Error Handling
145
145
  * ```typescript
146
- * import { OnChainDBError, TransactionError, ValidationError } from '@onchaindb/sdk';
146
+ * import { OnDBError, TransactionError, ValidationError } from '@ondb/sdk';
147
147
  *
148
148
  * try {
149
149
  * await db.store({ data: { test: 'data' } });
@@ -152,8 +152,8 @@ export declare const VERSION = "1.0.0";
152
152
  * console.log('Validation failed:', error.message);
153
153
  * } else if (error instanceof TransactionError) {
154
154
  * console.log('Transaction failed:', error.transactionId);
155
- * } else if (error instanceof OnChainDBError) {
156
- * console.log('OnChainDB error:', error.code);
155
+ * } else if (error instanceof OnDBError) {
156
+ * console.log('OnDB error:', error.code);
157
157
  * }
158
158
  * }
159
159
  * ```