core-services-sdk 1.3.65 → 1.3.66
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 +2 -1
- package/src/postgresql/pagination/paginate.js +4 -4
- package/tests/postgresql/apply-filter-snake-case.integration.test.js +2 -2
- package/tests/postgresql/apply-filter.integration.test.js +3 -3
- package/tests/postgresql/paginate.integration.test.js +47 -20
- package/tests/postgresql/pagination/paginate.js +4 -3
- package/tests/postgresql/validate-schema.integration.test.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "core-services-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.66",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@aws-sdk/credential-provider-node": "^3.862.0",
|
|
32
32
|
"@sendgrid/mail": "^8.1.5",
|
|
33
33
|
"amqplib": "^0.10.8",
|
|
34
|
+
"date-fns": "^4.1.0",
|
|
34
35
|
"dot": "^1.1.3",
|
|
35
36
|
"fastify": "^5.4.0",
|
|
36
37
|
"google-libphonenumber": "^3.2.42",
|
|
@@ -35,14 +35,14 @@ export async function sqlPaginate({
|
|
|
35
35
|
])
|
|
36
36
|
|
|
37
37
|
const totalCount = normalizeNumberOrDefault(countResult?.count || 0)
|
|
38
|
-
const
|
|
38
|
+
const pages = Math.ceil(totalCount / limit)
|
|
39
39
|
|
|
40
40
|
return {
|
|
41
|
+
page,
|
|
42
|
+
pages,
|
|
41
43
|
totalCount,
|
|
42
|
-
totalPages,
|
|
43
|
-
currentPage: page,
|
|
44
44
|
hasPrevious: page > 1,
|
|
45
|
-
hasNext: page <
|
|
45
|
+
hasNext: page < pages,
|
|
46
46
|
list: mapRow ? rows.map(mapRow) : rows,
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -12,10 +12,10 @@ import { applyFilterSnakeCase } from '../../src/postgresql/filters/apply-filter-
|
|
|
12
12
|
|
|
13
13
|
const PG_OPTIONS = {
|
|
14
14
|
port: 5444,
|
|
15
|
-
|
|
15
|
+
db: 'testdb',
|
|
16
16
|
user: 'testuser',
|
|
17
17
|
pass: 'testpass',
|
|
18
|
-
|
|
18
|
+
containerName: 'postgres-apply-filter-test-5444',
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const DATABASE_URI = buildPostgresUri(PG_OPTIONS)
|
|
@@ -3,8 +3,8 @@ import { describe, it, beforeAll, afterAll, beforeEach, expect } from 'vitest'
|
|
|
3
3
|
import knex from 'knex'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
startPostgres,
|
|
7
6
|
stopPostgres,
|
|
7
|
+
startPostgres,
|
|
8
8
|
buildPostgresUri,
|
|
9
9
|
} from '../../src/postgresql/start-stop-postgres-docker.js'
|
|
10
10
|
|
|
@@ -12,10 +12,10 @@ import { applyFilter } from '../../src/postgresql/filters/apply-filter.js'
|
|
|
12
12
|
|
|
13
13
|
const PG_OPTIONS = {
|
|
14
14
|
port: 5443,
|
|
15
|
-
|
|
15
|
+
db: 'testdb',
|
|
16
16
|
user: 'testuser',
|
|
17
17
|
pass: 'testpass',
|
|
18
|
-
|
|
18
|
+
containerName: 'postgres-apply-filter-test',
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const DATABASE_URI = buildPostgresUri(PG_OPTIONS)
|
|
@@ -9,13 +9,14 @@ import {
|
|
|
9
9
|
} from '../../src/postgresql/start-stop-postgres-docker.js'
|
|
10
10
|
|
|
11
11
|
import { sqlPaginate } from '../../src/postgresql/pagination/paginate.js'
|
|
12
|
+
import { sub } from 'date-fns'
|
|
12
13
|
|
|
13
14
|
const PG_OPTIONS = {
|
|
14
15
|
port: 5442,
|
|
15
|
-
|
|
16
|
+
db: 'testdb',
|
|
16
17
|
user: 'testuser',
|
|
17
18
|
pass: 'testpass',
|
|
18
|
-
|
|
19
|
+
containerName: 'postgres-paginate-test-5442',
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const DATABASE_URI = buildPostgresUri(PG_OPTIONS)
|
|
@@ -34,6 +35,7 @@ beforeAll(async () => {
|
|
|
34
35
|
table.uuid('id').primary()
|
|
35
36
|
table.string('name').notNullable()
|
|
36
37
|
table.string('type').notNullable()
|
|
38
|
+
table.bigInteger('age').notNullable()
|
|
37
39
|
table.timestamp('created_at').notNullable()
|
|
38
40
|
})
|
|
39
41
|
})
|
|
@@ -47,41 +49,60 @@ afterAll(async () => {
|
|
|
47
49
|
|
|
48
50
|
beforeEach(async () => {
|
|
49
51
|
await db('tenants').truncate()
|
|
50
|
-
|
|
51
|
-
await db('tenants').insert([
|
|
52
|
+
const records = [
|
|
52
53
|
{
|
|
53
54
|
id: '00000000-0000-0000-0000-000000000001',
|
|
54
55
|
name: 'Tenant A',
|
|
55
56
|
type: 'business',
|
|
56
|
-
|
|
57
|
+
age: 2,
|
|
58
|
+
created_at: new Date('2025-01-01'),
|
|
57
59
|
},
|
|
58
60
|
{
|
|
59
61
|
id: '00000000-0000-0000-0000-000000000002',
|
|
60
62
|
name: 'Tenant B',
|
|
63
|
+
age: 3,
|
|
61
64
|
type: 'business',
|
|
62
65
|
created_at: new Date('2024-01-02'),
|
|
63
66
|
},
|
|
64
67
|
{
|
|
65
68
|
id: '00000000-0000-0000-0000-000000000003',
|
|
66
69
|
name: 'Tenant C',
|
|
70
|
+
age: 1,
|
|
71
|
+
type: 'cpa',
|
|
72
|
+
created_at: new Date('2023-01-03'),
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
id: '00000000-0000-0000-0000-000000000004',
|
|
77
|
+
name: 'Tenant D',
|
|
78
|
+
age: 7,
|
|
79
|
+
type: 'cpa',
|
|
80
|
+
created_at: new Date('2022-01-03'),
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
{
|
|
84
|
+
id: '00000000-0000-0000-0000-000000000005',
|
|
85
|
+
name: 'Tenant E',
|
|
86
|
+
age: 0,
|
|
67
87
|
type: 'cpa',
|
|
68
|
-
created_at: new Date('
|
|
88
|
+
created_at: new Date('2021-01-03'),
|
|
69
89
|
},
|
|
70
|
-
]
|
|
90
|
+
]
|
|
91
|
+
await db('tenants').insert(records)
|
|
71
92
|
})
|
|
72
93
|
|
|
73
94
|
describe('paginate integration', () => {
|
|
74
95
|
it('returns first page without ordering guarantees', async () => {
|
|
75
96
|
const result = await sqlPaginate({
|
|
76
97
|
baseQuery: db('tenants'),
|
|
77
|
-
page:
|
|
98
|
+
page: 2,
|
|
78
99
|
limit: 2,
|
|
79
100
|
})
|
|
80
101
|
|
|
81
|
-
expect(result.totalCount).toBe(
|
|
82
|
-
expect(result.
|
|
83
|
-
expect(result.
|
|
84
|
-
expect(result.hasPrevious).toBe(
|
|
102
|
+
expect(result.totalCount).toBe(5)
|
|
103
|
+
expect(result.pages).toBe(3)
|
|
104
|
+
expect(result.page).toBe(2)
|
|
105
|
+
expect(result.hasPrevious).toBe(true)
|
|
85
106
|
expect(result.hasNext).toBe(true)
|
|
86
107
|
expect(result.list).toHaveLength(2)
|
|
87
108
|
})
|
|
@@ -93,19 +114,23 @@ describe('paginate integration', () => {
|
|
|
93
114
|
limit: 2,
|
|
94
115
|
})
|
|
95
116
|
|
|
96
|
-
expect(result.totalCount).toBe(
|
|
97
|
-
expect(result.
|
|
98
|
-
expect(result.
|
|
117
|
+
expect(result.totalCount).toBe(5)
|
|
118
|
+
expect(result.pages).toBe(3)
|
|
119
|
+
expect(result.page).toBe(2)
|
|
99
120
|
expect(result.hasPrevious).toBe(true)
|
|
100
|
-
expect(result.hasNext).toBe(
|
|
101
|
-
expect(result.list).toHaveLength(
|
|
121
|
+
expect(result.hasNext).toBe(true)
|
|
122
|
+
expect(result.list).toHaveLength(2)
|
|
102
123
|
})
|
|
103
124
|
|
|
104
125
|
it('applies filters correctly', async () => {
|
|
126
|
+
const minDate = sub(new Date(), { years: 2 })
|
|
105
127
|
const result = await sqlPaginate({
|
|
106
128
|
baseQuery: db('tenants'),
|
|
107
|
-
filter: {
|
|
129
|
+
filter: {
|
|
130
|
+
createdAt: { lte: new Date(), gte: minDate },
|
|
131
|
+
},
|
|
108
132
|
limit: 10,
|
|
133
|
+
page: 1,
|
|
109
134
|
})
|
|
110
135
|
|
|
111
136
|
expect(result.totalCount).toBe(2)
|
|
@@ -118,7 +143,7 @@ describe('paginate integration', () => {
|
|
|
118
143
|
const result = await sqlPaginate({
|
|
119
144
|
baseQuery: db('tenants'),
|
|
120
145
|
orderBy: {
|
|
121
|
-
column: '
|
|
146
|
+
column: 'name',
|
|
122
147
|
direction: 'asc',
|
|
123
148
|
},
|
|
124
149
|
})
|
|
@@ -127,6 +152,8 @@ describe('paginate integration', () => {
|
|
|
127
152
|
'Tenant A',
|
|
128
153
|
'Tenant B',
|
|
129
154
|
'Tenant C',
|
|
155
|
+
'Tenant D',
|
|
156
|
+
'Tenant E',
|
|
130
157
|
])
|
|
131
158
|
})
|
|
132
159
|
|
|
@@ -150,7 +177,7 @@ describe('paginate integration', () => {
|
|
|
150
177
|
})
|
|
151
178
|
|
|
152
179
|
expect(result.totalCount).toBe(0)
|
|
153
|
-
expect(result.
|
|
180
|
+
expect(result.pages).toBe(0)
|
|
154
181
|
expect(result.list).toEqual([])
|
|
155
182
|
expect(result.hasNext).toBe(false)
|
|
156
183
|
expect(result.hasPrevious).toBe(false)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
import { applyFilter } from '../filters/apply-filter.js'
|
|
2
3
|
import { applyFilterSnakeCase } from '../filters/apply-filter-snake-case.js'
|
|
3
4
|
import { applyOrderBy } from '../modifiers/apply-order-by.js'
|
|
@@ -35,14 +36,14 @@ export async function sqlPaginate({
|
|
|
35
36
|
])
|
|
36
37
|
|
|
37
38
|
const totalCount = normalizeNumberOrDefault(countResult?.count || 0)
|
|
38
|
-
const
|
|
39
|
+
const pages = Math.ceil(totalCount / limit)
|
|
39
40
|
|
|
40
41
|
return {
|
|
41
42
|
totalCount,
|
|
42
|
-
|
|
43
|
+
pages,
|
|
43
44
|
currentPage: page,
|
|
44
45
|
hasPrevious: page > 1,
|
|
45
|
-
hasNext: page <
|
|
46
|
+
hasNext: page < pages,
|
|
46
47
|
list: mapRow ? rows.map(mapRow) : rows,
|
|
47
48
|
}
|
|
48
49
|
}
|
|
@@ -11,10 +11,10 @@ import { validateSchema } from '../../src/postgresql/validate-schema.js'
|
|
|
11
11
|
|
|
12
12
|
const PG_OPTIONS = {
|
|
13
13
|
port: 5431,
|
|
14
|
-
|
|
14
|
+
db: 'testdb',
|
|
15
15
|
user: 'testuser',
|
|
16
16
|
pass: 'testpass',
|
|
17
|
-
|
|
17
|
+
containerName: 'postgres-validate-schema-test-5431',
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const DATABASE_URI = buildPostgresUri(PG_OPTIONS)
|