@ekodb/ekodb-client 0.6.1 → 0.7.1
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 +56 -3
- package/dist/client.js +78 -5
- package/dist/functions.d.ts +25 -0
- package/dist/functions.js +26 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/query-builder.test.d.ts +4 -0
- package/dist/query-builder.test.js +318 -0
- package/dist/utils.d.ts +88 -3
- package/dist/utils.js +130 -3
- package/dist/utils.test.d.ts +4 -0
- package/dist/utils.test.js +411 -0
- package/package.json +7 -4
- package/src/client.ts +125 -5
- package/src/functions.ts +59 -0
- package/src/index.ts +2 -0
- package/src/query-builder.test.ts +404 -0
- package/src/utils.test.ts +506 -0
- package/src/utils.ts +165 -3
package/dist/utils.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```typescript
|
|
14
|
-
* const user = await client.
|
|
14
|
+
* const user = await client.findById('users', userId);
|
|
15
15
|
* const email = getValue(user.email); // Extracts string from { type: 'String', value: 'user@example.com' }
|
|
16
16
|
* const age = getValue(user.age); // Extracts number from { type: 'Integer', value: 25 }
|
|
17
17
|
* ```
|
|
@@ -27,7 +27,7 @@ export declare function getValue<T = any>(field: any): T;
|
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```typescript
|
|
30
|
-
* const user = await client.
|
|
30
|
+
* const user = await client.findById('users', userId);
|
|
31
31
|
* const { email, first_name, status } = getValues(user, ['email', 'first_name', 'status']);
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
@@ -81,9 +81,94 @@ export declare function getObjectValue<T = any>(field: any): T | null;
|
|
|
81
81
|
*
|
|
82
82
|
* @example
|
|
83
83
|
* ```typescript
|
|
84
|
-
* const user = await client.
|
|
84
|
+
* const user = await client.findById('users', userId);
|
|
85
85
|
* const plainUser = extractRecord(user);
|
|
86
86
|
* // { id: '123', email: 'user@example.com', first_name: 'John', ... }
|
|
87
87
|
* ```
|
|
88
88
|
*/
|
|
89
89
|
export declare function extractRecord<T extends Record<string, any>>(record: any): T;
|
|
90
|
+
export interface WrappedFieldValue {
|
|
91
|
+
type: string;
|
|
92
|
+
value: unknown;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Field builders for creating wrapped type values to send to ekoDB.
|
|
96
|
+
* These are the inverse of the getValue* extraction functions.
|
|
97
|
+
*/
|
|
98
|
+
export declare const Field: {
|
|
99
|
+
/**
|
|
100
|
+
* Create a UUID field value
|
|
101
|
+
* @param value - UUID string (e.g., "550e8400-e29b-41d4-a716-446655440000")
|
|
102
|
+
*/
|
|
103
|
+
uuid: (value: string) => WrappedFieldValue;
|
|
104
|
+
/**
|
|
105
|
+
* Create a Decimal field value for precise numeric values
|
|
106
|
+
* @param value - Decimal as string (e.g., "99.99") to preserve precision
|
|
107
|
+
*/
|
|
108
|
+
decimal: (value: string) => WrappedFieldValue;
|
|
109
|
+
/**
|
|
110
|
+
* Create a DateTime field value
|
|
111
|
+
* @param value - Date object or RFC3339 string
|
|
112
|
+
*/
|
|
113
|
+
dateTime: (value: Date | string) => WrappedFieldValue;
|
|
114
|
+
/**
|
|
115
|
+
* Create a Duration field value
|
|
116
|
+
* @param milliseconds - Duration in milliseconds
|
|
117
|
+
*/
|
|
118
|
+
duration: (milliseconds: number) => WrappedFieldValue;
|
|
119
|
+
/**
|
|
120
|
+
* Create a Number field value (flexible numeric type)
|
|
121
|
+
* @param value - Integer or float
|
|
122
|
+
*/
|
|
123
|
+
number: (value: number) => WrappedFieldValue;
|
|
124
|
+
/**
|
|
125
|
+
* Create a Set field value (unique elements)
|
|
126
|
+
* @param values - Array of values (duplicates will be removed by server)
|
|
127
|
+
*/
|
|
128
|
+
set: <T>(values: T[]) => WrappedFieldValue;
|
|
129
|
+
/**
|
|
130
|
+
* Create a Vector field value (for embeddings/similarity search)
|
|
131
|
+
* @param values - Array of numbers representing the vector
|
|
132
|
+
*/
|
|
133
|
+
vector: (values: number[]) => WrappedFieldValue;
|
|
134
|
+
/**
|
|
135
|
+
* Create a Binary field value
|
|
136
|
+
* @param value - Base64 encoded string or Uint8Array
|
|
137
|
+
*/
|
|
138
|
+
binary: (value: string | Uint8Array) => WrappedFieldValue;
|
|
139
|
+
/**
|
|
140
|
+
* Create a Bytes field value
|
|
141
|
+
* @param value - Base64 encoded string or Uint8Array
|
|
142
|
+
*/
|
|
143
|
+
bytes: (value: string | Uint8Array) => WrappedFieldValue;
|
|
144
|
+
/**
|
|
145
|
+
* Create an Array field value
|
|
146
|
+
* @param values - Array of values
|
|
147
|
+
*/
|
|
148
|
+
array: <T>(values: T[]) => WrappedFieldValue;
|
|
149
|
+
/**
|
|
150
|
+
* Create an Object field value
|
|
151
|
+
* @param value - Object/map of key-value pairs
|
|
152
|
+
*/
|
|
153
|
+
object: (value: Record<string, unknown>) => WrappedFieldValue;
|
|
154
|
+
/**
|
|
155
|
+
* Create a String field value (explicit wrapping)
|
|
156
|
+
* @param value - String value
|
|
157
|
+
*/
|
|
158
|
+
string: (value: string) => WrappedFieldValue;
|
|
159
|
+
/**
|
|
160
|
+
* Create an Integer field value (explicit wrapping)
|
|
161
|
+
* @param value - Integer value
|
|
162
|
+
*/
|
|
163
|
+
integer: (value: number) => WrappedFieldValue;
|
|
164
|
+
/**
|
|
165
|
+
* Create a Float field value (explicit wrapping)
|
|
166
|
+
* @param value - Float value
|
|
167
|
+
*/
|
|
168
|
+
float: (value: number) => WrappedFieldValue;
|
|
169
|
+
/**
|
|
170
|
+
* Create a Boolean field value (explicit wrapping)
|
|
171
|
+
* @param value - Boolean value
|
|
172
|
+
*/
|
|
173
|
+
boolean: (value: boolean) => WrappedFieldValue;
|
|
174
|
+
};
|
package/dist/utils.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Utility functions for working with ekoDB records
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Field = void 0;
|
|
6
7
|
exports.getValue = getValue;
|
|
7
8
|
exports.getValues = getValues;
|
|
8
9
|
exports.getDateTimeValue = getDateTimeValue;
|
|
@@ -26,7 +27,7 @@ exports.extractRecord = extractRecord;
|
|
|
26
27
|
*
|
|
27
28
|
* @example
|
|
28
29
|
* ```typescript
|
|
29
|
-
* const user = await client.
|
|
30
|
+
* const user = await client.findById('users', userId);
|
|
30
31
|
* const email = getValue(user.email); // Extracts string from { type: 'String', value: 'user@example.com' }
|
|
31
32
|
* const age = getValue(user.age); // Extracts number from { type: 'Integer', value: 25 }
|
|
32
33
|
* ```
|
|
@@ -47,7 +48,7 @@ function getValue(field) {
|
|
|
47
48
|
*
|
|
48
49
|
* @example
|
|
49
50
|
* ```typescript
|
|
50
|
-
* const user = await client.
|
|
51
|
+
* const user = await client.findById('users', userId);
|
|
51
52
|
* const { email, first_name, status } = getValues(user, ['email', 'first_name', 'status']);
|
|
52
53
|
* ```
|
|
53
54
|
*/
|
|
@@ -176,7 +177,7 @@ function getObjectValue(field) {
|
|
|
176
177
|
*
|
|
177
178
|
* @example
|
|
178
179
|
* ```typescript
|
|
179
|
-
* const user = await client.
|
|
180
|
+
* const user = await client.findById('users', userId);
|
|
180
181
|
* const plainUser = extractRecord(user);
|
|
181
182
|
* // { id: '123', email: 'user@example.com', first_name: 'John', ... }
|
|
182
183
|
* ```
|
|
@@ -196,3 +197,129 @@ function extractRecord(record) {
|
|
|
196
197
|
}
|
|
197
198
|
return result;
|
|
198
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Field builders for creating wrapped type values to send to ekoDB.
|
|
202
|
+
* These are the inverse of the getValue* extraction functions.
|
|
203
|
+
*/
|
|
204
|
+
exports.Field = {
|
|
205
|
+
/**
|
|
206
|
+
* Create a UUID field value
|
|
207
|
+
* @param value - UUID string (e.g., "550e8400-e29b-41d4-a716-446655440000")
|
|
208
|
+
*/
|
|
209
|
+
uuid: (value) => ({
|
|
210
|
+
type: "UUID",
|
|
211
|
+
value,
|
|
212
|
+
}),
|
|
213
|
+
/**
|
|
214
|
+
* Create a Decimal field value for precise numeric values
|
|
215
|
+
* @param value - Decimal as string (e.g., "99.99") to preserve precision
|
|
216
|
+
*/
|
|
217
|
+
decimal: (value) => ({
|
|
218
|
+
type: "Decimal",
|
|
219
|
+
value,
|
|
220
|
+
}),
|
|
221
|
+
/**
|
|
222
|
+
* Create a DateTime field value
|
|
223
|
+
* @param value - Date object or RFC3339 string
|
|
224
|
+
*/
|
|
225
|
+
dateTime: (value) => ({
|
|
226
|
+
type: "DateTime",
|
|
227
|
+
value: value instanceof Date ? value.toISOString() : value,
|
|
228
|
+
}),
|
|
229
|
+
/**
|
|
230
|
+
* Create a Duration field value
|
|
231
|
+
* @param milliseconds - Duration in milliseconds
|
|
232
|
+
*/
|
|
233
|
+
duration: (milliseconds) => ({
|
|
234
|
+
type: "Duration",
|
|
235
|
+
value: milliseconds,
|
|
236
|
+
}),
|
|
237
|
+
/**
|
|
238
|
+
* Create a Number field value (flexible numeric type)
|
|
239
|
+
* @param value - Integer or float
|
|
240
|
+
*/
|
|
241
|
+
number: (value) => ({
|
|
242
|
+
type: "Number",
|
|
243
|
+
value,
|
|
244
|
+
}),
|
|
245
|
+
/**
|
|
246
|
+
* Create a Set field value (unique elements)
|
|
247
|
+
* @param values - Array of values (duplicates will be removed by server)
|
|
248
|
+
*/
|
|
249
|
+
set: (values) => ({
|
|
250
|
+
type: "Set",
|
|
251
|
+
value: values,
|
|
252
|
+
}),
|
|
253
|
+
/**
|
|
254
|
+
* Create a Vector field value (for embeddings/similarity search)
|
|
255
|
+
* @param values - Array of numbers representing the vector
|
|
256
|
+
*/
|
|
257
|
+
vector: (values) => ({
|
|
258
|
+
type: "Vector",
|
|
259
|
+
value: values,
|
|
260
|
+
}),
|
|
261
|
+
/**
|
|
262
|
+
* Create a Binary field value
|
|
263
|
+
* @param value - Base64 encoded string or Uint8Array
|
|
264
|
+
*/
|
|
265
|
+
binary: (value) => ({
|
|
266
|
+
type: "Binary",
|
|
267
|
+
value: value instanceof Uint8Array ? btoa(String.fromCharCode(...value)) : value,
|
|
268
|
+
}),
|
|
269
|
+
/**
|
|
270
|
+
* Create a Bytes field value
|
|
271
|
+
* @param value - Base64 encoded string or Uint8Array
|
|
272
|
+
*/
|
|
273
|
+
bytes: (value) => ({
|
|
274
|
+
type: "Bytes",
|
|
275
|
+
value: value instanceof Uint8Array ? btoa(String.fromCharCode(...value)) : value,
|
|
276
|
+
}),
|
|
277
|
+
/**
|
|
278
|
+
* Create an Array field value
|
|
279
|
+
* @param values - Array of values
|
|
280
|
+
*/
|
|
281
|
+
array: (values) => ({
|
|
282
|
+
type: "Array",
|
|
283
|
+
value: values,
|
|
284
|
+
}),
|
|
285
|
+
/**
|
|
286
|
+
* Create an Object field value
|
|
287
|
+
* @param value - Object/map of key-value pairs
|
|
288
|
+
*/
|
|
289
|
+
object: (value) => ({
|
|
290
|
+
type: "Object",
|
|
291
|
+
value,
|
|
292
|
+
}),
|
|
293
|
+
/**
|
|
294
|
+
* Create a String field value (explicit wrapping)
|
|
295
|
+
* @param value - String value
|
|
296
|
+
*/
|
|
297
|
+
string: (value) => ({
|
|
298
|
+
type: "String",
|
|
299
|
+
value,
|
|
300
|
+
}),
|
|
301
|
+
/**
|
|
302
|
+
* Create an Integer field value (explicit wrapping)
|
|
303
|
+
* @param value - Integer value
|
|
304
|
+
*/
|
|
305
|
+
integer: (value) => ({
|
|
306
|
+
type: "Integer",
|
|
307
|
+
value: Math.floor(value),
|
|
308
|
+
}),
|
|
309
|
+
/**
|
|
310
|
+
* Create a Float field value (explicit wrapping)
|
|
311
|
+
* @param value - Float value
|
|
312
|
+
*/
|
|
313
|
+
float: (value) => ({
|
|
314
|
+
type: "Float",
|
|
315
|
+
value,
|
|
316
|
+
}),
|
|
317
|
+
/**
|
|
318
|
+
* Create a Boolean field value (explicit wrapping)
|
|
319
|
+
* @param value - Boolean value
|
|
320
|
+
*/
|
|
321
|
+
boolean: (value) => ({
|
|
322
|
+
type: "Boolean",
|
|
323
|
+
value,
|
|
324
|
+
}),
|
|
325
|
+
};
|