rads-db 3.0.66 → 3.0.68
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.cjs +6 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.mjs +6 -4
- package/drivers/memory.cjs +1 -1
- package/drivers/memory.mjs +2 -0
- package/drivers/restApi.cjs +10 -4
- package/drivers/restApi.mjs +4 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -235,6 +235,8 @@ function getAggFromArray(array, args) {
|
|
|
235
235
|
result[key] = values.length ? ___default.mean(values) : void 0;
|
|
236
236
|
else if (operator === "max")
|
|
237
237
|
result[key] = values.length ? ___default.max(array.map((x) => x[field])) : void 0;
|
|
238
|
+
else if (operator === "sum")
|
|
239
|
+
result[key] = values.length ? ___default.sum(array.map((x) => x[field])) : void 0;
|
|
238
240
|
else
|
|
239
241
|
throw new Error(`Unknown operator: ${operator} (${key})`);
|
|
240
242
|
}
|
|
@@ -1200,7 +1202,7 @@ const restApi = (options) => (schema, entity) => {
|
|
|
1200
1202
|
throw new Error(`Entity ${entity} was not found in schema`);
|
|
1201
1203
|
const instance = {
|
|
1202
1204
|
driverName: "restApi",
|
|
1203
|
-
async getMany(args) {
|
|
1205
|
+
async getMany(args, ctx) {
|
|
1204
1206
|
args = args || {};
|
|
1205
1207
|
const url = `${opts.baseUrl}/${handlePlural}`;
|
|
1206
1208
|
const fetchOptions = {
|
|
@@ -1208,17 +1210,17 @@ const restApi = (options) => (schema, entity) => {
|
|
|
1208
1210
|
body: JSON.stringify(args),
|
|
1209
1211
|
headers: { "Content-Type": "application/json" }
|
|
1210
1212
|
};
|
|
1211
|
-
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(
|
|
1213
|
+
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders({ args, context: ctx }) };
|
|
1212
1214
|
return await fetchInner(url, fetchOptions);
|
|
1213
1215
|
},
|
|
1214
|
-
async putMany(item) {
|
|
1216
|
+
async putMany(item, ctx) {
|
|
1215
1217
|
const url = `${opts.baseUrl}/${handlePlural}`;
|
|
1216
1218
|
const fetchOptions = {
|
|
1217
1219
|
method: "PUT",
|
|
1218
1220
|
body: JSON.stringify({ data: item }),
|
|
1219
1221
|
headers: { "Content-Type": "application/json" }
|
|
1220
1222
|
};
|
|
1221
|
-
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(
|
|
1223
|
+
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders({ args: item, context: ctx }) };
|
|
1222
1224
|
return await fetchInner(url, fetchOptions);
|
|
1223
1225
|
},
|
|
1224
1226
|
async verifyMany(args, ctx) {
|
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ interface GetAggArgs<EN extends keyof EntityMeta> {
|
|
|
37
37
|
where?: Where<EN>;
|
|
38
38
|
agg: GetAggArgsAgg<EN>;
|
|
39
39
|
}
|
|
40
|
-
type GetAggArgsAgg<EN extends keyof EntityMeta, F extends string = EntityMeta[EN]['aggregates']> = ('_count' | `${F}_min` | `${F}_max`)[];
|
|
40
|
+
type GetAggArgsAgg<EN extends keyof EntityMeta, F extends string = EntityMeta[EN]['aggregates']> = ('_count' | `${F}_min` | `${F}_max` | `${F}_sum`)[];
|
|
41
41
|
type GetManyArgsAny = GetManyArgs<any>;
|
|
42
42
|
type GetArgsAny = GetArgs<any>;
|
|
43
43
|
type GetAggArgsAny = GetAggArgs<any>;
|
|
@@ -207,7 +207,10 @@ interface RestDriverOptions {
|
|
|
207
207
|
headers?: any;
|
|
208
208
|
method?: string;
|
|
209
209
|
}) => any;
|
|
210
|
-
getHeaders?: (
|
|
210
|
+
getHeaders?: (radsDbRequest: {
|
|
211
|
+
args?: any;
|
|
212
|
+
context?: RadsRequestContext;
|
|
213
|
+
}) => Record<string, string> | undefined;
|
|
211
214
|
}
|
|
212
215
|
interface CreateRadsDbArgs {
|
|
213
216
|
schema?: Schema;
|
|
@@ -382,8 +385,8 @@ interface RadsRequestContext {
|
|
|
382
385
|
silent?: boolean;
|
|
383
386
|
/** Mostly for internal use. When entity name is specified, indicates that calling put* on this entity is allowed, even if it's marked as @precomputed or @readonly */
|
|
384
387
|
skipPrecomputedCheckFor?: string;
|
|
385
|
-
/**
|
|
386
|
-
method?:
|
|
388
|
+
/** Method that was called - get, getAll, getMany, getAgg, put, putMany, etc */
|
|
389
|
+
method?: 'get' | 'getAll' | 'getMany' | 'getAgg' | 'put' | 'putMany' | 'deleteMany' | 'deleteAll';
|
|
387
390
|
/** if true, all cache layers will be bypassed */
|
|
388
391
|
noCache?: boolean;
|
|
389
392
|
[key: string]: any;
|
package/dist/index.mjs
CHANGED
|
@@ -228,6 +228,8 @@ function getAggFromArray(array, args) {
|
|
|
228
228
|
result[key] = values.length ? _.mean(values) : void 0;
|
|
229
229
|
else if (operator === "max")
|
|
230
230
|
result[key] = values.length ? _.max(array.map((x) => x[field])) : void 0;
|
|
231
|
+
else if (operator === "sum")
|
|
232
|
+
result[key] = values.length ? _.sum(array.map((x) => x[field])) : void 0;
|
|
231
233
|
else
|
|
232
234
|
throw new Error(`Unknown operator: ${operator} (${key})`);
|
|
233
235
|
}
|
|
@@ -1193,7 +1195,7 @@ const restApi = (options) => (schema, entity) => {
|
|
|
1193
1195
|
throw new Error(`Entity ${entity} was not found in schema`);
|
|
1194
1196
|
const instance = {
|
|
1195
1197
|
driverName: "restApi",
|
|
1196
|
-
async getMany(args) {
|
|
1198
|
+
async getMany(args, ctx) {
|
|
1197
1199
|
args = args || {};
|
|
1198
1200
|
const url = `${opts.baseUrl}/${handlePlural}`;
|
|
1199
1201
|
const fetchOptions = {
|
|
@@ -1201,17 +1203,17 @@ const restApi = (options) => (schema, entity) => {
|
|
|
1201
1203
|
body: JSON.stringify(args),
|
|
1202
1204
|
headers: { "Content-Type": "application/json" }
|
|
1203
1205
|
};
|
|
1204
|
-
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(
|
|
1206
|
+
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders({ args, context: ctx }) };
|
|
1205
1207
|
return await fetchInner(url, fetchOptions);
|
|
1206
1208
|
},
|
|
1207
|
-
async putMany(item) {
|
|
1209
|
+
async putMany(item, ctx) {
|
|
1208
1210
|
const url = `${opts.baseUrl}/${handlePlural}`;
|
|
1209
1211
|
const fetchOptions = {
|
|
1210
1212
|
method: "PUT",
|
|
1211
1213
|
body: JSON.stringify({ data: item }),
|
|
1212
1214
|
headers: { "Content-Type": "application/json" }
|
|
1213
1215
|
};
|
|
1214
|
-
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(
|
|
1216
|
+
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders({ args: item, context: ctx }) };
|
|
1215
1217
|
return await fetchInner(url, fetchOptions);
|
|
1216
1218
|
},
|
|
1217
1219
|
async verifyMany(args, ctx) {
|
package/drivers/memory.cjs
CHANGED
|
@@ -115,7 +115,7 @@ function getAggFromArray(array, args) {
|
|
|
115
115
|
const [field, operator] = key.split("_");
|
|
116
116
|
if (operator === "count") result[key] = array.length;else {
|
|
117
117
|
const values = array.map(x => x[field]).filter(x => x != null);
|
|
118
|
-
if (operator === "min") result[key] = values.length ? _lodash.default.min(values) : void 0;else if (operator === "avg") result[key] = values.length ? _lodash.default.mean(values) : void 0;else if (operator === "max") result[key] = values.length ? _lodash.default.max(array.map(x => x[field])) : void 0;else throw new Error(`Unknown operator: ${operator} (${key})`);
|
|
118
|
+
if (operator === "min") result[key] = values.length ? _lodash.default.min(values) : void 0;else if (operator === "avg") result[key] = values.length ? _lodash.default.mean(values) : void 0;else if (operator === "max") result[key] = values.length ? _lodash.default.max(array.map(x => x[field])) : void 0;else if (operator === "sum") result[key] = values.length ? _lodash.default.sum(array.map(x => x[field])) : void 0;else throw new Error(`Unknown operator: ${operator} (${key})`);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
return result;
|
package/drivers/memory.mjs
CHANGED
|
@@ -102,6 +102,8 @@ export function getAggFromArray(array, args) {
|
|
|
102
102
|
result[key] = values.length ? _.mean(values) : void 0;
|
|
103
103
|
else if (operator === "max")
|
|
104
104
|
result[key] = values.length ? _.max(array.map((x) => x[field])) : void 0;
|
|
105
|
+
else if (operator === "sum")
|
|
106
|
+
result[key] = values.length ? _.sum(array.map((x) => x[field])) : void 0;
|
|
105
107
|
else
|
|
106
108
|
throw new Error(`Unknown operator: ${operator} (${key})`);
|
|
107
109
|
}
|
package/drivers/restApi.cjs
CHANGED
|
@@ -33,7 +33,7 @@ var _default = options => (schema, entity) => {
|
|
|
33
33
|
if (!handlePlural) throw new Error(`Entity ${entity} was not found in schema`);
|
|
34
34
|
const instance = {
|
|
35
35
|
driverName: "restApi",
|
|
36
|
-
async getMany(args) {
|
|
36
|
+
async getMany(args, ctx) {
|
|
37
37
|
args = args || {};
|
|
38
38
|
const url = `${opts.baseUrl}/${handlePlural}`;
|
|
39
39
|
const fetchOptions = {
|
|
@@ -45,11 +45,14 @@ var _default = options => (schema, entity) => {
|
|
|
45
45
|
};
|
|
46
46
|
fetchOptions.headers = {
|
|
47
47
|
...fetchOptions.headers,
|
|
48
|
-
...opts.getHeaders(
|
|
48
|
+
...opts.getHeaders({
|
|
49
|
+
args,
|
|
50
|
+
context: ctx
|
|
51
|
+
})
|
|
49
52
|
};
|
|
50
53
|
return await fetchInner(url, fetchOptions);
|
|
51
54
|
},
|
|
52
|
-
async putMany(item) {
|
|
55
|
+
async putMany(item, ctx) {
|
|
53
56
|
const url = `${opts.baseUrl}/${handlePlural}`;
|
|
54
57
|
const fetchOptions = {
|
|
55
58
|
method: "PUT",
|
|
@@ -62,7 +65,10 @@ var _default = options => (schema, entity) => {
|
|
|
62
65
|
};
|
|
63
66
|
fetchOptions.headers = {
|
|
64
67
|
...fetchOptions.headers,
|
|
65
|
-
...opts.getHeaders(
|
|
68
|
+
...opts.getHeaders({
|
|
69
|
+
args: item,
|
|
70
|
+
context: ctx
|
|
71
|
+
})
|
|
66
72
|
};
|
|
67
73
|
return await fetchInner(url, fetchOptions);
|
|
68
74
|
},
|
package/drivers/restApi.mjs
CHANGED
|
@@ -27,7 +27,7 @@ export default (options) => (schema, entity) => {
|
|
|
27
27
|
throw new Error(`Entity ${entity} was not found in schema`);
|
|
28
28
|
const instance = {
|
|
29
29
|
driverName: "restApi",
|
|
30
|
-
async getMany(args) {
|
|
30
|
+
async getMany(args, ctx) {
|
|
31
31
|
args = args || {};
|
|
32
32
|
const url = `${opts.baseUrl}/${handlePlural}`;
|
|
33
33
|
const fetchOptions = {
|
|
@@ -35,17 +35,17 @@ export default (options) => (schema, entity) => {
|
|
|
35
35
|
body: JSON.stringify(args),
|
|
36
36
|
headers: { "Content-Type": "application/json" }
|
|
37
37
|
};
|
|
38
|
-
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(
|
|
38
|
+
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders({ args, context: ctx }) };
|
|
39
39
|
return await fetchInner(url, fetchOptions);
|
|
40
40
|
},
|
|
41
|
-
async putMany(item) {
|
|
41
|
+
async putMany(item, ctx) {
|
|
42
42
|
const url = `${opts.baseUrl}/${handlePlural}`;
|
|
43
43
|
const fetchOptions = {
|
|
44
44
|
method: "PUT",
|
|
45
45
|
body: JSON.stringify({ data: item }),
|
|
46
46
|
headers: { "Content-Type": "application/json" }
|
|
47
47
|
};
|
|
48
|
-
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders(
|
|
48
|
+
fetchOptions.headers = { ...fetchOptions.headers, ...opts.getHeaders({ args: item, context: ctx }) };
|
|
49
49
|
return await fetchInner(url, fetchOptions);
|
|
50
50
|
},
|
|
51
51
|
async verifyMany(args, ctx) {
|