@wxn0brp/vql-client 0.1.0 → 0.2.0

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,10 +1,10 @@
1
- import { VqlQueryRaw } from "./vql";
1
+ import { VQLUQ } from "./vql";
2
2
  export type VQLResult<T = any> = Promise<T>;
3
- export type VQLTransport = (query: VqlQueryRaw) => VQLResult;
3
+ export type VQLTransport = (query: VQLUQ) => VQLResult;
4
4
  export interface VQLHooks {
5
- onStart?: (query: VqlQueryRaw, hookContext: any) => void;
6
- onEnd?: (query: VqlQueryRaw, durationMs: number, result: any, hookContext: any) => void;
7
- onError?: (query: VqlQueryRaw, error: unknown, result?: any, hookContext?: any) => void;
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: VqlQueryRaw<T>, hookContext?: any): Promise<T>;
16
- export declare function defTransport(query: VqlQueryRaw): Promise<any>;
15
+ export declare function fetchVQL<T = any>(query: VQLUQ<T>, hookContext?: any): Promise<T>;
16
+ export declare function defTransport(query: VQLUQ): Promise<any>;
package/dist/min.js CHANGED
@@ -1 +1 @@
1
- var VQLClient=(()=>{var s=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var T=(n,r)=>{for(var a in r)s(n,a,{get:r[a],enumerable:!0})},R=(n,r,a,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Q(r))!L.call(n,o)&&o!==a&&s(n,o,{get:()=>r[o],enumerable:!(t=V(r,o))||t.enumerable});return n};var q=n=>R(s({},"__esModule",{value:!0}),n);var m={};T(m,{VConfig:()=>i,defTransport:()=>u,fetchVQL:()=>c});var i={transport:u,hooks:{},url:"/VQL"};async function c(n,r={}){var y,w,f,l;let{transport:a,hooks:t}=i,o=Date.now();try{(y=t.onStart)==null||y.call(t,n,r);let e=await a(n),d=Date.now()-o;if((w=t.onEnd)==null||w.call(t,n,d,e,r),e!=null&&e.err){let p=new Error(e.err);throw(f=t.onError)==null||f.call(t,n,p,e,r),p}return e.result!==void 0?e.result:e}catch(e){throw(l=t.onError)==null||l.call(t,n,e,null,r),e}}async function u(n){let r=await fetch(i.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:n})});if(!r.ok)throw new Error(`VQL request failed: ${r.status}`);return await r.json()}typeof window!="undefined"&&(window.VQLClient={fetchVQL:c,defTransport:u,cfg:i});return q(m);})();
1
+ var VQLClient=(()=>{var s=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var T=(n,r)=>{for(var a in r)s(n,a,{get:r[a],enumerable:!0})},m=(n,r,a,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of w(r))!l.call(n,e)&&e!==a&&s(n,e,{get:()=>r[e],enumerable:!(t=L(r,e))||t.enumerable});return n};var x=n=>m(s({},"__esModule",{value:!0}),n);var E={};T(E,{VConfig:()=>i,defTransport:()=>Q,fetchVQL:()=>d});var i={transport:Q,hooks:{},url:"/VQL"};async function d(n,r={}){var u,f,p,c;let{transport:a,hooks:t}=i,e=Date.now();try{(u=t.onStart)==null||u.call(t,n,r);let o=await a(n),V=Date.now()-e;if((f=t.onEnd)==null||f.call(t,n,V,o,r),o!=null&&o.err){let y=new Error(o.err);throw(p=t.onError)==null||p.call(t,n,y,o,r),y}return o.result!==void 0?o.result:o}catch(o){throw(c=t.onError)==null||c.call(t,n,o,null,r),o}}async function Q(n){let r=await fetch(i.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:n})});if(!r.ok)throw new Error(`VQL request failed: ${r.status}`);return await r.json()}typeof window!="undefined"&&(window.VQLClient={fetchVQL:d,defTransport:Q,cfg:i});return x(E);})();
package/dist/vql.d.ts CHANGED
@@ -137,106 +137,79 @@ declare namespace RelationTypes {
137
137
  };
138
138
  }
139
139
  }
