@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/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  VQL is a query language and processing framework designed for managing and interacting with databases using ValtheraDB. It provides a robust permission system, query execution, and a GUI for managing ACL rules and database structures.
4
4
 
5
+ [![npm version](https://img.shields.io/npm/v/@wxn0brp/vql)](https://www.npmjs.com/package/@wxn0brp/vql)
6
+ [![License](https://img.shields.io/npm/l/@wxn0brp/vql)](./LICENSE)
7
+ [![Downloads](https://img.shields.io/npm/dm/@wxn0brp/vql)](https://www.npmjs.com/package/@wxn0brp/vql)
8
+
5
9
  ## Features
6
10
 
7
11
  - **Query Execution**: Supports CRUD operations and advanced query capabilities.
@@ -16,18 +20,14 @@ Here is an example of how to use the `VQLProcessor` to execute a query:
16
20
  ```typescript
17
21
  import VQLProcessor from "@wxn0brp/vql";
18
22
  import { Valthera } from "@wxn0brp/db";
19
- import { GateWarden } from "@wxn0brp/gate-warden";
20
23
 
21
24
  // Initialize database instances
22
25
  const dbInstances = {
23
26
  myDatabase: new Valthera("path/to/database"),
24
27
  };
25
28
 
26
- // Initialize Gate Warden
27
- const gw = new GateWarden("path/to/gate-warden/database");
28
-
29
29
  // Create a VQLProcessor instance
30
- const processor = new VQLProcessor(dbInstances, gw);
30
+ const processor = new VQLProcessor(dbInstances);
31
31
 
32
32
  // Define a query (VQLR)
33
33
  const query = {
@@ -49,31 +49,11 @@ s.$gt.age = 18
49
49
  f.name = 1
50
50
  f.age = 1
51
51
  `
52
- // Or (use backticks like json)
53
- const VQLB = `
54
- myDatabase users
55
- {
56
- collection: "users",
57
- search: { $gt: { age: 18 } },
58
- fields: { name: 1, age: 1 },
59
- }
60
- `
61
- // Or (use markup like yaml)
62
- const VQLM = `
63
- myDatabase users
64
- collection: users
65
- search:
66
- $gt:
67
- age: 18
68
- fields:
69
- name: 1
70
- age: 1
71
- `
72
52
 
73
53
  // Execute the query
74
54
  (async () => {
75
55
  try {
76
- const result = await processor.execute(query, { id: "user123" });
56
+ const result = await processor.execute(query);
77
57
  console.log("Query Result:", result);
78
58
  } catch (error) {
79
59
  console.error("Error executing query:", error);
@@ -85,7 +65,6 @@ fields:
85
65
 
86
66
  - [Base/Map](./docs/lang/base.md)
87
67
  - [VQLS](./docs/lang/VQLS.md)
88
- - [VQLM/B](./docs/lang/VQLM.md)
89
68
  - [VQLR](./docs/lang/VQLR.md)
90
69
 
91
70
  ## License
@@ -13,7 +13,7 @@ export interface ValtheraResolver {
13
13
  meta?: ValtheraResolverMeta;
14
14
  getCollections?: ResolverFn<[], string[]>;
15
15
  issetCollection?: ResolverFn<[collection: string], boolean>;
16
- checkCollection?: ResolverFn<[collection: string], boolean>;
16
+ ensureCollection?: ResolverFn<[collection: string], boolean>;
17
17
  add?: ResolverFn<[collection: string, data: any, id_gen?: boolean], any>;
18
18
  find?: ResolverFn<[
19
19
  collection: string,
@@ -12,7 +12,7 @@ export function createValtheraAdapter(resolver, extendedFind = false) {
12
12
  c: null,
13
13
  getCollections: () => safe(resolver.getCollections)(),
14
14
  issetCollection: (c) => safe(resolver.issetCollection)(c),
15
- checkCollection: (c) => safe(resolver.checkCollection)(c),
15
+ ensureCollection: (c) => safe(resolver.ensureCollection)(c),
16
16
  add: (col, data, id_gen) => safe(resolver.add)(col, data, id_gen),
17
17
  find: (col, search, context, options, findOpts) => safe(resolver.find)(col, search, context, options, findOpts),
18
18
  findOne: (col, search, context, findOpts) => safe(resolver.findOne)(col, search, context, findOpts),
package/dist/config.d.ts CHANGED
@@ -3,13 +3,11 @@ export interface VQLConfigInterface {
3
3
  strictSelect: boolean;
4
4
  strictACL: boolean;
5
5
  noCheckPermissions: boolean;
6
- formatAjv: boolean;
7
6
  }
8
7
  export declare class VQLConfig implements VQLConfigInterface {
9
8
  hidePath: boolean;
10
9
  strictSelect: boolean;
11
10
  strictACL: boolean;
12
11
  noCheckPermissions: boolean;
13
- formatAjv: boolean;
14
12
  constructor(config?: Partial<VQLConfigInterface>);
15
13
  }
package/dist/config.js CHANGED
@@ -1,9 +1,8 @@
1
1
  export class VQLConfig {
2
- hidePath = true;
3
- strictSelect = true;
4
- strictACL = true;
5
- noCheckPermissions = false;
6
- formatAjv = true;
2
+ hidePath = false;
3
+ strictSelect = false;
4
+ strictACL = false;
5
+ noCheckPermissions = true;
7
6
  constructor(config) {
8
7
  if (config) {
9
8
  Object.assign(this, config);
@@ -21,7 +21,7 @@ export async function executeRelation(cpu, query, user) {
21
21
  const checkDb = checkDBsExist(cpu, query.r);
22
22
  if (checkDb.err)
23
23
  return checkDb;
24
- if (!cpu.config.noCheckPermissions && !await checkRelationPermission(cpu.config, cpu.gw, user, query)) {
24
+ if (!cpu.config.noCheckPermissions && !await checkRelationPermission(cpu.config, cpu.validFn, user, query)) {
25
25
  return { err: true, msg: "Permission denied", c: 403 };
26
26
  }
27
27
  const req = query.r;
@@ -5,7 +5,7 @@ export async function executeQuery(cpu, query, user) {
5
5
  return { err: true, msg: `Invalid query - db "${query.db || "undefined"}" not found`, c: 400 };
6
6
  const db = cpu.dbInstances[query.db];
7
7
  const operation = Object.keys(query.d)[0];
8
- if (!cpu.config.noCheckPermissions && !await checkRequestPermission(cpu.config, cpu.gw, user, query)) {
8
+ if (!cpu.config.noCheckPermissions && !await checkRequestPermission(cpu.config, cpu.validFn, user, query)) {
9
9
  return { err: true, msg: "Permission denied", c: 403 };
10
10
  }
11
11
  if (operation === "find") {
@@ -50,9 +50,9 @@ export async function executeQuery(cpu, query, user) {
50
50
  const params = query.d[operation];
51
51
  return db.removeCollection(params.collection);
52
52
  }
53
- else if (operation === "checkCollection") {
53
+ else if (operation === "ensureCollection") {
54
54
  const params = query.d[operation];
55
- return db.checkCollection(params.collection);
55
+ return db.ensureCollection(params.collection);
56
56
  }
57
57
  else if (operation === "issetCollection") {
58
58
  const params = query.d[operation];
@@ -1,8 +1,2 @@
1
1
  import { VQL } from "../../types/vql.js";
2
- export type VQLParserMode = "VQLS" | "VQLM" | "VQLB" | "VQLR";
3
- export declare function guessParser(query: string): {
4
- mode: VQLParserMode;
5
- query: string;
6
- };
7
- declare function parseStringQuery(query: string): VQL;
8
- export { parseStringQuery };
2
+ export declare function parseVQLS(query: string): VQL;
@@ -1,56 +1,153 @@
1
- import logger from "../../logger.js";
2
- import { parseVQLB } from "./json5.js";
3
- import { parseVQLS } from "./simple.js";
4
- import { parseVQLM } from "./yaml.js";
5
- function get3rdAnd4thWord(query) {
6
- let words = [];
7
- let word = "";
8
- let i = 0;
9
- while (i < query.length && words.length < 4) {
10
- const c = query[i++];
11
- if (" \t\n\r".includes(c)) {
12
- if (word)
13
- words.push(word);
14
- word = "";
1
+ import { convertSearchObjToSearchArray, extractMeta } from "./utils.js";
2
+ const aliases = {
3
+ s: "search",
4
+ f: "fields",
5
+ o: "options",
6
+ r: "relations",
7
+ d: "data",
8
+ e: "select",
9
+ u: "updater",
10
+ };
11
+ function parseArgs(input) {
12
+ const result = {};
13
+ const tokens = [];
14
+ let current = "";
15
+ let inQuotes = false;
16
+ let escape = false;
17
+ for (let i = 0; i < input.length; i++) {
18
+ const char = input[i];
19
+ if (escape) {
20
+ current += char;
21
+ escape = false;
22
+ }
23
+ else if (char === "\\") {
24
+ escape = true;
25
+ }
26
+ else if (char === "\"") {
27
+ inQuotes = !inQuotes;
28
+ }
29
+ else if (!inQuotes && (char === " " || char === "=")) {
30
+ if (current !== "") {
31
+ tokens.push(current);
32
+ current = "";
33
+ }
15
34
  }
16
35
  else {
17
- word += c;
36
+ current += char;
37
+ }
38
+ }
39
+ if (current !== "") {
40
+ tokens.push(current);
41
+ }
42
+ for (let i = 0; i < tokens.length; i += 2) {
43
+ const key = tokens[i];
44
+ let value = tokens[i + 1] ?? true;
45
+ if (typeof value === "string") {
46
+ const trimmed = value.trim();
47
+ if (trimmed === "") {
48
+ value = true;
49
+ }
50
+ else if (/^".*"$/.test(trimmed)) {
51
+ value = trimmed.slice(1, -1);
52
+ }
53
+ else if (trimmed.toLowerCase() === "true") {
54
+ value = true;
55
+ }
56
+ else if (trimmed.toLowerCase() === "false") {
57
+ value = false;
58
+ }
59
+ else if (!isNaN(Number(trimmed))) {
60
+ value = Number(trimmed);
61
+ }
62
+ else if ((trimmed.startsWith("{") && trimmed.endsWith("}")) || (trimmed.startsWith("[") && trimmed.endsWith("]"))) {
63
+ try {
64
+ value = JSON.parse(trimmed);
65
+ }
66
+ catch { }
67
+ }
18
68
  }
69
+ result[key] = value;
19
70
  }
20
- if (word && words.length < 4)
21
- words.push(word);
22
- return words[2] + (words[3] ? " " + words[3] : "");
71
+ return result;
23
72
  }
24
- export function guessParser(query) {
25
- query = query.trimStart();
26
- if (query[0] === "#") {
73
+ function buildVQL(db, op, collection, query) {
74
+ const hasRelations = "relations" in query;
75
+ if (hasRelations) {
76
+ const relations = {};
77
+ for (const key in query.relations) {
78
+ const value = query.relations[key];
79
+ relations[key] = {
80
+ path: [value.db || db, value.c || key],
81
+ ...value
82
+ };
83
+ delete relations[key].db;
84
+ delete relations[key].c;
85
+ }
86
+ if ("select" in query) {
87
+ query.select = convertSearchObjToSearchArray(query.select);
88
+ }
27
89
  return {
28
- mode: "VQL" + query[1].toUpperCase(),
29
- query: query.slice(2)
90
+ r: {
91
+ path: [db, collection],
92
+ ...query,
93
+ relations,
94
+ }
95
+ };
96
+ }
97
+ else {
98
+ if (query.fields && !query.select) {
99
+ query.select = query.fields;
100
+ delete query.fields;
101
+ }
102
+ if ("select" in query) {
103
+ query.select = [...new Set(convertSearchObjToSearchArray(query.select).map(k => k[0]).flat())];
104
+ }
105
+ return {
106
+ db,
107
+ d: {
108
+ [op]: {
109
+ collection,
110
+ ...query,
111
+ }
112
+ }
30
113
  };
31
114
  }
32
- const _34word = get3rdAnd4thWord(query);
33
- let mode = "VQLS";
34
- if (_34word.includes("{"))
35
- mode = "VQLB";
36
- else if (_34word.includes(":"))
37
- mode = "VQLM";
38
- return {
39
- mode,
40
- query
41
- };
42
115
  }
43
- function parseStringQuery(query) {
44
- const { mode, query: queryRaw } = guessParser(query);
45
- logger.debug("Query mode: " + mode);
46
- if (mode === "VQLB") {
47
- return parseVQLB(queryRaw);
116
+ export function parseVQLS(query) {
117
+ const { db, op, collection, body } = extractMeta(query);
118
+ const parsed = parseArgs(body);
119
+ for (const keysRaw of Object.keys(parsed)) {
120
+ const keys = keysRaw.split(".");
121
+ if (keys.length === 1) {
122
+ continue;
123
+ }
124
+ let obj = parsed;
125
+ for (let i = 0; i < keys.length; i++) {
126
+ const key = keys[i];
127
+ if (i < keys.length - 1) {
128
+ if (!(key in obj)) {
129
+ obj[key] = {};
130
+ }
131
+ obj = obj[key];
132
+ }
133
+ else {
134
+ obj[key] = parsed[keysRaw];
135
+ delete parsed[keysRaw];
136
+ }
137
+ }
138
+ }
139
+ for (const key in aliases) {
140
+ if (key in parsed) {
141
+ parsed[aliases[key]] = parsed[key];
142
+ delete parsed[key];
143
+ }
48
144
  }
49
- else if (mode === "VQLM") {
50
- return parseVQLM(queryRaw);
145
+ if ((op === "find" || op === "findOne") && !("search" in parsed)) {
146
+ parsed.search = {};
51
147
  }
52
- else {
53
- return parseVQLS(queryRaw);
148
+ if ((op === "update" || op === "remove") && !("updater" in parsed) && ("data" in parsed)) {
149
+ parsed.updater = parsed.data;
150
+ delete parsed.data;
54
151
  }
152
+ return buildVQL(db, op, collection, parsed);
55
153
  }
56
- export { parseStringQuery };
@@ -15,3 +15,4 @@ export declare function extractMeta(input: string): {
15
15
  collection: string;
16
16
  body: string;
17
17
  };
18
+ export declare function convertSearchObjToSearchArray(obj: Record<string, any>, parentKeys?: string[]): string[][];
@@ -9,7 +9,7 @@ const operations = [
9
9
  "update", "updateOne",
10
10
  "remove", "removeOne",
11
11
  "updateOneOrAdd",
12
- "checkCollection", "issetCollection",
12
+ "ensureCollection", "issetCollection",
13
13
  ];
14
14
  /**
15
15
  * Extracts metadata from a query string, including database name, operation,
@@ -87,3 +87,17 @@ function extendedCollectionToData(collection) {
87
87
  }
88
88
  return { op, collection: collectionName };
89
89
  }
90
+ export function convertSearchObjToSearchArray(obj, parentKeys = []) {
91
+ return Object.entries(obj).reduce((acc, [key, value]) => {
92
+ const currentPath = [...parentKeys, key];
93
+ if (!value) {
94
+ return acc;
95
+ }
96
+ else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
97
+ return [...acc, ...convertSearchObjToSearchArray(value, currentPath)];
98
+ }
99
+ else {
100
+ return [...acc, currentPath];
101
+ }
102
+ }, []);
103
+ }
@@ -1,4 +1,4 @@
1
- import { parseStringQuery } from "./cpu/string/index.js";
1
+ import { parseVQLS } from "./cpu/string/index.js";
2
2
  export function FF_VQL(app, processor, options = {}) {
3
3
  const path = options.path || "/VQL";
4
4
  const getContext = options.getUser || (() => ({}));
@@ -18,7 +18,7 @@ export function FF_VQL(app, processor, options = {}) {
18
18
  if (options.dev) {
19
19
  app.get(path + "-query", (req, res) => {
20
20
  try {
21
- return res.json(parseStringQuery(req.query?.query || ""));
21
+ return res.json(parseVQLS(req.query?.query || ""));
22
22
  }
23
23
  catch (e) {
24
24
  res.status(500);
package/dist/gw.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { GateWarden } from "@wxn0brp/gate-warden";
2
+ import { ValidFn } from "./types/perm.js";
3
+ export declare function createGwValidFn(gw: GateWarden): ValidFn;
package/dist/gw.js ADDED
@@ -0,0 +1,5 @@
1
+ export function createGwValidFn(gw) {
2
+ return async (path, perm, user) => {
3
+ return gw.hasAccess(user.id, path, perm);
4
+ };
5
+ }
@@ -1,4 +1,4 @@
1
- import { GateWarden } from "@wxn0brp/gate-warden";
1
+ import { ValidFn } from "../types/perm.js";
2
2
  import { RelationQuery } from "../types/vql.js";
3
3
  import { VQLConfig } from "../config.js";
4
- export declare function checkRelationPermission(config: VQLConfig, gw: GateWarden<any>, user: any, query: RelationQuery): Promise<boolean>;
4
+ export declare function checkRelationPermission(config: VQLConfig, validFn: ValidFn, user: any, query: RelationQuery): Promise<boolean>;
@@ -1,11 +1,12 @@
1
1
  import { PermCRUD } from "../types/perm.js";
2
2
  import { extractPathsFromData, hashKey } from "./utils.js";
3
- export async function checkRelationPermission(config, gw, user, query) {
3
+ export async function checkRelationPermission(config, validFn, user, query) {
4
4
  const { path, search, relations, select } = query.r;
5
5
  // Helper function to recursively check permissions with fallback mechanism
6
6
  const checkPermissionRecursively = async (entityId, fallbackLevels = []) => {
7
7
  // Check if the user has access to the current entity
8
- const result = await gw.hasAccess(user.id, entityId, PermCRUD.READ);
8
+ // const result = await gw.hasAccess(user.id, entityId, PermCRUD.READ);
9
+ const result = await validFn(entityId, PermCRUD.READ, user);
9
10
  if (result.granted) {
10
11
  return true;
11
12
  }
@@ -42,7 +43,7 @@ export async function checkRelationPermission(config, gw, user, query) {
42
43
  if (relations) {
43
44
  for (const relationKey in relations) {
44
45
  const r = relations[relationKey];
45
- if (!await checkRelationPermission(config, gw, user, { r })) {
46
+ if (!await checkRelationPermission(config, validFn, user, { r })) {
46
47
  return false;
47
48
  }
48
49
  }
@@ -1,5 +1,4 @@
1
- import { GateWarden } from "@wxn0brp/gate-warden";
2
- import { PermCRUD } from "../types/perm.js";
1
+ import { PermCRUD, ValidFn } from "../types/perm.js";
3
2
  import { VQLRequest } from "../types/vql.js";
4
3
  import { VQLConfig } from "../config.js";
5
4
  export declare function extractPaths(config: VQLConfig, query: VQLRequest): {
@@ -16,4 +15,4 @@ export declare function processFieldPath(pathObj: {
16
15
  path: string[];
17
16
  key: string;
18
17
  }): string[];
19
- export declare function checkRequestPermission(config: VQLConfig, gw: GateWarden<any>, user: any, query: VQLRequest): Promise<boolean>;
18
+ export declare function checkRequestPermission(config: VQLConfig, validFn: ValidFn, user: any, query: VQLRequest): Promise<boolean>;
@@ -34,7 +34,7 @@ export function extractPaths(config, query) {
34
34
  permPaths.paths.push({ filed: extractPathsFromData(qo.search), p: PermCRUD.READ });
35
35
  permPaths.paths.push({ filed: extractPathsFromData(qo.updater), p: PermCRUD.UPDATE });
36
36
  break;
37
- case "checkCollection":
37
+ case "ensureCollection":
38
38
  case "getCollections":
39
39
  case "issetCollection":
40
40
  case "removeCollection":
@@ -79,14 +79,15 @@ export function processFieldPath(pathObj) {
79
79
  }
80
80
  return processedPath;
81
81
  }
82
- export async function checkRequestPermission(config, gw, user, query) {
82
+ export async function checkRequestPermission(config, validFn, user, query) {
83
83
  if (!query)
84
84
  return false;
85
85
  const permPaths = extractPaths(config, query);
86
86
  // Helper function to recursively check permissions
87
87
  const checkPermissionRecursively = async (entityId, requiredPerm, fallbackLevels = []) => {
88
88
  // Check if the user has access to the current entity
89
- const result = await gw.hasAccess(user.id, entityId, requiredPerm);
89
+ // const result = await gw.hasAccess(user.id, entityId, requiredPerm);
90
+ const result = await validFn(entityId, requiredPerm, user);
90
91
  if (result.granted) {
91
92
  return true;
92
93
  }
@@ -1,13 +1,13 @@
1
1
  import { Relation, ValtheraCompatible } from "@wxn0brp/db-core";
2
- import { GateWarden } from "@wxn0brp/gate-warden";
3
- import { VQLConfig } from "./config.js";
2
+ import { VQLConfig, VQLConfigInterface } from "./config.js";
4
3
  import { VQL, VQLError, VqlQueryRaw } from "./types/vql.js";
5
- export declare class VQLProcessor<GW = any> {
4
+ import { ValidFn } from "./types/perm.js";
5
+ export declare class VQLProcessor {
6
6
  dbInstances: Record<string, ValtheraCompatible>;
7
- gw: GateWarden<GW>;
8
- config: VQLConfig;
7
+ validFn: ValidFn;
9
8
  relation: Relation;
10
9
  preDefinedSheets: Map<string, VQL>;
11
- constructor(dbInstances: Record<string, ValtheraCompatible>, gw?: GateWarden<GW>, config?: VQLConfig);
12
- execute<T = any>(queryRaw: VqlQueryRaw<T>, user: any): Promise<T | VQLError>;
10
+ config: VQLConfig;
11
+ constructor(dbInstances: Record<string, ValtheraCompatible>, config?: VQLConfig | Partial<VQLConfigInterface>, validFn?: ValidFn);
12
+ execute<T = any>(queryRaw: VqlQueryRaw<T>, user?: any): Promise<T | VQLError>;
13
13
  }
package/dist/processor.js CHANGED
@@ -2,23 +2,23 @@ import { Relation } from "@wxn0brp/db-core";
2
2
  import { VQLConfig } from "./config.js";
3
3
  import { executeRelation } from "./cpu/relation.js";
4
4
  import { executeQuery } from "./cpu/request.js";
5
- import { parseStringQuery } from "./cpu/string/index.js";
6
5
  import logger from "./logger.js";
7
6
  import { executeSheetAndReplaceVars } from "./sheet/index.js";
8
7
  import { validateRaw, validateVql } from "./valid.js";
8
+ import { parseVQLS } from "./cpu/string/index.js";
9
9
  export class VQLProcessor {
10
10
  dbInstances;
11
- gw;
12
- config;
11
+ validFn;
13
12
  relation;
14
13
  preDefinedSheets = new Map();
15
- constructor(dbInstances, gw = null, config = new VQLConfig()) {
14
+ config;
15
+ constructor(dbInstances, config = new VQLConfig(), validFn = async () => ({ granted: true, via: "" })) {
16
16
  this.dbInstances = dbInstances;
17
- this.gw = gw;
18
- this.config = config;
17
+ this.validFn = validFn;
19
18
  this.relation = new Relation(dbInstances);
19
+ this.config = config instanceof VQLConfig ? config : new VQLConfig(config);
20
20
  }
21
- async execute(queryRaw, user) {
21
+ async execute(queryRaw, user = {}) {
22
22
  if (typeof queryRaw === "string" || "query" in queryRaw) {
23
23
  logger.info("Incoming string query");
24
24
  const q = typeof queryRaw === "string" ? queryRaw : queryRaw.query;
@@ -26,7 +26,7 @@ export class VQLProcessor {
26
26
  const ref = typeof queryRaw === "string" ? null : queryRaw.ref;
27
27
  logger.debug(q);
28
28
  try {
29
- queryRaw = parseStringQuery(q);
29
+ queryRaw = parseVQLS(q);
30
30
  logger.debug("transformed query: ", queryRaw);
31
31
  }
32
32
  catch (e) {
@@ -43,14 +43,14 @@ export class VQLProcessor {
43
43
  logger.info("Incoming object query");
44
44
  logger.debug("Raw query: ", queryRaw);
45
45
  }
46
- const validateRawResult = validateRaw(this.config, queryRaw);
46
+ const validateRawResult = validateRaw(queryRaw);
47
47
  if (validateRawResult !== true) {
48
48
  logger.warn("Raw validation failed:", validateRawResult);
49
49
  return validateRawResult;
50
50
  }
51
51
  const query = executeSheetAndReplaceVars(queryRaw, this.preDefinedSheets, user);
52
52
  logger.debug("Executed sheet (expanded query):", query);
53
- const validateVqlResult = validateVql(this.config, query);
53
+ const validateVqlResult = validateVql(query);
54
54
  if (validateVqlResult !== true) {
55
55
  logger.warn("VQL validation failed:", validateVqlResult);
56
56
  return validateVqlResult;
@@ -5,3 +5,8 @@ export declare enum PermCRUD {
5
5
  DELETE = 8,
6
6
  COLLECTION = 16
7
7
  }
8
+ export interface ValidFnResult {
9
+ granted: boolean;
10
+ via?: string;
11
+ }
12
+ export type ValidFn = (path: string, perm: number, user: any) => Promise<ValidFnResult>;
@@ -13,7 +13,7 @@ export interface VQLQuery<T = any> {
13
13
  removeOne: VQLRemoveOne<T>;
14
14
  updateOneOrAdd: VQLUpdateOneOrAdd<T>;
15
15
  removeCollection: VQLCollectionOperation;
16
- checkCollection: VQLCollectionOperation;
16
+ ensureCollection: VQLCollectionOperation;
17
17
  issetCollection: VQLCollectionOperation;
18
18
  getCollections: {};
19
19
  }
@@ -38,7 +38,7 @@ export type VQLQueryData<T = any> = {
38
38
  } | {
39
39
  removeCollection: VQLCollectionOperation;
40
40
  } | {
41
- checkCollection: VQLCollectionOperation;
41
+ ensureCollection: VQLCollectionOperation;
42
42
  } | {
43
43
  issetCollection: VQLCollectionOperation;
44
44
  } | {
package/dist/valid.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import Ajv from "ajv";
2
- import { VQLConfig } from "./config.js";
3
1
  import { VQL, VQLError, VQLR } from "./types/vql.js";
4
- export declare const ajv: Ajv;
5
- export declare function validateRaw(config: VQLConfig, query: VQLR): true | VQLError;
6
- export declare function validateVql(config: VQLConfig, query: VQL): true | VQLError;
2
+ export declare function validateRaw(query: VQLR): true | VQLError;
3
+ export declare function validateVql(query: VQL): true | VQLError;