@wxn0brp/vql-client 0.1.0 → 0.2.1
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 +7 -7
- package/dist/index.js +8 -1
- package/dist/min.js +1 -1
- package/dist/vql.d.ts +61 -90
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VQLUQ } from "./vql";
|
|
2
2
|
export type VQLResult<T = any> = Promise<T>;
|
|
3
|
-
export type VQLTransport = (query:
|
|
3
|
+
export type VQLTransport = (query: VQLUQ) => VQLResult;
|
|
4
4
|
export interface VQLHooks {
|
|
5
|
-
onStart?: (query:
|
|
6
|
-
onEnd?: (query:
|
|
7
|
-
onError?: (query:
|
|
5
|
+
onStart?: (query: VQLUQ, hookContext: any) => void;
|
|
6
|
+
onEnd?: (query: VQLUQ, durationMs: number, result: any, hookContext: any) => void;
|
|
7
|
+
onError?: (query: VQLUQ, error: unknown, result?: any, hookContext?: any) => void;
|
|
8
8
|
}
|
|
9
9
|
export interface Config {
|
|
10
10
|
transport?: VQLTransport;
|
|
@@ -12,5 +12,5 @@ export interface Config {
|
|
|
12
12
|
url?: string;
|
|
13
13
|
}
|
|
14
14
|
export declare const VConfig: Config;
|
|
15
|
-
export declare function fetchVQL<T = any>(query:
|
|
16
|
-
export declare function defTransport(query:
|
|
15
|
+
export declare function fetchVQL<T = any>(query: VQLUQ<T>, vars?: any, hookContext?: any): Promise<T>;
|
|
16
|
+
export declare function defTransport(query: VQLUQ): Promise<any>;
|
package/dist/index.js
CHANGED
|
@@ -4,11 +4,18 @@ export const VConfig = {
|
|
|
4
4
|
hooks: {},
|
|
5
5
|
url: "/VQL"
|
|
6
6
|
};
|
|
7
|
-
export async function fetchVQL(query, hookContext = {}) {
|
|
7
|
+
export async function fetchVQL(query, vars = {}, hookContext = {}) {
|
|
8
8
|
const { transport, hooks } = VConfig;
|
|
9
9
|
const start = Date.now();
|
|
10
10
|
try {
|
|
11
|
+
hookContext = Object.assign({}, vars, hookContext);
|
|
11
12
|
hooks.onStart?.(query, hookContext);
|
|
13
|
+
if (typeof query === "string" && Object.keys(vars).length) {
|
|
14
|
+
query = {
|
|
15
|
+
query: query,
|
|
16
|
+
var: vars
|
|
17
|
+
};
|
|
18
|
+
}
|
|
12
19
|
const res = await transport(query);
|
|
13
20
|
const duration = Date.now() - start;
|
|
14
21
|
hooks.onEnd?.(query, duration, res, hookContext);
|
package/dist/min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VQLClient=(()=>{var s=Object.defineProperty;var
|
|
1
|
+
var VQLClient=(()=>{var s=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var g=(r,t)=>{for(var e in t)s(r,e,{get:t[e],enumerable:!0})},m=(r,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of w(t))!T.call(r,n)&&n!==e&&s(r,n,{get:()=>t[n],enumerable:!(a=l(t,n))||a.enumerable});return r};var E=r=>m(s({},"__esModule",{value:!0}),r);var U={};g(U,{VConfig:()=>i,defTransport:()=>Q,fetchVQL:()=>d});var i={transport:Q,hooks:{},url:"/VQL"};async function d(r,t={},e={}){var f,c,p,u;let{transport:a,hooks:n}=i,V=Date.now();try{e=Object.assign({},t,e),(f=n.onStart)==null||f.call(n,r,e),typeof r=="string"&&Object.keys(t).length&&(r={query:r,var:t});let o=await a(r),L=Date.now()-V;if((c=n.onEnd)==null||c.call(n,r,L,o,e),o!=null&&o.err){let y=new Error(o.err);throw(p=n.onError)==null||p.call(n,r,y,o,e),y}return o.result!==void 0?o.result:o}catch(o){throw(u=n.onError)==null||u.call(n,r,o,null,e),o}}async function Q(r){let t=await fetch(i.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:r})});if(!t.ok)throw new Error(`VQL request failed: ${t.status}`);return await t.json()}typeof window!="undefined"&&(window.VQLClient={fetchVQL:d,defTransport:Q,cfg:i});return E(U);})();
|
package/dist/vql.d.ts
CHANGED
|
@@ -85,13 +85,13 @@ declare class CollectionManager<D = Data> {
|
|
|
85
85
|
private collection;
|
|
86
86
|
constructor(db: ValtheraCompatible, collection: string);
|
|
87
87
|
add<T = Data>(data: Arg<T & D>, id_gen?: boolean): Promise<T>;
|
|
88
|
-
find<T = Data>(search?: Search<T & D>,
|
|
89
|
-
findOne<T = Data>(search?: Search<T & Data>,
|
|
88
|
+
find<T = Data>(search?: Search<T & D>, options?: DbFindOpts<T & Data>, findOpts?: FindOpts<T & Data>, context?: VContext): Promise<T[]>;
|
|
89
|
+
findOne<T = Data>(search?: Search<T & Data>, findOpts?: FindOpts<T & Data>, context?: VContext): Promise<T>;
|
|
90
90
|
update<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, context?: VContext): Promise<boolean>;
|
|
91
91
|
updateOne<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, context?: VContext): Promise<boolean>;
|
|
92
92
|
remove<T = Data>(search: Search<T & Data>, context?: VContext): Promise<boolean>;
|
|
93
93
|
removeOne<T = Data>(search: Search<T & Data>, context?: VContext): Promise<boolean>;
|
|
94
|
-
updateOneOrAdd<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, add_arg
|
|
94
|
+
updateOneOrAdd<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, { add_arg, context, id_gen }: UpdateOneOrAdd<T & Data>): Promise<boolean>;
|
|
95
95
|
}
|
|
96
96
|
export interface ValtheraCompatible {
|
|
97
97
|
c(collection: string): CollectionManager;
|
|
@@ -99,14 +99,19 @@ export interface ValtheraCompatible {
|
|
|
99
99
|
ensureCollection(collection: string): Promise<boolean>;
|
|
100
100
|
issetCollection(collection: string): Promise<boolean>;
|
|
101
101
|
add<T = Data>(collection: string, data: Arg<T>, id_gen?: boolean): Promise<T>;
|
|
102
|
-
find<T = Data>(collection: string, search
|
|
103
|
-
findOne<T = Data>(collection: string, search
|
|
102
|
+
find<T = Data>(collection: string, search?: Search<T>, options?: DbFindOpts<T>, findOpts?: FindOpts<T>, context?: VContext): Promise<T[]>;
|
|
103
|
+
findOne<T = Data>(collection: string, search?: Search<T>, findOpts?: FindOpts<T>, context?: VContext): Promise<T | null>;
|
|
104
104
|
update<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
|
|
105
105
|
updateOne<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
|
|
106
106
|
remove<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
|
|
107
107
|
removeOne<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
|
|
108
108
|
removeCollection(collection: string): Promise<boolean>;
|
|
109
|
-
updateOneOrAdd<T = Data>(collection: string, search: Search<T>, updater: Updater<T>,
|
|
109
|
+
updateOneOrAdd<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, opts?: UpdateOneOrAdd<T>): Promise<boolean>;
|
|
110
|
+
}
|
|
111
|
+
export interface UpdateOneOrAdd<T> {
|
|
112
|
+
add_arg?: Arg<T>;
|
|
113
|
+
id_gen?: boolean;
|
|
114
|
+
context?: VContext;
|
|
110
115
|
}
|
|
111
116
|
declare namespace RelationTypes {
|
|
112
117
|
type Path = [
|
|
@@ -137,134 +142,100 @@ declare namespace RelationTypes {
|
|
|
137
142
|
};
|
|
138
143
|
}
|
|
139
144
|
}
|
|
140
|
-
export interface
|
|
141
|
-
find: VQLFind<T>;
|
|
142
|
-
findOne: VQLFindOne<T>;
|
|
143
|
-
f: VQLFindOne<T>;
|
|
144
|
-
add: VQLAdd<T>;
|
|
145
|
-
update: VQLUpdate<T>;
|
|
146
|
-
updateOne: VQLUpdateOne<T>;
|
|
147
|
-
remove: VQLRemove<T>;
|
|
148
|
-
removeOne: VQLRemoveOne<T>;
|
|
149
|
-
updateOneOrAdd: VQLUpdateOneOrAdd<T>;
|
|
150
|
-
removeCollection: VQLCollectionOperation;
|
|
151
|
-
ensureCollection: VQLCollectionOperation;
|
|
152
|
-
issetCollection: VQLCollectionOperation;
|
|
153
|
-
getCollections: {};
|
|
154
|
-
}
|
|
155
|
-
export type VQLQueryData<T = any> = {
|
|
156
|
-
find: VQLFind<T>;
|
|
157
|
-
} | {
|
|
158
|
-
findOne: VQLFindOne<T>;
|
|
159
|
-
} | {
|
|
160
|
-
f: VQLFindOne<T>;
|
|
161
|
-
} | {
|
|
162
|
-
add: VQLAdd<T>;
|
|
163
|
-
} | {
|
|
164
|
-
update: VQLUpdate<T>;
|
|
165
|
-
} | {
|
|
166
|
-
updateOne: VQLUpdateOne<T>;
|
|
167
|
-
} | {
|
|
168
|
-
remove: VQLRemove<T>;
|
|
169
|
-
} | {
|
|
170
|
-
removeOne: VQLRemoveOne<T>;
|
|
171
|
-
} | {
|
|
172
|
-
updateOneOrAdd: VQLUpdateOneOrAdd<T>;
|
|
173
|
-
} | {
|
|
174
|
-
removeCollection: VQLCollectionOperation;
|
|
175
|
-
} | {
|
|
176
|
-
ensureCollection: VQLCollectionOperation;
|
|
177
|
-
} | {
|
|
178
|
-
issetCollection: VQLCollectionOperation;
|
|
179
|
-
} | {
|
|
180
|
-
getCollections: {};
|
|
181
|
-
};
|
|
182
|
-
export interface VQLRequest<T = any> {
|
|
183
|
-
db: string;
|
|
184
|
-
d: VQLQueryData<T>;
|
|
185
|
-
}
|
|
186
|
-
export interface VQLFind<T = any> {
|
|
145
|
+
export interface VQL_OP_Find<T = any> {
|
|
187
146
|
collection: string;
|
|
188
147
|
search?: Search<T>;
|
|
189
148
|
limit?: number;
|
|
190
|
-
fields?:
|
|
191
|
-
select?:
|
|
192
|
-
relations?: VQLRelations;
|
|
149
|
+
fields?: VQL_Fields;
|
|
150
|
+
select?: VQL_Fields;
|
|
193
151
|
options?: DbFindOpts<T>;
|
|
194
152
|
searchOpts?: FindOpts<T>;
|
|
195
153
|
}
|
|
196
|
-
export interface
|
|
154
|
+
export interface VQL_OP_FindOne<T = any> {
|
|
197
155
|
collection: string;
|
|
198
156
|
search: Search<T>;
|
|
199
|
-
fields?:
|
|
200
|
-
select?:
|
|
201
|
-
relations?: VQLRelations;
|
|
157
|
+
fields?: VQL_Fields;
|
|
158
|
+
select?: VQL_Fields;
|
|
202
159
|
searchOpts?: FindOpts<T>;
|
|
203
160
|
}
|
|
204
|
-
export interface
|
|
161
|
+
export interface VQL_OP_Add<T = any> {
|
|
205
162
|
collection: string;
|
|
206
163
|
data: Arg<T>;
|
|
207
164
|
id_gen?: boolean;
|
|
208
165
|
}
|
|
209
|
-
export interface
|
|
166
|
+
export interface VQL_OP_Update<T = any> {
|
|
210
167
|
collection: string;
|
|
211
168
|
search: Search<T>;
|
|
212
169
|
updater: UpdaterArg<T>;
|
|
213
170
|
}
|
|
214
|
-
export interface
|
|
171
|
+
export interface VQL_OP_Remove<T = any> {
|
|
215
172
|
collection: string;
|
|
216
173
|
search: Search<T>;
|
|
217
|
-
updater: UpdaterArg<T>;
|
|
218
174
|
}
|
|
219
|
-
export interface
|
|
220
|
-
collection: string;
|
|
221
|
-
search: Search<T>;
|
|
222
|
-
}
|
|
223
|
-
export interface VQLRemoveOne<T = any> {
|
|
224
|
-
collection: string;
|
|
225
|
-
search: Search<T>;
|
|
226
|
-
}
|
|
227
|
-
export interface VQLUpdateOneOrAdd<T = any> {
|
|
175
|
+
export interface VQL_OP_UpdateOneOrAdd<T = any> {
|
|
228
176
|
collection: string;
|
|
229
177
|
search: Search<T>;
|
|
230
178
|
updater: UpdaterArg<T>;
|
|
231
179
|
add_arg?: Arg<T>;
|
|
232
180
|
id_gen?: boolean;
|
|
233
181
|
}
|
|
234
|
-
export interface
|
|
182
|
+
export interface VQL_OP_CollectionOperation {
|
|
235
183
|
collection: string;
|
|
236
184
|
}
|
|
237
|
-
export type
|
|
238
|
-
export type
|
|
239
|
-
|
|
185
|
+
export type VQL_Fields = Record<string, boolean | number> | string[];
|
|
186
|
+
export type VQL_Query_CRUD_Data<T = any> = {
|
|
187
|
+
find: VQL_OP_Find<T>;
|
|
188
|
+
} | {
|
|
189
|
+
findOne: VQL_OP_FindOne<T>;
|
|
190
|
+
} | {
|
|
191
|
+
f: VQL_OP_FindOne<T>;
|
|
192
|
+
} | {
|
|
193
|
+
add: VQL_OP_Add<T>;
|
|
194
|
+
} | {
|
|
195
|
+
update: VQL_OP_Update<T>;
|
|
196
|
+
} | {
|
|
197
|
+
updateOne: VQL_OP_Update<T>;
|
|
198
|
+
} | {
|
|
199
|
+
remove: VQL_OP_Remove<T>;
|
|
200
|
+
} | {
|
|
201
|
+
removeOne: VQL_OP_Remove<T>;
|
|
202
|
+
} | {
|
|
203
|
+
updateOneOrAdd: VQL_OP_UpdateOneOrAdd<T>;
|
|
204
|
+
} | {
|
|
205
|
+
removeCollection: VQL_OP_CollectionOperation;
|
|
206
|
+
} | {
|
|
207
|
+
ensureCollection: VQL_OP_CollectionOperation;
|
|
208
|
+
} | {
|
|
209
|
+
issetCollection: VQL_OP_CollectionOperation;
|
|
210
|
+
} | {
|
|
211
|
+
getCollections: {};
|
|
212
|
+
};
|
|
213
|
+
export interface VQL_Query_CRUD<T = any> {
|
|
214
|
+
db: string;
|
|
215
|
+
d: VQL_Query_CRUD_Data<T>;
|
|
216
|
+
}
|
|
217
|
+
export interface VQL_Query_Relation {
|
|
240
218
|
r: {
|
|
241
219
|
path: RelationTypes.Path;
|
|
242
220
|
search: Search;
|
|
243
221
|
relations: RelationTypes.Relation;
|
|
244
222
|
many?: boolean;
|
|
245
223
|
options?: DbFindOpts;
|
|
246
|
-
select?: RelationTypes.FieldPath[]
|
|
224
|
+
select?: RelationTypes.FieldPath[] | Record<string, any>;
|
|
247
225
|
};
|
|
248
226
|
}
|
|
249
|
-
export interface
|
|
250
|
-
ref?: string;
|
|
227
|
+
export interface VQL_Var {
|
|
251
228
|
var?: {
|
|
252
229
|
[k: string]: any;
|
|
253
230
|
};
|
|
254
231
|
}
|
|
255
|
-
export type
|
|
256
|
-
export type
|
|
257
|
-
|
|
258
|
-
};
|
|
259
|
-
export type VQL<T = any> = (VQLRequest<T> | RelationQuery) & VQLRef;
|
|
260
|
-
export type VQLR<T = any> = VQL<T> | (DeepPartial<VQL<T>> & VQLRefRequired) | VQLRefRequired;
|
|
232
|
+
export type VQL_Query<T = any> = (VQL_Query_CRUD<T> | VQL_Query_Relation) & VQL_Var;
|
|
233
|
+
export type VQLUQ<T = any> = VQL_Query<T> | string | {
|
|
234
|
+
query: string;
|
|
235
|
+
} & VQL_Var;
|
|
261
236
|
export interface VQLError {
|
|
262
237
|
err: true;
|
|
263
238
|
msg: string;
|
|
264
239
|
c: number;
|
|
265
|
-
why?: string;
|
|
266
240
|
}
|
|
267
|
-
export type VqlQueryRaw<T = any> = VQLR<T> | string | {
|
|
268
|
-
query: string;
|
|
269
|
-
} & VQLRef;
|
|
270
241
|
export {};
|