@wxn0brp/vql-client 0.0.1 → 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 +23 -24
- package/.github/workflows/build.yml +0 -25
- package/build.js +0 -33
- package/src/index.ts +0 -70
- package/suglite.json +0 -10
- package/tsconfig.json +0 -25
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);})();
|
package/package.json
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"default": "./dist/index.js"
|
|
24
|
-
}
|
|
2
|
+
"name": "@wxn0brp/vql-client",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"author": "wxn0brP",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"esbuild": "^0.25.4",
|
|
11
|
+
"tsc-alias": "^1.8.10",
|
|
12
|
+
"typescript": "^5.7.3"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs",
|
|
22
|
+
"default": "./dist/index.js"
|
|
25
23
|
}
|
|
26
|
-
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
name: Build
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- master
|
|
7
|
-
tags:
|
|
8
|
-
- "*"
|
|
9
|
-
|
|
10
|
-
workflow_dispatch:
|
|
11
|
-
|
|
12
|
-
concurrency:
|
|
13
|
-
group: build-main
|
|
14
|
-
cancel-in-progress: true
|
|
15
|
-
|
|
16
|
-
jobs:
|
|
17
|
-
build:
|
|
18
|
-
uses: wxn0brP/workflow-dist/.github/workflows/build-ts.yml@main
|
|
19
|
-
with:
|
|
20
|
-
scriptsHandling: "remove-all"
|
|
21
|
-
customCommands: "npm run minify"
|
|
22
|
-
publishToNpm: true
|
|
23
|
-
|
|
24
|
-
secrets:
|
|
25
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/build.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import esbuild from "esbuild";
|
|
2
|
-
|
|
3
|
-
const sharedConfig = {
|
|
4
|
-
entryPoints: ["src/index.ts"],
|
|
5
|
-
bundle: true,
|
|
6
|
-
sourcemap: false,
|
|
7
|
-
target: "es2017",
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
Promise.all([
|
|
11
|
-
// IIFE + minified
|
|
12
|
-
esbuild.build({
|
|
13
|
-
...sharedConfig,
|
|
14
|
-
format: "iife",
|
|
15
|
-
globalName: "VQLClient",
|
|
16
|
-
minify: true,
|
|
17
|
-
outfile: "dist/vql-client.min.js",
|
|
18
|
-
}),
|
|
19
|
-
|
|
20
|
-
// CommonJS - require
|
|
21
|
-
esbuild.build({
|
|
22
|
-
...sharedConfig,
|
|
23
|
-
format: "cjs",
|
|
24
|
-
outfile: "dist/vql-client.cjs",
|
|
25
|
-
}),
|
|
26
|
-
])
|
|
27
|
-
.then(() => {
|
|
28
|
-
console.log("✅ Build complete");
|
|
29
|
-
})
|
|
30
|
-
.catch((e) => {
|
|
31
|
-
console.error("❌ Build failed:", e);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export type VQLQuery = string | object;
|
|
2
|
-
export type VQLResult<T = any> = Promise<T>;
|
|
3
|
-
export type VQLTransport = (query: VQLQuery) => VQLResult;
|
|
4
|
-
export type VQLHooks = {
|
|
5
|
-
onStart?: (query: VQLQuery) => void;
|
|
6
|
-
onEnd?: (query: VQLQuery, durationMs: number, result: any) => void;
|
|
7
|
-
onError?: (query: VQLQuery, error: unknown) => void;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
let transport: VQLTransport = defaultFetchTransport;
|
|
11
|
-
let hooks: VQLHooks = {};
|
|
12
|
-
|
|
13
|
-
export function initVQLClient(config: {
|
|
14
|
-
transport?: VQLTransport,
|
|
15
|
-
hooks?: VQLHooks
|
|
16
|
-
}) {
|
|
17
|
-
if (config.transport) transport = config.transport;
|
|
18
|
-
if (config.hooks) hooks = config.hooks;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function fetchVQL<T = any>(query: VQLQuery): Promise<T> {
|
|
22
|
-
const start = Date.now();
|
|
23
|
-
try {
|
|
24
|
-
hooks.onStart?.(query);
|
|
25
|
-
|
|
26
|
-
const res = await transport(query);
|
|
27
|
-
|
|
28
|
-
const duration = Date.now() - start;
|
|
29
|
-
hooks.onEnd?.(query, duration, res);
|
|
30
|
-
|
|
31
|
-
if (res?.err) {
|
|
32
|
-
const error = new Error(res.err);
|
|
33
|
-
hooks.onError?.(query, error);
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return res?.result ?? res;
|
|
38
|
-
} catch (e) {
|
|
39
|
-
hooks.onError?.(query, e);
|
|
40
|
-
throw e;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function resetVQLClient() {
|
|
45
|
-
transport = defaultFetchTransport;
|
|
46
|
-
hooks = {};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export async function defaultFetchTransport(query: VQLQuery): Promise<any> {
|
|
50
|
-
const res = await fetch("/VQL", {
|
|
51
|
-
method: "POST",
|
|
52
|
-
headers: {
|
|
53
|
-
"Content-Type": "application/json"
|
|
54
|
-
},
|
|
55
|
-
body: JSON.stringify({ query })
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
if (!res.ok) throw new Error(`VQL request failed: ${res.status}`);
|
|
59
|
-
return await res.json();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Export global for CDN use
|
|
63
|
-
if (typeof window !== "undefined") {
|
|
64
|
-
(window as any).VQLClient = {
|
|
65
|
-
fetchVQL,
|
|
66
|
-
initVQLClient,
|
|
67
|
-
resetVQLClient,
|
|
68
|
-
defaultFetchTransport
|
|
69
|
-
};
|
|
70
|
-
}
|
package/suglite.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "ES2022",
|
|
4
|
-
"target": "ES2022",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"paths": {},
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"outDir": "./dist",
|
|
10
|
-
"inlineSourceMap": false,
|
|
11
|
-
"sourceMap": false,
|
|
12
|
-
"declaration": true,
|
|
13
|
-
"removeComments": true
|
|
14
|
-
},
|
|
15
|
-
"include": [
|
|
16
|
-
"./src"
|
|
17
|
-
],
|
|
18
|
-
"exclude": [
|
|
19
|
-
"node_modules"
|
|
20
|
-
],
|
|
21
|
-
"tsc-alias": {
|
|
22
|
-
"resolveFullPaths": true,
|
|
23
|
-
"verbose": false
|
|
24
|
-
}
|
|
25
|
-
}
|