@antelopejs/interface-database 0.1.6 → 0.1.7

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 (53) hide show
  1. package/dist/antelope.test.js +1 -1
  2. package/dist/atomic.d.ts +3 -37
  3. package/dist/atomic.js +39 -121
  4. package/dist/atomic.js.map +1 -1
  5. package/dist/common.d.ts +1 -58
  6. package/dist/common.js +15 -41
  7. package/dist/common.js.map +1 -1
  8. package/dist/datum.d.ts +1 -55
  9. package/dist/datum.js +2 -66
  10. package/dist/datum.js.map +1 -1
  11. package/dist/query.d.ts +11 -12
  12. package/dist/query.js +24 -22
  13. package/dist/query.js.map +1 -1
  14. package/dist/schema.d.ts +3 -120
  15. package/dist/schema.js +7 -88
  16. package/dist/schema.js.map +1 -1
  17. package/dist/selection.d.ts +1 -104
  18. package/dist/selection.js +5 -123
  19. package/dist/selection.js.map +1 -1
  20. package/dist/staged-query/atomic.d.ts +34 -0
  21. package/dist/staged-query/atomic.js +108 -0
  22. package/dist/staged-query/atomic.js.map +1 -0
  23. package/dist/staged-query/common.d.ts +58 -0
  24. package/dist/staged-query/common.js +45 -0
  25. package/dist/staged-query/common.js.map +1 -0
  26. package/dist/staged-query/datum.d.ts +55 -0
  27. package/dist/staged-query/datum.js +70 -0
  28. package/dist/staged-query/datum.js.map +1 -0
  29. package/dist/staged-query/index.d.ts +8 -0
  30. package/dist/staged-query/index.js +36 -0
  31. package/dist/staged-query/index.js.map +1 -0
  32. package/dist/staged-query/query.d.ts +3 -0
  33. package/dist/staged-query/query.js +9 -0
  34. package/dist/staged-query/query.js.map +1 -0
  35. package/dist/staged-query/schema.d.ts +122 -0
  36. package/dist/staged-query/schema.js +95 -0
  37. package/dist/staged-query/schema.js.map +1 -0
  38. package/dist/staged-query/selection.d.ts +104 -0
  39. package/dist/staged-query/selection.js +126 -0
  40. package/dist/staged-query/selection.js.map +1 -0
  41. package/dist/staged-query/stream.d.ts +185 -0
  42. package/dist/staged-query/stream.js +221 -0
  43. package/dist/staged-query/stream.js.map +1 -0
  44. package/dist/staged-query/valueproxy.d.ts +415 -0
  45. package/dist/staged-query/valueproxy.js +562 -0
  46. package/dist/staged-query/valueproxy.js.map +1 -0
  47. package/dist/stream.d.ts +1 -185
  48. package/dist/stream.js +2 -217
  49. package/dist/stream.js.map +1 -1
  50. package/dist/valueproxy.d.ts +1 -415
  51. package/dist/valueproxy.js +15 -559
  52. package/dist/valueproxy.js.map +1 -1
  53. package/package.json +9 -1
