@wxn0brp/vql-client 0.2.7 → 0.2.9

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
package/README.md CHANGED
@@ -9,6 +9,12 @@ Supports:
9
9
  - Fully typed with TypeScript
10
10
  - Custom transport layers and lifecycle hooks
11
11
 
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @wxn0brp/vql-client
16
+ ```
17
+
12
18
  ## DOCS
13
19
 
14
20
  [API Reference](https://wxn0brp.github.io/VQL-client/)
@@ -32,9 +38,7 @@ const result = await fetchVQL("db1 user! s._id = xyz");
32
38
  </script>
33
39
  ```
34
40
 
35
- ## Usage
36
-
37
- ### `fetchVQL<T = any>(query: string | object, vars?: Object, hookContext?: Object): Promise<T>`
41
+ ### `fetchVQL<T = any>(query: string | object, vars?: Object, hookContext?: Object, fetchOptions?: FetchOptions): Promise<T>`
38
42
 
39
43
  Executes a VQL query and returns the result (unwrapped from `{ result }`, unless an error is present).
40
44
 
@@ -82,10 +86,16 @@ Returns:
82
86
  }
83
87
  ```
84
88
 
89
+ ## About Releases
90
+
91
+ Some releases may not have associated source code commits (e.g., `0.2.8`, `0.2.7`). These releases contain type definition updates only.
92
+
93
+ The `vql.d.ts` file is not maintained in this repository. During the release process, it is fetched (via `curl`) from the main project repository and included in the published package. If only the external type definitions change, a new version is published without modifying this repository’s source code.
94
+
85
95
  ## License
86
96
 
87
- MIT wxn0brP
97
+ MIT. See [LICENSE](./LICENSE)
88
98
 
89
99
  ## Contributing
90
100
 
91
- Contributions are welcome!
101
+ Contributions are welcome!
package/dist/vql.d.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  export interface Data {
2
2
  [key: string]: any;
3
3
  }
4
- export interface VContext {
5
- [key: string]: any;
6
- }
7
4
  export type KeysMatching<T, V, C = V> = {
8
5
  [K in keyof T]-?: T[K] extends C ? K : never;
9
6
  }[keyof T];
@@ -13,6 +10,7 @@ export type NestedValue<T, V, C = V> = {
13
10
  export type DeepPartial<T> = {
14
11
  [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
15
12
  };
13
+ export type JSPrimitiveType = "string" | "number" | "boolean" | "bigint" | "symbol" | "undefined" | "function" | "object";
16
14
  export type LogicalOperators<T = any> = {
17
15
  $and?: Array<SearchOptions<T>>;
18
16
  $or?: Array<SearchOptions<T>>;
@@ -39,8 +37,8 @@ export type ComparisonOperators<T = any> = {
39
37
  $idLte?: NestedValue<T, string | number, string | number>;
40
38
  };
41
39
  export type TypeAndExistenceOperators<T = any> = {
42
- $exists?: NestedValue<T, boolean>;
43
- $type?: NestedValue<T, string>;
40
+ $exists?: NestedValue<T, boolean, any>;
41
+ $type?: NestedValue<T, JSPrimitiveType, any>;
44
42
  };
45
43
  export type ArrayOperators<T = any> = {
46
44
  $arrinc?: DeepPartial<T>;
@@ -57,6 +55,9 @@ export type OtherOperators<T = any> = {
57
55
  };
58
56
  export type PredefinedSearchOperators<T = any> = LogicalOperators<T> & ComparisonOperators<T> & TypeAndExistenceOperators<T> & ArrayOperators<T> & StringOperators<T> & OtherOperators<T>;
59
57
  export type SearchOptions<T = any> = PredefinedSearchOperators<T> & DeepPartial<T> & Record<string, any>;
58
+ export interface VContext {
59
+ [key: string]: any;
60
+ }
60
61
  export type ArrayUpdater<T = any> = {
61
62
  $push?: NestedValue<T, any>;
62
63
  $pushset?: NestedValue<T, any>;
@@ -82,6 +83,41 @@ export type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
82
83
  export type UpdaterFunc<T = any> = (data: T, context: VContext) => boolean;
83
84
  export type Search<T = any> = SearchOptions<T> | SearchFunc<T>;
84
85
  export type Updater<T = any> = UpdaterArg<T> | UpdaterArg<T>[] | UpdaterFunc<T>;
86
+ export interface UpdateOneOrAdd<T> {
87
+ add_arg?: Arg<T>;
88
+ id_gen?: boolean;
89
+ context?: VContext;
90
+ }
91
+ export interface VQuery_Control {
92
+ }
93
+ export interface VQuery<T = Data> {
94
+ collection?: string;
95
+ search?: Search<T>;
96
+ context?: VContext;
97
+ dbFindOpts?: DbFindOpts<T>;
98
+ findOpts?: FindOpts<T>;
99
+ data?: Arg<T>;
100
+ id_gen?: boolean;
101
+ add_arg?: Arg<T>;
102
+ updater?: Updater<T>;
103
+ control?: VQuery_Control;
104
+ }
105
+ export type QueryBase<T = Data> = Required<Pick<VQuery<T>, "collection" | "search">> & Pick<VQuery<T>, "control">;
106
+ export type AddQuery<T = Data> = Required<Pick<VQuery<T>, "data" | "collection">> & Pick<VQuery<T>, "id_gen" | "control">;
107
+ export type FindQuery<T = Data> = Omit<QueryBase, "search"> & Pick<VQuery<T>, "search"> & Pick<VQuery<T>, "findOpts" | "dbFindOpts" | "context">;
108
+ export type FindOneQuery<T = Data> = QueryBase & Pick<VQuery<T>, "findOpts" | "context">;
109
+ export type UpdateQuery<T = Data> = QueryBase & Required<Pick<VQuery<T>, "updater">> & Pick<VQuery<T>, "context">;
110
+ export type RemoveQuery<T = Data> = QueryBase & Pick<VQuery<T>, "context">;
111
+ export type UpdateOneOrAddQuery<T = Data> = QueryBase & UpdateQuery & Pick<VQuery<T>, "add_arg" | "id_gen">;
112
+ export type ToggleOneQuery<T = Data> = QueryBase & Pick<VQuery<T>, "data" | "context">;
113
+ export interface UpdateOneOrAddResult<T> {
114
+ data: T;
115
+ type: "added" | "updated";
116
+ }
117
+ export interface ToggleOneResult<T> {
118
+ data: T;
119
+ type: "added" | "removed";
120
+ }
85
121
  export interface DbFindOpts<T = any> {
86
122
  reverse?: boolean;
87
123
  limit?: number;
@@ -94,40 +130,44 @@ export interface FindOpts<T = any> {
94
130
  exclude?: KeysMatching<T, any>[];
95
131
  transform?: Function;
96
132
  }
97
- declare class CollectionManager<D = Data> {
98
- private db;
99
- private collection;
133
+ declare class Collection<D = Data> {
134
+ db: ValtheraCompatible;
135
+ collection: string;
100
136
  constructor(db: ValtheraCompatible, collection: string);
101
- add<T = Data>(data: Arg<T & D>, id_gen?: boolean): Promise<T>;
102
- find<T = Data>(search?: Search<T & D>, options?: DbFindOpts<T & D>, findOpts?: FindOpts<T & D>, context?: VContext): Promise<T[]>;
103
- findOne<T = Data>(search?: Search<T & D>, findOpts?: FindOpts<T & D>, context?: VContext): Promise<T>;
104
- update<T = Data>(search: Search<T & D>, updater: Updater<T & D>, context?: VContext): Promise<boolean>;
105
- updateOne<T = Data>(search: Search<T & D>, updater: Updater<T & D>, context?: VContext): Promise<boolean>;
106
- remove<T = Data>(search: Search<T & D>, context?: VContext): Promise<boolean>;
107
- removeOne<T = Data>(search: Search<T & D>, context?: VContext): Promise<boolean>;
108
- updateOneOrAdd<T = Data>(search: Search<T & D>, updater: Updater<T & D>, { add_arg, context, id_gen }: UpdateOneOrAdd<T & D>): Promise<boolean>;
109
- toggleOne<T = Data>(search: Search<T & D>, data?: Arg<T & D>, context?: VContext): Promise<boolean>;
137
+ add(data: Arg<D>, id_gen: false): Promise<D>;
138
+ add(data: Arg<D>, id_gen?: true): Promise<D & {
139
+ _id: string;
140
+ }>;
141
+ find(search?: Search<D>, options?: DbFindOpts<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D[]>;
142
+ findOne(search?: Search<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D>;
143
+ update(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D[]>;
144
+ updateOne(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<D | null>;
145
+ remove(search: Search<D>, context?: VContext): Promise<D[]>;
146
+ removeOne(search: Search<D>, context?: VContext): Promise<D | null>;
147
+ updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<UpdateOneOrAddResult<D>>;
148
+ toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<ToggleOneResult<D>>;
110
149
  }
111
150
  export interface ValtheraCompatible {
112
- c(collection: string): CollectionManager;
151
+ c<T = Data>(collection: string): Collection<T>;
113
152
  getCollections(): Promise<string[]>;
114
153
  ensureCollection(collection: string): Promise<boolean>;
115
154
  issetCollection(collection: string): Promise<boolean>;
116
- add<T = Data>(collection: string, data: Arg<T>, id_gen?: boolean): Promise<T>;
117
- find<T = Data>(collection: string, search?: Search<T>, options?: DbFindOpts<T>, findOpts?: FindOpts<T>, context?: VContext): Promise<T[]>;
118
- findOne<T = Data>(collection: string, search?: Search<T>, findOpts?: FindOpts<T>, context?: VContext): Promise<T | null>;
119
- update<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
120
- updateOne<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
121
- remove<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
122
- removeOne<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
155
+ add<T = Data>(query: AddQuery<T>): Promise<T>;
156
+ find<T = Data>(query: FindQuery<T>): Promise<T[]>;
157
+ findOne<T = Data>(query: FindOneQuery<T>): Promise<T | null>;
158
+ update<T = Data>(query: UpdateQuery<T>): Promise<T[]>;
159
+ updateOne<T = Data>(query: UpdateQuery<T>): Promise<T | null>;
160
+ remove<T = Data>(query: RemoveQuery<T>): Promise<T[]>;
161
+ removeOne<T = Data>(query: RemoveQuery<T>): Promise<T | null>;
123
162
  removeCollection(collection: string): Promise<boolean>;
124
- updateOneOrAdd<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, opts?: UpdateOneOrAdd<T>): Promise<boolean>;
125
- toggleOne<T = Data>(collection: string, search: Search<T>, data?: Arg<T>, context?: VContext): Promise<boolean>;
163
+ updateOneOrAdd<T = Data>(query: UpdateOneOrAddQuery<T>): Promise<UpdateOneOrAddResult<T>>;
164
+ toggleOne<T = Data>(query: ToggleOneQuery<T>): Promise<ToggleOneResult<T>>;
126
165
  }
127
- export interface UpdateOneOrAdd<T> {
128
- add_arg?: Arg<T>;
129
- id_gen?: boolean;
130
- context?: VContext;
166
+ export interface VQuery_Control {
167
+ dir?: {
168
+ lastFileNum?: number;
169
+ sortedFiles?: string[];
170
+ };
131
171
  }
132
172
  declare namespace RelationTypes {
133
173
  type Path = [
@@ -147,7 +187,7 @@ declare namespace RelationTypes {
147
187
  fk?: string;
148
188
  as?: string;
149
189
  select?: string[];
150
- findOpts?: DbFindOpts;
190
+ dbFindOpts?: DbFindOpts;
151
191
  type?: "1" | "11" | "1n" | "nm";
152
192
  relations?: Relation;
153
193
  through?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql-client",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "VQL Client",