@wxn0brp/vql 0.10.2 → 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.
@@ -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];
@@ -104,6 +98,9 @@ export type PredefinedSearchOperators<T = any> = LogicalOperators<T> & Compariso
104
98
  * SearchOptions can be either a function or an object with predefined operators.
105
99
  */
106
100
  export type SearchOptions<T = any> = PredefinedSearchOperators<T> & DeepPartial<T> & Record<string, any>;
101
+ export interface VContext {
102
+ [key: string]: any;
103
+ }
107
104
  /** Arrays */
108
105
  export type ArrayUpdater<T = any> = {
109
106
  /** [1,2] -> $push 3 -> [1,2,3] */
@@ -147,6 +144,9 @@ export type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
147
144
  export type UpdaterFunc<T = any> = (data: T, context: VContext) => boolean;
148
145
  export type Search<T = any> = SearchOptions<T> | SearchFunc<T>;
149
146
  export type Updater<T = any> = UpdaterArg<T> | UpdaterArg<T>[] | UpdaterFunc<T>;
147
+ export interface Data {
148
+ [key: string]: any;
149
+ }
150
150
  export interface DbFindOpts<T = any> {
151
151
  reverse?: boolean;
152
152
  limit?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "main": "dist/index.js",
5
5
  "author": "wxn0brP",
6
6
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "peerDependencies": {
30
30
  "@wxn0brp/db-core": ">=0.4.0",
31
- "@wxn0brp/falcon-frame": ">=0.5.9",
31
+ "@wxn0brp/falcon-frame": ">=0.6.1",
32
32
  "@wxn0brp/gate-warden": ">=0.5.3"
33
33
  },
34
34
  "peerDependenciesMeta": {
@@ -45,9 +45,9 @@
45
45
  "devDependencies": {
46
46
  "@types/bun": "*",
47
47
  "@types/node": "*",
48
- "@wxn0brp/db": "^0.41.1",
48
+ "@wxn0brp/db": "^0.42.0",
49
49
  "@wxn0brp/db-core": "^0.4.0",
50
- "@wxn0brp/falcon-frame": "^0.5.9",
50
+ "@wxn0brp/falcon-frame": "^0.6.1",
51
51
  "@wxn0brp/gate-warden": "^0.5.3",
52
52
  "esbuild": "*",
53
53
  "tsc-alias": "*",