@wxn0brp/vql-client 0.2.12 → 0.2.14

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,42 @@
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
+ declare type Arg<T = any> = {
2
+ [K in keyof T]?: any;
3
+ } & Record<string, any>;
4
+ 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
+ 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
+ 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
+ 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>;
30
+ update(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D[]>;
31
+ updateOne(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D | null>;
32
+ remove(search: Search<D>, context?: VContext): Promise<D[]>;
33
+ removeOne(search: Search<D>, context?: VContext): Promise<D | null>;
34
+ updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<VQueryT.UpdateOneOrAddResult<D>>;
35
+ toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<VQueryT.ToggleOneResult<D>>;
36
+ createIndex(fields: string[], opts?: IndexOpts): Promise<void>;
37
+ }
38
+ declare type ComparisonOperators<T = any> = {
39
+ $ne?: NestedValue<T, any>;
20
40
  $gt?: NestedValue<T, number, number>;
21
41
  $lt?: NestedValue<T, number, number>;
22
42
  $gte?: NestedValue<T, number, number>;
@@ -36,155 +56,64 @@ export type ComparisonOperators<T = any> = {
36
56
  $idGte?: NestedValue<T, string | number, string | number>;
37
57
  $idLte?: NestedValue<T, string | number, string | number>;
38
58
  };
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 {
59
+ declare interface Data {
63
60
  [key: string]: any;
64
61
  }
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) => boolean;
88
- export type Search<T = any> = SearchOptions<T> | SearchFunc<T>;
89
- export type Updater<T = any> = UpdaterArg<T> | UpdaterArg<T>[] | UpdaterFunc<T>;
90
- export interface UpdateOneOrAdd<T> {
91
- add_arg?: Arg<T>;
92
- id_gen?: boolean;
93
- context?: VContext;
94
- }
95
- export interface VQuery_Control {
96
- }
97
- export interface VQuery<T = Data> {
98
- collection?: string;
99
- search?: Search<T>;
100
- context?: VContext;
101
- dbFindOpts?: DbFindOpts<T>;
102
- findOpts?: FindOpts<T>;
103
- data?: Arg<T>;
104
- id_gen?: boolean;
105
- add_arg?: Arg<T>;
106
- updater?: Updater<T>;
107
- control?: VQuery_Control;
108
- }
109
- export declare namespace VQueryT {
110
- type QueryBase<T = Data> = Required<Pick<VQuery<T>, "collection" | "search">> & Pick<VQuery<T>, "control">;
111
- type Add<T = Data> = Required<Pick<VQuery<T>, "data" | "collection">> & Pick<VQuery<T>, "id_gen" | "control">;
112
- type Find<T = Data> = Omit<QueryBase, "search"> & Pick<VQuery<T>, "search"> & Pick<VQuery<T>, "findOpts" | "dbFindOpts" | "context">;
113
- type FindOne<T = Data> = QueryBase & Pick<VQuery<T>, "findOpts" | "context">;
114
- type Update<T = Data> = QueryBase & Required<Pick<VQuery<T>, "updater">> & Pick<VQuery<T>, "context">;
115
- type Remove<T = Data> = QueryBase & Pick<VQuery<T>, "context">;
116
- type UpdateOneOrAdd<T = Data> = QueryBase & Update & Pick<VQuery<T>, "add_arg" | "id_gen">;
117
- type ToggleOne<T = Data> = QueryBase & Pick<VQuery<T>, "data" | "context">;
118
- interface UpdateOneOrAddResult<T> {
119
- data: T;
120
- type: "added" | "updated";
121
- }
122
- interface ToggleOneResult<T> {
123
- data: T;
124
- type: "added" | "removed";
125
- }
126
- }
127
- export type QueryBase<T = Data> = VQueryT.QueryBase<T>;
128
- export type AddQuery<T = Data> = VQueryT.Add<T>;
129
- export type FindQuery<T = Data> = VQueryT.Find<T>;
130
- export type FindOneQuery<T = Data> = VQueryT.FindOne<T>;
131
- export type UpdateQuery<T = Data> = VQueryT.Update<T>;
132
- export type RemoveQuery<T = Data> = VQueryT.Remove<T>;
133
- export type UpdateOneOrAddQuery<T = Data> = VQueryT.UpdateOneOrAdd<T>;
134
- export type ToggleOneQuery<T = Data> = VQueryT.ToggleOne<T>;
135
- export type UpdateOneOrAddResult<T> = VQueryT.UpdateOneOrAddResult<T>;
136
- export type ToggleOneResult<T> = VQueryT.ToggleOneResult<T>;
137
- export interface DbFindOpts<T = any> {
62
+ declare interface DbFindOpts<T = any> {
138
63
  reverse?: boolean;
139
64
  limit?: number;
140
65
  offset?: number;
141
- sortBy?: KeysMatching<T, any>;
66
+ sortBy?: KeysMatching<T, any> | {
67
+ field: KeysMatching<T, any>;
68
+ asc?: boolean;
69
+ }[];
142
70
  sortAsc?: boolean;
71
+ min?: Record<string, KeysMatching<T, number>>;
72
+ max?: Record<string, KeysMatching<T, number>>;
73
+ avg?: Record<string, KeysMatching<T, number>>;
74
+ sum?: Record<string, KeysMatching<T, number>>;
75
+ distinct?: KeysMatching<T, any>;
76
+ groupBy?: KeysMatching<T, any> | KeysMatching<T, any>[];
77
+ count?: Record<string, string>;
143
78
  }
144
- export interface FindOpts<T = any> {
145
- select?: KeysMatching<T, any>[];
146
- exclude?: KeysMatching<T, any>[];
79
+ declare type DeepPartial<T> = {
80
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
81
+ };
82
+ declare type FieldPath<T = any> = KeysMatching<T, any> | (string & {}) | string[];
83
+ declare interface FindOpts<T = any> {
84
+ select?: FieldPath<T>[];
85
+ exclude?: FieldPath<T>[];
147
86
  transform?: Function;
148
87
  }
149
- declare class Collection<D = Data> {
150
- db: ValtheraCompatible;
88
+ declare interface IndexDefinition {
151
89
  collection: string;
152
- constructor(db: ValtheraCompatible, collection: string);
153
- add(data: Arg<D>, id_gen: false): Promise<D>;
154
- add(data: Arg<D>, id_gen?: true): Promise<D & {
155
- _id: string;
156
- }>;
157
- find(search?: Search<D>, options?: DbFindOpts<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D[]>;
158
- findOne(search?: Search<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D>;
159
- update(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D[]>;
160
- updateOne(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D | null>;
161
- remove(search: Search<D>, context?: VContext): Promise<D[]>;
162
- removeOne(search: Search<D>, context?: VContext): Promise<D | null>;
163
- updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<VQueryT.UpdateOneOrAddResult<D>>;
164
- toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<VQueryT.ToggleOneResult<D>>;
90
+ fields: string[];
91
+ opts?: IndexOpts;
165
92
  }
166
- export interface ValtheraCompatible {
167
- c<T = Data>(collection: string): Collection<T>;
168
- getCollections(): Promise<string[]>;
169
- ensureCollection(collection: string): Promise<boolean>;
170
- issetCollection(collection: string): Promise<boolean>;
171
- add<T = Data>(query: VQueryT.Add<T>): Promise<T>;
172
- find<T = Data>(query: VQueryT.Find<T>): Promise<T[]>;
173
- findOne<T = Data>(query: VQueryT.FindOne<T>): Promise<T | null>;
174
- update<T = Data>(query: VQueryT.Update<T>): Promise<T[]>;
175
- updateOne<T = Data>(query: VQueryT.Update<T>): Promise<T | null>;
176
- remove<T = Data>(query: VQueryT.Remove<T>): Promise<T[]>;
177
- removeOne<T = Data>(query: VQueryT.Remove<T>): Promise<T | null>;
178
- removeCollection(collection: string): Promise<boolean>;
179
- updateOneOrAdd<T = Data>(query: VQueryT.UpdateOneOrAdd<T>): Promise<VQueryT.UpdateOneOrAddResult<T>>;
180
- toggleOne<T = Data>(query: VQueryT.ToggleOne<T>): Promise<VQueryT.ToggleOneResult<T>>;
181
- }
182
- export interface VQuery_Control {
183
- dir?: {
184
- lastFileNum?: number;
185
- sortedFiles?: string[];
186
- };
93
+ declare interface IndexOpts {
94
+ unique?: boolean;
95
+ name?: string;
187
96
  }
97
+ declare type JSPrimitiveType = "string" | "number" | "boolean" | "bigint" | "symbol" | "undefined" | "function" | "object";
98
+ declare type KeysMatching<T, V, C = V> = {
99
+ [K in keyof T]-?: T[K] extends C ? K : never;
100
+ }[keyof T];
101
+ declare type LogicalOperators<T = any> = {
102
+ $and?: Array<SearchOptions<T>>;
103
+ $or?: Array<SearchOptions<T>>;
104
+ $not?: SearchOptions<T>;
105
+ };
106
+ declare type NestedValue<T, V, C = V> = {
107
+ [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
+ };
109
+ declare type ObjectUpdater<T = any> = {
110
+ $merge?: NestedValue<T, any>;
111
+ $deepMerge?: NestedValue<T, any>;
112
+ };
113
+ declare type OtherOperators<T = any> = {
114
+ $subset?: DeepPartial<T>;
115
+ };
116
+ declare type PredefinedSearchOperators<T = any> = LogicalOperators<T> & ComparisonOperators<T> & TypeAndExistenceOperators<T> & ArrayOperators<T> & StringOperators<T> & OtherOperators<T>;
188
117
  declare namespace RelationTypes {
189
118
  type Path = [
190
119
  string,
@@ -204,7 +133,7 @@ declare namespace RelationTypes {
204
133
  as?: string;
205
134
  select?: string[];
206
135
  dbFindOpts?: DbFindOpts;
207
- type?: "1" | "11" | "1n" | "nm";
136
+ type?: "1" | "11" | "1n" | "nm" | "n1";
208
137
  relations?: Relation;
209
138
  through?: {
210
139
  table: string;
@@ -214,7 +143,69 @@ declare namespace RelationTypes {
214
143
  };
215
144
  }
216
145
  }
217
- export interface VQL_OP_Find<T = any> {
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> = {
150
+ $regex?: NestedValue<T, RegExp | string, string>;
151
+ $startsWith?: NestedValue<T, string, string>;
152
+ $endsWith?: NestedValue<T, string, string>;
153
+ $iStartsWith?: NestedValue<T, string, string>;
154
+ $iEndsWith?: NestedValue<T, string, string>;
155
+ };
156
+ declare interface TransactionHandle {
157
+ id: string;
158
+ _adapterData?: unknown;
159
+ }
160
+ declare type TypeAndExistenceOperators<T = any> = {
161
+ $exists?: NestedValue<T, boolean, any>;
162
+ $type?: NestedValue<T, JSPrimitiveType, any>;
163
+ };
164
+ declare interface UpdateOneOrAdd<T> {
165
+ add_arg?: Arg<T>;
166
+ id_gen?: boolean;
167
+ context?: VContext;
168
+ }
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 {
173
+ c<T = Data>(collection: string): Collection<T>;
174
+ getCollections(): Promise<string[]>;
175
+ ensureCollection(collection: string): Promise<boolean>;
176
+ issetCollection(collection: string): Promise<boolean>;
177
+ add<T = Data>(query: VQueryT.Add<T>): Promise<T>;
178
+ find<T = Data>(query: VQueryT.Find<T>): Promise<T[]>;
179
+ findOne<T = Data>(query: VQueryT.FindOne<T>): Promise<T | null>;
180
+ update<T = Data>(query: VQueryT.Update<T>): Promise<T[]>;
181
+ updateOne<T = Data>(query: VQueryT.Update<T>): Promise<T | null>;
182
+ remove<T = Data>(query: VQueryT.Remove<T>): Promise<T[]>;
183
+ removeOne<T = Data>(query: VQueryT.Remove<T>): Promise<T | null>;
184
+ removeCollection(collection: string): Promise<boolean>;
185
+ updateOneOrAdd<T = Data>(query: VQueryT.UpdateOneOrAdd<T>): Promise<VQueryT.UpdateOneOrAddResult<T>>;
186
+ toggleOne<T = Data>(query: VQueryT.ToggleOne<T>): Promise<VQueryT.ToggleOneResult<T>>;
187
+ createIndex(collection: string, fields: string[], opts?: IndexOpts): Promise<void>;
188
+ }
189
+ declare type ValueUpdater<T = any> = {
190
+ $inc?: NestedValue<T, number>;
191
+ $dec?: NestedValue<T, number>;
192
+ $unset?: NestedValue<T, any>;
193
+ $rename?: NestedValue<T, any>;
194
+ $set?: NestedValue<T, any>;
195
+ };
196
+ declare interface VContext {
197
+ [key: string]: any;
198
+ }
199
+ export declare type VQL_Fields = Record<string, boolean | number> | string[];
200
+ export declare interface VQL_OP_Add<T = any> {
201
+ collection: string;
202
+ data?: Arg<T>;
203
+ id_gen?: boolean;
204
+ }
205
+ export declare interface VQL_OP_CollectionOperation {
206
+ collection: string;
207
+ }
208
+ export declare interface VQL_OP_Find<T = any> {
218
209
  collection: string;
219
210
  search?: Search<T>;
220
211
  limit?: number;
@@ -222,43 +213,43 @@ export interface VQL_OP_Find<T = any> {
222
213
  options?: DbFindOpts<T>;
223
214
  searchOpts?: FindOpts<T>;
224
215
  }
225
- export interface VQL_OP_FindOne<T = any> {
216
+ export declare interface VQL_OP_FindOne<T = any> {
226
217
  collection: string;
227
218
  search: Search<T>;
228
219
  select?: VQL_Fields;
229
220
  searchOpts?: FindOpts<T>;
230
221
  }
231
- export interface VQL_OP_Add<T = any> {
222
+ export declare interface VQL_OP_Remove<T = any> {
232
223
  collection: string;
233
- data: Arg<T>;
234
- id_gen?: boolean;
224
+ search: Search<T>;
225
+ select?: VQL_Fields;
235
226
  }
236
- export interface VQL_OP_Update<T = any> {
227
+ export declare interface VQL_OP_ToggleOne<T = any> {
237
228
  collection: string;
238
229
  search: Search<T>;
239
- updater: UpdaterArg<T>;
230
+ data?: Arg<T>;
231
+ select?: VQL_Fields;
240
232
  }
241
- export interface VQL_OP_Remove<T = any> {
233
+ export declare interface VQL_OP_Update<T = any> {
242
234
  collection: string;
243
235
  search: Search<T>;
236
+ updater: UpdaterArg<T>;
237
+ select?: VQL_Fields;
244
238
  }
245
- export interface VQL_OP_UpdateOneOrAdd<T = any> {
239
+ export declare interface VQL_OP_UpdateOneOrAdd<T = any> {
246
240
  collection: string;
247
241
  search: Search<T>;
248
242
  updater: UpdaterArg<T>;
249
243
  add_arg?: Arg<T>;
250
244
  id_gen?: boolean;
245
+ select?: VQL_Fields;
251
246
  }
252
- export interface VQL_OP_ToggleOne<T = any> {
253
- collection: string;
254
- search: Search<T>;
255
- data?: Arg<T>;
256
- }
257
- export interface VQL_OP_CollectionOperation {
258
- collection: string;
247
+ export declare type VQL_Query<T = any> = (VQL_Query_CRUD<T> | VQL_Query_Relation) & VQL_Var;
248
+ export declare interface VQL_Query_CRUD<T = any> {
249
+ db: string;
250
+ d: VQL_Query_CRUD_Data<T>;
259
251
  }
260
- export type VQL_Fields = Record<string, boolean | number> | string[];
261
- export type VQL_Query_CRUD_Data<T = any> = {
252
+ export declare type VQL_Query_CRUD_Data<T = any> = {
262
253
  find: VQL_OP_Find<T>;
263
254
  } | {
264
255
  findOne: VQL_OP_FindOne<T>;
@@ -287,12 +278,8 @@ export type VQL_Query_CRUD_Data<T = any> = {
287
278
  } | {
288
279
  getCollections: {};
289
280
  };
290
- export type VQL_Query_CRUD_Keys = VQL_Query_CRUD_Data extends infer U ? U extends Record<string, unknown> ? keyof U : never : never;
291
- export interface VQL_Query_CRUD<T = any> {
292
- db: string;
293
- d: VQL_Query_CRUD_Data<T>;
294
- }
295
- export interface VQL_Query_Relation {
281
+ export declare type VQL_Query_CRUD_Keys = VQL_Query_CRUD_Data extends infer U ? U extends Record<string, unknown> ? keyof U : never : never;
282
+ export declare interface VQL_Query_Relation {
296
283
  r: {
297
284
  path: RelationTypes.Path;
298
285
  search: Search;
@@ -302,18 +289,87 @@ export interface VQL_Query_Relation {
302
289
  select?: RelationTypes.FieldPath[] | Record<string, any>;
303
290
  };
304
291
  }
305
- export interface VQL_Var {
292
+ export declare interface VQL_Var {
306
293
  var?: {
307
294
  [k: string]: any;
308
295
  };
309
296
  }
310
- export type VQL_Query<T = any> = (VQL_Query_CRUD<T> | VQL_Query_Relation) & VQL_Var;
311
- export type VQLUQ<T = any> = VQL_Query<T> | string | {
312
- query: string;
313
- } & VQL_Var;
314
- export interface VQLError {
297
+ export declare interface VQLError {
315
298
  err: true;
316
299
  msg: string;
317
300
  c: number;
318
301
  }
302
+ export declare type VQLUQ<T = any> = VQL_Query<T> | string | ({
303
+ query: string;
304
+ } & VQL_Var);
305
+ export declare interface VQuery<T = Data, AllowFn extends boolean = true> {
306
+ collection?: string;
307
+ search?: Search<T, AllowFn>;
308
+ context?: VContext;
309
+ dbFindOpts?: DbFindOpts<T>;
310
+ findOpts?: FindOpts<T>;
311
+ data?: Arg<T>;
312
+ id_gen?: boolean;
313
+ add_arg?: Arg<T>;
314
+ updater?: Updater<T, AllowFn>;
315
+ control?: VQuery_Control;
316
+ transaction?: TransactionHandle;
317
+ index?: IndexDefinition;
318
+ }
319
+ export declare interface VQuery_Control {
320
+ }
321
+ export declare namespace VQueryT {
322
+ type QueryBase<T = Data> = {
323
+ collection: string;
324
+ control?: VQuery_Control;
325
+ transaction?: TransactionHandle;
326
+ };
327
+ type Add<T = Data> = QueryBase<T> & {
328
+ data: Arg<T>;
329
+ id_gen?: boolean;
330
+ };
331
+ type Find<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
332
+ search?: Search<T, AllowFn>;
333
+ findOpts?: FindOpts<T>;
334
+ dbFindOpts?: DbFindOpts<T>;
335
+ context?: VContext;
336
+ };
337
+ type FindOne<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
338
+ search: Search<T, AllowFn>;
339
+ findOpts?: FindOpts<T>;
340
+ context?: VContext;
341
+ };
342
+ type Update<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
343
+ search: Search<T, AllowFn>;
344
+ updater: Updater<T, AllowFn>;
345
+ context?: VContext;
346
+ };
347
+ type Remove<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
348
+ search: Search<T, AllowFn>;
349
+ context?: VContext;
350
+ };
351
+ type UpdateOneOrAdd<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
352
+ search: Search<T, AllowFn>;
353
+ updater: Updater<T, AllowFn>;
354
+ add_arg?: Arg<T>;
355
+ id_gen?: boolean;
356
+ context?: VContext;
357
+ };
358
+ type ToggleOne<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
359
+ search: Search<T, AllowFn>;
360
+ data: Arg<T>;
361
+ context?: VContext;
362
+ };
363
+ interface UpdateOneOrAddResult<T> {
364
+ data: T;
365
+ type: "added" | "updated";
366
+ }
367
+ interface ToggleOneResult<T> {
368
+ data: T;
369
+ type: "added" | "removed";
370
+ }
371
+ type CreateIndex<T = Data> = QueryBase<T> & {
372
+ index: IndexDefinition;
373
+ };
374
+ }
319
375
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql-client",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
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"