@onyx.dev/onyx-database 1.0.2 → 1.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,1453 @@
1
+ /**
2
+ * Supported operators for building query criteria.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const criteria = { field: 'age', operator: 'GREATER_THAN', value: 21 };
7
+ * ```
8
+ */
9
+ type QueryCriteriaOperator = 'EQUAL' | 'NOT_EQUAL' | 'IN' | 'NOT_IN' | 'GREATER_THAN' | 'GREATER_THAN_EQUAL' | 'LESS_THAN' | 'LESS_THAN_EQUAL' | 'MATCHES' | 'NOT_MATCHES' | 'BETWEEN' | 'LIKE' | 'NOT_LIKE' | 'CONTAINS' | 'CONTAINS_IGNORE_CASE' | 'NOT_CONTAINS' | 'NOT_CONTAINS_IGNORE_CASE' | 'STARTS_WITH' | 'NOT_STARTS_WITH' | 'IS_NULL' | 'NOT_NULL';
10
+ /** Value payload for full-text (Lucene) searches. */
11
+ interface FullTextQuery {
12
+ queryText: string;
13
+ minScore: number | null;
14
+ }
15
+ /** Logical operator used to join conditions in a query. */
16
+ type LogicalOperator = 'AND' | 'OR';
17
+ /**
18
+ * Sorting instruction for query results.
19
+ *
20
+ * @property field - Field name to order by.
21
+ * @property order - Sort direction.
22
+ * @example
23
+ * ```ts
24
+ * const sort: Sort = { field: 'name', order: 'ASC' };
25
+ * ```
26
+ */
27
+ interface Sort {
28
+ field: string;
29
+ order: 'ASC' | 'DESC';
30
+ }
31
+ /** Actions emitted by real-time data streams. */
32
+ type StreamAction = 'CREATE' | 'UPDATE' | 'DELETE' | 'QUERY_RESPONSE' | 'KEEP_ALIVE';
33
+ /**
34
+ * Basic document representation used by the SDK.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const doc: OnyxDocument = { documentId: '1', content: 'hello' };
39
+ * ```
40
+ */
41
+ interface OnyxDocument {
42
+ /** Unique document identifier. */
43
+ documentId?: string;
44
+ /** Path within the Onyx database. */
45
+ path?: string;
46
+ /** Creation timestamp. */
47
+ created?: Date;
48
+ /** Last update timestamp. */
49
+ updated?: Date;
50
+ /** MIME type of the content. */
51
+ mimeType?: string;
52
+ /** Raw document content. */
53
+ content?: string;
54
+ }
55
+ /** Minimal fetch typing to avoid DOM lib dependency */
56
+ interface FetchResponse {
57
+ /** Whether the request succeeded (status in the range 200–299). */
58
+ ok: boolean;
59
+ /** HTTP status code. */
60
+ status: number;
61
+ /** HTTP status text. */
62
+ statusText: string;
63
+ /** Response headers getter. */
64
+ headers: {
65
+ get(name: string): string | null;
66
+ };
67
+ /** Reads the body as text. */
68
+ text(): Promise<string>;
69
+ /** Raw body for streams; left as unknown to avoid DOM typings */
70
+ body?: unknown;
71
+ }
72
+ /**
73
+ * Fetch implementation signature used by the SDK.
74
+ *
75
+ * @param url - Resource URL.
76
+ * @param init - Optional init parameters.
77
+ * @example
78
+ * ```ts
79
+ * const res = await fetchImpl('https://api.onyx.dev');
80
+ * ```
81
+ */
82
+ type FetchImpl = (url: string, init?: {
83
+ method?: string;
84
+ headers?: Record<string, string>;
85
+ body?: string;
86
+ }) => Promise<FetchResponse>;
87
+
88
+ /**
89
+ * Represents a single field comparison in a query.
90
+ *
91
+ * @property field - Field name to evaluate.
92
+ * @property operator - Comparison operator.
93
+ * @property value - Value to compare against.
94
+ * @example
95
+ * ```ts
96
+ * const criteria: QueryCriteria = { field: 'age', operator: 'GREATER_THAN', value: 18 };
97
+ * ```
98
+ */
99
+ interface QueryCriteria {
100
+ field: string;
101
+ operator: QueryCriteriaOperator;
102
+ value?: unknown;
103
+ }
104
+ /**
105
+ * Recursive condition structure used to express complex WHERE clauses.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const condition: QueryCondition = {
110
+ * conditionType: 'CompoundCondition',
111
+ * operator: 'AND',
112
+ * conditions: [
113
+ * { conditionType: 'SingleCondition', criteria: { field: 'age', operator: 'GREATER_THAN', value: 18 } },
114
+ * { conditionType: 'SingleCondition', criteria: { field: 'status', operator: 'EQUAL', value: 'ACTIVE' } }
115
+ * ]
116
+ * };
117
+ * ```
118
+ */
119
+ type QueryCondition = {
120
+ conditionType: 'SingleCondition';
121
+ criteria: QueryCriteria;
122
+ } | {
123
+ conditionType: 'CompoundCondition';
124
+ operator: LogicalOperator;
125
+ conditions: QueryCondition[];
126
+ };
127
+ /**
128
+ * Wire format for select queries sent to the server.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * const query: SelectQuery = {
133
+ * type: 'SelectQuery',
134
+ * fields: ['id', 'name'],
135
+ * limit: 10
136
+ * };
137
+ * ```
138
+ */
139
+ interface SelectQuery {
140
+ type: 'SelectQuery';
141
+ table?: string | null;
142
+ fields?: string[] | null;
143
+ conditions?: QueryCondition | null;
144
+ sort?: Sort[] | null;
145
+ limit?: number | null;
146
+ distinct?: boolean | null;
147
+ groupBy?: string[] | null;
148
+ partition?: string | null;
149
+ resolvers?: string[] | null;
150
+ }
151
+ /**
152
+ * Wire format for update queries sent to the server.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * const update: UpdateQuery = {
157
+ * type: 'UpdateQuery',
158
+ * updates: { name: 'New Name' }
159
+ * };
160
+ * ```
161
+ */
162
+ interface UpdateQuery {
163
+ type: 'UpdateQuery';
164
+ conditions?: QueryCondition | null;
165
+ updates: Record<string, unknown>;
166
+ sort?: Sort[] | null;
167
+ limit?: number | null;
168
+ partition?: string | null;
169
+ }
170
+ /**
171
+ * A single page of query results.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * const page: QueryPage<User> = { records: users, nextPage: token };
176
+ * ```
177
+ */
178
+ interface QueryPage<T> {
179
+ /** Records in the current page. */
180
+ records: T[];
181
+ /** Token for the next page or null if none. */
182
+ nextPage?: string | null;
183
+ }
184
+
185
+ /**
186
+ * Array-like container for paginated query results. Provides helper methods
187
+ * to traverse and aggregate records across pages.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * const results = new QueryResults(users, nextToken, fetchNext);
192
+ * const firstUser = results.first();
193
+ * ```
194
+ */
195
+ type QueryResultsPromise<T> = Promise<QueryResults<T>> & {
196
+ [K in keyof QueryResults<T> as QueryResults<T>[K] extends (...args: any[]) => any ? K : never]: QueryResults<T>[K] extends (...args: infer P) => infer R ? (...args: P) => Promise<Awaited<R>> : never;
197
+ };
198
+ declare class QueryResults<T> extends Array<T> {
199
+ /** Token for the next page of results or null. */
200
+ nextPage: string | null;
201
+ private readonly fetcher?;
202
+ /**
203
+ * @param records - Records in the current page.
204
+ * @param nextPage - Token representing the next page.
205
+ * @param fetcher - Function used to fetch the next page when needed.
206
+ * @example
207
+ * ```ts
208
+ * const results = new QueryResults(users, token, t => fetchMore(t));
209
+ * ```
210
+ */
211
+ constructor(records: Iterable<T> | ArrayLike<T> | T | null | undefined, nextPage: string | null, fetcher?: (token: string) => Promise<QueryResults<T>>);
212
+ /**
213
+ * Returns the first record in the result set.
214
+ * @throws Error if the result set is empty.
215
+ * @example
216
+ * ```ts
217
+ * const user = results.first();
218
+ * ```
219
+ */
220
+ first(): T;
221
+ /**
222
+ * Returns the first record or `null` if the result set is empty.
223
+ * @example
224
+ * ```ts
225
+ * const user = results.firstOrNull();
226
+ * ```
227
+ */
228
+ firstOrNull(): T | null;
229
+ /**
230
+ * Checks whether the current page has no records.
231
+ * @example
232
+ * ```ts
233
+ * if (results.isEmpty()) console.log('no data');
234
+ * ```
235
+ */
236
+ isEmpty(): boolean;
237
+ /**
238
+ * Number of records on the current page.
239
+ * @example
240
+ * ```ts
241
+ * console.log(results.size());
242
+ * ```
243
+ */
244
+ size(): number;
245
+ /**
246
+ * Iterates over each record on the current page only.
247
+ * @param action - Function to invoke for each record.
248
+ * @param thisArg - Optional `this` binding for the callback.
249
+ * @example
250
+ * ```ts
251
+ * results.forEachOnPage(u => console.log(u.id));
252
+ * ```
253
+ */
254
+ forEachOnPage(action: (item: T, index: number, array: QueryResults<T>) => void, thisArg?: unknown): void;
255
+ /**
256
+ * Iterates over every record across all pages sequentially.
257
+ * @param action - Function executed for each record. Returning `false`
258
+ * stops iteration early.
259
+ * @param thisArg - Optional `this` binding for the callback.
260
+ * @example
261
+ * ```ts
262
+ * await results.forEach(u => {
263
+ * console.log(u.id);
264
+ * });
265
+ * ```
266
+ */
267
+ forEach(action: (item: T, index: number, array: T[]) => void, thisArg?: unknown): Promise<void>;
268
+ /**
269
+ * Iterates over every record across all pages sequentially.
270
+ * @param action - Function executed for each record. Returning `false`
271
+ * stops iteration early.
272
+ * @example
273
+ * ```ts
274
+ * await results.forEachAll(u => {
275
+ * if (u.disabled) return false;
276
+ * });
277
+ * ```
278
+ */
279
+ forEachAll(action: (item: T) => boolean | void | Promise<boolean | void>): Promise<void>;
280
+ /**
281
+ * Iterates page by page across the result set.
282
+ * @param action - Function invoked with each page of records. Returning
283
+ * `false` stops iteration.
284
+ * @example
285
+ * ```ts
286
+ * await results.forEachPage(page => {
287
+ * console.log(page.length);
288
+ * });
289
+ * ```
290
+ */
291
+ forEachPage(action: (records: T[]) => boolean | void | Promise<boolean | void>): Promise<void>;
292
+ /**
293
+ * Collects all records from every page into a single array.
294
+ * @returns All records.
295
+ * @example
296
+ * ```ts
297
+ * const allUsers = await results.getAllRecords();
298
+ * ```
299
+ */
300
+ getAllRecords(): Promise<T[]>;
301
+ /**
302
+ * Filters all records using the provided predicate.
303
+ * @param predicate - Function used to test each record.
304
+ * @example
305
+ * ```ts
306
+ * const enabled = await results.filterAll(u => u.enabled);
307
+ * ```
308
+ */
309
+ filterAll(predicate: (record: T) => boolean): Promise<T[]>;
310
+ /**
311
+ * Maps all records using the provided transform.
312
+ * @param transform - Mapping function.
313
+ * @example
314
+ * ```ts
315
+ * const names = await results.mapAll(u => u.name);
316
+ * ```
317
+ */
318
+ mapAll<R>(transform: (record: T) => R): Promise<R[]>;
319
+ /**
320
+ * Extracts values for a field across all records.
321
+ * @param field - Name of the field to pluck.
322
+ * @example
323
+ * ```ts
324
+ * const ids = await results.values('id');
325
+ * ```
326
+ */
327
+ values<K extends keyof T>(field: K): Promise<Array<T[K]>>;
328
+ /**
329
+ * Maximum value produced by the selector across all records.
330
+ * @param selector - Function extracting a numeric value.
331
+ * @example
332
+ * ```ts
333
+ * const maxAge = await results.maxOfDouble(u => u.age);
334
+ * ```
335
+ */
336
+ maxOfDouble(selector: (record: T) => number): Promise<number>;
337
+ /**
338
+ * Minimum value produced by the selector across all records.
339
+ * @param selector - Function extracting a numeric value.
340
+ * @example
341
+ * ```ts
342
+ * const minAge = await results.minOfDouble(u => u.age);
343
+ * ```
344
+ */
345
+ minOfDouble(selector: (record: T) => number): Promise<number>;
346
+ /**
347
+ * Sum of values produced by the selector across all records.
348
+ * @param selector - Function extracting a numeric value.
349
+ * @example
350
+ * ```ts
351
+ * const total = await results.sumOfDouble(u => u.score);
352
+ * ```
353
+ */
354
+ sumOfDouble(selector: (record: T) => number): Promise<number>;
355
+ /**
356
+ * Maximum float value from the selector.
357
+ * @param selector - Function extracting a numeric value.
358
+ */
359
+ maxOfFloat(selector: (record: T) => number): Promise<number>;
360
+ /**
361
+ * Minimum float value from the selector.
362
+ * @param selector - Function extracting a numeric value.
363
+ */
364
+ minOfFloat(selector: (record: T) => number): Promise<number>;
365
+ /**
366
+ * Sum of float values from the selector.
367
+ * @param selector - Function extracting a numeric value.
368
+ */
369
+ sumOfFloat(selector: (record: T) => number): Promise<number>;
370
+ /**
371
+ * Maximum integer value from the selector.
372
+ * @param selector - Function extracting a numeric value.
373
+ */
374
+ maxOfInt(selector: (record: T) => number): Promise<number>;
375
+ /**
376
+ * Minimum integer value from the selector.
377
+ * @param selector - Function extracting a numeric value.
378
+ */
379
+ minOfInt(selector: (record: T) => number): Promise<number>;
380
+ /**
381
+ * Sum of integer values from the selector.
382
+ * @param selector - Function extracting a numeric value.
383
+ */
384
+ sumOfInt(selector: (record: T) => number): Promise<number>;
385
+ /**
386
+ * Maximum long value from the selector.
387
+ * @param selector - Function extracting a numeric value.
388
+ */
389
+ maxOfLong(selector: (record: T) => number): Promise<number>;
390
+ /**
391
+ * Minimum long value from the selector.
392
+ * @param selector - Function extracting a numeric value.
393
+ */
394
+ minOfLong(selector: (record: T) => number): Promise<number>;
395
+ /**
396
+ * Sum of long values from the selector.
397
+ * @param selector - Function extracting a numeric value.
398
+ */
399
+ sumOfLong(selector: (record: T) => number): Promise<number>;
400
+ /**
401
+ * Sum of bigint values from the selector.
402
+ * @param selector - Function extracting a bigint value.
403
+ * @example
404
+ * ```ts
405
+ * const total = await results.sumOfBigInt(u => u.balance);
406
+ * ```
407
+ */
408
+ sumOfBigInt(selector: (record: T) => bigint): Promise<bigint>;
409
+ /**
410
+ * Executes an action for each page in parallel.
411
+ * @param action - Function executed for each record concurrently.
412
+ * @example
413
+ * ```ts
414
+ * await results.forEachPageParallel(async u => sendEmail(u));
415
+ * ```
416
+ */
417
+ forEachPageParallel(action: (item: T) => void | Promise<void>): Promise<void>;
418
+ }
419
+
420
+ /**
421
+ * Builder used to compose query conditions.
422
+ */
423
+ interface IConditionBuilder {
424
+ /**
425
+ * Combines the current condition with another using `AND`.
426
+ * @param condition - Additional condition or builder.
427
+ * @example
428
+ * ```ts
429
+ * cb.and({ field: 'age', operator: 'GREATER_THAN', value: 18 });
430
+ * ```
431
+ */
432
+ and(condition: IConditionBuilder | QueryCriteria): IConditionBuilder;
433
+ /**
434
+ * Combines the current condition with another using `OR`.
435
+ * @param condition - Additional condition or builder.
436
+ * @example
437
+ * ```ts
438
+ * cb.or({ field: 'status', operator: 'EQUAL', value: 'ACTIVE' });
439
+ * ```
440
+ */
441
+ or(condition: IConditionBuilder | QueryCriteria): IConditionBuilder;
442
+ /**
443
+ * Materializes the composed condition into a `QueryCondition` object.
444
+ * @example
445
+ * ```ts
446
+ * const cond = cb.toCondition();
447
+ * ```
448
+ */
449
+ toCondition(): QueryCondition;
450
+ }
451
+ /**
452
+ * Fluent query builder for constructing and executing select/update/delete operations.
453
+ */
454
+ interface IQueryBuilder<T = unknown> {
455
+ /**
456
+ * Sets the table to query.
457
+ * @example
458
+ * ```ts
459
+ * const users = await db.from('User').list();
460
+ * ```
461
+ */
462
+ from(table: string): IQueryBuilder<T>;
463
+ /**
464
+ * Selects a subset of fields to return.
465
+ * @example
466
+ * ```ts
467
+ * const emails = await db.from('User').select('email').list();
468
+ * ```
469
+ */
470
+ select(...fields: Array<string | string[]>): IQueryBuilder<T>;
471
+ /**
472
+ * Resolves related values by name.
473
+ * @example
474
+ * ```ts
475
+ * const users = await db
476
+ * .from('User')
477
+ * .resolve('profile', 'roles')
478
+ * .list();
479
+ * ```
480
+ */
481
+ resolve(...values: Array<string | string[]>): IQueryBuilder<T>;
482
+ /**
483
+ * Adds a Lucene full-text search predicate.
484
+ * @example
485
+ * ```ts
486
+ * const results = await db.from('User').search('hello world', 4.4).list();
487
+ * ```
488
+ * @param queryText - Text to match against `__full_text__`.
489
+ * @param minScore - Optional minimum score; serializes as `null` when omitted.
490
+ */
491
+ search(queryText: string, minScore?: number | null): IQueryBuilder<T>;
492
+ /**
493
+ * Adds a filter condition.
494
+ * @example
495
+ * ```ts
496
+ * const active = await db.from('User').where(eq('status', 'active')).list();
497
+ * ```
498
+ */
499
+ where(condition: IConditionBuilder | QueryCriteria): IQueryBuilder<T>;
500
+ /**
501
+ * Adds an additional filter with `AND`.
502
+ * @example
503
+ * ```ts
504
+ * qb.where(eq('status', 'active')).and(eq('role', 'admin'));
505
+ * ```
506
+ */
507
+ and(condition: IConditionBuilder | QueryCriteria): IQueryBuilder<T>;
508
+ /**
509
+ * Adds an additional filter with `OR`.
510
+ * @example
511
+ * ```ts
512
+ * qb.where(eq('status', 'active')).or(eq('status', 'invited'));
513
+ * ```
514
+ */
515
+ or(condition: IConditionBuilder | QueryCriteria): IQueryBuilder<T>;
516
+ /**
517
+ * Orders results by the provided fields.
518
+ * @example
519
+ * ```ts
520
+ * const users = await db.from('User').orderBy(asc('createdAt')).list();
521
+ * ```
522
+ */
523
+ orderBy(...sorts: Sort[]): IQueryBuilder<T>;
524
+ /**
525
+ * Groups results by the provided fields.
526
+ * @example
527
+ * ```ts
528
+ * const stats = await db.from('User').groupBy('status').list();
529
+ * ```
530
+ */
531
+ groupBy(...fields: string[]): IQueryBuilder<T>;
532
+ /**
533
+ * Ensures only distinct records are returned.
534
+ * @example
535
+ * ```ts
536
+ * const roles = await db.from('User').select('role').distinct().list();
537
+ * ```
538
+ */
539
+ distinct(): IQueryBuilder<T>;
540
+ /**
541
+ * Limits the number of records returned.
542
+ * @example
543
+ * ```ts
544
+ * const few = await db.from('User').limit(5).list();
545
+ * ```
546
+ */
547
+ limit(n: number): IQueryBuilder<T>;
548
+ /**
549
+ * Restricts the query to a specific partition.
550
+ * @example
551
+ * ```ts
552
+ * const tenantUsers = await db.from('User').inPartition('tenantA').list();
553
+ * ```
554
+ */
555
+ inPartition(partition: string): IQueryBuilder<T>;
556
+ /** Sets the page size for subsequent `list` or `page` calls. */
557
+ pageSize(n: number): IQueryBuilder<T>;
558
+ /**
559
+ * Continues a paged query using a next-page token.
560
+ * @example
561
+ * ```ts
562
+ * const page2 = await db.from('User').nextPage(token).list();
563
+ * ```
564
+ */
565
+ nextPage(token: string): IQueryBuilder<T>;
566
+ /**
567
+ * Counts matching records.
568
+ * @example
569
+ * ```ts
570
+ * const total = await db.from('User').count();
571
+ * ```
572
+ */
573
+ count(): Promise<number>;
574
+ /**
575
+ * Lists records with optional pagination.
576
+ * @example
577
+ * ```ts
578
+ * const users = await db.from('User').list({ pageSize: 10 });
579
+ * ```
580
+ */
581
+ list(options?: {
582
+ pageSize?: number;
583
+ nextPage?: string;
584
+ }): QueryResultsPromise<T>;
585
+ /**
586
+ * Retrieves the first record or null.
587
+ * @example
588
+ * ```ts
589
+ * const user = await db.from('User').firstOrNull();
590
+ * ```
591
+ */
592
+ firstOrNull(): Promise<T | null>;
593
+ /**
594
+ * Retrieves exactly one record or null.
595
+ * @example
596
+ * ```ts
597
+ * const user = await db
598
+ * .from('User')
599
+ * .where(eq('email', 'a@b.com'))
600
+ * .one();
601
+ * ```
602
+ */
603
+ one(): Promise<T | null>;
604
+ /**
605
+ * Retrieves a single page of records with optional next token.
606
+ * @example
607
+ * ```ts
608
+ * const { records, nextPage } = await db.from('User').page({ pageSize: 25 });
609
+ * ```
610
+ */
611
+ page(options?: {
612
+ pageSize?: number;
613
+ nextPage?: string;
614
+ }): Promise<{
615
+ records: T[];
616
+ nextPage?: string | null;
617
+ }>;
618
+ /**
619
+ * Sets field updates for an update query.
620
+ * @example
621
+ * ```ts
622
+ * await db
623
+ * .from('User')
624
+ * .where(eq('id', 'u1'))
625
+ * .setUpdates({ status: 'active' })
626
+ * .update();
627
+ * ```
628
+ */
629
+ setUpdates(updates: Partial<T>): IQueryBuilder<T>;
630
+ /**
631
+ * Executes an update operation.
632
+ * @example
633
+ * ```ts
634
+ * await db.from('User').where(eq('id', 'u1')).setUpdates({ status: 'active' }).update();
635
+ * ```
636
+ */
637
+ update(): Promise<unknown>;
638
+ /**
639
+ * Executes a delete operation.
640
+ * Returns the number of deleted records.
641
+ * @example
642
+ * ```ts
643
+ * await db.from('User').where(eq('status', 'inactive')).delete();
644
+ * ```
645
+ */
646
+ delete(): Promise<number>;
647
+ /**
648
+ * Registers a listener for added items on a stream.
649
+ * @example
650
+ * ```ts
651
+ * db.from('User').onItemAdded(u => console.log('added', u));
652
+ * ```
653
+ */
654
+ onItemAdded(listener: (entity: T) => void): IQueryBuilder<T>;
655
+ /**
656
+ * Registers a listener for updated items on a stream.
657
+ * @example
658
+ * ```ts
659
+ * db.from('User').onItemUpdated(u => console.log('updated', u));
660
+ * ```
661
+ */
662
+ onItemUpdated(listener: (entity: T) => void): IQueryBuilder<T>;
663
+ /**
664
+ * Registers a listener for deleted items on a stream.
665
+ * @example
666
+ * ```ts
667
+ * db.from('User').onItemDeleted(u => console.log('deleted', u));
668
+ * ```
669
+ */
670
+ onItemDeleted(listener: (entity: T) => void): IQueryBuilder<T>;
671
+ /**
672
+ * Registers a listener for any stream item with its action.
673
+ * @example
674
+ * ```ts
675
+ * db.from('User').onItem((u, action) => console.log(action, u));
676
+ * ```
677
+ */
678
+ onItem(listener: (entity: T | null, action: StreamAction) => void): IQueryBuilder<T>;
679
+ /**
680
+ * Starts a stream including query results.
681
+ * @example
682
+ * ```ts
683
+ * const { cancel } = await db.from('User').stream();
684
+ * ```
685
+ */
686
+ stream(includeQueryResults?: boolean, keepAlive?: boolean): Promise<{
687
+ cancel: () => void;
688
+ }>;
689
+ /**
690
+ * Starts a stream emitting only events.
691
+ * @example
692
+ * ```ts
693
+ * const { cancel } = await db.from('User').streamEventsOnly();
694
+ * ```
695
+ */
696
+ streamEventsOnly(keepAlive?: boolean): Promise<{
697
+ cancel: () => void;
698
+ }>;
699
+ /**
700
+ * Starts a stream that returns events alongside query results.
701
+ * @example
702
+ * ```ts
703
+ * const { cancel } = await db.from('User').streamWithQueryResults();
704
+ * ```
705
+ */
706
+ streamWithQueryResults(keepAlive?: boolean): Promise<{
707
+ cancel: () => void;
708
+ }>;
709
+ }
710
+
711
+ /** Builder for save operations. */
712
+ interface ISaveBuilder<T = unknown> {
713
+ /**
714
+ * Cascades specified relationships when saving.
715
+ * @example
716
+ * ```ts
717
+ * await db.save('User').cascade('role').one(user);
718
+ * ```
719
+ */
720
+ cascade(...relationships: Array<string | string[]>): ISaveBuilder<T>;
721
+ /**
722
+ * Persists a single entity.
723
+ * @example
724
+ * ```ts
725
+ * await db.save('User').one({ id: 'u1' });
726
+ * ```
727
+ */
728
+ one(entity: Partial<T>): Promise<unknown>;
729
+ /**
730
+ * Persists multiple entities.
731
+ * @example
732
+ * ```ts
733
+ * await db.save('User').many([{ id: 'u1' }, { id: 'u2' }]);
734
+ * ```
735
+ */
736
+ many(entities: Array<Partial<T>>): Promise<unknown>;
737
+ }
738
+ /** Builder for cascading save/delete operations across multiple tables. */
739
+ interface ICascadeBuilder<Schema = Record<string, unknown>> {
740
+ /**
741
+ * Specifies relationships to cascade through.
742
+ * @example
743
+ * ```ts
744
+ * const builder = db.cascade('permissions');
745
+ * ```
746
+ */
747
+ cascade(...relationships: Array<string | string[]>): ICascadeBuilder<Schema>;
748
+ /**
749
+ * Saves one or many entities for a given table.
750
+ * @example
751
+ * ```ts
752
+ * await db.cascade('permissions').save('Role', role);
753
+ * ```
754
+ */
755
+ save<Table extends keyof Schema & string>(table: Table, entityOrEntities: Partial<Schema[Table]> | Array<Partial<Schema[Table]>>): Promise<unknown>;
756
+ /**
757
+ * Deletes an entity by primary key.
758
+ * @example
759
+ * ```ts
760
+ * await db.cascade('permissions').delete('Role', 'admin');
761
+ * ```
762
+ */
763
+ delete<Table extends keyof Schema & string>(table: Table, primaryKey: string): Promise<boolean>;
764
+ }
765
+ /** Builder for describing cascade relationship metadata. */
766
+ interface ICascadeRelationshipBuilder {
767
+ /**
768
+ * Names the relationship graph.
769
+ * @example
770
+ * ```ts
771
+ * builder.graph('permissions');
772
+ * ```
773
+ */
774
+ graph(name: string): ICascadeRelationshipBuilder;
775
+ /**
776
+ * Sets the graph type.
777
+ * @example
778
+ * ```ts
779
+ * builder.graphType('Permission');
780
+ * ```
781
+ */
782
+ graphType(type: string): ICascadeRelationshipBuilder;
783
+ /**
784
+ * Field on the target entity.
785
+ * @example
786
+ * ```ts
787
+ * builder.targetField('roleId');
788
+ * ```
789
+ */
790
+ targetField(field: string): ICascadeRelationshipBuilder;
791
+ /**
792
+ * Field on the source entity.
793
+ * @example
794
+ * ```ts
795
+ * const rel = builder.sourceField('id');
796
+ * ```
797
+ */
798
+ sourceField(field: string): string;
799
+ }
800
+
801
+ interface RetryOptions {
802
+ /**
803
+ * Enable or disable HTTP retries for idempotent GET requests. Defaults to `true`.
804
+ */
805
+ enabled?: boolean;
806
+ /**
807
+ * Maximum number of retry attempts after the initial GET request. Defaults to 3.
808
+ */
809
+ maxRetries?: number;
810
+ /**
811
+ * Initial backoff delay in milliseconds. Defaults to 300ms and grows with Fibonacci backoff.
812
+ */
813
+ initialDelayMs?: number;
814
+ }
815
+ interface OnyxConfig {
816
+ baseUrl?: string;
817
+ databaseId?: string;
818
+ apiKey?: string;
819
+ apiSecret?: string;
820
+ fetch?: FetchImpl;
821
+ /**
822
+ * Default partition for queries, `findById`, and deletes when removing by
823
+ * primary key. Saves rely on the entity's partition field instead.
824
+ */
825
+ partition?: string;
826
+ /**
827
+ * When true, log HTTP requests and bodies to the console.
828
+ */
829
+ requestLoggingEnabled?: boolean;
830
+ /**
831
+ * When true, log HTTP responses and bodies to the console.
832
+ */
833
+ responseLoggingEnabled?: boolean;
834
+ /**
835
+ * Milliseconds to cache resolved credentials; defaults to 5 minutes.
836
+ */
837
+ ttl?: number;
838
+ /**
839
+ * Retry configuration for idempotent GET requests.
840
+ */
841
+ retry?: RetryOptions;
842
+ }
843
+ interface IOnyxDatabase<Schema = Record<string, unknown>> {
844
+ /**
845
+ * Begin a query against a table.
846
+ *
847
+ * @example
848
+ * ```ts
849
+ * const maybeUser = await db
850
+ * .from('User')
851
+ * .where(eq('email', 'a@b.com'))
852
+ * .firstOrNull(); // or .one()
853
+ * ```
854
+ *
855
+ * @example
856
+ * ```ts
857
+ * const users = await db
858
+ * .select('id', 'email')
859
+ * .from('User')
860
+ * .list();
861
+ * ```
862
+ *
863
+ * @param table Table name to query.
864
+ */
865
+ from<Table extends keyof Schema & string>(table: Table): IQueryBuilder<Schema[Table]>;
866
+ /**
867
+ * Select specific fields for a query.
868
+ *
869
+ * @example
870
+ * ```ts
871
+ * const users = await db
872
+ * .select('id', 'name')
873
+ * .from('User')
874
+ * .list();
875
+ * ```
876
+ *
877
+ * @param fields Field names to project; omit to select all.
878
+ */
879
+ select(...fields: string[]): IQueryBuilder<Record<string, unknown>>;
880
+ /**
881
+ * Run a Lucene full-text search across all tables.
882
+ *
883
+ * @example
884
+ * ```ts
885
+ * const results = await db.search('hello world', 4.4).list();
886
+ * ```
887
+ *
888
+ * @param queryText Text to match against `__full_text__`.
889
+ * @param minScore Optional minimum score; serialized as `null` when omitted.
890
+ */
891
+ search(queryText: string, minScore?: number | null): IQueryBuilder<Record<string, unknown>>;
892
+ /**
893
+ * Include related records in the next save or delete.
894
+ *
895
+ * @example
896
+ * ```ts
897
+ * // Save a role and its permissions
898
+ * await db
899
+ * .cascade('permissions:Permission(roleId, id)')
900
+ * .save('Role', role);
901
+ *
902
+ * // Delete a role and all of its permissions via resolver
903
+ * await db
904
+ * .cascade('permissions')
905
+ * .delete('Role', 'admin');
906
+ * ```
907
+ *
908
+ * @param relationships Cascade relationship strings using
909
+ * `graph:Type(targetField, sourceField)` syntax when saving.
910
+ * When deleting, pass resolver attribute names only.
911
+ */
912
+ cascade(...relationships: Array<string | string[]>): ICascadeBuilder<Schema>;
913
+ /**
914
+ * Build cascade relationship strings programmatically.
915
+ *
916
+ * @example
917
+ * ```ts
918
+ * const rel = db
919
+ * .cascadeBuilder()
920
+ * .graph('permissions')
921
+ * .graphType('Permission')
922
+ * .targetField('roleId')
923
+ * .sourceField('id');
924
+ * await db.cascade(rel).save('Role', role);
925
+ * ```
926
+ *
927
+ * @returns Builder that emits strings like
928
+ * `graphName:TypeName(targetField, sourceField)`.
929
+ */
930
+ cascadeBuilder(): ICascadeRelationshipBuilder;
931
+ /**
932
+ * Start a save builder for inserting or updating entities.
933
+ *
934
+ * @example
935
+ * ```ts
936
+ * await db
937
+ * .save('User')
938
+ * .cascade('role:Role(userId, id)')
939
+ * .one({
940
+ * id: 'u1',
941
+ * email: 'a@b.com',
942
+ * role: { id: 'admin', userId: 'u1' }
943
+ * });
944
+ * ```
945
+ *
946
+ * @param table Table to save into.
947
+ */
948
+ save<Table extends keyof Schema & string>(table: Table): ISaveBuilder<Schema[Table]>;
949
+ /**
950
+ * Save one or many entities immediately.
951
+ *
952
+ * @example
953
+ * ```ts
954
+ * await db.save(
955
+ * 'Role',
956
+ * [{ id: 'admin', permissions: [{ id: 'perm1', roleId: 'admin' }] }],
957
+ * { relationships: ['permissions:Permission(roleId, id)'] }
958
+ * );
959
+ * ```
960
+ *
961
+ * The `relationships` option accepts cascade strings in the form
962
+ * `graphName:TypeName(targetField, sourceField)` describing how child records relate to the
963
+ * parent. Use {@link cascadeBuilder} to construct them safely.
964
+ *
965
+ * @param table Table to save into.
966
+ * @param entityOrEntities Object or array of objects to persist.
967
+ * @param options Optional settings for the save operation.
968
+ * @param options.relationships Cascade relationships to include.
969
+ */
970
+ save<Table extends keyof Schema & string>(table: Table, entityOrEntities: Partial<Schema[Table]> | Array<Partial<Schema[Table]>>, options?: {
971
+ relationships?: string[];
972
+ }): Promise<unknown>;
973
+ /**
974
+ * Save many entities in configurable batches.
975
+ *
976
+ * @example
977
+ * ```ts
978
+ * await db.batchSave('User', users, 500);
979
+ * ```
980
+ *
981
+ * @param table Table to save into.
982
+ * @param entities Array of entities to persist.
983
+ * @param batchSize Number of entities per batch; defaults to 1000.
984
+ */
985
+ batchSave<Table extends keyof Schema & string>(table: Table, entities: Array<Partial<Schema[Table]>>, batchSize?: number, options?: {
986
+ relationships?: string[];
987
+ }): Promise<void>;
988
+ /**
989
+ * Retrieve an entity by its primary key.
990
+ *
991
+ * @example
992
+ * ```ts
993
+ * const user = await db.findById('User', 'user_1', {
994
+ * partition: 'tenantA',
995
+ * resolvers: ['profile']
996
+ * });
997
+ * ```
998
+ *
999
+ * @param table Table to search.
1000
+ * @param primaryKey Primary key value.
1001
+ * @param options Optional partition and resolver settings.
1002
+ */
1003
+ findById<Table extends keyof Schema & string, T = Schema[Table]>(table: Table, primaryKey: string, options?: {
1004
+ partition?: string;
1005
+ resolvers?: string[];
1006
+ }): Promise<T | null>;
1007
+ /**
1008
+ * Delete an entity by primary key.
1009
+ *
1010
+ * @example
1011
+ * ```ts
1012
+ * const deleted = await db.delete('Role', 'admin', {
1013
+ * relationships: ['permissions']
1014
+ * });
1015
+ * ```
1016
+ *
1017
+ * @param table Table containing the entity.
1018
+ * @param primaryKey Primary key value.
1019
+ * @param options Optional partition and cascade relationships.
1020
+ * @returns `true` when the delete request succeeds.
1021
+ */
1022
+ delete<Table extends keyof Schema & string>(table: Table, primaryKey: string, options?: {
1023
+ partition?: string;
1024
+ relationships?: string[];
1025
+ }): Promise<boolean>;
1026
+ /**
1027
+ * Store a document (file blob) for later retrieval.
1028
+ *
1029
+ * @example
1030
+ * ```ts
1031
+ * const id = await db.saveDocument({
1032
+ * path: '/docs/note.txt',
1033
+ * mimeType: 'text/plain',
1034
+ * content: 'hello world'
1035
+ * });
1036
+ * ```
1037
+ */
1038
+ saveDocument(doc: OnyxDocument): Promise<unknown>;
1039
+ /**
1040
+ * Fetch a previously saved document.
1041
+ *
1042
+ * @example
1043
+ * ```ts
1044
+ * const doc = await db.getDocument('doc123', { width: 640, height: 480 });
1045
+ * ```
1046
+ *
1047
+ * @param documentId ID of the document to fetch.
1048
+ * @param options Optional image resize settings.
1049
+ */
1050
+ getDocument(documentId: string, options?: {
1051
+ width?: number;
1052
+ height?: number;
1053
+ }): Promise<unknown>;
1054
+ /**
1055
+ * Remove a stored document permanently.
1056
+ *
1057
+ * @example
1058
+ * ```ts
1059
+ * await db.deleteDocument('doc123');
1060
+ * ```
1061
+ *
1062
+ * @param documentId ID of the document to delete.
1063
+ */
1064
+ deleteDocument(documentId: string): Promise<unknown>;
1065
+ /**
1066
+ * Fetch the current schema for the configured database.
1067
+ *
1068
+ * @example
1069
+ * ```ts
1070
+ * const schema = await db.getSchema();
1071
+ * const userOnly = await db.getSchema({ tables: ['User'] });
1072
+ * ```
1073
+ */
1074
+ getSchema(options?: {
1075
+ tables?: string | string[];
1076
+ }): Promise<SchemaRevision>;
1077
+ /**
1078
+ * Retrieve the schema revision history for the configured database.
1079
+ */
1080
+ getSchemaHistory(): Promise<SchemaHistoryEntry[]>;
1081
+ /**
1082
+ * Compare the current API schema with a local schema definition.
1083
+ *
1084
+ * @example
1085
+ * ```ts
1086
+ * const diff = await db.diffSchema(localSchema);
1087
+ * if (!diff.newTables.length && !diff.removedTables.length && !diff.changedTables.length) {
1088
+ * console.log('Schemas match');
1089
+ * }
1090
+ * ```
1091
+ */
1092
+ diffSchema(localSchema: SchemaUpsertRequest): Promise<SchemaDiff>;
1093
+ /**
1094
+ * Update the schema for the configured database.
1095
+ *
1096
+ * @example
1097
+ * ```ts
1098
+ * await db.updateSchema({
1099
+ * revisionDescription: 'Add profile table',
1100
+ * entities: [
1101
+ * {
1102
+ * name: 'Profile',
1103
+ * identifier: { name: 'id', generator: 'UUID' },
1104
+ * attributes: [
1105
+ * { name: 'displayName', type: 'String', isNullable: false }
1106
+ * ]
1107
+ * }
1108
+ * ]
1109
+ * }, { publish: true });
1110
+ * ```
1111
+ */
1112
+ updateSchema(schema: SchemaUpsertRequest, options?: {
1113
+ publish?: boolean;
1114
+ }): Promise<SchemaRevision>;
1115
+ /**
1116
+ * Validate a schema definition without applying it to the database.
1117
+ */
1118
+ validateSchema(schema: SchemaUpsertRequest): Promise<SchemaValidationResult>;
1119
+ /**
1120
+ * List stored secrets for the configured database.
1121
+ */
1122
+ listSecrets(): Promise<SecretsListResponse>;
1123
+ /**
1124
+ * Fetch a decrypted secret value by key.
1125
+ */
1126
+ getSecret(key: string): Promise<SecretRecord>;
1127
+ /**
1128
+ * Create or update a secret.
1129
+ */
1130
+ putSecret(key: string, input: SecretSaveRequest): Promise<SecretMetadata>;
1131
+ /**
1132
+ * Delete a secret by key.
1133
+ */
1134
+ deleteSecret(key: string): Promise<{
1135
+ key: string;
1136
+ }>;
1137
+ /**
1138
+ * Cancels active streams; safe to call multiple times.
1139
+ * @example
1140
+ * ```ts
1141
+ * const stream = await db.from('User').stream();
1142
+ * stream.cancel();
1143
+ * db.close();
1144
+ * ```
1145
+ */
1146
+ close(): void;
1147
+ }
1148
+ interface OnyxFacade {
1149
+ /**
1150
+ * Initialize a database client.
1151
+ *
1152
+ * @example
1153
+ * ```ts
1154
+ * const db = onyx.init({
1155
+ * baseUrl: 'https://api.onyx.dev',
1156
+ * databaseId: 'my-db',
1157
+ * apiKey: 'key',
1158
+ * apiSecret: 'secret'
1159
+ * });
1160
+ * ```
1161
+ *
1162
+ * @param config Connection settings and optional custom fetch.
1163
+ * @remarks
1164
+ * Each `db` instance resolves configuration once and holds a single internal
1165
+ * HTTP client. Requests leverage Node's built-in `fetch`, which reuses and
1166
+ * pools connections for keep-alive, so additional connection caching or
1167
+ * pooling is rarely necessary.
1168
+ */
1169
+ init<Schema = Record<string, unknown>>(config?: OnyxConfig): IOnyxDatabase<Schema>;
1170
+ /**
1171
+ * Clear cached configuration so the next {@link init} call re-resolves
1172
+ * credentials immediately.
1173
+ */
1174
+ clearCacheConfig(): void;
1175
+ }
1176
+ interface SecretMetadata {
1177
+ key: string;
1178
+ purpose?: string;
1179
+ updatedAt: Date;
1180
+ }
1181
+ interface SecretRecord extends SecretMetadata {
1182
+ value: string;
1183
+ }
1184
+ interface SecretsListResponse {
1185
+ records: SecretMetadata[];
1186
+ meta: {
1187
+ totalRecords: number;
1188
+ };
1189
+ }
1190
+ interface SecretSaveRequest {
1191
+ purpose?: string;
1192
+ value?: string;
1193
+ }
1194
+ type SchemaDataType = 'String' | 'Boolean' | 'Char' | 'Byte' | 'Short' | 'Int' | 'Float' | 'Double' | 'Long' | 'Timestamp' | 'EmbeddedObject' | 'EmbeddedList';
1195
+ type SchemaIdentifierGenerator = 'None' | 'Sequence' | 'UUID';
1196
+ interface SchemaIdentifier {
1197
+ name: string;
1198
+ generator?: SchemaIdentifierGenerator;
1199
+ type?: SchemaDataType | string;
1200
+ }
1201
+ interface SchemaAttribute {
1202
+ name: string;
1203
+ type: SchemaDataType | string;
1204
+ isNullable?: boolean;
1205
+ }
1206
+ type SchemaIndexType = 'DEFAULT' | 'LUCENE' | string;
1207
+ interface SchemaIndex {
1208
+ name: string;
1209
+ type?: SchemaIndexType;
1210
+ minimumScore?: number;
1211
+ [key: string]: unknown;
1212
+ }
1213
+ interface SchemaResolver {
1214
+ name: string;
1215
+ resolver: string;
1216
+ [key: string]: unknown;
1217
+ }
1218
+ type SchemaTriggerEvent = 'PreInsert' | 'PostInsert' | 'PrePersist' | 'PostPersist' | 'PreUpdate' | 'PostUpdate' | 'PreDelete' | 'PostDelete' | string;
1219
+ interface SchemaTrigger {
1220
+ name: string;
1221
+ event: SchemaTriggerEvent;
1222
+ trigger: string;
1223
+ [key: string]: unknown;
1224
+ }
1225
+ interface SchemaEntity {
1226
+ name: string;
1227
+ identifier?: SchemaIdentifier;
1228
+ partition?: string;
1229
+ attributes?: SchemaAttribute[];
1230
+ indexes?: SchemaIndex[];
1231
+ resolvers?: SchemaResolver[];
1232
+ triggers?: SchemaTrigger[];
1233
+ [key: string]: unknown;
1234
+ }
1235
+ interface SchemaRevisionMetadata {
1236
+ revisionId?: string;
1237
+ createdAt?: Date;
1238
+ publishedAt?: Date;
1239
+ [key: string]: unknown;
1240
+ }
1241
+ interface SchemaRevision {
1242
+ databaseId: string;
1243
+ revisionDescription?: string;
1244
+ entities: SchemaEntity[];
1245
+ meta?: SchemaRevisionMetadata;
1246
+ [key: string]: unknown;
1247
+ }
1248
+ type SchemaHistoryEntry = SchemaRevision;
1249
+ type SchemaUpsertRequest = Omit<SchemaRevision, 'databaseId' | 'meta'> & {
1250
+ databaseId?: string;
1251
+ [key: string]: unknown;
1252
+ };
1253
+ interface SchemaValidationResult {
1254
+ valid?: boolean;
1255
+ schema?: SchemaRevision;
1256
+ errors?: Array<{
1257
+ message: string;
1258
+ }>;
1259
+ }
1260
+ interface SchemaAttributeChange {
1261
+ name: string;
1262
+ from: {
1263
+ type?: string;
1264
+ isNullable?: boolean;
1265
+ };
1266
+ to: {
1267
+ type?: string;
1268
+ isNullable?: boolean;
1269
+ };
1270
+ }
1271
+ interface SchemaIndexChange {
1272
+ name: string;
1273
+ from: SchemaIndex;
1274
+ to: SchemaIndex;
1275
+ }
1276
+ interface SchemaResolverChange {
1277
+ name: string;
1278
+ from: SchemaResolver;
1279
+ to: SchemaResolver;
1280
+ }
1281
+ interface SchemaTriggerChange {
1282
+ name: string;
1283
+ from: SchemaTrigger;
1284
+ to: SchemaTrigger;
1285
+ }
1286
+ interface SchemaTableDiff {
1287
+ name: string;
1288
+ partition?: {
1289
+ from: string | null;
1290
+ to: string | null;
1291
+ } | null;
1292
+ identifier?: {
1293
+ from: SchemaIdentifier | null;
1294
+ to: SchemaIdentifier | null;
1295
+ } | null;
1296
+ attributes?: {
1297
+ added: SchemaAttribute[];
1298
+ removed: string[];
1299
+ changed: SchemaAttributeChange[];
1300
+ };
1301
+ indexes?: {
1302
+ added: SchemaIndex[];
1303
+ removed: string[];
1304
+ changed: SchemaIndexChange[];
1305
+ };
1306
+ resolvers?: {
1307
+ added: SchemaResolver[];
1308
+ removed: string[];
1309
+ changed: SchemaResolverChange[];
1310
+ };
1311
+ triggers?: {
1312
+ added: SchemaTrigger[];
1313
+ removed: string[];
1314
+ changed: SchemaTriggerChange[];
1315
+ };
1316
+ }
1317
+ interface SchemaDiff {
1318
+ newTables: string[];
1319
+ removedTables: string[];
1320
+ changedTables: SchemaTableDiff[];
1321
+ }
1322
+
1323
+ declare const asc: (field: string) => Sort;
1324
+ declare const desc: (field: string) => Sort;
1325
+
1326
+ /** Builder for combining query conditions with logical operators. */
1327
+ declare class ConditionBuilderImpl implements IConditionBuilder {
1328
+ private condition;
1329
+ /**
1330
+ * Initialize with an optional starting criteria.
1331
+ *
1332
+ * @param criteria Initial query criteria to seed the builder.
1333
+ * @example
1334
+ * ```ts
1335
+ * const builder = new ConditionBuilderImpl({ field: 'id', operator: 'eq', value: '1' });
1336
+ * ```
1337
+ */
1338
+ constructor(criteria?: QueryCriteria | null);
1339
+ /**
1340
+ * Add a criteria combined with AND.
1341
+ *
1342
+ * @param condition Another builder or raw criteria to AND.
1343
+ * @example
1344
+ * ```ts
1345
+ * builder.and({ field: 'name', operator: 'eq', value: 'Ada' });
1346
+ * ```
1347
+ */
1348
+ and(condition: IConditionBuilder | QueryCriteria): IConditionBuilder;
1349
+ /**
1350
+ * Add a criteria combined with OR.
1351
+ *
1352
+ * @param condition Another builder or raw criteria to OR.
1353
+ * @example
1354
+ * ```ts
1355
+ * builder.or({ field: 'status', operator: 'eq', value: 'active' });
1356
+ * ```
1357
+ */
1358
+ or(condition: IConditionBuilder | QueryCriteria): IConditionBuilder;
1359
+ /**
1360
+ * Produce the composed QueryCondition.
1361
+ *
1362
+ * @example
1363
+ * ```ts
1364
+ * const condition = builder.toCondition();
1365
+ * ```
1366
+ */
1367
+ toCondition(): QueryCondition;
1368
+ /**
1369
+ * Wrap raw criteria into a single condition object.
1370
+ *
1371
+ * @param criteria Criteria to wrap.
1372
+ * @example
1373
+ * ```ts
1374
+ * builder['single']({ field: 'id', operator: 'eq', value: '1' });
1375
+ * ```
1376
+ */
1377
+ private single;
1378
+ /**
1379
+ * Create a compound condition using the provided operator.
1380
+ *
1381
+ * @param operator Logical operator to apply.
1382
+ * @param conditions Child conditions to combine.
1383
+ * @example
1384
+ * ```ts
1385
+ * builder['compound']('AND', [condA, condB]);
1386
+ * ```
1387
+ */
1388
+ private compound;
1389
+ /**
1390
+ * Merge the next condition into the existing tree using the operator.
1391
+ *
1392
+ * @param operator Logical operator for the merge.
1393
+ * @param next Condition to merge into the tree.
1394
+ * @example
1395
+ * ```ts
1396
+ * builder['addCompound']('AND', someCondition);
1397
+ * ```
1398
+ */
1399
+ private addCompound;
1400
+ /**
1401
+ * Normalize input into a QueryCondition instance.
1402
+ *
1403
+ * @param condition Builder or raw criteria to normalize.
1404
+ * @example
1405
+ * ```ts
1406
+ * const qc = builder['prepare']({ field: 'id', operator: 'eq', value: '1' });
1407
+ * ```
1408
+ */
1409
+ private prepare;
1410
+ }
1411
+
1412
+ declare const eq: (field: string, value: unknown) => ConditionBuilderImpl;
1413
+ declare const neq: (field: string, value: unknown) => ConditionBuilderImpl;
1414
+ declare function inOp(field: string, values: string): ConditionBuilderImpl;
1415
+ declare function inOp<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1416
+ declare function within<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1417
+ declare function notIn(field: string, values: string): ConditionBuilderImpl;
1418
+ declare function notIn<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1419
+ declare function notWithin<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1420
+ declare const between: (field: string, lower: unknown, upper: unknown) => ConditionBuilderImpl;
1421
+ declare const gt: (field: string, value: unknown) => ConditionBuilderImpl;
1422
+ declare const gte: (field: string, value: unknown) => ConditionBuilderImpl;
1423
+ declare const lt: (field: string, value: unknown) => ConditionBuilderImpl;
1424
+ declare const lte: (field: string, value: unknown) => ConditionBuilderImpl;
1425
+ declare const matches: (field: string, regex: string) => ConditionBuilderImpl;
1426
+ declare const search: (queryText: string, minScore?: number | null) => ConditionBuilderImpl;
1427
+ declare const notMatches: (field: string, regex: string) => ConditionBuilderImpl;
1428
+ declare const like: (field: string, pattern: string) => ConditionBuilderImpl;
1429
+ declare const notLike: (field: string, pattern: string) => ConditionBuilderImpl;
1430
+ declare const contains: (field: string, value: unknown) => ConditionBuilderImpl;
1431
+ declare const containsIgnoreCase: (field: string, value: unknown) => ConditionBuilderImpl;
1432
+ declare const notContains: (field: string, value: unknown) => ConditionBuilderImpl;
1433
+ declare const notContainsIgnoreCase: (field: string, value: unknown) => ConditionBuilderImpl;
1434
+ declare const startsWith: (field: string, prefix: string) => ConditionBuilderImpl;
1435
+ declare const notStartsWith: (field: string, prefix: string) => ConditionBuilderImpl;
1436
+ declare const isNull: (field: string) => ConditionBuilderImpl;
1437
+ declare const notNull: (field: string) => ConditionBuilderImpl;
1438
+
1439
+ declare const avg: (attribute: string) => string;
1440
+ declare const sum: (attribute: string) => string;
1441
+ declare const count: (attribute: string) => string;
1442
+ declare const min: (attribute: string) => string;
1443
+ declare const max: (attribute: string) => string;
1444
+ declare const std: (attribute: string) => string;
1445
+ declare const variance: (attribute: string) => string;
1446
+ declare const median: (attribute: string) => string;
1447
+ declare const upper: (attribute: string) => string;
1448
+ declare const lower: (attribute: string) => string;
1449
+ declare const substring: (attribute: string, from: number, length: number) => string;
1450
+ declare const replace: (attribute: string, pattern: string, repl: string) => string;
1451
+ declare const percentile: (attribute: string, p: number) => string;
1452
+
1453
+ export { inOp as $, type QueryCriteriaOperator as A, type Sort as B, type StreamAction as C, type OnyxDocument as D, type FetchResponse as E, type FullTextQuery as F, type FetchImpl as G, type QueryCriteria as H, type IOnyxDatabase as I, type QueryCondition as J, type SelectQuery as K, type LogicalOperator as L, type QueryPage as M, type IConditionBuilder as N, type OnyxFacade as O, type IQueryBuilder as P, QueryResults as Q, type RetryOptions as R, type SecretMetadata as S, type ISaveBuilder as T, type UpdateQuery as U, type ICascadeBuilder as V, type ICascadeRelationshipBuilder as W, asc as X, desc as Y, eq as Z, neq as _, type QueryResultsPromise as a, within as a0, notIn as a1, notWithin as a2, between as a3, gt as a4, gte as a5, lt as a6, lte as a7, matches as a8, search as a9, notMatches as aa, like as ab, notLike as ac, contains as ad, containsIgnoreCase as ae, notContains as af, notContainsIgnoreCase as ag, startsWith as ah, notStartsWith as ai, isNull as aj, notNull as ak, avg as al, sum as am, count as an, min as ao, max as ap, std as aq, variance as ar, median as as, upper as at, lower as au, substring as av, replace as aw, percentile as ax, type OnyxConfig as b, type SecretRecord as c, type SecretsListResponse as d, type SecretSaveRequest as e, type SchemaDataType as f, type SchemaIdentifierGenerator as g, type SchemaIdentifier as h, type SchemaAttribute as i, type SchemaIndexType as j, type SchemaIndex as k, type SchemaResolver as l, type SchemaTriggerEvent as m, type SchemaTrigger as n, type SchemaEntity as o, type SchemaRevisionMetadata as p, type SchemaRevision as q, type SchemaHistoryEntry as r, type SchemaUpsertRequest as s, type SchemaValidationResult as t, type SchemaAttributeChange as u, type SchemaIndexChange as v, type SchemaResolverChange as w, type SchemaTriggerChange as x, type SchemaTableDiff as y, type SchemaDiff as z };