@wxn0brp/vql-client 0.2.13 → 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 +2 -1
- package/dist/index.js +6 -7
- package/dist/min.js +1 -1
- package/dist/vql.d.ts +237 -170
- package/package.json +3 -2
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:
|
|
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
|
|
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
|
-
|
|
2
|
-
[
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
$
|
|
16
|
-
$
|
|
17
|
-
$
|
|
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
|
-
|
|
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,144 +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
|
-
|
|
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
|
-
|
|
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> {
|
|
62
|
+
declare interface DbFindOpts<T = any> {
|
|
91
63
|
reverse?: boolean;
|
|
92
64
|
limit?: number;
|
|
93
65
|
offset?: number;
|
|
94
|
-
sortBy?: KeysMatching<T, any
|
|
66
|
+
sortBy?: KeysMatching<T, any> | {
|
|
67
|
+
field: KeysMatching<T, any>;
|
|
68
|
+
asc?: boolean;
|
|
69
|
+
}[];
|
|
95
70
|
sortAsc?: boolean;
|
|
96
71
|
min?: Record<string, KeysMatching<T, number>>;
|
|
97
72
|
max?: Record<string, KeysMatching<T, number>>;
|
|
98
73
|
avg?: Record<string, KeysMatching<T, number>>;
|
|
74
|
+
sum?: Record<string, KeysMatching<T, number>>;
|
|
75
|
+
distinct?: KeysMatching<T, any>;
|
|
99
76
|
groupBy?: KeysMatching<T, any> | KeysMatching<T, any>[];
|
|
100
77
|
count?: Record<string, string>;
|
|
101
78
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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>[];
|
|
105
86
|
transform?: Function;
|
|
106
87
|
}
|
|
107
|
-
|
|
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;
|
|
88
|
+
declare interface IndexDefinition {
|
|
162
89
|
collection: string;
|
|
163
|
-
|
|
164
|
-
|
|
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>>;
|
|
90
|
+
fields: string[];
|
|
91
|
+
opts?: IndexOpts;
|
|
176
92
|
}
|
|
93
|
+
declare interface IndexOpts {
|
|
94
|
+
unique?: boolean;
|
|
95
|
+
name?: string;
|
|
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>;
|
|
177
117
|
declare namespace RelationTypes {
|
|
178
118
|
type Path = [
|
|
179
119
|
string,
|
|
@@ -193,7 +133,7 @@ declare namespace RelationTypes {
|
|
|
193
133
|
as?: string;
|
|
194
134
|
select?: string[];
|
|
195
135
|
dbFindOpts?: DbFindOpts;
|
|
196
|
-
type?: "1" | "11" | "1n" | "nm";
|
|
136
|
+
type?: "1" | "11" | "1n" | "nm" | "n1";
|
|
197
137
|
relations?: Relation;
|
|
198
138
|
through?: {
|
|
199
139
|
table: string;
|
|
@@ -203,7 +143,69 @@ declare namespace RelationTypes {
|
|
|
203
143
|
};
|
|
204
144
|
}
|
|
205
145
|
}
|
|
206
|
-
|
|
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> {
|
|
207
209
|
collection: string;
|
|
208
210
|
search?: Search<T>;
|
|
209
211
|
limit?: number;
|
|
@@ -211,43 +213,43 @@ export interface VQL_OP_Find<T = any> {
|
|
|
211
213
|
options?: DbFindOpts<T>;
|
|
212
214
|
searchOpts?: FindOpts<T>;
|
|
213
215
|
}
|
|
214
|
-
export interface VQL_OP_FindOne<T = any> {
|
|
216
|
+
export declare interface VQL_OP_FindOne<T = any> {
|
|
215
217
|
collection: string;
|
|
216
218
|
search: Search<T>;
|
|
217
219
|
select?: VQL_Fields;
|
|
218
220
|
searchOpts?: FindOpts<T>;
|
|
219
221
|
}
|
|
220
|
-
export interface
|
|
222
|
+
export declare interface VQL_OP_Remove<T = any> {
|
|
221
223
|
collection: string;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
+
search: Search<T>;
|
|
225
|
+
select?: VQL_Fields;
|
|
224
226
|
}
|
|
225
|
-
export interface
|
|
227
|
+
export declare interface VQL_OP_ToggleOne<T = any> {
|
|
226
228
|
collection: string;
|
|
227
229
|
search: Search<T>;
|
|
228
|
-
|
|
230
|
+
data?: Arg<T>;
|
|
231
|
+
select?: VQL_Fields;
|
|
229
232
|
}
|
|
230
|
-
export interface
|
|
233
|
+
export declare interface VQL_OP_Update<T = any> {
|
|
231
234
|
collection: string;
|
|
232
235
|
search: Search<T>;
|
|
236
|
+
updater: UpdaterArg<T>;
|
|
237
|
+
select?: VQL_Fields;
|
|
233
238
|
}
|
|
234
|
-
export interface VQL_OP_UpdateOneOrAdd<T = any> {
|
|
239
|
+
export declare interface VQL_OP_UpdateOneOrAdd<T = any> {
|
|
235
240
|
collection: string;
|
|
236
241
|
search: Search<T>;
|
|
237
242
|
updater: UpdaterArg<T>;
|
|
238
243
|
add_arg?: Arg<T>;
|
|
239
244
|
id_gen?: boolean;
|
|
245
|
+
select?: VQL_Fields;
|
|
240
246
|
}
|
|
241
|
-
export
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
export interface VQL_OP_CollectionOperation {
|
|
247
|
-
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>;
|
|
248
251
|
}
|
|
249
|
-
export type
|
|
250
|
-
export type VQL_Query_CRUD_Data<T = any> = {
|
|
252
|
+
export declare type VQL_Query_CRUD_Data<T = any> = {
|
|
251
253
|
find: VQL_OP_Find<T>;
|
|
252
254
|
} | {
|
|
253
255
|
findOne: VQL_OP_FindOne<T>;
|
|
@@ -276,12 +278,8 @@ export type VQL_Query_CRUD_Data<T = any> = {
|
|
|
276
278
|
} | {
|
|
277
279
|
getCollections: {};
|
|
278
280
|
};
|
|
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
|
|
281
|
-
db: string;
|
|
282
|
-
d: VQL_Query_CRUD_Data<T>;
|
|
283
|
-
}
|
|
284
|
-
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 {
|
|
285
283
|
r: {
|
|
286
284
|
path: RelationTypes.Path;
|
|
287
285
|
search: Search;
|
|
@@ -291,18 +289,87 @@ export interface VQL_Query_Relation {
|
|
|
291
289
|
select?: RelationTypes.FieldPath[] | Record<string, any>;
|
|
292
290
|
};
|
|
293
291
|
}
|
|
294
|
-
export interface VQL_Var {
|
|
292
|
+
export declare interface VQL_Var {
|
|
295
293
|
var?: {
|
|
296
294
|
[k: string]: any;
|
|
297
295
|
};
|
|
298
296
|
}
|
|
299
|
-
export
|
|
300
|
-
export type VQLUQ<T = any> = VQL_Query<T> | string | {
|
|
301
|
-
query: string;
|
|
302
|
-
} & VQL_Var;
|
|
303
|
-
export interface VQLError {
|
|
297
|
+
export declare interface VQLError {
|
|
304
298
|
err: true;
|
|
305
299
|
msg: string;
|
|
306
300
|
c: number;
|
|
307
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
|
+
}
|
|
308
375
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/vql-client",
|
|
3
|
-
"version": "0.2.
|
|
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": "^
|
|
31
|
+
"typescript": "^7"
|
|
31
32
|
},
|
|
32
33
|
"files": [
|
|
33
34
|
"dist"
|