@wxn0brp/vql-client 0.0.1

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.
@@ -0,0 +1,25 @@
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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 wxn0brP
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # @wxn0brp/vql-client
2
+
3
+ Minimalistic, pluggable client for **VQL** query execution.
4
+
5
+ Supports:
6
+
7
+ - ✅ ESM (`import`)
8
+ - ✅ CJS (`require`)
9
+ - ✅ CDN / `<script>` (`VQLClient`)
10
+ - ✅ Fully typed with TypeScript
11
+ - ✅ Custom transport layers and lifecycle hooks
12
+
13
+ ## 📦 Installation
14
+
15
+ ### NPM
16
+
17
+ ```bash
18
+ npm install @wxn0brp/vql-client
19
+ ```
20
+
21
+ ```ts
22
+ import { fetchVQL, initVQLClient, resetVQLClient } from "@wxn0brp/vql-client";
23
+
24
+ const result = await fetchVQL("db1 user! s._id = xyz");
25
+ ```
26
+
27
+ ### CDN
28
+
29
+ ```html
30
+ <script src="/dist/vql-client.min.js"></script>
31
+ <script>
32
+ VQLClient.fetchVQL("db1 user! s._id = xyz").then(console.log);
33
+ </script>
34
+ ```
35
+
36
+ You can also serve `vql-client.min.js` from your own CDN or static server.
37
+
38
+ ## 🧠 Usage
39
+
40
+ ### `fetchVQL<T = any>(query: string | object): Promise<T>`
41
+
42
+ Executes a VQL query and returns the result (unwrapped from `{ result }`, unless an error is present).
43
+
44
+ ### `initVQLClient(config: { transport?: fn, hooks?: {...} })`
45
+
46
+ Customize client behavior.
47
+
48
+ #### Example – custom transport and hooks:
49
+
50
+ ```ts
51
+ initVQLClient({
52
+ transport: async (query) => {
53
+ return await fetch("/VQL", {
54
+ method: "POST",
55
+ headers: { "Content-Type": "application/json" },
56
+ body: JSON.stringify({ query })
57
+ }).then(res => res.json());
58
+ },
59
+ hooks: {
60
+ onStart: (q) => console.log("VQL start", q),
61
+ onEnd: (q, ms, r) => console.log("VQL end", ms + "ms", r),
62
+ onError: (q, e) => console.error("VQL error", e)
63
+ }
64
+ });
65
+ ```
66
+
67
+ ### `resetVQLClient()`
68
+
69
+ Reset transport and hooks to default.
70
+
71
+ ## ✈️ Default Transport
72
+
73
+ ```ts
74
+ defaultFetchTransport(query): Promise<any>
75
+ ```
76
+
77
+ Sends:
78
+
79
+ ```
80
+ POST /VQL
81
+ Content-Type: application/json
82
+ Body: { query }
83
+ ```
84
+
85
+ Returns:
86
+
87
+ ```
88
+ {
89
+ result: any,
90
+ err?: string
91
+ }
92
+ ```
93
+
94
+ Use `initVQLClient({ transport })` to override with WebSocket, RPC, etc.
95
+
96
+ ## 📁 Output Files
97
+
98
+ ```
99
+ dist/
100
+ ├── index.js # ESM build (import)
101
+ ├── index.d.ts # TypeScript types
102
+ ├── vql-client.cjs # CommonJS build (require)
103
+ ├── vql-client.min.js # Global (CDN, window.VQLClient)
104
+ ```
105
+
106
+ ## 🧾 Typings in Browser
107
+
108
+ You can manually copy `index.d.ts` to your local project or declare global types:
109
+
110
+ ```ts
111
+ declare const VQLClient: {
112
+ fetchVQL<T = any>(query: string | object): Promise<T>;
113
+ initVQLClient(config: {
114
+ transport?: (query: string | object) => Promise<any>,
115
+ hooks?: {
116
+ onStart?: (query: string | object) => void,
117
+ onEnd?: (query: string | object, ms: number, result: any) => void,
118
+ onError?: (query: string | object, error: unknown) => void
119
+ }
120
+ }): void;
121
+ resetVQLClient(): void;
122
+ defaultFetchTransport(query: string | object): Promise<any>;
123
+ };
124
+ ```
125
+
126
+ ## 🧪 Example
127
+
128
+ ```ts
129
+ const result = await fetchVQL("api getUser! s._id = abc123");
130
+ console.log(result.name);
131
+ ```
132
+
133
+ ## 📜 License
134
+
135
+ MIT © wxn0brP
package/build.js ADDED
@@ -0,0 +1,33 @@
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
+ });
@@ -0,0 +1,15 @@
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
+ export declare function initVQLClient(config: {
10
+ transport?: VQLTransport;
11
+ hooks?: VQLHooks;
12
+ }): void;
13
+ export declare function fetchVQL<T = any>(query: VQLQuery): Promise<T>;
14
+ export declare function resetVQLClient(): void;
15
+ export declare function defaultFetchTransport(query: VQLQuery): Promise<any>;
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ let transport = defaultFetchTransport;
2
+ let hooks = {};
3
+ export function initVQLClient(config) {
4
+ if (config.transport)
5
+ transport = config.transport;
6
+ if (config.hooks)
7
+ hooks = config.hooks;
8
+ }
9
+ export async function fetchVQL(query) {
10
+ const start = Date.now();
11
+ try {
12
+ hooks.onStart?.(query);
13
+ const res = await transport(query);
14
+ const duration = Date.now() - start;
15
+ hooks.onEnd?.(query, duration, res);
16
+ if (res?.err) {
17
+ const error = new Error(res.err);
18
+ hooks.onError?.(query, error);
19
+ throw error;
20
+ }
21
+ return res?.result ?? res;
22
+ }
23
+ catch (e) {
24
+ hooks.onError?.(query, e);
25
+ throw e;
26
+ }
27
+ }
28
+ export function resetVQLClient() {
29
+ transport = defaultFetchTransport;
30
+ hooks = {};
31
+ }
32
+ export async function defaultFetchTransport(query) {
33
+ const res = await fetch("/VQL", {
34
+ method: "POST",
35
+ headers: {
36
+ "Content-Type": "application/json"
37
+ },
38
+ body: JSON.stringify({ query })
39
+ });
40
+ if (!res.ok)
41
+ throw new Error(`VQL request failed: ${res.status}`);
42
+ return await res.json();
43
+ }
44
+ if (typeof window !== "undefined") {
45
+ window.VQLClient = {
46
+ fetchVQL,
47
+ initVQLClient,
48
+ resetVQLClient,
49
+ defaultFetchTransport
50
+ };
51
+ }
@@ -0,0 +1,75 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ defaultFetchTransport: () => defaultFetchTransport,
23
+ fetchVQL: () => fetchVQL,
24
+ initVQLClient: () => initVQLClient,
25
+ resetVQLClient: () => resetVQLClient
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var transport = defaultFetchTransport;
29
+ var hooks = {};
30
+ function initVQLClient(config) {
31
+ if (config.transport) transport = config.transport;
32
+ if (config.hooks) hooks = config.hooks;
33
+ }
34
+ async function fetchVQL(query) {
35
+ var _a, _b, _c, _d, _e;
36
+ const start = Date.now();
37
+ try {
38
+ (_a = hooks.onStart) == null ? void 0 : _a.call(hooks, query);
39
+ const res = await transport(query);
40
+ const duration = Date.now() - start;
41
+ (_b = hooks.onEnd) == null ? void 0 : _b.call(hooks, query, duration, res);
42
+ if (res == null ? void 0 : res.err) {
43
+ const error = new Error(res.err);
44
+ (_c = hooks.onError) == null ? void 0 : _c.call(hooks, query, error);
45
+ throw error;
46
+ }
47
+ return (_d = res == null ? void 0 : res.result) != null ? _d : res;
48
+ } catch (e) {
49
+ (_e = hooks.onError) == null ? void 0 : _e.call(hooks, query, e);
50
+ throw e;
51
+ }
52
+ }
53
+ function resetVQLClient() {
54
+ transport = defaultFetchTransport;
55
+ hooks = {};
56
+ }
57
+ async function defaultFetchTransport(query) {
58
+ const res = await fetch("/VQL", {
59
+ method: "POST",
60
+ headers: {
61
+ "Content-Type": "application/json"
62
+ },
63
+ body: JSON.stringify({ query })
64
+ });
65
+ if (!res.ok) throw new Error(`VQL request failed: ${res.status}`);
66
+ return await res.json();
67
+ }
68
+ if (typeof window !== "undefined") {
69
+ window.VQLClient = {
70
+ fetchVQL,
71
+ initVQLClient,
72
+ resetVQLClient,
73
+ defaultFetchTransport
74
+ };
75
+ }
@@ -0,0 +1 @@
1
+ var VQLClient=(()=>{var Q=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var x=(t,r)=>{for(var a in r)Q(t,a,{get:r[a],enumerable:!0})},E=(t,r,a,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of l(r))!T.call(t,o)&&o!==a&&Q(t,o,{get:()=>r[o],enumerable:!(i=f(r,o))||i.enumerable});return t};var h=t=>E(Q({},"__esModule",{value:!0}),t);var m={};x(m,{defaultFetchTransport:()=>s,fetchVQL:()=>d,initVQLClient:()=>V,resetVQLClient:()=>c});var u=s,n={};function V(t){t.transport&&(u=t.transport),t.hooks&&(n=t.hooks)}async function d(t){var a,i,o,p,y;let r=Date.now();try{(a=n.onStart)==null||a.call(n,t);let e=await u(t),w=Date.now()-r;if((i=n.onEnd)==null||i.call(n,t,w,e),e!=null&&e.err){let L=new Error(e.err);throw(o=n.onError)==null||o.call(n,t,L),L}return(p=e==null?void 0:e.result)!=null?p:e}catch(e){throw(y=n.onError)==null||y.call(n,t,e),e}}function c(){u=s,n={}}async function s(t){let r=await fetch("/VQL",{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:s});return h(m);})();
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@wxn0brp/vql-client",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "author": "wxn0brP",
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "scripts": {
10
+ "build": "tsc && tsc-alias",
11
+ "minify": "node build.js"
12
+ },
13
+ "devDependencies": {
14
+ "esbuild": "^0.25.4",
15
+ "tsc-alias": "^1.8.10",
16
+ "typescript": "^5.7.3"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js",
22
+ "require": "./dist/index.cjs",
23
+ "default": "./dist/index.js"
24
+ }
25
+ }
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,70 @@
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 ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "cmd": "yarn build",
3
+ "watch": [
4
+ "src"
5
+ ],
6
+ "restart_cmd": "clear",
7
+ "events": {
8
+ "rs": "clear"
9
+ }
10
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
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
+ }