@auxilium/datalynk-client 0.9.11 → 1.0.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/README.md CHANGED
@@ -157,7 +157,7 @@ import {Contact} from 'models/contact'; // Import model for slice we will be usi
157
157
 
158
158
  const contacts: Contact[] = await api.slice<Contact>(Slices.Contact)
159
159
  .select()
160
- .exec().rows();
160
+ .rows().exec();
161
161
  ```
162
162
 
163
163
  </details>
@@ -167,6 +167,15 @@ const contacts: Contact[] = await api.slice<Contact>(Slices.Contact)
167
167
  <h3 id="authentication" style="display: inline">Authentication</h3>
168
168
  </summary>
169
169
 
170
+ #### Guest
171
+
172
+ Login as the guest account
173
+
174
+ ```js
175
+ const guest = await api.auth.loginGuest();
176
+ console.log(api.auth.isGuest()) // True
177
+ ```
178
+
170
179
  #### Login flow
171
180
 
172
181
  This library comes with some logic to automatically handle the login flow & should be called at the startup of your application:
@@ -212,7 +221,7 @@ const user = await api.auth.login('spoke', 'username', 'password', '2faCode');
212
221
  Multiple requests can be chained together to run them in order. The last request's response will be returned
213
222
 
214
223
  ```js
215
- const report = await api.chain({'$/auth/current': {}}, api.slice(12345).select());
224
+ const report = await api.chain({'$/auth/current': {}}, api.slice(12345).select().rows());
216
225
  ```
217
226
 
218
227
  All results can be returned together by using the `chainMap`
@@ -220,7 +229,7 @@ All results can be returned together by using the `chainMap`
220
229
  ```js
221
230
  const {user, report} = await api.chainMap({
222
231
  user: {'$/auth/current': {}},
223
- report: api.slice(52131).select()
232
+ report: api.slice(52131).select().rows()
224
233
  });
225
234
  ```
226
235
 
@@ -239,12 +248,12 @@ This library comes with LINQ style query language to help make interacting with
239
248
  // Get a single record
240
249
  const row = await api.slice<T>(12345)
241
250
  .select(12345)
242
- .exec().row();
251
+ .row().exec();
243
252
 
244
253
  // Get all slice records
245
254
  const rows = await api.slice<T>(12345)
246
255
  .select()
247
- .exec().rows();
256
+ .rows().exec();
248
257
 
249
258
  // Advanced queries
250
259
  const rows = await api.slice<T>(12345)
@@ -255,7 +264,7 @@ const rows = await api.slice<T>(12345)
255
264
  .where({field1: 0, field2: false})
256
265
  .order('field2', true) // ascending
257
266
  .limit(10)
258
- .exec().rows();
267
+ .rows().exec();
259
268
  ```
260
269
 
261
270
  #### Count
@@ -264,7 +273,7 @@ const rows = await api.slice<T>(12345)
264
273
  const count = await api.slice(12345)
265
274
  .count()
266
275
  .where({field1: 'value'})
267
- .exec().count();
276
+ .count().exec();
268
277
  ```
269
278
 
270
279
  #### Insert
@@ -273,7 +282,7 @@ const count = await api.slice(12345)
273
282
  // Insert record
274
283
  const key = await api.slice<Contact>(12345)
275
284
  .insert({first: 'Bilbo', last: 'Baggins'})
276
- .exec().key();
285
+ .id().exec();
277
286
 
278
287
  // Insert multiple rows
279
288
  const keys = await api.slice<Contacts>(12345)
@@ -281,7 +290,7 @@ const keys = await api.slice<Contacts>(12345)
281
290
  {first: 'Darth', last: 'Vader'},
282
291
  {first: 'John', last: 'Snow'}
283
292
  ])
284
- .exec().keys();
293
+ .ids().exec();
285
294
  ```
286
295
 
287
296
  #### Update
@@ -290,13 +299,13 @@ const keys = await api.slice<Contacts>(12345)
290
299
  // Update a record
291
300
  const success = await api.slice(12345)
292
301
  .update({id: 1, first: 'James', last: 'Kirk'})
293
- .exec().key();
302
+ .id().exec();
294
303
 
295
304
  // Update multiple rows with where
296
305
  await api.slice(12345)
297
306
  .update({evil: true})
298
307
  .where({first: 'Darth'})
299
- .exec().keys();
308
+ .ids().exec();
300
309
  ```
301
310
 
302
311
  #### Delete
@@ -305,13 +314,13 @@ await api.slice(12345)
305
314
  // Delete a record
306
315
  const success = await api.slice(12345)
307
316
  .delete(12345)
308
- .exec().key();
317
+ .id().exec();
309
318
 
310
319
  // Dlete multiple rows with where
311
320
  await api.slice(12345)
312
321
  .delete()
313
322
  .where({first: 'Darth'})
314
- .exec().keys();
323
+ .ids().exec();
315
324
  ```
