@wxn0brp/vql-client 0.0.6 → 0.0.8

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
@@ -1,19 +1,16 @@
1
- import { VQLR, VQLRef } from "./vql.js";
2
- export type VQLQuery = VQLR | string | {
3
- query: string;
4
- } & VQLRef;
1
+ import { VqlQueryRaw } from "./vql.js";
5
2
  export type VQLResult<T = any> = Promise<T>;
6
- export type VQLTransport = (query: VQLQuery) => VQLResult;
3
+ export type VQLTransport = (query: VqlQueryRaw) => VQLResult;
7
4
  export type VQLHooks = {
8
- onStart?: (query: VQLQuery) => void;
9
- onEnd?: (query: VQLQuery, durationMs: number, result: any) => void;
10
- onError?: (query: VQLQuery, error: unknown) => void;
5
+ onStart?: (query: VqlQueryRaw) => void;
6
+ onEnd?: (query: VqlQueryRaw, durationMs: number, result: any) => void;
7
+ onError?: (query: VqlQueryRaw, error: unknown) => void;
11
8
  };
12
9
  export declare function initVQLClient(config: {
13
10
  transport?: VQLTransport;
14
11
  hooks?: VQLHooks;
15
12
  defaultFetchUrl?: string;
16
13
  }): void;
17
- export declare function fetchVQL<T = any>(query: VQLQuery): Promise<T>;
14
+ export declare function fetchVQL<T = any>(query: VqlQueryRaw): Promise<T>;
18
15
  export declare function resetVQLClient(): void;
19
- export declare function defaultFetchTransport(query: VQLQuery): Promise<any>;
16
+ export declare function defaultFetchTransport(query: VqlQueryRaw): Promise<any>;
package/dist/index.js CHANGED
@@ -21,7 +21,9 @@ export async function fetchVQL(query) {
21
21
  hooks.onError?.(query, error);
22
22
  throw error;
23
23
  }
24
- return res?.result ?? res;
24
+ if (res.result !== undefined)
25
+ return res.result;
26
+ return res;
25
27
  }
26
28
  catch (e) {
27
29
  hooks.onError?.(query, e);
@@ -34,7 +34,7 @@ function initVQLClient(config) {
34
34
  if (config.defaultFetchUrl) defaultFetchUrl = config.defaultFetchUrl;
35
35
  }
36
36
  async function fetchVQL(query) {
37
- var _a, _b, _c, _d, _e;
37
+ var _a, _b, _c, _d;
38
38
  const start = Date.now();
39
39
  try {
40
40
  (_a = hooks.onStart) == null ? void 0 : _a.call(hooks, query);
@@ -46,9 +46,10 @@ async function fetchVQL(query) {
46
46
  (_c = hooks.onError) == null ? void 0 : _c.call(hooks, query, error);
47
47
  throw error;
48
48
  }
49
- return (_d = res == null ? void 0 : res.result) != null ? _d : res;
49
+ if (res.result !== void 0) return res.result;
50
+ return res;
50
51
  } catch (e) {
51
- (_e = hooks.onError) == null ? void 0 : _e.call(hooks, query, e);
52
+ (_d = hooks.onError) == null ? void 0 : _d.call(hooks, query, e);
52
53
  throw e;
53
54
  }
54
55
  }
@@ -1 +1 @@
1
- var VQLClient=(()=>{var Q=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var x=(t,r)=>{for(var a in r)Q(t,a,{get:r[a],enumerable:!0})},m=(t,r,a,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of T(r))!h.call(t,o)&&o!==a&&Q(t,o,{get:()=>r[o],enumerable:!(i=w(r,o))||i.enumerable});return t};var E=t=>m(Q({},"__esModule",{value:!0}),t);var R={};x(R,{defaultFetchTransport:()=>s,fetchVQL:()=>d,initVQLClient:()=>l,resetVQLClient:()=>f});var u=s,e={},y="/VQL";function l(t){t.transport&&(u=t.transport),t.hooks&&(e=t.hooks),t.defaultFetchUrl&&(y=t.defaultFetchUrl)}async function d(t){var a,i,o,p,L;let r=Date.now();try{(a=e.onStart)==null||a.call(e,t);let n=await u(t),c=Date.now()-r;if((i=e.onEnd)==null||i.call(e,t,c,n),n!=null&&n.err){let V=new Error(n.err);throw(o=e.onError)==null||o.call(e,t,V),V}return(p=n==null?void 0:n.result)!=null?p:n}catch(n){throw(L=e.onError)==null||L.call(e,t,n),n}}function f(){u=s,e={}}async function s(t){let r=await fetch(y,{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:l,resetVQLClient:f,defaultFetchTransport:s});return E(R);})();
1
+ var VQLClient=(()=>{var u=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var h=(r,t)=>{for(var a in t)u(r,a,{get:t[a],enumerable:!0})},R=(r,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of L(t))!T.call(r,o)&&o!==a&&u(r,o,{get:()=>t[o],enumerable:!(s=c(t,o))||s.enumerable});return r};var q=r=>R(u({},"__esModule",{value:!0}),r);var m={};h(m,{defaultFetchTransport:()=>i,fetchVQL:()=>Q,initVQLClient:()=>y,resetVQLClient:()=>V});var l=i,e={},w="/VQL";function y(r){r.transport&&(l=r.transport),r.hooks&&(e=r.hooks),r.defaultFetchUrl&&(w=r.defaultFetchUrl)}async function Q(r){var a,s,o,p;let t=Date.now();try{(a=e.onStart)==null||a.call(e,r);let n=await l(r),f=Date.now()-t;if((s=e.onEnd)==null||s.call(e,r,f,n),n!=null&&n.err){let d=new Error(n.err);throw(o=e.onError)==null||o.call(e,r,d),d}return n.result!==void 0?n.result:n}catch(n){throw(p=e.onError)==null||p.call(e,r,n),n}}function V(){l=i,e={}}async function i(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:Q,initVQLClient:y,resetVQLClient:V,defaultFetchTransport:i});return q(m);})();
package/dist/vql.d.ts CHANGED
@@ -272,4 +272,7 @@ export interface VQLError {
272
272
  c: number;
273
273
  why?: string;
274
274
  }
275
+ export type VqlQueryRaw = VQLR | string | {
276
+ query: string;
277
+ } & VQLRef;
275
278
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql-client",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "wxn0brP",