@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
@@ -1,327 +0,0 @@
1
- import { FieldConditionBuilder, LogicalOperator, createNestedQuery } from '../operators';
2
-
3
- describe('FieldConditionBuilder', () => {
4
- let builder: FieldConditionBuilder;
5
-
6
- beforeEach(() => {
7
- builder = new FieldConditionBuilder('testField');
8
- });
9
-
10
- describe('Basic operators', () => {
11
- test('equals creates correct condition', () => {
12
- const condition = builder.equals('value');
13
- expect(condition.field).toBe('testField');
14
- expect(condition.operator).toBe('is');
15
- expect(condition.value).toBe('value');
16
- });
17
-
18
- test('notEquals creates correct condition', () => {
19
- const condition = builder.notEquals('value');
20
- expect(condition.field).toBe('testField');
21
- expect(condition.operator).toBe('isNot');
22
- expect(condition.value).toBe('value');
23
- });
24
-
25
- test('greaterThan creates correct condition', () => {
26
- const condition = builder.greaterThan(10);
27
- expect(condition.operator).toBe('greaterThan');
28
- expect(condition.value).toBe(10);
29
- });
30
-
31
- test('lessThan creates correct condition', () => {
32
- const condition = builder.lessThan(10);
33
- expect(condition.operator).toBe('lessThan');
34
- expect(condition.value).toBe(10);
35
- });
36
- });
37
-
38
- describe('String operators', () => {
39
- test('contains creates correct condition', () => {
40
- const condition = builder.contains('substring');
41
- expect(condition.operator).toBe('includes');
42
- expect(condition.value).toBe('substring');
43
- });
44
-
45
- test('startsWith creates correct condition', () => {
46
- const condition = builder.startsWith('prefix');
47
- expect(condition.operator).toBe('startsWith');
48
- expect(condition.value).toBe('prefix');
49
- });
50
-
51
- test('endsWith creates correct condition', () => {
52
- const condition = builder.endsWith('suffix');
53
- expect(condition.operator).toBe('endsWith');
54
- expect(condition.value).toBe('suffix');
55
- });
56
-
57
- test('regExpMatches creates correct condition', () => {
58
- const pattern = '.*test.*';
59
- const condition = builder.regExpMatches(pattern);
60
- expect(condition.operator).toBe('regExpMatches');
61
- expect(condition.value).toBe(pattern);
62
- });
63
- });
64
-
65
- describe('Array operators', () => {
66
- test('in creates correct condition', () => {
67
- const values = [1, 2, 3];
68
- const condition = builder.in(values);
69
- expect(condition.operator).toBe('in');
70
- expect(condition.value).toEqual(values);
71
- });
72
-
73
- test('notIn creates correct condition', () => {
74
- const values = ['a', 'b', 'c'];
75
- const condition = builder.notIn(values);
76
- expect(condition.operator).toBe('notIn');
77
- expect(condition.value).toEqual(values);
78
- });
79
-
80
- test('arrayLength creates correct condition', () => {
81
- const condition = builder.arrayLength(5);
82
- expect(condition.operator).toBe('arrayLength');
83
- expect(condition.value).toBe(5);
84
- });
85
- });
86
-
87
- describe('Null/existence operators', () => {
88
- test('exists creates correct condition', () => {
89
- const condition = builder.exists();
90
- expect(condition.operator).toBe('exists');
91
- expect(condition.value).toBe(true);
92
- });
93
-
94
- test('notExists creates correct condition', () => {
95
- const condition = builder.notExists();
96
- expect(condition.operator).toBe('exists');
97
- expect(condition.value).toBe(false);
98
- });
99
-
100
- test('isNull creates correct condition', () => {
101
- const condition = builder.isNull();
102
- expect(condition.operator).toBe('isNull');
103
- expect(condition.value).toBe(true);
104
- });
105
-
106
- test('isNotNull creates correct condition', () => {
107
- const condition = builder.isNotNull();
108
- expect(condition.operator).toBe('isNull');
109
- expect(condition.value).toBe(false);
110
- });
111
- });
112
-
113
- describe('Date operators', () => {
114
- const testDate = new Date('2024-01-01');
115
-
116
- test('dateEquals creates correct condition', () => {
117
- const condition = builder.dateEquals(testDate);
118
- expect(condition.operator).toBe('dateEquals');
119
- expect(condition.value).toBe(testDate);
120
- });
121
-
122
- test('dateBefore creates correct condition', () => {
123
- const condition = builder.dateBefore(testDate);
124
- expect(condition.operator).toBe('dateBefore');
125
- expect(condition.value).toBe(testDate);
126
- });
127
-
128
- test('dateAfter creates correct condition', () => {
129
- const condition = builder.dateAfter(testDate);
130
- expect(condition.operator).toBe('dateAfter');
131
- expect(condition.value).toBe(testDate);
132
- });
133
-
134
- test('dateToday creates correct condition', () => {
135
- const condition = builder.dateToday();
136
- expect(condition.operator).toBe('dateToday');
137
- expect(condition.value).toBe(true);
138
- });
139
- });
140
-
141
- describe('Numeric operators', () => {
142
- test('between creates correct condition', () => {
143
- const condition = builder.between(10, 20);
144
- expect(condition.operator).toBe('between');
145
- expect(condition.value).toEqual({ min: 10, max: 20 });
146
- });
147
-
148
- test('notBetween creates correct condition', () => {
149
- const condition = builder.notBetween(5, 15);
150
- expect(condition.operator).toBe('notBetween');
151
- expect(condition.value).toEqual({ min: 5, max: 15 });
152
- });
153
- });
154
-
155
- describe('Type checking operators', () => {
156
- test('isString creates correct condition', () => {
157
- const condition = builder.isString();
158
- expect(condition.operator).toBe('isString');
159
- expect(condition.value).toBe(true);
160
- });
161
-
162
- test('isNumber creates correct condition', () => {
163
- const condition = builder.isNumber();
164
- expect(condition.operator).toBe('isNumber');
165
- expect(condition.value).toBe(true);
166
- });
167
-
168
- test('isBoolean creates correct condition', () => {
169
- const condition = builder.isBoolean();
170
- expect(condition.operator).toBe('isBoolean');
171
- expect(condition.value).toBe(true);
172
- });
173
- });
174
-
175
- describe('IP address operators', () => {
176
- test('ipEquals creates correct condition', () => {
177
- const condition = builder.ipEquals('192.168.1.1');
178
- expect(condition.operator).toBe('ipEquals');
179
- expect(condition.value).toBe('192.168.1.1');
180
- });
181
-
182
- test('ipInRange creates correct condition', () => {
183
- const condition = builder.ipInRange('192.168.1.0/24');
184
- expect(condition.operator).toBe('ipInRange');
185
- expect(condition.value).toBe('192.168.1.0/24');
186
- });
187
- });
188
-
189
- describe('Geographical operators', () => {
190
- test('geoWithinRadius creates correct condition', () => {
191
- const condition = builder.geoWithinRadius(40.7128, -74.0060, 10);
192
- expect(condition.operator).toBe('geoWithinRadius');
193
- expect(condition.value).toEqual({
194
- latitude: 40.7128,
195
- longitude: -74.0060,
196
- radiusKm: 10
197
- });
198
- });
199
-
200
- test('geoWithinBounds creates correct condition', () => {
201
- const northEast = { lat: 40.8, lng: -74.0 };
202
- const southWest = { lat: 40.6, lng: -74.2 };
203
- const condition = builder.geoWithinBounds(northEast, southWest);
204
- expect(condition.operator).toBe('geoWithinBounds');
205
- expect(condition.value).toEqual({ northEast, southWest });
206
- });
207
- });
208
- });
209
-
210
- describe('LogicalOperator', () => {
211
- test('Condition creates correct logical operator', () => {
212
- const condition = new FieldConditionBuilder('name').equals('John');
213
- const logicalOp = LogicalOperator.Condition(condition);
214
-
215
- expect(logicalOp.type).toBe('condition');
216
- expect(logicalOp.condition).toBe(condition);
217
- });
218
-
219
- test('And creates correct logical operator', () => {
220
- const condition1 = LogicalOperator.Condition(new FieldConditionBuilder('name').equals('John'));
221
- const condition2 = LogicalOperator.Condition(new FieldConditionBuilder('age').greaterThan(25));
222
-
223
- const andOp = LogicalOperator.And([condition1, condition2]);
224
- expect(andOp.type).toBe('and');
225
- expect(andOp.conditions).toHaveLength(2);
226
- });
227
-
228
- test('Or creates correct logical operator', () => {
229
- const condition1 = LogicalOperator.Condition(new FieldConditionBuilder('status').equals('active'));
230
- const condition2 = LogicalOperator.Condition(new FieldConditionBuilder('status').equals('pending'));
231
-
232
- const orOp = LogicalOperator.Or([condition1, condition2]);
233
- expect(orOp.type).toBe('or');
234
- expect(orOp.conditions).toHaveLength(2);
235
- });
236
-
237
- test('Not creates correct logical operator', () => {
238
- const condition = LogicalOperator.Condition(new FieldConditionBuilder('deleted').isTrue());
239
- const notOp = LogicalOperator.Not([condition]);
240
-
241
- expect(notOp.type).toBe('not');
242
- expect(notOp.conditions).toHaveLength(1);
243
- });
244
- });
245
-
246
- describe('Dot notation', () => {
247
- test('createNestedQuery handles simple field', () => {
248
- const result = createNestedQuery('name', 'is', 'John');
249
- expect(result).toEqual({
250
- name: { is: 'John' }
251
- });
252
- });
253
-
254
- test('createNestedQuery handles nested field', () => {
255
- const result = createNestedQuery('user.profile.name', 'is', 'John');
256
- expect(result).toEqual({
257
- user: {
258
- profile: {
259
- name: {
260
- is: 'John'
261
- }
262
- }
263
- }
264
- });
265
- });
266
-
267
- test('createNestedQuery handles deep nesting', () => {
268
- const result = createNestedQuery('a.b.c.d', 'contains', 'test');
269
- expect(result).toEqual({
270
- a: {
271
- b: {
272
- c: {
273
- d: {
274
- contains: 'test'
275
- }
276
- }
277
- }
278
- }
279
- });
280
- });
281
-
282
- test('LogicalOperator.toComposable integrates with dot notation', () => {
283
- const condition = new FieldConditionBuilder('user.profile.bio').equals('Developer');
284
- const logicalOp = LogicalOperator.Condition(condition);
285
- const composable = logicalOp.toComposable();
286
-
287
- expect(composable).toEqual({
288
- user: {
289
- profile: {
290
- bio: {
291
- is: 'Developer'
292
- }
293
- }
294
- }
295
- });
296
- });
297
-
298
- test('LogicalOperator.toComposable handles complex logical operations', () => {
299
- const condition1 = new FieldConditionBuilder('user.name').equals('John');
300
- const condition2 = new FieldConditionBuilder('user.age').greaterThan(25);
301
-
302
- const andOp = LogicalOperator.And([
303
- LogicalOperator.Condition(condition1),
304
- LogicalOperator.Condition(condition2)
305
- ]);
306
-
307
- const composable = andOp.toComposable();
308
- expect(composable).toEqual({
309
- and: [
310
- {
311
- user: {
312
- name: {
313
- is: 'John'
314
- }
315
- }
316
- },
317
- {
318
- user: {
319
- age: {
320
- greaterThan: 25
321
- }
322
- }
323
- }
324
- ]
325
- });
326
- });
327
- });