316
325
 
317
326
  </details>
@@ -363,8 +372,6 @@ api.socket.addListener(callbackFn(event)); // listen to all socket events
363
372
 
364
373
  </details>
365
374
 
366
- </details>
367
-
368
375
  <details>
369
376
  <summary>
370
377
  <h3 id="uploads" style="display: inline">Uploads</h3>
package/dist/api.d.ts CHANGED
@@ -2,7 +2,7 @@ import { BehaviorSubject } from 'rxjs';
2
2
  import { Auth } from './auth';
3
3
  import { Files } from './files';
4
4
  import { Pdf } from './pdf';
5
- import { Slice, SliceMeta } from './slice';
5
+ import { Slice } from './slice';
6
6
  import { Socket } from './socket';
7
7
  import { Superuser } from './superuser';
8
8
 
@@ -37,12 +37,10 @@ export type ApiOptions = {
37
37
  * Possible options for API calls
38
38
  */
39
39
  export interface ApiRequestOptions {
40
- /** Skip optimizations like bundling & caching */
41
- force?: boolean;
40
+ /** Skip bundling & caching */
41
+ noOptimize?: boolean;
42
42
  /** Skip the token translating step */
43
43
  raw?: boolean;
44
- /** Skip wrapping IDs in an array */
45
- rawUpload?: boolean;
46
44
  }
47
45
  /** API error response */
48
46
  export interface ApiError {
@@ -66,7 +64,7 @@ export declare class Api {
66
64
  private bundleOngoing;
67
65
  /** LocalStorage key for persisting logins */
68
66
  private localStorageKey;
69
- /** Pending requests */
67
+ /** Pending requests cache */
70
68
  private pending;
71
69
  /** Authentication helpers */
72
70
  readonly auth: Auth;
@@ -78,7 +76,7 @@ export declare class Api {
78
76
  readonly socket: Socket;
79
77
  /** Superuser helpers */
80
78
  readonly superuser: Superuser;
81
- /** API endpoint */
79
+ /** API URL endpoint */
82
80
  readonly url: string;
83
81
  /** API Session token */
84
82
  token$: BehaviorSubject<string | null>;
@@ -110,7 +108,7 @@ export declare class Api {
110
108
  /**
111
109
  * Chain multiple requests to execute together
112
110
  * @param {Slice<any>} requests List of requests to chain
113
- * @return {Promise<SlicePromise[]>} API Response
111
+ * @return {Promise<any>} API Response
114
112
  */
115
113
  chain(...requests: (any | Slice<any>)[]): Promise<any>;
116
114
  /**
@@ -121,6 +119,14 @@ export declare class Api {
121
119
  chainMap(request: {
122
120
  [key: string]: any;
123
121
  }): Promise<any>;
122
+ /**
123
+ * Exact same as `request` method, but logs the response in the console automatically
124
+ *
125
+ * @param {object | string} data Datalynk request as object or string
126
+ * @param {ApiRequestOptions} options
127
+ * @returns {Promise<any>} Datalynk response
128
+ */
129
+ debug<T = any>(data: any, options?: ApiRequestOptions): Promise<T>;
124
130
  /**
125
131
  * Send a request to Datalynk
126
132
  *
@@ -145,16 +151,8 @@ export declare class Api {
145
151
  * ```
146
152
  *
147
153
  * @param {number} slice Slice number the object will target
148
- * @returns {Slice<T extends SliceMeta>} Object for making requests & caching rows
149
- */
150
- slice<T extends SliceMeta>(slice: number | string): Slice<T>;
151
- /**
152
- * Exact same as `request` method, but logs the response in the console automatically
153
- *
154
- * @param {object | string} data Datalynk request as object or string
155
- * @param {ApiRequestOptions} options
156
- * @returns {Promise<any>} Datalynk response
154
+ * @returns {Slice<T = any>} Object for making requests & caching rows
157
155
  */
158
- test<T = any>(data: any, options?: ApiRequestOptions): Promise<T>;
156
+ slice<T = any>(slice: number | string): Slice<T>;
159
157
  }
160
158
  //# sourceMappingURL=api.d.ts.map
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAuB,MAAM,MAAM,CAAC;AAC3D,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,KAAK,EAAE,SAAS,EAAe,MAAM,SAAS,CAAC;AACvD,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,MAAM,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE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