@wxn0brp/vql-client 0.0.8 → 0.0.10
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 +4 -4
- package/dist/index.js +5 -5
- package/dist/vql-client.cjs +5 -5
- package/dist/vql-client.min.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,15 @@ import { VqlQueryRaw } from "./vql.js";
|
|
|
2
2
|
export type VQLResult<T = any> = Promise<T>;
|
|
3
3
|
export type VQLTransport = (query: VqlQueryRaw) => VQLResult;
|
|
4
4
|
export type VQLHooks = {
|
|
5
|
-
onStart?: (query: VqlQueryRaw) => void;
|
|
6
|
-
onEnd?: (query: VqlQueryRaw, durationMs: number, result: any) => void;
|
|
7
|
-
onError?: (query: VqlQueryRaw, error: unknown) => void;
|
|
5
|
+
onStart?: (query: VqlQueryRaw, hookContext: any) => void;
|
|
6
|
+
onEnd?: (query: VqlQueryRaw, durationMs: number, result: any, hookContext: any) => void;
|
|
7
|
+
onError?: (query: VqlQueryRaw, error: unknown, result?: any, hookContext?: any) => void;
|
|
8
8
|
};
|
|
9
9
|
export declare function initVQLClient(config: {
|
|
10
10
|
transport?: VQLTransport;
|
|
11
11
|
hooks?: VQLHooks;
|
|
12
12
|
defaultFetchUrl?: string;
|
|
13
13
|
}): void;
|
|
14
|
-
export declare function fetchVQL<T = any>(query: VqlQueryRaw): Promise<T>;
|
|
14
|
+
export declare function fetchVQL<T = any>(query: VqlQueryRaw, hookContext?: any): Promise<T>;
|
|
15
15
|
export declare function resetVQLClient(): void;
|
|
16
16
|
export declare function defaultFetchTransport(query: VqlQueryRaw): Promise<any>;
|
package/dist/index.js
CHANGED
|
@@ -9,16 +9,16 @@ export function initVQLClient(config) {
|
|
|
9
9
|
if (config.defaultFetchUrl)
|
|
10
10
|
defaultFetchUrl = config.defaultFetchUrl;
|
|
11
11
|
}
|
|
12
|
-
export async function fetchVQL(query) {
|
|
12
|
+
export async function fetchVQL(query, hookContext = {}) {
|
|
13
13
|
const start = Date.now();
|
|
14
14
|
try {
|
|
15
|
-
hooks.onStart?.(query);
|
|
15
|
+
hooks.onStart?.(query, hookContext);
|
|
16
16
|
const res = await transport(query);
|
|
17
17
|
const duration = Date.now() - start;
|
|
18
|
-
hooks.onEnd?.(query, duration, res);
|
|
18
|
+
hooks.onEnd?.(query, duration, res, hookContext);
|
|
19
19
|
if (res?.err) {
|
|
20
20
|
const error = new Error(res.err);
|
|
21
|
-
hooks.onError?.(query, error);
|
|
21
|
+
hooks.onError?.(query, error, res, hookContext);
|
|
22
22
|
throw error;
|
|
23
23
|
}
|
|
24
24
|
if (res.result !== undefined)
|
|
@@ -26,7 +26,7 @@ export async function fetchVQL(query) {
|
|
|
26
26
|
return res;
|
|
27
27
|
}
|
|
28
28
|
catch (e) {
|
|
29
|
-
hooks.onError?.(query, e);
|
|
29
|
+
hooks.onError?.(query, e, null, hookContext);
|
|
30
30
|
throw e;
|
|
31
31
|
}
|
|
32
32
|
}
|
package/dist/vql-client.cjs
CHANGED
|
@@ -33,23 +33,23 @@ function initVQLClient(config) {
|
|
|
33
33
|
if (config.hooks) hooks = config.hooks;
|
|
34
34
|
if (config.defaultFetchUrl) defaultFetchUrl = config.defaultFetchUrl;
|
|
35
35
|
}
|
|
36
|
-
async function fetchVQL(query) {
|
|
36
|
+
async function fetchVQL(query, hookContext = {}) {
|
|
37
37
|
var _a, _b, _c, _d;
|
|
38
38
|
const start = Date.now();
|
|
39
39
|
try {
|
|
40
|
-
(_a = hooks.onStart) == null ? void 0 : _a.call(hooks, query);
|
|
40
|
+
(_a = hooks.onStart) == null ? void 0 : _a.call(hooks, query, hookContext);
|
|
41
41
|
const res = await transport(query);
|
|
42
42
|
const duration = Date.now() - start;
|
|
43
|
-
(_b = hooks.onEnd) == null ? void 0 : _b.call(hooks, query, duration, res);
|
|
43
|
+
(_b = hooks.onEnd) == null ? void 0 : _b.call(hooks, query, duration, res, hookContext);
|
|
44
44
|
if (res == null ? void 0 : res.err) {
|
|
45
45
|
const error = new Error(res.err);
|
|
46
|
-
(_c = hooks.onError) == null ? void 0 : _c.call(hooks, query, error);
|
|
46
|
+
(_c = hooks.onError) == null ? void 0 : _c.call(hooks, query, error, res, hookContext);
|
|
47
47
|
throw error;
|
|
48
48
|
}
|
|
49
49
|
if (res.result !== void 0) return res.result;
|
|
50
50
|
return res;
|
|
51
51
|
} catch (e) {
|
|
52
|
-
(_d = hooks.onError) == null ? void 0 : _d.call(hooks, query, e);
|
|
52
|
+
(_d = hooks.onError) == null ? void 0 : _d.call(hooks, query, e, null, hookContext);
|
|
53
53
|
throw e;
|
|
54
54
|
}
|
|
55
55
|
}
|
package/dist/vql-client.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VQLClient=(()=>{var
|
|
1
|
+
var VQLClient=(()=>{var i=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var R=(r,t)=>{for(var a in t)i(r,a,{get:t[a],enumerable:!0})},q=(r,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of T(t))!h.call(r,o)&&o!==a&&i(r,o,{get:()=>t[o],enumerable:!(s=L(t,o))||s.enumerable});return r};var m=r=>q(i({},"__esModule",{value:!0}),r);var x={};R(x,{defaultFetchTransport:()=>u,fetchVQL:()=>V,initVQLClient:()=>Q,resetVQLClient:()=>f});var l=u,e={},w="/VQL";function Q(r){r.transport&&(l=r.transport),r.hooks&&(e=r.hooks),r.defaultFetchUrl&&(w=r.defaultFetchUrl)}async function V(r,t={}){var s,o,y,p;let a=Date.now();try{(s=e.onStart)==null||s.call(e,r,t);let n=await l(r),c=Date.now()-a;if((o=e.onEnd)==null||o.call(e,r,c,n,t),n!=null&&n.err){let d=new Error(n.err);throw(y=e.onError)==null||y.call(e,r,d,n,t),d}return n.result!==void 0?n.result:n}catch(n){throw(p=e.onError)==null||p.call(e,r,n,null,t),n}}function f(){l=u,e={}}async function u(r){let t=await fetch(w,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:r})});if(!t.ok)throw new Error(`VQL request failed: ${t.status}`);return await t.json()}typeof window!="undefined"&&(window.VQLClient={fetchVQL:V,initVQLClient:Q,resetVQLClient:f,defaultFetchTransport:u});return m(x);})();
|