@onchaindb/sdk 0.4.0 → 0.4.2

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 (98) hide show
  1. package/.DS_Store +0 -0
  2. package/.claude/settings.local.json +8 -0
  3. package/.gitignore +5 -0
  4. package/.idea/.gitignore +5 -0
  5. package/.idea/compiler.xml +6 -0
  6. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  7. package/.idea/jsLinters/eslint.xml +6 -0
  8. package/.idea/modules.xml +8 -0
  9. package/.idea/prettier.xml +7 -0
  10. package/.idea/sdk.iml +12 -0
  11. package/.idea/vcs.xml +6 -0
  12. package/.idea/workspace.xml +257 -0
  13. package/dist/client.d.ts.map +1 -1
  14. package/dist/client.js +11 -3
  15. package/dist/client.js.map +1 -1
  16. package/dist/database.d.ts +0 -20
  17. package/dist/database.d.ts.map +1 -1
  18. package/dist/database.js +0 -40
  19. package/dist/database.js.map +1 -1
  20. package/dist/query-sdk/tests/setup.d.ts +16 -0
  21. package/dist/query-sdk/tests/setup.d.ts.map +1 -0
  22. package/dist/query-sdk/tests/setup.js +49 -0
  23. package/dist/query-sdk/tests/setup.js.map +1 -0
  24. package/examples/basic-usage.ts +136 -0
  25. package/examples/blob-upload-example.ts +140 -0
  26. package/examples/collection-schema-example.ts +304 -0
  27. package/examples/server-side-joins.ts +201 -0
  28. package/examples/tweet-self-joins-example.ts +352 -0
  29. package/package-lock.json +3823 -0
  30. package/package.json +1 -1
  31. package/skills.md +1096 -0
  32. package/src/.env +1 -0
  33. package/src/batch.d.ts +121 -0
  34. package/src/batch.js +205 -0
  35. package/src/batch.ts +257 -0
  36. package/src/client.ts +1856 -0
  37. package/src/database.d.ts +268 -0
  38. package/src/database.js +294 -0
  39. package/src/database.ts +695 -0
  40. package/src/index.d.ts +160 -0
  41. package/src/index.js +186 -0
  42. package/src/index.ts +253 -0
  43. package/src/query-sdk/ConditionBuilder.ts +103 -0
  44. package/src/query-sdk/FieldConditionBuilder.ts +2 -0
  45. package/src/query-sdk/NestedBuilders.ts +186 -0
  46. package/src/query-sdk/OnChainDB.ts +294 -0
  47. package/src/query-sdk/QueryBuilder.ts +1191 -0
  48. package/src/query-sdk/QueryResult.ts +375 -0
  49. package/src/query-sdk/README.md +866 -0
  50. package/src/query-sdk/SelectionBuilder.ts +94 -0
  51. package/src/query-sdk/adapters/HttpClientAdapter.ts +249 -0
  52. package/src/query-sdk/dist/ConditionBuilder.d.ts +22 -0
  53. package/src/query-sdk/dist/ConditionBuilder.js +90 -0
  54. package/src/query-sdk/dist/FieldConditionBuilder.d.ts +1 -0
  55. package/src/query-sdk/dist/FieldConditionBuilder.js +6 -0
  56. package/src/query-sdk/dist/NestedBuilders.d.ts +43 -0
  57. package/src/query-sdk/dist/NestedBuilders.js +144 -0
  58. package/src/query-sdk/dist/OnChainDB.d.ts +19 -0
  59. package/src/query-sdk/dist/OnChainDB.js +123 -0
  60. package/src/query-sdk/dist/QueryBuilder.d.ts +70 -0
  61. package/src/query-sdk/dist/QueryBuilder.js +295 -0
  62. package/src/query-sdk/dist/QueryResult.d.ts +52 -0
  63. package/src/query-sdk/dist/QueryResult.js +293 -0
  64. package/src/query-sdk/dist/SelectionBuilder.d.ts +20 -0
  65. package/src/query-sdk/dist/SelectionBuilder.js +80 -0
  66. package/src/query-sdk/dist/adapters/HttpClientAdapter.d.ts +27 -0
  67. package/src/query-sdk/dist/adapters/HttpClientAdapter.js +170 -0
  68. package/src/query-sdk/dist/index.d.ts +36 -0
  69. package/src/query-sdk/dist/index.js +27 -0
  70. package/src/query-sdk/dist/operators.d.ts +56 -0
  71. package/src/query-sdk/dist/operators.js +289 -0
  72. package/src/query-sdk/dist/tests/setup.d.ts +15 -0
  73. package/src/query-sdk/dist/tests/setup.js +46 -0
  74. package/src/query-sdk/index.ts +59 -0
  75. package/src/query-sdk/jest.config.js +25 -0
  76. package/src/query-sdk/operators.ts +335 -0
  77. package/src/query-sdk/package.json +46 -0
  78. package/src/query-sdk/tests/FieldConditionBuilder.test.ts +84 -0
  79. package/src/query-sdk/tests/LogicalOperator.test.ts +85 -0
  80. package/src/query-sdk/tests/NestedBuilders.test.ts +321 -0
  81. package/src/query-sdk/tests/QueryBuilder.test.ts +348 -0
  82. package/src/query-sdk/tests/QueryResult.test.ts +464 -0
  83. package/src/query-sdk/tests/aggregations.test.ts +653 -0
  84. package/src/query-sdk/tests/comprehensive.test.ts +279 -0
  85. package/src/query-sdk/tests/integration.test.ts +608 -0
  86. package/src/query-sdk/tests/operators.test.ts +327 -0
  87. package/src/query-sdk/tests/setup.ts +59 -0
  88. package/src/query-sdk/tests/unit.test.ts +794 -0
  89. package/src/query-sdk/tsconfig.json +26 -0
  90. package/src/query-sdk/yarn.lock +3092 -0
  91. package/src/types.d.ts +131 -0
  92. package/src/types.js +46 -0
  93. package/src/types.ts +534 -0
  94. package/src/x402/index.ts +12 -0
  95. package/src/x402/types.ts +250 -0
  96. package/src/x402/utils.ts +332 -0
  97. package/tsconfig.json +20 -0
  98. package/yarn.lock +2309 -0
