@wxn0brp/vql-client 0.0.2 → 0.0.3
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 +1 -0
- package/dist/index.js +4 -1
- package/dist/vql-client.cjs +3 -1
- package/dist/vql-client.min.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type VQLHooks = {
|
|
|
9
9
|
export declare function initVQLClient(config: {
|
|
10
10
|
transport?: VQLTransport;
|
|
11
11
|
hooks?: VQLHooks;
|
|
12
|
+
defaultFetchUrl?: string;
|
|
12
13
|
}): void;
|
|
13
14
|
export declare function fetchVQL<T = any>(query: VQLQuery): Promise<T>;
|
|
14
15
|
export declare function resetVQLClient(): void;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
let transport = defaultFetchTransport;
|
|
2
2
|
let hooks = {};
|
|
3
|
+
let defaultFetchUrl = "/VQL";
|
|
3
4
|
export function initVQLClient(config) {
|
|
4
5
|
if (config.transport)
|
|
5
6
|
transport = config.transport;
|
|
6
7
|
if (config.hooks)
|
|
7
8
|
hooks = config.hooks;
|
|
9
|
+
if (config.defaultFetchUrl)
|
|
10
|
+
defaultFetchUrl = config.defaultFetchUrl;
|
|
8
11
|
}
|
|
9
12
|
export async function fetchVQL(query) {
|
|
10
13
|
const start = Date.now();
|
|
@@ -30,7 +33,7 @@ export function resetVQLClient() {
|
|
|
30
33
|
hooks = {};
|
|
31
34
|
}
|
|
32
35
|
export async function defaultFetchTransport(query) {
|
|
33
|
-
const res = await fetch(
|
|
36
|
+
const res = await fetch(defaultFetchUrl, {
|
|
34
37
|
method: "POST",
|
|
35
38
|
headers: {
|
|
36
39
|
"Content-Type": "application/json"
|
package/dist/vql-client.cjs
CHANGED
|
@@ -27,9 +27,11 @@ __export(index_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
var transport = defaultFetchTransport;
|
|
29
29
|
var hooks = {};
|
|
30
|
+
var defaultFetchUrl = "/VQL";
|
|
30
31
|
function initVQLClient(config) {
|
|
31
32
|
if (config.transport) transport = config.transport;
|
|
32
33
|
if (config.hooks) hooks = config.hooks;
|
|
34
|
+
if (config.defaultFetchUrl) defaultFetchUrl = config.defaultFetchUrl;
|
|
33
35
|
}
|
|
34
36
|
async function fetchVQL(query) {
|
|
35
37
|
var _a, _b, _c, _d, _e;
|
|
@@ -55,7 +57,7 @@ function resetVQLClient() {
|
|
|
55
57
|
hooks = {};
|
|
56
58
|
}
|
|
57
59
|
async function defaultFetchTransport(query) {
|
|
58
|
-
const res = await fetch(
|
|
60
|
+
const res = await fetch(defaultFetchUrl, {
|
|
59
61
|
method: "POST",
|
|
60
62
|
headers: {
|
|
61
63
|
"Content-Type": "application/json"
|
package/dist/vql-client.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VQLClient=(()=>{var
|
|
1
|
+
var VQLClient=(()=>{var u=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var x=(t,r)=>{for(var a in r)u(t,a,{get:r[a],enumerable:!0})},E=(t,r,a,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of T(r))!h.call(t,o)&&o!==a&&u(t,o,{get:()=>r[o],enumerable:!(s=w(r,o))||s.enumerable});return t};var m=t=>E(u({},"__esModule",{value:!0}),t);var F={};x(F,{defaultFetchTransport:()=>i,fetchVQL:()=>d,initVQLClient:()=>V,resetVQLClient:()=>c});var Q=i,e={},L="/VQL";function V(t){t.transport&&(Q=t.transport),t.hooks&&(e=t.hooks),t.defaultFetchUrl&&(L=t.defaultFetchUrl)}async function d(t){var a,s,o,p,y;let r=Date.now();try{(a=e.onStart)==null||a.call(e,t);let n=await Q(t),f=Date.now()-r;if((s=e.onEnd)==null||s.call(e,t,f,n),n!=null&&n.err){let l=new Error(n.err);throw(o=e.onError)==null||o.call(e,t,l),l}return(p=n==null?void 0:n.result)!=null?p:n}catch(n){throw(y=e.onError)==null||y.call(e,t,n),n}}function c(){Q=i,e={}}async function i(t){let r=await fetch(L,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t})});if(!r.ok)throw new Error(`VQL request failed: ${r.status}`);return await r.json()}typeof window!="undefined"&&(window.VQLClient={fetchVQL:d,initVQLClient:V,resetVQLClient:c,defaultFetchTransport:i});return m(F);})();
|