@wxn0brp/vql-client 0.2.5 → 0.2.6
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 +8 -1
- package/dist/min.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -23,3 +23,4 @@ export interface FetchOptions {
|
|
|
23
23
|
export declare const VConfig: Config;
|
|
24
24
|
export declare function fetchVQL<T = any>(query: VQLUQ<T>, vars?: any, hookContext?: any, fetchOptions?: FetchOptions): Promise<T>;
|
|
25
25
|
export declare function defTransport(query: VQLUQ, fetchOptions?: FetchOptions): Promise<any>;
|
|
26
|
+
export declare const V: <T = any>(strings: TemplateStringsArray, ...values: any[]) => Promise<T>;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
;
|
|
2
2
|
export const VConfig = {
|
|
3
3
|
transport: defTransport,
|
|
4
|
-
fetchImplementation: fetch,
|
|
4
|
+
fetchImplementation: (input, init) => fetch(input, init),
|
|
5
5
|
hooks: {},
|
|
6
6
|
url: "/VQL"
|
|
7
7
|
};
|
|
@@ -53,10 +53,17 @@ export async function defTransport(query, fetchOptions) {
|
|
|
53
53
|
throw new Error(`VQL request failed: ${res.status}`);
|
|
54
54
|
return await res.json();
|
|
55
55
|
}
|
|
56
|
+
export const V = async (strings, ...values) => {
|
|
57
|
+
const query = strings
|
|
58
|
+
.map((str, i) => str.trim() + (values[i] !== undefined ? values[i] : ""))
|
|
59
|
+
.join(" ");
|
|
60
|
+
return fetchVQL(query);
|
|
61
|
+
};
|
|
56
62
|
if (typeof window !== "undefined") {
|
|
57
63
|
window.VQLClient = {
|
|
58
64
|
fetchVQL,
|
|
59
65
|
defTransport,
|
|
66
|
+
VQL: V,
|
|
60
67
|
cfg: VConfig
|
|
61
68
|
};
|
|
62
69
|
}
|
package/dist/min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VQLClient=(()=>{var c=Object.defineProperty;var
|
|
1
|
+
var VQLClient=(()=>{var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var T=(t,n)=>{for(var e in n)c(t,e,{get:n[e],enumerable:!0})},b=(t,n,e,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of w(n))!h.call(t,o)&&o!==e&&c(t,o,{get:()=>n[o],enumerable:!(i=m(n,o))||i.enumerable});return t};var x=t=>b(c({},"__esModule",{value:!0}),t);var O={};T(O,{V:()=>g,VConfig:()=>s,defTransport:()=>d,fetchVQL:()=>y});var s={transport:d,fetchImplementation:(t,n)=>fetch(t,n),hooks:{},url:"/VQL"};async function y(t,n={},e={},i={}){var p,f,u,Q;let{transport:o,hooks:r}=s,V=Date.now();try{e=Object.assign({},s.hookContext,n,e),(p=r.onStart)==null||p.call(r,t,e),typeof t=="string"&&Object.keys(n).length&&(t={query:t,var:n});let a=await o(t,i),L=Date.now()-V;if((f=r.onEnd)==null||f.call(r,t,L,a,e),a!=null&&a.err){let l=new Error(a.err);throw(u=r.onError)==null||u.call(r,t,l,a,e),l}return a.result!==void 0?a.result:a}catch(a){throw(Q=r.onError)==null||Q.call(r,t,a,null,e),a}}async function d(t,n){let e=Object.assign({"Content-Type":"application/json"},s.headers,n.headers),i=Object.assign({},s.body,n.body,{query:t}),o={method:"POST",headers:e,body:JSON.stringify(i)};n.signal&&(o.signal=n.signal);let r=await s.fetchImplementation(s.url,o);if(!r.ok)throw new Error(`VQL request failed: ${r.status}`);return await r.json()}var g=async(t,...n)=>{let e=t.map((i,o)=>i.trim()+(n[o]!==void 0?n[o]:"")).join(" ");return y(e)};typeof window!="undefined"&&(window.VQLClient={fetchVQL:y,defTransport:d,VQL:g,cfg:s});return x(O);})();
|