Skip to content

Commit f6c68d5

Browse files
committed
feat: prepare for publish
- support 'attributes' option - support 'where' option - add tests - transpile
1 parent cdf51ef commit f6c68d5

12 files changed

+6740
-22
lines changed

.eslintrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends":[
3+
"@foobarhq/eslint-config",
4+
"@foobarhq/eslint-config-typescript"
5+
]
6+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
22
node_modules
3+
/lib

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

babel.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used by JEST
2+
3+
// eslint-disable-next-line import/no-commonjs
4+
module.exports = {
5+
presets: [
6+
['@babel/preset-env', { targets: { node: 'current' } }],
7+
'@babel/preset-typescript',
8+
],
9+
};

docker-compose.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '2'
2+
services:
3+
mmc-psql:
4+
image: postgres:12.2
5+
container_name: sequelize-cursor-psql
6+
ports:
7+
- "19132:5432"
8+
environment:
9+
# dev database, don't use these in prod!
10+
POSTGRES_PASSWORD: password
11+
POSTGRES_USER: user
12+
POSTGRES_DB: db
13+
mem_limit: 256M

package-lock.json

+6,224
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"name": "@ephys/sequelize-cursor-pagination",
33
"version": "1.0.0",
4-
"description": "Implement Cursor Pagination in the Sequelize ORM",
4+
"description": "Implements Cursor Pagination in the Sequelize ORM",
55
"main": "lib/index.js",
66
"scripts": {
7-
"test": "jest"
7+
"test": "eslint src/**/*.ts && jest",
8+
"build": "tsc",
9+
"prepublishOnly": "npm test && npm run build"
810
},
911
"repository": {
1012
"type": "git",
@@ -16,7 +18,20 @@
1618
"url": "https://github.com/Ephys/sequelize-cursor-pagination/issues"
1719
},
1820
"homepage": "https://github.com/Ephys/sequelize-cursor-pagination#readme",
19-
"peerDependencies": {
21+
"devDependencies": {
22+
"@babel/core": "^7.14.6",
23+
"@babel/preset-env": "^7.14.5",
24+
"@babel/preset-typescript": "^7.14.5",
25+
"@foobarhq/eslint-config": "^10.2.0",
26+
"@foobarhq/eslint-config-typescript": "^10.2.0",
27+
"@types/jest": "^26.0.23",
28+
"babel-jest": "^27.0.2",
29+
"eslint": "^7.29.0",
30+
"jest": "^27.0.4",
31+
"pg": "^8.6.0",
32+
"typescript": "^4.3.4"
33+
},
34+
"dependencies": {
2035
"sequelize": "^6.6.2"
2136
}
2237
}

