@kiwiproject/kiwi-js 0.7.0 → 0.8.0
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/dist/base/kiwi-preconditions.d.ts +1 -1
- package/dist/base/kiwi-preconditions.js +9 -5
- package/dist/express/kiwi-standard-responses-express.d.ts +12 -11
- package/dist/express/kiwi-standard-responses-express.js +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/model/error-message.js +2 -2
- package/dist/search/kiwi-page.js +1 -1
- package/dist/search/kiwi-sort.js +3 -3
- package/package.json +22 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const KiwiPreconditions: {
|
|
2
2
|
checkArgument: (expression: boolean, errorMessage?: string) => void;
|
|
3
|
-
checkArgumentDefined: (reference:
|
|
3
|
+
checkArgumentDefined: (reference: unknown, errorMessage?: string) => void;
|
|
4
4
|
checkArgumentNotBlank: (str: string, errorMessage?: string) => void;
|
|
5
5
|
checkState: (expression: boolean, errorMessage?: string) => void;
|
|
6
6
|
checkPositive: (value: number, errorMessage?: string) => void;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.KiwiPreconditions = void 0;
|
|
4
|
-
const checkPositiveOrZero = (value, errorMessage =
|
|
4
|
+
const checkPositiveOrZero = (value, errorMessage = "value must be positive or zero") => {
|
|
5
5
|
checkState(value >= 0, errorMessage);
|
|
6
6
|
};
|
|
7
7
|
const checkState = (expression, errorMessage = undefined) => {
|
|
8
8
|
if (!expression) {
|
|
9
|
-
const fullErrorMessage = errorMessage === undefined
|
|
9
|
+
const fullErrorMessage = errorMessage === undefined
|
|
10
|
+
? "IllegalStateException"
|
|
11
|
+
: `IllegalStateException: ${errorMessage}`;
|
|
10
12
|
throw new Error(fullErrorMessage);
|
|
11
13
|
}
|
|
12
14
|
};
|
|
13
|
-
const checkPositive = (value, errorMessage =
|
|
15
|
+
const checkPositive = (value, errorMessage = "value must be a positive number") => {
|
|
14
16
|
checkState(value > 0, errorMessage);
|
|
15
17
|
};
|
|
16
18
|
const checkArgumentDefined = (reference, errorMessage = undefined) => {
|
|
@@ -18,13 +20,15 @@ const checkArgumentDefined = (reference, errorMessage = undefined) => {
|
|
|
18
20
|
};
|
|
19
21
|
const checkArgument = (expression, errorMessage = undefined) => {
|
|
20
22
|
if (!expression) {
|
|
21
|
-
const fullErrorMessage = errorMessage === undefined
|
|
23
|
+
const fullErrorMessage = errorMessage === undefined
|
|
24
|
+
? "IllegalArgumentException"
|
|
25
|
+
: `IllegalArgumentException: ${errorMessage}`;
|
|
22
26
|
throw new Error(fullErrorMessage);
|
|
23
27
|
}
|
|
24
28
|
};
|
|
25
29
|
const checkArgumentNotBlank = (str, errorMessage = undefined) => {
|
|
26
30
|
checkArgumentDefined(str, errorMessage);
|
|
27
|
-
checkArgument(str !==
|
|
31
|
+
checkArgument(str !== "", errorMessage);
|
|
28
32
|
};
|
|
29
33
|
exports.KiwiPreconditions = {
|
|
30
34
|
checkArgument,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { Response } from "express";
|
|
1
2
|
export declare const KiwiStandardResponsesExpress: {
|
|
2
|
-
standardGetResponseWithIdentifier: (identifierField: string, identifier:
|
|
3
|
-
standardGetResponseWithMessage: (entity:
|
|
4
|
-
standardPostResponse: (location: string, entity:
|
|
5
|
-
standardPutResponse: (entity:
|
|
6
|
-
standardDeleteResponse: (res:
|
|
7
|
-
standardDeleteResponseWithEntity: (deletedEntity:
|
|
8
|
-
standardAcceptedResponse: (entity:
|
|
9
|
-
standardErrorResponse: (status: number, errorDetails: string, res:
|
|
10
|
-
standardUnauthorizedResponse: (errorDetails: string, res:
|
|
11
|
-
standardNotFoundResponse: (errorDetails: string, res:
|
|
12
|
-
standardBadRequestResponse: (errorDetails: string, res:
|
|
3
|
+
standardGetResponseWithIdentifier: (identifierField: string, identifier: unknown, entity: unknown, res: Response) => void;
|
|
4
|
+
standardGetResponseWithMessage: (entity: unknown, notFoundMessage: string, res: Response) => void;
|
|
5
|
+
standardPostResponse: (location: string, entity: unknown, res: Response) => void;
|
|
6
|
+
standardPutResponse: (entity: unknown, res: Response) => void;
|
|
7
|
+
standardDeleteResponse: (res: Response) => void;
|
|
8
|
+
standardDeleteResponseWithEntity: (deletedEntity: unknown, res: Response) => void;
|
|
9
|
+
standardAcceptedResponse: (entity: unknown, res: Response) => void;
|
|
10
|
+
standardErrorResponse: (status: number, errorDetails: string, res: Response) => void;
|
|
11
|
+
standardUnauthorizedResponse: (errorDetails: string, res: Response) => void;
|
|
12
|
+
standardNotFoundResponse: (errorDetails: string, res: Response) => void;
|
|
13
|
+
standardBadRequestResponse: (errorDetails: string, res: Response) => void;
|
|
13
14
|
};
|
|
@@ -51,7 +51,7 @@ const standardNotFoundResponse = (errorDetails, res) => {
|
|
|
51
51
|
* @param res the Express Response
|
|
52
52
|
*/
|
|
53
53
|
const standardPostResponse = (location, entity, res) => {
|
|
54
|
-
res.status(201).set(
|
|
54
|
+
res.status(201).set("Location", location).json(entity);
|
|
55
55
|
};
|
|
56
56
|
/**
|
|
57
57
|
* Returns a 200 OK response having the specified response entity.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { ErrorMessage } from
|
|
2
|
-
export { KiwiStandardResponsesExpress } from
|
|
3
|
-
export { KiwiPreconditions } from
|
|
4
|
-
export { KiwiPage } from
|
|
5
|
-
export { KiwiSort } from
|
|
1
|
+
export { ErrorMessage } from "./model/error-message";
|
|
2
|
+
export { KiwiStandardResponsesExpress } from "./express/kiwi-standard-responses-express";
|
|
3
|
+
export { KiwiPreconditions } from "./base/kiwi-preconditions";
|
|
4
|
+
export { KiwiPage } from "./search/kiwi-page";
|
|
5
|
+
export { KiwiSort } from "./search/kiwi-sort";
|
|
@@ -9,7 +9,7 @@ exports.ErrorMessage = void 0;
|
|
|
9
9
|
* field causes the error.
|
|
10
10
|
*/
|
|
11
11
|
class ErrorMessage {
|
|
12
|
-
constructor(code, message, fieldName =
|
|
12
|
+
constructor(code, message, fieldName = "", itemId = "") {
|
|
13
13
|
this.itemId = itemId;
|
|
14
14
|
this.code = code;
|
|
15
15
|
this.message = message;
|
|
@@ -20,7 +20,7 @@ class ErrorMessage {
|
|
|
20
20
|
message: this.message,
|
|
21
21
|
code: this.code,
|
|
22
22
|
fieldName: this.fieldName,
|
|
23
|
-
itemId: this.itemId
|
|
23
|
+
itemId: this.itemId,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
}
|
package/dist/search/kiwi-page.js
CHANGED
|
@@ -53,7 +53,7 @@ class KiwiPage {
|
|
|
53
53
|
}
|
|
54
54
|
isLast() {
|
|
55
55
|
const offset = 1 - this.pagingStartsWith;
|
|
56
|
-
return this.number ===
|
|
56
|
+
return this.number === this.totalPages - offset;
|
|
57
57
|
}
|
|
58
58
|
isSorted() {
|
|
59
59
|
return this.sort !== undefined && this.sort !== null;
|
package/dist/search/kiwi-sort.js
CHANGED
|
@@ -10,15 +10,15 @@ class KiwiSort {
|
|
|
10
10
|
this.ascending = ascending;
|
|
11
11
|
}
|
|
12
12
|
static ofAscending(property) {
|
|
13
|
-
return KiwiSort.of(property,
|
|
13
|
+
return KiwiSort.of(property, "ASC");
|
|
14
14
|
}
|
|
15
15
|
static ofDescending(property) {
|
|
16
|
-
return KiwiSort.of(property,
|
|
16
|
+
return KiwiSort.of(property, "DESC");
|
|
17
17
|
}
|
|
18
18
|
static of(property, direction) {
|
|
19
19
|
kiwi_preconditions_1.KiwiPreconditions.checkArgumentNotBlank(property);
|
|
20
20
|
kiwi_preconditions_1.KiwiPreconditions.checkArgumentNotBlank(direction);
|
|
21
|
-
return new KiwiSort(property, direction, false,
|
|
21
|
+
return new KiwiSort(property, direction, false, "ASC" === direction);
|
|
22
22
|
}
|
|
23
23
|
isDescending() {
|
|
24
24
|
return !this.ascending;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiwiproject/kiwi-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "KiwiJS is a utility library. It contains a variety of utilities that we have built over time and find useful. Most of these utilities are ports from the Java Kiwi library.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,20 +8,35 @@
|
|
|
8
8
|
"/dist"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
+
"format": "node node_modules/.bin/prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
|
|
12
|
+
"lint": "node node_modules/.bin/eslint --ext .js,.ts .",
|
|
11
13
|
"test": "node --experimental-vm-modules node_modules/.bin/jest --coverage --collectCoverageFrom=src/**/*.ts"
|
|
12
14
|
},
|
|
13
15
|
"jest": {
|
|
14
|
-
"testPathIgnorePatterns": [
|
|
16
|
+
"testPathIgnorePatterns": [
|
|
17
|
+
"<rootDir>/__tests__/__utils__",
|
|
18
|
+
"<rootDir>/node_modules/"
|
|
19
|
+
],
|
|
20
|
+
"coveragePathIgnorePatterns": [
|
|
21
|
+
"src/index.ts"
|
|
22
|
+
]
|
|
15
23
|
},
|
|
16
24
|
"dependencies": {
|
|
17
25
|
"express": "4.18.2"
|
|
18
26
|
},
|
|
19
27
|
"devDependencies": {
|
|
20
|
-
"@babel/core": "7.22.
|
|
21
|
-
"@babel/preset-env": "7.22.
|
|
28
|
+
"@babel/core": "7.22.10",
|
|
29
|
+
"@babel/preset-env": "7.22.10",
|
|
22
30
|
"@babel/preset-typescript": "7.22.5",
|
|
23
|
-
"@jest/globals": "29.6.
|
|
24
|
-
"
|
|
25
|
-
"
|
|
31
|
+
"@jest/globals": "29.6.2",
|
|
32
|
+
"@types/express": "4.17.17",
|
|
33
|
+
"@types/node": "20.5.0",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "6.4.0",
|
|
35
|
+
"@typescript-eslint/parser": "6.4.0",
|
|
36
|
+
"babel-jest": "29.6.2",
|
|
37
|
+
"eslint": "8.47.0",
|
|
38
|
+
"jest": "29.6.2",
|
|
39
|
+
"prettier": "3.0.1",
|
|
40
|
+
"typescript": "5.1.6"
|
|
26
41
|
}
|
|
27
42
|
}
|