@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.
- package/.claude/settings.local.json +10 -2
- package/README.md +422 -355
- package/dist/batch.d.ts +1 -10
- package/dist/batch.d.ts.map +1 -1
- package/dist/batch.js +4 -26
- package/dist/batch.js.map +1 -1
- package/dist/client.d.ts +29 -43
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +199 -323
- package/dist/client.js.map +1 -1
- package/dist/database.d.ts +14 -131
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +35 -131
- package/dist/database.js.map +1 -1
- package/dist/index.d.ts +6 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -15
- package/dist/index.js.map +1 -1
- package/dist/query-sdk/ConditionBuilder.d.ts +3 -11
- package/dist/query-sdk/ConditionBuilder.d.ts.map +1 -1
- package/dist/query-sdk/ConditionBuilder.js +10 -48
- package/dist/query-sdk/ConditionBuilder.js.map +1 -1
- package/dist/query-sdk/NestedBuilders.d.ts +33 -30
- package/dist/query-sdk/NestedBuilders.d.ts.map +1 -1
- package/dist/query-sdk/NestedBuilders.js +46 -43
- package/dist/query-sdk/NestedBuilders.js.map +1 -1
- package/dist/query-sdk/QueryBuilder.d.ts +4 -2
- package/dist/query-sdk/QueryBuilder.d.ts.map +1 -1
- package/dist/query-sdk/QueryBuilder.js +47 -169
- package/dist/query-sdk/QueryBuilder.js.map +1 -1
- package/dist/query-sdk/QueryResult.d.ts +0 -38
- package/dist/query-sdk/QueryResult.d.ts.map +1 -1
- package/dist/query-sdk/QueryResult.js +1 -227
- package/dist/query-sdk/QueryResult.js.map +1 -1
- package/dist/query-sdk/index.d.ts +1 -1
- package/dist/query-sdk/index.d.ts.map +1 -1
- package/dist/query-sdk/index.js.map +1 -1
- package/dist/query-sdk/operators.d.ts +32 -28
- package/dist/query-sdk/operators.d.ts.map +1 -1
- package/dist/query-sdk/operators.js +45 -155
- package/dist/query-sdk/operators.js.map +1 -1
- package/dist/types.d.ts +153 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/jest.config.js +4 -0
- package/package.json +1 -1
- package/skills.md +0 -1
- package/src/client.ts +243 -745
- package/src/database.ts +70 -493
- package/src/index.ts +40 -193
- package/src/query-sdk/ConditionBuilder.ts +37 -89
- package/src/query-sdk/NestedBuilders.ts +90 -92
- package/src/query-sdk/QueryBuilder.ts +59 -218
- package/src/query-sdk/QueryResult.ts +4 -330
- package/src/query-sdk/README.md +214 -583
- package/src/query-sdk/index.ts +1 -1
- package/src/query-sdk/operators.ts +91 -200
- package/src/query-sdk/tests/FieldConditionBuilder.test.ts +70 -71
- package/src/query-sdk/tests/LogicalOperator.test.ts +43 -82
- package/src/query-sdk/tests/NestedBuilders.test.ts +229 -309
- package/src/query-sdk/tests/QueryBuilder.test.ts +5 -5
- package/src/query-sdk/tests/QueryResult.test.ts +41 -435
- package/src/query-sdk/tests/comprehensive.test.ts +4 -185
- package/src/tests/client-requests.test.ts +280 -0
- package/src/tests/client-validation.test.ts +80 -0
- package/src/types.ts +229 -8
- package/src/batch.ts +0 -257
- package/src/query-sdk/dist/ConditionBuilder.d.ts +0 -22
- package/src/query-sdk/dist/ConditionBuilder.js +0 -90
- package/src/query-sdk/dist/FieldConditionBuilder.d.ts +0 -1
- package/src/query-sdk/dist/FieldConditionBuilder.js +0 -6
- package/src/query-sdk/dist/NestedBuilders.d.ts +0 -43
- package/src/query-sdk/dist/NestedBuilders.js +0 -144
- package/src/query-sdk/dist/OnChainDB.d.ts +0 -19
- package/src/query-sdk/dist/OnChainDB.js +0 -123
- package/src/query-sdk/dist/QueryBuilder.d.ts +0 -70
- package/src/query-sdk/dist/QueryBuilder.js +0 -295
- package/src/query-sdk/dist/QueryResult.d.ts +0 -52
- package/src/query-sdk/dist/QueryResult.js +0 -293
- package/src/query-sdk/dist/SelectionBuilder.d.ts +0 -20
- package/src/query-sdk/dist/SelectionBuilder.js +0 -80
- package/src/query-sdk/dist/adapters/HttpClientAdapter.d.ts +0 -27
- package/src/query-sdk/dist/adapters/HttpClientAdapter.js +0 -170
- package/src/query-sdk/dist/index.d.ts +0 -36
- package/src/query-sdk/dist/index.js +0 -27
- package/src/query-sdk/dist/operators.d.ts +0 -56
- package/src/query-sdk/dist/operators.js +0 -289
- package/src/query-sdk/dist/tests/setup.d.ts +0 -15
- package/src/query-sdk/dist/tests/setup.js +0 -46
- package/src/query-sdk/jest.config.js +0 -25
- package/src/query-sdk/package.json +0 -46
- package/src/query-sdk/tests/aggregations.test.ts +0 -653
- package/src/query-sdk/tests/integration.test.ts +0 -608
- package/src/query-sdk/tests/operators.test.ts +0 -327
- package/src/query-sdk/tests/unit.test.ts +0 -794
- package/src/query-sdk/tsconfig.json +0 -26
- package/src/query-sdk/yarn.lock +0 -3092
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NestedFieldConditionBuilder = exports.NestedConditionBuilder = void 0;
|
|
4
|
-
const operators_1 = require("./operators");
|
|
5
|
-
// Builder for creating nested field conditions with ORM-like syntax
|
|
6
|
-
class NestedConditionBuilder {
|
|
7
|
-
constructor(rootField) {
|
|
8
|
-
this.path = [rootField];
|
|
9
|
-
}
|
|
10
|
-
// Add another level to the path and create field conditions
|
|
11
|
-
field(fieldName) {
|
|
12
|
-
const newPath = [...this.path, fieldName];
|
|
13
|
-
return new NestedFieldConditionBuilder(newPath);
|
|
14
|
-
}
|
|
15
|
-
// Create nested structure with callback
|
|
16
|
-
nested(fieldName, builderFn) {
|
|
17
|
-
const nestedPath = [...this.path, fieldName];
|
|
18
|
-
const nestedBuilder = new NestedConditionBuilder('');
|
|
19
|
-
nestedBuilder.path = nestedPath;
|
|
20
|
-
return builderFn(nestedBuilder);
|
|
21
|
-
}
|
|
22
|
-
// Create logical groups
|
|
23
|
-
andGroup(builderFn) {
|
|
24
|
-
const conditions = builderFn(this);
|
|
25
|
-
return operators_1.LogicalOperator.And(conditions);
|
|
26
|
-
}
|
|
27
|
-
orGroup(builderFn) {
|
|
28
|
-
const conditions = builderFn(this);
|
|
29
|
-
return operators_1.LogicalOperator.Or(conditions);
|
|
30
|
-
}
|
|
31
|
-
notGroup(builderFn) {
|
|
32
|
-
const conditions = builderFn(this);
|
|
33
|
-
return operators_1.LogicalOperator.Not(conditions);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.NestedConditionBuilder = NestedConditionBuilder;
|
|
37
|
-
// Builder for field conditions within nested structures
|
|
38
|
-
// Only includes operators that actually exist in the Rust implementation
|
|
39
|
-
class NestedFieldConditionBuilder {
|
|
40
|
-
constructor(fieldPath) {
|
|
41
|
-
this.fieldPath = fieldPath;
|
|
42
|
-
}
|
|
43
|
-
createCondition(operator, value) {
|
|
44
|
-
const path = this.fieldPath.join('.');
|
|
45
|
-
return {
|
|
46
|
-
field: path,
|
|
47
|
-
operator,
|
|
48
|
-
value
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
// ===== BASE OPERATORS (BaseOperator) =====
|
|
52
|
-
equals(value) {
|
|
53
|
-
return this.createCondition('is', value);
|
|
54
|
-
}
|
|
55
|
-
notEquals(value) {
|
|
56
|
-
return this.createCondition('isNot', value);
|
|
57
|
-
}
|
|
58
|
-
in(values) {
|
|
59
|
-
return this.createCondition('in', values);
|
|
60
|
-
}
|
|
61
|
-
notIn(values) {
|
|
62
|
-
return this.createCondition('notIn', values);
|
|
63
|
-
}
|
|
64
|
-
isNull() {
|
|
65
|
-
return this.createCondition('isNull', true);
|
|
66
|
-
}
|
|
67
|
-
isNotNull() {
|
|
68
|
-
return this.createCondition('isNull', false);
|
|
69
|
-
}
|
|
70
|
-
exists() {
|
|
71
|
-
return this.createCondition('exists', true);
|
|
72
|
-
}
|
|
73
|
-
notExists() {
|
|
74
|
-
return this.createCondition('exists', false);
|
|
75
|
-
}
|
|
76
|
-
// ===== STRING OPERATORS (StringOperator) =====
|
|
77
|
-
startsWith(value) {
|
|
78
|
-
return this.createCondition('startsWith', value);
|
|
79
|
-
}
|
|
80
|
-
endsWith(value) {
|
|
81
|
-
return this.createCondition('endsWith', value);
|
|
82
|
-
}
|
|
83
|
-
contains(value) {
|
|
84
|
-
return this.createCondition('includes', value);
|
|
85
|
-
}
|
|
86
|
-
regExpMatches(pattern) {
|
|
87
|
-
return this.createCondition('regExpMatches', pattern);
|
|
88
|
-
}
|
|
89
|
-
includesCaseInsensitive(value) {
|
|
90
|
-
return this.createCondition('includesCaseInsensitive', value);
|
|
91
|
-
}
|
|
92
|
-
startsWithCaseInsensitive(value) {
|
|
93
|
-
return this.createCondition('startsWithCaseInsensitive', value);
|
|
94
|
-
}
|
|
95
|
-
endsWithCaseInsensitive(value) {
|
|
96
|
-
return this.createCondition('endsWithCaseInsensitive', value);
|
|
97
|
-
}
|
|
98
|
-
// ===== NUMBER OPERATORS (NumberOperator) =====
|
|
99
|
-
greaterThan(value) {
|
|
100
|
-
return this.createCondition('greaterThan', value);
|
|
101
|
-
}
|
|
102
|
-
lessThan(value) {
|
|
103
|
-
return this.createCondition('lessThan', value);
|
|
104
|
-
}
|
|
105
|
-
greaterThanOrEqual(value) {
|
|
106
|
-
return this.createCondition('greaterThanOrEqual', value);
|
|
107
|
-
}
|
|
108
|
-
lessThanOrEqual(value) {
|
|
109
|
-
return this.createCondition('lessThanOrEqual', value);
|
|
110
|
-
}
|
|
111
|
-
// ===== IP OPERATORS (IpOperator) =====
|
|
112
|
-
isLocalIp() {
|
|
113
|
-
return this.createCondition('isLocalIp', true);
|
|
114
|
-
}
|
|
115
|
-
isExternalIp() {
|
|
116
|
-
return this.createCondition('isExternalIp', true);
|
|
117
|
-
}
|
|
118
|
-
// ===== MISC OPERATORS (MiscOperator) =====
|
|
119
|
-
b64(value) {
|
|
120
|
-
return this.createCondition('b64', value);
|
|
121
|
-
}
|
|
122
|
-
inDataset(dataset) {
|
|
123
|
-
return this.createCondition('inDataset', dataset);
|
|
124
|
-
}
|
|
125
|
-
inCountry(countryCode) {
|
|
126
|
-
return this.createCondition('inCountry', countryCode);
|
|
127
|
-
}
|
|
128
|
-
cidr(cidr) {
|
|
129
|
-
return this.createCondition('CIDR', cidr);
|
|
130
|
-
}
|
|
131
|
-
// ===== BETWEEN OPERATOR =====
|
|
132
|
-
between(min, max) {
|
|
133
|
-
return this.createCondition('betweenOp', { from: min, to: max });
|
|
134
|
-
}
|
|
135
|
-
// ===== CONVENIENCE METHODS =====
|
|
136
|
-
// Boolean checks (using base operators)
|
|
137
|
-
isTrue() {
|
|
138
|
-
return this.equals(true);
|
|
139
|
-
}
|
|
140
|
-
isFalse() {
|
|
141
|
-
return this.equals(false);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
exports.NestedFieldConditionBuilder = NestedFieldConditionBuilder;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { QueryBuilder } from './QueryBuilder';
|
|
2
|
-
import { SelectionBuilder } from './SelectionBuilder';
|
|
3
|
-
import { FieldMap, HttpClient, QueryResponse } from "./index";
|
|
4
|
-
export declare class OnChainDB {
|
|
5
|
-
private static httpClient?;
|
|
6
|
-
private static serverUrl?;
|
|
7
|
-
static configure(httpClient: HttpClient, serverUrl: string): void;
|
|
8
|
-
static getHttpClient(): HttpClient | undefined;
|
|
9
|
-
static getServerUrl(): string | undefined;
|
|
10
|
-
static query(): QueryBuilder;
|
|
11
|
-
static queryWith(httpClient: HttpClient, serverUrl: string): QueryBuilder;
|
|
12
|
-
static select(builderFn: (builder: SelectionBuilder) => SelectionBuilder): QueryBuilder;
|
|
13
|
-
static rawQuery(queryJson: string, httpClient?: HttpClient, serverUrl?: string, fieldMap?: FieldMap): Promise<QueryResponse>;
|
|
14
|
-
static queryFromJson(queryObject: any, httpClient?: HttpClient, serverUrl?: string): Promise<QueryResponse>;
|
|
15
|
-
static healthCheck(httpClient?: HttpClient, serverUrl?: string): Promise<boolean>;
|
|
16
|
-
static serverInfo(httpClient?: HttpClient, serverUrl?: string): Promise<any>;
|
|
17
|
-
static reset(): void;
|
|
18
|
-
static isConfigured(): boolean;
|
|
19
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OnChainDB = void 0;
|
|
4
|
-
const QueryBuilder_1 = require("./QueryBuilder");
|
|
5
|
-
// Main SDK class providing static methods for query building
|
|
6
|
-
class OnChainDB {
|
|
7
|
-
// Configure the SDK with HTTP client and server URL
|
|
8
|
-
static configure(httpClient, serverUrl) {
|
|
9
|
-
this.httpClient = httpClient;
|
|
10
|
-
this.serverUrl = serverUrl;
|
|
11
|
-
}
|
|
12
|
-
// Get the configured HTTP client
|
|
13
|
-
static getHttpClient() {
|
|
14
|
-
return this.httpClient;
|
|
15
|
-
}
|
|
16
|
-
// Get the configured server URL
|
|
17
|
-
static getServerUrl() {
|
|
18
|
-
return this.serverUrl;
|
|
19
|
-
}
|
|
20
|
-
// Start building a new query
|
|
21
|
-
static query() {
|
|
22
|
-
return new QueryBuilder_1.QueryBuilder(this.httpClient, this.serverUrl);
|
|
23
|
-
}
|
|
24
|
-
// Create a query builder with specific HTTP client and server URL (one-time use)
|
|
25
|
-
static queryWith(httpClient, serverUrl) {
|
|
26
|
-
return new QueryBuilder_1.QueryBuilder(httpClient, serverUrl);
|
|
27
|
-
}
|
|
28
|
-
// Create a simple query with just field selection (no filtering)
|
|
29
|
-
static select(builderFn) {
|
|
30
|
-
const query = new QueryBuilder_1.QueryBuilder(this.httpClient, this.serverUrl);
|
|
31
|
-
query.select(builderFn);
|
|
32
|
-
return query;
|
|
33
|
-
}
|
|
34
|
-
// Execute a raw query using HTTP
|
|
35
|
-
static async rawQuery(queryJson, httpClient, serverUrl, fieldMap) {
|
|
36
|
-
const client = httpClient || this.httpClient;
|
|
37
|
-
const url = serverUrl || this.serverUrl;
|
|
38
|
-
if (!client) {
|
|
39
|
-
throw new Error('HTTP client is required for raw query execution');
|
|
40
|
-
}
|
|
41
|
-
if (!url) {
|
|
42
|
-
throw new Error('Server URL is required for raw query execution');
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const queryValue = JSON.parse(queryJson);
|
|
46
|
-
const request = {
|
|
47
|
-
...queryValue,
|
|
48
|
-
// Include fieldMap if provided (for server-side field mapping)
|
|
49
|
-
...(fieldMap && { fieldMap })
|
|
50
|
-
};
|
|
51
|
-
const response = await client.post(`${url}/list`, request, { 'Content-Type': 'application/json' });
|
|
52
|
-
return response;
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
if (error instanceof SyntaxError) {
|
|
56
|
-
throw new Error(`Invalid query JSON: ${error.message}`);
|
|
57
|
-
}
|
|
58
|
-
throw new Error(`Raw query execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// Execute a query from a JSON object (useful for dynamic queries)
|
|
62
|
-
static async queryFromJson(queryObject, httpClient, serverUrl) {
|
|
63
|
-
const client = httpClient || this.httpClient;
|
|
64
|
-
const url = serverUrl || this.serverUrl;
|
|
65
|
-
if (!client) {
|
|
66
|
-
throw new Error('HTTP client is required for JSON query execution');
|
|
67
|
-
}
|
|
68
|
-
if (!url) {
|
|
69
|
-
throw new Error('Server URL is required for JSON query execution');
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
const request = queryObject;
|
|
73
|
-
const response = await client.post(`${url}/list`, request, { 'Content-Type': 'application/json' });
|
|
74
|
-
return response;
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
throw new Error(`JSON query execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// Health check for the server
|
|
81
|
-
static async healthCheck(httpClient, serverUrl) {
|
|
82
|
-
const client = httpClient || this.httpClient;
|
|
83
|
-
const url = serverUrl || this.serverUrl;
|
|
84
|
-
if (!client || !url) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
try {
|
|
88
|
-
await client.post(`${url}/health`, {}, { 'Content-Type': 'application/json' });
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
// Get server information
|
|
96
|
-
static async serverInfo(httpClient, serverUrl) {
|
|
97
|
-
const client = httpClient || this.httpClient;
|
|
98
|
-
const url = serverUrl || this.serverUrl;
|
|
99
|
-
if (!client) {
|
|
100
|
-
throw new Error('HTTP client is required for server info');
|
|
101
|
-
}
|
|
102
|
-
if (!url) {
|
|
103
|
-
throw new Error('Server URL is required for server info');
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
const response = await client.post(`${url}/info`, {}, { 'Content-Type': 'application/json' });
|
|
107
|
-
return response;
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
throw new Error(`Failed to get server info: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// Reset SDK configuration
|
|
114
|
-
static reset() {
|
|
115
|
-
this.httpClient = undefined;
|
|
116
|
-
this.serverUrl = undefined;
|
|
117
|
-
}
|
|
118
|
-
// Check if SDK is configured
|
|
119
|
-
static isConfigured() {
|
|
120
|
-
return this.httpClient !== undefined && this.serverUrl !== undefined;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
exports.OnChainDB = OnChainDB;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { QueryRequest, QueryResponse, Val } from '../index';
|
|
2
|
-
import { LogicalOperator } from './operators';
|
|
3
|
-
import { SelectionBuilder } from './SelectionBuilder';
|
|
4
|
-
import { ConditionBuilder } from './ConditionBuilder';
|
|
5
|
-
import { FieldMap, HttpClient } from "./index";
|
|
6
|
-
export declare class QueryBuilder {
|
|
7
|
-
private findConditions?;
|
|
8
|
-
private selections?;
|
|
9
|
-
private fieldMap?;
|
|
10
|
-
private limitValue?;
|
|
11
|
-
private offsetValue?;
|
|
12
|
-
private sortBy?;
|
|
13
|
-
private sortDirection?;
|
|
14
|
-
private httpClient?;
|
|
15
|
-
private serverUrl?;
|
|
16
|
-
private collectionName;
|
|
17
|
-
private app;
|
|
18
|
-
constructor(httpClient?: HttpClient, serverUrl?: string, app?: string);
|
|
19
|
-
static new(httpClient?: HttpClient, serverUrl?: string, app?: string): QueryBuilder;
|
|
20
|
-
withHttpClient(httpClient: HttpClient): QueryBuilder;
|
|
21
|
-
withServerUrl(serverUrl: string): QueryBuilder;
|
|
22
|
-
find(builderFn: (builder: ConditionBuilder) => LogicalOperator): QueryBuilder;
|
|
23
|
-
collection(s: string): QueryBuilder;
|
|
24
|
-
whereField(fieldName: string): WhereClause;
|
|
25
|
-
select(builderFn: (builder: SelectionBuilder) => SelectionBuilder): QueryBuilder;
|
|
26
|
-
selectFields(fields: string[]): QueryBuilder;
|
|
27
|
-
selectAll(): QueryBuilder;
|
|
28
|
-
withFieldMap(fieldMap: FieldMap): QueryBuilder;
|
|
29
|
-
limit(limit: number): QueryBuilder;
|
|
30
|
-
offset(offset: number): QueryBuilder;
|
|
31
|
-
orderBy(fields: string): QueryBuilder;
|
|
32
|
-
execute<T extends Record<string, any>>(): Promise<QueryResponse<T>>;
|
|
33
|
-
isValid(): boolean;
|
|
34
|
-
buildRawQuery(): QueryRequest;
|
|
35
|
-
clone(): QueryBuilder;
|
|
36
|
-
private buildQueryValue;
|
|
37
|
-
}
|
|
38
|
-
export declare class WhereClause {
|
|
39
|
-
private queryBuilder;
|
|
40
|
-
private fieldName;
|
|
41
|
-
constructor(queryBuilder: QueryBuilder, fieldName: string);
|
|
42
|
-
equals(value: Val): QueryBuilder;
|
|
43
|
-
notEquals(value: Val): QueryBuilder;
|
|
44
|
-
greaterThan(value: Val): QueryBuilder;
|
|
45
|
-
greaterThanOrEqual(value: Val): QueryBuilder;
|
|
46
|
-
lessThan(value: Val): QueryBuilder;
|
|
47
|
-
lessThanOrEqual(value: Val): QueryBuilder;
|
|
48
|
-
contains(value: string): QueryBuilder;
|
|
49
|
-
startsWith(value: string): QueryBuilder;
|
|
50
|
-
endsWith(value: string): QueryBuilder;
|
|
51
|
-
in(values: Val[]): QueryBuilder;
|
|
52
|
-
notIn(values: Val[]): QueryBuilder;
|
|
53
|
-
exists(): QueryBuilder;
|
|
54
|
-
notExists(): QueryBuilder;
|
|
55
|
-
isNull(): QueryBuilder;
|
|
56
|
-
isNotNull(): QueryBuilder;
|
|
57
|
-
regExpMatches(pattern: string): QueryBuilder;
|
|
58
|
-
includesCaseInsensitive(value: string): QueryBuilder;
|
|
59
|
-
startsWithCaseInsensitive(value: string): QueryBuilder;
|
|
60
|
-
endsWithCaseInsensitive(value: string): QueryBuilder;
|
|
61
|
-
isLocalIp(): QueryBuilder;
|
|
62
|
-
isExternalIp(): QueryBuilder;
|
|
63
|
-
b64(value: string): QueryBuilder;
|
|
64
|
-
inDataset(dataset: string): QueryBuilder;
|
|
65
|
-
inCountry(countryCode: string): QueryBuilder;
|
|
66
|
-
cidr(cidr: string): QueryBuilder;
|
|
67
|
-
between(min: any, max: any): QueryBuilder;
|
|
68
|
-
isTrue(): QueryBuilder;
|
|
69
|
-
isFalse(): QueryBuilder;
|
|
70
|
-
}
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WhereClause = exports.QueryBuilder = void 0;
|
|
4
|
-
const operators_1 = require("./operators");
|
|
5
|
-
const SelectionBuilder_1 = require("./SelectionBuilder");
|
|
6
|
-
const ConditionBuilder_1 = require("./ConditionBuilder");
|
|
7
|
-
// Main query builder providing fluent API for building queries
|
|
8
|
-
class QueryBuilder {
|
|
9
|
-
constructor(httpClient, serverUrl, app) {
|
|
10
|
-
this.httpClient = httpClient;
|
|
11
|
-
this.serverUrl = serverUrl;
|
|
12
|
-
this.app = app;
|
|
13
|
-
}
|
|
14
|
-
static new(httpClient, serverUrl, app) {
|
|
15
|
-
return new QueryBuilder(httpClient, serverUrl, app);
|
|
16
|
-
}
|
|
17
|
-
// Set HTTP client and server URL (for method chaining)
|
|
18
|
-
withHttpClient(httpClient) {
|
|
19
|
-
this.httpClient = httpClient;
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
withServerUrl(serverUrl) {
|
|
23
|
-
this.serverUrl = serverUrl;
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
// Build find conditions using a builder function
|
|
27
|
-
find(builderFn) {
|
|
28
|
-
const conditionBuilder = new ConditionBuilder_1.ConditionBuilder();
|
|
29
|
-
this.findConditions = builderFn(conditionBuilder);
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
collection(s) {
|
|
33
|
-
this.collectionName = s;
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
// Simple field condition (equivalent to Rust's where_field)
|
|
37
|
-
whereField(fieldName) {
|
|
38
|
-
return new WhereClause(this, fieldName);
|
|
39
|
-
}
|
|
40
|
-
// Build selections using a builder function
|
|
41
|
-
select(builderFn) {
|
|
42
|
-
const selectionBuilder = new SelectionBuilder_1.SelectionBuilder();
|
|
43
|
-
builderFn(selectionBuilder);
|
|
44
|
-
this.selections = selectionBuilder.build();
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
// Select specific fields by name
|
|
48
|
-
selectFields(fields) {
|
|
49
|
-
const selectionBuilder = new SelectionBuilder_1.SelectionBuilder();
|
|
50
|
-
selectionBuilder.fields(fields);
|
|
51
|
-
this.selections = selectionBuilder.build();
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
// Select all fields (no field filtering)
|
|
55
|
-
selectAll() {
|
|
56
|
-
this.selections = SelectionBuilder_1.SelectionBuilder.all();
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
// Set field mapping for the query
|
|
60
|
-
withFieldMap(fieldMap) {
|
|
61
|
-
this.fieldMap = fieldMap;
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
// Set limit for results
|
|
65
|
-
limit(limit) {
|
|
66
|
-
this.limitValue = limit;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
// Set offset for results
|
|
70
|
-
offset(offset) {
|
|
71
|
-
this.offsetValue = offset;
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
// Set sorting fields
|
|
75
|
-
orderBy(fields) {
|
|
76
|
-
this.sortBy = fields;
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
// Execute the query via HTTP
|
|
80
|
-
async execute() {
|
|
81
|
-
if (!this.httpClient) {
|
|
82
|
-
throw new Error('HTTP client is required for query execution');
|
|
83
|
-
}
|
|
84
|
-
if (!this.serverUrl) {
|
|
85
|
-
throw new Error('Server URL is required for query execution');
|
|
86
|
-
}
|
|
87
|
-
const queryValue = this.buildQueryValue();
|
|
88
|
-
const request = {
|
|
89
|
-
...queryValue,
|
|
90
|
-
limit: this.limitValue,
|
|
91
|
-
offset: this.offsetValue,
|
|
92
|
-
sortBy: this.sortBy,
|
|
93
|
-
root: `${this.app}::${this.collectionName}`
|
|
94
|
-
};
|
|
95
|
-
try {
|
|
96
|
-
const response = await this.httpClient.post(`${this.serverUrl}/list`, request, { 'Content-Type': 'application/json' });
|
|
97
|
-
return response?.data || {
|
|
98
|
-
records: [],
|
|
99
|
-
limit: 0,
|
|
100
|
-
page: 0,
|
|
101
|
-
total: 0,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
throw new Error(`Query execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
// Check if the query is valid (has required components)
|
|
109
|
-
isValid() {
|
|
110
|
-
// A query is valid if it has either find conditions or selections
|
|
111
|
-
return this.findConditions !== undefined || this.selections !== undefined;
|
|
112
|
-
}
|
|
113
|
-
// Build raw query JSON (useful for debugging)
|
|
114
|
-
buildRawQuery() {
|
|
115
|
-
return {
|
|
116
|
-
...this.buildQueryValue(),
|
|
117
|
-
limit: this.limitValue,
|
|
118
|
-
offset: this.offsetValue,
|
|
119
|
-
sortBy: this.sortBy
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
// Clone the query builder
|
|
123
|
-
clone() {
|
|
124
|
-
const cloned = new QueryBuilder(this.httpClient, this.serverUrl);
|
|
125
|
-
cloned.findConditions = this.findConditions;
|
|
126
|
-
cloned.selections = this.selections ? { ...this.selections } : undefined;
|
|
127
|
-
cloned.fieldMap = this.fieldMap ? { ...this.fieldMap } : undefined;
|
|
128
|
-
cloned.limitValue = this.limitValue;
|
|
129
|
-
cloned.offsetValue = this.offsetValue;
|
|
130
|
-
cloned.sortBy = this.sortBy;
|
|
131
|
-
return cloned;
|
|
132
|
-
}
|
|
133
|
-
// Build the query value object for HTTP requests
|
|
134
|
-
buildQueryValue() {
|
|
135
|
-
const find = this.findConditions ? this.findConditions.toComposable() : {};
|
|
136
|
-
const select = this.selections || SelectionBuilder_1.SelectionBuilder.all();
|
|
137
|
-
return {
|
|
138
|
-
find,
|
|
139
|
-
select
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
exports.QueryBuilder = QueryBuilder;
|
|
144
|
-
// Helper class for building where clauses with method chaining
|
|
145
|
-
class WhereClause {
|
|
146
|
-
constructor(queryBuilder, fieldName) {
|
|
147
|
-
this.queryBuilder = queryBuilder;
|
|
148
|
-
this.fieldName = fieldName;
|
|
149
|
-
}
|
|
150
|
-
equals(value) {
|
|
151
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).equals(value);
|
|
152
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
153
|
-
return this.queryBuilder;
|
|
154
|
-
}
|
|
155
|
-
notEquals(value) {
|
|
156
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).notEquals(value);
|
|
157
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
158
|
-
return this.queryBuilder;
|
|
159
|
-
}
|
|
160
|
-
greaterThan(value) {
|
|
161
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).greaterThan(value);
|
|
162
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
163
|
-
return this.queryBuilder;
|
|
164
|
-
}
|
|
165
|
-
greaterThanOrEqual(value) {
|
|
166
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).greaterThanOrEqual(value);
|
|
167
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
168
|
-
return this.queryBuilder;
|
|
169
|
-
}
|
|
170
|
-
lessThan(value) {
|
|
171
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).lessThan(value);
|
|
172
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
173
|
-
return this.queryBuilder;
|
|
174
|
-
}
|
|
175
|
-
lessThanOrEqual(value) {
|
|
176
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).lessThanOrEqual(value);
|
|
177
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
178
|
-
return this.queryBuilder;
|
|
179
|
-
}
|
|
180
|
-
contains(value) {
|
|
181
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).contains(value);
|
|
182
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
183
|
-
return this.queryBuilder;
|
|
184
|
-
}
|
|
185
|
-
startsWith(value) {
|
|
186
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).startsWith(value);
|
|
187
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
188
|
-
return this.queryBuilder;
|
|
189
|
-
}
|
|
190
|
-
endsWith(value) {
|
|
191
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).endsWith(value);
|
|
192
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
193
|
-
return this.queryBuilder;
|
|
194
|
-
}
|
|
195
|
-
in(values) {
|
|
196
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).in(values);
|
|
197
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
198
|
-
return this.queryBuilder;
|
|
199
|
-
}
|
|
200
|
-
notIn(values) {
|
|
201
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).notIn(values);
|
|
202
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
203
|
-
return this.queryBuilder;
|
|
204
|
-
}
|
|
205
|
-
exists() {
|
|
206
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).exists();
|
|
207
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
208
|
-
return this.queryBuilder;
|
|
209
|
-
}
|
|
210
|
-
notExists() {
|
|
211
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).notExists();
|
|
212
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
213
|
-
return this.queryBuilder;
|
|
214
|
-
}
|
|
215
|
-
isNull() {
|
|
216
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).isNull();
|
|
217
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
218
|
-
return this.queryBuilder;
|
|
219
|
-
}
|
|
220
|
-
isNotNull() {
|
|
221
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).isNotNull();
|
|
222
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
223
|
-
return this.queryBuilder;
|
|
224
|
-
}
|
|
225
|
-
regExpMatches(pattern) {
|
|
226
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).regExpMatches(pattern);
|
|
227
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
228
|
-
return this.queryBuilder;
|
|
229
|
-
}
|
|
230
|
-
includesCaseInsensitive(value) {
|
|
231
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).includesCaseInsensitive(value);
|
|
232
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
233
|
-
return this.queryBuilder;
|
|
234
|
-
}
|
|
235
|
-
startsWithCaseInsensitive(value) {
|
|
236
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).startsWithCaseInsensitive(value);
|
|
237
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
238
|
-
return this.queryBuilder;
|
|
239
|
-
}
|
|
240
|
-
endsWithCaseInsensitive(value) {
|
|
241
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).endsWithCaseInsensitive(value);
|
|
242
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
243
|
-
return this.queryBuilder;
|
|
244
|
-
}
|
|
245
|
-
// ===== IP OPERATORS =====
|
|
246
|
-
isLocalIp() {
|
|
247
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).isLocalIp();
|
|
248
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
249
|
-
return this.queryBuilder;
|
|
250
|
-
}
|
|
251
|
-
isExternalIp() {
|
|
252
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).isExternalIp();
|
|
253
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
254
|
-
return this.queryBuilder;
|
|
255
|
-
}
|
|
256
|
-
// ===== MISC OPERATORS =====
|
|
257
|
-
b64(value) {
|
|
258
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).b64(value);
|
|
259
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
260
|
-
return this.queryBuilder;
|
|
261
|
-
}
|
|
262
|
-
inDataset(dataset) {
|
|
263
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).inDataset(dataset);
|
|
264
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
265
|
-
return this.queryBuilder;
|
|
266
|
-
}
|
|
267
|
-
inCountry(countryCode) {
|
|
268
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).inCountry(countryCode);
|
|
269
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
270
|
-
return this.queryBuilder;
|
|
271
|
-
}
|
|
272
|
-
cidr(cidr) {
|
|
273
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).cidr(cidr);
|
|
274
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
275
|
-
return this.queryBuilder;
|
|
276
|
-
}
|
|
277
|
-
// ===== BETWEEN OPERATOR =====
|
|
278
|
-
between(min, max) {
|
|
279
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).between(min, max);
|
|
280
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
281
|
-
return this.queryBuilder;
|
|
282
|
-
}
|
|
283
|
-
// ===== CONVENIENCE METHODS =====
|
|
284
|
-
isTrue() {
|
|
285
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).isTrue();
|
|
286
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
287
|
-
return this.queryBuilder;
|
|
288
|
-
}
|
|
289
|
-
isFalse() {
|
|
290
|
-
const condition = new operators_1.FieldConditionBuilder(this.fieldName).isFalse();
|
|
291
|
-
this.queryBuilder.findConditions = operators_1.LogicalOperator.Condition(condition);
|
|
292
|
-
return this.queryBuilder;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
exports.WhereClause = WhereClause;
|