140
- export interface VQLQuery<T = any> {
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> {
140
+ export interface VQL_OP_Find<T = any> {
187
141
  collection: string;
188
142
  search?: Search<T>;
189
143
  limit?: number;
190
- fields?: VQLFields;
191
- select?: VQLFields;
192
- relations?: VQLRelations;
144
+ fields?: VQL_Fields;
145
+ select?: VQL_Fields;
193
146
  options?: DbFindOpts<T>;
194
147
  searchOpts?: FindOpts<T>;
195
148
  }
196
- export interface VQLFindOne<T = any> {
149
+ export interface VQL_OP_FindOne<T = any> {
197
150
  collection: string;
198
151
  search: Search<T>;
199
- fields?: VQLFields;
200
- select?: VQLFields;
201
- relations?: VQLRelations;
152
+ fields?: VQL_Fields;
153
+ select?: VQL_Fields;
202
154
  searchOpts?: FindOpts<T>;
203
155
  }
204
- export interface VQLAdd<T = any> {
156
+ export interface VQL_OP_Add<T = any> {
205
157
  collection: string;
206
158
  data: Arg<T>;
207
159
  id_gen?: boolean;
208
160
  }
209
- export interface VQLUpdate<T = any> {
210
- collection: string;
211
- search: Search<T>;
212
- updater: UpdaterArg<T>;
213
- }
214
- export interface VQLUpdateOne<T = any> {
161
+ export interface VQL_OP_Update<T = any> {
215
162
  collection: string;
216
163
  search: Search<T>;
217
164
  updater: UpdaterArg<T>;
218
165
  }
219
- export interface VQLRemove<T = any> {
166
+ export interface VQL_OP_Remove<T = any> {
220
167
  collection: string;
221
168
  search: Search<T>;
222
169
  }
223
- export interface VQLRemoveOne<T = any> {
224
- collection: string;
225
- search: Search<T>;
226
- }
227
- export interface VQLUpdateOneOrAdd<T = any> {
170
+ export interface VQL_OP_UpdateOneOrAdd<T = any> {
228
171
  collection: string;
229
172
  search: Search<T>;
230
173
  updater: UpdaterArg<T>;
231
174
  add_arg?: Arg<T>;
232
175
  id_gen?: boolean;
233
176
  }
234
- export interface VQLCollectionOperation {
177
+ export interface VQL_OP_CollectionOperation {
235
178
  collection: string;
236
179
  }
237
- export type VQLFields = Record<string, boolean | number> | string[];
238
- export type VQLRelations = Record<string, VQLFind | VQLFindOne>;
239
- export interface RelationQuery {
180
+ export type VQL_Fields = Record<string, boolean | number> | string[];
181
+ export type VQL_Query_CRUD_Data<T = any> = {
182
+ find: VQL_OP_Find<T>;
183
+ } | {
184
+ findOne: VQL_OP_FindOne<T>;
185
+ } | {
186
+ f: VQL_OP_FindOne<T>;
187
+ } | {
188
+ add: VQL_OP_Add<T>;
189
+ } | {
190
+ update: VQL_OP_Update<T>;
191
+ } | {
192
+ updateOne: VQL_OP_Update<T>;
193
+ } | {
194
+ remove: VQL_OP_Remove<T>;
195
+ } | {
196
+ removeOne: VQL_OP_Remove<T>;
197
+ } | {
198
+ updateOneOrAdd: VQL_OP_UpdateOneOrAdd<T>;
199
+ } | {
200
+ removeCollection: VQL_OP_CollectionOperation;
201
+ } | {
202
+ ensureCollection: VQL_OP_CollectionOperation;
203
+ } | {
204
+ issetCollection: VQL_OP_CollectionOperation;
205
+ } | {
206
+ getCollections: {};
207
+ };
208
+ export interface VQL_Query_CRUD<T = any> {
209
+ db: string;
210
+ d: VQL_Query_CRUD_Data<T>;
211
+ }
212
+ export interface VQL_Query_Relation {
240
213
  r: {
241
214
  path: RelationTypes.Path;
242
215
  search: Search;
@@ -246,25 +219,18 @@ export interface RelationQuery {
246
219
  select?: RelationTypes.FieldPath[];
247
220
  };
248
221
  }
249
- export interface VQLRef {
250
- ref?: string;
222
+ export interface VQL_Var {
251
223
  var?: {
252
224
  [k: string]: any;
253
225
  };
254
226
  }
255
- export type VQLRefRequired = VQLRef & Required<Pick<VQLRef, "ref">>;
256
- export type DeepPartial<T> = {
257
- [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
258
- };
259
- export type VQL<T = any> = (VQLRequest<T> | RelationQuery) & VQLRef;
260
- export type VQLR<T = any> = VQL<T> | (DeepPartial<VQL<T>> & VQLRefRequired) | VQLRefRequired;
227
+ export type VQL_Query<T = any> = (VQL_Query_CRUD<T> | VQL_Query_Relation) & VQL_Var;
228
+ export type VQLUQ<T = any> = VQL_Query<T> | string | {
229
+ query: string;
230
+ } & VQL_Var;
261
231
  export interface VQLError {
262
232
  err: true;
263
233
  msg: string;
264
234
  c: number;
265
- why?: string;
266
235
  }
267
- export type VqlQueryRaw<T = any> = VQLR<T> | string | {
268
- query: string;
269
- } & VQLRef;
270
236
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/vql-client",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "VQL Client",