@wxn0brp/vql 0.4.2 → 0.4.3
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/vql.d.ts +323 -0
- package/package.json +1 -1
package/dist/vql.d.ts
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export interface Data {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
export interface VContext {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
export type KeysMatching<T, V, C = V> = {
|
|
10
|
+
[K in keyof T]-?: T[K] extends C ? K : never;
|
|
11
|
+
}[keyof T];
|
|
12
|
+
export type PartialOfType<T, V, C = V> = Partial<Record<KeysMatching<T, V, C>, V>>;
|
|
13
|
+
export type PartialPickMatching<T, V, C = V> = Partial<Pick<T, KeysMatching<T, V, C>>>;
|
|
14
|
+
/** Logical Operators */
|
|
15
|
+
export type LogicalOperators<T = any> = {
|
|
16
|
+
/**
|
|
17
|
+
* Recursively applies multiple conditions, all of which must evaluate to true.
|
|
18
|
+
* Can include other operators such as $gt, $exists, or nested $and/$or conditions.
|
|
19
|
+
*/
|
|
20
|
+
$and?: Array<SearchOptions<T>>;
|
|
21
|
+
/**
|
|
22
|
+
* Recursively applies multiple conditions, at least one of which must evaluate to true.
|
|
23
|
+
* Can include other operators such as $lt, $type, or nested $and/$or conditions.
|
|
24
|
+
*/
|
|
25
|
+
$or?: Array<SearchOptions<T>>;
|
|
26
|
+
/**
|
|
27
|
+
* Negates a single condition.
|
|
28
|
+
* Can include any other operator as its value.
|
|
29
|
+
*/
|
|
30
|
+
$not?: SearchOptions<T>;
|
|
31
|
+
};
|
|
32
|
+
/** Comparison Operators */
|
|
33
|
+
export type ComparisonOperators<T = any> = {
|
|
34
|
+
$gt?: PartialOfType<T, number>;
|
|
35
|
+
$lt?: PartialOfType<T, number>;
|
|
36
|
+
$gte?: PartialOfType<T, number>;
|
|
37
|
+
$lte?: PartialOfType<T, number>;
|
|
38
|
+
$between?: PartialOfType<T, [
|
|
39
|
+
number,
|
|
40
|
+
number
|
|
41
|
+
], number>;
|
|
42
|
+
$in?: Partial<Record<keyof T, T[keyof T][]>>;
|
|
43
|
+
$nin?: Partial<Record<keyof T, T[keyof T][]>>;
|
|
44
|
+
};
|
|
45
|
+
/** Type and Existence Operators */
|
|
46
|
+
export type TypeAndExistenceOperators<T = any> = {
|
|
47
|
+
$exists?: PartialOfType<T, boolean, any>;
|
|
48
|
+
$type?: PartialOfType<T, string>;
|
|
49
|
+
};
|
|
50
|
+
/** Array Operators */
|
|
51
|
+
export type ArrayOperators<T = any> = {
|
|
52
|
+
$arrinc?: PartialPickMatching<T, any[]>;
|
|
53
|
+
$arrincall?: PartialPickMatching<T, any[]>;
|
|
54
|
+
$size?: PartialOfType<T, number>;
|
|
55
|
+
};
|
|
56
|
+
/** String Operators */
|
|
57
|
+
export type StringOperators<T = any> = {
|
|
58
|
+
$regex?: PartialOfType<T, RegExp, string>;
|
|
59
|
+
$startsWith?: PartialOfType<T, string>;
|
|
60
|
+
$endsWith?: PartialOfType<T, string>;
|
|
61
|
+
};
|
|
62
|
+
/** Other Operators */
|
|
63
|
+
export type OtherOperators<T = any> = {
|
|
64
|
+
$subset?: Partial<Record<keyof T, T[keyof T]>>;
|
|
65
|
+
};
|
|
66
|
+
/** Predefined Search Operators */
|
|
67
|
+
export type PredefinedSearchOperators<T = any> = LogicalOperators<T> & ComparisonOperators<T> & TypeAndExistenceOperators<T> & ArrayOperators<T> & StringOperators<T> & OtherOperators<T>;
|
|
68
|
+
/**
|
|
69
|
+
* SearchOptions can be either a function or an object with predefined operators.
|
|
70
|
+
*/
|
|
71
|
+
export type SearchOptions<T = any> = PredefinedSearchOperators<T> & Arg<T>;
|
|
72
|
+
/** Arrays */
|
|
73
|
+
export type ArrayUpdater<T = any> = {
|
|
74
|
+
$push?: PartialOfType<T, any>;
|
|
75
|
+
/** Pushes items into an array and removes duplicates */
|
|
76
|
+
$pushset?: PartialOfType<T, any>;
|
|
77
|
+
$pull?: PartialOfType<T, any>;
|
|
78
|
+
$pullall?: PartialOfType<T, any>;
|
|
79
|
+
};
|
|
80
|
+
/** Objects */
|
|
81
|
+
export type ObjectUpdater<T = any> = {
|
|
82
|
+
$merge?: PartialOfType<T, any[]>;
|
|
83
|
+
};
|
|
84
|
+
/** Values */
|
|
85
|
+
export type ValueUpdater<T = any> = {
|
|
86
|
+
$inc?: PartialOfType<T, number>;
|
|
87
|
+
$dec?: PartialOfType<T, number>;
|
|
88
|
+
$unset?: PartialOfType<T, any>;
|
|
89
|
+
$rename?: PartialOfType<T, any>;
|
|
90
|
+
};
|
|
91
|
+
export type UpdaterArg<T = any> = ArrayUpdater<T> & ObjectUpdater<T> & ValueUpdater<T> & Arg<T>;
|
|
92
|
+
export type Arg<T = any> = {
|
|
93
|
+
[K in keyof T]?: any;
|
|
94
|
+
} & Record<string, any>;
|
|
95
|
+
export type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
|
|
96
|
+
export type UpdaterFunc<T = any> = (data: T, context: VContext) => boolean;
|
|
97
|
+
export type Search<T = any> = SearchOptions<T> | SearchFunc<T>;
|
|
98
|
+
export type Updater<T = any> = UpdaterArg<T> | UpdaterArg<T>[] | UpdaterFunc<T>;
|
|
99
|
+
export interface DbFindOpts<T = any> {
|
|
100
|
+
reverse?: boolean;
|
|
101
|
+
max?: number;
|
|
102
|
+
offset?: number;
|
|
103
|
+
sortBy?: KeysMatching<T, any>;
|
|
104
|
+
sortAsc?: boolean;
|
|
105
|
+
}
|
|
106
|
+
export interface FindOpts<T = any> {
|
|
107
|
+
select?: KeysMatching<T, any>[];
|
|
108
|
+
exclude?: KeysMatching<T, any>[];
|
|
109
|
+
transform?: Function;
|
|
110
|
+
}
|
|
111
|
+
declare class CollectionManager {
|
|
112
|
+
private db;
|
|
113
|
+
private collection;
|
|
114
|
+
constructor(db: ValtheraCompatible, collection: string);
|
|
115
|
+
/**
|
|
116
|
+
* Add data to a database.
|
|
117
|
+
*/
|
|
118
|
+
add<T = Data>(data: Arg, id_gen?: boolean): Promise<T>;
|
|
119
|
+
/**
|
|
120
|
+
* Find data in a database.
|
|
121
|
+
*/
|
|
122
|
+
find<T = Data>(search: Search, context?: VContext, options?: DbFindOpts, findOpts?: FindOpts): Promise<T[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Find one data entry in a database.
|
|
125
|
+
*/
|
|
126
|
+
findOne<T = Data>(search: Search, context?: VContext, findOpts?: FindOpts): Promise<T>;
|
|
127
|
+
/**
|
|
128
|
+
* Update data in a database.
|
|
129
|
+
*/
|
|
130
|
+
update(search: Search, updater: Updater, context?: VContext): Promise<boolean>;
|
|
131
|
+
/**
|
|
132
|
+
* Update one data entry in a database.
|
|
133
|
+
*/
|
|
134
|
+
updateOne(search: Search, updater: Updater, context?: VContext): Promise<boolean>;
|
|
135
|
+
/**
|
|
136
|
+
* Remove data from a database.
|
|
137
|
+
*/
|
|
138
|
+
remove(search: Search, context?: VContext): Promise<boolean>;
|
|
139
|
+
/**
|
|
140
|
+
* Remove one data entry from a database.
|
|
141
|
+
*/
|
|
142
|
+
removeOne(search: Search, context?: VContext): Promise<boolean>;
|
|
143
|
+
/**
|
|
144
|
+
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
145
|
+
*/
|
|
146
|
+
updateOneOrAdd(search: Search, updater: Updater, add_arg?: Arg, context?: VContext, id_gen?: boolean): Promise<boolean>;
|
|
147
|
+
}
|
|
148
|
+
export interface ValtheraCompatible {
|
|
149
|
+
c(collection: string): CollectionManager;
|
|
150
|
+
getCollections(): Promise<string[]>;
|
|
151
|
+
checkCollection(collection: string): Promise<boolean>;
|
|
152
|
+
issetCollection(collection: string): Promise<boolean>;
|
|
153
|
+
add<T = Data>(collection: string, data: Arg<T>, id_gen?: boolean): Promise<T>;
|
|
154
|
+
find<T = Data>(collection: string, search: Search<T>, context?: VContext, options?: DbFindOpts<T>, findOpts?: FindOpts<T>): Promise<T[]>;
|
|
155
|
+
findOne<T = Data>(collection: string, search: Search<T>, context?: VContext, findOpts?: FindOpts<T>): Promise<T | null>;
|
|
156
|
+
update<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
|
|
157
|
+
updateOne<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
|
|
158
|
+
remove<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
|
|
159
|
+
removeOne<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
|
|
160
|
+
removeCollection(collection: string): Promise<boolean>;
|
|
161
|
+
updateOneOrAdd<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, add_arg?: Arg<T>, context?: VContext, id_gen?: boolean): Promise<boolean>;
|
|
162
|
+
}
|
|
163
|
+
declare namespace RelationTypes {
|
|
164
|
+
type Path = [
|
|
165
|
+
string,
|
|
166
|
+
string
|
|
167
|
+
];
|
|
168
|
+
type FieldPath = string[];
|
|
169
|
+
interface DBS {
|
|
170
|
+
[key: string]: ValtheraCompatible;
|
|
171
|
+
}
|
|
172
|
+
interface Relation {
|
|
173
|
+
[key: string]: RelationConfig;
|
|
174
|
+
}
|
|
175
|
+
interface RelationConfig {
|
|
176
|
+
path: Path;
|
|
177
|
+
pk?: string;
|
|
178
|
+
fk?: string;
|
|
179
|
+
as?: string;
|
|
180
|
+
select?: string[];
|
|
181
|
+
findOpts?: DbFindOpts;
|
|
182
|
+
type?: "1" | "11" | "1n" | "nm";
|
|
183
|
+
relations?: Relation;
|
|
184
|
+
through?: {
|
|
185
|
+
table: string;
|
|
186
|
+
db?: string;
|
|
187
|
+
pk: string;
|
|
188
|
+
fk: string;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
export interface VQLQuery<T = any> {
|
|
193
|
+
find: VQLFind<T>;
|
|
194
|
+
findOne: VQLFindOne<T>;
|
|
195
|
+
f: VQLFindOne<T>;
|
|
196
|
+
add: VQLAdd<T>;
|
|
197
|
+
update: VQLUpdate<T>;
|
|
198
|
+
updateOne: VQLUpdateOne<T>;
|
|
199
|
+
remove: VQLRemove<T>;
|
|
200
|
+
removeOne: VQLRemoveOne<T>;
|
|
201
|
+
updateOneOrAdd: VQLUpdateOneOrAdd<T>;
|
|
202
|
+
removeCollection: VQLCollectionOperation;
|
|
203
|
+
checkCollection: VQLCollectionOperation;
|
|
204
|
+
issetCollection: VQLCollectionOperation;
|
|
205
|
+
getCollections: {};
|
|
206
|
+
}
|
|
207
|
+
export type VQLQueryData<T = any> = {
|
|
208
|
+
find: VQLFind<T>;
|
|
209
|
+
} | {
|
|
210
|
+
findOne: VQLFindOne<T>;
|
|
211
|
+
} | {
|
|
212
|
+
f: VQLFindOne<T>;
|
|
213
|
+
} | {
|
|
214
|
+
add: VQLAdd<T>;
|
|
215
|
+
} | {
|
|
216
|
+
update: VQLUpdate<T>;
|
|
217
|
+
} | {
|
|
218
|
+
updateOne: VQLUpdateOne<T>;
|
|
219
|
+
} | {
|
|
220
|
+
remove: VQLRemove<T>;
|
|
221
|
+
} | {
|
|
222
|
+
removeOne: VQLRemoveOne<T>;
|
|
223
|
+
} | {
|
|
224
|
+
updateOneOrAdd: VQLUpdateOneOrAdd<T>;
|
|
225
|
+
} | {
|
|
226
|
+
removeCollection: VQLCollectionOperation;
|
|
227
|
+
} | {
|
|
228
|
+
checkCollection: VQLCollectionOperation;
|
|
229
|
+
} | {
|
|
230
|
+
issetCollection: VQLCollectionOperation;
|
|
231
|
+
} | {
|
|
232
|
+
getCollections: {};
|
|
233
|
+
};
|
|
234
|
+
export interface VQLRequest<T = any> {
|
|
235
|
+
db: string;
|
|
236
|
+
d: VQLQueryData<T>;
|
|
237
|
+
}
|
|
238
|
+
export interface VQLFind<T = any> {
|
|
239
|
+
collection: string;
|
|
240
|
+
search?: Search<T>;
|
|
241
|
+
limit?: number;
|
|
242
|
+
fields?: VQLFields;
|
|
243
|
+
select?: VQLFields;
|
|
244
|
+
relations?: VQLRelations;
|
|
245
|
+
options?: DbFindOpts<T>;
|
|
246
|
+
searchOpts?: FindOpts<T>;
|
|
247
|
+
}
|
|
248
|
+
export interface VQLFindOne<T = any> {
|
|
249
|
+
collection: string;
|
|
250
|
+
search: Search<T>;
|
|
251
|
+
fields?: VQLFields;
|
|
252
|
+
select?: VQLFields;
|
|
253
|
+
relations?: VQLRelations;
|
|
254
|
+
searchOpts?: FindOpts<T>;
|
|
255
|
+
}
|
|
256
|
+
export interface VQLAdd<T = any> {
|
|
257
|
+
collection: string;
|
|
258
|
+
data: Arg<T>;
|
|
259
|
+
id_gen?: boolean;
|
|
260
|
+
}
|
|
261
|
+
export interface VQLUpdate<T = any> {
|
|
262
|
+
collection: string;
|
|
263
|
+
search: Search<T>;
|
|
264
|
+
updater: UpdaterArg<T>;
|
|
265
|
+
}
|
|
266
|
+
export interface VQLUpdateOne<T = any> {
|
|
267
|
+
collection: string;
|
|
268
|
+
search: Search<T>;
|
|
269
|
+
updater: UpdaterArg<T>;
|
|
270
|
+
}
|
|
271
|
+
export interface VQLRemove<T = any> {
|
|
272
|
+
collection: string;
|
|
273
|
+
search: Search<T>;
|
|
274
|
+
}
|
|
275
|
+
export interface VQLRemoveOne<T = any> {
|
|
276
|
+
collection: string;
|
|
277
|
+
search: Search<T>;
|
|
278
|
+
}
|
|
279
|
+
export interface VQLUpdateOneOrAdd<T = any> {
|
|
280
|
+
collection: string;
|
|
281
|
+
search: Search<T>;
|
|
282
|
+
updater: UpdaterArg<T>;
|
|
283
|
+
add_arg?: Arg<T>;
|
|
284
|
+
id_gen?: boolean;
|
|
285
|
+
}
|
|
286
|
+
export interface VQLCollectionOperation {
|
|
287
|
+
collection: string;
|
|
288
|
+
}
|
|
289
|
+
export type VQLFields = Record<string, boolean | number> | string[];
|
|
290
|
+
export type VQLRelations = Record<string, VQLFind | VQLFindOne>;
|
|
291
|
+
export interface RelationQuery {
|
|
292
|
+
r: {
|
|
293
|
+
path: RelationTypes.Path;
|
|
294
|
+
search: Search;
|
|
295
|
+
relations: RelationTypes.Relation;
|
|
296
|
+
many?: boolean;
|
|
297
|
+
options?: DbFindOpts;
|
|
298
|
+
select?: RelationTypes.FieldPath[];
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
export interface VQLRef {
|
|
302
|
+
ref?: string;
|
|
303
|
+
var?: {
|
|
304
|
+
[k: string]: any;
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
export type VQLRefRequired = VQLRef & Required<Pick<VQLRef, "ref">>;
|
|
308
|
+
export type DeepPartial<T> = {
|
|
309
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
310
|
+
};
|
|
311
|
+
export type VQL<T = any> = (VQLRequest<T> | RelationQuery) & VQLRef;
|
|
312
|
+
export type VQLR<T = any> = VQL<T> | (DeepPartial<VQL<T>> & VQLRefRequired) | VQLRefRequired;
|
|
313
|
+
export interface VQLError {
|
|
314
|
+
err: true;
|
|
315
|
+
msg: string;
|
|
316
|
+
c: number;
|
|
317
|
+
why?: string;
|
|
318
|
+
}
|
|
319
|
+
export type VqlQueryRaw<T = any> = VQLR<T> | string | {
|
|
320
|
+
query: string;
|
|
321
|
+
} & VQLRef;
|
|
322
|
+
|
|
323
|
+
export {};
|