@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.
- package/dist/client.d.ts +3 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +61 -71
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/query-sdk/OnDB.d.ts +27 -0
- package/dist/query-sdk/OnDB.d.ts.map +1 -0
- package/dist/query-sdk/OnDB.js +191 -0
- package/dist/query-sdk/OnDB.js.map +1 -0
- package/dist/query-sdk/index.d.ts +1 -1
- package/dist/query-sdk/index.d.ts.map +1 -1
- package/dist/query-sdk/index.js +3 -3
- package/dist/query-sdk/index.js.map +1 -1
- package/dist/types.d.ts +6 -35
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -8
- package/dist/types.js.map +1 -1
- package/dist/x402/types.d.ts +1 -1
- package/dist/x402/types.d.ts.map +1 -1
- package/dist/x402/utils.js +2 -2
- package/dist/x402/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/batch.d.ts +3 -3
- package/src/batch.js +1 -1
- package/src/client.ts +73 -106
- package/src/database.d.ts +1 -1
- package/src/database.js +4 -4
- package/src/database.ts +2 -2
- package/src/index.d.ts +18 -18
- package/src/index.js +16 -16
- package/src/index.ts +7 -8
- package/src/query-sdk/{OnChainDB.ts → OnDB.ts} +1 -1
- package/src/query-sdk/README.md +8 -8
- package/src/query-sdk/index.ts +1 -1
- package/src/tests/client-requests.test.ts +3 -3
- package/src/tests/client-validation.test.ts +5 -5
- package/src/types.d.ts +6 -6
- package/src/types.js +8 -8
- package/src/types.ts +10 -46
- package/src/x402/types.ts +3 -3
- package/src/x402/utils.ts +3 -3
- 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
|
-
|
|
8
|
-
|
|
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
|
-
*
|
|
60
|
+
* OnDB TypeScript SDK
|
|
62
61
|
*
|
|
63
|
-
* Provides a complete interface for storing and querying data on
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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<
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
332
|
+
throw new OnDBError('No ticket_id in response after payment', 'STORE_ERROR');
|
|
334
333
|
}
|
|
335
334
|
|
|
336
335
|
/**
|
|
337
|
-
* Store data on
|
|
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
|
|
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
|
|
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
|
|
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
|
|
458
|
-
new
|
|
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
|
|
479
|
-
new
|
|
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,
|
|
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,
|
|
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
|
|
725
|
-
new
|
|
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
|
|
737
|
-
new
|
|
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
|
|
749
|
-
new
|
|
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
|
|
761
|
-
new
|
|
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
|
|
773
|
-
new
|
|
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
|
|
785
|
-
new
|
|
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
|
|
797
|
-
new
|
|
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
|
|
808
|
-
new
|
|
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
|
|
820
|
-
new
|
|
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
|
|
832
|
-
new
|
|
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
|
|
844
|
-
new
|
|
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
|
|
856
|
-
new
|
|
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
|
|
870
|
-
new
|
|
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
|
|
891
|
-
new
|
|
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
|
|
937
|
-
new
|
|
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
|
|
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
|
|
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
|
|
1027
|
-
new
|
|
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
|
|
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
|
|
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
|
|
1081
|
-
//
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1209
|
-
new
|
|
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
|
|
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
|
|
1267
|
-
new
|
|
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
|
|
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
|
|
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
|
|
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`, `
|
|
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.
|
|
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
package/src/index.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export {
|
|
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 {
|
|
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 {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
export declare function createClient(config:
|
|
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
|
-
*
|
|
16
|
+
* OnDB TypeScript SDK
|
|
17
17
|
*
|
|
18
|
-
* A complete TypeScript SDK for
|
|
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 '@
|
|
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
|
|
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 {
|
|
62
|
+
* import { OnDBClient } from '@ondb/sdk';
|
|
63
63
|
*
|
|
64
|
-
* const db = new
|
|
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 {
|
|
86
|
+
* import { OnDBClient, BulkBuilder } from '@ondb/sdk';
|
|
87
87
|
*
|
|
88
|
-
* const db = new
|
|
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 '@
|
|
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 {
|
|
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
|
|
156
|
-
* console.log('
|
|
155
|
+
* } else if (error instanceof OnDBError) {
|
|
156
|
+
* console.log('OnDB error:', error.code);
|
|
157
157
|
* }
|
|
158
158
|
* }
|
|
159
159
|
* ```
|