@onchaindb/sdk 0.4.4 → 1.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 (97) 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 +29 -43
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +199 -323
  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 +6 -9
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -15
  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/dist/query-sdk/QueryBuilder.d.ts +4 -2
  28. package/dist/query-sdk/QueryBuilder.d.ts.map +1 -1
  29. package/dist/query-sdk/QueryBuilder.js +47 -169
  30. package/dist/query-sdk/QueryBuilder.js.map +1 -1
  31. package/dist/query-sdk/QueryResult.d.ts +0 -38
  32. package/dist/query-sdk/QueryResult.d.ts.map +1 -1
  33. package/dist/query-sdk/QueryResult.js +1 -227
  34. package/dist/query-sdk/QueryResult.js.map +1 -1
  35. package/dist/query-sdk/index.d.ts +1 -1
  36. package/dist/query-sdk/index.d.ts.map +1 -1
  37. package/dist/query-sdk/index.js.map +1 -1
  38. package/dist/query-sdk/operators.d.ts +32 -28
  39. package/dist/query-sdk/operators.d.ts.map +1 -1
  40. package/dist/query-sdk/operators.js +45 -155
  41. package/dist/query-sdk/operators.js.map +1 -1
  42. package/dist/types.d.ts +153 -1
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/types.js.map +1 -1
  45. package/jest.config.js +4 -0
  46. package/package.json +1 -1
  47. package/skills.md +0 -1
  48. package/src/client.ts +243 -745
  49. package/src/database.ts +70 -493
  50. package/src/index.ts +40 -193
  51. package/src/query-sdk/ConditionBuilder.ts +37 -89
  52. package/src/query-sdk/NestedBuilders.ts +90 -92
  53. package/src/query-sdk/QueryBuilder.ts +59 -218
  54. package/src/query-sdk/QueryResult.ts +4 -330
  55. package/src/query-sdk/README.md +214 -583
  56. package/src/query-sdk/index.ts +1 -1
  57. package/src/query-sdk/operators.ts +91 -200
  58. package/src/query-sdk/tests/FieldConditionBuilder.test.ts +70 -71
  59. package/src/query-sdk/tests/LogicalOperator.test.ts +43 -82
  60. package/src/query-sdk/tests/NestedBuilders.test.ts +229 -309
  61. package/src/query-sdk/tests/QueryBuilder.test.ts +5 -5
  62. package/src/query-sdk/tests/QueryResult.test.ts +41 -435
  63. package/src/query-sdk/tests/comprehensive.test.ts +4 -185
  64. package/src/tests/client-requests.test.ts +280 -0
  65. package/src/tests/client-validation.test.ts +80 -0
  66. package/src/types.ts +229 -8
  67. package/src/batch.ts +0 -257
  68. package/src/query-sdk/dist/ConditionBuilder.d.ts +0 -22
  69. package/src/query-sdk/dist/ConditionBuilder.js +0 -90
  70. package/src/query-sdk/dist/FieldConditionBuilder.d.ts +0 -1
  71. package/src/query-sdk/dist/FieldConditionBuilder.js +0 -6
  72. package/src/query-sdk/dist/NestedBuilders.d.ts +0 -43
  73. package/src/query-sdk/dist/NestedBuilders.js +0 -144
  74. package/src/query-sdk/dist/OnChainDB.d.ts +0 -19
  75. package/src/query-sdk/dist/OnChainDB.js +0 -123
  76. package/src/query-sdk/dist/QueryBuilder.d.ts +0 -70
  77. package/src/query-sdk/dist/QueryBuilder.js +0 -295
  78. package/src/query-sdk/dist/QueryResult.d.ts +0 -52
  79. package/src/query-sdk/dist/QueryResult.js +0 -293
  80. package/src/query-sdk/dist/SelectionBuilder.d.ts +0 -20
  81. package/src/query-sdk/dist/SelectionBuilder.js +0 -80
  82. package/src/query-sdk/dist/adapters/HttpClientAdapter.d.ts +0 -27
  83. package/src/query-sdk/dist/adapters/HttpClientAdapter.js +0 -170
  84. package/src/query-sdk/dist/index.d.ts +0 -36
  85. package/src/query-sdk/dist/index.js +0 -27
  86. package/src/query-sdk/dist/operators.d.ts +0 -56
  87. package/src/query-sdk/dist/operators.js +0 -289
  88. package/src/query-sdk/dist/tests/setup.d.ts +0 -15
  89. package/src/query-sdk/dist/tests/setup.js +0 -46
  90. package/src/query-sdk/jest.config.js +0 -25
  91. package/src/query-sdk/package.json +0 -46
  92. package/src/query-sdk/tests/aggregations.test.ts +0 -653
  93. package/src/query-sdk/tests/integration.test.ts +0 -608
  94. package/src/query-sdk/tests/operators.test.ts +0 -327
  95. package/src/query-sdk/tests/unit.test.ts +0 -794
  96. package/src/query-sdk/tsconfig.json +0 -26
  97. 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
- });