@wxn0brp/vql-client 0.0.3 → 0.0.6

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/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- export type VQLQuery = string | object;
1
+ import { VQLR, VQLRef } from "./vql.js";
2
+ export type VQLQuery = VQLR | string | {
3
+ query: string;
4
+ } & VQLRef;
2
5
  export type VQLResult<T = any> = Promise<T>;
3
6
  export type VQLTransport = (query: VQLQuery) => VQLResult;
4
7
  export type VQLHooks = {
@@ -1 +1 @@
1
- var VQLClient=(()=>{var u=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var x=(t,r)=>{for(var a in r)u(t,a,{get:r[a],enumerable:!0})},E=(t,r,a,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of T(r))!h.call(t,o)&&o!==a&&u(t,o,{get:()=>r[o],enumerable:!(s=w(r,o))||s.enumerable});return t};var m=t=>E(u({},"__esModule",{value:!0}),t);var F={};x(F,{defaultFetchTransport:()=>i,fetchVQL:()=>d,initVQLClient:()=>V,resetVQLClient:()=>c});var Q=i,e={},L="/VQL";function V(t){t.transport&&(Q=t.transport),t.hooks&&(e=t.hooks),t.defaultFetchUrl&&(L=t.defaultFetchUrl)}async function d(t){var a,s,o,p,y;let r=Date.now();try{(a=e.onStart)==null||a.call(e,t);let n=await Q(t),f=Date.now()-r;if((s=e.onEnd)==null||s.call(e,t,f,n),n!=null&&n.err){let l=new Error(n.err);throw(o=e.onError)==null||o.call(e,t,l),l}return(p=n==null?void 0:n.result)!=null?p:n}catch(n){throw(y=e.onError)==null||y.call(e,t,n),n}}function c(){Q=i,e={}}async function i(t){let r=await fetch(L,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t})});if(!r.ok)throw new Error(`VQL request failed: ${r.status}`);return await r.json()}typeof window!="undefined"&&(window.VQLClient={fetchVQL:d,initVQLClient:V,resetVQLClient:c,defaultFetchTransport:i});return m(F);})();
1
+ var VQLClient=(()=>{var Q=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var x=(t,r)=>{for(var a in r)Q(t,a,{get:r[a],enumerable:!0})},m=(t,r,a,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of T(r))!h.call(t,o)&&o!==a&&Q(t,o,{get:()=>r[o],enumerable:!(i=w(r,o))||i.enumerable});return t};var E=t=>m(Q({},"__esModule",{value:!0}),t);var R={};x(R,{defaultFetchTransport:()=>s,fetchVQL:()=>d,initVQLClient:()=>l,resetVQLClient:()=>f});var u=s,e={},y="/VQL";function l(t){t.transport&&(u=t.transport),t.hooks&&(e=t.hooks),t.defaultFetchUrl&&(y=t.defaultFetchUrl)}async function d(t){var a,i,o,p,L;let r=Date.now();try{(a=e.onStart)==null||a.call(e,t);let n=await u(t),c=Date.now()-r;if((i=e.onEnd)==null||i.call(e,t,c,n),n!=null&&n.err){let V=new Error(n.err);throw(o=e.onError)==null||o.call(e,t,V),V}return(p=n==null?void 0:n.result)!=null?p:n}catch(n){throw(L=e.onError)==null||L.call(e,t,n),n}}function f(){u=s,e={}}async function s(t){let r=await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t})});if(!r.ok)throw new Error(`VQL request failed: ${r.status}`);return await r.json()}typeof window!="undefined"&&(window.VQLClient={fetchVQL:d,initVQLClient:l,resetVQLClient:f,defaultFetchTransport:s});return E(R);})();
package/dist/vql.d.ts ADDED
@@ -0,0 +1,275 @@
1
+ export interface Data {
2
+ [key: string]: any;
3
+ }
4
+ export interface Context {
5
+ [key: string]: any;
6
+ }
7
+ export type Id = string;
8
+ export type LogicalOperators = {
9
+ $and?: Array<SearchOptions>;
10
+ $or?: Array<SearchOptions>;
11
+ $not?: SearchOptions;
12
+ };
13
+ export type ComparisonOperators = {
14
+ $gt?: Record<string, number>;
15
+ $lt?: Record<string, number>;
16
+ $gte?: Record<string, number>;
17
+ $lte?: Record<string, number>;
18
+ $in?: Record<string, any[]>;
19
+ $nin?: Record<string, any[]>;
20
+ $between?: Record<string, [
21
+ number,
22
+ number
23
+ ]>;
24
+ };
25
+ export type TypeAndExistenceOperators = {
26
+ $exists?: Record<string, boolean>;
27
+ $type?: Record<string, string>;
28
+ };
29
+ export type ArrayOperators = {
30
+ $arrinc?: Record<string, any[]>;
31
+ $arrincall?: Record<string, any[]>;
32
+ $size?: Record<string, number>;
33
+ };
34
+ export type StringOperators = {
35
+ $regex?: Record<string, RegExp>;
36
+ $startsWith?: Record<string, string>;
37
+ $endsWith?: Record<string, string>;
38
+ };
39
+ export type OtherOperators = {
40
+ $subset?: Record<string, any>;
41
+ };
42
+ export type PredefinedSearchOperators = LogicalOperators & ComparisonOperators & TypeAndExistenceOperators & ArrayOperators & StringOperators & OtherOperators;
43
+ export type SearchOptions = PredefinedSearchOperators & Arg;
44
+ export type ArrayUpdater = {
45
+ $push?: any;
46
+ $pushset?: any;
47
+ $pull?: any;
48
+ $pullall?: any;
49
+ };
50
+ export type ObjectUpdater = {
51
+ $merge?: any;
52
+ };
53
+ export type ValueUpdater = {
54
+ $set?: any;
55
+ $inc?: any;
56
+ $dec?: any;
57
+ $unset?: any;
58
+ $rename?: any;
59
+ };
60
+ export type UpdaterArg = ArrayUpdater & ObjectUpdater & ValueUpdater & {
61
+ [key: string]: any;
62
+ };
63
+ export interface Arg {
64
+ _id?: Id;
65
+ [key: string]: any;
66
+ }
67
+ export type SearchFunc<T = any> = (data: T, context: Context) => boolean;
68
+ export type UpdaterFunc<T = any> = (data: T, context: Context) => boolean;
69
+ export type Search<T = any> = SearchOptions | SearchFunc<T>;
70
+ export type Updater<T = any> = UpdaterArg | UpdaterArg[] | UpdaterFunc<T>;
71
+ export interface DbFindOpts {
72
+ reverse?: boolean;
73
+ max?: number;
74
+ }
75
+ export interface FindOpts {
76
+ select?: string[];
77
+ exclude?: string[];
78
+ transform?: Function;
79
+ }
80
+ export interface Transaction {
81
+ type: "update" | "updateOne" | "updateOneOrAdd" | "remove" | "removeOne";
82
+ search: Search;
83
+ updater?: Updater;
84
+ addArg?: Arg;
85
+ idGen?: boolean;
86
+ context?: Context;
87
+ }
88
+ export interface ValtheraCompatible {
89
+ c(collection: string): CollectionManager;
90
+ getCollections(): Promise<string[]>;
91
+ checkCollection(collection: string): Promise<boolean>;
92
+ issetCollection(collection: string): Promise<boolean>;
93
+ add<T = Data>(collection: string, data: Arg, id_gen?: boolean): Promise<T>;
94
+ find<T = Data>(collection: string, search: Search, context?: Context, options?: DbFindOpts, findOpts?: FindOpts): Promise<T[]>;
95
+ findOne<T = Data>(collection: string, search: Search, context?: Context, findOpts?: FindOpts): Promise<T | null>;
96
+ findStream<T = Data>(collection: string, search: Search, context?: Context, findOpts?: FindOpts, limit?: number): Promise<AsyncGenerator<T>>;
97
+ update(collection: string, search: Search, updater: Updater, context?: Context): Promise<boolean>;
98
+ updateOne(collection: string, search: Search, updater: Updater, context?: Context): Promise<boolean>;
99
+ remove(collection: string, search: Search, context?: Context): Promise<boolean>;
100
+ removeOne(collection: string, search: Search, context?: Context): Promise<boolean>;
101
+ removeCollection(collection: string): Promise<boolean>;
102
+ transaction(collection: string, transaction: Transaction[]): Promise<boolean>;
103
+ updateOneOrAdd(collection: string, search: Search, updater: Updater, add_arg?: Arg, context?: Context, id_gen?: boolean): Promise<boolean>;
104
+ }
105
+ declare class CollectionManager {
106
+ private db;
107
+ private collection;
108
+ constructor(db: ValtheraCompatible, collection: string);
109
+ add<T = Data>(data: Arg, id_gen?: boolean): Promise<T>;
110
+ find<T = Data>(search: Search, context?: Context, options?: DbFindOpts, findOpts?: FindOpts): Promise<T[]>;
111
+ findOne<T = Data>(search: Search, context?: Context, findOpts?: FindOpts): Promise<T>;
112
+ findStream<T = Data>(search: Search, context?: Context, findOpts?: FindOpts, limit?: number): AsyncGenerator<T>;
113
+ update(search: Search, updater: Updater, context?: Context): Promise<boolean>;
114
+ updateOne(search: Search, updater: Updater, context?: Context): Promise<boolean>;
115
+ remove(search: Search, context?: Context): Promise<boolean>;
116
+ removeOne(search: Search, context?: Context): Promise<boolean>;
117
+ updateOneOrAdd(search: Search, updater: Updater, add_arg?: Arg, context?: Context, id_gen?: boolean): Promise<boolean>;
118
+ }
119
+ declare namespace RelationTypes {
120
+ type Path = [
121
+ string,
122
+ string
123
+ ];
124
+ type FieldPath = string[];
125
+ interface DBS {
126
+ [key: string]: ValtheraCompatible;
127
+ }
128
+ interface Relation {
129
+ [key: string]: RelationConfig;
130
+ }
131
+ interface RelationConfig {
132
+ path: Path;
133
+ pk?: string;
134
+ fk?: string;
135
+ as?: string;
136
+ select?: string[];
137
+ findOpts?: DbFindOpts;
138
+ type?: "1" | "11" | "1n" | "nm";
139
+ relations?: Relation;
140
+ through?: {
141
+ table: string;
142
+ db?: string;
143
+ pk: string;
144
+ fk: string;
145
+ };
146
+ }
147
+ }
148
+ export type VQLQuery = {
149
+ find: VQLFind;
150
+ findOne: VQLFindOne;
151
+ f: VQLFindOne;
152
+ add: VQLAdd;
153
+ update: VQLUpdate;
154
+ updateOne: VQLUpdateOne;
155
+ remove: VQLRemove;
156
+ removeOne: VQLRemoveOne;
157
+ updateOneOrAdd: VQLUpdateOneOrAdd;
158
+ removeCollection: VQLCollectionOperation;
159
+ checkCollection: VQLCollectionOperation;
160
+ issetCollection: VQLCollectionOperation;
161
+ getCollections: {};
162
+ };
163
+ export type VQLQueryData = {
164
+ find: VQLFind;
165
+ } | {
166
+ findOne: VQLFindOne;
167
+ } | {
168
+ f: VQLFindOne;
169
+ } | {
170
+ add: VQLAdd;
171
+ } | {
172
+ update: VQLUpdate;
173
+ } | {
174
+ updateOne: VQLUpdateOne;
175
+ } | {
176
+ remove: VQLRemove;
177
+ } | {
178
+ removeOne: VQLRemoveOne;
179
+ } | {
180
+ updateOneOrAdd: VQLUpdateOneOrAdd;
181
+ } | {
182
+ removeCollection: VQLCollectionOperation;
183
+ } | {
184
+ checkCollection: VQLCollectionOperation;
185
+ } | {
186
+ issetCollection: VQLCollectionOperation;
187
+ } | {
188
+ getCollections: {};
189
+ };
190
+ export interface VQLRequest {
191
+ db: string;
192
+ d: VQLQueryData;
193
+ }
194
+ export interface VQLFind {
195
+ collection: string;
196
+ search?: Search;
197
+ limit?: number;
198
+ fields?: VQLFields;
199
+ select?: VQLFields;
200
+ relations?: VQLRelations;
201
+ options?: DbFindOpts;
202
+ searchOpts?: FindOpts;
203
+ }
204
+ export interface VQLFindOne {
205
+ collection: string;
206
+ search: Search;
207
+ fields?: VQLFields;
208
+ select?: VQLFields;
209
+ relations?: VQLRelations;
210
+ searchOpts?: FindOpts;
211
+ }
212
+ export interface VQLAdd {
213
+ collection: string;
214
+ data: Arg;
215
+ id_gen?: boolean;
216
+ }
217
+ export interface VQLUpdate {
218
+ collection: string;
219
+ search: Search;
220
+ updater: UpdaterArg;
221
+ }
222
+ export interface VQLUpdateOne {
223
+ collection: string;
224
+ search: Search;
225
+ updater: UpdaterArg;
226
+ }
227
+ export interface VQLRemove {
228
+ collection: string;
229
+ search: Search;
230
+ }
231
+ export interface VQLRemoveOne {
232
+ collection: string;
233
+ search: Search;
234
+ }
235
+ export interface VQLUpdateOneOrAdd {
236
+ collection: string;
237
+ search: Search;
238
+ updater: UpdaterArg;
239
+ add_arg?: Arg;
240
+ id_gen?: boolean;
241
+ }
242
+ export interface VQLCollectionOperation {
243
+ collection: string;
244
+ }
245
+ export type VQLFields = Record<string, boolean | number> | string[];
246
+ export type VQLRelations = Record<string, VQLFind | VQLFindOne>;
247
+ export interface RelationQuery {
248
+ r: {
249
+ path: RelationTypes.Path;
250
+ search: Search;
251
+ relations: RelationTypes.Relation;
252
+ many?: boolean;
253
+ options?: DbFindOpts;
254
+ select?: RelationTypes.FieldPath[];
255
+ };
256
+ }
257
+ export interface VQLRef {
258
+ ref?: string;
259
+ var?: {
260
+ [k: string]: any;
261
+ };
262
+ }
263
+ export type VQLRefRequired = VQLRef & Required<Pick<VQLRef, "ref">>;
264
+ export type DeepPartial<T> = {
265
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
266
+ };
267
+ export type VQL = (VQLRequest | RelationQuery) & VQLRef;
268
+ export type VQLR = VQL | (DeepPartial<VQL> & VQLRefRequired) | VQLRefRequired;
269
+ export interface VQLError {
270
+ err: true;
271
+ msg: string;
272
+ c: number;
273
+ why?: string;
274
+ }
275
+ export {};
package/dist/vql.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql-client",
3
- "version": "0.0.3",
3
+ "version": "0.0.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "wxn0brP",
@@ -20,6 +20,12 @@
20
20
  "import": "./dist/index.js",
21
21
  "require": "./dist/index.cjs",
22
22
  "default": "./dist/index.js"
23
+ },
24
+ "./*": {
25
+ "types": "./dist/*.d.ts",
26
+ "import": "./dist/*.js",
27
+ "require": "./dist/*.cjs",
28
+ "default": "./dist/*.js"
23
29
  }
24
30
  }
25
31
  }