@wxn0brp/vql-client 0.2.14 → 0.2.15

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 (2) hide show
  1. package/dist/vql.d.ts +54 -34
  2. package/package.json +1 -1
package/dist/vql.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- declare type Arg<T = any> = {
1
+ export declare type Arg<T = any> = {
2
2
  [K in keyof T]?: any;
3
3
  } & Record<string, any>;
4
- declare type ArrayOperators<T = any> = {
4
+ export declare type ArrayOperators<T = any> = {
5
5
  $arrInc?: {
6
6
  [K in keyof T]?: T[K] extends any[] ? T[K][number][] : T[K][];
7
7
  };
@@ -10,14 +10,14 @@ declare type ArrayOperators<T = any> = {
10
10
  };
11
11
  $size?: NestedValue<T, number>;
12
12
  };
13
- declare type ArrayUpdater<T = any> = {
13
+ export declare type ArrayUpdater<T = any> = {
14
14
  $push?: NestedValue<T, any>;
15
15
  $pushSet?: NestedValue<T, any>;
16
16
  $pushAll?: NestedValue<T, any>;
17
17
  $pull?: NestedValue<T, any>;
18
18
  $pullAll?: NestedValue<T, any>;
19
19
  };
20
- declare class Collection<D = Data> {
20
+ export declare class Collection<D = Data> {
21
21
  db: ValtheraCompatible;
22
22
  collection: string;
23
23
  constructor(db: ValtheraCompatible, collection: string);
@@ -25,8 +25,13 @@ declare class Collection<D = Data> {
25
25
  add(data: Arg<D>, id_gen?: true): Promise<D & {
26
26
  _id: string;
27
27
  }>;
28
+ bulkAdd(data: Arg<D>[], id_gen: false): Promise<D[]>;
29
+ bulkAdd(data: Arg<D>[], id_gen?: true): Promise<(D & {
30
+ _id: string;
31
+ })[]>;
28
32
  find(search?: Search<D>, options?: DbFindOpts<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D[]>;
29
- findOne(search?: Search<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D>;
33
+ findOne(search?: Search<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D | null>;
34
+ count(search?: Search<D, false>): Promise<number>;
30
35
  update(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D[]>;
31
36
  updateOne(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D | null>;
32
37
  remove(search: Search<D>, context?: VContext): Promise<D[]>;
@@ -34,8 +39,9 @@ declare class Collection<D = Data> {
34
39
  updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<VQueryT.UpdateOneOrAddResult<D>>;
35
40
  toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<VQueryT.ToggleOneResult<D>>;
36
41
  createIndex(fields: string[], opts?: IndexOpts): Promise<void>;
42
+ removeIndex(fields: string[]): Promise<void>;
37
43
  }
38
- declare type ComparisonOperators<T = any> = {
44
+ export declare type ComparisonOperators<T = any> = {
39
45
  $ne?: NestedValue<T, any>;
40
46
  $gt?: NestedValue<T, number, number>;
41
47
  $lt?: NestedValue<T, number, number>;
@@ -56,10 +62,10 @@ declare type ComparisonOperators<T = any> = {
56
62
  $idGte?: NestedValue<T, string | number, string | number>;
57
63
  $idLte?: NestedValue<T, string | number, string | number>;
58
64
  };
59
- declare interface Data {
65
+ export declare interface Data {
60
66
  [key: string]: any;
61
67
  }
62
- declare interface DbFindOpts<T = any> {
68
+ export declare interface DbFindOpts<T = any> {
63
69
  reverse?: boolean;
64
70
  limit?: number;
65
71
  offset?: number;
@@ -76,45 +82,45 @@ declare interface DbFindOpts<T = any> {
76
82
  groupBy?: KeysMatching<T, any> | KeysMatching<T, any>[];
77
83
  count?: Record<string, string>;
78
84
  }
79
- declare type DeepPartial<T> = {
85
+ export declare type DeepPartial<T> = {
80
86
  [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
81
87
  };
82
- declare type FieldPath<T = any> = KeysMatching<T, any> | (string & {}) | string[];
83
- declare interface FindOpts<T = any> {
88
+ export declare type FieldPath<T = any> = KeysMatching<T, any> | (string & {}) | string[];
89
+ export declare interface FindOpts<T = any> {
84
90
  select?: FieldPath<T>[];
85
91
  exclude?: FieldPath<T>[];
86
92
  transform?: Function;
87
93
  }
88
- declare interface IndexDefinition {
94
+ export declare interface IndexDefinition {
89
95
  collection: string;
90
96
  fields: string[];
91
97
  opts?: IndexOpts;
92
98
  }
93
- declare interface IndexOpts {
99
+ export declare interface IndexOpts {
94
100
  unique?: boolean;
95
101
  name?: string;
96
102
  }
97
- declare type JSPrimitiveType = "string" | "number" | "boolean" | "bigint" | "symbol" | "undefined" | "function" | "object";
98
- declare type KeysMatching<T, V, C = V> = {
103
+ export declare type JSPrimitiveType = "string" | "number" | "boolean" | "bigint" | "symbol" | "undefined" | "function" | "object";
104
+ export declare type KeysMatching<T, V, C = V> = {
99
105
  [K in keyof T]-?: T[K] extends C ? K : never;
100
106
  }[keyof T];
101
- declare type LogicalOperators<T = any> = {
107
+ export declare type LogicalOperators<T = any> = {
102
108
  $and?: Array<SearchOptions<T>>;
103
109
  $or?: Array<SearchOptions<T>>;
104
110
  $not?: SearchOptions<T>;
105
111
  };
106
- declare type NestedValue<T, V, C = V> = {
112
+ export declare type NestedValue<T, V, C = V> = {
107
113
  [K in keyof T as T[K] extends C ? K : T[K] extends object ? K : never]?: T[K] extends C ? V : T[K] extends object ? NestedValue<T[K], V, C> : never;
108
114
  };
109
- declare type ObjectUpdater<T = any> = {
115
+ export declare type ObjectUpdater<T = any> = {
110
116
  $merge?: NestedValue<T, any>;
111
117
  $deepMerge?: NestedValue<T, any>;
112
118
  };
113
- declare type OtherOperators<T = any> = {
119
+ export declare type OtherOperators<T = any> = {
114
120
  $subset?: DeepPartial<T>;
115
121
  };
116
- declare type PredefinedSearchOperators<T = any> = LogicalOperators<T> & ComparisonOperators<T> & TypeAndExistenceOperators<T> & ArrayOperators<T> & StringOperators<T> & OtherOperators<T>;
117
- declare namespace RelationTypes {
122
+ export declare type PredefinedSearchOperators<T = any> = LogicalOperators<T> & ComparisonOperators<T> & TypeAndExistenceOperators<T> & ArrayOperators<T> & StringOperators<T> & OtherOperators<T>;
123
+ export declare namespace RelationTypes {
118
124
  type Path = [
119
125
  string,
120
126
  string
@@ -143,33 +149,33 @@ declare namespace RelationTypes {
143
149
  };
144
150
  }
145
151
  }
146
- declare type Search<T = any, AllowFn extends boolean = true> = AllowFn extends true ? SearchOptions<T> | SearchFunc<T> : SearchOptions<T>;
147
- declare type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
148
- declare type SearchOptions<T = any> = PredefinedSearchOperators<T> & DeepPartial<T> & Record<string, any>;
149
- declare type StringOperators<T = any> = {
152
+ export declare type Search<T = any, AllowFn extends boolean = true> = AllowFn extends true ? SearchOptions<T> | SearchFunc<T> : SearchOptions<T>;
153
+ export declare type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
154
+ export declare type SearchOptions<T = any> = PredefinedSearchOperators<T> & DeepPartial<T> & Record<string, any>;
155
+ export declare type StringOperators<T = any> = {
150
156
  $regex?: NestedValue<T, RegExp | string, string>;
151
157
  $startsWith?: NestedValue<T, string, string>;
152
158
  $endsWith?: NestedValue<T, string, string>;
153
159
  $iStartsWith?: NestedValue<T, string, string>;
154
160
  $iEndsWith?: NestedValue<T, string, string>;
155
161
  };
156
- declare interface TransactionHandle {
162
+ export declare interface TransactionHandle {
157
163
  id: string;
158
164
  _adapterData?: unknown;
159
165
  }
160
- declare type TypeAndExistenceOperators<T = any> = {
166
+ export declare type TypeAndExistenceOperators<T = any> = {
161
167
  $exists?: NestedValue<T, boolean, any>;
162
168
  $type?: NestedValue<T, JSPrimitiveType, any>;
163
169
  };
164
- declare interface UpdateOneOrAdd<T> {
170
+ export declare interface UpdateOneOrAdd<T> {
165
171
  add_arg?: Arg<T>;
166
172
  id_gen?: boolean;
167
173
  context?: VContext;
168
174
  }
169
- declare type Updater<T = any, AllowFn extends boolean = true> = AllowFn extends true ? UpdaterArg<T> | UpdaterFunc<T> : UpdaterArg<T>;
170
- declare type UpdaterArg<T = any> = ArrayUpdater<T> & ObjectUpdater<T> & ValueUpdater<T> & DeepPartial<T> & Record<string, any>;
171
- declare type UpdaterFunc<T = any> = (data: T, context: VContext) => Data | void;
172
- declare interface ValtheraCompatible {
175
+ export declare type Updater<T = any, AllowFn extends boolean = true> = AllowFn extends true ? UpdaterArg<T> | UpdaterFunc<T> : UpdaterArg<T>;
176
+ export declare type UpdaterArg<T = any> = ArrayUpdater<T> & ObjectUpdater<T> & ValueUpdater<T> & DeepPartial<T> & Record<string, any>;
177
+ export declare type UpdaterFunc<T = any> = (data: T, context: VContext) => Data | void;
178
+ export declare interface ValtheraCompatible {
173
179
  c<T = Data>(collection: string): Collection<T>;
174
180
  getCollections(): Promise<string[]>;
175
181
  ensureCollection(collection: string): Promise<boolean>;
@@ -185,15 +191,18 @@ declare interface ValtheraCompatible {
185
191
  updateOneOrAdd<T = Data>(query: VQueryT.UpdateOneOrAdd<T>): Promise<VQueryT.UpdateOneOrAddResult<T>>;
186
192
  toggleOne<T = Data>(query: VQueryT.ToggleOne<T>): Promise<VQueryT.ToggleOneResult<T>>;
187
193
  createIndex(collection: string, fields: string[], opts?: IndexOpts): Promise<void>;
194
+ removeIndex(collection: string, fields: string[]): Promise<void>;
195
+ count(query: VQueryT.Count): Promise<number>;
196
+ bulkAdd<T = Data>(query: VQueryT.BulkAdd<T>): Promise<T[]>;
188
197
  }
189
- declare type ValueUpdater<T = any> = {
198
+ export declare type ValueUpdater<T = any> = {
190
199
  $inc?: NestedValue<T, number>;
191
200
  $dec?: NestedValue<T, number>;
192
201
  $unset?: NestedValue<T, any>;
193
202
  $rename?: NestedValue<T, any>;
194
203
  $set?: NestedValue<T, any>;
195
204
  };
196
- declare interface VContext {
205
+ export declare interface VContext {
197
206
  [key: string]: any;
198
207
  }
199
208
  export declare type VQL_Fields = Record<string, boolean | number> | string[];
@@ -309,6 +318,7 @@ export declare interface VQuery<T = Data, AllowFn extends boolean = true> {
309
318
  dbFindOpts?: DbFindOpts<T>;
310
319
  findOpts?: FindOpts<T>;
311
320
  data?: Arg<T>;
321
+ datas?: Arg<T>[];
312
322
  id_gen?: boolean;
313
323
  add_arg?: Arg<T>;
314
324
  updater?: Updater<T, AllowFn>;
@@ -328,6 +338,10 @@ export declare namespace VQueryT {
328
338
  data: Arg<T>;
329
339
  id_gen?: boolean;
330
340
  };
341
+ type BulkAdd<T = Data> = QueryBase<T> & {
342
+ datas: Arg<T>[];
343
+ id_gen?: boolean;
344
+ };
331
345
  type Find<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
332
346
  search?: Search<T, AllowFn>;
333
347
  findOpts?: FindOpts<T>;
@@ -371,5 +385,11 @@ export declare namespace VQueryT {
371
385
  type CreateIndex<T = Data> = QueryBase<T> & {
372
386
  index: IndexDefinition;
373
387
  };
388
+ type RemoveIndex<T = Data> = QueryBase<T> & {
389
+ index: IndexDefinition;
390
+ };
391
+ type Count<T = Data> = QueryBase<T> & {
392
+ search: Search<T, false>;
393
+ };
374
394
  }
375
395
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql-client",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "VQL Client",