mielk-api 1.0.5 → 1.0.7

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.
@@ -1,8 +1,9 @@
1
1
  import { ApiStatus } from "../types/types.js";
2
- export declare const API_STATUS_CODES: {
2
+ export declare const API_STATUS: {
3
3
  OK: ApiStatus;
4
4
  CREATED: ApiStatus;
5
5
  BAD_REQUEST: ApiStatus;
6
+ UNAUTHORIZED: ApiStatus;
6
7
  NOT_FOUND: ApiStatus;
7
8
  CONFLICT: ApiStatus;
8
9
  SERVER_ERROR: ApiStatus;
@@ -1,11 +1,12 @@
1
- import { msgTag } from "mielk-fn/tags";
2
- import { Msg } from "../../internal/messaging/Msg.js";
1
+ import { Msg } from "../../internal/messaging/messageTags.js";
3
2
  const createApiStatus = (success, code, defaultMessageTag) => ({ success, code, defaultMessageTag });
4
- export const API_STATUS_CODES = {
5
- OK: createApiStatus(true, 200, msgTag(Msg.API_STATUS.OK)),
6
- CREATED: createApiStatus(true, 200, msgTag(Msg.API_STATUS.CREATED)),
7
- BAD_REQUEST: createApiStatus(false, 400, msgTag(Msg.API_STATUS.BAD_REQUEST)),
8
- NOT_FOUND: createApiStatus(false, 404, msgTag(Msg.API_STATUS.NOT_FOUND)),
9
- CONFLICT: createApiStatus(false, 409, msgTag(Msg.API_STATUS.CONFLICT)),
10
- SERVER_ERROR: createApiStatus(false, 500, msgTag(Msg.API_STATUS.SERVER_ERROR)),
3
+ const msg = Msg.ApiStatus;
4
+ export const API_STATUS = {
5
+ OK: createApiStatus(true, 200, msg.ok),
6
+ CREATED: createApiStatus(true, 201, msg.created),
7
+ BAD_REQUEST: createApiStatus(false, 400, msg.badRequest),
8
+ UNAUTHORIZED: createApiStatus(false, 401, msg.unauthorized),
9
+ NOT_FOUND: createApiStatus(false, 404, msg.notFound),
10
+ CONFLICT: createApiStatus(false, 409, msg.conflict),
11
+ SERVER_ERROR: createApiStatus(false, 500, msg.serverError),
11
12
  };
@@ -1,4 +1,4 @@
1
- export declare const PG_ERROR_CODES: {
1
+ export declare const PG_ERRORS: {
2
2
  UNIQUE_VIOLATION: string;
3
3
  FOREIGN_KEY_VIOLATION: string;
4
4
  };
@@ -1,4 +1,4 @@
1
- export const PG_ERROR_CODES = {
1
+ export const PG_ERRORS = {
2
2
  UNIQUE_VIOLATION: '23505',
3
3
  FOREIGN_KEY_VIOLATION: '23503',
4
4
  };
@@ -1,6 +1,6 @@
1
1
  import type { ApiStatus } from './types/types.js';
2
- import { PG_ERROR_CODES } from './enums/PostgreErrorCodes.js';
3
- import { API_STATUS_CODES } from './enums/ApiStatus.js';
2
+ import { PG_ERRORS } from './enums/PostgreErrorCodes.js';
3
+ import { API_STATUS } from './enums/ApiStatus.js';
4
4
  export type { ApiStatus };
5
- export { PG_ERROR_CODES };
6
- export { API_STATUS_CODES };
5
+ export { PG_ERRORS };
6
+ export { API_STATUS };
@@ -1,4 +1,4 @@
1
- import { PG_ERROR_CODES } from './enums/PostgreErrorCodes.js';
2
- import { API_STATUS_CODES } from './enums/ApiStatus.js';
3
- export { PG_ERROR_CODES };
4
- export { API_STATUS_CODES };
1
+ import { PG_ERRORS } from './enums/PostgreErrorCodes.js';
2
+ import { API_STATUS } from './enums/ApiStatus.js';
3
+ export { PG_ERRORS };
4
+ export { API_STATUS };
@@ -4,6 +4,10 @@ export interface ApiSuccess<T> {
4
4
  }
5
5
  export interface ApiError {
6
6
  success: false;
7
- error: string;
7
+ details: ApiErrorDetails;
8
8
  }
9
9
  export type ApiResponse<T> = ApiSuccess<T> | ApiError;
10
+ export type ApiErrorDetails = {
11
+ message: string;
12
+ params?: (string | number | Date | unknown | boolean)[];
13
+ };
@@ -0,0 +1,11 @@
1
+ export declare const Msg: {
2
+ ApiStatus: {
3
+ ok: string;
4
+ created: string;
5
+ unauthorized: string;
6
+ badRequest: string;
7
+ notFound: string;
8
+ conflict: string;
9
+ serverError: string;
10
+ };
11
+ };
@@ -0,0 +1,13 @@
1
+ const PARENT_FOLDER = 'api/';
2
+ const API_STATUS_FOLDER = `${PARENT_FOLDER}/ApiStatus`;
3
+ export const Msg = {
4
+ ApiStatus: {
5
+ ok: `${API_STATUS_FOLDER}:ok`,
6
+ created: `${API_STATUS_FOLDER}:created`,
7
+ unauthorized: `${API_STATUS_FOLDER}:unauthorized`,
8
+ badRequest: `${API_STATUS_FOLDER}:badRequest`,
9
+ notFound: `${API_STATUS_FOLDER}:notFound`,
10
+ conflict: `${API_STATUS_FOLDER}:conflict`,
11
+ serverError: `${API_STATUS_FOLDER}:serverError`,
12
+ }
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mielk-api",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "keywords": [],
5
5
  "author": "mielk",
6
6
  "description": "Wrapper for API operations",
@@ -56,6 +56,6 @@
56
56
  "dist"
57
57
  ],
58
58
  "dependencies": {
59
- "mielk-fn": "^1.1.0"
59
+ "mielk-fn": "^1.1.1"
60
60
  }
61
61
  }
@@ -1,10 +0,0 @@
1
- export declare const Msg: {
2
- API_STATUS: {
3
- OK: import("mielk-fn/tags").Tag;
4
- CREATED: import("mielk-fn/tags").Tag;
5
- BAD_REQUEST: import("mielk-fn/tags").Tag;
6
- NOT_FOUND: import("mielk-fn/tags").Tag;
7
- CONFLICT: import("mielk-fn/tags").Tag;
8
- SERVER_ERROR: import("mielk-fn/tags").Tag;
9
- };
10
- };
@@ -1,5 +0,0 @@
1
- import { ApiStatusMessageTags } from "./apiStatusTags.js";
2
- const prefix = 'Api';
3
- export const Msg = {
4
- API_STATUS: ApiStatusMessageTags(prefix),
5
- };
@@ -1,8 +0,0 @@
1
- export declare const ApiStatusMessageTags: (parentPrefix: string) => {
2
- OK: import("mielk-fn/tags").Tag;
3
- CREATED: import("mielk-fn/tags").Tag;
4
- BAD_REQUEST: import("mielk-fn/tags").Tag;
5
- NOT_FOUND: import("mielk-fn/tags").Tag;
6
- CONFLICT: import("mielk-fn/tags").Tag;
7
- SERVER_ERROR: import("mielk-fn/tags").Tag;
8
- };
@@ -1,10 +0,0 @@
1
- import { createTag } from 'mielk-fn/tags';
2
- const prefix = 'ApiStatus';
3
- export const ApiStatusMessageTags = (parentPrefix) => ({
4
- OK: createTag(parentPrefix, prefix, 'ok'),
5
- CREATED: createTag(parentPrefix, prefix, 'created'),
6
- BAD_REQUEST: createTag(parentPrefix, prefix, 'badRequest'),
7
- NOT_FOUND: createTag(parentPrefix, prefix, 'notFound'),
8
- CONFLICT: createTag(parentPrefix, prefix, 'conflict'),
9
- SERVER_ERROR: createTag(parentPrefix, prefix, 'serverError'),
10
- });