src/__snapshots__/index.spec.ts.snap

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`sequelizeFindByCursor does not include extra PK in ORDER BY if it’s already present: nodes 1`] = `
4+
Array [
5+
Object {
6+
"firstName": "Alan",
7+
"id": 5,
8+
"lastName": "LastName",
9+
},
10+
Object {
11+
"firstName": "Bernard",
12+
"id": 4,
13+
"lastName": "LastName",
14+
},
15+
Object {
16+
"firstName": "Cedric",
17+
"id": 3,
18+
"lastName": "Anderson",
19+
},
20+
Object {
21+
"firstName": "Cedric",
22+
"id": 2,
23+
"lastName": "Brown",
24+
},
25+
Object {
26+
"firstName": "Dimitri",
27+
"id": 6,
28+
"lastName": "LastName",
29+
},
30+
Object {
31+
"firstName": "Dimitri",
32+
"id": 1,
33+
"lastName": "LastName",
34+
},
35+
]
36+
`;
37+
38+
exports[`sequelizeFindByCursor does not include extra PK in ORDER BY if it’s already present: query 1`] = `"Executing (default): SELECT \\"users\\".* FROM (SELECT \\"first_name\\" AS \\"firstName\\", \\"last_name\\" AS \\"lastName\\", \\"id\\" FROM \\"users\\" AS \\"users\\" ORDER BY \\"users\\".\\"first_name\\" ASC, \\"users\\".\\"last_name\\" ASC, \\"users\\".\\"id\\" DESC LIMIT 11) AS \\"users\\" ORDER BY \\"firstName\\" ASC, \\"lastName\\" ASC, \\"users\\".\\"id\\" DESC;"`;
39+
40+
exports[`sequelizeFindByCursor includes PK in ORDER BY to ensures constant order: nodes 1`] = `
41+
Array [
42+
Object {
43+
"firstName": "Alan",
44+
"id": 5,
45+
"lastName": "LastName",
46+
},
47+
Object {
48+
"firstName": "Bernard",
49+
"id": 4,
50+
"lastName": "LastName",
51+
},
52+
Object {
53+
"firstName": "Cedric",
54+
"id": 3,
55+
"lastName": "Anderson",
56+
},
57+
Object {
58+
"firstName": "Cedric",
59+
"id": 2,
60+
"lastName": "Brown",
61+
},
62+
Object {
63+
"firstName": "Dimitri",
64+
"id": 1,
65+
"lastName": "LastName",
66+
},
67+
Object {
68+
"firstName": "Dimitri",
69+
"id": 6,
70+
"lastName": "LastName",
71+
},
72+
]
73+
`;
74+
75+
exports[`sequelizeFindByCursor includes PK in ORDER BY to ensures constant order: query 1`] = `"Executing (default): SELECT \\"users\\".* FROM (SELECT \\"first_name\\" AS \\"firstName\\", \\"last_name\\" AS \\"lastName\\", \\"id\\" FROM \\"users\\" AS \\"users\\" ORDER BY \\"users\\".\\"first_name\\" ASC, \\"users\\".\\"last_name\\" ASC, \\"users\\".\\"id\\" ASC LIMIT 11) AS \\"users\\" ORDER BY \\"firstName\\" ASC, \\"lastName\\" ASC, \\"users\\".\\"id\\" ASC;"`;
76+
77+
exports[`sequelizeFindByCursor supports filtering: nodes 1`] = `
78+
Array [
79+
Object {
80+
"firstName": "Dimitri",
81+
"id": 1,
82+
"lastName": "LastName",
83+
},
84+
Object {
85+
"firstName": "Dimitri",
86+
"id": 6,
87+
"lastName": "LastName",
88+
},
89+
]
90+
`;
91+
92+
exports[`sequelizeFindByCursor supports filtering: query 1`] = `"Executing (default): SELECT \\"users\\".* FROM (SELECT \\"first_name\\" AS \\"firstName\\", \\"last_name\\" AS \\"lastName\\", \\"id\\" FROM \\"users\\" AS \\"users\\" WHERE (\\"users\\".\\"birth_date\\" >= '1990-01-01' AND (\\"users\\".\\"first_name\\" > 'Bernard' OR (\\"users\\".\\"first_name\\" = 'Bernard' AND (\\"users\\".\\"last_name\\" > 'LastName' OR (\\"users\\".\\"last_name\\" = 'LastName' AND \\"users\\".\\"id\\" > 4))))) ORDER BY \\"users\\".\\"first_name\\" ASC, \\"users\\".\\"last_name\\" ASC, \\"users\\".\\"id\\" ASC LIMIT 11) AS \\"users\\" ORDER BY \\"firstName\\" ASC, \\"lastName\\" ASC, \\"users\\".\\"id\\" ASC;"`;
93+
94+
exports[`sequelizeFindByCursor supports filtering: query 2`] = `"Executing (default): SELECT \\"users\\".* FROM (SELECT \\"first_name\\" AS \\"firstName\\", \\"last_name\\" AS \\"lastName\\", \\"id\\" FROM \\"users\\" AS \\"users\\" WHERE (\\"users\\".\\"birth_date\\" >= '1990-01-01' AND (\\"users\\".\\"first_name\\" < 'Bernard' OR (\\"users\\".\\"first_name\\" = 'Bernard' AND (\\"users\\".\\"last_name\\" < 'LastName' OR (\\"users\\".\\"last_name\\" = 'LastName' AND \\"users\\".\\"id\\" < 4))))) ORDER BY \\"users\\".\\"first_name\\" DESC, \\"users\\".\\"last_name\\" DESC, \\"users\\".\\"id\\" DESC LIMIT 1) AS \\"users\\" ORDER BY \\"firstName\\" DESC, \\"lastName\\" DESC, \\"users\\".\\"id\\" DESC;"`;
95+
96+
exports[`sequelizeFindByCursor supports returning the first x elements after another cursor: nodes 1`] = `
97+
Array [
98+
Object {
99+
"firstName": "Cedric",
100+
"id": 2,
101+
"lastName": "Brown",
102+
},
103+
Object {
104+
"firstName": "Dimitri",
105+
"id": 1,
106+
"lastName": "LastName",
107+
},
108+
]
109+
`;
110+
111+
exports[`sequelizeFindByCursor supports returning the first x elements before another cursor: nodes 1`] = `
112+
Array [
113+
Object {
114+
"firstName": "Alan",
115+
"id": 5,
116+
"lastName": "LastName",
117+
},
118+
Object {
119+
"firstName": "Bernard",
120+
"id": 4,
121+
"lastName": "LastName",
122+
},
123+
]
124+
`;
125+
126+
exports[`sequelizeFindByCursor supports returning the first x elements of the set: nodes 1`] = `
127+
Array [
128+
Object {
129+
"firstName": "Alan",
130+
"id": 5,
131+
"lastName": "LastName",
132+
},
133+
Object {
134+
"firstName": "Bernard",
135+
"id": 4,
136+
"lastName": "LastName",
137+
},
138+
]
139+
`;
140+
141+
exports[`sequelizeFindByCursor supports returning the last x elements after another cursor: nodes 1`] = `
142+
Array [
143+
Object {
144+
"firstName": "Dimitri",
145+
"id": 1,
146+
"lastName": "LastName",
147+
},
148+
Object {
149+
"firstName": "Dimitri",
150+
"id": 6,
151+
"lastName": "LastName",
152+
},
153+
]
154+
`;
155+
156+
exports[`sequelizeFindByCursor supports returning the last x elements before another cursor: nodes 1`] = `
157+
Array [
158+
Object {
159+
"firstName": "Cedric",
160+
"id": 3,
161+
"lastName": "Anderson",
162+
},
163+
Object {
164+
"firstName": "Cedric",
165+
"id": 2,
166+
"lastName": "Brown",
167+
},
168+
]
169+
`;
170+
171+
exports[`sequelizeFindByCursor supports returning the last x elements of the set: nodes 1`] = `
172+
Array [
173+
Object {
174+
"firstName": "Dimitri",
175+
"id": 1,
176+
"lastName": "LastName",
177+
},
178+
Object {
179+
"firstName": "Dimitri",
180+
"id": 6,
181+
"lastName": "LastName",
182+
},
183+
]
184+
`;

0 commit comments

Comments
 (0)