@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,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SelectionBuilder = void 0;
4
- class SelectionBuilder {
5
- constructor() {
6
- this.selections = {};
7
- }
8
- static new() {
9
- return new SelectionBuilder();
10
- }
11
- // Static method to create selection that includes all fields
12
- static all() {
13
- return { "*": true }; // Empty selection map means select all fields
14
- }
15
- // Select specific fields
16
- field(fieldName) {
17
- this.selections[fieldName] = true; // true indicates field should be included
18
- return this;
19
- }
20
- // Select multiple fields at once
21
- fields(fieldNames) {
22
- fieldNames.forEach(field => {
23
- this.selections[field] = true;
24
- });
25
- return this;
26
- }
27
- // Select nested fields with a builder function
28
- nested(fieldName, builderFn) {
29
- const nestedBuilder = new SelectionBuilder();
30
- builderFn(nestedBuilder);
31
- this.selections[fieldName] = nestedBuilder.build();
32
- return this;
33
- }
34
- // Exclude specific fields (useful when selecting most fields)
35
- exclude(fieldName) {
36
- this.selections[fieldName] = false; // false indicates field should be excluded
37
- return this;
38
- }
39
- // Exclude multiple fields
40
- excludeFields(fieldNames) {
41
- fieldNames.forEach(field => {
42
- this.selections[field] = false;
43
- });
44
- return this;
45
- }
46
- // Build and return the selection map
47
- build() {
48
- return { ...this.selections };
49
- }
50
- // Reset the builder
51
- clear() {
52
- this.selections = {};
53
- return this;
54
- }
55
- // Check if any selections have been made
56
- isEmpty() {
57
- return Object.keys(this.selections).length === 0;
58
- }
59
- // Get current selection count
60
- getSelectionCount() {
61
- return Object.keys(this.selections).length;
62
- }
63
- // Check if a specific field is selected
64
- hasField(fieldName) {
65
- return fieldName in this.selections && this.selections[fieldName] === true;
66
- }
67
- // Check if a specific field is excluded
68
- isFieldExcluded(fieldName) {
69
- return fieldName in this.selections && this.selections[fieldName] === false;
70
- }
71
- // Get all selected field names
72
- getSelectedFields() {
73
- return Object.keys(this.selections).filter(field => this.selections[field] === true);
74
- }
75
- // Get all excluded field names
76
- getExcludedFields() {
77
- return Object.keys(this.selections).filter(field => this.selections[field] === false);
78
- }
79
- }
80
- exports.SelectionBuilder = SelectionBuilder;
@@ -1,27 +0,0 @@
1
- import { HttpClient } from "../index";
2
- declare global {
3
- interface Window {
4
- any: any;
5
- }
6
- }
7
- export declare class FetchHttpClient implements HttpClient {
8
- private fetchFn;
9
- constructor(fetchImplementation?: typeof fetch);
10
- post(url: string, data: any, headers?: Record<string, string>): Promise<any>;
11
- }
12
- export declare class AxiosHttpClient implements HttpClient {
13
- private axios;
14
- constructor(axiosInstance: any);
15
- post(url: string, data: any, headers?: Record<string, string>): Promise<any>;
16
- }
17
- export declare class NodeHttpClient implements HttpClient {
18
- private timeout;
19
- constructor(timeout?: number);
20
- post(url: string, data: any, headers?: Record<string, string>): Promise<any>;
21
- }
22
- export declare function createHttpClient(options?: {
23
- type?: 'fetch' | 'axios' | 'node';
24
- fetchImplementation?: typeof fetch;
25
- axiosInstance?: any;
26
- timeout?: number;
27
- }): HttpClient;
@@ -1,170 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeHttpClient = exports.AxiosHttpClient = exports.FetchHttpClient = void 0;
4
- exports.createHttpClient = createHttpClient;
5
- // Adapter for fetch API (works in both browser and Node.js with node-fetch)
6
- class FetchHttpClient {
7
- constructor(fetchImplementation) {
8
- // Use provided fetch implementation or global fetch
9
- this.fetchFn = fetchImplementation || (globalThis.fetch?.bind(globalThis));
10
- if (!this.fetchFn) {
11
- throw new Error('Fetch is not available. Please provide a fetch implementation or use in an environment that supports fetch.');
12
- }
13
- }
14
- async post(url, data, headers = {}) {
15
- try {
16
- const response = await this.fetchFn(url, {
17
- method: 'POST',
18
- headers: {
19
- 'Content-Type': 'application/json',
20
- ...headers,
21
- },
22
- body: JSON.stringify(data),
23
- });
24
- if (!response.ok) {
25
- const errorText = await response.text();
26
- throw new Error(`HTTP ${response.status}: ${errorText}`);
27
- }
28
- const contentType = response.headers.get('content-type');
29
- if (contentType && contentType.includes('application/json')) {
30
- return await response.json();
31
- }
32
- else {
33
- return await response.text();
34
- }
35
- }
36
- catch (error) {
37
- if (error instanceof Error) {
38
- throw error;
39
- }
40
- throw new Error(`Request failed: ${error}`);
41
- }
42
- }
43
- }
44
- exports.FetchHttpClient = FetchHttpClient;
45
- // Adapter for axios (if user prefers axios)
46
- class AxiosHttpClient {
47
- constructor(axiosInstance) {
48
- if (!axiosInstance) {
49
- throw new Error('Axios instance is required');
50
- }
51
- this.axios = axiosInstance;
52
- }
53
- async post(url, data, headers = {}) {
54
- try {
55
- const response = await this.axios.post(url, data, {
56
- headers: {
57
- 'Content-Type': 'application/json',
58
- ...headers,
59
- },
60
- });
61
- return response.data;
62
- }
63
- catch (error) {
64
- if (error.response) {
65
- throw new Error(`HTTP ${error.response.status}: ${JSON.stringify(error.response.data)}`);
66
- }
67
- else if (error.request) {
68
- throw new Error('No response received from server');
69
- }
70
- else {
71
- throw new Error(`Request setup error: ${error.message}`);
72
- }
73
- }
74
- }
75
- }
76
- exports.AxiosHttpClient = AxiosHttpClient;
77
- // Simple HTTP client using Node.js built-in modules (for Node.js environments)
78
- class NodeHttpClient {
79
- constructor(timeout = 30000) {
80
- this.timeout = timeout;
81
- }
82
- async post(url, data, headers = {}) {
83
- return new Promise((resolve, reject) => {
84
- const urlObj = new URL(url);
85
- const isHttps = urlObj.protocol === 'https:';
86
- // Dynamic import to avoid issues in browser environments
87
- const httpModule = isHttps ? require('https') : require('http');
88
- const postData = JSON.stringify(data);
89
- const options = {
90
- hostname: urlObj.hostname,
91
- port: urlObj.port || (isHttps ? 443 : 80),
92
- path: urlObj.pathname + urlObj.search,
93
- method: 'POST',
94
- headers: {
95
- 'Content-Type': 'application/json',
96
- 'Content-Length': Buffer.byteLength(postData),
97
- ...headers,
98
- },
99
- timeout: this.timeout,
100
- };
101
- const req = httpModule.request(options, (res) => {
102
- let responseData = '';
103
- res.on('data', (chunk) => {
104
- responseData += chunk;
105
- });
106
- res.on('end', () => {
107
- try {
108
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
109
- const contentType = res.headers['content-type'] || '';
110
- if (contentType.includes('application/json')) {
111
- resolve(JSON.parse(responseData));
112
- }
113
- else {
114
- resolve(responseData);
115
- }
116
- }
117
- else {
118
- reject(new Error(`HTTP ${res.statusCode}: ${responseData}`));
119
- }
120
- }
121
- catch (error) {
122
- reject(new Error(`Failed to parse response: ${error}`));
123
- }
124
- });
125
- });
126
- req.on('error', (error) => {
127
- reject(new Error(`Request failed: ${error.message}`));
128
- });
129
- req.on('timeout', () => {
130
- req.destroy();
131
- reject(new Error(`Request timed out after ${this.timeout}ms`));
132
- });
133
- req.write(postData);
134
- req.end();
135
- });
136
- }
137
- }
138
- exports.NodeHttpClient = NodeHttpClient;
139
- // Factory function to create appropriate HTTP client based on environment
140
- function createHttpClient(options = {}) {
141
- const { type, fetchImplementation, axiosInstance, timeout } = options;
142
- // Auto-detect environment if type is not specified
143
- if (!type) {
144
- if (typeof globalThis !== 'undefined' && typeof globalThis.fetch === 'function') {
145
- return new FetchHttpClient(fetchImplementation);
146
- }
147
- else { // @ts-ignore
148
- if (typeof window !== 'undefined') {
149
- throw new Error('Fetch is not available in this browser environment. Please provide a fetch implementation.');
150
- }
151
- else {
152
- // Assume Node.js environment
153
- return new NodeHttpClient(timeout);
154
- }
155
- }
156
- }
157
- switch (type) {
158
- case 'fetch':
159
- return new FetchHttpClient(fetchImplementation);
160
- case 'axios':
161
- if (!axiosInstance) {
162
- throw new Error('Axios instance is required when using axios client');
163
- }
164
- return new AxiosHttpClient(axiosInstance);
165
- case 'node':
166
- return new NodeHttpClient(timeout);
167
- default:
168
- throw new Error(`Unknown HTTP client type: ${type}`);
169
- }
170
- }
@@ -1,36 +0,0 @@
1
- export interface HttpClient {
2
- post(url: string, data: any, headers?: Record<string, string>): Promise<any>;
3
- }
4
- export interface QueryValue {
5
- find: any;
6
- select: any;
7
- }
8
- export type QueryRequest = QueryValue & {
9
- limit?: number;
10
- offset?: number;
11
- sort?: string[];
12
- };
13
- export interface QueryResponse<T = any> {
14
- records: T[];
15
- total?: number;
16
- error?: string;
17
- }
18
- export type SelectionMap = Record<string, any>;
19
- export type FieldMap = Record<string, string>;
20
- export type Val = string | number | boolean | null | Val[] | Date | RegExp;
21
- export interface BetweenValue {
22
- min: Val;
23
- max: Val;
24
- }
25
- export interface DateRange {
26
- start: Date | string | number;
27
- end: Date | string | number;
28
- }
29
- export { OnChainDB } from './OnChainDB';
30
- export { QueryBuilder } from './QueryBuilder';
31
- export { SelectionBuilder } from './SelectionBuilder';
32
- export { ConditionBuilder } from './ConditionBuilder';
33
- export { FieldConditionBuilder, LogicalOperator, Condition } from './operators';
34
- export { NestedConditionBuilder, NestedFieldConditionBuilder } from './NestedBuilders';
35
- export { QueryResult, NumericSummary, createQueryResult } from './QueryResult';
36
- export { FetchHttpClient, AxiosHttpClient, NodeHttpClient, createHttpClient } from './adapters/HttpClientAdapter';
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createHttpClient = exports.NodeHttpClient = exports.AxiosHttpClient = exports.FetchHttpClient = exports.createQueryResult = exports.QueryResult = exports.NestedFieldConditionBuilder = exports.NestedConditionBuilder = exports.LogicalOperator = exports.FieldConditionBuilder = exports.ConditionBuilder = exports.SelectionBuilder = exports.QueryBuilder = exports.OnChainDB = void 0;
4
- // Main SDK exports
5
- var OnChainDB_1 = require("./OnChainDB");
6
- Object.defineProperty(exports, "OnChainDB", { enumerable: true, get: function () { return OnChainDB_1.OnChainDB; } });
7
- var QueryBuilder_1 = require("./QueryBuilder");
8
- Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return QueryBuilder_1.QueryBuilder; } });
9
- var SelectionBuilder_1 = require("./SelectionBuilder");
10
- Object.defineProperty(exports, "SelectionBuilder", { enumerable: true, get: function () { return SelectionBuilder_1.SelectionBuilder; } });
11
- var ConditionBuilder_1 = require("./ConditionBuilder");
12
- Object.defineProperty(exports, "ConditionBuilder", { enumerable: true, get: function () { return ConditionBuilder_1.ConditionBuilder; } });
13
- var operators_1 = require("./operators");
14
- Object.defineProperty(exports, "FieldConditionBuilder", { enumerable: true, get: function () { return operators_1.FieldConditionBuilder; } });
15
- Object.defineProperty(exports, "LogicalOperator", { enumerable: true, get: function () { return operators_1.LogicalOperator; } });
16
- var NestedBuilders_1 = require("./NestedBuilders");
17
- Object.defineProperty(exports, "NestedConditionBuilder", { enumerable: true, get: function () { return NestedBuilders_1.NestedConditionBuilder; } });
18
- Object.defineProperty(exports, "NestedFieldConditionBuilder", { enumerable: true, get: function () { return NestedBuilders_1.NestedFieldConditionBuilder; } });
19
- var QueryResult_1 = require("./QueryResult");
20
- Object.defineProperty(exports, "QueryResult", { enumerable: true, get: function () { return QueryResult_1.QueryResult; } });
21
- Object.defineProperty(exports, "createQueryResult", { enumerable: true, get: function () { return QueryResult_1.createQueryResult; } });
22
- // HTTP Client adapters
23
- var HttpClientAdapter_1 = require("./adapters/HttpClientAdapter");
24
- Object.defineProperty(exports, "FetchHttpClient", { enumerable: true, get: function () { return HttpClientAdapter_1.FetchHttpClient; } });
25
- Object.defineProperty(exports, "AxiosHttpClient", { enumerable: true, get: function () { return HttpClientAdapter_1.AxiosHttpClient; } });
26
- Object.defineProperty(exports, "NodeHttpClient", { enumerable: true, get: function () { return HttpClientAdapter_1.NodeHttpClient; } });
27
- Object.defineProperty(exports, "createHttpClient", { enumerable: true, get: function () { return HttpClientAdapter_1.createHttpClient; } });
@@ -1,56 +0,0 @@
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
- }
@@ -1,289 +0,0 @@
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;