@ekodb/ekodb-client 0.2.1 → 0.4.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/dist/client.d.ts +49 -3
- package/dist/client.js +144 -39
- package/dist/functions.d.ts +195 -0
- package/dist/functions.js +154 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/package.json +2 -1
- package/src/client.ts +245 -25
- package/src/functions.ts +420 -0
- package/src/index.ts +12 -0
package/src/functions.ts
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripts API for ekoDB TypeScript client
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface Script {
|
|
6
|
+
label: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
version: string;
|
|
10
|
+
parameters: { [key: string]: ParameterDefinition };
|
|
11
|
+
functions: FunctionStageConfig[];
|
|
12
|
+
tags: string[];
|
|
13
|
+
created_at?: string;
|
|
14
|
+
updated_at?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ParameterDefinition {
|
|
18
|
+
required: boolean;
|
|
19
|
+
default?: any;
|
|
20
|
+
description?: string;
|
|
21
|
+
param_type?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ParameterValue removed - use plain values instead
|
|
25
|
+
|
|
26
|
+
export type FunctionStageConfig =
|
|
27
|
+
| { type: "FindAll"; collection: string }
|
|
28
|
+
| {
|
|
29
|
+
type: "Query";
|
|
30
|
+
collection: string;
|
|
31
|
+
filter?: Record<string, any>;
|
|
32
|
+
sort?: SortFieldConfig[];
|
|
33
|
+
limit?: number;
|
|
34
|
+
skip?: number;
|
|
35
|
+
}
|
|
36
|
+
| { type: "Project"; fields: string[]; exclude: boolean }
|
|
37
|
+
| {
|
|
38
|
+
type: "Group";
|
|
39
|
+
by_fields: string[];
|
|
40
|
+
functions: GroupFunctionConfig[];
|
|
41
|
+
}
|
|
42
|
+
| { type: "Count"; output_field: string }
|
|
43
|
+
| { type: "Filter"; filter: Record<string, any> }
|
|
44
|
+
| { type: "Sort"; sort: SortFieldConfig[] }
|
|
45
|
+
| { type: "Limit"; limit: number }
|
|
46
|
+
| { type: "Skip"; skip: number }
|
|
47
|
+
| {
|
|
48
|
+
type: "Insert";
|
|
49
|
+
collection: string;
|
|
50
|
+
record: Record<string, any>;
|
|
51
|
+
bypass_ripple?: boolean;
|
|
52
|
+
ttl?: number;
|
|
53
|
+
}
|
|
54
|
+
| {
|
|
55
|
+
type: "Update";
|
|
56
|
+
collection: string;
|
|
57
|
+
filter: Record<string, any>;
|
|
58
|
+
updates: Record<string, any>;
|
|
59
|
+
bypass_ripple?: boolean;
|
|
60
|
+
ttl?: number;
|
|
61
|
+
}
|
|
62
|
+
| {
|
|
63
|
+
type: "UpdateById";
|
|
64
|
+
collection: string;
|
|
65
|
+
record_id: string;
|
|
66
|
+
updates: Record<string, any>;
|
|
67
|
+
bypass_ripple?: boolean;
|
|
68
|
+
ttl?: number;
|
|
69
|
+
}
|
|
70
|
+
| {
|
|
71
|
+
type: "Delete";
|
|
72
|
+
collection: string;
|
|
73
|
+
filter: Record<string, any>;
|
|
74
|
+
bypass_ripple?: boolean;
|
|
75
|
+
}
|
|
76
|
+
| {
|
|
77
|
+
type: "DeleteById";
|
|
78
|
+
collection: string;
|
|
79
|
+
record_id: string;
|
|
80
|
+
bypass_ripple?: boolean;
|
|
81
|
+
}
|
|
82
|
+
| {
|
|
83
|
+
type: "BatchInsert";
|
|
84
|
+
collection: string;
|
|
85
|
+
records: Record<string, any>[];
|
|
86
|
+
bypass_ripple?: boolean;
|
|
87
|
+
}
|
|
88
|
+
| {
|
|
89
|
+
type: "BatchDelete";
|
|
90
|
+
collection: string;
|
|
91
|
+
record_ids: string[];
|
|
92
|
+
bypass_ripple?: boolean;
|
|
93
|
+
}
|
|
94
|
+
| {
|
|
95
|
+
type: "HttpRequest";
|
|
96
|
+
url: string;
|
|
97
|
+
method?: string;
|
|
98
|
+
headers?: Record<string, string>;
|
|
99
|
+
body?: any;
|
|
100
|
+
}
|
|
101
|
+
| {
|
|
102
|
+
type: "VectorSearch";
|
|
103
|
+
collection: string;
|
|
104
|
+
query_vector: number[];
|
|
105
|
+
limit?: number;
|
|
106
|
+
threshold?: number;
|
|
107
|
+
}
|
|
108
|
+
| {
|
|
109
|
+
type: "TextSearch";
|
|
110
|
+
collection: string;
|
|
111
|
+
query_text: string;
|
|
112
|
+
fields?: string[];
|
|
113
|
+
limit?: number;
|
|
114
|
+
fuzzy?: boolean;
|
|
115
|
+
}
|
|
116
|
+
| {
|
|
117
|
+
type: "HybridSearch";
|
|
118
|
+
collection: string;
|
|
119
|
+
query_text: string;
|
|
120
|
+
query_vector?: number[];
|
|
121
|
+
limit?: number;
|
|
122
|
+
}
|
|
123
|
+
| {
|
|
124
|
+
type: "Chat";
|
|
125
|
+
messages: ChatMessage[];
|
|
126
|
+
model?: string;
|
|
127
|
+
temperature?: number;
|
|
128
|
+
max_tokens?: number;
|
|
129
|
+
}
|
|
130
|
+
| {
|
|
131
|
+
type: "Embed";
|
|
132
|
+
input_field: string;
|
|
133
|
+
output_field: string;
|
|
134
|
+
model?: string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export interface ChatMessage {
|
|
138
|
+
role: string;
|
|
139
|
+
content: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const ChatMessage = {
|
|
143
|
+
system: (content: string): ChatMessage => ({
|
|
144
|
+
role: "system",
|
|
145
|
+
content: content,
|
|
146
|
+
}),
|
|
147
|
+
user: (content: string): ChatMessage => ({
|
|
148
|
+
role: "user",
|
|
149
|
+
content: content,
|
|
150
|
+
}),
|
|
151
|
+
assistant: (content: string): ChatMessage => ({
|
|
152
|
+
role: "assistant",
|
|
153
|
+
content: content,
|
|
154
|
+
}),
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export interface GroupFunctionConfig {
|
|
158
|
+
output_field: string;
|
|
159
|
+
operation:
|
|
160
|
+
| "Sum"
|
|
161
|
+
| "Average"
|
|
162
|
+
| "Count"
|
|
163
|
+
| "Min"
|
|
164
|
+
| "Max"
|
|
165
|
+
| "First"
|
|
166
|
+
| "Last"
|
|
167
|
+
| "Push";
|
|
168
|
+
input_field?: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface SortFieldConfig {
|
|
172
|
+
field: string;
|
|
173
|
+
ascending: boolean;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface FunctionResult {
|
|
177
|
+
records: Record<string, any>[];
|
|
178
|
+
stats: FunctionStats;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface FunctionStats {
|
|
182
|
+
input_count: number;
|
|
183
|
+
output_count: number;
|
|
184
|
+
execution_time_ms: number;
|
|
185
|
+
stages_executed: number;
|
|
186
|
+
stage_stats: StageStats[];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface StageStats {
|
|
190
|
+
stage: string;
|
|
191
|
+
input_count: number;
|
|
192
|
+
output_count: number;
|
|
193
|
+
execution_time_ms: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Stage builder functions
|
|
197
|
+
export const Stage = {
|
|
198
|
+
findAll: (collection: string): FunctionStageConfig => ({
|
|
199
|
+
type: "FindAll",
|
|
200
|
+
collection,
|
|
201
|
+
}),
|
|
202
|
+
|
|
203
|
+
query: (
|
|
204
|
+
collection: string,
|
|
205
|
+
filter?: Record<string, any>,
|
|
206
|
+
sort?: SortFieldConfig[],
|
|
207
|
+
limit?: number,
|
|
208
|
+
skip?: number,
|
|
209
|
+
): FunctionStageConfig => ({
|
|
210
|
+
type: "Query",
|
|
211
|
+
collection,
|
|
212
|
+
filter,
|
|
213
|
+
sort,
|
|
214
|
+
limit,
|
|
215
|
+
skip,
|
|
216
|
+
}),
|
|
217
|
+
|
|
218
|
+
project: (fields: string[], exclude = false): FunctionStageConfig => ({
|
|
219
|
+
type: "Project",
|
|
220
|
+
fields,
|
|
221
|
+
exclude,
|
|
222
|
+
}),
|
|
223
|
+
|
|
224
|
+
group: (
|
|
225
|
+
by_fields: string[],
|
|
226
|
+
functions: GroupFunctionConfig[],
|
|
227
|
+
): FunctionStageConfig => ({
|
|
228
|
+
type: "Group",
|
|
229
|
+
by_fields,
|
|
230
|
+
functions,
|
|
231
|
+
}),
|
|
232
|
+
|
|
233
|
+
count: (output_field = "count"): FunctionStageConfig => ({
|
|
234
|
+
type: "Count",
|
|
235
|
+
output_field,
|
|
236
|
+
}),
|
|
237
|
+
|
|
238
|
+
insert: (
|
|
239
|
+
collection: string,
|
|
240
|
+
record: Record<string, any>,
|
|
241
|
+
bypassRipple = false,
|
|
242
|
+
ttl?: number,
|
|
243
|
+
): FunctionStageConfig => ({
|
|
244
|
+
type: "Insert",
|
|
245
|
+
collection,
|
|
246
|
+
record,
|
|
247
|
+
bypass_ripple: bypassRipple,
|
|
248
|
+
ttl,
|
|
249
|
+
}),
|
|
250
|
+
|
|
251
|
+
update: (
|
|
252
|
+
collection: string,
|
|
253
|
+
filter: Record<string, any>,
|
|
254
|
+
updates: Record<string, any>,
|
|
255
|
+
bypassRipple = false,
|
|
256
|
+
ttl?: number,
|
|
257
|
+
): FunctionStageConfig => ({
|
|
258
|
+
type: "Update",
|
|
259
|
+
collection,
|
|
260
|
+
filter,
|
|
261
|
+
updates,
|
|
262
|
+
bypass_ripple: bypassRipple,
|
|
263
|
+
ttl,
|
|
264
|
+
}),
|
|
265
|
+
|
|
266
|
+
updateById: (
|
|
267
|
+
collection: string,
|
|
268
|
+
record_id: string,
|
|
269
|
+
updates: Record<string, any>,
|
|
270
|
+
bypassRipple = false,
|
|
271
|
+
ttl?: number,
|
|
272
|
+
): FunctionStageConfig => ({
|
|
273
|
+
type: "UpdateById",
|
|
274
|
+
collection,
|
|
275
|
+
record_id,
|
|
276
|
+
updates,
|
|
277
|
+
bypass_ripple: bypassRipple,
|
|
278
|
+
ttl,
|
|
279
|
+
}),
|
|
280
|
+
|
|
281
|
+
delete: (
|
|
282
|
+
collection: string,
|
|
283
|
+
filter: Record<string, any>,
|
|
284
|
+
bypassRipple = false,
|
|
285
|
+
): FunctionStageConfig => ({
|
|
286
|
+
type: "Delete",
|
|
287
|
+
collection,
|
|
288
|
+
filter,
|
|
289
|
+
bypass_ripple: bypassRipple,
|
|
290
|
+
}),
|
|
291
|
+
|
|
292
|
+
deleteById: (
|
|
293
|
+
collection: string,
|
|
294
|
+
record_id: string,
|
|
295
|
+
bypassRipple = false,
|
|
296
|
+
): FunctionStageConfig => ({
|
|
297
|
+
type: "DeleteById",
|
|
298
|
+
collection,
|
|
299
|
+
record_id,
|
|
300
|
+
bypass_ripple: bypassRipple,
|
|
301
|
+
}),
|
|
302
|
+
|
|
303
|
+
batchInsert: (
|
|
304
|
+
collection: string,
|
|
305
|
+
records: Record<string, any>[],
|
|
306
|
+
bypassRipple = false,
|
|
307
|
+
): FunctionStageConfig => ({
|
|
308
|
+
type: "BatchInsert",
|
|
309
|
+
collection,
|
|
310
|
+
records,
|
|
311
|
+
bypass_ripple: bypassRipple,
|
|
312
|
+
}),
|
|
313
|
+
|
|
314
|
+
batchDelete: (
|
|
315
|
+
collection: string,
|
|
316
|
+
record_ids: string[],
|
|
317
|
+
bypassRipple = false,
|
|
318
|
+
): FunctionStageConfig => ({
|
|
319
|
+
type: "BatchDelete",
|
|
320
|
+
collection,
|
|
321
|
+
record_ids,
|
|
322
|
+
bypass_ripple: bypassRipple,
|
|
323
|
+
}),
|
|
324
|
+
|
|
325
|
+
filter: (filter: Record<string, any>): FunctionStageConfig => ({
|
|
326
|
+
type: "Filter",
|
|
327
|
+
filter,
|
|
328
|
+
}),
|
|
329
|
+
|
|
330
|
+
sort: (sort: SortFieldConfig[]): FunctionStageConfig => ({
|
|
331
|
+
type: "Sort",
|
|
332
|
+
sort,
|
|
333
|
+
}),
|
|
334
|
+
|
|
335
|
+
limit: (limit: number): FunctionStageConfig => ({
|
|
336
|
+
type: "Limit",
|
|
337
|
+
limit,
|
|
338
|
+
}),
|
|
339
|
+
|
|
340
|
+
skip: (skip: number): FunctionStageConfig => ({
|
|
341
|
+
type: "Skip",
|
|
342
|
+
skip,
|
|
343
|
+
}),
|
|
344
|
+
|
|
345
|
+
httpRequest: (
|
|
346
|
+
url: string,
|
|
347
|
+
method = "GET",
|
|
348
|
+
headers?: Record<string, string>,
|
|
349
|
+
body?: any,
|
|
350
|
+
): FunctionStageConfig => ({
|
|
351
|
+
type: "HttpRequest",
|
|
352
|
+
url,
|
|
353
|
+
method,
|
|
354
|
+
headers,
|
|
355
|
+
body,
|
|
356
|
+
}),
|
|
357
|
+
|
|
358
|
+
vectorSearch: (
|
|
359
|
+
collection: string,
|
|
360
|
+
query_vector: number[],
|
|
361
|
+
limit?: number,
|
|
362
|
+
threshold?: number,
|
|
363
|
+
): FunctionStageConfig => ({
|
|
364
|
+
type: "VectorSearch",
|
|
365
|
+
collection,
|
|
366
|
+
query_vector,
|
|
367
|
+
limit,
|
|
368
|
+
threshold,
|
|
369
|
+
}),
|
|
370
|
+
|
|
371
|
+
textSearch: (
|
|
372
|
+
collection: string,
|
|
373
|
+
query_text: string,
|
|
374
|
+
options?: { fields?: string[]; limit?: number; fuzzy?: boolean },
|
|
375
|
+
): FunctionStageConfig => ({
|
|
376
|
+
type: "TextSearch",
|
|
377
|
+
collection,
|
|
378
|
+
query_text,
|
|
379
|
+
fields: options?.fields,
|
|
380
|
+
limit: options?.limit,
|
|
381
|
+
fuzzy: options?.fuzzy,
|
|
382
|
+
}),
|
|
383
|
+
|
|
384
|
+
hybridSearch: (
|
|
385
|
+
collection: string,
|
|
386
|
+
query_text: string,
|
|
387
|
+
query_vector?: number[],
|
|
388
|
+
limit?: number,
|
|
389
|
+
): FunctionStageConfig => ({
|
|
390
|
+
type: "HybridSearch",
|
|
391
|
+
collection,
|
|
392
|
+
query_text,
|
|
393
|
+
query_vector,
|
|
394
|
+
limit,
|
|
395
|
+
}),
|
|
396
|
+
|
|
397
|
+
chat: (
|
|
398
|
+
messages: ChatMessage[],
|
|
399
|
+
model?: string,
|
|
400
|
+
temperature?: number,
|
|
401
|
+
max_tokens?: number,
|
|
402
|
+
): FunctionStageConfig => ({
|
|
403
|
+
type: "Chat",
|
|
404
|
+
messages,
|
|
405
|
+
model,
|
|
406
|
+
temperature,
|
|
407
|
+
max_tokens,
|
|
408
|
+
}),
|
|
409
|
+
|
|
410
|
+
embed: (
|
|
411
|
+
input_field: string,
|
|
412
|
+
output_field: string,
|
|
413
|
+
model?: string,
|
|
414
|
+
): FunctionStageConfig => ({
|
|
415
|
+
type: "Embed",
|
|
416
|
+
input_field,
|
|
417
|
+
output_field,
|
|
418
|
+
model,
|
|
419
|
+
}),
|
|
420
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export {
|
|
2
2
|
EkoDBClient,
|
|
3
3
|
WebSocketClient,
|
|
4
|
+
SerializationFormat,
|
|
4
5
|
MergeStrategy,
|
|
5
6
|
RateLimitError,
|
|
6
7
|
} from "./client";
|
|
@@ -13,6 +14,7 @@ export {
|
|
|
13
14
|
DistanceMetric,
|
|
14
15
|
} from "./schema";
|
|
15
16
|
export { JoinBuilder } from "./join";
|
|
17
|
+
export { Stage, ChatMessage } from "./functions";
|
|
16
18
|
export type { SearchQuery, SearchResult, SearchResponse } from "./search";
|
|
17
19
|
export type {
|
|
18
20
|
Schema,
|
|
@@ -21,6 +23,16 @@ export type {
|
|
|
21
23
|
CollectionMetadata,
|
|
22
24
|
} from "./schema";
|
|
23
25
|
export type { JoinConfig } from "./join";
|
|
26
|
+
export type {
|
|
27
|
+
Script,
|
|
28
|
+
ParameterDefinition,
|
|
29
|
+
FunctionStageConfig,
|
|
30
|
+
GroupFunctionConfig,
|
|
31
|
+
SortFieldConfig,
|
|
32
|
+
FunctionResult,
|
|
33
|
+
FunctionStats,
|
|
34
|
+
StageStats,
|
|
35
|
+
} from "./functions";
|
|
24
36
|
export type {
|
|
25
37
|
Record,
|
|
26
38
|
Query,
|