@wxn0brp/vql 0.10.1 → 0.10.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 wxn0brP
3
+ Copyright (c) 2026 wxn0brP
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- import CollectionManager from "@wxn0brp/db-core/helpers/CollectionManager";
1
+ import { CollectionManager } from "@wxn0brp/db-core/helpers/collectionManager";
2
2
  import updateFindObject from "@wxn0brp/db-core/utils/updateFindObject";
3
3
  const list = [
4
4
  "ensureCollection", "issetCollection", "getCollections", "removeCollection",
@@ -1,10 +1,11 @@
1
1
  import { type VQLProcessor } from "../processor.js";
2
- import type { FalconFrame, FFRequest } from "@wxn0brp/falcon-frame";
3
- type ContextFn = (req: FFRequest) => Promise<any> | any;
2
+ import type { FalconFrame, FFRequest, FFResponse } from "@wxn0brp/falcon-frame";
3
+ export type ContextFn = (req: FFRequest, res: FFResponse) => Promise<any> | any;
4
4
  interface FF_VQL_Options {
5
+ /** @default "/VQL" */
5
6
  path?: string;
6
7
  getUser?: ContextFn;
7
8
  dev?: boolean;
8
9
  }
9
- export declare function FF_VQL(app: FalconFrame, processor: VQLProcessor, options?: FF_VQL_Options): void;
10
+ export declare function FF_VQL(app: FalconFrame<any>, processor: VQLProcessor, options?: FF_VQL_Options): void;
10
11
  export {};
@@ -1,10 +1,17 @@
1
1
  import { parseVQLS } from "../cpu/string/index.js";
2
+ function formatMessage(e) {
3
+ return e instanceof Error
4
+ ? e.message
5
+ : typeof e === "string"
6
+ ? e
7
+ : JSON.stringify(e);
8
+ }
2
9
  export function FF_VQL(app, processor, options = {}) {
3
10
  const path = options.path || "/VQL";
4
11
  const getContext = options.getUser || (() => ({}));
5
12
  app.post(path, async (req, res) => {
6
13
  try {
7
- const ctx = await getContext(req);
14
+ const ctx = await getContext(req, res);
8
15
  const result = await processor.execute(req.body.query, ctx);
9
16
  if (result && result.err)
10
17
  return result;
@@ -12,17 +19,17 @@ export function FF_VQL(app, processor, options = {}) {
12
19
  }
13
20
  catch (e) {
14
21
  res.status(500);
15
- return { err: true, msg: e.message };
22
+ return { err: true, msg: formatMessage(e) };
16
23
  }
17
24
  });
18
25
  if (options.dev) {
19
26
  app.get(path + "-query", (req, res) => {
20
27
  try {
21
- return res.json(parseVQLS(req.query?.query || ""));
28
+ return parseVQLS(req.query?.query || "");
22
29
  }
23
30
  catch (e) {
24
31
  res.status(500);
25
- return { err: true, msg: e.message };
32
+ return { err: true, msg: formatMessage(e) };
26
33
  }
27
34
  });
28
35
  }
package/dist/vql.d.ts CHANGED
@@ -1,11 +1,5 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- export interface Data {
4
- [key: string]: any;
5
- }
6
- export interface VContext {
7
- [key: string]: any;
8
- }
9
3
  export type KeysMatching<T, V, C = V> = {
10
4
  [K in keyof T]-?: T[K] extends C ? K : never;
11
5
  }[keyof T];
@@ -17,6 +11,7 @@ export type NestedValue<T, V, C = V> = {
17
11
  export type DeepPartial<T> = {
18
12
  [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
19
13
  };
14
+ export type JSPrimitiveType = "string" | "number" | "boolean" | "bigint" | "symbol" | "undefined" | "function" | "object";
20
15
  /** Logical Operators */
21
16
  export type LogicalOperators<T = any> = {
22
17
  /**
@@ -70,9 +65,9 @@ export type ComparisonOperators<T = any> = {
70
65
  /** Type and Existence Operators with nested support */
71
66
  export type TypeAndExistenceOperators<T = any> = {
72
67
  /** "name" in { name: "John" } */
73
- $exists?: NestedValue<T, boolean>;
68
+ $exists?: NestedValue<T, boolean, any>;
74
69
  /** "name" == "string" in { name: "John" } */
75
- $type?: NestedValue<T, string>;
70
+ $type?: NestedValue<T, JSPrimitiveType, any>;
76
71
  };
77
72
  /** Array Operators with nested support */
78
73
  export type ArrayOperators<T = any> = {
@@ -103,6 +98,9 @@ export type PredefinedSearchOperators<T = any> = LogicalOperators<T> & Compariso
103
98
  * SearchOptions can be either a function or an object with predefined operators.
104
99
  */
105
100
  export type SearchOptions<T = any> = PredefinedSearchOperators<T> & DeepPartial<T> & Record<string, any>;
101
+ export interface VContext {
102
+ [key: string]: any;
103
+ }
106
104
  /** Arrays */
107
105
  export type ArrayUpdater<T = any> = {
108
106
  /** [1,2] -> $push 3 -> [1,2,3] */
@@ -146,6 +144,9 @@ export type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
146
144
  export type UpdaterFunc<T = any> = (data: T, context: VContext) => boolean;
147
145
  export type Search<T = any> = SearchOptions<T> | SearchFunc<T>;
148
146
  export type Updater<T = any> = UpdaterArg<T> | UpdaterArg<T>[] | UpdaterFunc<T>;
147
+ export interface Data {
148
+ [key: string]: any;
149
+ }
149
150
  export interface DbFindOpts<T = any> {
150
151
  reverse?: boolean;
151
152
  limit?: number;
@@ -165,39 +166,39 @@ declare class CollectionManager<D = Data> {
165
166
  /**
166
167
  * Add data to a database.
167
168
  */
168
- add<T = Data>(data: Arg<T & D>, id_gen?: boolean): Promise<T>;
169
+ add(data: Arg<D>, id_gen?: boolean): Promise<D>;
169
170
  /**
170
171
  * Find data in a database.
171
172
  */
172
- find<T = Data>(search?: Search<T & D>, options?: DbFindOpts<T & D>, findOpts?: FindOpts<T & D>, context?: VContext): Promise<T[]>;
173
+ find(search?: Search<D>, options?: DbFindOpts<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D[]>;
173
174
  /**
174
175
  * Find one data entry in a database.
175
176
  */
176
- findOne<T = Data>(search?: Search<T & D>, findOpts?: FindOpts<T & D>, context?: VContext): Promise<T>;
177
+ findOne(search?: Search<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D>;
177
178
  /**
178
179
  * Update data in a database.
179
180
  */
180
- update<T = Data>(search: Search<T & D>, updater: Updater<T & D>, context?: VContext): Promise<boolean>;
181
+ update(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<boolean>;
181
182
  /**
182
183
  * Update one data entry in a database.
183
184
  */
184
- updateOne<T = Data>(search: Search<T & D>, updater: Updater<T & D>, context?: VContext): Promise<boolean>;
185
+ updateOne(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<boolean>;
185
186
  /**
186
187
  * Remove data from a database.
187
188
  */
188
- remove<T = Data>(search: Search<T & D>, context?: VContext): Promise<boolean>;
189
+ remove(search: Search<D>, context?: VContext): Promise<boolean>;
189
190
  /**
190
191
  * Remove one data entry from a database.
191
192
  */
192
- removeOne<T = Data>(search: Search<T & D>, context?: VContext): Promise<boolean>;
193
+ removeOne(search: Search<D>, context?: VContext): Promise<boolean>;
193
194
  /**
194
195
  * Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
195
196
  */
196
- updateOneOrAdd<T = Data>(search: Search<T & D>, updater: Updater<T & D>, { add_arg, context, id_gen }: UpdateOneOrAdd<T & D>): Promise<boolean>;
197
+ updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<boolean>;
197
198
  /**
198
199
  * Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
199
200
  */
200
- toggleOne<T = Data>(search: Search<T & D>, data?: Arg<T & D>, context?: VContext): Promise<boolean>;
201
+ toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<boolean>;
201
202
  }
202
203
  export interface ValtheraCompatible {
203
204
  c(collection: string): CollectionManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "main": "dist/index.js",
5
5
  "author": "wxn0brP",
6
6
  "license": "MIT",
@@ -27,9 +27,9 @@
27
27
  "query-language"
28
28
  ],
29
29
  "peerDependencies": {
30
- "@wxn0brp/db-core": ">=0.3.0",
31
- "@wxn0brp/falcon-frame": ">=0.5.3",
32
- "@wxn0brp/gate-warden": ">=0.5.0"
30
+ "@wxn0brp/db-core": ">=0.4.0",
31
+ "@wxn0brp/falcon-frame": ">=0.6.1",
32
+ "@wxn0brp/gate-warden": ">=0.5.3"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "@wxn0brp/falcon-frame": {
@@ -45,10 +45,10 @@
45
45
  "devDependencies": {
46
46
  "@types/bun": "*",
47
47
  "@types/node": "*",
48
- "@wxn0brp/db": "^0.41.0",
49
- "@wxn0brp/db-core": "^0.3.0",
50
- "@wxn0brp/falcon-frame": "^0.5.3",
51
- "@wxn0brp/gate-warden": "^0.5.0",
48
+ "@wxn0brp/db": "^0.42.0",
49
+ "@wxn0brp/db-core": "^0.4.0",
50
+ "@wxn0brp/falcon-frame": "^0.6.1",
51
+ "@wxn0brp/gate-warden": "^0.5.3",
52
52
  "esbuild": "*",
53
53
  "tsc-alias": "*",
54
54
  "typescript": "*"