@wxn0brp/vql-client 0.0.12 → 0.1.0

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/README.md CHANGED
@@ -5,21 +5,16 @@ Minimalistic, pluggable client for **VQL** query execution.
5
5
  Supports:
6
6
 
7
7
  - ✅ ESM (`import`)
8
- - ✅ CJS (`require`)
9
8
  - ✅ CDN / `<script>` (`VQLClient`)
10
9
  - ✅ Fully typed with TypeScript
11
10
  - ✅ Custom transport layers and lifecycle hooks
12
11
 
13
- ## 📦 Installation
12
+ ## 🚀 Usage
14
13
 
15
- ### NPM
16
-
17
- ```bash
18
- npm install @wxn0brp/vql-client
19
- ```
14
+ ### ESM
20
15
 
21
16
  ```ts
22
- import { fetchVQL, initVQLClient, resetVQLClient } from "@wxn0brp/vql-client";
17
+ import { fetchVQL, VConfig } from "@wxn0brp/vql-client";
23
18
 
24
19
  const result = await fetchVQL("db1 user! s._id = xyz");
25
20
  ```
@@ -27,51 +22,43 @@ const result = await fetchVQL("db1 user! s._id = xyz");
27
22
  ### CDN
28
23
 
29
24
  ```html
30
- <script src="/dist/vql-client.min.js"></script>
25
+ <script src="https://unpkg.com/@wxn0brp/vql-client/dist/min.js"></script>
31
26
  <script>
32
27
  VQLClient.fetchVQL("db1 user! s._id = xyz").then(console.log);
33
28
  </script>
34
29
  ```
35
30
 
36
- You can also serve `vql-client.min.js` from your own CDN or static server.
37
-
38
31
  ## 🧠 Usage
39
32
 
40
33
  ### `fetchVQL<T = any>(query: string | object): Promise<T>`
41
34
 
42
35
  Executes a VQL query and returns the result (unwrapped from `{ result }`, unless an error is present).
43
36
 
44
- ### `initVQLClient(config: { transport?: fn, hooks?: {...} })`
37
+ ### `VConfig`
45
38
 
46
39
  Customize client behavior.
47
40
 
48
41
  #### Example – custom transport and hooks:
49
42
 
50
43
  ```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
- });
44
+ VConfig.transport = async (query) => {
45
+ return await fetch("/VQL", {
46
+ method: "POST",
47
+ headers: { "Content-Type": "application/json" },
48
+ body: JSON.stringify({ query })
49
+ }).then(res => res.json());
50
+ }
51
+ VConfig.hooks = {
52
+ onStart: (q) => console.log("VQL start", q),
53
+ onEnd: (q, ms, r) => console.log("VQL end", ms + "ms", r),
54
+ onError: (q, e) => console.error("VQL error", e)
55
+ }
65
56
  ```
66
57
 
67
- ### `resetVQLClient()`
68
-
69
- Reset transport and hooks to default.
70
-
71
58
  ## ✈️ Default Transport
72
59
 
73
60
  ```ts
74
- defaultFetchTransport(query): Promise<any>
61
+ defTransport(query): Promise<any>
75
62
  ```
76
63
 
77
64
  Sends:
@@ -91,45 +78,15 @@ Returns:
91
78
  }
92
79
  ```
93
80
 
94
- Use `initVQLClient({ transport })` to override with WebSocket, RPC, etc.
95
-
96
81
  ## 📁 Output Files
97
82
 
98
83
  ```
99
84
  dist/
100
85
  ├── index.js # ESM build (import)
101
86
  ├── index.d.ts # TypeScript types
102
- ├── vql-client.cjs # CommonJS build (require)
103
87
  ├── vql-client.min.js # Global (CDN, window.VQLClient)
