@orion-js/paginated-mongodb 3.11.15 → 3.12.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/package.json CHANGED
@@ -1,41 +1,45 @@
1
1
  {
2
2
  "name": "@orion-js/paginated-mongodb",
3
- "version": "3.11.15",
4
- "main": "lib/index.js",
5
- "types": "lib/index.d.ts",
3
+ "version": "3.12.0",
4
+ "main": "./dist/index.cjs",
5
+ "types": "./dist/index.d.ts",
6
6
  "files": [
7
- "/lib"
7
+ "dist"
8
8
  ],
9
9
  "author": "nicolaslopezj",
10
10
  "license": "MIT",
11
11
  "scripts": {
12
- "test": "jest",
12
+ "test": "bun test",
13
13
  "prepare": "yarn run build",
14
- "clean": "rm -rf ./lib",
15
- "build": "yarn run clean && tsc",
14
+ "clean": "rm -rf ./dist",
15
+ "build": "bun run build.ts",
16
16
  "watch": "tsc -w",
17
- "upgrade-interactive": "yarn upgrade-interactive"
17
+ "upgrade-interactive": "yarn upgrade-interactive",
18
+ "dev": "bun --watch src/index.ts"
18
19
  },
19
20
  "dependencies": {
20
- "@orion-js/helpers": "^3.11.15",
21
- "@orion-js/models": "^3.11.15",
22
- "@orion-js/mongodb": "^3.11.15",
23
- "@orion-js/resolvers": "^3.11.15",
24
- "@orion-js/schema": "^3.11.8",
25
- "@orion-js/services": "^3.11.15",
26
- "@orion-js/typed-model": "^3.11.15"
21
+ "@orion-js/helpers": "3.12.0",
22
+ "@orion-js/models": "3.12.0",
23
+ "@orion-js/mongodb": "3.12.0",
24
+ "@orion-js/resolvers": "3.12.0",
25
+ "@orion-js/schema": "3.12.0",
26
+ "@orion-js/services": "3.12.0",
27
+ "@orion-js/typed-model": "3.12.0"
27
28
  },
28
29
  "devDependencies": {
29
- "@shelf/jest-mongodb": "^4.3.2",
30
- "@types/jest": "^29.5.12",
31
30
  "@types/lodash": "4.14.176",
32
- "@types/node": "16.11.7",
33
- "jest": "29.7.0",
34
- "ts-jest": "29.1.2",
35
- "typescript": "^4.4.4"
31
+ "typescript": "^5.4.5",
32
+ "@types/bun": "^1.2.4"
36
33
  },
37
34
  "publishConfig": {
38
35
  "access": "public"
39
36
  },
40
- "gitHead": "a5c95d9fd18f779c834644eb757928cdb840643c"
41
- }
37
+ "gitHead": "9fd28b6f6b348cebc9f0dc207805647969277372",
38
+ "type": "module",
39
+ "module": "./dist/index.js",
40
+ "exports": {
41
+ "types": "./dist/index.d.ts",
42
+ "import": "./dist/index.js",
43
+ "require": "./dist/index.cjs"
44
+ }
45
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Orionjs Team
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/lib/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import paginatedResolver from './paginatedResolver';
2
- import tokenPaginatedResolver from './tokenPaginatedResolver';
3
- export { paginatedResolver, tokenPaginatedResolver };
4
- export * from './service';
package/lib/index.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.tokenPaginatedResolver = exports.paginatedResolver = void 0;
17
- const paginatedResolver_1 = __importDefault(require("./paginatedResolver"));
18
- exports.paginatedResolver = paginatedResolver_1.default;
19
- const tokenPaginatedResolver_1 = __importDefault(require("./tokenPaginatedResolver"));
20
- exports.tokenPaginatedResolver = tokenPaginatedResolver_1.default;
21
- __exportStar(require("./service"), exports);
@@ -1,5 +0,0 @@
1
- declare const _default: ({ returns, modelName }: {
2
- returns: any;
3
- modelName: any;
4
- }) => import("@orion-js/models").Model<any>;
5
- export default _default;
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const models_1 = require("@orion-js/models");
7
- const hash_1 = __importDefault(require("./hash"));
8
- const resolvers_1 = require("@orion-js/resolvers");
9
- exports.default = ({ returns, modelName }) => {
10
- const getTotalCount = async function (paginated) {
11
- if (typeof paginated.count === 'undefined') {
12
- paginated.count = await paginated.cursor.count();
13
- }
14
- return paginated.count;
15
- };
16
- const _id = (0, resolvers_1.modelResolver)({
17
- returns: 'ID',
18
- async resolve(paginated, p, viewer) {
19
- const { params } = paginated;
20
- const num = (0, hash_1.default)({
21
- modelName: modelName,
22
- typename: returns.name,
23
- userId: viewer.userId,
24
- params: params
25
- });
26
- return String(Math.abs(num));
27
- }
28
- });
29
- const totalCount = (0, resolvers_1.modelResolver)({
30
- returns: 'integer',
31
- resolve: getTotalCount
32
- });
33
- const totalPages = (0, resolvers_1.modelResolver)({
34
- returns: 'integer',
35
- async resolve(paginated) {
36
- const count = await getTotalCount(paginated);
37
- if (!paginated.options.limit)
38
- return 1;
39
- return Math.ceil(count / paginated.options.limit);
40
- }
41
- });
42
- const hasNextPage = (0, resolvers_1.modelResolver)({
43
- returns: Boolean,
44
- async resolve(paginated) {
45
- const count = await getTotalCount(paginated);
46
- const { skip, limit } = paginated.options;
47
- if (!limit)
48
- return false;
49
- return skip + limit < count;
50
- }
51
- });
52
- const hasPreviousPage = (0, resolvers_1.modelResolver)({
53
- returns: Boolean,
54
- async resolve(paginated) {
55
- const count = await getTotalCount(paginated);
56
- const { skip } = paginated.options;
57
- return count && skip !== 0;
58
- }
59
- });
60
- const items = (0, resolvers_1.modelResolver)({
61
- returns: [returns],
62
- async resolve({ cursor }) {
63
- return await cursor.toArray();
64
- }
65
- });
66
- return (0, models_1.createModel)({
67
- name: modelName || `Paginated${returns.name}`,
68
- resolvers: {
69
- _id,
70
- totalCount,
71
- totalPages,
72
- hasNextPage,
73
- hasPreviousPage,
74
- items
75
- }
76
- });
77
- };
@@ -1 +0,0 @@
1
- export default function (obj?: object): number;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1(obj = {}) {
4
- return JSON.stringify(obj)
5
- .split('')
6
- .reduce((prevHash, currVal) => (prevHash << 5) - prevHash + currVal.charCodeAt(0), 0);
7
- }
8
- exports.default = default_1;
@@ -1,36 +0,0 @@
1
- export interface PaginatedCursor {
2
- count?: () => Promise<number> | number;
3
- toArray: () => Promise<any[]>;
4
- limit?: (newLimit: number) => void;
5
- skip?: (newSkip: number) => void;
6
- sort?: (newSort: {
7
- [key: string]: 1 | -1;
8
- }) => void;
9
- }
10
- export declare type PaginatedResolverGetCursorResultWithCount = {
11
- count: () => Promise<number> | number;
12
- cursor: PaginatedCursor;
13
- };
14
- export declare type PaginatedResolverGetCursorResult = PaginatedCursor | PaginatedResolverGetCursorResultWithCount;
15
- export interface PaginatedResolverOpts {
16
- returns: any;
17
- getCursor: (params?: any, viewer?: any) => Promise<PaginatedResolverGetCursorResult>;
18
- allowedSorts?: string[];
19
- defaultSortBy?: string;
20
- defaultSortType?: 'asc' | 'desc';
21
- params?: any;
22
- modelName?: string;
23
- permissionsOptions?: any;
24
- }
25
- export default function paginatedResolver({ returns, params, allowedSorts, defaultSortBy, defaultSortType, getCursor, getCursorAndCount, modelName, ...otherOptions }: PaginatedResolverOpts & {
26
- [key: string]: any;
27
- }): import("@orion-js/resolvers").Resolver<(params: any, viewer: any, info?: any) => Promise<{
28
- cursor: PaginatedCursor;
29
- params: any;
30
- viewer: any;
31
- options: {
32
- skip: number;
33
- limit: any;
34
- };
35
- count: number;
36
- }>, undefined>;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const resolvers_1 = require("@orion-js/resolvers");
7
- const getModel_1 = __importDefault(require("./getModel"));
8
- const params_1 = __importDefault(require("./params"));
9
- const setOptions_1 = __importDefault(require("./setOptions"));
10
- const getArgs_1 = require("@orion-js/resolvers/lib/resolver/getArgs");
11
- function paginatedResolver({ returns, params, allowedSorts, defaultSortBy, defaultSortType, getCursor, getCursorAndCount, modelName, ...otherOptions }) {
12
- const getCursorResult = async (...args) => {
13
- const result = await getCursor(...args);
14
- if (result.cursor) {
15
- const resultWithCount = result;
16
- return { cursor: resultWithCount.cursor, getCount: () => resultWithCount.count() };
17
- }
18
- else {
19
- const resultWithoutCount = result;
20
- return { cursor: resultWithoutCount, getCount: () => resultWithoutCount.count() };
21
- }
22
- };
23
- return (0, resolvers_1.resolver)({
24
- params: (0, params_1.default)({ params, allowedSorts, defaultSortBy, defaultSortType }),
25
- returns: (0, getModel_1.default)({ modelName, returns }),
26
- async resolve(...args) {
27
- const { params, viewer } = (0, getArgs_1.getArgs)(...args);
28
- const { cursor, getCount } = await getCursorResult(...args);
29
- /* counting the total number of elements of this cursor, so we make sure
30
- that it is going to be computed only once */
31
- const count = await getCount();
32
- const options = (0, setOptions_1.default)(params, cursor);
33
- return {
34
- cursor,
35
- params,
36
- viewer,
37
- options,
38
- count
39
- };
40
- },
41
- ...otherOptions
42
- });
43
- }
44
- exports.default = paginatedResolver;
@@ -1 +0,0 @@
1
- export {};
@@ -1,127 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const models_1 = require("@orion-js/models");
16
- const helpers_1 = require("@orion-js/helpers");
17
- const _1 = __importDefault(require("."));
18
- const typed_model_1 = require("@orion-js/typed-model");
19
- const mongodb_1 = require("@orion-js/mongodb");
20
- describe('Full example of paginated resolver', () => {
21
- const createResolver = async () => {
22
- let ItemSchema = class ItemSchema {
23
- };
24
- __decorate([
25
- (0, typed_model_1.Prop)(),
26
- __metadata("design:type", String)
27
- ], ItemSchema.prototype, "_id", void 0);
28
- __decorate([
29
- (0, typed_model_1.Prop)(),
30
- __metadata("design:type", String)
31
- ], ItemSchema.prototype, "name", void 0);
32
- __decorate([
33
- (0, typed_model_1.Prop)(),
34
- __metadata("design:type", Number)
35
- ], ItemSchema.prototype, "index", void 0);
36
- ItemSchema = __decorate([
37
- (0, typed_model_1.TypedSchema)()
38
- ], ItemSchema);
39
- const collection = (0, mongodb_1.createCollection)({
40
- name: (0, helpers_1.generateId)(),
41
- schema: ItemSchema
42
- });
43
- await collection.insertMany([
44
- { name: `Number 1`, index: 1 },
45
- { name: `Number 2`, index: 2 },
46
- { name: `Number 3`, index: 3 },
47
- { name: `Number 4`, index: 4 },
48
- { name: `Number 5`, index: 5 },
49
- { name: `Number 6`, index: 6 }
50
- ]);
51
- let Params = class Params {
52
- };
53
- __decorate([
54
- (0, typed_model_1.Prop)({ optional: true }),
55
- __metadata("design:type", String)
56
- ], Params.prototype, "filter", void 0);
57
- Params = __decorate([
58
- (0, typed_model_1.TypedSchema)()
59
- ], Params);
60
- return (0, _1.default)({
61
- returns: ItemSchema,
62
- params: Params,
63
- allowedSorts: ['index'],
64
- async getCursor(params) {
65
- const query = {};
66
- if (params.filter) {
67
- query.name = params.filter;
68
- }
69
- return collection.find(query);
70
- }
71
- });
72
- };
73
- it('should work passing custom params', async () => {
74
- const resolver = await createResolver();
75
- const result = (await resolver.resolve({
76
- filter: `Number 1`
77
- }, {}));
78
- const items = await result.items();
79
- const count = await result.totalCount();
80
- expect(items.length).toBe(1);
81
- expect(items[0].index).toBe(1);
82
- expect(count).toBe(1);
83
- });
84
- it('should using sorts', async () => {
85
- const resolver = await createResolver();
86
- const result = (await resolver.resolve({
87
- sortBy: 'index',
88
- sortType: 'asc'
89
- }, {}));
90
- const items = await result.items();
91
- const count = await result.totalCount();
92
- expect(items.map(item => item.index)).toEqual([1, 2, 3, 4, 5, 6]);
93
- expect(count).toBe(6);
94
- });
95
- });
96
- describe('Cursors with count', () => {
97
- const createResolver = async () => {
98
- const cursor = {
99
- count: () => 100,
100
- toArray: async () => [{ hello: 'foo' }]
101
- };
102
- return (0, _1.default)({
103
- returns: (0, models_1.createModel)({
104
- name: 'Hello',
105
- schema: {
106
- hello: {
107
- type: String
108
- }
109
- }
110
- }),
111
- async getCursor() {
112
- return {
113
- cursor: cursor,
114
- count: () => 10
115
- };
116
- }
117
- });
118
- };
119
- it('should not call cursor.count', async () => {
120
- const resolver = await createResolver();
121
- const result = (await resolver.resolve({}, {}));
122
- const items = await result.items();
123
- const count = await result.totalCount();
124
- expect(items.length).toBe(1);
125
- expect(count).toBe(10);
126
- });
127
- });
@@ -1,5 +0,0 @@
1
- import { Schema } from '@orion-js/schema';
2
- import { PaginatedResolverOpts } from '.';
3
- declare type OptionsKeys = 'params' | 'allowedSorts' | 'defaultSortBy' | 'defaultSortType';
4
- export default function getParams(options: Pick<PaginatedResolverOpts, OptionsKeys>): Schema;
5
- export {};
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const lodash_1 = require("lodash");
4
- function getParams(options) {
5
- const { params, allowedSorts, defaultSortBy, defaultSortType } = options;
6
- const schema = {
7
- page: {
8
- type: 'integer',
9
- defaultValue: 1,
10
- min: 1
11
- },
12
- limit: {
13
- type: 'integer',
14
- defaultValue: 0,
15
- min: 0,
16
- max: 200
17
- }
18
- };
19
- if (allowedSorts && allowedSorts.length) {
20
- schema.sortBy = {
21
- type: String,
22
- allowedValues: allowedSorts,
23
- optional: true
24
- };
25
- if (defaultSortBy) {
26
- schema.sortBy.defaultValue = defaultSortBy;
27
- }
28
- schema.sortType = {
29
- type: String,
30
- allowedValues: ['asc', 'desc'],
31
- optional: true
32
- };
33
- if (defaultSortType) {
34
- schema.sortType.defaultValue = defaultSortType;
35
- }
36
- }
37
- if (params) {
38
- if (typeof params === 'function' && params.getModel && params.__schemaId) {
39
- const modelSchema = params.getModel().getSchema();
40
- Object.assign(schema, (0, lodash_1.omit)(modelSchema, '__model'));
41
- }
42
- else if (params.__isModel) {
43
- const modelSchema = params.getSchema();
44
- Object.assign(schema, (0, lodash_1.omit)(modelSchema, '__model'));
45
- }
46
- else {
47
- Object.assign(schema, params);
48
- }
49
- }
50
- return schema;
51
- }
52
- exports.default = getParams;
@@ -1 +0,0 @@
1
- export {};
@@ -1,149 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const models_1 = require("@orion-js/models");
16
- const params_1 = __importDefault(require("./params"));
17
- const typed_model_1 = require("@orion-js/typed-model");
18
- describe('Get params', () => {
19
- it('should return the params', () => {
20
- const params = (0, params_1.default)({
21
- params: { foo: 'bar' }
22
- });
23
- expect(params).toEqual({
24
- page: {
25
- type: 'integer',
26
- defaultValue: 1,
27
- min: 1
28
- },
29
- limit: {
30
- type: 'integer',
31
- defaultValue: 0,
32
- min: 0,
33
- max: 200
34
- },
35
- foo: 'bar'
36
- });
37
- });
38
- it('should return the params with allowed sort', () => {
39
- const params = (0, params_1.default)({
40
- params: { foo: 'bar' },
41
- allowedSorts: ['foo']
42
- });
43
- expect(params).toEqual({
44
- page: {
45
- type: 'integer',
46
- defaultValue: 1,
47
- min: 1
48
- },
49
- limit: {
50
- type: 'integer',
51
- defaultValue: 0,
52
- min: 0,
53
- max: 200
54
- },
55
- sortBy: {
56
- type: String,
57
- allowedValues: ['foo'],
58
- optional: true
59
- },
60
- sortType: {
61
- type: String,
62
- allowedValues: ['asc', 'desc'],
63
- optional: true
64
- },
65
- foo: 'bar'
66
- });
67
- });
68
- it('should return the params correctly if we pass a model', () => {
69
- const model = (0, models_1.createModel)({
70
- name: 'Params',
71
- schema: {
72
- foo: {
73
- type: 'string'
74
- }
75
- }
76
- });
77
- const params = (0, params_1.default)({
78
- params: model,
79
- allowedSorts: ['foo']
80
- });
81
- expect(params).toEqual({
82
- page: {
83
- type: 'integer',
84
- defaultValue: 1,
85
- min: 1
86
- },
87
- limit: {
88
- type: 'integer',
89
- defaultValue: 0,
90
- min: 0,
91
- max: 200
92
- },
93
- sortBy: {
94
- type: String,
95
- allowedValues: ['foo'],
96
- optional: true
97
- },
98
- sortType: {
99
- type: String,
100
- allowedValues: ['asc', 'desc'],
101
- optional: true
102
- },
103
- foo: {
104
- type: 'string'
105
- }
106
- });
107
- });
108
- it('should return the params correctly if we pass a typed schema', () => {
109
- let Schema = class Schema {
110
- };
111
- __decorate([
112
- (0, typed_model_1.Prop)(),
113
- __metadata("design:type", String)
114
- ], Schema.prototype, "foo", void 0);
115
- Schema = __decorate([
116
- (0, typed_model_1.TypedSchema)()
117
- ], Schema);
118
- const params = (0, params_1.default)({
119
- params: Schema,
120
- allowedSorts: ['foo']
121
- });
122
- expect(params).toEqual({
123
- page: {
124
- type: 'integer',
125
- defaultValue: 1,
126
- min: 1
127
- },
128
- limit: {
129
- type: 'integer',
130
- defaultValue: 0,
131
- min: 0,
132
- max: 200
133
- },
134
- sortBy: {
135
- type: String,
136
- allowedValues: ['foo'],
137
- optional: true
138
- },
139
- sortType: {
140
- type: String,
141
- allowedValues: ['asc', 'desc'],
142
- optional: true
143
- },
144
- foo: {
145
- type: String
146
- }
147
- });
148
- });
149
- });
@@ -1,10 +0,0 @@
1
- import { PaginatedCursor } from './index';
2
- export default function ({ page, limit, sortBy, sortType }: {
3
- page: any;
4
- limit: any;
5
- sortBy: any;
6
- sortType: any;
7
- }, cursor: PaginatedCursor): {
8
- skip: number;
9
- limit: any;
10
- };
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1({ page, limit, sortBy, sortType }, cursor) {
4
- const skip = limit * (page - 1);
5
- if (limit && cursor.limit) {
6
- cursor.limit(limit);
7
- }
8
- if (skip && cursor.skip) {
9
- cursor.skip(skip);
10
- }
11
- if (sortBy && sortType && cursor.sort) {
12
- cursor.sort({
13
- [`${sortBy}`]: sortType === 'asc' ? 1 : -1
14
- });
15
- }
16
- return {
17
- skip,
18
- limit
19
- };
20
- }
21
- exports.default = default_1;