@wxn0brp/vql-client 0.2.13 → 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.
package/dist/index.d.ts CHANGED
@@ -6,9 +6,10 @@ export interface VQLHooks {
6
6
  onEnd?: (query: VQLUQ, durationMs: number, result: any, hookContext: any) => void;
7
7
  onError?: (query: VQLUQ, error: unknown, result?: any, hookContext?: any) => void;
8
8
  }
9
+ export type FetchImplementation = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
9
10
  export interface Config {
10
11
  transport?: VQLTransport;
11
- fetchImplementation: typeof fetch;
12
+ fetchImplementation: FetchImplementation;
12
13
  hooks?: VQLHooks;
13
14
  url?: string;
14
15
  body?: Record<string, any>;
package/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
- ;
2
1
  export const VConfig = {
3
2
  transport: defTransport,
4
3
  fetchImplementation: (input, init) => fetch(input, init),
5
4
  hooks: {},
6
- url: "/VQL"
5
+ url: "/VQL",
7
6
  };
8
7
  export async function fetchVQL(query, vars = {}, hookContext = {}, fetchOptions = {}) {
9
8
  const { transport, hooks } = VConfig;
@@ -14,7 +13,7 @@ export async function fetchVQL(query, vars = {}, hookContext = {}, fetchOptions
14
13
  if (typeof query === "string" && Object.keys(vars).length) {
15
14
  query = {
16
15
  query: query,
17
- var: vars
16
+ var: vars,
18
17
  };
19
18
  }
20
19
  const res = await transport(query, fetchOptions);
@@ -36,15 +35,15 @@ export async function fetchVQL(query, vars = {}, hookContext = {}, fetchOptions
36
35
  }
37
36
  export async function defTransport(query, fetchOptions) {
38
37
  const headers = Object.assign({
39
- "Content-Type": "application/json"
38
+ "Content-Type": "application/json",
40
39
  }, VConfig.headers, fetchOptions.headers);
41
40
  const body = Object.assign({}, VConfig.body, fetchOptions.body, {
42
- query
41
+ query,
43
42
  });
44
43
  const queryConfig = {
45
44
  method: "POST",
46
45
  headers,
47
- body: JSON.stringify(body)
46
+ body: JSON.stringify(body),
48
47
  };
49
48
  if (fetchOptions.signal)
50
49
  queryConfig.signal = fetchOptions.signal;
@@ -64,6 +63,6 @@ if (typeof window !== "undefined") {
64
63
  fetchVQL,
65
64
  defTransport,
66
65
  VQL: V,
67
- cfg: VConfig
66
+ cfg: VConfig,
68
67
  };
69
68
  }
package/dist/min.js CHANGED
@@ -1 +1 @@
1
- var VQLClient=(()=>{var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var T=(t,n)=>{for(var e in n)c(t,e,{get:n[e],enumerable:!0})},b=(t,n,e,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of w(n))!h.call(t,o)&&o!==e&&c(t,o,{get:()=>n[o],enumerable:!(i=m(n,o))||i.enumerable});return t};var x=t=>b(c({},"__esModule",{value:!0}),t);var O={};T(O,{V:()=>g,VConfig:()=>s,defTransport:()=>d,fetchVQL:()=>y});var s={transport:d,fetchImplementation:(t,n)=>fetch(t,n),hooks:{},url:"/VQL"};async function y(t,n={},e={},i={}){var p,f,u,Q;let{transport:o,hooks:r}=s,V=Date.now();try{e=Object.assign({},s.hookContext,n,e),(p=r.onStart)==null||p.call(r,t,e),typeof t=="string"&&Object.keys(n).length&&(t={query:t,var:n});let a=await o(t,i),L=Date.now()-V;if((f=r.onEnd)==null||f.call(r,t,L,a,e),a!=null&&a.err){let l=new Error(a.err);throw(u=r.onError)==null||u.call(r,t,l,a,e),l}return a.result!==void 0?a.result:a}catch(a){throw(Q=r.onError)==null||Q.call(r,t,a,null,e),a}}async function d(t,n){let e=Object.assign({"Content-Type":"application/json"},s.headers,n.headers),i=Object.assign({},s.body,n.body,{query:t}),o={method:"POST",headers:e,body:JSON.stringify(i)};n.signal&&(o.signal=n.signal);let r=await s.fetchImplementation(s.url,o);if(!r.ok)throw new Error(`VQL request failed: ${r.status}`);return await r.json()}var g=async(t,...n)=>{let e=t.map((i,o)=>i.trim()+(n[o]!==void 0?n[o]:"")).join(" ");return y(e)};typeof window!="undefined"&&(window.VQLClient={fetchVQL:y,defTransport:d,VQL:g,cfg:s});return x(O);})();
1
+ var VQLClient=(()=>{var c=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var T=(t,n)=>{for(var r in n)c(t,r,{get:n[r],enumerable:!0})},b=(t,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of h(n))!w.call(t,o)&&o!==r&&c(t,o,{get:()=>n[o],enumerable:!(i=L(n,o))||i.enumerable});return t};var R=t=>b(c({},"__esModule",{value:!0}),t);var x={};T(x,{V:()=>g,VConfig:()=>s,defTransport:()=>p,fetchVQL:()=>y});var s={transport:p,fetchImplementation:(t,n)=>fetch(t,n),hooks:{},url:"/VQL"};async function y(t,n={},r={},i={}){var d,f,u,l;let{transport:o,hooks:e}=s,m=Date.now();try{r=Object.assign({},s.hookContext,n,r),(d=e.onStart)==null||d.call(e,t,r),typeof t=="string"&&Object.keys(n).length&&(t={query:t,var:n});let a=await o(t,i),V=Date.now()-m;if((f=e.onEnd)==null||f.call(e,t,V,a,r),a!=null&&a.err){let Q=new Error(a.err);throw(u=e.onError)==null||u.call(e,t,Q,a,r),Q}return a.result!==void 0?a.result:a}catch(a){throw(l=e.onError)==null||l.call(e,t,a,null,r),a}}async function p(t,n){let r=Object.assign({"Content-Type":"application/json"},s.headers,n.headers),i=Object.assign({},s.body,n.body,{query:t}),o={method:"POST",headers:r,body:JSON.stringify(i)};n.signal&&(o.signal=n.signal);let e=await s.fetchImplementation(s.url,o);if(!e.ok)throw new Error(`VQL request failed: ${e.status}`);return await e.json()}var g=async(t,...n)=>{let r=t.map((i,o)=>i.trim()+(n[o]!==void 0?n[o]:"")).join(" ");return y(r)};typeof window!="undefined"&&(window.VQLClient={fetchVQL:y,defTransport:p,VQL:g,cfg:s});return R(x);})();
package/dist/vql.d.ts CHANGED
@@ -1,22 +1,48 @@
1
- export interface Data {
2
- [key: string]: any;
3
- }
4
- export type KeysMatching<T, V, C = V> = {
5
- [K in keyof T]-?: T[K] extends C ? K : never;
6
- }[keyof T];
7
- export type NestedValue<T, V, C = V> = {
8
- [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;
9
- };
10
- export type DeepPartial<T> = {
11
- [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
1
+ export declare type Arg<T = any> = {
2
+ [K in keyof T]?: any;
3
+ } & Record<string, any>;
4
+ export declare type ArrayOperators<T = any> = {
5
+ $arrInc?: {
6
+ [K in keyof T]?: T[K] extends any[] ? T[K][number][] : T[K][];
7
+ };
8
+ $arrIncAll?: {
9
+ [K in keyof T]?: T[K] extends any[] ? T[K][number][] : T[K][];
10
+ };
11
+ $size?: NestedValue<T, number>;
12
12
  };
13
- export type JSPrimitiveType = "string" | "number" | "boolean" | "bigint" | "symbol" | "undefined" | "function" | "object";
14
- export type LogicalOperators<T = any> = {
15
- $and?: Array<SearchOptions<T>>;
16
- $or?: Array<SearchOptions<T>>;
17
- $not?: SearchOptions<T>;
13
+ export declare type ArrayUpdater<T = any> = {
14
+ $push?: NestedValue<T, any>;
15
+ $pushSet?: NestedValue<T, any>;
16
+ $pushAll?: NestedValue<T, any>;
17
+ $pull?: NestedValue<T, any>;
18
+ $pullAll?: NestedValue<T, any>;
18
19
  };
19
- export type ComparisonOperators<T = any> = {
20
+ export declare class Collection<D = Data> {
21
+ db: ValtheraCompatible;
22
+ collection: string;
23
+ constructor(db: ValtheraCompatible, collection: string);
24
+ add(data: Arg<D>, id_gen: false): Promise<D>;
25
+ add(data: Arg<D>, id_gen?: true): Promise<D & {
26
+ _id: string;
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
+ })[]>;
32
+ find(search?: Search<D>, options?: DbFindOpts<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>;
35
+ update(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D[]>;
36
+ updateOne(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D | null>;
37
+ remove(search: Search<D>, context?: VContext): Promise<D[]>;
38
+ removeOne(search: Search<D>, context?: VContext): Promise<D | null>;
39
+ updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<VQueryT.UpdateOneOrAddResult<D>>;
40
+ toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<VQueryT.ToggleOneResult<D>>;
41
+ createIndex(fields: string[], opts?: IndexOpts): Promise<void>;
42
+ removeIndex(fields: string[]): Promise<void>;
43
+ }
44
+ export declare type ComparisonOperators<T = any> = {
45
+ $ne?: NestedValue<T, any>;
20
46
  $gt?: NestedValue<T, number, number>;
21
47
  $lt?: NestedValue<T, number, number>;
22
48
  $gte?: NestedValue<T, number, number>;
@@ -36,145 +62,65 @@ export type ComparisonOperators<T = any> = {
36
62
  $idGte?: NestedValue<T, string | number, string | number>;
37
63
  $idLte?: NestedValue<T, string | number, string | number>;
38
64
  };
39
- export type TypeAndExistenceOperators<T = any> = {
40
- $exists?: NestedValue<T, boolean, any>;
41
- $type?: NestedValue<T, JSPrimitiveType, any>;
42
- };
43
- export type ArrayOperators<T = any> = {
44
- $arrinc?: {
45
- [K in keyof T]?: T[K] extends any[] ? T[K][number][] : T[K][];
46
- };
47
- $arrincall?: {
48
- [K in keyof T]?: T[K] extends any[] ? T[K][number][] : T[K][];
49
- };
50
- $size?: NestedValue<T, number>;
51
- };
52
- export type StringOperators<T = any> = {
53
- $regex?: NestedValue<T, RegExp | string, string>;
54
- $startsWith?: NestedValue<T, string, string>;
55
- $endsWith?: NestedValue<T, string, string>;
56
- };
57
- export type OtherOperators<T = any> = {
58
- $subset?: DeepPartial<T>;
59
- };
60
- export type PredefinedSearchOperators<T = any> = LogicalOperators<T> & ComparisonOperators<T> & TypeAndExistenceOperators<T> & ArrayOperators<T> & StringOperators<T> & OtherOperators<T>;
61
- export type SearchOptions<T = any> = PredefinedSearchOperators<T> & DeepPartial<T> & Record<string, any>;
62
- export interface VContext {
65
+ export declare interface Data {
63
66
  [key: string]: any;
64
67
  }
65
- export type ArrayUpdater<T = any> = {
66
- $push?: NestedValue<T, any>;
67
- $pushset?: NestedValue<T, any>;
68
- $pull?: NestedValue<T, any>;
69
- $pullall?: NestedValue<T, any>;
70
- };
71
- export type ObjectUpdater<T = any> = {
72
- $merge?: NestedValue<T, any>;
73
- $deepMerge?: NestedValue<T, any>;
74
- };
75
- export type ValueUpdater<T = any> = {
76
- $inc?: NestedValue<T, number>;
77
- $dec?: NestedValue<T, number>;
78
- $unset?: NestedValue<T, any>;
79
- $rename?: NestedValue<T, any>;
80
- $set?: NestedValue<T, any>;
81
- };
82
- export type UpdaterArg<T = any> = ArrayUpdater<T> & ObjectUpdater<T> & ValueUpdater<T> & DeepPartial<T> & Record<string, any>;
83
- export type Arg<T = any> = {
84
- [K in keyof T]?: any;
85
- } & Record<string, any>;
86
- export type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
87
- export type UpdaterFunc<T = any> = (data: T, context: VContext) => Data | void;
88
- export type Search<T = any> = SearchOptions<T> | SearchFunc<T>;
89
- export type Updater<T = any> = UpdaterArg<T> | UpdaterFunc<T>;
90
- export interface DbFindOpts<T = any> {
68
+ export declare interface DbFindOpts<T = any> {
91
69
  reverse?: boolean;
92
70
  limit?: number;
93
71
  offset?: number;
94
- sortBy?: KeysMatching<T, any>;
72
+ sortBy?: KeysMatching<T, any> | {
73
+ field: KeysMatching<T, any>;
74
+ asc?: boolean;
75
+ }[];
95
76
  sortAsc?: boolean;
96
77
  min?: Record<string, KeysMatching<T, number>>;
97
78
  max?: Record<string, KeysMatching<T, number>>;
98
79
  avg?: Record<string, KeysMatching<T, number>>;
80
+ sum?: Record<string, KeysMatching<T, number>>;
81
+ distinct?: KeysMatching<T, any>;
99
82
  groupBy?: KeysMatching<T, any> | KeysMatching<T, any>[];
100
83
  count?: Record<string, string>;
101
84
  }
102
- export interface FindOpts<T = any> {
103
- select?: KeysMatching<T, any>[];
104
- exclude?: KeysMatching<T, any>[];
85
+ export declare type DeepPartial<T> = {
86
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
87
+ };
88
+ export declare type FieldPath<T = any> = KeysMatching<T, any> | (string & {}) | string[];
89
+ export declare interface FindOpts<T = any> {
90
+ select?: FieldPath<T>[];
91
+ exclude?: FieldPath<T>[];
105
92
  transform?: Function;
106
93
  }
107
- export interface VQuery_Control {
108
- }
109
- export interface VQuery<T = Data> {
110
- collection?: string;
111
- search?: Search<T>;
112
- context?: VContext;
113
- dbFindOpts?: DbFindOpts<T>;
114
- findOpts?: FindOpts<T>;
115
- data?: Arg<T>;
116
- id_gen?: boolean;
117
- add_arg?: Arg<T>;
118
- updater?: Updater<T>;
119
- control?: VQuery_Control;
120
- }
121
- export declare namespace VQueryT {
122
- type QueryBase<T = Data> = Required<Pick<VQuery<T>, "collection" | "search">> & Pick<VQuery<T>, "control">;
123
- type Add<T = Data> = Required<Pick<VQuery<T>, "data" | "collection">> & Pick<VQuery<T>, "id_gen" | "control">;
124
- type Find<T = Data> = Omit<QueryBase, "search"> & Pick<VQuery<T>, "search"> & Pick<VQuery<T>, "findOpts" | "dbFindOpts" | "context">;
125
- type FindOne<T = Data> = QueryBase & Pick<VQuery<T>, "findOpts" | "context">;
126
- type Update<T = Data> = QueryBase & Required<Pick<VQuery<T>, "updater">> & Pick<VQuery<T>, "context">;
127
- type Remove<T = Data> = QueryBase & Pick<VQuery<T>, "context">;
128
- type UpdateOneOrAdd<T = Data> = QueryBase & Update & Pick<VQuery<T>, "add_arg" | "id_gen">;
129
- type ToggleOne<T = Data> = QueryBase & Pick<VQuery<T>, "data" | "context">;
130
- interface UpdateOneOrAddResult<T> {
131
- data: T;
132
- type: "added" | "updated";
133
- }
134
- interface ToggleOneResult<T> {
135
- data: T;
136
- type: "added" | "removed";
137
- }
138
- }
139
- export interface UpdateOneOrAdd<T> {
140
- add_arg?: Arg<T>;
141
- id_gen?: boolean;
142
- context?: VContext;
143
- }
144
- export interface ValtheraCompatible {
145
- c<T = Data>(collection: string): Collection<T>;
146
- getCollections(): Promise<string[]>;
147
- ensureCollection(collection: string): Promise<boolean>;
148
- issetCollection(collection: string): Promise<boolean>;
149
- add<T = Data>(query: VQueryT.Add<T>): Promise<T>;
150
- find<T = Data>(query: VQueryT.Find<T>): Promise<T[]>;
151
- findOne<T = Data>(query: VQueryT.FindOne<T>): Promise<T | null>;
152
- update<T = Data>(query: VQueryT.Update<T>): Promise<T[]>;
153
- updateOne<T = Data>(query: VQueryT.Update<T>): Promise<T | null>;
154
- remove<T = Data>(query: VQueryT.Remove<T>): Promise<T[]>;
155
- removeOne<T = Data>(query: VQueryT.Remove<T>): Promise<T | null>;
156
- removeCollection(collection: string): Promise<boolean>;
157
- updateOneOrAdd<T = Data>(query: VQueryT.UpdateOneOrAdd<T>): Promise<VQueryT.UpdateOneOrAddResult<T>>;
158
- toggleOne<T = Data>(query: VQueryT.ToggleOne<T>): Promise<VQueryT.ToggleOneResult<T>>;
159
- }
160
- declare class Collection<D = Data> {
161
- db: ValtheraCompatible;
94
+ export declare interface IndexDefinition {
162
95
  collection: string;
163
- constructor(db: ValtheraCompatible, collection: string);
164
- add(data: Arg<D>, id_gen: false): Promise<D>;
165
- add(data: Arg<D>, id_gen?: true): Promise<D & {
166
- _id: string;
167
- }>;
168
- find(search?: Search<D>, options?: DbFindOpts<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D[]>;
169
- findOne(search?: Search<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D>;
170
- update(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D[]>;
171
- updateOne(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D | null>;
172
- remove(search: Search<D>, context?: VContext): Promise<D[]>;
173
- removeOne(search: Search<D>, context?: VContext): Promise<D | null>;
174
- updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<VQueryT.UpdateOneOrAddResult<D>>;
175
- toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<VQueryT.ToggleOneResult<D>>;
96
+ fields: string[];
97
+ opts?: IndexOpts;
98
+ }
99
+ export declare interface IndexOpts {
100
+ unique?: boolean;
101
+ name?: string;
176
102
  }
177
- declare namespace RelationTypes {
103
+ export declare type JSPrimitiveType = "string" | "number" | "boolean" | "bigint" | "symbol" | "undefined" | "function" | "object";
104
+ export declare type KeysMatching<T, V, C = V> = {
105
+ [K in keyof T]-?: T[K] extends C ? K : never;
106
+ }[keyof T];
107
+ export declare type LogicalOperators<T = any> = {
108
+ $and?: Array<SearchOptions<T>>;
109
+ $or?: Array<SearchOptions<T>>;
110
+ $not?: SearchOptions<T>;
111
+ };
112
+ export declare type NestedValue<T, V, C = V> = {
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;
114
+ };
115
+ export declare type ObjectUpdater<T = any> = {
116
+ $merge?: NestedValue<T, any>;
117
+ $deepMerge?: NestedValue<T, any>;
118
+ };
119
+ export declare type OtherOperators<T = any> = {
120
+ $subset?: DeepPartial<T>;
121
+ };
122
+ export declare type PredefinedSearchOperators<T = any> = LogicalOperators<T> & ComparisonOperators<T> & TypeAndExistenceOperators<T> & ArrayOperators<T> & StringOperators<T> & OtherOperators<T>;
123
+ export declare namespace RelationTypes {
178
124
  type Path = [
179
125
  string,
180
126
  string
@@ -193,7 +139,7 @@ declare namespace RelationTypes {
193
139
  as?: string;
194
140
  select?: string[];
195
141
  dbFindOpts?: DbFindOpts;
196
- type?: "1" | "11" | "1n" | "nm";
142
+ type?: "1" | "11" | "1n" | "nm" | "n1";
197
143
  relations?: Relation;
198
144
  through?: {
199
145
  table: string;
@@ -203,7 +149,72 @@ declare namespace RelationTypes {
203
149
  };
204
150
  }
205
151
  }
206
- export interface VQL_OP_Find<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> = {
156
+ $regex?: NestedValue<T, RegExp | string, string>;
157
+ $startsWith?: NestedValue<T, string, string>;
158
+ $endsWith?: NestedValue<T, string, string>;
159
+ $iStartsWith?: NestedValue<T, string, string>;
160
+ $iEndsWith?: NestedValue<T, string, string>;
161
+ };
162
+ export declare interface TransactionHandle {
163
+ id: string;
164
+ _adapterData?: unknown;
165
+ }
166
+ export declare type TypeAndExistenceOperators<T = any> = {
167
+ $exists?: NestedValue<T, boolean, any>;
168
+ $type?: NestedValue<T, JSPrimitiveType, any>;
169
+ };
170
+ export declare interface UpdateOneOrAdd<T> {
171
+ add_arg?: Arg<T>;
172
+ id_gen?: boolean;
173
+ context?: VContext;
174
+ }
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 {
179
+ c<T = Data>(collection: string): Collection<T>;
180
+ getCollections(): Promise<string[]>;
181
+ ensureCollection(collection: string): Promise<boolean>;
182
+ issetCollection(collection: string): Promise<boolean>;
183
+ add<T = Data>(query: VQueryT.Add<T>): Promise<T>;
184
+ find<T = Data>(query: VQueryT.Find<T>): Promise<T[]>;
185
+ findOne<T = Data>(query: VQueryT.FindOne<T>): Promise<T | null>;
186
+ update<T = Data>(query: VQueryT.Update<T>): Promise<T[]>;
187
+ updateOne<T = Data>(query: VQueryT.Update<T>): Promise<T | null>;
188
+ remove<T = Data>(query: VQueryT.Remove<T>): Promise<T[]>;
189
+ removeOne<T = Data>(query: VQueryT.Remove<T>): Promise<T | null>;
190
+ removeCollection(collection: string): Promise<boolean>;
191
+ updateOneOrAdd<T = Data>(query: VQueryT.UpdateOneOrAdd<T>): Promise<VQueryT.UpdateOneOrAddResult<T>>;
192
+ toggleOne<T = Data>(query: VQueryT.ToggleOne<T>): Promise<VQueryT.ToggleOneResult<T>>;
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[]>;
197
+ }
198
+ export declare type ValueUpdater<T = any> = {
199
+ $inc?: NestedValue<T, number>;
200
+ $dec?: NestedValue<T, number>;
201
+ $unset?: NestedValue<T, any>;
202
+ $rename?: NestedValue<T, any>;
203
+ $set?: NestedValue<T, any>;
204
+ };
205
+ export declare interface VContext {
206
+ [key: string]: any;
207
+ }
208
+ export declare type VQL_Fields = Record<string, boolean | number> | string[];
209
+ export declare interface VQL_OP_Add<T = any> {
210
+ collection: string;
211
+ data?: Arg<T>;
212
+ id_gen?: boolean;
213
+ }
214
+ export declare interface VQL_OP_CollectionOperation {
215
+ collection: string;
216
+ }
217
+ export declare interface VQL_OP_Find<T = any> {
207
218
  collection: string;
208
219
  search?: Search<T>;
209
220
  limit?: number;
@@ -211,43 +222,43 @@ export interface VQL_OP_Find<T = any> {
211
222
  options?: DbFindOpts<T>;
212
223
  searchOpts?: FindOpts<T>;
213
224
  }
214
- export interface VQL_OP_FindOne<T = any> {
225
+ export declare interface VQL_OP_FindOne<T = any> {
215
226
  collection: string;
216
227
  search: Search<T>;
217
228
  select?: VQL_Fields;
218
229
  searchOpts?: FindOpts<T>;
219
230
  }
220
- export interface VQL_OP_Add<T = any> {
231
+ export declare interface VQL_OP_Remove<T = any> {
221
232
  collection: string;
222
- data: Arg<T>;
223
- id_gen?: boolean;
233
+ search: Search<T>;
234
+ select?: VQL_Fields;
224
235
  }
225
- export interface VQL_OP_Update<T = any> {
236
+ export declare interface VQL_OP_ToggleOne<T = any> {
226
237
  collection: string;
227
238
  search: Search<T>;
228
- updater: UpdaterArg<T>;
239
+ data?: Arg<T>;
240
+ select?: VQL_Fields;
229
241
  }
230
- export interface VQL_OP_Remove<T = any> {
242
+ export declare interface VQL_OP_Update<T = any> {
231
243
  collection: string;
232
244
  search: Search<T>;
245
+ updater: UpdaterArg<T>;
246
+ select?: VQL_Fields;
233
247
  }
234
- export interface VQL_OP_UpdateOneOrAdd<T = any> {
248
+ export declare interface VQL_OP_UpdateOneOrAdd<T = any> {
235
249
  collection: string;
236
250
  search: Search<T>;
237
251
  updater: UpdaterArg<T>;
238
252
  add_arg?: Arg<T>;
239
253
  id_gen?: boolean;
254
+ select?: VQL_Fields;
240
255
  }
241
- export interface VQL_OP_ToggleOne<T = any> {
242
- collection: string;
243
- search: Search<T>;
244
- data?: Arg<T>;
245
- }
246
- export interface VQL_OP_CollectionOperation {
247
- collection: string;
256
+ export declare type VQL_Query<T = any> = (VQL_Query_CRUD<T> | VQL_Query_Relation) & VQL_Var;
257
+ export declare interface VQL_Query_CRUD<T = any> {
258
+ db: string;
259
+ d: VQL_Query_CRUD_Data<T>;
248
260
  }
249
- export type VQL_Fields = Record<string, boolean | number> | string[];
250
- export type VQL_Query_CRUD_Data<T = any> = {
261
+ export declare type VQL_Query_CRUD_Data<T = any> = {
251
262
  find: VQL_OP_Find<T>;
252
263
  } | {
253
264
  findOne: VQL_OP_FindOne<T>;
@@ -276,12 +287,8 @@ export type VQL_Query_CRUD_Data<T = any> = {
276
287
  } | {
277
288
  getCollections: {};
278
289
  };
279
- export type VQL_Query_CRUD_Keys = VQL_Query_CRUD_Data extends infer U ? U extends Record<string, unknown> ? keyof U : never : never;
280
- export interface VQL_Query_CRUD<T = any> {
281
- db: string;
282
- d: VQL_Query_CRUD_Data<T>;
283
- }
284
- export interface VQL_Query_Relation {
290
+ export declare type VQL_Query_CRUD_Keys = VQL_Query_CRUD_Data extends infer U ? U extends Record<string, unknown> ? keyof U : never : never;
291
+ export declare interface VQL_Query_Relation {
285
292
  r: {
286
293
  path: RelationTypes.Path;
287
294
  search: Search;
@@ -291,18 +298,98 @@ export interface VQL_Query_Relation {
291
298
  select?: RelationTypes.FieldPath[] | Record<string, any>;
292
299
  };
293
300
  }
294
- export interface VQL_Var {
301
+ export declare interface VQL_Var {
295
302
  var?: {
296
303
  [k: string]: any;
297
304
  };
298
305
  }
299
- export type VQL_Query<T = any> = (VQL_Query_CRUD<T> | VQL_Query_Relation) & VQL_Var;
300
- export type VQLUQ<T = any> = VQL_Query<T> | string | {
301
- query: string;
302
- } & VQL_Var;
303
- export interface VQLError {
306
+ export declare interface VQLError {
304
307
  err: true;
305
308
  msg: string;
306
309
  c: number;
307
310
  }
311
+ export declare type VQLUQ<T = any> = VQL_Query<T> | string | ({
312
+ query: string;
313
+ } & VQL_Var);
314
+ export declare interface VQuery<T = Data, AllowFn extends boolean = true> {
315
+ collection?: string;
316
+ search?: Search<T, AllowFn>;
317
+ context?: VContext;
318
+ dbFindOpts?: DbFindOpts<T>;
319
+ findOpts?: FindOpts<T>;
320
+ data?: Arg<T>;
321
+ datas?: Arg<T>[];
322
+ id_gen?: boolean;
323
+ add_arg?: Arg<T>;
324
+ updater?: Updater<T, AllowFn>;
325
+ control?: VQuery_Control;
326
+ transaction?: TransactionHandle;
327
+ index?: IndexDefinition;
328
+ }
329
+ export declare interface VQuery_Control {
330
+ }
331
+ export declare namespace VQueryT {
332
+ type QueryBase<T = Data> = {
333
+ collection: string;
334
+ control?: VQuery_Control;
335
+ transaction?: TransactionHandle;
336
+ };
337
+ type Add<T = Data> = QueryBase<T> & {
338
+ data: Arg<T>;
339
+ id_gen?: boolean;
340
+ };
341
+ type BulkAdd<T = Data> = QueryBase<T> & {
342
+ datas: Arg<T>[];
343
+ id_gen?: boolean;
344
+ };
345
+ type Find<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
346
+ search?: Search<T, AllowFn>;
347
+ findOpts?: FindOpts<T>;
348
+ dbFindOpts?: DbFindOpts<T>;
349
+ context?: VContext;
350
+ };
351
+ type FindOne<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
352
+ search: Search<T, AllowFn>;
353
+ findOpts?: FindOpts<T>;
354
+ context?: VContext;
355
+ };
356
+ type Update<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
357
+ search: Search<T, AllowFn>;
358
+ updater: Updater<T, AllowFn>;
359
+ context?: VContext;
360
+ };
361
+ type Remove<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
362
+ search: Search<T, AllowFn>;
363
+ context?: VContext;
364
+ };
365
+ type UpdateOneOrAdd<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
366
+ search: Search<T, AllowFn>;
367
+ updater: Updater<T, AllowFn>;
368
+ add_arg?: Arg<T>;
369
+ id_gen?: boolean;
370
+ context?: VContext;
371
+ };
372
+ type ToggleOne<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
373
+ search: Search<T, AllowFn>;
374
+ data: Arg<T>;
375
+ context?: VContext;
376
+ };
377
+ interface UpdateOneOrAddResult<T> {
378
+ data: T;
379
+ type: "added" | "updated";
380
+ }
381
+ interface ToggleOneResult<T> {
382
+ data: T;
383
+ type: "added" | "removed";
384
+ }
385
+ type CreateIndex<T = Data> = QueryBase<T> & {
386
+ index: IndexDefinition;
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
+ };
394
+ }
308
395
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql-client",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "VQL Client",
@@ -26,8 +26,9 @@
26
26
  "license": "MIT",
27
27
  "type": "module",
28
28
  "devDependencies": {
29
+ "@wxn0brp/biome": "*",
29
30
  "esbuild": "^0.28",
30
- "typescript": "^6"
31
+ "typescript": "^7"
31
32
  },
32
33
  "files": [
33
34
  "dist"