@wxn0brp/vql 0.4.3 → 0.6.0-alpha.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/dist/valid.js CHANGED
@@ -1,38 +1,60 @@
1
- import Ajv from "ajv";
2
- import ajvFormat from "ajv-formats";
3
- import { readFileSync } from "fs";
4
- import { buildAjvErrorTree } from "./ajv.js";
5
- import { deepMerge } from "./merge.js";
6
- const filePath = import.meta.dirname + "/schema.json";
7
- const schema = JSON.parse(readFileSync(filePath, "utf-8"));
8
- export const ajv = new Ajv({
9
- allowUnionTypes: true,
10
- strict: false
11
- });
12
- ajvFormat(ajv);
13
- const validVQLR = ajv.compile(schema);
14
- const modSchema = schema;
15
- modSchema.anyOf = [
16
- {
17
- "$ref": "#/definitions/VQL"
18
- }
19
- ];
20
- const validVQL = ajv.compile(modSchema);
21
- export function validateRaw(config, query) {
22
- if (!validVQLR(query)) {
23
- let why = validVQLR.errors;
24
- why = config.formatAjv ? buildAjvErrorTree(why) : why;
25
- why = deepMerge(why, query);
26
- return { err: true, msg: "Invalid query raw", c: 400, why };
27
- }
1
+ function emptyErr() {
2
+ return {
3
+ err: true,
4
+ msg: "Bad query",
5
+ c: 400
6
+ };
7
+ }
8
+ function isObj(obj, one = true) {
9
+ return typeof obj === "object" && obj !== null && !Array.isArray(obj) && (!one || Object.keys(obj).length !== 0);
10
+ }
11
+ export function validateRaw(query) {
12
+ if (("r" in query && isObj(query.r)) ||
13
+ ("db" in query && typeof query.db === "string" && isObj(query.d)) ||
14
+ ("ref" in query && isObj(query.ref)))
15
+ return true;
16
+ return emptyErr();
17
+ }
18
+ function validR(query) {
19
+ const { r } = query;
20
+ if (!("path" in r) || !Array.isArray(r.path) || r.path.length !== 2)
21
+ return emptyErr();
22
+ if (!isObj(r.search, false))
23
+ return emptyErr();
28
24
  return true;
29
25
  }
30
- export function validateVql(config, query) {
31
- if (!validVQL(query)) {
32
- let why = validVQL.errors;
33
- why = config.formatAjv ? buildAjvErrorTree(why) : why;
34
- why = deepMerge(why, query);
35
- return { err: true, msg: "Invalid query", c: 400, why };
26
+ function validD(query) {
27
+ const { d } = query;
28
+ const key = Object.keys(d)[0];
29
+ if (key === "getCollection")
30
+ return true;
31
+ const value = d[key];
32
+ if (typeof value.collection !== "string" || value.collection.trim() === "")
33
+ return emptyErr();
34
+ if (key === "issetCollection" || key === "ensureCollection")
35
+ return true;
36
+ if (key === "add") {
37
+ if (!isObj(value.data, false))
38
+ return emptyErr();
39
+ else
40
+ return true;
41
+ }
42
+ if ("search" in value && !isObj(value.search))
43
+ return emptyErr();
44
+ if (key === "find" || key === "findOne" || key === "remove" || key === "removeOne")
45
+ return true;
46
+ if (key === "update" || key === "updateOne" || key === "updateOneOrAdd") {
47
+ if (!isObj(value.updater, false))
48
+ return emptyErr();
49
+ else
50
+ return true;
36
51
  }
37
52
  return true;
38
53
  }
54
+ export function validateVql(query) {
55
+ if ("r" in query && isObj(query.r))
56
+ return validR(query);
57
+ if ("d" in query && isObj(query.d))
58
+ return validD(query);
59
+ return emptyErr();
60
+ }
package/dist/vql.d.ts CHANGED
@@ -108,47 +108,47 @@ export interface FindOpts<T = any> {
108
108
  exclude?: KeysMatching<T, any>[];
109
109
  transform?: Function;
110
110
  }
111
- declare class CollectionManager {
111
+ declare class CollectionManager<D = Data> {
112
112
  private db;
113
113
  private collection;
114
114
  constructor(db: ValtheraCompatible, collection: string);
115
115
  /**
116
116
  * Add data to a database.
117
117
  */
118
- add<T = Data>(data: Arg, id_gen?: boolean): Promise<T>;
118
+ add<T = Data>(data: Arg<T & D>, id_gen?: boolean): Promise<T>;
119
119
  /**
120
120
  * Find data in a database.
121
121
  */
122
- find<T = Data>(search: Search, context?: VContext, options?: DbFindOpts, findOpts?: FindOpts): Promise<T[]>;
122
+ find<T = Data>(search?: Search<T & D>, context?: VContext, options?: DbFindOpts<T & Data>, findOpts?: FindOpts<T & Data>): Promise<T[]>;
123
123
  /**
124
124
  * Find one data entry in a database.
125
125
  */
126
- findOne<T = Data>(search: Search, context?: VContext, findOpts?: FindOpts): Promise<T>;
126
+ findOne<T = Data>(search?: Search<T & Data>, context?: VContext, findOpts?: FindOpts<T & Data>): Promise<T>;
127
127
  /**
128
128
  * Update data in a database.
129
129
  */
130
- update(search: Search, updater: Updater, context?: VContext): Promise<boolean>;
130
+ update<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, context?: VContext): Promise<boolean>;
131
131
  /**
132
132
  * Update one data entry in a database.
133
133
  */
134
- updateOne(search: Search, updater: Updater, context?: VContext): Promise<boolean>;
134
+ updateOne<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, context?: VContext): Promise<boolean>;
135
135
  /**
136
136
  * Remove data from a database.
137
137
  */
138
- remove(search: Search, context?: VContext): Promise<boolean>;
138
+ remove<T = Data>(search: Search<T & Data>, context?: VContext): Promise<boolean>;
139
139
  /**
140
140
  * Remove one data entry from a database.
141
141
  */
142
- removeOne(search: Search, context?: VContext): Promise<boolean>;
142
+ removeOne<T = Data>(search: Search<T & Data>, context?: VContext): Promise<boolean>;
143
143
  /**
144
144
  * Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
145
145
  */
146
- updateOneOrAdd(search: Search, updater: Updater, add_arg?: Arg, context?: VContext, id_gen?: boolean): Promise<boolean>;
146
+ updateOneOrAdd<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, add_arg?: Arg<T & Data>, context?: VContext, id_gen?: boolean): Promise<boolean>;
147
147
  }
148
148
  export interface ValtheraCompatible {
149
149
  c(collection: string): CollectionManager;
150
150
  getCollections(): Promise<string[]>;
151
- checkCollection(collection: string): Promise<boolean>;
151
+ ensureCollection(collection: string): Promise<boolean>;
152
152
  issetCollection(collection: string): Promise<boolean>;
153
153
  add<T = Data>(collection: string, data: Arg<T>, id_gen?: boolean): Promise<T>;
154
154
  find<T = Data>(collection: string, search: Search<T>, context?: VContext, options?: DbFindOpts<T>, findOpts?: FindOpts<T>): Promise<T[]>;
@@ -200,7 +200,7 @@ export interface VQLQuery<T = any> {
200
200
  removeOne: VQLRemoveOne<T>;
201
201
  updateOneOrAdd: VQLUpdateOneOrAdd<T>;
202
202
  removeCollection: VQLCollectionOperation;
203
- checkCollection: VQLCollectionOperation;
203
+ ensureCollection: VQLCollectionOperation;
204
204
  issetCollection: VQLCollectionOperation;
205
205
  getCollections: {};
206
206
  }
@@ -225,7 +225,7 @@ export type VQLQueryData<T = any> = {
225
225
  } | {
226
226
  removeCollection: VQLCollectionOperation;
227
227
  } | {
228
- checkCollection: VQLCollectionOperation;
228
+ ensureCollection: VQLCollectionOperation;
229
229
  } | {
230
230
  issetCollection: VQLCollectionOperation;
231
231
  } | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql",
3
- "version": "0.4.3",
3
+ "version": "0.6.0-alpha.0",
4
4
  "main": "dist/index.js",
5
5
  "author": "wxn0brP",
6
6
  "license": "MIT",
@@ -15,8 +15,9 @@
15
15
  "dist"
16
16
  ],
17
17
  "peerDependencies": {
18
- "@wxn0brp/db-core": ">=0.0.1 <0.1.0",
19
- "@wxn0brp/falcon-frame": ">=0.0.18"
18
+ "@wxn0brp/db-core": ">=0.1.4",
19
+ "@wxn0brp/falcon-frame": ">=0.0.20",
20
+ "@wxn0brp/gate-warden": ">=0.4.0"
20
21
  },
21
22
  "peerDependenciesMeta": {
22
23
  "@wxn0brp/falcon-frame": {
@@ -24,25 +25,23 @@
24
25
  },
25
26
  "@wxn0brp/db-core": {
26
27
  "optional": false
28
+ },
29
+ "@wxn0brp/gate-warden": {
30
+ "optional": true
27
31
  }
28
32
  },
29
33
  "devDependencies": {
30
- "@types/node": "^24.0.13",
31
- "@wxn0brp/db": "^0.20.1",
32
- "@wxn0brp/falcon-frame": "0.0.18",
34
+ "@types/node": "^24.1.0",
35
+ "@wxn0brp/db": "^0.30.0",
36
+ "@wxn0brp/falcon-frame": "0.0.20",
37
+ "@wxn0brp/gate-warden": "^0.4.0",
33
38
  "dotenv": "^17.2.0",
34
- "source-map-support": "^0.5.21",
39
+ "esbuild": "^0.25.8",
35
40
  "tsc-alias": "^1.8.10",
36
- "typescript": "^5.7.3",
37
- "typescript-json-schema": "^0.65.1"
41
+ "typescript": "^5.7.3"
38
42
  },
39
43
  "dependencies": {
40
- "@wxn0brp/gate-warden": ">=0.3.0",
41
- "@wxn0brp/lucerna-log": "^0.1.1",
42
- "ajv": "^8.17.1",
43
- "ajv-formats": "^3.0.1",
44
- "js-yaml": "^4.1.0",
45
- "json5": "^2.2.3"
44
+ "@wxn0brp/lucerna-log": "^0.1.1"
46
45
  },
47
46
  "exports": {
48
47
  ".": {
package/dist/ajv.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { ErrorObject } from "ajv";
2
- export declare function buildAjvErrorTree(errors: ErrorObject[]): Record<string, any>;
package/dist/ajv.js DELETED
@@ -1,80 +0,0 @@
1
- function parseInstancePath(path) {
2
- if (!path)
3
- return [];
4
- const unescaped = path.slice(1).replace(/~0/g, "~").replace(/~1/g, "/");
5
- return unescaped.split("/").filter(seg => seg !== "");
6
- }
7
- function formatSingleError(error) {
8
- const { keyword, params, message } = error;
9
- switch (keyword) {
10
- case "type":
11
- return `expected type: ${params.type}`;
12
- case "required":
13
- return `missing required property: ${params.missingProperty}`;
14
- case "additionalProperties":
15
- return `unexpected property: ${params.additionalProperty}`;
16
- case "enum":
17
- const allowedValues = params.allowedValues.join(", ");
18
- return `value not in: [${allowedValues}]`;
19
- case "minLength":
20
- return `too short (min ${params.limit} characters)`;
21
- case "maxLength":
22
- return `too long (max ${params.limit} characters)`;
23
- case "minimum":
24
- return `value < ${params.limit}`;
25
- case "maximum":
26
- return `value > ${params.limit}`;
27
- case "pattern":
28
- return `does not match pattern`;
29
- case "anyOf":
30
- return `value does not satisfy any of the variants`;
31
- case "oneOf":
32
- return `value satisfies multiple variants`;
33
- case "allOf":
34
- return `value does not satisfy all conditions`;
35
- default:
36
- return message || `validation error: ${keyword}`;
37
- }
38
- }
39
- // Recursively remove error types and leave only messages
40
- function finalizeNode(node) {
41
- if (node.__errors) {
42
- node.__errors = node.__errors.map((e) => e.message);
43
- }
44
- for (const key in node) {
45
- if (key !== "__errors" && typeof node[key] === "object") {
46
- finalizeNode(node[key]);
47
- }
48
- }
49
- }
50
- export function buildAjvErrorTree(errors) {
51
- const errorTree = {};
52
- for (const error of errors) {
53
- const segments = parseInstancePath(error.instancePath);
54
- let currentNode = errorTree;
55
- for (const segment of segments) {
56
- if (!(segment in currentNode)) {
57
- currentNode[segment] = {};
58
- }
59
- currentNode = currentNode[segment];
60
- }
61
- const formattedMessage = formatSingleError(error);
62
- const isComposite = ["anyOf", "oneOf", "allOf"].includes(error.keyword);
63
- if (!currentNode.__errors) {
64
- currentNode.__errors = [];
65
- }
66
- if (isComposite) {
67
- // Replace all previous errors with only this general one
68
- currentNode.__errors = [{ keyword: error.keyword, message: formattedMessage }];
69
- }
70
- else {
71
- // Check if there is already a general error
72
- const hasComposite = currentNode.__errors.some((e) => ["anyOf", "oneOf", "allOf"].includes(e.keyword));
73
- if (!hasComposite) {
74
- currentNode.__errors.push({ keyword: error.keyword, message: formattedMessage });
75
- }
76
- }
77
- }
78
- finalizeNode(errorTree);
79
- return errorTree;
80
- }
@@ -1,2 +0,0 @@
1
- import { VQL } from "../../types/vql.js";
2
- export declare function parseVQLB(query: string): VQL;
@@ -1,8 +0,0 @@
1
- import JSON5 from "json5";
2
- import { extractMeta } from "./utils.js";
3
- import { processVQL_MB } from "./middle.js";
4
- export function parseVQLB(query) {
5
- const { db, op, collection, body } = extractMeta(query);
6
- const parsed = JSON5.parse(body);
7
- return processVQL_MB(db, op, collection, parsed);
8
- }
@@ -1,3 +0,0 @@
1
- import { VQL } from "../../types/vql.js";
2
- export declare function processVQL_MB(db: string, op: string, collection: string, parsed: Record<string, any>): VQL;
3
- export declare function convertSearchObjToSearchArray(obj: Record<string, any>, parentKeys?: string[]): string[][];
@@ -1,41 +0,0 @@
1
- export function processVQL_MB(db, op, collection, parsed) {
2
- return "relations" in parsed ?
3
- processRelation_MB(db, collection, parsed) :
4
- processQuery_MB(db, op, collection, parsed);
5
- }
6
- export function convertSearchObjToSearchArray(obj, parentKeys = []) {
7
- return Object.entries(obj).reduce((acc, [key, value]) => {
8
- const currentPath = [...parentKeys, key];
9
- if (!value) {
10
- return acc;
11
- }
12
- else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
13
- return [...acc, ...convertSearchObjToSearchArray(value, currentPath)];
14
- }
15
- else {
16
- return [...acc, currentPath];
17
- }
18
- }, []);
19
- }
20
- function processRelation_MB(db, collection, parsed) {
21
- if ("select" in parsed && typeof parsed.select === "object" && !Array.isArray(parsed.select)) {
22
- parsed.select = convertSearchObjToSearchArray(parsed.select);
23
- }
24
- return {
25
- r: {
26
- path: [parsed.db || db, parsed.c || collection],
27
- ...parsed
28
- }
29
- };
30
- }
31
- function processQuery_MB(db, op, collection, parsed) {
32
- return {
33
- db,
34
- d: {
35
- [op]: {
36
- collection,
37
- ...parsed
38
- }
39
- }
40
- };
41
- }
@@ -1,2 +0,0 @@
1
- import { VQL } from "../../types/vql.js";
2
- export declare function parseVQLS(query: string): VQL;
@@ -1,155 +0,0 @@
1
- import { extractMeta } from "./utils.js";
2
- import JSON5 from "json5";
3
- import { convertSearchObjToSearchArray } from "./middle.js";
4
- const aliases = {
5
- s: "search",
6
- f: "fields",
7
- o: "options",
8
- r: "relations",
9
- d: "data",
10
- e: "select",
11
- u: "updater",
12
- };
13
- function parseArgs(input) {
14
- const result = {};
15
- const tokens = [];
16
- let current = "";
17
- let inQuotes = false;
18
- let escape = false;
19
- for (let i = 0; i < input.length; i++) {
20
- const char = input[i];
21
- if (escape) {
22
- current += char;
23
- escape = false;
24
- }
25
- else if (char === "\\") {
26
- escape = true;
27
- }
28
- else if (char === "\"") {
29
- inQuotes = !inQuotes;
30
- }
31
- else if (!inQuotes && (char === " " || char === "=")) {
32
- if (current !== "") {
33
- tokens.push(current);
34
- current = "";
35
- }
36
- }
37
- else {
38
- current += char;
39
- }
40
- }
41
- if (current !== "") {
42
- tokens.push(current);
43
- }
44
- for (let i = 0; i < tokens.length; i += 2) {
45
- const key = tokens[i];
46
- let value = tokens[i + 1] ?? true;
47
- if (typeof value === "string") {
48
- const trimmed = value.trim();
49
- if (trimmed === "") {
50
- value = true;
51
- }
52
- else if (/^".*"$/.test(trimmed)) {
53
- value = trimmed.slice(1, -1);
54
- }
55
- else if (trimmed.toLowerCase() === "true") {
56
- value = true;
57
- }
58
- else if (trimmed.toLowerCase() === "false") {
59
- value = false;
60
- }
61
- else if (!isNaN(Number(trimmed))) {
62
- value = Number(trimmed);
63
- }
64
- else if ((trimmed.startsWith("{") && trimmed.endsWith("}")) || (trimmed.startsWith("[") && trimmed.endsWith("]"))) {
65
- try {
66
- value = JSON5.parse(trimmed);
67
- }
68
- catch { }
69
- }
70
- }
71
- result[key] = value;
72
- }
73
- return result;
74
- }
75
- function buildVQL(db, op, collection, query) {
76
- const hasRelations = "relations" in query;
77
- if (hasRelations) {
78
- const relations = {};
79
- for (const key in query.relations) {
80
- const value = query.relations[key];
81
- relations[key] = {
82
- path: [value.db || db, value.c || key],
83
- ...value
84
- };
85
- delete relations[key].db;
86
- delete relations[key].c;
87
- }
88
- if ("select" in query) {
89
- query.select = convertSearchObjToSearchArray(query.select);
90
- }
91
- return {
92
- r: {
93
- path: [db, collection],
94
- ...query,
95
- relations,
96
- }
97
- };
98
- }
99
- else {
100
- if (query.fields && !query.select) {
101
- query.select = query.fields;
102
- delete query.fields;
103
- }
104
- if ("select" in query) {
105
- query.select = [...new Set(convertSearchObjToSearchArray(query.select).map(k => k[0]).flat())];
106
- }
107
- return {
108
- db,
109
- d: {
110
- [op]: {
111
- collection,
112
- ...query,
113
- }
114
- }
115
- };
116
- }
117
- }
118
- export function parseVQLS(query) {
119
- const { db, op, collection, body } = extractMeta(query);
120
- const parsed = parseArgs(body);
121
- for (const keysRaw of Object.keys(parsed)) {
122
- const keys = keysRaw.split(".");
123
- if (keys.length === 1) {
124
- continue;
125
- }
126
- let obj = parsed;
127
- for (let i = 0; i < keys.length; i++) {
128
- const key = keys[i];
129
- if (i < keys.length - 1) {
130
- if (!(key in obj)) {
131
- obj[key] = {};
132
- }
133
- obj = obj[key];
134
- }
135
- else {
136
- obj[key] = parsed[keysRaw];
137
- delete parsed[keysRaw];
138
- }
139
- }
140
- }
141
- for (const key in aliases) {
142
- if (key in parsed) {
143
- parsed[aliases[key]] = parsed[key];
144
- delete parsed[key];
145
- }
146
- }
147
- if ((op === "find" || op === "findOne") && !("search" in parsed)) {
148
- parsed.search = {};
149
- }
150
- if ((op === "update" || op === "remove") && !("updater" in parsed) && ("data" in parsed)) {
151
- parsed.updater = parsed.data;
152
- delete parsed.data;
153
- }
154
- return buildVQL(db, op, collection, parsed);
155
- }
@@ -1,2 +0,0 @@
1
- import { VQL } from "../../types/vql.js";
2
- export declare function parseVQLM(query: string): VQL;
@@ -1,19 +0,0 @@
1
- import { processVQL_MB } from "./middle.js";
2
- import { extractMeta } from "./utils.js";
3
- import yaml from "js-yaml";
4
- export function parseVQLM(query) {
5
- const { db, op, collection } = extractMeta(query);
6
- let lineEndIndex = 0;
7
- let foundNonWhitespace = false;
8
- for (let i = 0; i < query.length; i++) {
9
- if (!foundNonWhitespace && query[i] !== " " && query[i] !== "\t" && query[i] !== "\r" && query[i] !== "\n")
10
- foundNonWhitespace = true;
11
- if (foundNonWhitespace && query[i] === "\n") {
12
- lineEndIndex = i;
13
- break;
14
- }
15
- }
16
- const body = query.slice(lineEndIndex + 1);
17
- const parsed = yaml.load(body);
18
- return processVQL_MB(db, op, collection, parsed);
19
- }
package/dist/schema.json DELETED
@@ -1 +0,0 @@
1
- {"anyOf":[{"$ref":"#/definitions/VQLRefRequired"},{"allOf":[{"$ref":"#/definitions/VQLRequest"},{"$ref":"#/definitions/VQLRef"}]},{"allOf":[{"$ref":"#/definitions/RelationQuery"},{"$ref":"#/definitions/VQLRef"}]},{"allOf":[{"$ref":"#/definitions/DeepPartial<VQLRequest&VQLRef>"},{"$ref":"#/definitions/VQLRef"},{"$ref":"#/definitions/Required<Pick<VQLRef,\"ref\">>"}]},{"allOf":[{"$ref":"#/definitions/DeepPartial<RelationQuery&VQLRef>"},{"$ref":"#/definitions/VQLRef"},{"$ref":"#/definitions/Required<Pick<VQLRef,\"ref\">>"}]}],"definitions":{"VQLRefRequired":{"allOf":[{"$ref":"#/definitions/VQLRef"},{"$ref":"#/definitions/Required<Pick<VQLRef,\"ref\">>"}]},"VQLRef":{"type":"object","properties":{"ref":{"type":"string"},"var":{"type":"object","additionalProperties":{}}}},"Required<Pick<VQLRef,\"ref\">>":{"type":"object","properties":{"ref":{"type":"string"}},"required":["ref"]},"VQLRequest":{"type":"object","properties":{"db":{"type":"string"},"d":{"$ref":"#/definitions/VQLQueryData"}},"required":["d","db"]},"VQLQueryData":{"anyOf":[{"type":"object","properties":{"find":{"$ref":"#/definitions/VQLFind"}},"required":["find"]},{"type":"object","properties":{"findOne":{"$ref":"#/definitions/VQLFindOne"}},"required":["findOne"]},{"type":"object","properties":{"f":{"$ref":"#/definitions/VQLFindOne"}},"required":["f"]},{"type":"object","properties":{"add":{"$ref":"#/definitions/VQLAdd"}},"required":["add"]},{"type":"object","properties":{"update":{"$ref":"#/definitions/VQLUpdate"}},"required":["update"]},{"type":"object","properties":{"updateOne":{"$ref":"#/definitions/VQLUpdateOne"}},"required":["updateOne"]},{"type":"object","properties":{"remove":{"$ref":"#/definitions/VQLRemove"}},"required":["remove"]},{"type":"object","properties":{"removeOne":{"$ref":"#/definitions/VQLRemoveOne"}},"required":["removeOne"]},{"type":"object","properties":{"updateOneOrAdd":{"$ref":"#/definitions/VQLUpdateOneOrAdd"}},"required":["updateOneOrAdd"]},{"type":"object","properties":{"removeCollection":{"$ref":"#/definitions/VQLCollectionOperation"}},"required":["removeCollection"]},{"type":"object","properties":{"checkCollection":{"$ref":"#/definitions/VQLCollectionOperation"}},"required":["checkCollection"]},{"type":"object","properties":{"issetCollection":{"$ref":"#/definitions/VQLCollectionOperation"}},"required":["issetCollection"]},{"type":"object","properties":{"getCollections":{"type":"object","properties":{}}},"required":["getCollections"]}]},"VQLFind":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/Search<any>"},"limit":{"type":"number"},"fields":{"$ref":"#/definitions/VQLFields"},"select":{"$ref":"#/definitions/VQLFields"},"relations":{"$ref":"#/definitions/VQLRelations"},"options":{"$ref":"#/definitions/DbFindOpts"},"searchOpts":{"$ref":"#/definitions/FindOpts"}},"required":["collection"]},"Search<any>":{"anyOf":[{"$ref":"#/definitions/SearchOptions","description":"SearchOptions can be either a function or an object with predefined operators."},{"type":"object"}]},"SearchOptions":{"description":"SearchOptions can be either a function or an object with predefined operators.","allOf":[{"description":"Logical Operators","type":"object","properties":{"$and":{"description":"Recursively applies multiple conditions, all of which must evaluate to true.\nCan include other operators such as $gt, $exists, or nested $and/$or conditions.","type":"array","items":{"$ref":"#/definitions/SearchOptions"}},"$or":{"description":"Recursively applies multiple conditions, at least one of which must evaluate to true.\nCan include other operators such as $lt, $type, or nested $and/$or conditions.","type":"array","items":{"$ref":"#/definitions/SearchOptions"}},"$not":{"$ref":"#/definitions/SearchOptions","description":"Negates a single condition.\nCan include any other operator as its value."}}},{"description":"Comparison Operators","type":"object","properties":{"$gt":{"$ref":"#/definitions/Record<string,number>"},"$lt":{"$ref":"#/definitions/Record<string,number>"},"$gte":{"$ref":"#/definitions/Record<string,number>"},"$lte":{"$ref":"#/definitions/Record<string,number>"},"$in":{"$ref":"#/definitions/Record<string,any[]>"},"$nin":{"$ref":"#/definitions/Record<string,any[]>"},"$between":{"$ref":"#/definitions/Record<string,[number,number]>"}}},{"description":"Type and Existence Operators","type":"object","properties":{"$exists":{"$ref":"#/definitions/Record<string,boolean>"},"$type":{"$ref":"#/definitions/Record<string,string>"}}},{"description":"Array Operators","type":"object","properties":{"$arrinc":{"$ref":"#/definitions/Record<string,any[]>"},"$arrincall":{"$ref":"#/definitions/Record<string,any[]>"},"$size":{"$ref":"#/definitions/Record<string,number>"}}},{"description":"String Operators","type":"object","properties":{"$regex":{"$ref":"#/definitions/Record<string,RegExp>"},"$startsWith":{"$ref":"#/definitions/Record<string,string>"},"$endsWith":{"$ref":"#/definitions/Record<string,string>"}}},{"description":"Other Operators","type":"object","properties":{"$subset":{"$ref":"#/definitions/Record<string,any>"}}},{"$ref":"#/definitions/Arg"}]},"Record<string,number>":{"type":"object"},"Record<string,any[]>":{"type":"object"},"Record<string,[number,number]>":{"type":"object"},"Record<string,boolean>":{"type":"object"},"Record<string,string>":{"type":"object"},"Record<string,RegExp>":{"type":"object"},"Record<string,any>":{"type":"object"},"Arg":{"type":"object","additionalProperties":{},"properties":{"_id":{"type":"string"}}},"VQLFields":{"anyOf":[{"type":"array","items":{"type":"string"}},{"$ref":"#/definitions/Record<string,number|boolean>"}]},"Record<string,number|boolean>":{"type":"object"},"VQLRelations":{"type":"object"},"DbFindOpts":{"type":"object","properties":{"reverse":{"type":"boolean"},"max":{"type":"number"},"offset":{"type":"number"},"sortBy":{"type":"string"},"sortAsc":{"type":"boolean"}}},"FindOpts":{"type":"object","properties":{"select":{"type":"array","items":{"type":"string"}},"exclude":{"type":"array","items":{"type":"string"}},"transform":{"$ref":"#/definitions/Function"}}},"Function":{"type":"object","properties":{"prototype":{},"length":{"type":"number"},"arguments":{},"caller":{"$ref":"#/definitions/Function"},"name":{"type":"string"}},"required":["arguments","caller","length","name","prototype"]},"VQLFindOne":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/Search<any>"},"fields":{"$ref":"#/definitions/VQLFields"},"select":{"$ref":"#/definitions/VQLFields"},"relations":{"$ref":"#/definitions/VQLRelations"},"searchOpts":{"$ref":"#/definitions/FindOpts"}},"required":["collection","search"]},"VQLAdd":{"type":"object","properties":{"collection":{"type":"string"},"data":{"$ref":"#/definitions/Arg"},"id_gen":{"type":"boolean"}},"required":["collection","data"]},"VQLUpdate":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/Search<any>"},"updater":{"$ref":"#/definitions/UpdaterArg"}},"required":["collection","search","updater"]},"UpdaterArg":{"allOf":[{"description":"Arrays","type":"object","properties":{"$push":{},"$pushset":{"description":"Pushes items into an array and removes duplicates"},"$pull":{},"$pullall":{}}},{"description":"Objects","type":"object","properties":{"$merge":{}}},{"description":"Values","type":"object","properties":{"$set":{},"$inc":{},"$dec":{},"$unset":{},"$rename":{}}},{"type":"object","additionalProperties":{}}]},"VQLUpdateOne":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/Search<any>"},"updater":{"$ref":"#/definitions/UpdaterArg"}},"required":["collection","search","updater"]},"VQLRemove":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/Search<any>"}},"required":["collection","search"]},"VQLRemoveOne":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/Search<any>"}},"required":["collection","search"]},"VQLUpdateOneOrAdd":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/Search<any>"},"updater":{"$ref":"#/definitions/UpdaterArg"},"add_arg":{"$ref":"#/definitions/Arg"},"id_gen":{"type":"boolean"}},"required":["collection","search","updater"]},"VQLCollectionOperation":{"type":"object","properties":{"collection":{"type":"string"}},"required":["collection"]},"RelationQuery":{"type":"object","properties":{"r":{"type":"object","properties":{"path":{"type":"array","items":[{"type":"string"},{"type":"string"}],"minItems":2,"maxItems":2},"search":{"$ref":"#/definitions/Search<any>"},"relations":{"$ref":"#/definitions/RelationTypes.Relation"},"many":{"type":"boolean"},"options":{"$ref":"#/definitions/DbFindOpts"},"select":{"type":"array","items":{"type":"array","items":{"type":"string"}}}},"required":["path","relations","search"]}},"required":["r"]},"RelationTypes.Relation":{"type":"object","additionalProperties":{"$ref":"#/definitions/RelationTypes.RelationConfig"}},"RelationTypes.RelationConfig":{"type":"object","properties":{"path":{"type":"array","items":[{"type":"string"},{"type":"string"}],"minItems":2,"maxItems":2},"pk":{"type":"string"},"fk":{"type":"string"},"as":{"type":"string"},"select":{"type":"array","items":{"type":"string"}},"findOpts":{"$ref":"#/definitions/DbFindOpts"},"type":{"enum":["1","11","1n","nm"],"type":"string"},"relations":{"$ref":"#/definitions/RelationTypes.Relation"},"through":{"type":"object","properties":{"table":{"type":"string"},"db":{"type":"string"},"pk":{"type":"string"},"fk":{"type":"string"}},"required":["fk","pk","table"]}},"required":["path"]},"DeepPartial<VQLRequest&VQLRef>":{"type":"object","properties":{"db":{"type":"string"},"d":{"$ref":"#/definitions/DeepPartial<VQLQueryData>"},"ref":{"type":"string"},"var":{"$ref":"#/definitions/DeepPartial<{[k:string]:any;}>"}}},"DeepPartial<VQLQueryData>":{"anyOf":[{"$ref":"#/definitions/DeepPartial<{find:VQLFind;}>"},{"$ref":"#/definitions/DeepPartial<{findOne:VQLFindOne;}>"},{"$ref":"#/definitions/DeepPartial<{f:VQLFindOne;}>"},{"$ref":"#/definitions/DeepPartial<{add:VQLAdd;}>"},{"$ref":"#/definitions/DeepPartial<{update:VQLUpdate;}>"},{"$ref":"#/definitions/DeepPartial<{updateOne:VQLUpdateOne;}>"},{"$ref":"#/definitions/DeepPartial<{remove:VQLRemove;}>"},{"$ref":"#/definitions/DeepPartial<{removeOne:VQLRemoveOne;}>"},{"$ref":"#/definitions/DeepPartial<{updateOneOrAdd:VQLUpdateOneOrAdd;}>"},{"$ref":"#/definitions/DeepPartial<{removeCollection:VQLCollectionOperation;}>"},{"$ref":"#/definitions/DeepPartial<{checkCollection:VQLCollectionOperation;}>"},{"$ref":"#/definitions/DeepPartial<{issetCollection:VQLCollectionOperation;}>"},{"$ref":"#/definitions/DeepPartial<{getCollections:{};}>"}]},"DeepPartial<{find:VQLFind;}>":{"type":"object","properties":{"find":{"$ref":"#/definitions/DeepPartial<VQLFind>"}}},"DeepPartial<VQLFind>":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/DeepPartial<Search<any>>"},"limit":{"type":"number"},"fields":{"$ref":"#/definitions/DeepPartial<VQLFields>"},"select":{"$ref":"#/definitions/DeepPartial<VQLFields>"},"relations":{"$ref":"#/definitions/DeepPartial<VQLRelations>"},"options":{"$ref":"#/definitions/DeepPartial<DbFindOpts>"},"searchOpts":{"$ref":"#/definitions/DeepPartial<FindOpts>"}}},"DeepPartial<Search<any>>":{"anyOf":[{"$ref":"#/definitions/DeepPartial<SearchOptions>"},{"$ref":"#/definitions/DeepPartial<SearchFunc<any>>"}]},"DeepPartial<SearchOptions>":{"type":"object","properties":{"$and":{"description":"Recursively applies multiple conditions, all of which must evaluate to true.\nCan include other operators such as $gt, $exists, or nested $and/$or conditions.","type":"array","items":{"$ref":"#/definitions/DeepPartial<SearchOptions>_1"}},"$or":{"description":"Recursively applies multiple conditions, at least one of which must evaluate to true.\nCan include other operators such as $lt, $type, or nested $and/$or conditions.","type":"array","items":{"$ref":"#/definitions/DeepPartial<SearchOptions>_1"}},"$not":{"$ref":"#/definitions/DeepPartial<SearchOptions>_1","description":"Negates a single condition.\nCan include any other operator as its value."},"$gt":{"$ref":"#/definitions/DeepPartial<Record<string,number>>"},"$lt":{"$ref":"#/definitions/DeepPartial<Record<string,number>>"},"$gte":{"$ref":"#/definitions/DeepPartial<Record<string,number>>"},"$lte":{"$ref":"#/definitions/DeepPartial<Record<string,number>>"},"$in":{"$ref":"#/definitions/DeepPartial<Record<string,any[]>>"},"$nin":{"$ref":"#/definitions/DeepPartial<Record<string,any[]>>"},"$between":{"$ref":"#/definitions/DeepPartial<Record<string,[number,number]>>"},"$exists":{"$ref":"#/definitions/DeepPartial<Record<string,boolean>>"},"$type":{"$ref":"#/definitions/DeepPartial<Record<string,string>>"},"$arrinc":{"$ref":"#/definitions/DeepPartial<Record<string,any[]>>"},"$arrincall":{"$ref":"#/definitions/DeepPartial<Record<string,any[]>>"},"$size":{"$ref":"#/definitions/DeepPartial<Record<string,number>>"},"$regex":{"$ref":"#/definitions/DeepPartial<Record<string,RegExp>>"},"$startsWith":{"$ref":"#/definitions/DeepPartial<Record<string,string>>"},"$endsWith":{"$ref":"#/definitions/DeepPartial<Record<string,string>>"},"$subset":{"$ref":"#/definitions/DeepPartial<Record<string,any>>"},"_id":{"type":"string"}}},"DeepPartial<SearchOptions>_1":{"type":"object","properties":{"$and":{"description":"Recursively applies multiple conditions, all of which must evaluate to true.\nCan include other operators such as $gt, $exists, or nested $and/$or conditions.","type":"array","items":{"$ref":"#/definitions/DeepPartial<SearchOptions>_1"}},"$or":{"description":"Recursively applies multiple conditions, at least one of which must evaluate to true.\nCan include other operators such as $lt, $type, or nested $and/$or conditions.","type":"array","items":{"$ref":"#/definitions/DeepPartial<SearchOptions>_1"}},"$not":{"$ref":"#/definitions/DeepPartial<SearchOptions>_1","description":"Negates a single condition.\nCan include any other operator as its value."},"$gt":{"$ref":"#/definitions/DeepPartial<Record<string,number>>"},"$lt":{"$ref":"#/definitions/DeepPartial<Record<string,number>>"},"$gte":{"$ref":"#/definitions/DeepPartial<Record<string,number>>"},"$lte":{"$ref":"#/definitions/DeepPartial<Record<string,number>>"},"$in":{"$ref":"#/definitions/DeepPartial<Record<string,any[]>>"},"$nin":{"$ref":"#/definitions/DeepPartial<Record<string,any[]>>"},"$between":{"$ref":"#/definitions/DeepPartial<Record<string,[number,number]>>"},"$exists":{"$ref":"#/definitions/DeepPartial<Record<string,boolean>>"},"$type":{"$ref":"#/definitions/DeepPartial<Record<string,string>>"},"$arrinc":{"$ref":"#/definitions/DeepPartial<Record<string,any[]>>"},"$arrincall":{"$ref":"#/definitions/DeepPartial<Record<string,any[]>>"},"$size":{"$ref":"#/definitions/DeepPartial<Record<string,number>>"},"$regex":{"$ref":"#/definitions/DeepPartial<Record<string,RegExp>>"},"$startsWith":{"$ref":"#/definitions/DeepPartial<Record<string,string>>"},"$endsWith":{"$ref":"#/definitions/DeepPartial<Record<string,string>>"},"$subset":{"$ref":"#/definitions/DeepPartial<Record<string,any>>"},"_id":{"type":"string"}}},"DeepPartial<Record<string,number>>":{"type":"object"},"DeepPartial<Record<string,any[]>>":{"type":"object"},"DeepPartial<Record<string,[number,number]>>":{"type":"object"},"DeepPartial<Record<string,boolean>>":{"type":"object"},"DeepPartial<Record<string,string>>":{"type":"object"},"DeepPartial<Record<string,RegExp>>":{"type":"object"},"DeepPartial<Record<string,any>>":{"type":"object"},"DeepPartial<SearchFunc<any>>":{"type":"object"},"DeepPartial<VQLFields>":{"anyOf":[{"type":"array","items":{"type":"string"}},{"$ref":"#/definitions/DeepPartial<Record<string,number|boolean>>"}]},"DeepPartial<Record<string,number|boolean>>":{"type":"object"},"DeepPartial<VQLRelations>":{"type":"object"},"DeepPartial<DbFindOpts>":{"type":"object","properties":{"reverse":{"type":"boolean"},"max":{"type":"number"},"offset":{"type":"number"},"sortBy":{"type":"string"},"sortAsc":{"type":"boolean"}}},"DeepPartial<FindOpts>":{"type":"object","properties":{"select":{"type":"array","items":{"type":"string"}},"exclude":{"type":"array","items":{"type":"string"}},"transform":{"$ref":"#/definitions/DeepPartial<Function>"}}},"DeepPartial<Function>":{"type":"object","properties":{"apply":{"$ref":"#/definitions/DeepPartial<(this:Function,thisArg:any,argArray?:any)=>any>"},"call":{"$ref":"#/definitions/DeepPartial<(this:Function,thisArg:any,...argArray:any[])=>any>"},"bind":{"$ref":"#/definitions/DeepPartial<(this:Function,thisArg:any,...argArray:any[])=>any>_1"},"toString":{"$ref":"#/definitions/DeepPartial<()=>string>"},"prototype":{},"length":{"type":"number"},"arguments":{},"caller":{"$ref":"#/definitions/DeepPartial<Function>"},"name":{"type":"string"},"__@hasInstance@73":{"$ref":"#/definitions/DeepPartial<(value:any)=>boolean>"}}},"DeepPartial<(this:Function,thisArg:any,argArray?:any)=>any>":{"type":"object"},"DeepPartial<(this:Function,thisArg:any,...argArray:any[])=>any>":{"type":"object"},"DeepPartial<(this:Function,thisArg:any,...argArray:any[])=>any>_1":{"type":"object"},"DeepPartial<()=>string>":{"type":"object"},"DeepPartial<(value:any)=>boolean>":{"type":"object"},"DeepPartial<{findOne:VQLFindOne;}>":{"type":"object","properties":{"findOne":{"$ref":"#/definitions/DeepPartial<VQLFindOne>"}}},"DeepPartial<VQLFindOne>":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/DeepPartial<Search<any>>"},"fields":{"$ref":"#/definitions/DeepPartial<VQLFields>"},"select":{"$ref":"#/definitions/DeepPartial<VQLFields>"},"relations":{"$ref":"#/definitions/DeepPartial<VQLRelations>"},"searchOpts":{"$ref":"#/definitions/DeepPartial<FindOpts>"}}},"DeepPartial<{f:VQLFindOne;}>":{"type":"object","properties":{"f":{"$ref":"#/definitions/DeepPartial<VQLFindOne>"}}},"DeepPartial<{add:VQLAdd;}>":{"type":"object","properties":{"add":{"$ref":"#/definitions/DeepPartial<VQLAdd>"}}},"DeepPartial<VQLAdd>":{"type":"object","properties":{"collection":{"type":"string"},"data":{"$ref":"#/definitions/DeepPartial<Arg>"},"id_gen":{"type":"boolean"}}},"DeepPartial<Arg>":{"type":"object","properties":{"_id":{"type":"string"}}},"DeepPartial<{update:VQLUpdate;}>":{"type":"object","properties":{"update":{"$ref":"#/definitions/DeepPartial<VQLUpdate>"}}},"DeepPartial<VQLUpdate>":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/DeepPartial<Search<any>>"},"updater":{"$ref":"#/definitions/DeepPartial<UpdaterArg>"}}},"DeepPartial<UpdaterArg>":{"type":"object","properties":{"$push":{},"$pushset":{"description":"Pushes items into an array and removes duplicates"},"$pull":{},"$pullall":{},"$merge":{},"$set":{},"$inc":{},"$dec":{},"$unset":{},"$rename":{}}},"DeepPartial<{updateOne:VQLUpdateOne;}>":{"type":"object","properties":{"updateOne":{"$ref":"#/definitions/DeepPartial<VQLUpdateOne>"}}},"DeepPartial<VQLUpdateOne>":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/DeepPartial<Search<any>>"},"updater":{"$ref":"#/definitions/DeepPartial<UpdaterArg>"}}},"DeepPartial<{remove:VQLRemove;}>":{"type":"object","properties":{"remove":{"$ref":"#/definitions/DeepPartial<VQLRemove>"}}},"DeepPartial<VQLRemove>":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/DeepPartial<Search<any>>"}}},"DeepPartial<{removeOne:VQLRemoveOne;}>":{"type":"object","properties":{"removeOne":{"$ref":"#/definitions/DeepPartial<VQLRemoveOne>"}}},"DeepPartial<VQLRemoveOne>":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/DeepPartial<Search<any>>"}}},"DeepPartial<{updateOneOrAdd:VQLUpdateOneOrAdd;}>":{"type":"object","properties":{"updateOneOrAdd":{"$ref":"#/definitions/DeepPartial<VQLUpdateOneOrAdd>"}}},"DeepPartial<VQLUpdateOneOrAdd>":{"type":"object","properties":{"collection":{"type":"string"},"search":{"$ref":"#/definitions/DeepPartial<Search<any>>"},"updater":{"$ref":"#/definitions/DeepPartial<UpdaterArg>"},"add_arg":{"$ref":"#/definitions/DeepPartial<Arg>"},"id_gen":{"type":"boolean"}}},"DeepPartial<{removeCollection:VQLCollectionOperation;}>":{"type":"object","properties":{"removeCollection":{"$ref":"#/definitions/DeepPartial<VQLCollectionOperation>"}}},"DeepPartial<VQLCollectionOperation>":{"type":"object","properties":{"collection":{"type":"string"}}},"DeepPartial<{checkCollection:VQLCollectionOperation;}>":{"type":"object","properties":{"checkCollection":{"$ref":"#/definitions/DeepPartial<VQLCollectionOperation>"}}},"DeepPartial<{issetCollection:VQLCollectionOperation;}>":{"type":"object","properties":{"issetCollection":{"$ref":"#/definitions/DeepPartial<VQLCollectionOperation>"}}},"DeepPartial<{getCollections:{};}>":{"type":"object","properties":{"getCollections":{"$ref":"#/definitions/DeepPartial<{}>"}}},"DeepPartial<{}>":{"type":"object"},"DeepPartial<{[k:string]:any;}>":{"type":"object"},"DeepPartial<RelationQuery&VQLRef>":{"type":"object","properties":{"r":{"$ref":"#/definitions/DeepPartial<{path:RelationTypes.Path;search:Search<any>;relations:RelationTypes.Relation;many?:boolean;options?:DbFindOpts;select?:RelationTypes.FieldPath[];}>"},"ref":{"type":"string"},"var":{"$ref":"#/definitions/DeepPartial<{[k:string]:any;}>"}}},"DeepPartial<{path:RelationTypes.Path;search:Search<any>;relations:RelationTypes.Relation;many?:boolean;options?:DbFindOpts;select?:RelationTypes.FieldPath[];}>":{"type":"object","properties":{"path":{"type":"array","items":[{"type":"string"},{"type":"string"}],"minItems":0,"maxItems":2},"search":{"$ref":"#/definitions/DeepPartial<Search<any>>"},"relations":{"$ref":"#/definitions/DeepPartial<RelationTypes.Relation>"},"many":{"type":"boolean"},"options":{"$ref":"#/definitions/DeepPartial<DbFindOpts>"},"select":{"type":"array","items":{"type":"array","items":{"type":"string"}}}}},"DeepPartial<RelationTypes.Relation>":{"type":"object"}},"$schema":"http://json-schema.org/draft-07/schema#"}