104
88
  ```
105
89
 
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
90
  ## 📜 License
134
91
 
135
- MIT © wxn0brP
92
+ MIT wxn0brP
package/dist/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- import { VqlQueryRaw } from "./vql.js";
1
+ import { VqlQueryRaw } from "./vql";
2
2
  export type VQLResult<T = any> = Promise<T>;
3
3
  export type VQLTransport = (query: VqlQueryRaw) => VQLResult;
4
- export type VQLHooks = {
4
+ export interface VQLHooks {
5
5
  onStart?: (query: VqlQueryRaw, hookContext: any) => void;
6
6
  onEnd?: (query: VqlQueryRaw, durationMs: number, result: any, hookContext: any) => void;
7
7
  onError?: (query: VqlQueryRaw, error: unknown, result?: any, hookContext?: any) => void;
8
- };
9
- export declare function initVQLClient(config: {
8
+ }
9
+ export interface Config {
10
10
  transport?: VQLTransport;
11
11
  hooks?: VQLHooks;
12
- defaultFetchUrl?: string;
13
- }): void;
12
+ url?: string;
13
+ }
14
+ export declare const VConfig: Config;
14
15
  export declare function fetchVQL<T = any>(query: VqlQueryRaw<T>, hookContext?: any): Promise<T>;
15
- export declare function resetVQLClient(): void;
16
- export declare function defaultFetchTransport(query: VqlQueryRaw): Promise<any>;
16
+ export declare function defTransport(query: VqlQueryRaw): Promise<any>;
package/dist/index.js CHANGED
@@ -1,15 +1,11 @@
1
- let transport = defaultFetchTransport;
2
- let hooks = {};
3
- let defaultFetchUrl = "/VQL";
4
- export function initVQLClient(config) {
5
- if (config.transport)
6
- transport = config.transport;
7
- if (config.hooks)
8
- hooks = config.hooks;
9
- if (config.defaultFetchUrl)
10
- defaultFetchUrl = config.defaultFetchUrl;
11
- }
1
+ ;
2
+ export const VConfig = {
3
+ transport: defTransport,
4
+ hooks: {},
5
+ url: "/VQL"
6
+ };
12
7
  export async function fetchVQL(query, hookContext = {}) {
8
+ const { transport, hooks } = VConfig;
13
9
  const start = Date.now();
14
10
  try {
15
11
  hooks.onStart?.(query, hookContext);
@@ -30,12 +26,8 @@ export async function fetchVQL(query, hookContext = {}) {
30
26
  throw e;
31
27
  }
32
28
  }
33
- export function resetVQLClient() {
34
- transport = defaultFetchTransport;
35
- hooks = {};
36
- }
37
- export async function defaultFetchTransport(query) {
38
- const res = await fetch(defaultFetchUrl, {
29
+ export async function defTransport(query) {
30
+ const res = await fetch(VConfig.url, {
39
31
  method: "POST",
40
32
  headers: {
41
33
  "Content-Type": "application/json"
@@ -49,8 +41,7 @@ export async function defaultFetchTransport(query) {
49
41
  if (typeof window !== "undefined") {
50
42
  window.VQLClient = {
51
43
  fetchVQL,
52
- initVQLClient,
53
- resetVQLClient,
54
- defaultFetchTransport
44
+ defTransport,
45
+ cfg: VConfig
55
46
  };
56
47
  }
package/dist/min.js ADDED
@@ -0,0 +1 @@
1
+ var VQLClient=(()=>{var s=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var T=(n,r)=>{for(var a in r)s(n,a,{get:r[a],enumerable:!0})},R=(n,r,a,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Q(r))!L.call(n,o)&&o!==a&&s(n,o,{get:()=>r[o],enumerable:!(t=V(r,o))||t.enumerable});return n};var q=n=>R(s({},"__esModule",{value:!0}),n);var m={};T(m,{VConfig:()=>i,defTransport:()=>u,fetchVQL:()=>c});var i={transport:u,hooks:{},url:"/VQL"};async function c(n,r={}){var y,w,f,l;let{transport:a,hooks:t}=i,o=Date.now();try{(y=t.onStart)==null||y.call(t,n,r);let e=await a(n),d=Date.now()-o;if((w=t.onEnd)==null||w.call(t,n,d,e,r),e!=null&&e.err){let p=new Error(e.err);throw(f=t.onError)==null||f.call(t,n,p,e,r),p}return e.result!==void 0?e.result:e}catch(e){throw(l=t.onError)==null||l.call(t,n,e,null,r),e}}async function u(n){let r=await fetch(i.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:n})});if(!r.ok)throw new Error(`VQL request failed: ${r.status}`);return await r.json()}typeof window!="undefined"&&(window.VQLClient={fetchVQL:c,defTransport:u,cfg:i});return q(m);})();
package/dist/vql.d.ts CHANGED
@@ -80,23 +80,23 @@ export interface FindOpts<T = any> {
80
80
  exclude?: KeysMatching<T, any>[];
81
81
  transform?: Function;
82
82
  }
83
- declare class CollectionManager {
83
+ declare class CollectionManager<D = Data> {
84
84
  private db;
85
85
  private collection;
86
86
  constructor(db: ValtheraCompatible, collection: string);
87
- add<T = Data>(data: Arg, id_gen?: boolean): Promise<T>;
88
- find<T = Data>(search: Search, context?: VContext, options?: DbFindOpts, findOpts?: FindOpts): Promise<T[]>;
89
- findOne<T = Data>(search: Search, context?: VContext, findOpts?: FindOpts): Promise<T>;
90
- update(search: Search, updater: Updater, context?: VContext): Promise<boolean>;
91
- updateOne(search: Search, updater: Updater, context?: VContext): Promise<boolean>;
92
- remove(search: Search, context?: VContext): Promise<boolean>;
93
- removeOne(search: Search, context?: VContext): Promise<boolean>;
94
- updateOneOrAdd(search: Search, updater: Updater, add_arg?: Arg, context?: VContext, id_gen?: boolean): Promise<boolean>;
87
+ add<T = Data>(data: Arg<T & D>, id_gen?: boolean): Promise<T>;
88
+ find<T = Data>(search?: Search<T & D>, context?: VContext, options?: DbFindOpts<T & Data>, findOpts?: FindOpts<T & Data>): Promise<T[]>;
89
+ findOne<T = Data>(search?: Search<T & Data>, context?: VContext, findOpts?: FindOpts<T & Data>): Promise<T>;
90
+ update<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, context?: VContext): Promise<boolean>;
91
+ updateOne<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, context?: VContext): Promise<boolean>;
92
+ remove<T = Data>(search: Search<T & Data>, context?: VContext): Promise<boolean>;
93
+ removeOne<T = Data>(search: Search<T & Data>, context?: VContext): Promise<boolean>;
94
+ updateOneOrAdd<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, add_arg?: Arg<T & Data>, context?: VContext, id_gen?: boolean): Promise<boolean>;
95
95
  }
96
96
  export interface ValtheraCompatible {
97
97
  c(collection: string): CollectionManager;
98
98
  getCollections(): Promise<string[]>;
99
- checkCollection(collection: string): Promise<boolean>;
99
+ ensureCollection(collection: string): Promise<boolean>;
100
100
  issetCollection(collection: string): Promise<boolean>;
101
101
  add<T = Data>(collection: string, data: Arg<T>, id_gen?: boolean): Promise<T>;
102
102
  find<T = Data>(collection: string, search: Search<T>, context?: VContext, options?: DbFindOpts<T>, findOpts?: FindOpts<T>): Promise<T[]>;
@@ -148,7 +148,7 @@ export interface VQLQuery<T = any> {
148
148
  removeOne: VQLRemoveOne<T>;
149
149
  updateOneOrAdd: VQLUpdateOneOrAdd<T>;
150
150
  removeCollection: VQLCollectionOperation;
151
- checkCollection: VQLCollectionOperation;
151
+ ensureCollection: VQLCollectionOperation;
152
152
  issetCollection: VQLCollectionOperation;
153
153
  getCollections: {};
154
154
  }
@@ -173,7 +173,7 @@ export type VQLQueryData<T = any> = {
173
173
  } | {
174
174
  removeCollection: VQLCollectionOperation;
175
175
  } | {
176
- checkCollection: VQLCollectionOperation;
176
+ ensureCollection: VQLCollectionOperation;
177
177
  } | {
178
178
  issetCollection: VQLCollectionOperation;
179
179
  } | {
package/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql-client",
3
- "version": "0.0.12",
3
+ "version": "0.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
+ "description": "VQL Client",
7
+ "homepage": "https://github.com/wxn0brP/VQL-client",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/wxn0brP/VQL-client.git"
11
+ },
6
12
  "author": "wxn0brP",
7
13
  "license": "MIT",
8
14
  "type": "module",
9
15
  "devDependencies": {
10
- "esbuild": "^0.25.4",
11
- "tsc-alias": "^1.8.10",
12
- "typescript": "^5.7.3"
16
+ "esbuild": "^0.25.8",
17
+ "typescript": "^5.8.3"
13
18
  },
14
19
  "files": [
15
20
  "dist"
@@ -18,13 +23,11 @@
18
23
  ".": {
19
24
  "types": "./dist/index.d.ts",
20
25
  "import": "./dist/index.js",
21
- "require": "./dist/index.cjs",
22
26
  "default": "./dist/index.js"
23
27
  },
24
28
  "./*": {
25
29
  "types": "./dist/*.d.ts",
26
30
  "import": "./dist/*.js",
27
- "require": "./dist/*.cjs",
28
31
  "default": "./dist/*.js"
29
32
  }
30
33
  }
@@ -1,78 +0,0 @@
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
- var defaultFetchUrl = "/VQL";
31
- function initVQLClient(config) {
32
- if (config.transport) transport = config.transport;
33
- if (config.hooks) hooks = config.hooks;
34
- if (config.defaultFetchUrl) defaultFetchUrl = config.defaultFetchUrl;
35
- }
36
- async function fetchVQL(query, hookContext = {}) {
37
- var _a, _b, _c, _d;
38
- const start = Date.now();
39
- try {
40
- (_a = hooks.onStart) == null ? void 0 : _a.call(hooks, query, hookContext);
41
- const res = await transport(query);
42
- const duration = Date.now() - start;
43
- (_b = hooks.onEnd) == null ? void 0 : _b.call(hooks, query, duration, res, hookContext);
44
- if (res == null ? void 0 : res.err) {
45
- const error = new Error(res.err);
46
- (_c = hooks.onError) == null ? void 0 : _c.call(hooks, query, error, res, hookContext);
47
- throw error;
48
- }
49
- if (res.result !== void 0) return res.result;
50
- return res;
51
- } catch (e) {
52
- (_d = hooks.onError) == null ? void 0 : _d.call(hooks, query, e, null, hookContext);
53
- throw e;
54
- }
55
- }
56
- function resetVQLClient() {
57
- transport = defaultFetchTransport;
58
- hooks = {};
59
- }
60
- async function defaultFetchTransport(query) {
61
- const res = await fetch(defaultFetchUrl, {
62
- method: "POST",
63
- headers: {
64
- "Content-Type": "application/json"
65
- },
66
- body: JSON.stringify({ query })
67
- });
68
- if (!res.ok) throw new Error(`VQL request failed: ${res.status}`);
69
- return await res.json();
70
- }
71
- if (typeof window !== "undefined") {
72
- window.VQLClient = {
73
- fetchVQL,
74
- initVQLClient,
75
- resetVQLClient,
76
- defaultFetchTransport
77
- };
78
- }
@@ -1 +0,0 @@
1
- var VQLClient=(()=>{var i=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var R=(r,t)=>{for(var a in t)i(r,a,{get:t[a],enumerable:!0})},q=(r,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of T(t))!h.call(r,o)&&o!==a&&i(r,o,{get:()=>t[o],enumerable:!(s=L(t,o))||s.enumerable});return r};var m=r=>q(i({},"__esModule",{value:!0}),r);var x={};R(x,{defaultFetchTransport:()=>u,fetchVQL:()=>V,initVQLClient:()=>Q,resetVQLClient:()=>f});var l=u,e={},w="/VQL";function Q(r){r.transport&&(l=r.transport),r.hooks&&(e=r.hooks),r.defaultFetchUrl&&(w=r.defaultFetchUrl)}async function V(r,t={}){var s,o,y,p;let a=Date.now();try{(s=e.onStart)==null||s.call(e,r,t);let n=await l(r),c=Date.now()-a;if((o=e.onEnd)==null||o.call(e,r,c,n,t),n!=null&&n.err){let d=new Error(n.err);throw(y=e.onError)==null||y.call(e,r,d,n,t),d}return n.result!==void 0?n.result:n}catch(n){throw(p=e.onError)==null||p.call(e,r,n,null,t),n}}function f(){l=u,e={}}async function u(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:V,initVQLClient:Q,resetVQLClient:f,defaultFetchTransport:u});return m(x);})();