@ekodb/ekodb-client 0.1.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.
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Schema management for collections
3
+ *
4
+ * This module provides types and utilities for defining and managing
5
+ * collection schemas with field types, constraints, and indexes.
6
+ */
7
+ /**
8
+ * Vector index algorithm
9
+ */
10
+ export declare enum VectorIndexAlgorithm {
11
+ /** Simple flat index (brute force) */
12
+ Flat = "flat",
13
+ /** Hierarchical Navigable Small World */
14
+ HNSW = "hnsw",
15
+ /** Inverted File Index (for future) */
16
+ IVF = "ivf"
17
+ }
18
+ /**
19
+ * Distance metric for vector similarity
20
+ */
21
+ export declare enum DistanceMetric {
22
+ Cosine = "cosine",
23
+ Euclidean = "euclidean",
24
+ DotProduct = "dotproduct"
25
+ }
26
+ /**
27
+ * Index configuration for a field
28
+ */
29
+ export type IndexConfig = {
30
+ type: "text";
31
+ language?: string;
32
+ analyzer?: string;
33
+ } | {
34
+ type: "vector";
35
+ algorithm?: VectorIndexAlgorithm;
36
+ metric?: DistanceMetric;
37
+ m?: number;
38
+ ef_construction?: number;
39
+ } | {
40
+ type: "btree";
41
+ } | {
42
+ type: "hash";
43
+ };
44
+ /**
45
+ * Field type schema with constraints
46
+ *
47
+ * Valid field types (case-sensitive):
48
+ * - String, Integer, Float, Boolean, DateTime
49
+ * - Array, Object, Vector, Set
50
+ * - UUID, Decimal, Binary, Bytes, Duration, Number, Null
51
+ */
52
+ export interface FieldTypeSchema {
53
+ /** Field type - must be one of the valid types (case-sensitive, e.g., "String", "Integer", "Float") */
54
+ field_type: string;
55
+ /** Default value for the field */
56
+ default?: any;
57
+ /** Whether the field must be unique across records */
58
+ unique?: boolean;
59
+ /** Whether the field is required */
60
+ required?: boolean;
61
+ /** Allowed enum values */
62
+ enums?: any[];
63
+ /** Maximum value (for numbers/dates) */
64
+ max?: any;
65
+ /** Minimum value (for numbers/dates) */
66
+ min?: any;
67
+ /** Regex pattern for string validation */
68
+ regex?: string;
69
+ /** Index configuration */
70
+ index?: IndexConfig;
71
+ }
72
+ /**
73
+ * Collection schema
74
+ */
75
+ export interface Schema {
76
+ /** Field definitions */
77
+ fields: Record<string, FieldTypeSchema>;
78
+ /** Schema version */
79
+ version?: number;
80
+ /** Creation timestamp */
81
+ created_at?: string;
82
+ /** Last modification timestamp */
83
+ last_modified?: string;
84
+ /** Whether to bypass ripple replication */
85
+ bypass_ripple?: boolean;
86
+ }
87
+ /**
88
+ * Collection metadata with analytics
89
+ */
90
+ export interface CollectionMetadata {
91
+ /** Schema definition */
92
+ collection: Schema;
93
+ /** Analytics data (if available) */
94
+ analytics?: any;
95
+ }
96
+ /**
97
+ * Builder for constructing field type schemas
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const field = new FieldTypeSchemaBuilder("string")
102
+ * .required()
103
+ * .unique()
104
+ * .pattern("^[a-z]+$")
105
+ * .build();
106
+ * ```
107
+ */
108
+ export declare class FieldTypeSchemaBuilder {
109
+ private schema;
110
+ constructor(fieldType: string);
111
+ /**
112
+ * Set the field as required
113
+ */
114
+ required(): this;
115
+ /**
116
+ * Set the field as unique
117
+ */
118
+ unique(): this;
119
+ /**
120
+ * Set a default value
121
+ */
122
+ defaultValue(value: any): this;
123
+ /**
124
+ * Set enum values
125
+ */
126
+ enums(values: any[]): this;
127
+ /**
128
+ * Set min/max range
129
+ */
130
+ range(min?: any, max?: any): this;
131
+ /**
132
+ * Set regex pattern
133
+ */
134
+ pattern(regex: string): this;
135
+ /**
136
+ * Add a text index
137
+ */
138
+ textIndex(language?: string, analyzer?: string): this;
139
+ /**
140
+ * Add a vector index
141
+ */
142
+ vectorIndex(algorithm?: VectorIndexAlgorithm, metric?: DistanceMetric, m?: number, efConstruction?: number): this;
143
+ /**
144
+ * Add a B-tree index
145
+ */
146
+ btreeIndex(): this;
147
+ /**
148
+ * Add a hash index
149
+ */
150
+ hashIndex(): this;
151
+ /**
152
+ * Build the final FieldTypeSchema
153
+ */
154
+ build(): FieldTypeSchema;
155
+ }
156
+ /**
157
+ * Builder for constructing collection schemas
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const schema = new SchemaBuilder()
162
+ * .addField("name", new FieldTypeSchemaBuilder("string").required())
163
+ * .addField("email", new FieldTypeSchemaBuilder("string").unique())
164
+ * .addField("age", new FieldTypeSchemaBuilder("number").range(0, 150))
165
+ * .build();
166
+ *
167
+ * await client.createCollection("users", schema);
168
+ * ```
169
+ */
170
+ export declare class SchemaBuilder {
171
+ private schema;
172
+ constructor();
173
+ /**
174
+ * Add a field to the schema
175
+ */
176
+ addField(name: string, field: FieldTypeSchema | FieldTypeSchemaBuilder): this;
177
+ /**
178
+ * Set bypass_ripple flag
179
+ */
180
+ bypassRipple(bypass: boolean): this;
181
+ /**
182
+ * Set schema version
183
+ */
184
+ version(version: number): this;
185
+ /**
186
+ * Build the final Schema
187
+ */
188
+ build(): Schema;
189
+ }
package/dist/schema.js ADDED
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ /**
3
+ * Schema management for collections
4
+ *
5
+ * This module provides types and utilities for defining and managing
6
+ * collection schemas with field types, constraints, and indexes.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.SchemaBuilder = exports.FieldTypeSchemaBuilder = exports.DistanceMetric = exports.VectorIndexAlgorithm = void 0;
10
+ /**
11
+ * Vector index algorithm
12
+ */
13
+ var VectorIndexAlgorithm;
14
+ (function (VectorIndexAlgorithm) {
15
+ /** Simple flat index (brute force) */
16
+ VectorIndexAlgorithm["Flat"] = "flat";
17
+ /** Hierarchical Navigable Small World */
18
+ VectorIndexAlgorithm["HNSW"] = "hnsw";
19
+ /** Inverted File Index (for future) */
20
+ VectorIndexAlgorithm["IVF"] = "ivf";
21
+ })(VectorIndexAlgorithm || (exports.VectorIndexAlgorithm = VectorIndexAlgorithm = {}));
22
+ /**
23
+ * Distance metric for vector similarity
24
+ */
25
+ var DistanceMetric;
26
+ (function (DistanceMetric) {
27
+ DistanceMetric["Cosine"] = "cosine";
28
+ DistanceMetric["Euclidean"] = "euclidean";
29
+ DistanceMetric["DotProduct"] = "dotproduct";
30
+ })(DistanceMetric || (exports.DistanceMetric = DistanceMetric = {}));
31
+ /**
32
+ * Builder for constructing field type schemas
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const field = new FieldTypeSchemaBuilder("string")
37
+ * .required()
38
+ * .unique()
39
+ * .pattern("^[a-z]+$")
40
+ * .build();
41
+ * ```
42
+ */
43
+ class FieldTypeSchemaBuilder {
44
+ constructor(fieldType) {
45
+ this.schema = { field_type: fieldType };
46
+ }
47
+ /**
48
+ * Set the field as required
49
+ */
50
+ required() {
51
+ this.schema.required = true;
52
+ return this;
53
+ }
54
+ /**
55
+ * Set the field as unique
56
+ */
57
+ unique() {
58
+ this.schema.unique = true;
59
+ return this;
60
+ }
61
+ /**
62
+ * Set a default value
63
+ */
64
+ defaultValue(value) {
65
+ this.schema.default = value;
66
+ return this;
67
+ }
68
+ /**
69
+ * Set enum values
70
+ */
71
+ enums(values) {
72
+ this.schema.enums = values;
73
+ return this;
74
+ }
75
+ /**
76
+ * Set min/max range
77
+ */
78
+ range(min, max) {
79
+ this.schema.min = min;
80
+ this.schema.max = max;
81
+ return this;
82
+ }
83
+ /**
84
+ * Set regex pattern
85
+ */
86
+ pattern(regex) {
87
+ this.schema.regex = regex;
88
+ return this;
89
+ }
90
+ /**
91
+ * Add a text index
92
+ */
93
+ textIndex(language = "english", analyzer) {
94
+ this.schema.index = {
95
+ type: "text",
96
+ language,
97
+ analyzer,
98
+ };
99
+ return this;
100
+ }
101
+ /**
102
+ * Add a vector index
103
+ */
104
+ vectorIndex(algorithm = VectorIndexAlgorithm.Flat, metric = DistanceMetric.Cosine, m = 16, efConstruction = 200) {
105
+ this.schema.index = {
106
+ type: "vector",
107
+ algorithm,
108
+ metric,
109
+ m,
110
+ ef_construction: efConstruction,
111
+ };
112
+ return this;
113
+ }
114
+ /**
115
+ * Add a B-tree index
116
+ */
117
+ btreeIndex() {
118
+ this.schema.index = { type: "btree" };
119
+ return this;
120
+ }
121
+ /**
122
+ * Add a hash index
123
+ */
124
+ hashIndex() {
125
+ this.schema.index = { type: "hash" };
126
+ return this;
127
+ }
128
+ /**
129
+ * Build the final FieldTypeSchema
130
+ */
131
+ build() {
132
+ return this.schema;
133
+ }
134
+ }
135
+ exports.FieldTypeSchemaBuilder = FieldTypeSchemaBuilder;
136
+ /**
137
+ * Builder for constructing collection schemas
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const schema = new SchemaBuilder()
142
+ * .addField("name", new FieldTypeSchemaBuilder("string").required())
143
+ * .addField("email", new FieldTypeSchemaBuilder("string").unique())
144
+ * .addField("age", new FieldTypeSchemaBuilder("number").range(0, 150))
145
+ * .build();
146
+ *
147
+ * await client.createCollection("users", schema);
148
+ * ```
149
+ */
150
+ class SchemaBuilder {
151
+ constructor() {
152
+ this.schema = {
153
+ fields: {},
154
+ version: 1,
155
+ bypass_ripple: true,
156
+ };
157
+ }
158
+ /**
159
+ * Add a field to the schema
160
+ */
161
+ addField(name, field) {
162
+ this.schema.fields[name] = field instanceof FieldTypeSchemaBuilder ? field.build() : field;
163
+ return this;
164
+ }
165
+ /**
166
+ * Set bypass_ripple flag
167
+ */
168
+ bypassRipple(bypass) {
169
+ this.schema.bypass_ripple = bypass;
170
+ return this;
171
+ }
172
+ /**
173
+ * Set schema version
174
+ */
175
+ version(version) {
176
+ this.schema.version = version;
177
+ return this;
178
+ }
179
+ /**
180
+ * Build the final Schema
181
+ */
182
+ build() {
183
+ return this.schema;
184
+ }
185
+ }
186
+ exports.SchemaBuilder = SchemaBuilder;
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Full-text and vector search support for ekoDB
3
+ *
4
+ * This module provides comprehensive search capabilities including:
5
+ * - Full-text search with fuzzy matching
6
+ * - Vector/semantic search
7
+ * - Hybrid search (text + vector)
8
+ * - Field weighting and boosting
9
+ */
10
+ export interface SearchQuery {
11
+ /** Search query string */
12
+ query: string;
13
+ /** Language for stemming (e.g., "english", "spanish", "french") */
14
+ language?: string;
15
+ /** Case-sensitive search */
16
+ case_sensitive?: boolean;
17
+ /** Enable fuzzy matching (typo tolerance) */
18
+ fuzzy?: boolean;
19
+ /** Minimum score threshold (0.0-1.0) */
20
+ min_score?: number;
21
+ /** Fields to search in (comma-separated or array) */
22
+ fields?: string | string[];
23
+ /** Field weights (format: "field1:2.0,field2:1.5" or object) */
24
+ weights?: string | Record<string, number>;
25
+ /** Enable stemming */
26
+ enable_stemming?: boolean;
27
+ /** Boost exact matches */
28
+ boost_exact?: boolean;
29
+ /** Maximum edit distance for fuzzy matching (0-5) */
30
+ max_edit_distance?: number;
31
+ /** Bypass ripple cache */
32
+ bypass_ripple?: boolean;
33
+ /** Bypass cache */
34
+ bypass_cache?: boolean;
35
+ /** Maximum number of results to return */
36
+ limit?: number;
37
+ /** Query vector for semantic search */
38
+ vector?: number[];
39
+ /** Field containing vectors (default: "embedding") */
40
+ vector_field?: string;
41
+ /** Similarity metric: "cosine", "euclidean", "dotproduct" */
42
+ vector_metric?: string;
43
+ /** Number of vector results (k-nearest neighbors) */
44
+ vector_k?: number;
45
+ /** Minimum similarity threshold */
46
+ vector_threshold?: number;
47
+ /** Weight for text search (0.0-1.0) */
48
+ text_weight?: number;
49
+ /** Weight for vector search (0.0-1.0) */
50
+ vector_weight?: number;
51
+ }
52
+ /**
53
+ * Search result with score and matched fields
54
+ */
55
+ export interface SearchResult {
56
+ /** The matched record */
57
+ record: any;
58
+ /** Relevance score */
59
+ score: number;
60
+ /** Fields that matched the search query */
61
+ matched_fields: string[];
62
+ }
63
+ /**
64
+ * Search response containing results and metadata
65
+ */
66
+ export interface SearchResponse {
67
+ /** Array of search results */
68
+ results: SearchResult[];
69
+ /** Total number of results found */
70
+ total: number;
71
+ /** Query execution time in milliseconds */
72
+ took_ms?: number;
73
+ }
74
+ /**
75
+ * Builder for constructing search queries with fluent API
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const query = new SearchQueryBuilder("john")
80
+ * .fields(["name", "email"])
81
+ * .fuzzy(true)
82
+ * .minScore(0.5)
83
+ * .limit(10)
84
+ * .build();
85
+ *
86
+ * const results = await client.search("users", query);
87
+ * ```
88
+ */
89
+ export declare class SearchQueryBuilder {
90
+ private query;
91
+ constructor(queryString: string);
92
+ /**
93
+ * Set the language for stemming
94
+ */
95
+ language(language: string): this;
96
+ /**
97
+ * Enable case-sensitive search
98
+ */
99
+ caseSensitive(enabled?: boolean): this;
100
+ /**
101
+ * Enable fuzzy matching
102
+ */
103
+ fuzzy(enabled?: boolean): this;
104
+ /**
105
+ * Set minimum score threshold
106
+ */
107
+ minScore(score: number): this;
108
+ /**
109
+ * Set fields to search in
110
+ */
111
+ fields(fields: string | string[]): this;
112
+ /**
113
+ * Set field weights
114
+ */
115
+ weights(weights: string | Record<string, number>): this;
116
+ /**
117
+ * Enable stemming
118
+ */
119
+ enableStemming(enabled?: boolean): this;
120
+ /**
121
+ * Boost exact matches
122
+ */
123
+ boostExact(enabled?: boolean): this;
124
+ /**
125
+ * Set maximum edit distance for fuzzy matching
126
+ */
127
+ maxEditDistance(distance: number): this;
128
+ /**
129
+ * Set query vector for semantic search
130
+ */
131
+ vector(vector: number[]): this;
132
+ /**
133
+ * Set vector field name
134
+ */
135
+ vectorField(field: string): this;
136
+ /**
137
+ * Set vector similarity metric
138
+ */
139
+ vectorMetric(metric: "cosine" | "euclidean" | "dotproduct"): this;
140
+ /**
141
+ * Set number of vector results (k-nearest neighbors)
142
+ */
143
+ vectorK(k: number): this;
144
+ /**
145
+ * Set minimum similarity threshold
146
+ */
147
+ vectorThreshold(threshold: number): this;
148
+ /**
149
+ * Set text search weight for hybrid search
150
+ */
151
+ textWeight(weight: number): this;
152
+ /**
153
+ * Set vector search weight for hybrid search
154
+ */
155
+ vectorWeight(weight: number): this;
156
+ /**
157
+ * Bypass ripple cache
158
+ */
159
+ bypassRipple(bypass?: boolean): this;
160
+ /**
161
+ * Bypass cache
162
+ */
163
+ bypassCache(bypass?: boolean): this;
164
+ /**
165
+ * Set maximum number of results to return
166
+ */
167
+ limit(limit: number): this;
168
+ /**
169
+ * Build the final SearchQuery object
170
+ */
171
+ build(): SearchQuery;
172
+ }