defuss-db 1.1.4 → 2.0.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/README.md +202 -90
- package/dist/client.cjs +241 -222
- package/dist/client.d.ts +16 -77
- package/dist/client.mjs +231 -223
- package/dist/index.cjs +866 -30
- package/dist/index.d.cts +243 -56
- package/dist/index.d.mts +243 -56
- package/dist/index.d.ts +243 -56
- package/dist/index.mjs +856 -31
- package/dist/runtime-C-5MF9ur.mjs +242 -0
- package/dist/runtime-CJK5Yy0J.d.ts +17 -0
- package/dist/runtime-E8GdpV6o.cjs +251 -0
- package/dist/server.cjs +1064 -642
- package/dist/server.d.ts +77 -210
- package/dist/server.mjs +1055 -645
- package/package.json +13 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
type RecordValue = string | bigint | number | boolean | null | ArrayBuffer | Blob;
|
|
1
|
+
type RecordValue = string | bigint | number | boolean | null | ArrayBuffer | Blob | Date;
|
|
2
|
+
type DefussValue = RecordValue | DefussValue[] | {
|
|
3
|
+
[key: string]: DefussValue | undefined;
|
|
4
|
+
};
|
|
2
5
|
type PrimaryKeyValue = bigint | number | string;
|
|
3
6
|
interface DefussRecord {
|
|
4
|
-
|
|
5
|
-
[key: string]:
|
|
7
|
+
id?: PrimaryKeyValue;
|
|
8
|
+
[key: string]: DefussValue | undefined;
|
|
6
9
|
}
|
|
10
|
+
type DefussSelector = Partial<Record<string, RecordValue>>;
|
|
11
|
+
interface DefussIndexDefinition<T extends DefussRecord = DefussRecord> {
|
|
12
|
+
name: string;
|
|
13
|
+
source?: string | ((value: T) => RecordValue | undefined);
|
|
14
|
+
unique?: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface DefussTableDefinition<T extends DefussRecord = DefussRecord> {
|
|
17
|
+
name: string;
|
|
18
|
+
indexes?: Array<DefussIndexDefinition<T>>;
|
|
19
|
+
}
|
|
20
|
+
declare function defineTable<T extends DefussRecord>(definition: DefussTableDefinition<T>): DefussTableDefinition<T>;
|
|
7
21
|
/**
|
|
8
22
|
* Generic provider interface for Defuss microdb.
|
|
9
23
|
*/
|
|
@@ -12,117 +26,290 @@ interface DefussProvider<O> {
|
|
|
12
26
|
* Connects to the database using the provided connection string.
|
|
13
27
|
* @param connectionString - The database connection string.
|
|
14
28
|
*/
|
|
15
|
-
connect(options: O): void
|
|
29
|
+
connect(options: O): Promise<void>;
|
|
16
30
|
/**
|
|
17
31
|
* Disconnects from the database.
|
|
18
32
|
*/
|
|
19
|
-
disconnect(): void
|
|
33
|
+
disconnect(): Promise<void>;
|
|
20
34
|
/**
|
|
21
35
|
* Checks if the provider is currently connected to the database.
|
|
22
36
|
* @returns True if connected, false otherwise.
|
|
23
37
|
*/
|
|
24
38
|
isConnected(): boolean;
|
|
25
39
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
40
|
+
* Ensures a table exists using the provided table definition.
|
|
41
|
+
* @param definition - The normalized table definition.
|
|
28
42
|
*/
|
|
29
|
-
|
|
43
|
+
ensureTable<T extends DefussRecord>(definition: DefussTableDefinition<T>): Promise<void>;
|
|
30
44
|
/**
|
|
31
|
-
* Inserts an item into the specified table
|
|
32
|
-
* @param
|
|
45
|
+
* Inserts an item into the specified table.
|
|
46
|
+
* @param definition - The table definition.
|
|
33
47
|
* @param value - The item to insert.
|
|
34
|
-
* @param indexData - A JSON object representing dynamic indices.
|
|
35
48
|
* @returns The primary key of the inserted row.
|
|
36
49
|
*/
|
|
37
|
-
insert<T extends DefussRecord>(
|
|
50
|
+
insert<T extends DefussRecord>(definition: DefussTableDefinition<T>, value: T): Promise<PrimaryKeyValue>;
|
|
38
51
|
/**
|
|
39
|
-
* Finds items based on provided
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
52
|
+
* Finds items based on the provided selector.
|
|
53
|
+
* @param definition - The table definition.
|
|
54
|
+
* @param selector - A selector over real value fields. All fields are optional.
|
|
42
55
|
* @returns An array of matching items.
|
|
43
56
|
*/
|
|
44
|
-
find<T extends DefussRecord>(
|
|
57
|
+
find<T extends DefussRecord>(definition: DefussTableDefinition<T>, selector?: DefussSelector): Promise<T[]>;
|
|
45
58
|
/**
|
|
46
|
-
* Finds a single item based on provided
|
|
47
|
-
* @param
|
|
48
|
-
* @param
|
|
59
|
+
* Finds a single item based on the provided selector.
|
|
60
|
+
* @param definition - The table definition.
|
|
61
|
+
* @param selector - A selector over real value fields. All fields are optional.
|
|
49
62
|
* @returns The first matching item or null if not found.
|
|
50
63
|
*/
|
|
51
|
-
findOne<T extends DefussRecord>(
|
|
64
|
+
findOne<T extends DefussRecord>(definition: DefussTableDefinition<T>, selector?: DefussSelector): Promise<T | null>;
|
|
52
65
|
/**
|
|
53
|
-
* Updates items based on provided
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
66
|
+
* Updates items based on the provided selector.
|
|
67
|
+
* @param definition - The table definition.
|
|
68
|
+
* @param selector - A selector over real value fields. All fields are optional.
|
|
56
69
|
* @param dataToUpdate - A JSON object representing fields to update.
|
|
57
70
|
*/
|
|
58
|
-
update<T extends DefussRecord>(
|
|
71
|
+
update<T extends DefussRecord>(definition: DefussTableDefinition<T>, selector: DefussSelector, dataToUpdate: Partial<T>): Promise<void>;
|
|
59
72
|
/**
|
|
60
|
-
* Deletes items based on provided
|
|
61
|
-
* @param
|
|
62
|
-
* @param
|
|
73
|
+
* Deletes items based on the provided selector.
|
|
74
|
+
* @param definition - The table definition.
|
|
75
|
+
* @param selector - A selector over real value fields. All fields are optional.
|
|
63
76
|
*/
|
|
64
|
-
delete(
|
|
77
|
+
delete<T extends DefussRecord>(definition: DefussTableDefinition<T>, selector: DefussSelector): Promise<void>;
|
|
65
78
|
/**
|
|
66
|
-
* Upserts an item into the specified table based on
|
|
67
|
-
* @param
|
|
79
|
+
* Upserts an item into the specified table based on the provided selector.
|
|
80
|
+
* @param definition - The table definition.
|
|
81
|
+
* @param selector - A non-empty selector resolving to `id` or a declared unique index.
|
|
68
82
|
* @param value - The item to insert or update.
|
|
69
|
-
* @param indexData - A JSON object representing dynamic indices used to identify the record.
|
|
70
83
|
* @returns The primary key of the upserted row.
|
|
71
84
|
*/
|
|
72
|
-
upsert<T extends DefussRecord>(
|
|
85
|
+
upsert<T extends DefussRecord>(definition: DefussTableDefinition<T>, selector: DefussSelector, value: T): Promise<PrimaryKeyValue>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type AnyRecord = Record<string, unknown>;
|
|
89
|
+
type Awaitable<TValue> = TValue | Promise<TValue>;
|
|
90
|
+
type MergeShape<TLeft extends AnyRecord, TRight extends AnyRecord> = Omit<TLeft, keyof TRight> & TRight;
|
|
91
|
+
type ShallowNullable<TValue> = {
|
|
92
|
+
[K in keyof TValue]: TValue[K] | null;
|
|
93
|
+
};
|
|
94
|
+
type AggregationJoinType = "left" | "right" | "inner";
|
|
95
|
+
type AggregationNamespacedRow<Alias extends string, TRow extends AnyRecord> = {
|
|
96
|
+
[K in Alias]: TRow;
|
|
97
|
+
};
|
|
98
|
+
type AggregationJoinResult<TRow extends AnyRecord, Alias extends string, TJoined extends AnyRecord, TType extends AggregationJoinType> = TType extends "inner" ? MergeShape<TRow, Record<Alias, TJoined>> : TType extends "left" ? MergeShape<TRow, Record<Alias, TJoined | null>> : MergeShape<ShallowNullable<TRow>, Record<Alias, TJoined>>;
|
|
99
|
+
interface AggregationCreateOptions<Alias extends string = string> {
|
|
100
|
+
as?: Alias;
|
|
101
|
+
where?: DefussSelector;
|
|
102
|
+
}
|
|
103
|
+
type AggregationRowsLoader<TRow extends AnyRecord> = TRow[] | Promise<TRow[]> | (() => TRow[] | Promise<TRow[]>);
|
|
104
|
+
interface AggregationTableSource<TRow extends DefussRecord = DefussRecord, Alias extends string = string> {
|
|
105
|
+
table: AggregationTableLike<TRow>;
|
|
106
|
+
as: Alias;
|
|
107
|
+
where?: DefussSelector;
|
|
108
|
+
}
|
|
109
|
+
interface AggregationRowsSource<TRow extends AnyRecord = AnyRecord, Alias extends string = string> {
|
|
110
|
+
rows: AggregationRowsLoader<TRow>;
|
|
111
|
+
as: Alias;
|
|
112
|
+
}
|
|
113
|
+
type AggregationSource<TRow extends AnyRecord = AnyRecord, Alias extends string = string> = AggregationTableSource<TRow & DefussRecord, Alias> | AggregationRowsSource<TRow, Alias>;
|
|
114
|
+
interface AggregationJoinSpec<TType extends AggregationJoinType = AggregationJoinType> {
|
|
115
|
+
type?: TType;
|
|
116
|
+
left: string;
|
|
117
|
+
right: string;
|
|
118
|
+
}
|
|
119
|
+
interface AggregationRowContext<TRow extends AnyRecord> {
|
|
120
|
+
index: number;
|
|
121
|
+
rows: readonly TRow[];
|
|
122
|
+
sources: Readonly<Record<string, readonly AnyRecord[]>>;
|
|
123
|
+
aggregation: AggregationBuilder<any>;
|
|
124
|
+
}
|
|
125
|
+
interface AggregationMergeContext<TRow extends AnyRecord> {
|
|
126
|
+
index: number;
|
|
127
|
+
rows: readonly TRow[];
|
|
128
|
+
sources: Readonly<Record<string, readonly AnyRecord[]>>;
|
|
129
|
+
aggregation: AggregationBuilder<any>;
|
|
73
130
|
}
|
|
131
|
+
interface AggregationGroupContext<TRow extends AnyRecord, TKeyRow extends AnyRecord = AnyRecord> {
|
|
132
|
+
key: Readonly<TKeyRow>;
|
|
133
|
+
rows: readonly TRow[];
|
|
134
|
+
sources: Readonly<Record<string, readonly AnyRecord[]>>;
|
|
135
|
+
aggregation: AggregationBuilder<any>;
|
|
136
|
+
}
|
|
137
|
+
interface AggregationSortContext<TRow extends AnyRecord> {
|
|
138
|
+
rows: readonly TRow[];
|
|
139
|
+
sources: Readonly<Record<string, readonly AnyRecord[]>>;
|
|
140
|
+
aggregation: AggregationBuilder<any>;
|
|
141
|
+
}
|
|
142
|
+
type AggregationValueResolver<TRow extends AnyRecord, TValue> = string | ((row: Readonly<TRow>, context: AggregationRowContext<TRow>) => Awaitable<TValue>);
|
|
143
|
+
type AggregationProjectionMap<TRow extends AnyRecord> = Record<string, AggregationValueResolver<TRow, unknown>>;
|
|
144
|
+
type AggregationRowMapper<TRow extends AnyRecord, TNext extends AnyRecord> = (row: Readonly<TRow>, context: AggregationRowContext<TRow>) => Awaitable<TNext>;
|
|
145
|
+
type AggregationRemoveFieldsInput<TRow extends AnyRecord> = readonly string[] | ((row: Readonly<TRow>, context: AggregationRowContext<TRow>) => Awaitable<readonly string[]>);
|
|
146
|
+
type AggregationMergeRowsResult<TNext extends AnyRecord> = TNext | null | undefined;
|
|
147
|
+
type AggregationMergeRowsFn<TRow extends AnyRecord, TNext extends AnyRecord> = (left: Readonly<TRow>, right: Readonly<TRow>, context: AggregationMergeContext<TRow>) => Awaitable<AggregationMergeRowsResult<TNext>>;
|
|
148
|
+
type AggregationDistinctSelector<TRow extends AnyRecord> = string | readonly string[] | ((row: Readonly<TRow>, context: AggregationRowContext<TRow>) => Awaitable<unknown | readonly unknown[]>);
|
|
149
|
+
interface AggregationDistinctOptions {
|
|
150
|
+
keep?: "first" | "last";
|
|
151
|
+
}
|
|
152
|
+
type AggregationGroupKeys<TRow extends AnyRecord> = string | readonly string[] | AggregationProjectionMap<TRow>;
|
|
153
|
+
type AggregationGroupReducer<TRow extends AnyRecord, TValue = unknown, TKeyRow extends AnyRecord = AnyRecord> = (rows: readonly TRow[], context: AggregationGroupContext<TRow, TKeyRow>) => Awaitable<TValue>;
|
|
154
|
+
type AggregationReducerMap<TRow extends AnyRecord, TKeyRow extends AnyRecord = AnyRecord> = Record<string, AggregationGroupReducer<TRow, unknown, TKeyRow>>;
|
|
155
|
+
type AggregationReducerResult<TReducers extends AggregationReducerMap<any, any>> = {
|
|
156
|
+
[K in keyof TReducers]: Awaited<ReturnType<TReducers[K]>>;
|
|
157
|
+
};
|
|
158
|
+
type AggregationSortDirection = "asc" | "desc";
|
|
159
|
+
interface AggregationFieldSortSpec {
|
|
160
|
+
field: string;
|
|
161
|
+
direction?: AggregationSortDirection;
|
|
162
|
+
}
|
|
163
|
+
interface AggregationResolverSortSpec<TRow extends AnyRecord> {
|
|
164
|
+
by: AggregationValueResolver<TRow, unknown>;
|
|
165
|
+
direction?: AggregationSortDirection;
|
|
166
|
+
}
|
|
167
|
+
type AggregationSortSpec<TRow extends AnyRecord> = AggregationFieldSortSpec | AggregationResolverSortSpec<TRow>;
|
|
168
|
+
type AggregationSortComparator<TRow extends AnyRecord> = (left: Readonly<TRow>, right: Readonly<TRow>, context: AggregationSortContext<TRow>) => Awaitable<number>;
|
|
169
|
+
interface AggregationTableLike<TRow extends DefussRecord = DefussRecord> {
|
|
170
|
+
find(selector?: DefussSelector): Promise<TRow[]>;
|
|
171
|
+
definition: unknown;
|
|
172
|
+
}
|
|
173
|
+
type ProjectionResult<TProjection extends AggregationProjectionMap<any>> = {
|
|
174
|
+
[K in keyof TProjection]: TProjection[K] extends (...args: any[]) => infer TResult ? Awaited<TResult> : unknown;
|
|
175
|
+
};
|
|
176
|
+
type AggregationJoinDefinition = {
|
|
177
|
+
source: AggregationSource<AnyRecord, string>;
|
|
178
|
+
spec: Required<AggregationJoinSpec>;
|
|
179
|
+
};
|
|
180
|
+
type AggregationOperation = {
|
|
181
|
+
kind: "project";
|
|
182
|
+
mapping: AggregationProjectionMap<any>;
|
|
183
|
+
} | {
|
|
184
|
+
kind: "alias";
|
|
185
|
+
mapping: AggregationProjectionMap<any>;
|
|
186
|
+
} | {
|
|
187
|
+
kind: "compute";
|
|
188
|
+
field: string;
|
|
189
|
+
resolver: AggregationValueResolver<any, unknown>;
|
|
190
|
+
} | {
|
|
191
|
+
kind: "computeMany";
|
|
192
|
+
mapping: AggregationProjectionMap<any>;
|
|
193
|
+
} | {
|
|
194
|
+
kind: "mapRows";
|
|
195
|
+
mapper: AggregationRowMapper<any, AnyRecord>;
|
|
196
|
+
} | {
|
|
197
|
+
kind: "removeFields";
|
|
198
|
+
paths: AggregationRemoveFieldsInput<any>;
|
|
199
|
+
} | {
|
|
200
|
+
kind: "mergeConsecutive";
|
|
201
|
+
merger: AggregationMergeRowsFn<any, AnyRecord>;
|
|
202
|
+
} | {
|
|
203
|
+
kind: "distinctBy";
|
|
204
|
+
selector: AggregationDistinctSelector<any>;
|
|
205
|
+
options: AggregationDistinctOptions;
|
|
206
|
+
} | {
|
|
207
|
+
kind: "groupBy";
|
|
208
|
+
keys: AggregationGroupKeys<any>;
|
|
209
|
+
reducers: AggregationReducerMap<any, AnyRecord>;
|
|
210
|
+
} | {
|
|
211
|
+
kind: "sortBy";
|
|
212
|
+
specs?: AggregationSortSpec<any>[];
|
|
213
|
+
comparator?: AggregationSortComparator<any>;
|
|
214
|
+
};
|
|
215
|
+
declare class AggregationBuilder<TRow extends AnyRecord> {
|
|
216
|
+
private readonly baseSource;
|
|
217
|
+
private readonly joins;
|
|
218
|
+
private readonly operations;
|
|
219
|
+
constructor(baseSource: AggregationSource<AnyRecord, string>, joins?: AggregationJoinDefinition[], operations?: AggregationOperation[]);
|
|
220
|
+
join<TJoined extends AnyRecord, Alias extends string, TType extends AggregationJoinType = "left">(source: AggregationSource<TJoined, Alias>, spec: AggregationJoinSpec<TType>): AggregationBuilder<AggregationJoinResult<TRow, Alias, TJoined, TType>>;
|
|
221
|
+
project<TProjection extends AggregationProjectionMap<TRow>>(mapping: TProjection): AggregationBuilder<ProjectionResult<TProjection>>;
|
|
222
|
+
alias<TProjection extends AggregationProjectionMap<TRow>>(mapping: TProjection): AggregationBuilder<MergeShape<TRow, ProjectionResult<TProjection>>>;
|
|
223
|
+
compute<TKey extends string, TValue>(field: TKey, resolver: AggregationValueResolver<TRow, TValue>): AggregationBuilder<MergeShape<TRow, Record<TKey, TValue>>>;
|
|
224
|
+
computeMany<TProjection extends AggregationProjectionMap<TRow>>(mapping: TProjection): AggregationBuilder<MergeShape<TRow, ProjectionResult<TProjection>>>;
|
|
225
|
+
mapRows<TNext extends AnyRecord>(mapper: AggregationRowMapper<TRow, TNext>): AggregationBuilder<TNext>;
|
|
226
|
+
removeFields(paths: AggregationRemoveFieldsInput<TRow>): AggregationBuilder<TRow>;
|
|
227
|
+
mergeConsecutive<TNext extends AnyRecord = TRow>(merger: AggregationMergeRowsFn<TRow, TNext>): AggregationBuilder<TNext>;
|
|
228
|
+
distinctBy(selector: AggregationDistinctSelector<TRow>, options?: AggregationDistinctOptions): AggregationBuilder<TRow>;
|
|
229
|
+
groupBy<TKeyProjection extends AggregationProjectionMap<TRow>, TReducers extends AggregationReducerMap<TRow, ProjectionResult<TKeyProjection>>>(keys: TKeyProjection, reducers: TReducers): AggregationBuilder<MergeShape<ProjectionResult<TKeyProjection>, AggregationReducerResult<TReducers>>>;
|
|
230
|
+
groupBy<TKey extends string, TReducers extends AggregationReducerMap<TRow, Record<TKey, unknown>>>(keys: TKey | readonly TKey[], reducers: TReducers): AggregationBuilder<Record<TKey, unknown> & AggregationReducerResult<TReducers>>;
|
|
231
|
+
sortBy(comparator: AggregationSortComparator<TRow>): AggregationBuilder<TRow>;
|
|
232
|
+
sortBy(specs: AggregationSortSpec<TRow> | readonly AggregationSortSpec<TRow>[]): AggregationBuilder<TRow>;
|
|
233
|
+
execute(): Promise<TRow[]>;
|
|
234
|
+
private getSourceAliases;
|
|
235
|
+
private loadSourceRows;
|
|
236
|
+
private applyOperation;
|
|
237
|
+
}
|
|
238
|
+
declare function createAggregation<TRow extends DefussRecord, Alias extends string = "base">(table: AggregationTableLike<TRow>, options?: AggregationCreateOptions<Alias>): AggregationBuilder<AggregationNamespacedRow<Alias, TRow>>;
|
|
239
|
+
declare function createAggregation<TRow extends AnyRecord, Alias extends string>(source: AggregationSource<TRow, Alias>): AggregationBuilder<AggregationNamespacedRow<Alias, TRow>>;
|
|
240
|
+
declare function createAggregation<TRow extends AnyRecord, Alias extends string = "base">(rows: AggregationRowsLoader<TRow>, options?: Pick<AggregationCreateOptions<Alias>, "as">): AggregationBuilder<AggregationNamespacedRow<Alias, TRow>>;
|
|
241
|
+
declare function countRows<TRow extends AnyRecord>(): AggregationGroupReducer<TRow, number>;
|
|
242
|
+
declare function sumBy<TRow extends AnyRecord>(resolver: AggregationValueResolver<TRow, unknown>): AggregationGroupReducer<TRow, number>;
|
|
243
|
+
declare function avgBy<TRow extends AnyRecord>(resolver: AggregationValueResolver<TRow, unknown>): AggregationGroupReducer<TRow, number>;
|
|
244
|
+
declare function minBy<TRow extends AnyRecord>(resolver: AggregationValueResolver<TRow, unknown>): AggregationGroupReducer<TRow, unknown>;
|
|
245
|
+
declare function maxBy<TRow extends AnyRecord>(resolver: AggregationValueResolver<TRow, unknown>): AggregationGroupReducer<TRow, unknown>;
|
|
246
|
+
declare function firstBy<TRow extends AnyRecord>(resolver?: AggregationValueResolver<TRow, unknown>): AggregationGroupReducer<TRow, unknown>;
|
|
247
|
+
declare function lastBy<TRow extends AnyRecord>(resolver?: AggregationValueResolver<TRow, unknown>): AggregationGroupReducer<TRow, unknown>;
|
|
248
|
+
declare const aggregationReducers: {
|
|
249
|
+
count: typeof countRows;
|
|
250
|
+
sum: typeof sumBy;
|
|
251
|
+
avg: typeof avgBy;
|
|
252
|
+
min: typeof minBy;
|
|
253
|
+
max: typeof maxBy;
|
|
254
|
+
first: typeof firstBy;
|
|
255
|
+
last: typeof lastBy;
|
|
256
|
+
};
|
|
74
257
|
|
|
75
258
|
declare class DefussTable<T extends DefussRecord, O> {
|
|
76
259
|
provider: DefussProvider<O>;
|
|
77
|
-
|
|
260
|
+
definition: DefussTableDefinition<T>;
|
|
78
261
|
/**
|
|
79
|
-
* Initializes the DefussTable with the specified table
|
|
262
|
+
* Initializes the DefussTable with the specified table definition and provider.
|
|
80
263
|
* @param provider - The DefussProvider instance.
|
|
81
|
-
* @param
|
|
264
|
+
* @param definition - The table definition.
|
|
82
265
|
*/
|
|
83
|
-
constructor(provider: DefussProvider<O>,
|
|
266
|
+
constructor(provider: DefussProvider<O>, definition: DefussTableDefinition<T>);
|
|
84
267
|
/**
|
|
85
268
|
* Creates the table if it doesn't exist.
|
|
86
269
|
*/
|
|
87
270
|
init(): Promise<void>;
|
|
88
271
|
/**
|
|
89
|
-
* Inserts an item into the table
|
|
272
|
+
* Inserts an item into the table.
|
|
90
273
|
* @param value - The item to insert.
|
|
91
|
-
* @param indexData - A JSON object representing dynamic indices.
|
|
92
274
|
* @returns The primary key of the inserted row.
|
|
93
275
|
*/
|
|
94
|
-
insert(value: T
|
|
276
|
+
insert(value: T): Promise<PrimaryKeyValue>;
|
|
95
277
|
/**
|
|
96
|
-
* Finds items based on provided
|
|
97
|
-
* @param
|
|
278
|
+
* Finds items based on the provided selector.
|
|
279
|
+
* @param selector - A selector over real value fields. All fields are optional.
|
|
98
280
|
* @returns An array of matching items.
|
|
99
281
|
*/
|
|
100
|
-
find(
|
|
282
|
+
find(selector?: DefussSelector): Promise<T[]>;
|
|
101
283
|
/**
|
|
102
|
-
* Finds a single item based on provided
|
|
103
|
-
* @param
|
|
284
|
+
* Finds a single item based on the provided selector.
|
|
285
|
+
* @param selector - A selector over real value fields. All fields are optional.
|
|
104
286
|
* @returns The first matching item or null if not found.
|
|
105
287
|
*/
|
|
106
|
-
findOne(
|
|
288
|
+
findOne(selector?: DefussSelector): Promise<T | null>;
|
|
107
289
|
/**
|
|
108
|
-
* Updates items based on provided
|
|
109
|
-
* @param
|
|
290
|
+
* Updates items based on the provided selector.
|
|
291
|
+
* @param selector - A selector over real value fields.
|
|
110
292
|
* @param dataToUpdate - A JSON object representing fields to update.
|
|
111
293
|
*/
|
|
112
|
-
update(
|
|
294
|
+
update(selector: DefussSelector, dataToUpdate: Partial<T>): Promise<void>;
|
|
113
295
|
/**
|
|
114
|
-
* Deletes items based on provided
|
|
115
|
-
* @param
|
|
296
|
+
* Deletes items based on the provided selector.
|
|
297
|
+
* @param selector - A selector over real value fields.
|
|
116
298
|
*/
|
|
117
|
-
delete(
|
|
299
|
+
delete(selector: DefussSelector): Promise<void>;
|
|
118
300
|
/**
|
|
119
|
-
* Upserts an item into the table based on
|
|
301
|
+
* Upserts an item into the table based on the provided selector.
|
|
302
|
+
* @param selector - A non-empty selector resolving to `id` or a declared unique index.
|
|
120
303
|
* @param value - The item to insert or update.
|
|
121
|
-
* @param indexData - A JSON object representing dynamic indices used to identify the record.
|
|
122
304
|
* @returns The primary key of the upserted row.
|
|
123
305
|
*/
|
|
124
|
-
upsert(
|
|
306
|
+
upsert(selector: DefussSelector, value: T): Promise<PrimaryKeyValue>;
|
|
307
|
+
/**
|
|
308
|
+
* Starts a provider-agnostic aggregation pipeline rooted in this table.
|
|
309
|
+
* Any `where` selector is applied before rows enter the aggregation layer.
|
|
310
|
+
*/
|
|
311
|
+
aggregate<Alias extends string = "base">(options?: AggregationCreateOptions<Alias>): AggregationBuilder<AggregationNamespacedRow<Alias, T>>;
|
|
125
312
|
}
|
|
126
313
|
|
|
127
|
-
export { DefussTable };
|
|
128
|
-
export type { DefussProvider, DefussRecord, PrimaryKeyValue, RecordValue };
|
|
314
|
+
export { AggregationBuilder, DefussTable, aggregationReducers, avgBy, countRows, createAggregation, defineTable, firstBy, lastBy, maxBy, minBy, sumBy };
|
|
315
|
+
export type { AggregationCreateOptions, AggregationDistinctOptions, AggregationDistinctSelector, AggregationFieldSortSpec, AggregationGroupContext, AggregationGroupKeys, AggregationGroupReducer, AggregationJoinResult, AggregationJoinSpec, AggregationJoinType, AggregationMergeContext, AggregationMergeRowsFn, AggregationMergeRowsResult, AggregationNamespacedRow, AggregationProjectionMap, AggregationRemoveFieldsInput, AggregationResolverSortSpec, AggregationRowContext, AggregationRowMapper, AggregationRowsLoader, AggregationRowsSource, AggregationSortComparator, AggregationSortContext, AggregationSortDirection, AggregationSortSpec, AggregationSource, AggregationTableLike, AggregationTableSource, AggregationValueResolver, DefussIndexDefinition, DefussProvider, DefussRecord, DefussSelector, DefussTableDefinition, DefussValue, PrimaryKeyValue, RecordValue };
|