@@ -0,0 +1,415 @@
1
+ import { StagedObject, type ExtractType } from "./common";
2
+ export type ValueProxyOrValue<T> = ValueProxy<T> | T;
3
+ export type Is<Left, Right, R> = Left extends Right ? R : never;
4
+ export type ArrayValue<T> = T extends (infer V)[] ? V : never;
5
+ export type IsArray<Left, Right, R> = Right extends (infer A)[] ? Is<A, Left, R> : never;
6
+ export type OnlyObject<T> = T extends Record<any, any> ? T : never;
7
+ /**
8
+ * Proxy to an actual value in the database
9
+ *
10
+ * Actions performed on this proxy are not executed right away but instead recorded for the actual query
11
+ */
12
+ export declare class ValueProxy<T> extends StagedObject {
13
+ static arg<T = unknown>(id: number): ValueProxy<T>;
14
+ /**
15
+ * Create a new proxy with a constant value
16
+ *
17
+ * @param value Value
18
+ * @returns Proxy
19
+ */
20
+ static constant<T = unknown>(value: T): ValueProxy<T>;
21
+ /**
22
+ * Changes the type of this proxy.
23
+ * This does not actually perform any conversion, it only changes the typescript type.
24
+ *
25
+ * @returns Same proxy with a different type
26
+ */
27
+ cast<U>(): ValueProxy<U>;
28
+ /**
29
+ * Returns the parameter if the proxy is null.
30
+ *
31
+ * @param value Value to use in case the proxy is null
32
+ * @returns Non-null value.
33
+ */
34
+ default<U>(value: ValueProxyOrValue<U>): ValueProxy<U | Exclude<T, null | undefined>>;
35
+ /**
36
+ * AND operator.
37
+ *
38
+ * @param other Operand B
39
+ * @returns A && B
40
+ */
41
+ and(value: unknown): ValueProxy<boolean>;
42
+ /**
43
+ * OR operator.
44
+ *
45
+ * @param other Operand B
46
+ * @returns A || B
47
+ */
48
+ or(value: unknown): ValueProxy<boolean>;
49
+ /**
50
+ * NOT operator.
51
+ *
52
+ * @returns !A
53
+ */
54
+ not(): ValueProxy<boolean>;
55
+ /**
56
+ * Equality operator.
57
+ *
58
+ * @param other Operand B
59
+ * @returns A == B
60
+ */
61
+ eq(value: unknown): ValueProxy<boolean>;
62
+ /**
63
+ * Inequality operator.
64
+ *
65
+ * @param other Operand B
66
+ * @returns A != B
67
+ */
68
+ ne(value: unknown): ValueProxy<boolean>;
69
+ /**
70
+ * Addition operator.
71
+ *
72
+ * @param other Operand B
73
+ * @returns New value
74
+ */
75
+ add(this: Is<Date | number, T, this>, value: ValueProxyOrValue<number>): ValueProxy<T>;
76
+ /**
77
+ * Subtraction operator.
78
+ *
79
+ * @param other Operand B
80
+ * @returns New value
81
+ */
82
+ sub<U>(this: Is<Date | number, T, this>, value: ValueProxyOrValue<U>): ValueProxy<Date extends U ? (Date extends T ? number : never) | (number extends U ? T extends number ? number : Date : never) : Extract<number, T> | Extract<Date, T>>;
83
+ /**
84
+ * Determines whether or not the proxy is between the two bounds.
85
+ *
86
+ * @param left Left bound (inclusive)
87
+ * @param right Right bound (exclusive)
88
+ * @returns True if the date is within the bounds
89
+ */
90
+ during(this: Is<Date, T, this>, left: ValueProxyOrValue<Date>, right: ValueProxyOrValue<Date>): ValueProxy<boolean>;
91
+ private withTimezone;
92
+ /**
93
+ * Number of seconds since the start of the day.
94
+ *
95
+ * @returns Seconds
96
+ */
97
+ timeofday(this: Is<Date, T, this>, timezone?: ValueProxyOrValue<string>): ValueProxy<number>;
98
+ /**
99
+ * Year.
100
+ *
101
+ * @returns Year
102
+ */
103
+ year(this: Is<Date, T, this>, timezone?: ValueProxyOrValue<string>): ValueProxy<number>;
104
+ /**
105
+ * Month.
106
+ *
107
+ * @returns Month
108
+ */
109
+ month(this: Is<Date, T, this>, timezone?: ValueProxyOrValue<string>): ValueProxy<number>;
110
+ /**
111
+ * Day of the month.
112
+ *
113
+ * @returns Day of the month
114
+ */
115
+ day(this: Is<Date, T, this>, timezone?: ValueProxyOrValue<string>): ValueProxy<number>;
116
+ /**
117
+ * Day of the week.
118
+ *
119
+ * @returns Day of the week
120
+ */
121
+ dayofweek(this: Is<Date, T, this>, timezone?: ValueProxyOrValue<string>): ValueProxy<number>;
122
+ /**
123
+ * Day of the year.
124
+ *
125
+ * @returns Day of the year
126
+ */
127
+ dayofyear(this: Is<Date, T, this>, timezone?: ValueProxyOrValue<string>): ValueProxy<number>;
128
+ /**
129
+ * Hour of the day.
130
+ *
131
+ * @returns Hours
132
+ */
133
+ hours(this: Is<Date, T, this>, timezone?: ValueProxyOrValue<string>): ValueProxy<number>;
134
+ /**
135
+ * Minutes.
136
+ *
137
+ * @returns Minutes
138
+ */
139
+ minutes(this: Is<Date, T, this>, timezone?: ValueProxyOrValue<string>): ValueProxy<number>;
140
+ /**
141
+ * Seconds.
142
+ *
143
+ * @returns Seconds
144
+ */
145
+ seconds(this: Is<Date, T, this>, timezone?: ValueProxyOrValue<string>): ValueProxy<number>;
146
+ /**
147
+ * Seconds since the UNIX epoch with millisecond precision.
148
+ *
149
+ * @returns Seconds
150
+ */
151
+ epoch(this: Is<Date, T, this>): ValueProxy<number>;
152
+ /**
153
+ * Multiplication operator.
154
+ *
155
+ * @param other Operand B
156
+ * @returns A * B
157
+ */
158
+ mul(this: Is<number, T, this>, other: ValueProxyOrValue<number>): ValueProxy<number>;
159
+ /**
160
+ * Division operator.
161
+ *
162
+ * @param other Operand B
163
+ * @returns A / B
164
+ */
165
+ div(this: Is<number, T, this>, other: ValueProxyOrValue<number>): ValueProxy<number>;
166
+ /**
167
+ * Modulo operator.
168
+ *
169
+ * @param other Operand B
170
+ * @returns A % B
171
+ */
172
+ mod(this: Is<number, T, this>, other: ValueProxyOrValue<number>): ValueProxy<number>;
173
+ /**
174
+ * Round to the nearest integer.
175
+ *
176
+ * @returns Integer
177
+ */
178
+ round(this: Is<number, T, this>): ValueProxy<number>;
179
+ /**
180
+ * Round to the higher integer.
181
+ *
182
+ * @returns Integer
183
+ */
184
+ ceil(this: Is<number, T, this>): ValueProxy<number>;
185
+ /**
186
+ * Round to the lower integer.
187
+ *
188
+ * @returns Integer
189
+ */
190
+ floor(this: Is<number, T, this>): ValueProxy<number>;
191
+ /**
192
+ * Bitwise AND operator.
193
+ *
194
+ * @param other Operand B
195
+ * @return A & B
196
+ */
197
+ band(this: Is<number, T, this>, other: ValueProxyOrValue<number>): ValueProxy<number>;
198
+ /**
199
+ * Bitwise OR operator.
200
+ *
201
+ * @param other Operand B
202
+ * @return A | B
203
+ */
204
+ bor(this: Is<number, T, this>, other: ValueProxyOrValue<number>): ValueProxy<number>;
205
+ /**
206
+ * Bitwise XOR operator.
207
+ *
208
+ * @param other Operand B
209
+ * @return A ^ B
210
+ */
211
+ bxor(this: Is<number, T, this>, other: ValueProxyOrValue<number>): ValueProxy<number>;
212
+ /**
213
+ * Bitwise NOT operator.
214
+ *
215
+ * @return ~A
216
+ */
217
+ bnot(this: Is<number, T, this>): ValueProxy<number>;
218
+ /**
219
+ * Bitwise left shift operator.
220
+ *
221
+ * @param other Operand B
222
+ * @returns A << B
223
+ */
224
+ blshift(this: Is<number, T, this>, other: ValueProxyOrValue<number>): ValueProxy<number>;
225
+ /**
226
+ * Bitwise right shift operator.
227
+ *
228
+ * @param other Operand B
229
+ * @returns A >> B
230
+ */
231
+ brshift(this: Is<number, T, this>, other: ValueProxyOrValue<number>): ValueProxy<number>;
232
+ /**
233
+ * Bitwise right shift operator with sign preservation.
234
+ *
235
+ * @param other Operand B
236
+ * @returns A >> B (sign-preserving)
237
+ */
238
+ brshiftPreserveSign(this: Is<number, T, this>, other: ValueProxyOrValue<number>): ValueProxy<number>;
239
+ /**
240
+ * Greater-than operator.
241
+ *
242
+ * @param other Operand B
243
+ * @returns A > B
244
+ */
245
+ gt(this: Is<Date | number | string, T, this>, other: ValueProxyOrValue<T>): ValueProxy<boolean>;
246
+ /**
247
+ * Greater-or-equal operator.
248
+ *
249
+ * @param other Operand B
250
+ * @returns A >= B
251
+ */
252
+ ge(this: Is<Date | number | string, T, this>, other: ValueProxyOrValue<T>): ValueProxy<boolean>;
253
+ /**
254
+ * Lesser-than operator.
255
+ *
256
+ * @param other Operand B
257
+ * @returns A < B
258
+ */
259
+ lt(this: Is<Date | number | string, T, this>, other: ValueProxyOrValue<T>): ValueProxy<boolean>;
260
+ /**
261
+ * Lesser-or-equal operator.
262
+ *
263
+ * @param other Operand B
264
+ * @returns A <= B
265
+ */
266
+ le(this: Is<Date | number | string, T, this>, other: ValueProxyOrValue<T>): ValueProxy<boolean>;
267
+ /**
268
+ * Splits the string using a separator.
269
+ *
270
+ * @param separator Separator string
271
+ * @param maxSplits Maximum number of results
272
+ * @returns Array of sub-strings
273
+ */
274
+ split(this: Is<string, T, this>, separator?: string, maxSplits?: number): ValueProxy<string[]>;
275
+ /**
276
+ * Concatenate the string with another.
277
+ *
278
+ * @param other Second string
279
+ * @returns Concatenated string
280
+ */
281
+ concat(this: Is<string, T, this>, other: ValueProxyOrValue<string>): ValueProxy<string>;
282
+ /**
283
+ * Converts the string to all upper case.
284
+ *
285
+ * @returns New string
286
+ */
287
+ upcase(this: Is<string, T, this>): ValueProxy<string>;
288
+ /**
289
+ * Converts the string to all lower case.
290
+ *
291
+ * @returns New string
292
+ */
293
+ downcase(this: Is<string, T, this>): ValueProxy<string>;
294
+ /**
295
+ * Gets the number of Unicode codepoints in the string.
296
+ *
297
+ * @returns Number of codepoints
298
+ */
299
+ strlen(this: Is<string, T, this>): ValueProxy<number>;
300
+ /**
301
+ * Checks if the string matches a regex.
302
+ *
303
+ * @param regex Regex
304
+ * @returns True if the string matched
305
+ */
306
+ match(this: Is<string, T, this>, regex: ValueProxyOrValue<string>): ValueProxy<boolean>;
307
+ /**
308
+ * Indexes the array with a given number position
309
+ *
310
+ * @param key Position in the array
311
+ * @returns Element at the given position
312
+ */
313
+ index(this: IsArray<unknown, T, this>, key: ValueProxyOrValue<number>): ValueProxy<ArrayValue<T>>;
314
+ /**
315
+ * Tests if the arrays contains a value.
316
+ *
317
+ * @param val Value to search for.
318
+ * @returns True if the value was found.
319
+ */
320
+ includes(this: IsArray<unknown, T, this>, val: ValueProxyOrValue<ArrayValue<T>>): ValueProxy<boolean>;
321
+ /**
322
+ * Returns a slice of the array.
323
+ *
324
+ * @param start Start index (inclusive, 0-indexed)
325
+ * @param end End index (exclusive)
326
+ * @returns Sub-array
327
+ */
328
+ slice(this: IsArray<unknown, T, this>, start: ValueProxyOrValue<number>, end?: ValueProxyOrValue<number>): ValueProxy<ArrayValue<T>[]>;
329
+ /**
330
+ * Maps the array values using a mapping function.
331
+ *
332
+ * @param mapper Mapping function
333
+ * @returns New array
334
+ */
335
+ map<U>(this: IsArray<unknown, T, this>, mapper: (val: ValueProxy<ArrayValue<T>>) => U): ValueProxy<ExtractType<U>[]>;
336
+ /**
337
+ * Filters the array using a predicate function.
338
+ *
339
+ * @param predicate Predicate function.
340
+ * @returns Filtered array
341
+ */
342
+ filter(this: IsArray<unknown, T, this>, predicate: (val: ValueProxy<ArrayValue<T>>) => ValueProxyOrValue<boolean>): ValueProxy<ArrayValue<T>[]>;
343
+ /**
344
+ * Checks if the array is empty.
345
+ *
346
+ * @returns True if the array is empty
347
+ */
348
+ isempty(this: IsArray<unknown, T, this>): ValueProxy<boolean>;
349
+ /**
350
+ * Gets the length of the array.
351
+ *
352
+ * @returns Length
353
+ */
354
+ count(this: IsArray<unknown, T, this>): ValueProxy<number>;
355
+ /**
356
+ * Gets the sum of a number array.
357
+ *
358
+ * @returns Sum
359
+ */
360
+ sum(this: IsArray<number, T, this>): ValueProxy<number>;
361
+ /**
362
+ * Gets the average of a number array.
363
+ *
364
+ * @returns Average
365
+ */
366
+ avg(this: IsArray<number, T, this>): ValueProxy<number>;
367
+ /**
368
+ * Gets the minimum of a number array.
369
+ *
370
+ * @returns Minimum
371
+ */
372
+ min(this: IsArray<number, T, this>): ValueProxy<number>;
373
+ /**
374
+ * Gets the maxmimum of a number array.
375
+ *
376
+ * @returns Maximum
377
+ */
378
+ max(this: IsArray<number, T, this>): ValueProxy<number>;
379
+ /**
380
+ * Indexes the object.
381
+ *
382
+ * TODO: Better name?
383
+ *
384
+ * @param key Field name
385
+ * @param def Default value
386
+ * @returns Value of the field
387
+ */
388
+ key<TO = OnlyObject<T>, K extends keyof TO = keyof TO, U = undefined>(this: Is<T, Record<any, any>, this>, key: ValueProxyOrValue<K>, def?: ValueProxyOrValue<U>): ValueProxy<U extends undefined ? TO[K] : U | Exclude<TO[K], null | undefined>>;
389
+ /**
390
+ * Merges the object with another.
391
+ *
392
+ * @param value Other object
393
+ * @returns `{...A, ...B}`
394
+ */
395
+ merge<U, TO = OnlyObject<T>>(this: Is<T, Record<any, any>, this>, other: ValueProxyOrValue<U>): ValueProxy<Omit<TO, keyof U> & ExtractType<U>>;
396
+ /**
397
+ * Gets the keys of the object as an array.
398
+ *
399
+ * @returns Array of keys
400
+ */
401
+ keys<TO = OnlyObject<T>>(this: Is<T, Record<any, any>, this>): ValueProxy<(keyof TO)[]>;
402
+ /**
403
+ * Gets the values of the object as an array.
404
+ *
405
+ * @returns Array of values
406
+ */
407
+ values<TO = OnlyObject<T>>(this: Is<T, Record<any, any>, this>): ValueProxy<TO[keyof TO][]>;
408
+ /**
409
+ * Tests if the object has the specified fields.
410
+ *
411
+ * @param fields field list
412
+ * @returns True if the object matches
413
+ */
414
+ hasfields(this: Is<T, Record<any, any>, this>, ...fields: string[]): ValueProxy<boolean>;
415
+ }