package/src/index.d.ts ADDED
@@ -0,0 +1,160 @@
1
+ export { OnChainDBClient } from './client';
2
+ export { BatchOperations, BulkBuilder } from './batch';
3
+ export { QueryBuilder, SelectionBuilder, FieldConditionBuilder, LogicalOperator } from './query-sdk';
4
+ export { DatabaseManager, createDatabaseManager } from './database';
5
+ export type { OnChainDBConfig, StoreRequest, StoreResponse, TransactionStatus, QueryRequest, QueryResponse, TransactionEvents, IndexRequest, IndexResponse, AdvancedQueryRequest, IndexPaymentProof, IndexCostEstimate, StorageCostEstimate } from './types';
6
+ export type { SelectionMap, QueryRequest as RawQuery, QueryResponse as OnChainQueryResponse, QueryValue, Val } from './query-sdk';
7
+ export type { Condition } from './query-sdk';
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;
13
+ export { AxiosHttpClient, FetchHttpClient, NodeHttpClient, createHttpClient } from './query-sdk';
14
+ export declare const VERSION = "1.0.0";
15
+ /**
16
+ * OnChainDB TypeScript SDK
17
+ *
18
+ * A complete TypeScript SDK for OnChainDB - the decentralized database
19
+ * built on Celestia blockchain.
20
+ *
21
+ * Features:
22
+ * - ✅ Full type safety with TypeScript
23
+ * - ✅ Automatic transaction management
24
+ * - ✅ Real-time confirmation tracking
25
+ * - ✅ Batch operations with progress tracking
26
+ * - ✅ Built-in error handling and retries
27
+ * - ✅ Event-driven architecture
28
+ * - ✅ Query building and filtering
29
+ * - ✅ Complete database management (collections, indexes, schemas)
30
+ * - ✅ Performance monitoring and optimization
31
+ * - ✅ Schema validation and migration
32
+ *
33
+ * @example Basic Usage
34
+ * ```typescript
35
+ * import { createClient } from '@onchaindb/sdk';
36
+ *
37
+ * const db = createClient({
38
+ * endpoint: 'http://localhost:9092',
39
+ * apiKey: 'your-api-key'
40
+ * });
41
+ *
42
+ * // Store data
43
+ * const result = await db.store({
44
+ * data: { message: 'Hello OnChainDB!', user: 'alice' },
45
+ * collection: 'messages'
46
+ * });
47
+ *
48
+ * console.log('Stored with ID:', result.id);
49
+ * console.log('Transaction:', result.transaction_hash);
50
+ *
51
+ * // Query data
52
+ * const messages = await db.query({
53
+ * collection: 'messages',
54
+ * limit: 10
55
+ * });
56
+ *
57
+ * console.log(`Found ${messages.total} messages`);
58
+ * ```
59
+ *
60
+ * @example Advanced Usage with Events
61
+ * ```typescript
62
+ * import { OnChainDBClient } from '@onchaindb/sdk';
63
+ *
64
+ * const db = new OnChainDBClient({
65
+ * endpoint: 'http://localhost:9092'
66
+ * });
67
+ *
68
+ * // Listen for transaction events
69
+ * db.on('transaction:pending', (tx) => {
70
+ * console.log('Transaction pending:', tx.id);
71
+ * });
72
+ *
73
+ * db.on('transaction:confirmed', (tx) => {
74
+ * console.log('Transaction confirmed:', tx.id);
75
+ * });
76
+ *
77
+ * // Store and wait for confirmation
78
+ * const confirmed = await db.storeAndConfirm({
79
+ * data: { important: 'data that needs confirmation' },
80
+ * collection: 'critical'
81
+ * });
82
+ * ```
83
+ *
84
+ * @example Batch Operations
85
+ * ```typescript
86
+ * import { OnChainDBClient, BulkBuilder } from '@onchaindb/sdk';
87
+ *
88
+ * const db = new OnChainDBClient({ endpoint: 'http://localhost:9092' });
89
+ * const batch = db.batch();
90
+ *
91
+ * // Build bulk operation
92
+ * const builder = new BulkBuilder()
93
+ * .collection('tweets')
94
+ * .add({ message: 'Tweet 1', author: 'alice' })
95
+ * .add({ message: 'Tweet 2', author: 'bob' })
96
+ * .add({ message: 'Tweet 3', author: 'charlie' });
97
+ *
98
+ * // Execute with progress tracking
99
+ * const results = await batch.store(builder.build(), {
100
+ * concurrency: 5,
101
+ * waitForConfirmation: true,
102
+ * onProgress: (completed, total) => {
103
+ * console.log(`Progress: ${completed}/${total}`);
104
+ * }
105
+ * });
106
+ * ```
107
+ *
108
+ * @example Database Management
109
+ * ```typescript
110
+ * import { createClient } from '@onchaindb/sdk';
111
+ *
112
+ * const client = createClient({
113
+ * endpoint: 'http://localhost:9092',
114
+ * apiKey: 'your-api-key'
115
+ * });
116
+ *
117
+ * // Get database manager for an app
118
+ * const db = client.database('app_12345');
119
+ *
120
+ * // Create collections with schemas
121
+ * await db.createCollection('users', {
122
+ * fields: {
123
+ * id: { type: 'string', unique: true, required: true },
124
+ * name: { type: 'string', required: true },
125
+ * email: { type: 'string', unique: true, required: true },
126
+ * created_at: { type: 'date', default: () => new Date() }
127
+ * }
128
+ * });
129
+ *
130
+ * // Create optimized indexes
131
+ * await db.createIndex({
132
+ * name: 'users_email_index',
133
+ * collection: 'users',
134
+ * field_name: 'email',
135
+ * index_type: 'btree',
136
+ * options: { unique: true }
137
+ * });
138
+ *
139
+ * // Monitor performance
140
+ * const stats = await db.getDatabaseStats();
141
+ * console.log(`Collections: ${stats.total_collections}, Indexes: ${stats.total_indexes}`);
142
+ * ```
143
+ *
144
+ * @example Error Handling
145
+ * ```typescript
146
+ * import { OnChainDBError, TransactionError, ValidationError } from '@onchaindb/sdk';
147
+ *
148
+ * try {
149
+ * await db.store({ data: { test: 'data' } });
150
+ * } catch (error) {
151
+ * if (error instanceof ValidationError) {
152
+ * console.log('Validation failed:', error.message);
153
+ * } else if (error instanceof TransactionError) {
154
+ * console.log('Transaction failed:', error.transactionId);
155
+ * } else if (error instanceof OnChainDBError) {
156
+ * console.log('OnChainDB error:', error.code);
157
+ * }
158
+ * }
159
+ * ```
160
+ */
package/src/index.js ADDED
@@ -0,0 +1,186 @@
1
+ "use strict";
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;
4
+ exports.createClient = createClient;
5
+ // Main SDK exports
6
+ var client_1 = require("./client");
7
+ Object.defineProperty(exports, "OnChainDBClient", { enumerable: true, get: function () { return client_1.OnChainDBClient; } });
8
+ var batch_1 = require("./batch");
9
+ Object.defineProperty(exports, "BatchOperations", { enumerable: true, get: function () { return batch_1.BatchOperations; } });
10
+ Object.defineProperty(exports, "BulkBuilder", { enumerable: true, get: function () { return batch_1.BulkBuilder; } });
11
+ // Query builder exports from ./query-sdk
12
+ var query_sdk_1 = require("./query-sdk");
13
+ Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return query_sdk_1.QueryBuilder; } });
14
+ Object.defineProperty(exports, "SelectionBuilder", { enumerable: true, get: function () { return query_sdk_1.SelectionBuilder; } });
15
+ Object.defineProperty(exports, "FieldConditionBuilder", { enumerable: true, get: function () { return query_sdk_1.FieldConditionBuilder; } });
16
+ Object.defineProperty(exports, "LogicalOperator", { enumerable: true, get: function () { return query_sdk_1.LogicalOperator; } });
17
+ // Database management exports
18
+ var database_1 = require("./database");
19
+ Object.defineProperty(exports, "DatabaseManager", { enumerable: true, get: function () { return database_1.DatabaseManager; } });
20
+ Object.defineProperty(exports, "createDatabaseManager", { enumerable: true, get: function () { return database_1.createDatabaseManager; } });
21
+ // Error exports
22
+ var types_1 = require("./types");
23
+ Object.defineProperty(exports, "OnChainDBError", { enumerable: true, get: function () { return types_1.OnChainDBError; } });
24
+ Object.defineProperty(exports, "TransactionError", { enumerable: true, get: function () { return types_1.TransactionError; } });
25
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return types_1.ValidationError; } });
26
+ Object.defineProperty(exports, "PaymentRequiredError", { enumerable: true, get: function () { return types_1.PaymentRequiredError; } });
27
+ Object.defineProperty(exports, "PaymentVerificationError", { enumerable: true, get: function () { return types_1.PaymentVerificationError; } });
28
+ const client_2 = require("./client");
29
+ // Convenience factory function
30
+ function createClient(config) {
31
+ return new client_2.OnChainDBClient(config);
32
+ }
33
+ // Re-export HTTP client utilities from ./query-sdk for advanced usage
34
+ var query_sdk_2 = require("./query-sdk");
35
+ Object.defineProperty(exports, "AxiosHttpClient", { enumerable: true, get: function () { return query_sdk_2.AxiosHttpClient; } });
36
+ Object.defineProperty(exports, "FetchHttpClient", { enumerable: true, get: function () { return query_sdk_2.FetchHttpClient; } });
37
+ Object.defineProperty(exports, "NodeHttpClient", { enumerable: true, get: function () { return query_sdk_2.NodeHttpClient; } });
38
+ Object.defineProperty(exports, "createHttpClient", { enumerable: true, get: function () { return query_sdk_2.createHttpClient; } });
39
+ // SDK version
40
+ exports.VERSION = '1.0.0';
41
+ /**
42
+ * OnChainDB TypeScript SDK
43
+ *
44
+ * A complete TypeScript SDK for OnChainDB - the decentralized database
45
+ * built on Celestia blockchain.
46
+ *
47
+ * Features:
48
+ * - ✅ Full type safety with TypeScript
49
+ * - ✅ Automatic transaction management
50
+ * - ✅ Real-time confirmation tracking
51
+ * - ✅ Batch operations with progress tracking
52
+ * - ✅ Built-in error handling and retries
53
+ * - ✅ Event-driven architecture
54
+ * - ✅ Query building and filtering
55
+ * - ✅ Complete database management (collections, indexes, schemas)
56
+ * - ✅ Performance monitoring and optimization
57
+ * - ✅ Schema validation and migration
58
+ *
59
+ * @example Basic Usage
60
+ * ```typescript
61
+ * import { createClient } from '@onchaindb/sdk';
62
+ *
63
+ * const db = createClient({
64
+ * endpoint: 'http://localhost:9092',
65
+ * apiKey: 'your-api-key'
66
+ * });
67
+ *
68
+ * // Store data
69
+ * const result = await db.store({
70
+ * data: { message: 'Hello OnChainDB!', user: 'alice' },
71
+ * collection: 'messages'
72
+ * });
73
+ *
74
+ * console.log('Stored with ID:', result.id);
75
+ * console.log('Transaction:', result.transaction_hash);
76
+ *
77
+ * // Query data
78
+ * const messages = await db.query({
79
+ * collection: 'messages',
80
+ * limit: 10
81
+ * });
82
+ *
83
+ * console.log(`Found ${messages.total} messages`);
84
+ * ```
85
+ *
86
+ * @example Advanced Usage with Events
87
+ * ```typescript
88
+ * import { OnChainDBClient } from '@onchaindb/sdk';
89
+ *
90
+ * const db = new OnChainDBClient({
91
+ * endpoint: 'http://localhost:9092'
92
+ * });
93
+ *
94
+ * // Listen for transaction events
95
+ * db.on('transaction:pending', (tx) => {
96
+ * console.log('Transaction pending:', tx.id);
97
+ * });
98
+ *
99
+ * db.on('transaction:confirmed', (tx) => {
100
+ * console.log('Transaction confirmed:', tx.id);
101
+ * });
102
+ *
103
+ * // Store and wait for confirmation
104
+ * const confirmed = await db.storeAndConfirm({
105
+ * data: { important: 'data that needs confirmation' },
106
+ * collection: 'critical'
107
+ * });
108
+ * ```
109
+ *
110
+ * @example Batch Operations
111
+ * ```typescript
112
+ * import { OnChainDBClient, BulkBuilder } from '@onchaindb/sdk';
113
+ *
114
+ * const db = new OnChainDBClient({ endpoint: 'http://localhost:9092' });
115
+ * const batch = db.batch();
116
+ *
117
+ * // Build bulk operation
118
+ * const builder = new BulkBuilder()
119
+ * .collection('tweets')
120
+ * .add({ message: 'Tweet 1', author: 'alice' })
121
+ * .add({ message: 'Tweet 2', author: 'bob' })
122
+ * .add({ message: 'Tweet 3', author: 'charlie' });
123
+ *
124
+ * // Execute with progress tracking
125
+ * const results = await batch.store(builder.build(), {
126
+ * concurrency: 5,
127
+ * waitForConfirmation: true,
128
+ * onProgress: (completed, total) => {
129
+ * console.log(`Progress: ${completed}/${total}`);
130
+ * }
131
+ * });
132
+ * ```
133
+ *
134
+ * @example Database Management
135
+ * ```typescript
136
+ * import { createClient } from '@onchaindb/sdk';
137
+ *
138
+ * const client = createClient({
139
+ * endpoint: 'http://localhost:9092',
140
+ * apiKey: 'your-api-key'
141
+ * });
142
+ *
143
+ * // Get database manager for an app
144
+ * const db = client.database('app_12345');
145
+ *
146
+ * // Create collections with schemas
147
+ * await db.createCollection('users', {
148
+ * fields: {
149
+ * id: { type: 'string', unique: true, required: true },
150
+ * name: { type: 'string', required: true },
151
+ * email: { type: 'string', unique: true, required: true },
152
+ * created_at: { type: 'date', default: () => new Date() }
153
+ * }
154
+ * });
155
+ *
156
+ * // Create optimized indexes
157
+ * await db.createIndex({
158
+ * name: 'users_email_index',
159
+ * collection: 'users',
160
+ * field_name: 'email',
161
+ * index_type: 'btree',
162
+ * options: { unique: true }
163
+ * });
164
+ *
165
+ * // Monitor performance
166
+ * const stats = await db.getDatabaseStats();
167
+ * console.log(`Collections: ${stats.total_collections}, Indexes: ${stats.total_indexes}`);
168
+ * ```
169
+ *
170
+ * @example Error Handling
171
+ * ```typescript
172
+ * import { OnChainDBError, TransactionError, ValidationError } from '@onchaindb/sdk';
173
+ *
174
+ * try {
175
+ * await db.store({ data: { test: 'data' } });
176
+ * } catch (error) {
177
+ * if (error instanceof ValidationError) {
178
+ * console.log('Validation failed:', error.message);
179
+ * } else if (error instanceof TransactionError) {
180
+ * console.log('Transaction failed:', error.transactionId);
181
+ * } else if (error instanceof OnChainDBError) {
182
+ * console.log('OnChainDB error:', error.code);
183
+ * }
184
+ * }
185
+ * ```
186
+ */
package/src/index.ts ADDED
@@ -0,0 +1,253 @@
1
+ // Main SDK exports
2
+ export {OnChainDBClient} from './client';
3
+ export {BatchOperations, BulkBuilder} from './batch';
4
+
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
12
+ export type {
13
+ OnChainDBConfig,
14
+ StoreRequest,
15
+ StoreResponse,
16
+ TransactionStatus,
17
+ QueryRequest,
18
+ QueryResponse,
19
+ TransactionEvents,
20
+ IndexRequest,
21
+ IndexResponse,
22
+ RelationRequest,
23
+ RelationResponse,
24
+ AdvancedQueryRequest,
25
+ UploadBlobRequest,
26
+ UploadBlobResponse,
27
+ RetrieveBlobRequest,
28
+ BlobMetadata,
29
+ PricingQuoteRequest,
30
+ PricingQuoteResponse,
31
+ SimpleCollectionSchema,
32
+ SimpleFieldDefinition,
33
+ CreateCollectionResult,
34
+ SyncCollectionResult,
35
+ BaseDocument,
36
+ ShardingStrategy,
37
+ ShardKey,
38
+ SimpleCollectionSchemaWithSharding
39
+ } from './types';
40
+
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';
52
+
53
+ // x402 payment types
54
+ export type {
55
+ X402Quote,
56
+ X402PaymentRequirement,
57
+ X402PaymentResult,
58
+ ChainType,
59
+ PaymentMethod
60
+ } from './x402';
61
+
62
+ // Database management type exports
63
+ export type {
64
+ Collection,
65
+ CollectionSchema,
66
+ FieldDefinition,
67
+ FieldValidation,
68
+ Relationship,
69
+ Index,
70
+ IndexOptions,
71
+ IndexStatus,
72
+ IndexStatistics,
73
+ PriceConfig,
74
+ CollectionMetadata,
75
+ DatabaseStats,
76
+ QueryPlan,
77
+ BatchOperation,
78
+ BatchResult,
79
+ MaterializedView,
80
+ ViewInfo,
81
+ ListViewsResponse
82
+ } from './database';
83
+
84
+ // Error exports
85
+ export {
86
+ OnChainDBError,
87
+ TransactionError,
88
+ ValidationError,
89
+ PaymentRequiredError,
90
+ PaymentVerificationError
91
+ } from './types';
92
+
93
+ // Import types for factory function
94
+ import {OnChainDBConfig} from './types';
95
+ import {OnChainDBClient} from './client';
96
+
97
+ // Convenience factory function
98
+ export function createClient(config: OnChainDBConfig): OnChainDBClient {
99
+ return new OnChainDBClient(config);
100
+ }
101
+
102
+ // Re-export HTTP client utilities from ./query-sdk for advanced usage
103
+ export {AxiosHttpClient, FetchHttpClient, NodeHttpClient, createHttpClient} from './query-sdk';
104
+
105
+ // SDK version
106
+ 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
+ */
@@ -0,0 +1,103 @@
1
+ import { LogicalOperator, FieldConditionBuilder } from './operators';
2
+ import { NestedConditionBuilder } from './NestedBuilders';
3
+
4
+ // Builder for creating complex conditions with logical operators
5
+ export class ConditionBuilder {
6
+ private conditions: LogicalOperator[] = [];
7
+ private currentOperator?: 'and' | 'or' | 'not';
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
+ }
57
+
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
+ }
64
+
65
+ // Add a condition to the current builder
66
+ addCondition(condition: LogicalOperator): ConditionBuilder {
67
+ this.conditions.push(condition);
68
+ return this;
69
+ }
70
+
71
+ // Build and return all conditions
72
+ build(): LogicalOperator[] {
73
+ return [...this.conditions];
74
+ }
75
+
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');
80
+ }
81
+ if (this.conditions.length === 1) {
82
+ return this.conditions[0];
83
+ }
84
+ return LogicalOperator.And(this.conditions);
85
+ }
86
+
87
+ // Clear all conditions
88
+ clear(): ConditionBuilder {
89
+ this.conditions = [];
90
+ this.currentOperator = undefined;
91
+ return this;
92
+ }
93
+
94
+ // Check if any conditions have been added
95
+ isEmpty(): boolean {
96
+ return this.conditions.length === 0;
97
+ }
98
+
99
+ // Get the number of conditions
100
+ getConditionCount(): number {
101
+ return this.conditions.length;
102
+ }
103
+ }
@@ -0,0 +1,2 @@
1
+ // Re-export from operators for convenience
2
+ export { FieldConditionBuilder } from './operators';