@auxilium/datalynk-client 0.9.2 → 0.9.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/README.md +10 -1
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +128 -23
- package/dist/index.mjs +128 -23
- package/dist/slice.d.ts +99 -16
- package/dist/slice.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -227,15 +227,24 @@ const rows = await api.slice<T>(12345)
|
|
|
227
227
|
// Advanced queries
|
|
228
228
|
const rows = await api.slice<T>(12345)
|
|
229
229
|
.select()
|
|
230
|
+
.fields({'field1': 'field2'})
|
|
230
231
|
.where('field1', '<', 0)
|
|
231
232
|
.or()
|
|
232
233
|
.where({field1: 0, field2: false})
|
|
233
|
-
.fields({'field1': 'field2'})
|
|
234
234
|
.order('field2', true) // ascending
|
|
235
235
|
.limit(10)
|
|
236
236
|
.exec().rows();
|
|
237
237
|
```
|
|
238
238
|
|
|
239
|
+
#### Count
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
const count = await api.slice(12345)
|
|
243
|
+
.count()
|
|
244
|
+
.where({field1: 'value'})
|
|
245
|
+
.exec().count();
|
|
246
|
+
```
|
|
247
|
+
|
|
239
248
|
#### Insert
|
|
240
249
|
|
|
241
250
|
```ts
|
package/dist/api.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export type JwtPayload = {
|
|
|
24
24
|
export type ApiOptions = {
|
|
25
25
|
/** Bundle requests together that happen in quick succession */
|
|
26
26
|
bundleTime?: number;
|
|
27
|
+
/** Use legacy dates by default */
|
|
28
|
+
legacyDates?: boolean;
|
|
27
29
|
/** Name of client for logging */
|
|
28
30
|
origin?: string;
|
|
29
31
|
/** Save session token to localStorage to persist logins */
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.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AE,MAAM,GAAG,MAAM;IAIxD;;;;;;OAMG;IACI,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,CAAC,CAAC;CAS5E"}
|
package/dist/index.cjs
CHANGED
|
@@ -2013,6 +2013,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2013
2013
|
catch(callback) {
|
|
2014
2014
|
return this.promise.catch(callback);
|
|
2015
2015
|
}
|
|
2016
|
+
/**
|
|
2017
|
+
* Count rows or fetch count alias result
|
|
2018
|
+
*/
|
|
2019
|
+
async count() {
|
|
2020
|
+
var _a, _b;
|
|
2021
|
+
const rows = await this.rows();
|
|
2022
|
+
if (typeof ((_a = rows == null ? void 0 : rows[0]) == null ? void 0 : _a["count"]) == "number") return (_b = rows == null ? void 0 : rows[0]) == null ? void 0 : _b["count"];
|
|
2023
|
+
return rows.length;
|
|
2024
|
+
}
|
|
2016
2025
|
/**
|
|
2017
2026
|
* Log the raw result to the console for inspection
|
|
2018
2027
|
*/
|
|
@@ -2120,7 +2129,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2120
2129
|
}
|
|
2121
2130
|
/**
|
|
2122
2131
|
* Whitelist and alias fields. Alias for the fields functions
|
|
2123
|
-
*
|
|
2132
|
+
* @example
|
|
2133
|
+
* ```ts
|
|
2134
|
+
* const id: {id: number, field2: any}[] = await new Slice<T>(12345)
|
|
2135
|
+
* .select().alias({id: 'id', field1: 'field2'}).exec().keys();
|
|
2136
|
+
* ```
|
|
2124
2137
|
* @param {object} aliasKeyVals List of properties to whitelist and what to rename them to
|
|
2125
2138
|
*/
|
|
2126
2139
|
alias(aliasKeyVals) {
|
|
@@ -2128,6 +2141,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2128
2141
|
}
|
|
2129
2142
|
/**
|
|
2130
2143
|
* Add an 'AND' condition inside the where argument
|
|
2144
|
+
* @example
|
|
2145
|
+
* ```ts
|
|
2146
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
2147
|
+
* .where('field1', '>', 1)
|
|
2148
|
+
* .and()
|
|
2149
|
+
* .where({field2: 2, field3: 3})
|
|
2150
|
+
* .exec().rows();
|
|
2151
|
+
* ```
|
|
2131
2152
|
*/
|
|
2132
2153
|
and() {
|
|
2133
2154
|
var _a;
|
|
@@ -2136,6 +2157,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2136
2157
|
else this.request.where = ["$and"];
|
|
2137
2158
|
return this;
|
|
2138
2159
|
}
|
|
2160
|
+
/**
|
|
2161
|
+
* Count the returned rows
|
|
2162
|
+
* @example
|
|
2163
|
+
* ```ts
|
|
2164
|
+
* const count = await new Slice(12345).count()
|
|
2165
|
+
* .where({field1: 1})
|
|
2166
|
+
* .exec().count();
|
|
2167
|
+
* ```
|
|
2168
|
+
* @param {object | string} arg Count argument
|
|
2169
|
+
*/
|
|
2170
|
+
count(arg = "id") {
|
|
2171
|
+
this.operation = "$/slice/report";
|
|
2172
|
+
this.request.fields = { count: ["$count", typeof arg == "object" ? arg : ["$field", arg]] };
|
|
2173
|
+
return this;
|
|
2174
|
+
}
|
|
2139
2175
|
/**
|
|
2140
2176
|
* Output the formed request to the console for inspection
|
|
2141
2177
|
*/
|
|
@@ -2145,7 +2181,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2145
2181
|
}
|
|
2146
2182
|
/**
|
|
2147
2183
|
* Set the request type to delete
|
|
2148
|
-
*
|
|
2184
|
+
* @example
|
|
2185
|
+
* ```ts
|
|
2186
|
+
* await new Slice(12345).delete(id).exec();
|
|
2187
|
+
* ```
|
|
2149
2188
|
* @param {number | number[]} id ID(s) to delete
|
|
2150
2189
|
*/
|
|
2151
2190
|
delete(id) {
|
|
@@ -2158,16 +2197,23 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2158
2197
|
}
|
|
2159
2198
|
/**
|
|
2160
2199
|
* Filter rows from slice based on an excel expression
|
|
2161
|
-
*
|
|
2162
|
-
*
|
|
2200
|
+
* @example
|
|
2201
|
+
* ```ts
|
|
2202
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
2203
|
+
* .excel('')
|
|
2204
|
+
* .exec().rows();
|
|
2205
|
+
* ```
|
|
2206
|
+
* @param formula Excel formula to use as where clause
|
|
2163
2207
|
*/
|
|
2164
|
-
excel(
|
|
2165
|
-
this.request.where
|
|
2208
|
+
excel(formula) {
|
|
2209
|
+
if (this.request.where) {
|
|
2210
|
+
this.and();
|
|
2211
|
+
this.request.push({ "$excel": formula });
|
|
2212
|
+
} else this.request.where = { "$excel": formula };
|
|
2166
2213
|
return this;
|
|
2167
2214
|
}
|
|
2168
2215
|
/**
|
|
2169
2216
|
* Compile the request and send it
|
|
2170
|
-
*
|
|
2171
2217
|
* @param {ApiRequestOptions} options API Request options
|
|
2172
2218
|
* @return {SlicePromise<T>}
|
|
2173
2219
|
*/
|
|
@@ -2182,7 +2228,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2182
2228
|
}
|
|
2183
2229
|
/**
|
|
2184
2230
|
* Set the request type to insert
|
|
2185
|
-
*
|
|
2231
|
+
* @example
|
|
2232
|
+
* ```ts
|
|
2233
|
+
* const id: number = await new Slice<T>(12345).insert([
|
|
2234
|
+
* {field1: 1},
|
|
2235
|
+
* {field1: 2}
|
|
2236
|
+
* ]).exec().keys();
|
|
2237
|
+
* ```
|
|
2186
2238
|
* @param {T | T[]} rows Rows to be inserted into the slice
|
|
2187
2239
|
*/
|
|
2188
2240
|
insert(rows) {
|
|
@@ -2194,7 +2246,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2194
2246
|
}
|
|
2195
2247
|
/**
|
|
2196
2248
|
* Limit number of rows returned
|
|
2197
|
-
*
|
|
2249
|
+
* @example
|
|
2250
|
+
* ```ts
|
|
2251
|
+
* const rows: T[] = await new Slice<T>(12345).select().limit(10)
|
|
2252
|
+
* .exec().rows();
|
|
2253
|
+
* ```
|
|
2198
2254
|
* @param {number} num Number of rows to return
|
|
2199
2255
|
*/
|
|
2200
2256
|
limit(num) {
|
|
@@ -2202,17 +2258,34 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2202
2258
|
}
|
|
2203
2259
|
/**
|
|
2204
2260
|
* Add an 'OR' condition inside the where argument
|
|
2261
|
+
* @example
|
|
2262
|
+
* ```ts
|
|
2263
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
2264
|
+
* .where('field1', '>', 1)
|
|
2265
|
+
* .or()
|
|
2266
|
+
* .where({field2: 2, field3: 3})
|
|
2267
|
+
* .or()
|
|
2268
|
+
* .where(['$gt', ['$field', field4], 4)
|
|
2269
|
+
* .exec().rows();
|
|
2270
|
+
* ```
|
|
2205
2271
|
*/
|
|
2206
2272
|
or() {
|
|
2207
2273
|
var _a;
|
|
2208
|
-
if (((_a = this.request.where) == null ? void 0 : _a[0]) == "$or")
|
|
2209
|
-
|
|
2210
|
-
|
|
2274
|
+
if (((_a = this.request.where) == null ? void 0 : _a[0]) == "$or") {
|
|
2275
|
+
this.request.where.push(null);
|
|
2276
|
+
return this;
|
|
2277
|
+
}
|
|
2278
|
+
if (this.request.where) this.request.where = ["$or", this.request.where, null];
|
|
2279
|
+
else this.request.where = ["$or", null];
|
|
2211
2280
|
return this;
|
|
2212
2281
|
}
|
|
2213
2282
|
/**
|
|
2214
2283
|
* Order rows by a field
|
|
2215
|
-
*
|
|
2284
|
+
* @example
|
|
2285
|
+
* ```ts
|
|
2286
|
+
* const rows: T[] = new Slice<T>(12345).select().order('field1', true) // true = ascending
|
|
2287
|
+
* .exec().rows();
|
|
2288
|
+
* ```
|
|
2216
2289
|
* @param {string} field property name
|
|
2217
2290
|
* @param {boolean} ascending Sort in ascending or descending order
|
|
2218
2291
|
*/
|
|
@@ -2223,7 +2296,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2223
2296
|
}
|
|
2224
2297
|
/**
|
|
2225
2298
|
* Set the request type to select
|
|
2226
|
-
*
|
|
2299
|
+
* @example
|
|
2300
|
+
* ```ts
|
|
2301
|
+
* const rows: T[] = new Slice<T>(12345).select().exec().rows();
|
|
2302
|
+
* const row: T = new Slice<T>(12345).select(id).exec().row();
|
|
2303
|
+
* ```
|
|
2227
2304
|
* @param {number | number[]} id ID(s) to select, leaving blank will return all rows
|
|
2228
2305
|
*/
|
|
2229
2306
|
select(id) {
|
|
@@ -2236,7 +2313,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2236
2313
|
}
|
|
2237
2314
|
/**
|
|
2238
2315
|
* Synchronize cache with server
|
|
2239
|
-
*
|
|
2316
|
+
* @example
|
|
2317
|
+
* ```ts
|
|
2318
|
+
* const slice: Slice = new Slice<T>(Slices.Contact);
|
|
2319
|
+
* slice.sync().subscribe((rows: T[]) => {});
|
|
2320
|
+
* ```
|
|
2240
2321
|
* @param {boolean} on Enable/disable events
|
|
2241
2322
|
* @return {BehaviorSubject<T[]>} Cache which can be subscribed to
|
|
2242
2323
|
*/
|
|
@@ -2256,7 +2337,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2256
2337
|
}
|
|
2257
2338
|
/**
|
|
2258
2339
|
* Set the request type to update
|
|
2259
|
-
*
|
|
2340
|
+
* @example
|
|
2341
|
+
* ```ts
|
|
2342
|
+
* const ids: number[] = await new Slice<Type>(12345).update([
|
|
2343
|
+
* {id: 1, field1: 1},
|
|
2344
|
+
* {id: 2, field1: 1}
|
|
2345
|
+
* ]).exec().keys();
|
|
2346
|
+
* ```
|
|
2260
2347
|
* @param {T | T[]} rows Rows to be updated, each row must have an ID
|
|
2261
2348
|
*/
|
|
2262
2349
|
update(rows) {
|
|
@@ -2267,17 +2354,24 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2267
2354
|
return this;
|
|
2268
2355
|
}
|
|
2269
2356
|
/**
|
|
2270
|
-
* Add where condition to request
|
|
2271
|
-
*
|
|
2272
|
-
*
|
|
2357
|
+
* Add where condition to request
|
|
2358
|
+
* @example
|
|
2359
|
+
* ```ts
|
|
2360
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
2361
|
+
* .where('field1', '>', 1)
|
|
2362
|
+
* .where({field2: 2, field3: 3}) // Automatic AND
|
|
2363
|
+
* .or()
|
|
2364
|
+
* .where(['$gt', ['$field', field4], 4)
|
|
2365
|
+
* .exec().rows();
|
|
2366
|
+
* ```
|
|
2273
2367
|
* @param {string | object} field property to compare or a map of equality comparisons
|
|
2274
2368
|
* @param {string} operator Operation to compare with. Accepts JS operators (>=, ==, !=, ...) as well as datalynk styax ($gte, $eq, $is, $not, ...)
|
|
2275
2369
|
* @param {any} value value to compare against
|
|
2276
2370
|
*/
|
|
2277
2371
|
where(field, operator, value) {
|
|
2278
|
-
this.and();
|
|
2372
|
+
if (this.request.where && this.request.where[0] != "$or") this.and();
|
|
2279
2373
|
if (typeof field == "object") {
|
|
2280
|
-
Object.entries(field).forEach(([key, value2]) => this.
|
|
2374
|
+
Object.entries(field).forEach(([key, value2]) => this.where(key, "==", value2));
|
|
2281
2375
|
} else if (operator == null) {
|
|
2282
2376
|
throw new Error("Malformed where clause");
|
|
2283
2377
|
} else {
|
|
@@ -2307,7 +2401,17 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2307
2401
|
operator = "$mod";
|
|
2308
2402
|
break;
|
|
2309
2403
|
}
|
|
2310
|
-
this.request.where.
|
|
2404
|
+
if (!this.request.where) this.request.where = [operator, ["$field", field], value];
|
|
2405
|
+
else {
|
|
2406
|
+
if (this.request.where[0] == "$or") {
|
|
2407
|
+
const i = this.request.where.length - 1;
|
|
2408
|
+
if (this.request.where[i] == null) this.request.where[i] = [operator, ["$field", field], value];
|
|
2409
|
+
else {
|
|
2410
|
+
if (this.request.where[i][0] == "$and") this.request.where[i].push([operator, ["$field", field], value]);
|
|
2411
|
+
else this.request.where[i] = ["$and", this.request.where[i], [operator, ["$field", field], value]];
|
|
2412
|
+
}
|
|
2413
|
+
} else this.request.where.push([operator, ["$field", field], value]);
|
|
2414
|
+
}
|
|
2311
2415
|
}
|
|
2312
2416
|
return this;
|
|
2313
2417
|
}
|
|
@@ -2519,7 +2623,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2519
2623
|
method: "POST",
|
|
2520
2624
|
headers: clean({
|
|
2521
2625
|
Authorization: this.token ? `Bearer ${this.token}` : void 0,
|
|
2522
|
-
"Content-Type": "application/json"
|
|
2626
|
+
"Content-Type": "application/json",
|
|
2627
|
+
"X-Date-Return-Format": this.options.legacyDates ? void 0 : "ISO8601"
|
|
2523
2628
|
}),
|
|
2524
2629
|
body: JSON.stringify(Api.translateTokens(req))
|
|
2525
2630
|
}).then(async (resp) => {
|
package/dist/index.mjs
CHANGED
|
@@ -2009,6 +2009,15 @@ class SlicePromise {
|
|
|
2009
2009
|
catch(callback) {
|
|
2010
2010
|
return this.promise.catch(callback);
|
|
2011
2011
|
}
|
|
2012
|
+
/**
|
|
2013
|
+
* Count rows or fetch count alias result
|
|
2014
|
+
*/
|
|
2015
|
+
async count() {
|
|
2016
|
+
var _a, _b;
|
|
2017
|
+
const rows = await this.rows();
|
|
2018
|
+
if (typeof ((_a = rows == null ? void 0 : rows[0]) == null ? void 0 : _a["count"]) == "number") return (_b = rows == null ? void 0 : rows[0]) == null ? void 0 : _b["count"];
|
|
2019
|
+
return rows.length;
|
|
2020
|
+
}
|
|
2012
2021
|
/**
|
|
2013
2022
|
* Log the raw result to the console for inspection
|
|
2014
2023
|
*/
|
|
@@ -2116,7 +2125,11 @@ class Slice {
|
|
|
2116
2125
|
}
|
|
2117
2126
|
/**
|
|
2118
2127
|
* Whitelist and alias fields. Alias for the fields functions
|
|
2119
|
-
*
|
|
2128
|
+
* @example
|
|
2129
|
+
* ```ts
|
|
2130
|
+
* const id: {id: number, field2: any}[] = await new Slice<T>(12345)
|
|
2131
|
+
* .select().alias({id: 'id', field1: 'field2'}).exec().keys();
|
|
2132
|
+
* ```
|
|
2120
2133
|
* @param {object} aliasKeyVals List of properties to whitelist and what to rename them to
|
|
2121
2134
|
*/
|
|
2122
2135
|
alias(aliasKeyVals) {
|
|
@@ -2124,6 +2137,14 @@ class Slice {
|
|
|
2124
2137
|
}
|
|
2125
2138
|
/**
|
|
2126
2139
|
* Add an 'AND' condition inside the where argument
|
|
2140
|
+
* @example
|
|
2141
|
+
* ```ts
|
|
2142
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
2143
|
+
* .where('field1', '>', 1)
|
|
2144
|
+
* .and()
|
|
2145
|
+
* .where({field2: 2, field3: 3})
|
|
2146
|
+
* .exec().rows();
|
|
2147
|
+
* ```
|
|
2127
2148
|
*/
|
|
2128
2149
|
and() {
|
|
2129
2150
|
var _a;
|
|
@@ -2132,6 +2153,21 @@ class Slice {
|
|
|
2132
2153
|
else this.request.where = ["$and"];
|
|
2133
2154
|
return this;
|
|
2134
2155
|
}
|
|
2156
|
+
/**
|
|
2157
|
+
* Count the returned rows
|
|
2158
|
+
* @example
|
|
2159
|
+
* ```ts
|
|
2160
|
+
* const count = await new Slice(12345).count()
|
|
2161
|
+
* .where({field1: 1})
|
|
2162
|
+
* .exec().count();
|
|
2163
|
+
* ```
|
|
2164
|
+
* @param {object | string} arg Count argument
|
|
2165
|
+
*/
|
|
2166
|
+
count(arg = "id") {
|
|
2167
|
+
this.operation = "$/slice/report";
|
|
2168
|
+
this.request.fields = { count: ["$count", typeof arg == "object" ? arg : ["$field", arg]] };
|
|
2169
|
+
return this;
|
|
2170
|
+
}
|
|
2135
2171
|
/**
|
|
2136
2172
|
* Output the formed request to the console for inspection
|
|
2137
2173
|
*/
|
|
@@ -2141,7 +2177,10 @@ class Slice {
|
|
|
2141
2177
|
}
|
|
2142
2178
|
/**
|
|
2143
2179
|
* Set the request type to delete
|
|
2144
|
-
*
|
|
2180
|
+
* @example
|
|
2181
|
+
* ```ts
|
|
2182
|
+
* await new Slice(12345).delete(id).exec();
|
|
2183
|
+
* ```
|
|
2145
2184
|
* @param {number | number[]} id ID(s) to delete
|
|
2146
2185
|
*/
|
|
2147
2186
|
delete(id) {
|
|
@@ -2154,16 +2193,23 @@ class Slice {
|
|
|
2154
2193
|
}
|
|
2155
2194
|
/**
|
|
2156
2195
|
* Filter rows from slice based on an excel expression
|
|
2157
|
-
*
|
|
2158
|
-
*
|
|
2196
|
+
* @example
|
|
2197
|
+
* ```ts
|
|
2198
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
2199
|
+
* .excel('')
|
|
2200
|
+
* .exec().rows();
|
|
2201
|
+
* ```
|
|
2202
|
+
* @param formula Excel formula to use as where clause
|
|
2159
2203
|
*/
|
|
2160
|
-
excel(
|
|
2161
|
-
this.request.where
|
|
2204
|
+
excel(formula) {
|
|
2205
|
+
if (this.request.where) {
|
|
2206
|
+
this.and();
|
|
2207
|
+
this.request.push({ "$excel": formula });
|
|
2208
|
+
} else this.request.where = { "$excel": formula };
|
|
2162
2209
|
return this;
|
|
2163
2210
|
}
|
|
2164
2211
|
/**
|
|
2165
2212
|
* Compile the request and send it
|
|
2166
|
-
*
|
|
2167
2213
|
* @param {ApiRequestOptions} options API Request options
|
|
2168
2214
|
* @return {SlicePromise<T>}
|
|
2169
2215
|
*/
|
|
@@ -2178,7 +2224,13 @@ class Slice {
|
|
|
2178
2224
|
}
|
|
2179
2225
|
/**
|
|
2180
2226
|
* Set the request type to insert
|
|
2181
|
-
*
|
|
2227
|
+
* @example
|
|
2228
|
+
* ```ts
|
|
2229
|
+
* const id: number = await new Slice<T>(12345).insert([
|
|
2230
|
+
* {field1: 1},
|
|
2231
|
+
* {field1: 2}
|
|
2232
|
+
* ]).exec().keys();
|
|
2233
|
+
* ```
|
|
2182
2234
|
* @param {T | T[]} rows Rows to be inserted into the slice
|
|
2183
2235
|
*/
|
|
2184
2236
|
insert(rows) {
|
|
@@ -2190,7 +2242,11 @@ class Slice {
|
|
|
2190
2242
|
}
|
|
2191
2243
|
/**
|
|
2192
2244
|
* Limit number of rows returned
|
|
2193
|
-
*
|
|
2245
|
+
* @example
|
|
2246
|
+
* ```ts
|
|
2247
|
+
* const rows: T[] = await new Slice<T>(12345).select().limit(10)
|
|
2248
|
+
* .exec().rows();
|
|
2249
|
+
* ```
|
|
2194
2250
|
* @param {number} num Number of rows to return
|
|
2195
2251
|
*/
|
|
2196
2252
|
limit(num) {
|
|
@@ -2198,17 +2254,34 @@ class Slice {
|
|
|
2198
2254
|
}
|
|
2199
2255
|
/**
|
|
2200
2256
|
* Add an 'OR' condition inside the where argument
|
|
2257
|
+
* @example
|
|
2258
|
+
* ```ts
|
|
2259
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
2260
|
+
* .where('field1', '>', 1)
|
|
2261
|
+
* .or()
|
|
2262
|
+
* .where({field2: 2, field3: 3})
|
|
2263
|
+
* .or()
|
|
2264
|
+
* .where(['$gt', ['$field', field4], 4)
|
|
2265
|
+
* .exec().rows();
|
|
2266
|
+
* ```
|
|
2201
2267
|
*/
|
|
2202
2268
|
or() {
|
|
2203
2269
|
var _a;
|
|
2204
|
-
if (((_a = this.request.where) == null ? void 0 : _a[0]) == "$or")
|
|
2205
|
-
|
|
2206
|
-
|
|
2270
|
+
if (((_a = this.request.where) == null ? void 0 : _a[0]) == "$or") {
|
|
2271
|
+
this.request.where.push(null);
|
|
2272
|
+
return this;
|
|
2273
|
+
}
|
|
2274
|
+
if (this.request.where) this.request.where = ["$or", this.request.where, null];
|
|
2275
|
+
else this.request.where = ["$or", null];
|
|
2207
2276
|
return this;
|
|
2208
2277
|
}
|
|
2209
2278
|
/**
|
|
2210
2279
|
* Order rows by a field
|
|
2211
|
-
*
|
|
2280
|
+
* @example
|
|
2281
|
+
* ```ts
|
|
2282
|
+
* const rows: T[] = new Slice<T>(12345).select().order('field1', true) // true = ascending
|
|
2283
|
+
* .exec().rows();
|
|
2284
|
+
* ```
|
|
2212
2285
|
* @param {string} field property name
|
|
2213
2286
|
* @param {boolean} ascending Sort in ascending or descending order
|
|
2214
2287
|
*/
|
|
@@ -2219,7 +2292,11 @@ class Slice {
|
|
|
2219
2292
|
}
|
|
2220
2293
|
/**
|
|
2221
2294
|
* Set the request type to select
|
|
2222
|
-
*
|
|
2295
|
+
* @example
|
|
2296
|
+
* ```ts
|
|
2297
|
+
* const rows: T[] = new Slice<T>(12345).select().exec().rows();
|
|
2298
|
+
* const row: T = new Slice<T>(12345).select(id).exec().row();
|
|
2299
|
+
* ```
|
|
2223
2300
|
* @param {number | number[]} id ID(s) to select, leaving blank will return all rows
|
|
2224
2301
|
*/
|
|
2225
2302
|
select(id) {
|
|
@@ -2232,7 +2309,11 @@ class Slice {
|
|
|
2232
2309
|
}
|
|
2233
2310
|
/**
|
|
2234
2311
|
* Synchronize cache with server
|
|
2235
|
-
*
|
|
2312
|
+
* @example
|
|
2313
|
+
* ```ts
|
|
2314
|
+
* const slice: Slice = new Slice<T>(Slices.Contact);
|
|
2315
|
+
* slice.sync().subscribe((rows: T[]) => {});
|
|
2316
|
+
* ```
|
|
2236
2317
|
* @param {boolean} on Enable/disable events
|
|
2237
2318
|
* @return {BehaviorSubject<T[]>} Cache which can be subscribed to
|
|
2238
2319
|
*/
|
|
@@ -2252,7 +2333,13 @@ class Slice {
|
|
|
2252
2333
|
}
|
|
2253
2334
|
/**
|
|
2254
2335
|
* Set the request type to update
|
|
2255
|
-
*
|
|
2336
|
+
* @example
|
|
2337
|
+
* ```ts
|
|
2338
|
+
* const ids: number[] = await new Slice<Type>(12345).update([
|
|
2339
|
+
* {id: 1, field1: 1},
|
|
2340
|
+
* {id: 2, field1: 1}
|
|
2341
|
+
* ]).exec().keys();
|
|
2342
|
+
* ```
|
|
2256
2343
|
* @param {T | T[]} rows Rows to be updated, each row must have an ID
|
|
2257
2344
|
*/
|
|
2258
2345
|
update(rows) {
|
|
@@ -2263,17 +2350,24 @@ class Slice {
|
|
|
2263
2350
|
return this;
|
|
2264
2351
|
}
|
|
2265
2352
|
/**
|
|
2266
|
-
* Add where condition to request
|
|
2267
|
-
*
|
|
2268
|
-
*
|
|
2353
|
+
* Add where condition to request
|
|
2354
|
+
* @example
|
|
2355
|
+
* ```ts
|
|
2356
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
2357
|
+
* .where('field1', '>', 1)
|
|
2358
|
+
* .where({field2: 2, field3: 3}) // Automatic AND
|
|
2359
|
+
* .or()
|
|
2360
|
+
* .where(['$gt', ['$field', field4], 4)
|
|
2361
|
+
* .exec().rows();
|
|
2362
|
+
* ```
|
|
2269
2363
|
* @param {string | object} field property to compare or a map of equality comparisons
|
|
2270
2364
|
* @param {string} operator Operation to compare with. Accepts JS operators (>=, ==, !=, ...) as well as datalynk styax ($gte, $eq, $is, $not, ...)
|
|
2271
2365
|
* @param {any} value value to compare against
|
|
2272
2366
|
*/
|
|
2273
2367
|
where(field, operator, value) {
|
|
2274
|
-
this.and();
|
|
2368
|
+
if (this.request.where && this.request.where[0] != "$or") this.and();
|
|
2275
2369
|
if (typeof field == "object") {
|
|
2276
|
-
Object.entries(field).forEach(([key, value2]) => this.
|
|
2370
|
+
Object.entries(field).forEach(([key, value2]) => this.where(key, "==", value2));
|
|
2277
2371
|
} else if (operator == null) {
|
|
2278
2372
|
throw new Error("Malformed where clause");
|
|
2279
2373
|
} else {
|
|
@@ -2303,7 +2397,17 @@ class Slice {
|
|
|
2303
2397
|
operator = "$mod";
|
|
2304
2398
|
break;
|
|
2305
2399
|
}
|
|
2306
|
-
this.request.where.
|
|
2400
|
+
if (!this.request.where) this.request.where = [operator, ["$field", field], value];
|
|
2401
|
+
else {
|
|
2402
|
+
if (this.request.where[0] == "$or") {
|
|
2403
|
+
const i = this.request.where.length - 1;
|
|
2404
|
+
if (this.request.where[i] == null) this.request.where[i] = [operator, ["$field", field], value];
|
|
2405
|
+
else {
|
|
2406
|
+
if (this.request.where[i][0] == "$and") this.request.where[i].push([operator, ["$field", field], value]);
|
|
2407
|
+
else this.request.where[i] = ["$and", this.request.where[i], [operator, ["$field", field], value]];
|
|
2408
|
+
}
|
|
2409
|
+
} else this.request.where.push([operator, ["$field", field], value]);
|
|
2410
|
+
}
|
|
2307
2411
|
}
|
|
2308
2412
|
return this;
|
|
2309
2413
|
}
|
|
@@ -2515,7 +2619,8 @@ class Api {
|
|
|
2515
2619
|
method: "POST",
|
|
2516
2620
|
headers: clean({
|
|
2517
2621
|
Authorization: this.token ? `Bearer ${this.token}` : void 0,
|
|
2518
|
-
"Content-Type": "application/json"
|
|
2622
|
+
"Content-Type": "application/json",
|
|
2623
|
+
"X-Date-Return-Format": this.options.legacyDates ? void 0 : "ISO8601"
|
|
2519
2624
|
}),
|
|
2520
2625
|
body: JSON.stringify(Api.translateTokens(req))
|
|
2521
2626
|
}).then(async (resp) => {
|
package/dist/slice.d.ts
CHANGED
|
@@ -26,6 +26,10 @@ export declare class SlicePromise<T extends SliceMeta> {
|
|
|
26
26
|
* Catch promise errors
|
|
27
27
|
*/
|
|
28
28
|
catch(callback: (error: ApiError | any) => any): Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Count rows or fetch count alias result
|
|
31
|
+
*/
|
|
32
|
+
count(): Promise<number>;
|
|
29
33
|
/**
|
|
30
34
|
* Log the raw result to the console for inspection
|
|
31
35
|
*/
|
|
@@ -111,7 +115,11 @@ export declare class Slice<T extends SliceMeta> {
|
|
|
111
115
|
constructor(slice: number | string, api: Api);
|
|
112
116
|
/**
|
|
113
117
|
* Whitelist and alias fields. Alias for the fields functions
|
|
114
|
-
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const id: {id: number, field2: any}[] = await new Slice<T>(12345)
|
|
121
|
+
* .select().alias({id: 'id', field1: 'field2'}).exec().keys();
|
|
122
|
+
* ```
|
|
115
123
|
* @param {object} aliasKeyVals List of properties to whitelist and what to rename them to
|
|
116
124
|
*/
|
|
117
125
|
alias(aliasKeyVals: {
|
|
@@ -119,34 +127,64 @@ export declare class Slice<T extends SliceMeta> {
|
|
|
119
127
|
}): Slice<T>;
|
|
120
128
|
/**
|
|
121
129
|
* Add an 'AND' condition inside the where argument
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
133
|
+
* .where('field1', '>', 1)
|
|
134
|
+
* .and()
|
|
135
|
+
* .where({field2: 2, field3: 3})
|
|
136
|
+
* .exec().rows();
|
|
137
|
+
* ```
|
|
122
138
|
*/
|
|
123
139
|
and(): this;
|
|
140
|
+
/**
|
|
141
|
+
* Count the returned rows
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const count = await new Slice(12345).count()
|
|
145
|
+
* .where({field1: 1})
|
|
146
|
+
* .exec().count();
|
|
147
|
+
* ```
|
|
148
|
+
* @param {object | string} arg Count argument
|
|
149
|
+
*/
|
|
150
|
+
count(arg?: object | string): this;
|
|
124
151
|
/**
|
|
125
152
|
* Output the formed request to the console for inspection
|
|
126
153
|
*/
|
|
127
154
|
debug(): this;
|
|
128
155
|
/**
|
|
129
156
|
* Set the request type to delete
|
|
130
|
-
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* await new Slice(12345).delete(id).exec();
|
|
160
|
+
* ```
|
|
131
161
|
* @param {number | number[]} id ID(s) to delete
|
|
132
162
|
*/
|
|
133
163
|
delete(id?: number | number[]): Slice<T>;
|
|
134
164
|
/**
|
|
135
165
|
* Filter rows from slice based on an excel expression
|
|
136
|
-
*
|
|
137
|
-
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
169
|
+
* .excel('')
|
|
170
|
+
* .exec().rows();
|
|
171
|
+
* ```
|
|
172
|
+
* @param formula Excel formula to use as where clause
|
|
138
173
|
*/
|
|
139
|
-
excel(
|
|
174
|
+
excel(formula: string): Slice<T>;
|
|
140
175
|
/**
|
|
141
176
|
* Compile the request and send it
|
|
142
|
-
*
|
|
143
177
|
* @param {ApiRequestOptions} options API Request options
|
|
144
178
|
* @return {SlicePromise<T>}
|
|
145
179
|
*/
|
|
146
180
|
exec(options?: ApiRequestOptions): SlicePromise<T>;
|
|
147
181
|
/**
|
|
148
182
|
* Whitelist fields by passing an array of keys or alias fields by using a map
|
|
149
|
-
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* const id: {id: number, field1: any}[] = await new Slice<T>(12345)
|
|
186
|
+
* .select().fields(['id', 'field1']).exec().keys();
|
|
187
|
+
* ```
|
|
150
188
|
* @param {object} whitelist Either a list of keys to whitelist or a map of keys to rename
|
|
151
189
|
*/
|
|
152
190
|
fields(whitelist: string[]): Slice<T>;
|
|
@@ -155,50 +193,95 @@ export declare class Slice<T extends SliceMeta> {
|
|
|
155
193
|
}): Slice<T>;
|
|
156
194
|
/**
|
|
157
195
|
* Set the request type to insert
|
|
158
|
-
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* const id: number = await new Slice<T>(12345).insert([
|
|
199
|
+
* {field1: 1},
|
|
200
|
+
* {field1: 2}
|
|
201
|
+
* ]).exec().keys();
|
|
202
|
+
* ```
|
|
159
203
|
* @param {T | T[]} rows Rows to be inserted into the slice
|
|
160
204
|
*/
|
|
161
205
|
insert(rows: T | T[]): Slice<T>;
|
|
162
206
|
/**
|
|
163
207
|
* Limit number of rows returned
|
|
164
|
-
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* const rows: T[] = await new Slice<T>(12345).select().limit(10)
|
|
211
|
+
* .exec().rows();
|
|
212
|
+
* ```
|
|
165
213
|
* @param {number} num Number of rows to return
|
|
166
214
|
*/
|
|
167
215
|
limit(num: number): void;
|
|
168
216
|
/**
|
|
169
217
|
* Add an 'OR' condition inside the where argument
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
221
|
+
* .where('field1', '>', 1)
|
|
222
|
+
* .or()
|
|
223
|
+
* .where({field2: 2, field3: 3})
|
|
224
|
+
* .or()
|
|
225
|
+
* .where(['$gt', ['$field', field4], 4)
|
|
226
|
+
* .exec().rows();
|
|
227
|
+
* ```
|
|
170
228
|
*/
|
|
171
229
|
or(): this;
|
|
172
230
|
/**
|
|
173
231
|
* Order rows by a field
|
|
174
|
-
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* const rows: T[] = new Slice<T>(12345).select().order('field1', true) // true = ascending
|
|
235
|
+
* .exec().rows();
|
|
236
|
+
* ```
|
|
175
237
|
* @param {string} field property name
|
|
176
238
|
* @param {boolean} ascending Sort in ascending or descending order
|
|
177
239
|
*/
|
|
178
240
|
order(field: string, ascending?: boolean): Slice<T>;
|
|
179
241
|
/**
|
|
180
242
|
* Set the request type to select
|
|
181
|
-
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* const rows: T[] = new Slice<T>(12345).select().exec().rows();
|
|
246
|
+
* const row: T = new Slice<T>(12345).select(id).exec().row();
|
|
247
|
+
* ```
|
|
182
248
|
* @param {number | number[]} id ID(s) to select, leaving blank will return all rows
|
|
183
249
|
*/
|
|
184
250
|
select(id?: number | number[]): Slice<T>;
|
|
185
251
|
/**
|
|
186
252
|
* Synchronize cache with server
|
|
187
|
-
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* const slice: Slice = new Slice<T>(Slices.Contact);
|
|
256
|
+
* slice.sync().subscribe((rows: T[]) => {});
|
|
257
|
+
* ```
|
|
188
258
|
* @param {boolean} on Enable/disable events
|
|
189
259
|
* @return {BehaviorSubject<T[]>} Cache which can be subscribed to
|
|
190
260
|
*/
|
|
191
261
|
sync(on?: boolean): BehaviorSubject<T[]> | undefined;
|
|
192
262
|
/**
|
|
193
263
|
* Set the request type to update
|
|
194
|
-
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* const ids: number[] = await new Slice<Type>(12345).update([
|
|
267
|
+
* {id: 1, field1: 1},
|
|
268
|
+
* {id: 2, field1: 1}
|
|
269
|
+
* ]).exec().keys();
|
|
270
|
+
* ```
|
|
195
271
|
* @param {T | T[]} rows Rows to be updated, each row must have an ID
|
|
196
272
|
*/
|
|
197
273
|
update(rows: T | T[]): this;
|
|
198
274
|
/**
|
|
199
|
-
* Add where condition to request
|
|
200
|
-
*
|
|
201
|
-
*
|
|
275
|
+
* Add where condition to request
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* const rows: T[] = await new Slice<T>(12345).select()
|
|
279
|
+
* .where('field1', '>', 1)
|
|
280
|
+
* .where({field2: 2, field3: 3}) // Automatic AND
|
|
281
|
+
* .or()
|
|
282
|
+
* .where(['$gt', ['$field', field4], 4)
|
|
283
|
+
* .exec().rows();
|
|
284
|
+
* ```
|
|
202
285
|
* @param {string | object} field property to compare or a map of equality comparisons
|
|
203
286
|
* @param {string} operator Operation to compare with. Accepts JS operators (>=, ==, !=, ...) as well as datalynk styax ($gte, $eq, $is, $not, ...)
|
|
204
287
|
* @param {any} value value to compare against
|
package/dist/slice.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,MAAM,CAAC;AACrC,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,iBAAiB,EAAC,MAAM,OAAO,CAAC;AACvD,OAAO,EAAmB,WAAW,EAAC,MAAM,UAAU,CAAC;AAEvD,MAAM,WAAW,SAAS;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ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AC,OAAO,CAAC,EAAE,iBAAiB,GAAG,YAAY,CAAC,CAAC,CAAC;IAMlD;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;IACrC,MAAM,CAAC,KAAK,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;KAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IAQzD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;IAQ/B;;;;;;;;OAQG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM;IAIjB;;;;;;;;;;;;OAYG;IACH,EAAE;IAUF;;;;;;;;;OASG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,UAAO,GAAG,KAAK,CAAC,CAAC,CAAC;IAMhD;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;IASxC;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,UAAO;IAoBd;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE;IAQpB;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC;CA+CvE"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@auxilium/datalynk-client",
|
|
3
3
|
"description": "Datalynk client library",
|
|
4
4
|
"repository": "https://gitlab.auxiliumgroup.com/auxilium/datalynk/datalynk-client",
|
|
5
|
-
"version": "0.9.
|
|
5
|
+
"version": "0.9.6",
|
|
6
6
|
"author": "Zak Timson <zaktimson@gmail.com>",
|
|
7
7
|
"private": false,
|
|
8
8
|
"main": "./dist/index.cjs",
|