@onchaindb/sdk 2.0.1 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/.claude/settings.local.json +5 -1
  2. package/.gitignore +1 -0
  3. package/README.md +0 -1
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +0 -5
  6. package/dist/client.js.map +1 -1
  7. package/dist/database.d.ts +46 -8
  8. package/dist/database.d.ts.map +1 -1
  9. package/dist/database.js +32 -9
  10. package/dist/database.js.map +1 -1
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +4 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/query-sdk/NestedBuilders.d.ts +3 -2
  16. package/dist/query-sdk/NestedBuilders.d.ts.map +1 -1
  17. package/dist/query-sdk/NestedBuilders.js +7 -4
  18. package/dist/query-sdk/NestedBuilders.js.map +1 -1
  19. package/dist/query-sdk/QueryBuilder.d.ts +17 -15
  20. package/dist/query-sdk/QueryBuilder.d.ts.map +1 -1
  21. package/dist/query-sdk/QueryBuilder.js +126 -190
  22. package/dist/query-sdk/QueryBuilder.js.map +1 -1
  23. package/dist/query-sdk/index.d.ts +24 -1
  24. package/dist/query-sdk/index.d.ts.map +1 -1
  25. package/dist/query-sdk/index.js.map +1 -1
  26. package/dist/query-sdk/operators.d.ts +3 -2
  27. package/dist/query-sdk/operators.d.ts.map +1 -1
  28. package/dist/query-sdk/operators.js +7 -4
  29. package/dist/query-sdk/operators.js.map +1 -1
  30. package/dist/types.d.ts +17 -13
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/types.js.map +1 -1
  33. package/package.json +1 -1
  34. package/skills.md +5 -5
  35. package/src/client.ts +0 -6
  36. package/src/database.ts +159 -26
  37. package/src/index.ts +23 -10
  38. package/src/query-sdk/NestedBuilders.ts +14 -4
  39. package/src/query-sdk/QueryBuilder.ts +212 -235
  40. package/src/query-sdk/index.ts +19 -1
  41. package/src/query-sdk/operators.ts +15 -4
  42. package/src/query-sdk/tests/FieldConditionBuilder.test.ts +4 -2
  43. package/src/query-sdk/tests/NestedBuilders.test.ts +4 -3
  44. package/src/types.ts +26 -17
  45. package/.DS_Store +0 -0
@@ -202,16 +202,27 @@ export class FieldConditionBuilder {
202
202
  return this.cond('b64', value);
203
203
  }
204
204
 
