@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.
- package/.DS_Store +0 -0
- package/.claude/settings.local.json +8 -0
- package/.gitignore +5 -0
- package/.idea/.gitignore +5 -0
- package/.idea/compiler.xml +6 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/jsLinters/eslint.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +7 -0
- package/.idea/sdk.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +257 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +11 -3
- package/dist/client.js.map +1 -1
- package/dist/database.d.ts +0 -20
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +0 -40
- package/dist/database.js.map +1 -1
- package/dist/query-sdk/tests/setup.d.ts +16 -0
- package/dist/query-sdk/tests/setup.d.ts.map +1 -0
- package/dist/query-sdk/tests/setup.js +49 -0
- package/dist/query-sdk/tests/setup.js.map +1 -0
- package/examples/basic-usage.ts +136 -0
- package/examples/blob-upload-example.ts +140 -0
- package/examples/collection-schema-example.ts +304 -0
- package/examples/server-side-joins.ts +201 -0
- package/examples/tweet-self-joins-example.ts +352 -0
- package/package-lock.json +3823 -0
- package/package.json +1 -1
- package/skills.md +1096 -0
- package/src/.env +1 -0
- package/src/batch.d.ts +121 -0
- package/src/batch.js +205 -0
- package/src/batch.ts +257 -0
- package/src/client.ts +1856 -0
- package/src/database.d.ts +268 -0
- package/src/database.js +294 -0
- package/src/database.ts +695 -0
- package/src/index.d.ts +160 -0
- package/src/index.js +186 -0
- package/src/index.ts +253 -0
- package/src/query-sdk/ConditionBuilder.ts +103 -0
- package/src/query-sdk/FieldConditionBuilder.ts +2 -0
- package/src/query-sdk/NestedBuilders.ts +186 -0
- package/src/query-sdk/OnChainDB.ts +294 -0
- package/src/query-sdk/QueryBuilder.ts +1191 -0
- package/src/query-sdk/QueryResult.ts +375 -0
- package/src/query-sdk/README.md +866 -0
- package/src/query-sdk/SelectionBuilder.ts +94 -0
- package/src/query-sdk/adapters/HttpClientAdapter.ts +249 -0
- package/src/query-sdk/dist/ConditionBuilder.d.ts +22 -0
- package/src/query-sdk/dist/ConditionBuilder.js +90 -0
- package/src/query-sdk/dist/FieldConditionBuilder.d.ts +1 -0
- package/src/query-sdk/dist/FieldConditionBuilder.js +6 -0
- package/src/query-sdk/dist/NestedBuilders.d.ts +43 -0
- package/src/query-sdk/dist/NestedBuilders.js +144 -0
- package/src/query-sdk/dist/OnChainDB.d.ts +19 -0
- package/src/query-sdk/dist/OnChainDB.js +123 -0
- package/src/query-sdk/dist/QueryBuilder.d.ts +70 -0
- package/src/query-sdk/dist/QueryBuilder.js +295 -0
- package/src/query-sdk/dist/QueryResult.d.ts +52 -0
- package/src/query-sdk/dist/QueryResult.js +293 -0
- package/src/query-sdk/dist/SelectionBuilder.d.ts +20 -0
- package/src/query-sdk/dist/SelectionBuilder.js +80 -0
- package/src/query-sdk/dist/adapters/HttpClientAdapter.d.ts +27 -0
- package/src/query-sdk/dist/adapters/HttpClientAdapter.js +170 -0
- package/src/query-sdk/dist/index.d.ts +36 -0
- package/src/query-sdk/dist/index.js +27 -0
- package/src/query-sdk/dist/operators.d.ts +56 -0
- package/src/query-sdk/dist/operators.js +289 -0
- package/src/query-sdk/dist/tests/setup.d.ts +15 -0
- package/src/query-sdk/dist/tests/setup.js +46 -0
- package/src/query-sdk/index.ts +59 -0
- package/src/query-sdk/jest.config.js +25 -0
- package/src/query-sdk/operators.ts +335 -0
- package/src/query-sdk/package.json +46 -0
- package/src/query-sdk/tests/FieldConditionBuilder.test.ts +84 -0
- package/src/query-sdk/tests/LogicalOperator.test.ts +85 -0
- package/src/query-sdk/tests/NestedBuilders.test.ts +321 -0
- package/src/query-sdk/tests/QueryBuilder.test.ts +348 -0
- package/src/query-sdk/tests/QueryResult.test.ts +464 -0
- package/src/query-sdk/tests/aggregations.test.ts +653 -0
- package/src/query-sdk/tests/comprehensive.test.ts +279 -0
- package/src/query-sdk/tests/integration.test.ts +608 -0
- package/src/query-sdk/tests/operators.test.ts +327 -0
- package/src/query-sdk/tests/setup.ts +59 -0
- package/src/query-sdk/tests/unit.test.ts +794 -0
- package/src/query-sdk/tsconfig.json +26 -0
- package/src/query-sdk/yarn.lock +3092 -0
- package/src/types.d.ts +131 -0
- package/src/types.js +46 -0
- package/src/types.ts +534 -0
- package/src/x402/index.ts +12 -0
- package/src/x402/types.ts +250 -0
- package/src/x402/utils.ts +332 -0
- package/tsconfig.json +20 -0
- package/yarn.lock +2309 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { BetweenValue, DateRange, Val } from './index';
|
|
2
|
+
export interface Condition {
|
|
3
|
+
field: string;
|
|
4
|
+
operator: string;
|
|
5
|
+
value: Val | BetweenValue | DateRange;
|
|
6
|
+
}
|
|
7
|
+
export declare function createNestedQuery(fieldPath: string, operator: string, value: Val | BetweenValue | DateRange): any;
|
|
8
|
+
export declare enum LogicalOperatorType {
|
|
9
|
+
AND = "and",
|
|
10
|
+
OR = "or",
|
|
11
|
+
NOT = "not",
|
|
12
|
+
CONDITION = "condition"
|
|
13
|
+
}
|
|
14
|
+
export declare class LogicalOperator {
|
|
15
|
+
type: LogicalOperatorType;
|
|
16
|
+
conditions: LogicalOperator[];
|
|
17
|
+
condition?: Condition | undefined;
|
|
18
|
+
constructor(type: LogicalOperatorType, conditions?: LogicalOperator[], condition?: Condition | undefined);
|
|
19
|
+
static And(conditions: LogicalOperator[]): LogicalOperator;
|
|
20
|
+
static Or(conditions: LogicalOperator[]): LogicalOperator;
|
|
21
|
+
static Not(conditions: LogicalOperator[]): LogicalOperator;
|
|
22
|
+
static Condition(condition: Condition): LogicalOperator;
|
|
23
|
+
toComposable(): any;
|
|
24
|
+
}
|
|
25
|
+
export declare class FieldConditionBuilder {
|
|
26
|
+
private fieldName;
|
|
27
|
+
constructor(fieldName: string);
|
|
28
|
+
equals(value: Val): Condition;
|
|
29
|
+
notEquals(value: Val): Condition;
|
|
30
|
+
in(values: Val[]): Condition;
|
|
31
|
+
notIn(values: Val[]): Condition;
|
|
32
|
+
isNull(): Condition;
|
|
33
|
+
isNotNull(): Condition;
|
|
34
|
+
exists(): Condition;
|
|
35
|
+
notExists(): Condition;
|
|
36
|
+
startsWith(value: string): Condition;
|
|
37
|
+
endsWith(value: string): Condition;
|
|
38
|
+
contains(value: string): Condition;
|
|
39
|
+
regExpMatches(pattern: string): Condition;
|
|
40
|
+
includesCaseInsensitive(value: string): Condition;
|
|
41
|
+
startsWithCaseInsensitive(value: string): Condition;
|
|
42
|
+
endsWithCaseInsensitive(value: string): Condition;
|
|
43
|
+
greaterThan(value: Val): Condition;
|
|
44
|
+
lessThan(value: Val): Condition;
|
|
45
|
+
greaterThanOrEqual(value: Val): Condition;
|
|
46
|
+
lessThanOrEqual(value: Val): Condition;
|
|
47
|
+
isLocalIp(): Condition;
|
|
48
|
+
isExternalIp(): Condition;
|
|
49
|
+
b64(value: string): Condition;
|
|
50
|
+
inDataset(dataset: string): Condition;
|
|
51
|
+
inCountry(countryCode: string): Condition;
|
|
52
|
+
cidr(cidr: string): Condition;
|
|
53
|
+
between(min: Val, max: Val): Condition;
|
|
54
|
+
isTrue(): Condition;
|
|
55
|
+
isFalse(): Condition;
|
|
56
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FieldConditionBuilder = exports.LogicalOperator = exports.LogicalOperatorType = void 0;
|
|
4
|
+
exports.createNestedQuery = createNestedQuery;
|
|
5
|
+
// Helper function to convert dot notation paths to nested structures
|
|
6
|
+
function createNestedQuery(fieldPath, operator, value) {
|
|
7
|
+
if (!fieldPath.includes('.')) {
|
|
8
|
+
return {
|
|
9
|
+
[fieldPath]: {
|
|
10
|
+
[operator]: value
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const pathParts = fieldPath.split('.');
|
|
15
|
+
let result = {
|
|
16
|
+
[operator]: value
|
|
17
|
+
};
|
|
18
|
+
// Build nested structure from inside out
|
|
19
|
+
for (let i = pathParts.length - 1; i >= 0; i--) {
|
|
20
|
+
const part = pathParts[i];
|
|
21
|
+
if (i === pathParts.length - 1) {
|
|
22
|
+
result = {
|
|
23
|
+
[part]: result
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
result = {
|
|
28
|
+
[part]: result
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
// Logical operators for combining conditions
|
|
35
|
+
var LogicalOperatorType;
|
|
36
|
+
(function (LogicalOperatorType) {
|
|
37
|
+
LogicalOperatorType["AND"] = "and";
|
|
38
|
+
LogicalOperatorType["OR"] = "or";
|
|
39
|
+
LogicalOperatorType["NOT"] = "not";
|
|
40
|
+
LogicalOperatorType["CONDITION"] = "condition";
|
|
41
|
+
})(LogicalOperatorType || (exports.LogicalOperatorType = LogicalOperatorType = {}));
|
|
42
|
+
class LogicalOperator {
|
|
43
|
+
constructor(type, conditions = [], condition) {
|
|
44
|
+
this.type = type;
|
|
45
|
+
this.conditions = conditions;
|
|
46
|
+
this.condition = condition;
|
|
47
|
+
}
|
|
48
|
+
static And(conditions) {
|
|
49
|
+
return new LogicalOperator(LogicalOperatorType.AND, conditions);
|
|
50
|
+
}
|
|
51
|
+
static Or(conditions) {
|
|
52
|
+
return new LogicalOperator(LogicalOperatorType.OR, conditions);
|
|
53
|
+
}
|
|
54
|
+
static Not(conditions) {
|
|
55
|
+
return new LogicalOperator(LogicalOperatorType.NOT, conditions);
|
|
56
|
+
}
|
|
57
|
+
static Condition(condition) {
|
|
58
|
+
return new LogicalOperator(LogicalOperatorType.CONDITION, [], condition);
|
|
59
|
+
}
|
|
60
|
+
// Convert to composable query structure for HTTP requests
|
|
61
|
+
toComposable() {
|
|
62
|
+
switch (this.type) {
|
|
63
|
+
case LogicalOperatorType.AND:
|
|
64
|
+
return {
|
|
65
|
+
[LogicalOperatorType.AND]: this.conditions.map(c => c.toComposable())
|
|
66
|
+
};
|
|
67
|
+
case LogicalOperatorType.OR:
|
|
68
|
+
return {
|
|
69
|
+
[LogicalOperatorType.OR]: this.conditions.map(c => c.toComposable())
|
|
70
|
+
};
|
|
71
|
+
case LogicalOperatorType.NOT:
|
|
72
|
+
return {
|
|
73
|
+
[LogicalOperatorType.NOT]: this.conditions.map(c => c.toComposable())
|
|
74
|
+
};
|
|
75
|
+
case LogicalOperatorType.CONDITION:
|
|
76
|
+
if (!this.condition)
|
|
77
|
+
throw new Error('Condition is required for CONDITION type');
|
|
78
|
+
// Use dot notation helper to create nested structures
|
|
79
|
+
return createNestedQuery(this.condition.field, this.condition.operator, this.condition.value);
|
|
80
|
+
default:
|
|
81
|
+
throw new Error(`Unknown logical operator type: ${this.type}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.LogicalOperator = LogicalOperator;
|
|
86
|
+
// Field condition builder for creating individual field conditions
|
|
87
|
+
// Only includes operators that actually exist in the Rust implementation
|
|
88
|
+
class FieldConditionBuilder {
|
|
89
|
+
constructor(fieldName) {
|
|
90
|
+
this.fieldName = fieldName;
|
|
91
|
+
}
|
|
92
|
+
// ===== BASE OPERATORS (BaseOperator) =====
|
|
93
|
+
equals(value) {
|
|
94
|
+
return {
|
|
95
|
+
field: this.fieldName,
|
|
96
|
+
operator: 'is',
|
|
97
|
+
value
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
notEquals(value) {
|
|
101
|
+
return {
|
|
102
|
+
field: this.fieldName,
|
|
103
|
+
operator: 'isNot',
|
|
104
|
+
value
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
in(values) {
|
|
108
|
+
return {
|
|
109
|
+
field: this.fieldName,
|
|
110
|
+
operator: 'in',
|
|
111
|
+
value: values
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
notIn(values) {
|
|
115
|
+
return {
|
|
116
|
+
field: this.fieldName,
|
|
117
|
+
operator: 'notIn',
|
|
118
|
+
value: values
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
isNull() {
|
|
122
|
+
return {
|
|
123
|
+
field: this.fieldName,
|
|
124
|
+
operator: 'isNull',
|
|
125
|
+
value: true
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
isNotNull() {
|
|
129
|
+
return {
|
|
130
|
+
field: this.fieldName,
|
|
131
|
+
operator: 'isNull',
|
|
132
|
+
value: false
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
exists() {
|
|
136
|
+
return {
|
|
137
|
+
field: this.fieldName,
|
|
138
|
+
operator: 'exists',
|
|
139
|
+
value: true
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
notExists() {
|
|
143
|
+
return {
|
|
144
|
+
field: this.fieldName,
|
|
145
|
+
operator: 'exists',
|
|
146
|
+
value: false
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// ===== STRING OPERATORS (StringOperator) =====
|
|
150
|
+
startsWith(value) {
|
|
151
|
+
return {
|
|
152
|
+
field: this.fieldName,
|
|
153
|
+
operator: 'startsWith',
|
|
154
|
+
value
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
endsWith(value) {
|
|
158
|
+
return {
|
|
159
|
+
field: this.fieldName,
|
|
160
|
+
operator: 'endsWith',
|
|
161
|
+
value
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
contains(value) {
|
|
165
|
+
return {
|
|
166
|
+
field: this.fieldName,
|
|
167
|
+
operator: 'includes',
|
|
168
|
+
value
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
regExpMatches(pattern) {
|
|
172
|
+
return {
|
|
173
|
+
field: this.fieldName,
|
|
174
|
+
operator: 'regExpMatches',
|
|
175
|
+
value: pattern
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
includesCaseInsensitive(value) {
|
|
179
|
+
return {
|
|
180
|
+
field: this.fieldName,
|
|
181
|
+
operator: 'includesCaseInsensitive',
|
|
182
|
+
value
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
startsWithCaseInsensitive(value) {
|
|
186
|
+
return {
|
|
187
|
+
field: this.fieldName,
|
|
188
|
+
operator: 'startsWithCaseInsensitive',
|
|
189
|
+
value
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
endsWithCaseInsensitive(value) {
|
|
193
|
+
return {
|
|
194
|
+
field: this.fieldName,
|
|
195
|
+
operator: 'endsWithCaseInsensitive',
|
|
196
|
+
value
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
// ===== NUMBER OPERATORS (NumberOperator) =====
|
|
200
|
+
greaterThan(value) {
|
|
201
|
+
return {
|
|
202
|
+
field: this.fieldName,
|
|
203
|
+
operator: 'greaterThan',
|
|
204
|
+
value
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
lessThan(value) {
|
|
208
|
+
return {
|
|
209
|
+
field: this.fieldName,
|
|
210
|
+
operator: 'lessThan',
|
|
211
|
+
value
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
greaterThanOrEqual(value) {
|
|
215
|
+
return {
|
|
216
|
+
field: this.fieldName,
|
|
217
|
+
operator: 'greaterThanOrEqual',
|
|
218
|
+
value
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
lessThanOrEqual(value) {
|
|
222
|
+
return {
|
|
223
|
+
field: this.fieldName,
|
|
224
|
+
operator: 'lessThanOrEqual',
|
|
225
|
+
value
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
// ===== IP OPERATORS (IpOperator) =====
|
|
229
|
+
isLocalIp() {
|
|
230
|
+
return {
|
|
231
|
+
field: this.fieldName,
|
|
232
|
+
operator: 'isLocalIp',
|
|
233
|
+
value: true
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
isExternalIp() {
|
|
237
|
+
return {
|
|
238
|
+
field: this.fieldName,
|
|
239
|
+
operator: 'isExternalIp',
|
|
240
|
+
value: true
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
// ===== MISC OPERATORS (MiscOperator) =====
|
|
244
|
+
b64(value) {
|
|
245
|
+
return {
|
|
246
|
+
field: this.fieldName,
|
|
247
|
+
operator: 'b64',
|
|
248
|
+
value
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
inDataset(dataset) {
|
|
252
|
+
return {
|
|
253
|
+
field: this.fieldName,
|
|
254
|
+
operator: 'inDataset',
|
|
255
|
+
value: dataset
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
inCountry(countryCode) {
|
|
259
|
+
return {
|
|
260
|
+
field: this.fieldName,
|
|
261
|
+
operator: 'inCountry',
|
|
262
|
+
value: countryCode
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
cidr(cidr) {
|
|
266
|
+
return {
|
|
267
|
+
field: this.fieldName,
|
|
268
|
+
operator: 'CIDR',
|
|
269
|
+
value: cidr
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
// ===== BETWEEN OPERATOR =====
|
|
273
|
+
between(min, max) {
|
|
274
|
+
return {
|
|
275
|
+
field: this.fieldName,
|
|
276
|
+
operator: 'betweenOp',
|
|
277
|
+
value: { from: min, to: max }
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
// ===== CONVENIENCE METHODS =====
|
|
281
|
+
// Boolean checks (using base operators)
|
|
282
|
+
isTrue() {
|
|
283
|
+
return this.equals(true);
|
|
284
|
+
}
|
|
285
|
+
isFalse() {
|
|
286
|
+
return this.equals(false);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
exports.FieldConditionBuilder = FieldConditionBuilder;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'jest';
|
|
2
|
+
export declare const createMockResponse: (data: any) => {
|
|
3
|
+
data: {
|
|
4
|
+
records: any[];
|
|
5
|
+
total: number;
|
|
6
|
+
page: number;
|
|
7
|
+
limit: number;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare class MockHttpClient {
|
|
11
|
+
private responses;
|
|
12
|
+
setResponse(url: string, response: any): void;
|
|
13
|
+
post(url: string, data: any, headers?: Record<string, string>): Promise<any>;
|
|
14
|
+
clear(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Jest setup file for global test configuration
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.MockHttpClient = exports.createMockResponse = void 0;
|
|
5
|
+
// Extend Jest matchers if needed
|
|
6
|
+
require("jest");
|
|
7
|
+
// Global test timeout
|
|
8
|
+
jest.setTimeout(30000);
|
|
9
|
+
// Mock console methods for cleaner test output
|
|
10
|
+
const originalConsoleError = console.error;
|
|
11
|
+
const originalConsoleWarn = console.warn;
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
console.error = jest.fn();
|
|
14
|
+
console.warn = jest.fn();
|
|
15
|
+
});
|
|
16
|
+
afterAll(() => {
|
|
17
|
+
console.error = originalConsoleError;
|
|
18
|
+
console.warn = originalConsoleWarn;
|
|
19
|
+
});
|
|
20
|
+
// Helper function to create mock HTTP responses
|
|
21
|
+
const createMockResponse = (data) => ({
|
|
22
|
+
data: {
|
|
23
|
+
records: Array.isArray(data) ? data : [data],
|
|
24
|
+
total: Array.isArray(data) ? data.length : 1,
|
|
25
|
+
page: 1,
|
|
26
|
+
limit: 10
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
exports.createMockResponse = createMockResponse;
|
|
30
|
+
// Mock HTTP client for tests
|
|
31
|
+
class MockHttpClient {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.responses = new Map();
|
|
34
|
+
}
|
|
35
|
+
setResponse(url, response) {
|
|
36
|
+
this.responses.set(url, response);
|
|
37
|
+
}
|
|
38
|
+
async post(url, data, headers) {
|
|
39
|
+
const response = this.responses.get(url) || (0, exports.createMockResponse)([]);
|
|
40
|
+
return Promise.resolve(response);
|
|
41
|
+
}
|
|
42
|
+
clear() {
|
|
43
|
+
this.responses.clear();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.MockHttpClient = MockHttpClient;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// HTTP Client Interface for dependency injection
|
|
2
|
+
export interface HttpClient {
|
|
3
|
+
post(url: string, data: any, headers?: Record<string, string>): Promise<any>;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Query types matching Rust SDK structure
|
|
7
|
+
export interface QueryValue {
|
|
8
|
+
find: any;
|
|
9
|
+
select: any;
|
|
10
|
+
include_history?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type QueryRequest = QueryValue & {
|
|
14
|
+
limit?: number;
|
|
15
|
+
offset?: number;
|
|
16
|
+
sort?: string[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface QueryResponse<T = any> {
|
|
20
|
+
records: T[];
|
|
21
|
+
total?: number;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Selection types
|
|
26
|
+
export type SelectionMap = Record<string, any>;
|
|
27
|
+
export type FieldMap = Record<string, string>;
|
|
28
|
+
|
|
29
|
+
// Operator values - expanded to match Rust SDK
|
|
30
|
+
export type Val = string | number | boolean | null | Val[] | Date | RegExp;
|
|
31
|
+
|
|
32
|
+
// Extended operator types to match Rust SDK
|
|
33
|
+
export interface BetweenValue {
|
|
34
|
+
min: Val;
|
|
35
|
+
max: Val;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface DateRange {
|
|
39
|
+
start: Date | string | number;
|
|
40
|
+
end: Date | string | number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Main SDK exports
|
|
44
|
+
export {OnChainDB} from './OnChainDB';
|
|
45
|
+
export {QueryBuilder, JoinBuilder, ServerJoinConfig, GroupByQueryBuilder} from './QueryBuilder';
|
|
46
|
+
export {SelectionBuilder} from './SelectionBuilder';
|
|
47
|
+
export {ConditionBuilder} from './ConditionBuilder';
|
|
48
|
+
export {FieldConditionBuilder, LogicalOperator, Condition} from './operators';
|
|
49
|
+
export {NestedConditionBuilder, NestedFieldConditionBuilder} from './NestedBuilders';
|
|
50
|
+
export {QueryResult, NumericSummary, createQueryResult} from './QueryResult';
|
|
51
|
+
|
|
52
|
+
// HTTP Client adapters
|
|
53
|
+
export {
|
|
54
|
+
FetchHttpClient,
|
|
55
|
+
AxiosHttpClient,
|
|
56
|
+
NodeHttpClient,
|
|
57
|
+
createHttpClient
|
|
58
|
+
} from './adapters/HttpClientAdapter';
|
|
59
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
roots: ['<rootDir>/tests'],
|
|
5
|
+
testMatch: [
|
|
6
|
+
'**/__tests__/**/*.ts',
|
|
7
|
+
'**/?(*.)+(spec|test).ts'
|
|
8
|
+
],
|
|
9
|
+
transform: {
|
|
10
|
+
'^.+\\.ts$': 'ts-jest',
|
|
11
|
+
},
|
|
12
|
+
collectCoverageFrom: [
|
|
13
|
+
'**/*.ts',
|
|
14
|
+
'!**/*.d.ts',
|
|
15
|
+
'!**/node_modules/**',
|
|
16
|
+
'!**/tests/**',
|
|
17
|
+
],
|
|
18
|
+
coverageDirectory: 'coverage',
|
|
19
|
+
coverageReporters: [
|
|
20
|
+
'text',
|
|
21
|
+
'lcov',
|
|
22
|
+
'html'
|
|
23
|
+
],
|
|
24
|
+
setupFilesAfterEnv: ['<rootDir>/tests/setup.ts']
|
|
25
|
+
};
|