@wxn0brp/vql-orm 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 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,66 @@
1
+ # @wxn0brp/vql-orm
2
+
3
+ A lightweight and intuitive query builder for VQL (Valthera Query Language). This ORM-like library provides a fluent, chainable interface to construct VQL queries programmatically.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @wxn0brp/vql-orm @wxn0brp/vql-client
9
+ ```
10
+
11
+ **Note:** `@wxn0brp/vql-client` is a `peerDependency` and must be installed alongside this package.
12
+
13
+ ## Usage
14
+
15
+ The main entry point is the `VO` (VQL ORM) factory function, which creates a new query builder instance.
16
+
17
+ Here's a basic example of how to build a `find` query:
18
+
19
+ ```typescript
20
+ import { VO } from "@wxn0brp/vql-orm";
21
+
22
+ // Create a query builder instance for the "myShop" database
23
+ const qb = VO("myShop");
24
+
25
+ // Build a query
26
+ const userQuery = qb
27
+ .from("users")
28
+ .select("name", "email", "age")
29
+ .where({
30
+ status: "active",
31
+ $gt: { age: 18 }
32
+ })
33
+ .limit(10)
34
+ .query(); // This generates the final VQL query object and resets the builder
35
+
36
+ console.log(JSON.stringify(userQuery, null, 2));
37
+ ```
38
+
39
+ This will produce the following VQL query object:
40
+
41
+ ```json
42
+ {
43
+ "db": "myShop",
44
+ "d": {
45
+ "find": {
46
+ "collection": "users",
47
+ "search": {
48
+ "status": "active",
49
+ "$gt": {
50
+ "age": 18
51
+ }
52
+ },
53
+ "select": [
54
+ "name",
55
+ "email",
56
+ "age"
57
+ ],
58
+ "limit": 10
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ ## License
65
+
66
+ This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
@@ -0,0 +1,22 @@
1
+ import type { Search, VQLUQ } from "@wxn0brp/vql-client/vql";
2
+ export declare class VQL_ORM {
3
+ dbName: string;
4
+ _collection: string;
5
+ _select: string[];
6
+ _search: Search;
7
+ _limit: number;
8
+ _one: boolean;
9
+ _vars: Record<string, any>;
10
+ constructor(dbName: string);
11
+ setDbName(dbName: string): void;
12
+ from(collection: string): this;
13
+ select(...select: string[]): this;
14
+ where(search: Search): this;
15
+ limit(limit: number): this;
16
+ one(on?: boolean): this;
17
+ var(name: string, value: any): this;
18
+ vars(vars: Record<string, any>): this;
19
+ query(): VQLUQ;
20
+ reset(): void;
21
+ }
22
+ export declare function VO(db: string): VQL_ORM;
package/dist/index.js ADDED
@@ -0,0 +1,77 @@
1
+ import { deepMerge } from "./merge.js";
2
+ export class VQL_ORM {
3
+ dbName;
4
+ _collection;
5
+ _select;
6
+ _search;
7
+ _limit;
8
+ _one;
9
+ _vars;
10
+ constructor(dbName) {
11
+ this.dbName = dbName;
12
+ this.reset();
13
+ }
14
+ setDbName(dbName) {
15
+ this.dbName = dbName;
16
+ }
17
+ from(collection) {
18
+ this._collection = collection;
19
+ return this;
20
+ }
21
+ select(...select) {
22
+ this._select = (this._select || []).concat(select);
23
+ return this;
24
+ }
25
+ where(search) {
26
+ this._search = deepMerge(this._search, search);
27
+ return this;
28
+ }
29
+ limit(limit) {
30
+ this._limit = limit;
31
+ return this;
32
+ }
33
+ one(on = true) {
34
+ this._one = on;
35
+ return this;
36
+ }
37
+ var(name, value) {
38
+ this._vars[name] = value;
39
+ return this;
40
+ }
41
+ vars(vars) {
42
+ this._vars = deepMerge(this._vars, vars);
43
+ return this;
44
+ }
45
+ query() {
46
+ const op = "find" + (this._one ? "One" : "");
47
+ const q = {
48
+ db: this.dbName,
49
+ d: {}
50
+ };
51
+ const qData = {
52
+ collection: this._collection,
53
+ search: this._search,
54
+ };
55
+ if (Object.keys(this._select).length)
56
+ qData.select = this._select;
57
+ if (this._limit)
58
+ qData.limit = this._limit;
59
+ // @ts-ignore
60
+ q.d[op] = qData;
61
+ if (Object.keys(this._vars))
62
+ q.var = this._vars;
63
+ this.reset();
64
+ return q;
65
+ }
66
+ reset() {
67
+ this._collection = "";
68
+ this._select = [];
69
+ this._search = {};
70
+ this._limit = 0;
71
+ this._one = false;
72
+ this._vars = {};
73
+ }
74
+ }
75
+ export function VO(db) {
76
+ return new VQL_ORM(db);
77
+ }
@@ -0,0 +1 @@
1
+ export declare function deepMerge<T extends object>(...sources: T[]): T;
package/dist/merge.js ADDED
@@ -0,0 +1,16 @@
1
+ const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
2
+ export function deepMerge(...sources) {
3
+ const out = {};
4
+ for (const src of sources) {
5
+ for (const key in src) {
6
+ if (!Object.prototype.hasOwnProperty.call(src, key))
7
+ continue;
8
+ const sv = src[key];
9
+ const ov = out[key];
10
+ out[key] = isObj(sv) && isObj(ov)
11
+ ? deepMerge(ov, sv)
12
+ : sv;
13
+ }
14
+ }
15
+ return out;
16
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@wxn0brp/vql-orm",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "description": "",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/wxn0brP/VQL-orm.git"
10
+ },
11
+ "homepage": "https://github.com/wxn0brP/VQL-orm",
12
+ "author": "wxn0brP",
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "scripts": {
16
+ "build": "tsc && tsc-alias"
17
+ },
18
+ "devDependencies": {
19
+ "@types/bun": "*",
20
+ "@wxn0brp/vql-client": "^0.2.10",
21
+ "tsc-alias": "^1",
22
+ "typescript": "^6"
23
+ },
24
+ "peerDependencies": {
25
+ "@wxn0brp/vql-client": "^0.2.10"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "./*": {
37
+ "types": "./dist/*.d.ts",
38
+ "import": "./dist/*.js",
39
+ "default": "./dist/*.js"
40
+ }
41
+ }
42
+ }