@sprucelabs/data-stores 11.2.0 → 11.2.3
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.
|
@@ -104,7 +104,14 @@ class CursorPager {
|
|
|
104
104
|
return JSON.stringify(cursor);
|
|
105
105
|
}
|
|
106
106
|
static prepareQueryOptions(options) {
|
|
107
|
-
const { previous, sort = [] } = (0, just_clone_1.default)((0, schema_1.assertOptions)(options, ['limit']));
|
|
107
|
+
const { previous, sort = [], limit, } = (0, just_clone_1.default)((0, schema_1.assertOptions)(options, ['limit']));
|
|
108
|
+
if (limit < 1) {
|
|
109
|
+
throw new schema_1.SchemaError({
|
|
110
|
+
code: 'INVALID_PARAMETERS',
|
|
111
|
+
parameters: ['limit'],
|
|
112
|
+
friendlyMessage: 'Your limit must be above zero!',
|
|
113
|
+
});
|
|
114
|
+
}
|
|
108
115
|
if (!sort.find((p) => p.field === 'id')) {
|
|
109
116
|
sort.push({
|
|
110
117
|
field: 'id',
|
|
@@ -116,7 +123,7 @@ class CursorPager {
|
|
|
116
123
|
s.direction = s.direction === 'asc' ? 'desc' : 'asc';
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
|
-
return Object.assign(Object.assign({}, options), { limit:
|
|
126
|
+
return Object.assign(Object.assign({}, options), { limit: limit + 1, sort });
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
exports.default = CursorPager;
|
|
@@ -7,7 +7,11 @@ const CursorPager_1 = __importDefault(require("./CursorPager"));
|
|
|
7
7
|
class CursorPagerFaker {
|
|
8
8
|
static setResponse(response) {
|
|
9
9
|
//@ts-ignore
|
|
10
|
-
CursorPager_1.default.find =
|
|
10
|
+
CursorPager_1.default.find = async (...args) => {
|
|
11
|
+
//@ts-ignore
|
|
12
|
+
const results = await response(...args);
|
|
13
|
+
return Object.assign({ next: null, previous: null, records: [] }, results);
|
|
14
|
+
};
|
|
11
15
|
}
|
|
12
16
|
static async beforeEach() {
|
|
13
17
|
if (!this.originalFind) {
|
|
@@ -18,7 +18,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
18
18
|
}
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
|
-
import { assertOptions } from '@sprucelabs/schema';
|
|
21
|
+
import { assertOptions, SchemaError } from '@sprucelabs/schema';
|
|
22
22
|
import clone from 'just-clone';
|
|
23
23
|
export default class CursorPager {
|
|
24
24
|
static find(store, query, options) {
|
|
@@ -110,7 +110,14 @@ export default class CursorPager {
|
|
|
110
110
|
return JSON.stringify(cursor);
|
|
111
111
|
}
|
|
112
112
|
static prepareQueryOptions(options) {
|
|
113
|
-
const { previous, sort = [] } = clone(assertOptions(options, ['limit']));
|
|
113
|
+
const { previous, sort = [], limit, } = clone(assertOptions(options, ['limit']));
|
|
114
|
+
if (limit < 1) {
|
|
115
|
+
throw new SchemaError({
|
|
116
|
+
code: 'INVALID_PARAMETERS',
|
|
117
|
+
parameters: ['limit'],
|
|
118
|
+
friendlyMessage: 'Your limit must be above zero!',
|
|
119
|
+
});
|
|
120
|
+
}
|
|
114
121
|
if (!sort.find((p) => p.field === 'id')) {
|
|
115
122
|
sort.push({
|
|
116
123
|
field: 'id',
|
|
@@ -122,6 +129,6 @@ export default class CursorPager {
|
|
|
122
129
|
s.direction = s.direction === 'asc' ? 'desc' : 'asc';
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
|
-
return Object.assign(Object.assign({}, options), { limit:
|
|
132
|
+
return Object.assign(Object.assign({}, options), { limit: limit + 1, sort });
|
|
126
133
|
}
|
|
127
134
|
}
|
|
@@ -11,7 +11,11 @@ import CursorPager from './CursorPager.js';
|
|
|
11
11
|
export default class CursorPagerFaker {
|
|
12
12
|
static setResponse(response) {
|
|
13
13
|
//@ts-ignore
|
|
14
|
-
CursorPager.find =
|
|
14
|
+
CursorPager.find = (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
const results = yield response(...args);
|
|
17
|
+
return Object.assign({ next: null, previous: null, records: [] }, results);
|
|
18
|
+
});
|
|
15
19
|
}
|
|
16
20
|
static beforeEach() {
|
|
17
21
|
return __awaiter(this, void 0, void 0, function* () {
|