Skip to content

Commit

Permalink
refactor: remove @secjs/contracts from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Mar 5, 2022
1 parent edb47ab commit 9daaa4c
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 25 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The intention behind this repository is to always maintain a `Utils` package wit
> it keeps as dev dependency because one day `@secjs/core` will install everything once.
```bash
npm install @secjs/contracts @secjs/exceptions
npm install @secjs/exceptions
```

> Then you can install the package using:
Expand Down Expand Up @@ -741,8 +741,7 @@ scheduler(func, 3000) // scheduler function will execute the func every 3 second
> Use paginate get meta and links from for response
```js
import { paginate } from '@secjs/utils'
import { PaginationContract } from '@secjs/contracts'
import { paginate, PaginationContract } from '@secjs/utils'

const filters = {
where: { id: 1 }
Expand Down
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './src/Contracts/FileContract'
export * from './src/Contracts/PaginationContract'
export * from './src/Contracts/DBUrlParserContract'

export * from './src/Classes/Is'
Expand Down
21 changes: 4 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@secjs/utils",
"version": "1.7.2",
"version": "1.7.3",
"description": "",
"license": "MIT",
"author": "João Lenon",
Expand All @@ -18,7 +18,6 @@
"nodejs"
],
"devDependencies": {
"@secjs/contracts": "1.2.1",
"@secjs/exceptions": "1.0.4",
"@types/bytes": "3.1.1",
"@types/debug": "4.1.5",
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Parser } from './Parser'
import { lookup } from 'mime-types'
import { randomBytes } from 'crypto'
import { parse, isAbsolute } from 'path'
import { FileContract } from '@secjs/contracts'
import { FileContract } from '../Contracts/FileContract'
import { InternalServerException } from '@secjs/exceptions'

export interface FileJsonContract {
Expand Down
15 changes: 15 additions & 0 deletions src/Contracts/FileContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @secjs/utils
*
* (c) João Lenon <lenon@secjs.com.br>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

export interface FileContract {
name?: string
base?: string
path?: string
value?: string | Buffer
}
35 changes: 35 additions & 0 deletions src/Contracts/PaginationContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @secjs/utils
*
* (c) João Lenon <lenon@secjs.com.br>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

export interface PaginationMetaContract {
itemCount: number
totalItems: number
totalPages: number
currentPage: number
itemsPerPage: number
}

export interface PaginationLinksContract {
first: string
previous: string
next: string
last: string
}

export interface PaginatedResponse<T = any[]> {
meta: PaginationMetaContract
links: PaginationLinksContract
data: T
}

export interface PaginationContract {
page?: number
limit?: number
resourceUrl?: string
}
7 changes: 5 additions & 2 deletions src/Functions/paginate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { PaginatedResponse, PaginationContract } from '@secjs/contracts'
import {
PaginatedResponse,
PaginationContract,
} from '../Contracts/PaginationContract'

export function paginate(
data: any[],
total: number,
pagination: PaginationContract,
): PaginatedResponse<any> {
): PaginatedResponse {
const totalPages = Math.ceil(total / pagination.limit)

const meta = {
Expand Down

0 comments on commit 9daaa4c

Please sign in to comment.