@ekodb/ekodb-client 0.5.0 → 0.6.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.
@@ -5,12 +5,12 @@ export interface Script {
5
5
  label: string;
6
6
  name: string;
7
7
  description?: string;
8
- version: string;
8
+ version?: string;
9
9
  parameters: {
10
10
  [key: string]: ParameterDefinition;
11
11
  };
12
12
  functions: FunctionStageConfig[];
13
- tags: string[];
13
+ tags?: string[];
14
14
  created_at?: string;
15
15
  updated_at?: string;
16
16
  }
@@ -129,6 +129,51 @@ export type FunctionStageConfig = {
129
129
  input_field: string;
130
130
  output_field: string;
131
131
  model?: string;
132
+ } | {
133
+ type: "FindById";
134
+ collection: string;
135
+ record_id: string;
136
+ } | {
137
+ type: "FindOne";
138
+ collection: string;
139
+ key: string;
140
+ value: any;
141
+ } | {
142
+ type: "If";
143
+ condition: ScriptCondition;
144
+ then_functions: FunctionStageConfig[];
145
+ else_functions?: FunctionStageConfig[];
146
+ } | {
147
+ type: "ForEach";
148
+ functions: FunctionStageConfig[];
149
+ } | {
150
+ type: "CallFunction";
151
+ function_label: string;
152
+ params?: Record<string, any>;
153
+ } | {
154
+ type: "FindOneAndUpdate";
155
+ collection: string;
156
+ record_id: string;
157
+ updates: Record<string, any>;
158
+ bypass_ripple?: boolean;
159
+ ttl?: number;
160
+ } | {
161
+ type: "UpdateWithAction";
162
+ collection: string;
163
+ record_id: string;
164
+ action: string;
165
+ field: string;
166
+ value: any;
167
+ bypass_ripple?: boolean;
168
+ } | {
169
+ type: "CreateSavepoint";
170
+ name: string;
171
+ } | {
172
+ type: "RollbackToSavepoint";
173
+ name: string;
174
+ } | {
175
+ type: "ReleaseSavepoint";
176
+ name: string;
132
177
  };
