@wxn0brp/vql-client 0.2.3 → 0.2.5
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 +11 -3
- package/dist/index.js +18 -10
- package/dist/min.js +1 -1
- package/dist/vql.d.ts +17 -1
- package/package.json +14 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VQLUQ } from "./vql";
|
|
2
2
|
export type VQLResult<T = any> = Promise<T>;
|
|
3
|
-
export type VQLTransport = (query: VQLUQ) => VQLResult;
|
|
3
|
+
export type VQLTransport = (query: VQLUQ, fetchOptions?: FetchOptions) => VQLResult;
|
|
4
4
|
export interface VQLHooks {
|
|
5
5
|
onStart?: (query: VQLUQ, hookContext: any) => void;
|
|
6
6
|
onEnd?: (query: VQLUQ, durationMs: number, result: any, hookContext: any) => void;
|
|
@@ -8,10 +8,18 @@ export interface VQLHooks {
|
|
|
8
8
|
}
|
|
9
9
|
export interface Config {
|
|
10
10
|
transport?: VQLTransport;
|
|
11
|
+
fetchImplementation: typeof fetch;
|
|
11
12
|
hooks?: VQLHooks;
|
|
12
13
|
url?: string;
|
|
13
14
|
body?: Record<string, any>;
|
|
15
|
+
headers?: Record<string, any>;
|
|
16
|
+
hookContext?: any;
|
|
17
|
+
}
|
|
18
|
+
export interface FetchOptions {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
headers?: Record<string, any>;
|
|
21
|
+
body?: Record<string, any>;
|
|
14
22
|
}
|
|
15
23
|
export declare const VConfig: Config;
|
|
16
|
-
export declare function fetchVQL<T = any>(query: VQLUQ<T>, vars?: any, hookContext?: any): Promise<T>;
|
|
17
|
-
export declare function defTransport(query: VQLUQ): Promise<any>;
|
|
24
|
+
export declare function fetchVQL<T = any>(query: VQLUQ<T>, vars?: any, hookContext?: any, fetchOptions?: FetchOptions): Promise<T>;
|
|
25
|
+
export declare function defTransport(query: VQLUQ, fetchOptions?: FetchOptions): Promise<any>;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
;
|
|
2
2
|
export const VConfig = {
|
|
3
3
|
transport: defTransport,
|
|
4
|
+
fetchImplementation: fetch,
|
|
4
5
|
hooks: {},
|
|
5
6
|
url: "/VQL"
|
|
6
7
|
};
|
|
7
|
-
export async function fetchVQL(query, vars = {}, hookContext = {}) {
|
|
8
|
+
export async function fetchVQL(query, vars = {}, hookContext = {}, fetchOptions = {}) {
|
|
8
9
|
const { transport, hooks } = VConfig;
|
|
9
10
|
const start = Date.now();
|
|
10
11
|
try {
|
|
11
|
-
hookContext = Object.assign({}, vars, hookContext);
|
|
12
|
+
hookContext = Object.assign({}, VConfig.hookContext, vars, hookContext);
|
|
12
13
|
hooks.onStart?.(query, hookContext);
|
|
13
14
|
if (typeof query === "string" && Object.keys(vars).length) {
|
|
14
15
|
query = {
|
|
@@ -16,7 +17,7 @@ export async function fetchVQL(query, vars = {}, hookContext = {}) {
|
|
|
16
17
|
var: vars
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
|
-
const res = await transport(query);
|
|
20
|
+
const res = await transport(query, fetchOptions);
|
|
20
21
|
const duration = Date.now() - start;
|
|
21
22
|
hooks.onEnd?.(query, duration, res, hookContext);
|
|
22
23
|
if (res?.err) {
|
|
@@ -33,14 +34,21 @@ export async function fetchVQL(query, vars = {}, hookContext = {}) {
|
|
|
33
34
|
throw e;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
|
-
export async function defTransport(query) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
body: JSON.stringify({ query, ...(VConfig.body || {}) })
|
|
37
|
+
export async function defTransport(query, fetchOptions) {
|
|
38
|
+
const headers = Object.assign({
|
|
39
|
+
"Content-Type": "application/json"
|
|
40
|
+
}, VConfig.headers, fetchOptions.headers);
|
|
41
|
+
const body = Object.assign({}, VConfig.body, fetchOptions.body, {
|
|
42
|
+
query
|
|
43
43
|
});
|
|
44
|
+
const queryConfig = {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers,
|
|
47
|
+
body: JSON.stringify(body)
|
|
48
|
+
};
|
|
49
|
+
if (fetchOptions.signal)
|
|
50
|
+
queryConfig.signal = fetchOptions.signal;
|
|
51
|
+
const res = await VConfig.fetchImplementation(VConfig.url, queryConfig);
|
|
44
52
|
if (!res.ok)
|
|
45
53
|
throw new Error(`VQL request failed: ${res.status}`);
|
|
46
54
|
return await res.json();
|
package/dist/min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VQLClient=(()=>{var
|
|
1
|
+
var VQLClient=(()=>{var c=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var m=(n,t)=>{for(var e in t)c(n,e,{get:t[e],enumerable:!0})},b=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of w(t))!h.call(n,a)&&a!==e&&c(n,a,{get:()=>t[a],enumerable:!(s=L(t,a))||s.enumerable});return n};var T=n=>b(c({},"__esModule",{value:!0}),n);var x={};m(x,{VConfig:()=>i,defTransport:()=>y,fetchVQL:()=>u});var i={transport:y,fetchImplementation:fetch,hooks:{},url:"/VQL"};async function u(n,t={},e={},s={}){var d,f,p,Q;let{transport:a,hooks:r}=i,g=Date.now();try{e=Object.assign({},i.hookContext,t,e),(d=r.onStart)==null||d.call(r,n,e),typeof n=="string"&&Object.keys(t).length&&(n={query:n,var:t});let o=await a(n,s),V=Date.now()-g;if((f=r.onEnd)==null||f.call(r,n,V,o,e),o!=null&&o.err){let l=new Error(o.err);throw(p=r.onError)==null||p.call(r,n,l,o,e),l}return o.result!==void 0?o.result:o}catch(o){throw(Q=r.onError)==null||Q.call(r,n,o,null,e),o}}async function y(n,t){let e=Object.assign({"Content-Type":"application/json"},i.headers,t.headers),s=Object.assign({},i.body,t.body,{query:n}),a={method:"POST",headers:e,body:JSON.stringify(s)};t.signal&&(a.signal=t.signal);let r=await i.fetchImplementation(i.url,a);if(!r.ok)throw new Error(`VQL request failed: ${r.status}`);return await r.json()}typeof window!="undefined"&&(window.VQLClient={fetchVQL:u,defTransport:y,cfg:i});return T(x);})();
|
package/dist/vql.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ export type ComparisonOperators<T = any> = {
|
|
|
25
25
|
], number>;
|
|
26
26
|
$in?: Partial<Record<keyof T, T[keyof T][]>>;
|
|
27
27
|
$nin?: Partial<Record<keyof T, T[keyof T][]>>;
|
|
28
|
+
$idGt?: PartialOfType<T, string | number>;
|
|
29
|
+
$idLt?: PartialOfType<T, string | number>;
|
|
30
|
+
$idGte?: PartialOfType<T, string | number>;
|
|
31
|
+
$idLte?: PartialOfType<T, string | number>;
|
|
28
32
|
};
|
|
29
33
|
export type TypeAndExistenceOperators<T = any> = {
|
|
30
34
|
$exists?: PartialOfType<T, boolean, any>;
|
|
@@ -52,13 +56,15 @@ export type ArrayUpdater<T = any> = {
|
|
|
52
56
|
$pullall?: PartialOfType<T, any>;
|
|
53
57
|
};
|
|
54
58
|
export type ObjectUpdater<T = any> = {
|
|
55
|
-
$merge?: PartialOfType<T, any
|
|
59
|
+
$merge?: PartialOfType<T, any>;
|
|
60
|
+
$deepMerge?: PartialOfType<T, any>;
|
|
56
61
|
};
|
|
57
62
|
export type ValueUpdater<T = any> = {
|
|
58
63
|
$inc?: PartialOfType<T, number>;
|
|
59
64
|
$dec?: PartialOfType<T, number>;
|
|
60
65
|
$unset?: PartialOfType<T, any>;
|
|
61
66
|
$rename?: PartialOfType<T, any>;
|
|
67
|
+
$set?: PartialOfType<T, any>;
|
|
62
68
|
};
|
|
63
69
|
export type UpdaterArg<T = any> = ArrayUpdater<T> & ObjectUpdater<T> & ValueUpdater<T> & Arg<T>;
|
|
64
70
|
export type Arg<T = any> = {
|
|
@@ -92,6 +98,7 @@ declare class CollectionManager<D = Data> {
|
|
|
92
98
|
remove<T = Data>(search: Search<T & Data>, context?: VContext): Promise<boolean>;
|
|
93
99
|
removeOne<T = Data>(search: Search<T & Data>, context?: VContext): Promise<boolean>;
|
|
94
100
|
updateOneOrAdd<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, { add_arg, context, id_gen }: UpdateOneOrAdd<T & Data>): Promise<boolean>;
|
|
101
|
+
toggleOne<T = Data>(search: Search<T & Data>, data?: Arg<T & Data>, context?: VContext): Promise<boolean>;
|
|
95
102
|
}
|
|
96
103
|
export interface ValtheraCompatible {
|
|
97
104
|
c(collection: string): CollectionManager;
|
|
@@ -107,6 +114,7 @@ export interface ValtheraCompatible {
|
|
|
107
114
|
removeOne<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
|
|
108
115
|
removeCollection(collection: string): Promise<boolean>;
|
|
109
116
|
updateOneOrAdd<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, opts?: UpdateOneOrAdd<T>): Promise<boolean>;
|
|
117
|
+
toggleOne<T = Data>(collection: string, search: Search<T>, data?: Arg<T>, context?: VContext): Promise<boolean>;
|
|
110
118
|
}
|
|
111
119
|
export interface UpdateOneOrAdd<T> {
|
|
112
120
|
add_arg?: Arg<T>;
|
|
@@ -179,6 +187,11 @@ export interface VQL_OP_UpdateOneOrAdd<T = any> {
|
|
|
179
187
|
add_arg?: Arg<T>;
|
|
180
188
|
id_gen?: boolean;
|
|
181
189
|
}
|
|
190
|
+
export interface VQL_OP_ToggleOne<T = any> {
|
|
191
|
+
collection: string;
|
|
192
|
+
search: Search<T>;
|
|
193
|
+
data?: Arg<T>;
|
|
194
|
+
}
|
|
182
195
|
export interface VQL_OP_CollectionOperation {
|
|
183
196
|
collection: string;
|
|
184
197
|
}
|
|
@@ -201,6 +214,8 @@ export type VQL_Query_CRUD_Data<T = any> = {
|
|
|
201
214
|
removeOne: VQL_OP_Remove<T>;
|
|
202
215
|
} | {
|
|
203
216
|
updateOneOrAdd: VQL_OP_UpdateOneOrAdd<T>;
|
|
217
|
+
} | {
|
|
218
|
+
toggleOne: VQL_OP_ToggleOne<T>;
|
|
204
219
|
} | {
|
|
205
220
|
removeCollection: VQL_OP_CollectionOperation;
|
|
206
221
|
} | {
|
|
@@ -210,6 +225,7 @@ export type VQL_Query_CRUD_Data<T = any> = {
|
|
|
210
225
|
} | {
|
|
211
226
|
getCollections: {};
|
|
212
227
|
};
|
|
228
|
+
export type VQL_Query_CRUD_Keys = VQL_Query_CRUD_Data extends infer U ? U extends Record<string, unknown> ? keyof U : never : never;
|
|
213
229
|
export interface VQL_Query_CRUD<T = any> {
|
|
214
230
|
db: string;
|
|
215
231
|
d: VQL_Query_CRUD_Data<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/vql-client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "VQL Client",
|
|
@@ -9,6 +9,19 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/wxn0brP/VQL-client.git"
|
|
11
11
|
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"vql",
|
|
14
|
+
"valthera",
|
|
15
|
+
"database",
|
|
16
|
+
"orm",
|
|
17
|
+
"api",
|
|
18
|
+
"crud",
|
|
19
|
+
"nosql",
|
|
20
|
+
"query",
|
|
21
|
+
"db",
|
|
22
|
+
"query-language",
|
|
23
|
+
"client"
|
|
24
|
+
],
|
|
12
25
|
"author": "wxn0brP",
|
|
13
26
|
"license": "MIT",
|
|
14
27
|
"type": "module",
|