@onchaindb/sdk 0.4.5 → 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 (117) hide show
  1. package/.claude/settings.local.json +10 -2
  2. package/README.md +422 -355
  3. package/dist/batch.d.ts +1 -10
  4. package/dist/batch.d.ts.map +1 -1
  5. package/dist/batch.js +4 -26
  6. package/dist/batch.js.map +1 -1
  7. package/dist/client.d.ts +31 -46
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +222 -357
  10. package/dist/client.js.map +1 -1
  11. package/dist/database.d.ts +14 -131
  12. package/dist/database.d.ts.map +1 -1
  13. package/dist/database.js +35 -131
  14. package/dist/database.js.map +1 -1
  15. package/dist/index.d.ts +10 -13
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +4 -18
  18. package/dist/index.js.map +1 -1
  19. package/dist/query-sdk/ConditionBuilder.d.ts +3 -11
  20. package/dist/query-sdk/ConditionBuilder.d.ts.map +1 -1
  21. package/dist/query-sdk/ConditionBuilder.js +10 -48
  22. package/dist/query-sdk/ConditionBuilder.js.map +1 -1
  23. package/dist/query-sdk/NestedBuilders.d.ts +33 -30
  24. package/dist/query-sdk/NestedBuilders.d.ts.map +1 -1
  25. package/dist/query-sdk/NestedBuilders.js +46 -43
  26. package/dist/query-sdk/NestedBuilders.js.map +1 -1
  27. package/{src/query-sdk/dist/OnChainDB.d.ts → dist/query-sdk/OnDB.d.ts} +10 -2
  28. package/dist/query-sdk/OnDB.d.ts.map +1 -0
  29. package/{src/query-sdk/dist/OnChainDB.js → dist/query-sdk/OnDB.js} +86 -18
  30. package/dist/query-sdk/OnDB.js.map +1 -0
  31. package/dist/query-sdk/QueryBuilder.d.ts +4 -2
  32. package/dist/query-sdk/QueryBuilder.d.ts.map +1 -1
  33. package/dist/query-sdk/QueryBuilder.js +47 -169
  34. package/dist/query-sdk/QueryBuilder.js.map +1 -1
  35. package/dist/query-sdk/QueryResult.d.ts +0 -38
  36. package/dist/query-sdk/QueryResult.d.ts.map +1 -1
  37. package/dist/query-sdk/QueryResult.js +1 -227
  38. package/dist/query-sdk/QueryResult.js.map +1 -1
  39. package/dist/query-sdk/index.d.ts +2 -2
  40. package/dist/query-sdk/index.d.ts.map +1 -1
  41. package/dist/query-sdk/index.js +3 -3
  42. package/dist/query-sdk/index.js.map +1 -1
  43. package/dist/query-sdk/operators.d.ts +32 -28
  44. package/dist/query-sdk/operators.d.ts.map +1 -1
  45. package/dist/query-sdk/operators.js +45 -155
  46. package/dist/query-sdk/operators.js.map +1 -1
  47. package/dist/types.d.ts +159 -36
  48. package/dist/types.d.ts.map +1 -1
  49. package/dist/types.js +8 -8
  50. package/dist/types.js.map +1 -1
  51. package/dist/x402/types.d.ts +1 -1
  52. package/dist/x402/types.d.ts.map +1 -1
  53. package/dist/x402/utils.js +2 -2
  54. package/dist/x402/utils.js.map +1 -1
  55. package/jest.config.js +4 -0
  56. package/package.json +1 -1
  57. package/skills.md +0 -1
  58. package/src/batch.d.ts +3 -3
  59. package/src/batch.js +1 -1
  60. package/src/client.ts +287 -823
  61. package/src/database.d.ts +1 -1
  62. package/src/database.js +4 -4
  63. package/src/database.ts +71 -494
  64. package/src/index.d.ts +18 -18
  65. package/src/index.js +16 -16
  66. package/src/index.ts +44 -198
  67. package/src/query-sdk/ConditionBuilder.ts +37 -89
  68. package/src/query-sdk/NestedBuilders.ts +90 -92
  69. package/src/query-sdk/{OnChainDB.ts → OnDB.ts} +1 -1
  70. package/src/query-sdk/QueryBuilder.ts +59 -218
  71. package/src/query-sdk/QueryResult.ts +4 -330
  72. package/src/query-sdk/README.md +218 -587
  73. package/src/query-sdk/index.ts +2 -2
  74. package/src/query-sdk/operators.ts +91 -200
  75. package/src/query-sdk/tests/FieldConditionBuilder.test.ts +70 -71
  76. package/src/query-sdk/tests/LogicalOperator.test.ts +43 -82
  77. package/src/query-sdk/tests/NestedBuilders.test.ts +229 -309
  78. package/src/query-sdk/tests/QueryBuilder.test.ts +5 -5
  79. package/src/query-sdk/tests/QueryResult.test.ts +41 -435
  80. package/src/query-sdk/tests/comprehensive.test.ts +4 -185
  81. package/src/tests/client-requests.test.ts +280 -0
  82. package/src/tests/client-validation.test.ts +80 -0
  83. package/src/types.d.ts +6 -6
  84. package/src/types.js +8 -8
  85. package/src/types.ts +239 -54
  86. package/src/x402/types.ts +3 -3
  87. package/src/x402/utils.ts +3 -3
  88. package/examples/blob-upload-example.ts +0 -140
  89. package/src/batch.ts +0 -257
  90. package/src/query-sdk/dist/ConditionBuilder.d.ts +0 -22
  91. package/src/query-sdk/dist/ConditionBuilder.js +0 -90
  92. package/src/query-sdk/dist/FieldConditionBuilder.d.ts +0 -1
  93. package/src/query-sdk/dist/FieldConditionBuilder.js +0 -6
  94. package/src/query-sdk/dist/NestedBuilders.d.ts +0 -43
  95. package/src/query-sdk/dist/NestedBuilders.js +0 -144
  96. package/src/query-sdk/dist/QueryBuilder.d.ts +0 -70
  97. package/src/query-sdk/dist/QueryBuilder.js +0 -295
  98. package/src/query-sdk/dist/QueryResult.d.ts +0 -52
  99. package/src/query-sdk/dist/QueryResult.js +0 -293
  100. package/src/query-sdk/dist/SelectionBuilder.d.ts +0 -20
  101. package/src/query-sdk/dist/SelectionBuilder.js +0 -80
  102. package/src/query-sdk/dist/adapters/HttpClientAdapter.d.ts +0 -27
  103. package/src/query-sdk/dist/adapters/HttpClientAdapter.js +0 -170
  104. package/src/query-sdk/dist/index.d.ts +0 -36
  105. package/src/query-sdk/dist/index.js +0 -27
  106. package/src/query-sdk/dist/operators.d.ts +0 -56
  107. package/src/query-sdk/dist/operators.js +0 -289
  108. package/src/query-sdk/dist/tests/setup.d.ts +0 -15
  109. package/src/query-sdk/dist/tests/setup.js +0 -46
  110. package/src/query-sdk/jest.config.js +0 -25
  111. package/src/query-sdk/package.json +0 -46
  112. package/src/query-sdk/tests/aggregations.test.ts +0 -653
  113. package/src/query-sdk/tests/integration.test.ts +0 -608
  114. package/src/query-sdk/tests/operators.test.ts +0 -327
  115. package/src/query-sdk/tests/unit.test.ts +0 -794
  116. package/src/query-sdk/tsconfig.json +0 -26
  117. package/src/query-sdk/yarn.lock +0 -3092
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
  * ```
package/src/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VERSION = exports.createHttpClient = exports.NodeHttpClient = exports.FetchHttpClient = exports.AxiosHttpClient = exports.PaymentVerificationError = exports.PaymentRequiredError = exports.ValidationError = exports.TransactionError = exports.OnChainDBError = exports.createDatabaseManager = exports.DatabaseManager = exports.LogicalOperator = exports.FieldConditionBuilder = exports.SelectionBuilder = exports.QueryBuilder = exports.BulkBuilder = exports.BatchOperations = exports.OnChainDBClient = void 0;
3
+ exports.VERSION = exports.createHttpClient = exports.NodeHttpClient = exports.FetchHttpClient = exports.AxiosHttpClient = exports.PaymentVerificationError = exports.PaymentRequiredError = exports.ValidationError = exports.TransactionError = exports.OnDBError = exports.createDatabaseManager = exports.DatabaseManager = exports.LogicalOperator = exports.FieldConditionBuilder = exports.SelectionBuilder = exports.QueryBuilder = exports.BulkBuilder = exports.BatchOperations = exports.OnDBClient = void 0;
4
4
  exports.createClient = createClient;
5
5
  // Main SDK exports
6
6
  var client_1 = require("./client");
7
- Object.defineProperty(exports, "OnChainDBClient", { enumerable: true, get: function () { return client_1.OnChainDBClient; } });
7
+ Object.defineProperty(exports, "OnDBClient", { enumerable: true, get: function () { return client_1.OnDBClient; } });
8
8
  var batch_1 = require("./batch");
9
9
  Object.defineProperty(exports, "BatchOperations", { enumerable: true, get: function () { return batch_1.BatchOperations; } });
10
10
  Object.defineProperty(exports, "BulkBuilder", { enumerable: true, get: function () { return batch_1.BulkBuilder; } });
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "DatabaseManager", { enumerable: true, get: funct
20
20
  Object.defineProperty(exports, "createDatabaseManager", { enumerable: true, get: function () { return database_1.createDatabaseManager; } });
21
21
  // Error exports
22
22
  var types_1 = require("./types");
23
- Object.defineProperty(exports, "OnChainDBError", { enumerable: true, get: function () { return types_1.OnChainDBError; } });
23
+ Object.defineProperty(exports, "OnDBError", { enumerable: true, get: function () { return types_1.OnDBError; } });
24
24
  Object.defineProperty(exports, "TransactionError", { enumerable: true, get: function () { return types_1.TransactionError; } });
25
25
  Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return types_1.ValidationError; } });
26
26
  Object.defineProperty(exports, "PaymentRequiredError", { enumerable: true, get: function () { return types_1.PaymentRequiredError; } });
@@ -28,7 +28,7 @@ Object.defineProperty(exports, "PaymentVerificationError", { enumerable: true, g
28
28
  const client_2 = require("./client");
29
29
  // Convenience factory function
30
30
  function createClient(config) {
31
- return new client_2.OnChainDBClient(config);
31
+ return new client_2.OnDBClient(config);
32
32
  }
33
33
  // Re-export HTTP client utilities from ./query-sdk for advanced usage
34
34
  var query_sdk_2 = require("./query-sdk");
@@ -39,9 +39,9 @@ Object.defineProperty(exports, "createHttpClient", { enumerable: true, get: func
39
39
  // SDK version
40
40
  exports.VERSION = '1.0.0';
41
41
  /**
42
- * OnChainDB TypeScript SDK
42
+ * OnDB TypeScript SDK
43
43
  *
44
- * A complete TypeScript SDK for OnChainDB - the decentralized database
44
+ * A complete TypeScript SDK for OnDB - the decentralized database
45
45
  * built on Celestia blockchain.
46
46
  *
47
47
  * Features:
@@ -58,7 +58,7 @@ exports.VERSION = '1.0.0';
58
58
  *
59
59
  * @example Basic Usage
60
60
  * ```typescript