133
178
  export interface ChatMessage {
134
179
  role: string;
@@ -148,6 +193,34 @@ export interface SortFieldConfig {
148
193
  field: string;
149
194
  ascending: boolean;
150
195
  }
196
+ export type ScriptCondition = {
197
+ type: "FieldEquals";
198
+ field: string;
199
+ value: any;
200
+ } | {
201
+ type: "FieldExists";
202
+ field: string;
203
+ } | {
204
+ type: "HasRecords";
205
+ } | {
206
+ type: "CountEquals";
207
+ count: number;
208
+ } | {
209
+ type: "CountGreaterThan";
210
+ count: number;
211
+ } | {
212
+ type: "CountLessThan";
213
+ count: number;
214
+ } | {
215
+ type: "And";
216
+ conditions: ScriptCondition[];
217
+ } | {
218
+ type: "Or";
219
+ conditions: ScriptCondition[];
220
+ } | {
221
+ type: "Not";
222
+ condition: ScriptCondition;
223
+ };
151
224
  export interface FunctionResult {
152
225
  records: Record<string, any>[];
153
226
  stats: FunctionStats;
@@ -192,4 +265,14 @@ export declare const Stage: {
192
265
  hybridSearch: (collection: string, query_text: string, query_vector?: number[], limit?: number) => FunctionStageConfig;
193
266
  chat: (messages: ChatMessage[], model?: string, temperature?: number, max_tokens?: number) => FunctionStageConfig;
194
267
  embed: (input_field: string, output_field: string, model?: string) => FunctionStageConfig;
268
+ findById: (collection: string, record_id: string) => FunctionStageConfig;
269
+ findOne: (collection: string, key: string, value: any) => FunctionStageConfig;
270
+ if: (condition: ScriptCondition, thenFunctions: FunctionStageConfig[], elseFunctions?: FunctionStageConfig[]) => FunctionStageConfig;
271
+ forEach: (functions: FunctionStageConfig[]) => FunctionStageConfig;
272
+ callFunction: (function_label: string, params?: Record<string, any>) => FunctionStageConfig;
273
+ findOneAndUpdate: (collection: string, record_id: string, updates: Record<string, any>, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
274
+ updateWithAction: (collection: string, record_id: string, action: string, field: string, value: any, bypassRipple?: boolean) => FunctionStageConfig;
275
+ createSavepoint: (name: string) => FunctionStageConfig;
276
+ rollbackToSavepoint: (name: string) => FunctionStageConfig;
277
+ releaseSavepoint: (name: string) => FunctionStageConfig;
195
278
  };
package/dist/functions.js CHANGED
@@ -151,4 +151,59 @@ exports.Stage = {
151
151
  output_field,
152
152
  model,
153
153
  }),
154
+ findById: (collection, record_id) => ({
155
+ type: "FindById",
156
+ collection,
157
+ record_id,
158
+ }),
159
+ findOne: (collection, key, value) => ({
160
+ type: "FindOne",
161
+ collection,
162
+ key,
163
+ value,
164
+ }),
165
+ if: (condition, thenFunctions, elseFunctions) => ({
166
+ type: "If",
167
+ condition,
168
+ then_functions: thenFunctions,
169
+ else_functions: elseFunctions,
170
+ }),
171
+ forEach: (functions) => ({
172
+ type: "ForEach",
173
+ functions,
174
+ }),
175
+ callFunction: (function_label, params) => ({
176
+ type: "CallFunction",
177
+ function_label,
178
+ params,
179
+ }),
180
+ findOneAndUpdate: (collection, record_id, updates, bypassRipple = false, ttl) => ({
181
+ type: "FindOneAndUpdate",
182
+ collection,
183
+ record_id,
184
+ updates,
185
+ bypass_ripple: bypassRipple,
186
+ ttl,
187
+ }),
188
+ updateWithAction: (collection, record_id, action, field, value, bypassRipple = false) => ({
189
+ type: "UpdateWithAction",
190
+ collection,
191
+ record_id,
192
+ action,
193
+ field,
194
+ value,
195
+ bypass_ripple: bypassRipple,
196
+ }),
197
+ createSavepoint: (name) => ({
198
+ type: "CreateSavepoint",
199
+ name,
200
+ }),
201
+ rollbackToSavepoint: (name) => ({
202
+ type: "RollbackToSavepoint",
203
+ name,
204
+ }),
205
+ releaseSavepoint: (name) => ({
206
+ type: "ReleaseSavepoint",
207
+ name,
208
+ }),
154
209
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekodb/ekodb-client",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Official TypeScript/JavaScript client for ekoDB",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/functions.ts CHANGED
@@ -6,10 +6,10 @@ export interface Script {
6
6
  label: string;
7
7
  name: string;
8
8
  description?: string;
9
- version: string;
9
+ version?: string;
10
10
  parameters: { [key: string]: ParameterDefinition };
11
11
  functions: FunctionStageConfig[];
12
- tags: string[];
12
+ tags?: string[];
13
13
  created_at?: string;
14
14
  updated_at?: string;
15
15
  }
@@ -132,6 +132,61 @@ export type FunctionStageConfig =
132
132
  input_field: string;
133
133
  output_field: string;
134
134
  model?: string;
135
+ }
136
+ | {
137
+ type: "FindById";
138
+ collection: string;
139
+ record_id: string;
140
+ }
141
+ | {
142
+ type: "FindOne";
143
+ collection: string;
144
+ key: string;
145
+ value: any;
146
+ }
147
+ | {
148
+ type: "If";
149
+ condition: ScriptCondition;
150
+ then_functions: FunctionStageConfig[];
151
+ else_functions?: FunctionStageConfig[];
152
+ }
153
+ | {
154
+ type: "ForEach";
155
+ functions: FunctionStageConfig[];
156
+ }
157
+ | {
158
+ type: "CallFunction";
159
+ function_label: string;
160
+ params?: Record<string, any>;
161
+ }
162
+ | {
163
+ type: "FindOneAndUpdate";
164
+ collection: string;
165
+ record_id: string;
166
+ updates: Record<string, any>;
167
+ bypass_ripple?: boolean;
168
+ ttl?: number;
169
+ }
170
+ | {
171
+ type: "UpdateWithAction";
172
+ collection: string;
173
+ record_id: string;
174
+ action: string;
175
+ field: string;
176
+ value: any;
177
+ bypass_ripple?: boolean;
178
+ }
179
+ | {
180
+ type: "CreateSavepoint";
181
+ name: string;
182
+ }
183
+ | {
184
+ type: "RollbackToSavepoint";
185
+ name: string;
186
+ }
187
+ | {
188
+ type: "ReleaseSavepoint";
189
+ name: string;
135
190
  };
136
191
 
137
192
  export interface ChatMessage {
@@ -173,6 +228,17 @@ export interface SortFieldConfig {
173
228
  ascending: boolean;
174
229
  }
175
230
 
231
+ export type ScriptCondition =
232
+ | { type: "FieldEquals"; field: string; value: any }
233
+ | { type: "FieldExists"; field: string }
234
+ | { type: "HasRecords" }
235
+ | { type: "CountEquals"; count: number }
236
+ | { type: "CountGreaterThan"; count: number }
237
+ | { type: "CountLessThan"; count: number }
238
+ | { type: "And"; conditions: ScriptCondition[] }
239
+ | { type: "Or"; conditions: ScriptCondition[] }
240
+ | { type: "Not"; condition: ScriptCondition };
241
+
176
242
  export interface FunctionResult {
177
243
  records: Record<string, any>[];
178
244
  stats: FunctionStats;
@@ -417,4 +483,93 @@ export const Stage = {
417
483
  output_field,
418
484
  model,
419
485
  }),
486
+
487
+ findById: (collection: string, record_id: string): FunctionStageConfig => ({
488
+ type: "FindById",
489
+ collection,
490
+ record_id,
491
+ }),
492
+
493
+ findOne: (
494
+ collection: string,
495
+ key: string,
496
+ value: any,
497
+ ): FunctionStageConfig => ({
498
+ type: "FindOne",
499
+ collection,
500
+ key,
501
+ value,
502
+ }),
503
+
504
+ if: (
505
+ condition: ScriptCondition,
506
+ thenFunctions: FunctionStageConfig[],
507
+ elseFunctions?: FunctionStageConfig[],
508
+ ): FunctionStageConfig => ({
509
+ type: "If",
510
+ condition,
511
+ then_functions: thenFunctions,
512
+ else_functions: elseFunctions,
513
+ }),
514
+
515
+ forEach: (functions: FunctionStageConfig[]): FunctionStageConfig => ({
516
+ type: "ForEach",
517
+ functions,
518
+ }),
519
+
520
+ callFunction: (
521
+ function_label: string,
522
+ params?: Record<string, any>,
523
+ ): FunctionStageConfig => ({
524
+ type: "CallFunction",
525
+ function_label,
526
+ params,
527
+ }),
528
+
529
+ findOneAndUpdate: (
530
+ collection: string,
531
+ record_id: string,
532
+ updates: Record<string, any>,
533
+ bypassRipple = false,
534
+ ttl?: number,
535
+ ): FunctionStageConfig => ({
536
+ type: "FindOneAndUpdate",
537
+ collection,
538
+ record_id,
539
+ updates,
540
+ bypass_ripple: bypassRipple,
541
+ ttl,
542
+ }),
543
+
544
+ updateWithAction: (
545
+ collection: string,
546
+ record_id: string,
547
+ action: string,
548
+ field: string,
549
+ value: any,
550
+ bypassRipple = false,
551
+ ): FunctionStageConfig => ({
552
+ type: "UpdateWithAction",
553
+ collection,
554
+ record_id,
555
+ action,
556
+ field,
557
+ value,
558
+ bypass_ripple: bypassRipple,
559
+ }),
560
+
561
+ createSavepoint: (name: string): FunctionStageConfig => ({
562
+ type: "CreateSavepoint",
563
+ name,
564
+ }),
565
+
566
+ rollbackToSavepoint: (name: string): FunctionStageConfig => ({
567
+ type: "RollbackToSavepoint",
568
+ name,
569
+ }),
570
+
571
+ releaseSavepoint: (name: string): FunctionStageConfig => ({
572
+ type: "ReleaseSavepoint",
573
+ name,
574
+ }),
420
575
  };