205
- inDataset(dataset: string): LogicalOperator {
206
- return this.cond('inDataset', dataset);
205
+ /** Case-sensitive membership check — use this when exact casing matters. For case-insensitive use .in() */
206
+ inDataset(values: string[]): LogicalOperator {
207
+ return this.cond('inDataset', values as any);
207
208
  }
208
209
 
209
210
  inCountry(countryCode: string): LogicalOperator {
210
211
  return this.cond('inCountry', countryCode);
211
212
  }
212
213
 
213
- cidr(cidr: string): LogicalOperator {
214
- return this.cond('CIDR', cidr);
214
+ /**
215
+ * Checks whether the data IP falls within any of the given CIDR ranges.
216
+ * IMPORTANT: always sends the "$cidr" alias — never the canonical "CIDR" key,
217
+ * which triggers a stack overflow in Scepter's recursive Operator enum.
218
+ */
219
+ cidr(ranges: string | string[]): LogicalOperator {
220
+ return this.cond('$cidr', (Array.isArray(ranges) ? ranges : [ranges]) as any);
221
+ }
222
+
223
+ /** Matches if the field value contains ANY of the given keywords (case-insensitive substring). */
224
+ keywords(keywords: string[]): LogicalOperator {
225
+ return this.cond('keywords', keywords as any);
215
226
  }
216
227
 
217
228
  // ===== CONVENIENCE =====
@@ -48,9 +48,11 @@ describe('FieldConditionBuilder', () => {
48
48
  test('isLocalIp', () => expect(builder.isLocalIp().toComposable()).toEqual({ field: { isLocalIp: true } }));
49
49
  test('isExternalIp', () => expect(builder.isExternalIp().toComposable()).toEqual({ field: { isExternalIp: true } }));
50
50
  test('b64', () => expect(builder.b64('dGVzdA==').toComposable()).toEqual({ field: { b64: 'dGVzdA==' } }));
51
- test('inDataset', () => expect(builder.inDataset('malware_ips').toComposable()).toEqual({ field: { inDataset: 'malware_ips' } }));
51
+ test('inDataset', () => expect(builder.inDataset(['admin', 'moderator']).toComposable()).toEqual({ field: { inDataset: ['admin', 'moderator'] } }));
52
52
  test('inCountry', () => expect(builder.inCountry('US').toComposable()).toEqual({ field: { inCountry: 'US' } }));
53
- test('cidr', () => expect(builder.cidr('192.168.1.0/24').toComposable()).toEqual({ field: { CIDR: '192.168.1.0/24' } }));
53
+ test('cidr single', () => expect(builder.cidr('192.168.1.0/24').toComposable()).toEqual({ field: { '$cidr': ['192.168.1.0/24'] } }));
54
+ test('cidr array', () => expect(builder.cidr(['192.168.0.0/16', '10.0.0.0/8']).toComposable()).toEqual({ field: { '$cidr': ['192.168.0.0/16', '10.0.0.0/8'] } }));
55
+ test('keywords', () => expect(builder.keywords(['rust', 'async']).toComposable()).toEqual({ field: { keywords: ['rust', 'async'] } }));
54
56
  });
55
57
 
56
58
  describe('Dot-notation fields', () => {
@@ -171,11 +171,12 @@ describe('NestedFieldConditionBuilder', () => {
171
171
  });
172
172
 
173
173
  describe('Misc operators', () => {
174
- test('b64, inCountry, inDataset, cidr', () => {
174
+ test('b64, inCountry, inDataset, cidr, keywords', () => {
175
175
  expect(fieldBuilder.b64('dGVzdA==').condition?.operator).toBe('b64');
176
176
  expect(fieldBuilder.inCountry('US').condition?.operator).toBe('inCountry');
177
- expect(fieldBuilder.inDataset('malware_ips').condition?.operator).toBe('inDataset');
178
- expect(fieldBuilder.cidr('192.168.1.0/24').condition?.operator).toBe('CIDR');
177
+ expect(fieldBuilder.inDataset(['admin', 'moderator']).condition?.operator).toBe('inDataset');
178
+ expect(fieldBuilder.cidr('192.168.1.0/24').condition?.operator).toBe('$cidr');
179
+ expect(fieldBuilder.keywords(['rust', 'async']).condition?.operator).toBe('keywords');
179
180
  });
180
181
 
181
182
  test('IP operators', () => {
package/src/types.ts CHANGED
@@ -6,7 +6,6 @@ export interface OnDBConfig {
6
6
  endpoint: string;
7
7
  apiKey?: string; // Deprecated: use appKey instead
8
8
  appKey?: string; // App API key for write operations (X-App-Key header)
9
- userKey?: string; // User API key for Auto-Pay (X-User-Key header)
10
9
  agentKey?: string; // Agent Key with Pay permission (X-Agent-Key header)
11
10
  appId?: string; // Application ID for automatic root building
12
11
  timeout?: number;
@@ -118,11 +117,6 @@ export interface TaskInfo {
118
117
  progress_log: string[];
119
118
  }
120
119
 
121
- export interface UserTasksResponse {
122
- user_address: string;
123
- tasks: TaskInfo[];
124
- total_tasks: number;
125
- }
126
120
 
127
121
  export interface TransactionStatus {
128
122
  id: string;
@@ -140,9 +134,12 @@ export interface QueryRequest {
140
134
  limit?: number;
141
135
  offset?: number;
142
136
  sortBy?: string;
143
- sortDirection?: string,
144
- find?: QueryValue["find"],
145
- select?: QueryValue["select"],
137
+ sortDirection?: string;
138
+ find?: QueryValue["find"];
139
+ select?: QueryValue["select"];
140
+ field_map?: QueryValue["field_map"];
141
+ group_by?: QueryValue["group_by"];
142
+ aggregate?: QueryValue["aggregate"];
146
143
  }
147
144
 
148
145
  // Enhanced query support for advanced query builder
@@ -252,18 +249,28 @@ export class PaymentVerificationError extends OnDBError {
252
249
  }
253
250
  }
254
251
 
255
- // Index Management
252
+ // Index Management — mirrors CreateIndexRequest from broker (handlers/indexes.rs)
256
253
  export interface IndexRequest {
254
+ name: string;
257
255
  collection: string;
258
- field: string;
259
- type: 'string' | 'number' | 'boolean' | 'date';
256
+ field_name: string;
257
+ index_type: 'btree' | 'hash' | 'fulltext' | 'composite' | 'price';
258
+ store_values?: boolean;
259
+ unique_constraint?: boolean;
260
+ sort_enabled?: boolean;
261
+ /** Write-time payment config — only for index_type: 'price'. */
262
+ price_config?: import('./database').WriteIndexConfig;
263
+ /** Read-time payment config. */
264
+ read_price_config?: import('./database').ReadIndexConfig;
265
+ /** Creator revenue sharing config. */
266
+ creator_premium_config?: import('./database').CreatorPremiumConfig;
260
267
  }
261
268
 
262
269
  export interface IndexResponse {
263
270
  id: string;
264
271
  collection: string;
265
- field: string;
266
- type: string;
272
+ field_name: string;
273
+ index_type: string;
267
274
  status: 'active' | 'building' | 'failed';
268
275
  }
269
276
 
@@ -337,7 +344,9 @@ export interface PricingQuoteRequest {
337
344
  export type {
338
345
  Index,
339
346
  IndexOptions,
340
- PriceConfig,
347
+ WriteIndexConfig,
348
+ ReadIndexConfig,
349
+ CreatorPremiumConfig,
341
350
  } from './database';
342
351
 
343
352
  /**
@@ -691,8 +700,8 @@ export interface ViewDataResponse<T = any> {
691
700
  }
692
701
 
693
702
  export interface ViewQueryRequest {
694
- find?: any;
695
- select?: string[];
703
+ find?: Record<string, any>;
704
+ select?: Record<string, boolean>;
696
705
  sort_by?: string[];
697
706
  limit?: number;
698
707
  offset?: number;
package/.DS_Store DELETED
Binary file