From 519916b3b5b7c33f1ab2921c0c8f743decb18941 Mon Sep 17 00:00:00 2001 From: Iben Van de Veire Date: Fri, 10 Jan 2025 09:53:04 +0100 Subject: [PATCH] build(nodejs-hal-tools):v2.0.0 --- libs/javascript/pagination/README.md | 116 +++--------------------- libs/javascript/pagination/package.json | 6 +- 2 files changed, 17 insertions(+), 105 deletions(-) diff --git a/libs/javascript/pagination/README.md b/libs/javascript/pagination/README.md index 776c8ead..aa7b969a 100644 --- a/libs/javascript/pagination/README.md +++ b/libs/javascript/pagination/README.md @@ -1,113 +1,25 @@ -# Studio Hyperdrive HAL Toolset +# Javascript Tools: Pagination (`@studiohyperdrive/nodejs-hal-tools`) -## General +`@studiohyperdrive/nodejs-hal-tools` is light-weight package that contains a set of tools for working with HAL standards. -WARNING: This package has been renamed to [@studiohyperdrive/nodejs-hal-tools](https://www.npmjs.com/package/@studiohyperdrive/nodejs-hal-tools). +## Installation -This repo contains a set of tools for working with HAL standards. +Install the package first: -It is build with: -- node: `v18.x.x` ( ~ `lts/hydrogen`) -- npm: `10.x.x` - -For a complete list of packages and version check out the `package.json` file. - -## Use - -### Install - -You can install this package by doing: -``` bash -$ npm install @studiohyperdrive/nodejs-hal-tools -``` -or if you use Yarn: -``` bash -$ yarn add @studiohyperdrive/nodejs-hal-tools -``` - -### In your code -In your code, you can use this package and it's interfaces like this: - -```typescript -import { HALFormat } from '@studiohyperdrive/nodejs-hal-tools'; - -class DoSomething { - public async findAll(page: number, size: number): Promise> { - const [entities, totalElements] = await this.MyEntitiyRepository.findAndCount( - calculateTakeSkip(page, size), - ); - const key = 'my-entities'; - const path = `https://my-api.com/v1/api/${key}`; - - return HALFormat({ - path, - key, - entities, - page, - size, - totalElements, - }); - } -} +```shell +npm install @studiohyperdrive/nodejs-hal-tools ``` -This will transform your entities and count to a HAL formatted response which you can return to the client. - -#### Parameters -- `path`: The path parameter is optional, if omitted, the _links section is not added -- `maxPages`: An optional parameter that limits the maximum number of pages returned. This can be useful in scenario's with lots of items, where querying with limit/offset can be time consuming. To prevent the user from navigating to e.g. page 599, you can limit that number using the `maxPages` parameter. - - -### What's in the package? -This package exposes the following functions: -- `calculateTotalPages`: This function will calculate the total amount of pages based on the pagesize & total amount of items. -- `calculatePagination`: This function will calculate and return all pagination properties. -- `calculateNextPage`: This function will calculate your next page or, when there is none, return your current page. -- `createHalLinks`: This function will create a set of links required by the HAL Format. -- `HALFormat`: This function is the main one which will use the above and your input to transform your input to a HAL-formatted object. - -And the following interfaces: -- `IHALLink`: An interface for a single HAL link. -- `IHALLinks`: An interface for the `_links` property. -- `IHALEntities`: An interface for the `_embedded` property, takes in an optional `T`. -- `IHALPagination`: An interface for the `_page` property. -- `IHALFormat`: An interface for the HAL formatted object containing the above properties. -- `IHALFormatParams`: An interface for the arguments of the `HALFormat` function. -## Setup for contribution - -### Clone and install dependencies -To setup this project, clone the repo and run `npm i` to install the dependencies. - -### NPM -The available commands for building the project are: - -| command | runs | -|--------------|-----------------------------------------------------------------------------------------------------------| -| build | This script runs tsc to compile and your code (target to the `dist` folder). | -| prepare | This script runs the `npm run build` command, it is a hook on the npm publish. | -
- -The available commands for testing the project are: - -| command | runs | -|--------------|-----------------------------------------------------------------------------------------------------------| -| lint | This script will run linting and fix what it can. | -| test | This script will run your Jest tests for the library and create a coverage report. | -| test | This script will run your Jest tests but with the `--watchAll` flag. It does not create a coverage report.| -
+## Versioning and build information -## Publish +This package will follow a semver-like format, `major.minor.patch`, in which: -This project can be published to the npm registry. To do so follow these steps: -1. Run `npm version ` to create a new version and commit + tag it. -2. Open a Merge Request on Github. -3. Once your changes have been commited to the main-branch, you can publish to the repo. -4. Run `npm publish`. +- `major`: Introduces new features or breaking changes +- `minor`: Introduces minor non-breaking changes +- `patch`: Introduces bugfixes -## Team +For more information about the build process, authors, contributions and issues, we refer to the [hyperdrive-opensource](https://github.com/studiohyperdrive/hyperdrive-opensource) repository. -This project has been created by: -- Denis Valcke: denis.valcke@studiohyperdrive.be +## Documentation -It is currently maintained by: -- Denis Valcke: denis.valcke@studiohyperdrive.be +To find more information regarding this package, we refer to [our documentation platform](https://open-source.studiohyperdrive.be/docs/angular/page/introduction). diff --git a/libs/javascript/pagination/package.json b/libs/javascript/pagination/package.json index 2bf2c098..cfa9e3d7 100644 --- a/libs/javascript/pagination/package.json +++ b/libs/javascript/pagination/package.json @@ -1,20 +1,20 @@ { "name": "@studiohyperdrive/nodejs-hal-tools", - "version": "1.2.0", + "version": "2.0.0", "description": "A NodeJs based approach to pagination based on the HAL standards.", "keywords": [ "pagination", "hal", "nodejs" ], - "homepage": "https://github.com/studiohyperdrive/ngx-tools/tree/master/libs/javascript/pagination", + "homepage": "https://open-source.studiohyperdrive.be/docs/javascript/pagination/introduction", "author": { "name": "Studio Hyperdrive", "url": "https://studiohyperdrive.be/" }, "repository": { "type": "git", - "url": "https://github.com/studiohyperdrive/ngx-tools", + "url": "https://github.com/studiohyperdrive/hyperdrive-opensource", "directory": "libs/javascript/pagination/src" }, "license": "MIT",