61
- * import { createClient } from '@onchaindb/sdk';
61
+ * import { createClient } from '@ondb/sdk';
62
62
  *
63
63
  * const db = createClient({
64
64
  * endpoint: 'http://localhost:9092',
@@ -67,7 +67,7 @@ exports.VERSION = '1.0.0';
67
67
  *
68
68
  * // Store data
69
69
  * const result = await db.store({
70
- * data: { message: 'Hello OnChainDB!', user: 'alice' },
70
+ * data: { message: 'Hello OnDB!', user: 'alice' },
71
71
  * collection: 'messages'
72
72
  * });
73
73
  *
@@ -85,9 +85,9 @@ exports.VERSION = '1.0.0';
85
85
  *
86
86
  * @example Advanced Usage with Events
87
87
  * ```typescript
88
- * import { OnChainDBClient } from '@onchaindb/sdk';
88
+ * import { OnDBClient } from '@ondb/sdk';
89
89
  *
90
- * const db = new OnChainDBClient({
90
+ * const db = new OnDBClient({
91
91
  * endpoint: 'http://localhost:9092'
92
92
  * });
93
93
  *
@@ -109,9 +109,9 @@ exports.VERSION = '1.0.0';
109
109
  *
110
110
  * @example Batch Operations
111
111
  * ```typescript
112
- * import { OnChainDBClient, BulkBuilder } from '@onchaindb/sdk';
112
+ * import { OnDBClient, BulkBuilder } from '@ondb/sdk';
113
113
  *
114
- * const db = new OnChainDBClient({ endpoint: 'http://localhost:9092' });
114
+ * const db = new OnDBClient({ endpoint: 'http://localhost:9092' });
115
115
  * const batch = db.batch();
116
116
  *
117
117
  * // Build bulk operation
@@ -133,7 +133,7 @@ exports.VERSION = '1.0.0';
133
133
  *
134
134
  * @example Database Management
135
135
  * ```typescript
136
- * import { createClient } from '@onchaindb/sdk';
136
+ * import { createClient } from '@ondb/sdk';
137
137
  *
138
138
  * const client = createClient({
139
139
  * endpoint: 'http://localhost:9092',
@@ -169,7 +169,7 @@ exports.VERSION = '1.0.0';
169
169
  *
170
170
  * @example Error Handling
171
171
  * ```typescript
172
- * import { OnChainDBError, TransactionError, ValidationError } from '@onchaindb/sdk';
172
+ * import { OnDBError, TransactionError, ValidationError } from '@ondb/sdk';
173
173
  *
174
174
  * try {
175
175
  * await db.store({ data: { test: 'data' } });
@@ -178,8 +178,8 @@ exports.VERSION = '1.0.0';
178
178
  * console.log('Validation failed:', error.message);
179
179
  * } else if (error instanceof TransactionError) {
180
180
  * console.log('Transaction failed:', error.transactionId);
181
- * } else if (error instanceof OnChainDBError) {
182
- * console.log('OnChainDB error:', error.code);
181
+ * } else if (error instanceof OnDBError) {
182
+ * console.log('OnDB error:', error.code);
183
183
  * }
184
184
  * }
185
185
  * ```
package/src/index.ts CHANGED
@@ -1,16 +1,11 @@
1
1
  // Main SDK exports
2
- export {OnChainDBClient} from './client';
3
- export {BatchOperations, BulkBuilder} from './batch';
2
+ export { OnDBClient } from './client';
3
+ export { QueryBuilder } from './query-sdk';
4
+ export { DatabaseManager, createDatabaseManager } from './database';
4
5
 
5
- // Query builder exports from ./query-sdk
6
- export {QueryBuilder, SelectionBuilder, FieldConditionBuilder, LogicalOperator, ConditionBuilder, JoinBuilder, OnChainDB} from './query-sdk';
7
-
8
- // Database management exports
9
- export {DatabaseManager, createDatabaseManager} from './database';
10
-
11
- // Type exports
6
+ // Core type exports
12
7
  export type {
13
- OnChainDBConfig,
8
+ OnDBConfig,
14
9
  StoreRequest,
15
10
  StoreResponse,
16
11
  TransactionStatus,
@@ -27,227 +22,78 @@ export type {
27
22
  RetrieveBlobRequest,
28
23
  BlobMetadata,
29
24
  PricingQuoteRequest,
30
- PricingQuoteResponse,
31
25
  SimpleCollectionSchema,
32
26
  SimpleFieldDefinition,
27
+ SimpleCollectionSchemaWithSharding,
28
+ ShardingStrategy,
29
+ ShardKey,
33
30
  CreateCollectionResult,
34
31
  SyncCollectionResult,
32
+ UpdateCollectionRequest,
33
+ SetRetentionRequest,
34
+ ApiConfig,
35
+ SqlQueryRequest,
36
+ SqlQueryResponse,
37
+ SqlInsertRequest,
38
+ SqlCreateViewRequest,
39
+ ViewDataResponse,
40
+ ViewQueryRequest,
41
+ QueryParameter,
42
+ QueryDefinition,
43
+ CreateQueryRequest,
44
+ CreateQueryResponse,
45
+ QueryDataResponse,
46
+ RetentionConfig,
47
+ CollectionRetentionCost,
48
+ RetentionCostResponse,
49
+ CollectionResponse,
50
+ CreateApiCollectionRequest,
35
51
  BaseDocument,
36
- ShardingStrategy,
37
- ShardKey,
38
- SimpleCollectionSchemaWithSharding
52
+ AppKeyPermission,
53
+ PayLimits,
54
+ CreateKeyRequest,
55
+ AppKeyInfo,
39
56
  } from './types';
40
57
 
41
- // Query type exports from ./query-sdk
42
- export type {
43
- SelectionMap,
44
- QueryRequest as RawQuery,
45
- QueryResponse as OnChainQueryResponse,
46
- QueryValue,
47
- Val
48
- } from './query-sdk';
49
-
50
- // Re-export operator types from ./query-sdk
51
- export type {Condition} from './query-sdk';
58
+ // Query type exports (useful for advanced typing)
59
+ export type { QueryResponse as RawQueryResponse, SelectionMap, Val } from './query-sdk';
52
60
 
53
- // x402 payment types
61
+ // x402 payment types (needed for payment callbacks)
54
62
  export type {
55
63
  X402Quote,
56
64
  X402PaymentRequirement,
57
65
  X402PaymentResult,
66
+ X402PaymentCallbackResult,
58
67
  ChainType,
59
- PaymentMethod
68
+ PaymentMethod,
60
69
  } from './x402';
61
70
 
62
71
  // Database management type exports
63
72
  export type {
64
- Collection,
65
- CollectionSchema,
66
- FieldDefinition,
67
- FieldValidation,
68
- Relationship,
69
73
  Index,
70
74
  IndexOptions,
71
- IndexStatus,
72
- IndexStatistics,
73
75
  PriceConfig,
74
- CollectionMetadata,
75
- DatabaseStats,
76
- QueryPlan,
77
- BatchOperation,
78
- BatchResult,
79
76
  MaterializedView,
80
77
  ViewInfo,
81
- ListViewsResponse
78
+ ListViewsResponse,
82
79
  } from './database';
83
80
 
84
81
  // Error exports
85
82
  export {
86
- OnChainDBError,
83
+ OnDBError,
87
84
  TransactionError,
88
85
  ValidationError,
89
86
  PaymentRequiredError,
90
- PaymentVerificationError
87
+ PaymentVerificationError,
91
88
  } from './types';
92
89
 
93
- // Import types for factory function
94
- import {OnChainDBConfig} from './types';
95
- import {OnChainDBClient} from './client';
96
-
97
90
  // Convenience factory function
98
- export function createClient(config: OnChainDBConfig): OnChainDBClient {
99
- return new OnChainDBClient(config);
100
- }
91
+ import { OnDBConfig } from './types';
92
+ import { OnDBClient } from './client';
101
93
 
102
- // Re-export HTTP client utilities from ./query-sdk for advanced usage
103
- export {AxiosHttpClient, FetchHttpClient, NodeHttpClient, createHttpClient} from './query-sdk';
94
+ export function createClient(config: OnDBConfig): OnDBClient {
95
+ return new OnDBClient(config);
96
+ }
104
97
 
105
98
  // SDK version
106
99
  export const VERSION = '1.0.0';
107
-
108
- /**
109
- * OnChainDB TypeScript SDK
110
- *
111
- * A complete TypeScript SDK for OnChainDB - the decentralized database
112
- * built on Celestia blockchain.
113
- *
114
- * Features:
115
- * - ✅ Full type safety with TypeScript
116
- * - ✅ Automatic transaction management
117
- * - ✅ Real-time confirmation tracking
118
- * - ✅ Batch operations with progress tracking
119
- * - ✅ Built-in error handling and retries
120
- * - ✅ Event-driven architecture
121
- * - ✅ Query building and filtering
122
- * - ✅ Complete database management (collections, indexes, schemas)
123
- * - ✅ Performance monitoring and optimization
124
- * - ✅ Schema validation and migration
125
- *
126
- * @example Basic Usage
127
- * ```typescript
128
- * import { createClient } from '@onchaindb/sdk';
129
- *
130
- * const db = createClient({
131
- * endpoint: 'http://localhost:9092',
132
- * apiKey: 'your-api-key'
133
- * });
134
- *
135
- * // Store data
136
- * const result = await db.store({
137
- * data: { message: 'Hello OnChainDB!', user: 'alice' },
138
- * collection: 'messages'
139
- * });
140
- *
141
- * console.log('Stored with ID:', result.id);
142
- * console.log('Transaction:', result.transaction_hash);
143
- *
144
- * // Query data
145
- * const messages = await db.query({
146
- * collection: 'messages',
147
- * limit: 10
148
- * });
149
- *
150
- * console.log(`Found ${messages.total} messages`);
151
- * ```
152
- *
153
- * @example Advanced Usage with Events
154
- * ```typescript
155
- * import { OnChainDBClient } from '@onchaindb/sdk';
156
- *
157
- * const db = new OnChainDBClient({
158
- * endpoint: 'http://localhost:9092'
159
- * });
160
- *
161
- * // Listen for transaction events
162
- * db.on('transaction:pending', (tx) => {
163
- * console.log('Transaction pending:', tx.id);
164
- * });
165
- *
166
- * db.on('transaction:confirmed', (tx) => {
167
- * console.log('Transaction confirmed:', tx.id);
168
- * });
169
- *
170
- * // Store and wait for confirmation
171
- * const confirmed = await db.storeAndConfirm({
172
- * data: { important: 'data that needs confirmation' },
173
- * collection: 'critical'
174
- * });
175
- * ```
176
- *
177
- * @example Batch Operations
178
- * ```typescript
179
- * import { OnChainDBClient, BulkBuilder } from '@onchaindb/sdk';
180
- *
181
- * const db = new OnChainDBClient({ endpoint: 'http://localhost:9092' });
182
- * const batch = db.batch();
183
- *
184
- * // Build bulk operation
185
- * const builder = new BulkBuilder()
186
- * .collection('tweets')
187
- * .add({ message: 'Tweet 1', author: 'alice' })
188
- * .add({ message: 'Tweet 2', author: 'bob' })
189
- * .add({ message: 'Tweet 3', author: 'charlie' });
190
- *
191
- * // Execute with progress tracking
192
- * const results = await batch.store(builder.build(), {
193
- * concurrency: 5,
194
- * waitForConfirmation: true,
195
- * onProgress: (completed, total) => {
196
- * console.log(`Progress: ${completed}/${total}`);
197
- * }
198
- * });
199
- * ```
200
- *
201
- * @example Database Management
202
- * ```typescript
203
- * import { createClient } from '@onchaindb/sdk';
204
- *
205
- * const client = createClient({
206
- * endpoint: 'http://localhost:9092',
207
- * apiKey: 'your-api-key'
208
- * });
209
- *
210
- * // Get database manager for an app
211
- * const db = client.database('app_12345');
212
- *
213
- * // Create collections with schemas
214
- * await db.createCollection('users', {
215
- * fields: {
216
- * id: { type: 'string', unique: true, required: true },
217
- * name: { type: 'string', required: true },
218
- * email: { type: 'string', unique: true, required: true },
219
- * created_at: { type: 'date', default: () => new Date() }
220
- * }
221
- * });
222
- *
223
- * // Create optimized indexes
224
- * await db.createIndex({
225
- * name: 'users_email_index',
226
- * collection: 'users',
227
- * field_name: 'email',
228
- * index_type: 'btree',
229
- * options: { unique: true }
230
- * });
231
- *
232
- * // Monitor performance
233
- * const stats = await db.getDatabaseStats();
234
- * console.log(`Collections: ${stats.total_collections}, Indexes: ${stats.total_indexes}`);
235
- * ```
236
- *
237
- * @example Error Handling
238
- * ```typescript
239
- * import { OnChainDBError, TransactionError, ValidationError } from '@onchaindb/sdk';
240
- *
241
- * try {
242
- * await db.store({ data: { test: 'data' } });
243
- * } catch (error) {
244
- * if (error instanceof ValidationError) {
245
- * console.log('Validation failed:', error.message);
246
- * } else if (error instanceof TransactionError) {
247
- * console.log('Transaction failed:', error.transactionId);
248
- * } else if (error instanceof OnChainDBError) {
249
- * console.log('OnChainDB error:', error.code);
250
- * }
251
- * }
252
- * ```
253
- */
@@ -1,103 +1,51 @@
1
1
  import { LogicalOperator, FieldConditionBuilder } from './operators';
2
2
  import { NestedConditionBuilder } from './NestedBuilders';
3
3
 
4
- // Builder for creating complex conditions with logical operators
4
+ // Builder for creating complex conditions with logical operators.
5
+ // Received as the argument inside .find() and .on() callbacks.
5
6
  export class ConditionBuilder {
6
- private conditions: LogicalOperator[] = [];
7
- private currentOperator?: 'and' | 'or' | 'not';
7
+ constructor() {}
8
8
 
9
- constructor() {}
10
-
11
- static new(): ConditionBuilder {
12
- return new ConditionBuilder();
13
- }
14
-
15
- // Create a field condition builder
16
- field(fieldName: string): FieldConditionBuilder {
17
- return new FieldConditionBuilder(fieldName);
18
- }
19
-
20
- // Create a nested field condition with fluent API (like Rust SDK)
21
- nested(fieldName: string, builderFn: (builder: NestedConditionBuilder) => LogicalOperator): LogicalOperator {
22
- const nestedBuilder = new NestedConditionBuilder(fieldName);
23
- return builderFn(nestedBuilder);
24
- }
25
-
26
- // Add an AND operator context
27
- and(): ConditionBuilder {
28
- this.currentOperator = 'and';
29
- return this;
30
- }
31
-
32
- // Add an OR operator context
33
- or(): ConditionBuilder {
34
- this.currentOperator = 'or';
35
- return this;
36
- }
37
-
38
- // Add a NOT operator context
39
- not(): ConditionBuilder {
40
- this.currentOperator = 'not';
41
- return this;
42
- }
43
-
44
- // Group conditions with AND logic
45
- andGroup(builderFn: (builder: ConditionBuilder) => LogicalOperator[]): LogicalOperator {
46
- const nestedBuilder = new ConditionBuilder();
47
- const conditions = builderFn(nestedBuilder);
48
- return LogicalOperator.And(conditions);
49
- }
50
-
51
- // Group conditions with OR logic
52
- orGroup(builderFn: (builder: ConditionBuilder) => LogicalOperator[]): LogicalOperator {
53
- const nestedBuilder = new ConditionBuilder();
54
- const conditions = builderFn(nestedBuilder);
55
- return LogicalOperator.Or(conditions);
56
- }
9
+ static new(): ConditionBuilder {
10
+ return new ConditionBuilder();
11
+ }
57
12
 
58
- // Group conditions with NOT logic
59
- notGroup(builderFn: (builder: ConditionBuilder) => LogicalOperator[]): LogicalOperator {
60
- const nestedBuilder = new ConditionBuilder();
61
- const conditions = builderFn(nestedBuilder);
62
- return LogicalOperator.Not(conditions);
63
- }
13
+ // Create a field condition builder for a single field
14
+ field(fieldName: string): FieldConditionBuilder {
15
+ return new FieldConditionBuilder(fieldName);
16
+ }
64
17
 
65
- // Add a condition to the current builder
66
- addCondition(condition: LogicalOperator): ConditionBuilder {
67
- this.conditions.push(condition);
68
- return this;
69
- }
18
+ // Create a nested field condition (dot-notation path)
19
+ nested(fieldName: string, builderFn: (builder: NestedConditionBuilder) => LogicalOperator): LogicalOperator {
20
+ const nestedBuilder = new NestedConditionBuilder(fieldName);
21
+ return builderFn(nestedBuilder);
22
+ }
70
23
 
71
- // Build and return all conditions
72
- build(): LogicalOperator[] {
73
- return [...this.conditions];
74
- }
24
+ // Combine conditions with AND — the default when no group is specified
25
+ and(...conditions: LogicalOperator[]): LogicalOperator {
26
+ return LogicalOperator.And(conditions);
27
+ }
75
28
 
76
- // Build as a single logical operator (combines all conditions with AND by default)
77
- buildSingle(): LogicalOperator {
78
- if (this.conditions.length === 0) {
79
- throw new Error('No conditions to build');
29
+ // Combine conditions with OR
30
+ or(...conditions: LogicalOperator[]): LogicalOperator {
31
+ return LogicalOperator.Or(conditions);
80
32
  }
81
- if (this.conditions.length === 1) {
82
- return this.conditions[0];
33
+
34
+ // Negate conditions with NOT
35
+ not(...conditions: LogicalOperator[]): LogicalOperator {
36
+ return LogicalOperator.Not(conditions);
83
37
  }
84
- return LogicalOperator.And(this.conditions);
85
- }
86
38
 
87
- // Clear all conditions
88
- clear(): ConditionBuilder {
89
- this.conditions = [];
90
- this.currentOperator = undefined;
91
- return this;
92
- }
39
+ // Callback-style group helpers (kept for compatibility)
40
+ andGroup(builderFn: (builder: ConditionBuilder) => LogicalOperator[]): LogicalOperator {
41
+ return LogicalOperator.And(builderFn(new ConditionBuilder()));
42
+ }
93
43
 
94
- // Check if any conditions have been added
95
- isEmpty(): boolean {
96
- return this.conditions.length === 0;
97
- }
44
+ orGroup(builderFn: (builder: ConditionBuilder) => LogicalOperator[]): LogicalOperator {
45
+ return LogicalOperator.Or(builderFn(new ConditionBuilder()));
46
+ }
98
47
 
99
- // Get the number of conditions
100
- getConditionCount(): number {
101
- return this.conditions.length;
102
- }
103
- }
48
+ notGroup(builderFn: (builder: ConditionBuilder) => LogicalOperator[]): LogicalOperator {
49
+ return LogicalOperator.Not(builderFn(new ConditionBuilder()));
50
+ }
51
+ }