typeorm-cursor-pagination
typeorm-cursor-pagination copied to clipboard
fix encode / decode by type to support branded ids
- for some reason decodeByType was handling objects and dates the same
- in my scenario the branded id was an abject that needed to be treated differently than a date
- I added a check for the existence of the toString method
Thanks for your contribution. Please add some proper test cases, and remove the comment of the specific use case.
i would but i was expecting tests to work locally right now I have
0 passing (6s)
7 failing
--------------|---------|----------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------|---------|----------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
All files | 13.24 | 5.56 | 3.03 | 13.43 |
Paginator.ts | 3.8 | 0 | 0 | 3.85 | 36,38,40,42,44,46,48,51,52,56,60,64,68,72,76,77,79,80,83,84,87,88,91,92,95,96,99,103,110,112-115,118,119,122,123,125,129-135,140,141,144,145,148,152,154,155,158-160,163,167,171,175-178,181,185-191,194,198,202,208
index.ts | 14.29 | 0 | 0 | 14.29 | 27,29,31,33,34,37,38,41,42,45,46,49
utils.ts | 30.23 | 16.67 | 12.5 | 30.95 | 2,6,14,17,20,28,44,46,49,53,64,65,70,72,73,76,80,82,83,86,90,94,100,104,106,107,110,114,118
--------------|---------|----------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
i ran yarn test:docker and npm run test:docker
so how do I check my tests before pushing them?
thanks
What is the exact error of the testing?
TypeORM cursor-based pagination column naming strategy test
Camel case naming strategy
1) "before all" hook for "should correctly paginate entities with camel case pagination keys"
2) "after all" hook for "should correctly paginate entities with camel case pagination keys"
Snake case naming strategy test
3) "before all" hook for "should correctly paginate entities with snake case pagination keys"
4) "after all" hook for "should correctly paginate entities with snake case pagination keys"
TypeORM cursor-based pagination test
5) "before all" hook for "should paginate correctly with before and after cursor"
6) "after all" hook for "should return empty array and null cursor if no data"
Reflect.getMetadata Date type is Object test
7) should throw error with object type and non date value
0 passing (6s)
7 failing
1) TypeORM cursor-based pagination column naming strategy test
Camel case naming strategy
"before all" hook for "should correctly paginate entities with camel case pagination keys":
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/test/columnNamingStrategy.ts)
at listOnTimeout (node:internal/timers:555:17)
at processTimers (node:internal/timers:498:7)
2) TypeORM cursor-based pagination column naming strategy test
Camel case naming strategy
"after all" hook for "should correctly paginate entities with camel case pagination keys":
TypeError: Cannot read property 'connect' of undefined
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/src/driver/postgres/PostgresDriver.ts:780:25
at new Promise (<anonymous>)
at PostgresDriver.obtainMasterConnection (src/driver/postgres/PostgresDriver.ts:779:16)
at PostgresQueryRunner.connect (src/driver/postgres/PostgresQueryRunner.ts:90:58)
at PostgresQueryRunner.<anonymous> (src/driver/postgres/PostgresQueryRunner.ts:163:55)
at step (node_modules/tslib/tslib.js:139:27)
at Object.next (node_modules/tslib/tslib.js:120:57)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/node_modules/tslib/tslib.js:113:75
at new Promise (<anonymous>)
at Object.__awaiter (node_modules/tslib/tslib.js:109:16)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/src/driver/postgres/PostgresQueryRunner.ts:161:50
at new Promise (<anonymous>)
at PostgresQueryRunner.query (src/driver/postgres/PostgresQueryRunner.ts:161:16)
at Connection.<anonymous> (src/connection/Connection.ts:400:42)
at step (node_modules/tslib/tslib.js:139:27)
at Object.next (node_modules/tslib/tslib.js:120:57)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/node_modules/tslib/tslib.js:113:75
at new Promise (<anonymous>)
at Object.__awaiter (node_modules/tslib/tslib.js:109:16)
at Connection.query (node_modules/typeorm/connection/Connection.js:379:24)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/test/columnNamingStrategy.ts:57:29
at Generator.next (<anonymous>)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/test/columnNamingStrategy.ts:8:71
at new Promise (<anonymous>)
at __awaiter (test/columnNamingStrategy.ts:4:12)
at Context.<anonymous> (test/columnNamingStrategy.ts:56:22)
at processImmediate (node:internal/timers:462:21)
3) TypeORM cursor-based pagination column naming strategy test
Snake case naming strategy test
"before all" hook for "should correctly paginate entities with snake case pagination keys":
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/test/columnNamingStrategy.ts)
at listOnTimeout (node:internal/timers:555:17)
at processTimers (node:internal/timers:498:7)
4) TypeORM cursor-based pagination column naming strategy test
Snake case naming strategy test
"after all" hook for "should correctly paginate entities with snake case pagination keys":
TypeError: Cannot read property 'connect' of undefined
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/src/driver/postgres/PostgresDriver.ts:780:25
at new Promise (<anonymous>)
at PostgresDriver.obtainMasterConnection (src/driver/postgres/PostgresDriver.ts:779:16)
at PostgresQueryRunner.connect (src/driver/postgres/PostgresQueryRunner.ts:90:58)
at PostgresQueryRunner.<anonymous> (src/driver/postgres/PostgresQueryRunner.ts:163:55)
at step (node_modules/tslib/tslib.js:139:27)
at Object.next (node_modules/tslib/tslib.js:120:57)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/node_modules/tslib/tslib.js:113:75
at new Promise (<anonymous>)
at Object.__awaiter (node_modules/tslib/tslib.js:109:16)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/src/driver/postgres/PostgresQueryRunner.ts:161:50
at new Promise (<anonymous>)
at PostgresQueryRunner.query (src/driver/postgres/PostgresQueryRunner.ts:161:16)
at Connection.<anonymous> (src/connection/Connection.ts:400:42)
at step (node_modules/tslib/tslib.js:139:27)
at Object.next (node_modules/tslib/tslib.js:120:57)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/node_modules/tslib/tslib.js:113:75
at new Promise (<anonymous>)
at Object.__awaiter (node_modules/tslib/tslib.js:109:16)
at Connection.query (node_modules/typeorm/connection/Connection.js:379:24)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/test/columnNamingStrategy.ts:104:29
at Generator.next (<anonymous>)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/test/columnNamingStrategy.ts:8:71
at new Promise (<anonymous>)
at __awaiter (test/columnNamingStrategy.ts:4:12)
at Context.<anonymous> (test/columnNamingStrategy.ts:103:22)
at processImmediate (node:internal/timers:462:21)
5) TypeORM cursor-based pagination test
"before all" hook for "should paginate correctly with before and after cursor":
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/test/pagination.ts)
at listOnTimeout (node:internal/timers:555:17)
at processTimers (node:internal/timers:498:7)
6) TypeORM cursor-based pagination test
"after all" hook for "should return empty array and null cursor if no data":
TypeError: Cannot read property 'connect' of undefined
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/src/driver/postgres/PostgresDriver.ts:780:25
at new Promise (<anonymous>)
at PostgresDriver.obtainMasterConnection (src/driver/postgres/PostgresDriver.ts:779:16)
at PostgresQueryRunner.connect (src/driver/postgres/PostgresQueryRunner.ts:90:58)
at PostgresQueryRunner.<anonymous> (src/driver/postgres/PostgresQueryRunner.ts:163:55)
at step (node_modules/tslib/tslib.js:139:27)
at Object.next (node_modules/tslib/tslib.js:120:57)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/node_modules/tslib/tslib.js:113:75
at new Promise (<anonymous>)
at Object.__awaiter (node_modules/tslib/tslib.js:109:16)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/src/driver/postgres/PostgresQueryRunner.ts:161:50
at new Promise (<anonymous>)
at PostgresQueryRunner.query (src/driver/postgres/PostgresQueryRunner.ts:161:16)
at Connection.<anonymous> (src/connection/Connection.ts:400:42)
at step (node_modules/tslib/tslib.js:139:27)
at Object.next (node_modules/tslib/tslib.js:120:57)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/node_modules/tslib/tslib.js:113:75
at new Promise (<anonymous>)
at Object.__awaiter (node_modules/tslib/tslib.js:109:16)
at Connection.query (node_modules/typeorm/connection/Connection.js:379:24)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/test/pagination.ts:122:27
at Generator.next (<anonymous>)
at /Users/wowzaaa/Projects/github-prs/typeorm-cursor-pagination/test/pagination.ts:8:71
at new Promise (<anonymous>)
at __awaiter (test/pagination.ts:4:12)
at Context.<anonymous> (test/pagination.ts:121:20)
at processImmediate (node:internal/timers:462:21)
7) Reflect.getMetadata Date type is Object test
should throw error with object type and non date value:
AssertionError: expected [Function] to throw an error
at Context.<anonymous> (test/reflection.ts:21:66)
at processImmediate (node:internal/timers:462:21)
can I also ask the reason for using
Reflect.getMetadata('design:type', this.entity.prototype, key).name.toLowerCase();
instead of
Object.prototype.toString.call(key)
I believe it's a TypeORM issue: https://github.com/typeorm/typeorm/issues/5733
Please remove the node_modules folder, and run npm install with the Node v10 before running the integration test.
can I also ask the reason for using
Reflect.getMetadata('design:type', this.entity.prototype, key).name.toLowerCase();instead of
Object.prototype.toString.call(key)
It is just a different implementation. I don't have a concrete reason, both of them can achieve our goal.