@bejibun/core 0.1.35 → 0.1.37

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +38 -2
  2. package/README.md +14 -1
  3. package/bases/BaseController.js +1 -1
  4. package/bases/BaseModel.js +2 -2
  5. package/builders/ResponseBuilder.js +3 -3
  6. package/builders/RouterBuilder.d.ts +1 -1
  7. package/builders/RouterBuilder.js +2 -2
  8. package/bun.lock +9 -0
  9. package/exceptions/ModelNotFoundException.js +1 -1
  10. package/exceptions/RouterInvalidException.js +1 -1
  11. package/exceptions/ValidatorException.js +1 -1
  12. package/facades/Router.d.ts +1 -1
  13. package/facades/Router.js +3 -3
  14. package/facades/index.d.ts +0 -3
  15. package/facades/index.js +0 -3
  16. package/index.d.ts +0 -2
  17. package/index.js +0 -2
  18. package/package.json +4 -1
  19. package/src/bases/BaseController.ts +1 -1
  20. package/src/bases/BaseModel.ts +2 -2
  21. package/src/builders/ResponseBuilder.ts +3 -3
  22. package/src/builders/RouterBuilder.ts +3 -3
  23. package/src/exceptions/ModelNotFoundException.ts +1 -1
  24. package/src/exceptions/RouterInvalidException.ts +1 -1
  25. package/src/exceptions/ValidatorException.ts +1 -1
  26. package/src/facades/Router.ts +3 -3
  27. package/src/facades/index.ts +1 -4
  28. package/src/index.ts +1 -5
  29. package/src/utils/vines/exists.ts +1 -1
  30. package/src/utils/vines/unique.ts +1 -1
  31. package/utils/vines/exists.js +1 -1
  32. package/utils/vines/unique.js +1 -1
  33. package/builders/ChalkBuilder.d.ts +0 -14
  34. package/builders/ChalkBuilder.js +0 -51
  35. package/builders/EnumBuilder.d.ts +0 -11
  36. package/builders/EnumBuilder.js +0 -23
  37. package/builders/StrBuilder.d.ts +0 -6
  38. package/builders/StrBuilder.js +0 -19
  39. package/config/cors.d.ts +0 -2
  40. package/config/cors.js +0 -9
  41. package/enums/CorsHeaderEnum.d.ts +0 -8
  42. package/enums/CorsHeaderEnum.js +0 -9
  43. package/enums/HttpMethodEnum.d.ts +0 -12
  44. package/enums/HttpMethodEnum.js +0 -13
  45. package/enums/index.d.ts +0 -2
  46. package/enums/index.js +0 -2
  47. package/facades/Chalk.d.ts +0 -4
  48. package/facades/Chalk.js +0 -6
  49. package/facades/Enum.d.ts +0 -6
  50. package/facades/Enum.js +0 -6
  51. package/facades/Str.d.ts +0 -4
  52. package/facades/Str.js +0 -6
  53. package/src/builders/ChalkBuilder.ts +0 -60
  54. package/src/builders/EnumBuilder.ts +0 -32
  55. package/src/builders/StrBuilder.ts +0 -25
  56. package/src/config/cors.ts +0 -10
  57. package/src/enums/CorsHeaderEnum.ts +0 -9
  58. package/src/enums/HttpMethodEnum.ts +0 -13
  59. package/src/enums/index.ts +0 -2
  60. package/src/facades/Chalk.ts +0 -7
  61. package/src/facades/Enum.ts +0 -10
  62. package/src/facades/Str.ts +0 -7
  63. package/src/utils/utils.ts +0 -72
  64. package/utils/utils.d.ts +0 -5
  65. package/utils/utils.js +0 -60
package/CHANGELOG.md CHANGED
@@ -3,12 +3,48 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
+ ## [v0.1.36](https://github.com/crenata/bejibun-core/compare/v0.1.35...v0.1.36) - 2025-10-14
7
+
8
+ ### 🩹 Fixes
9
+
10
+ ### 📖 Changes
11
+ What's New :
12
+ - Include `@bejibun/logger` for default
13
+
14
+ Refactors :
15
+ - Move cors into `@bejibun/cors`
16
+ - Move utils and enums into `@bejibun/utils`
17
+
18
+ ### ❤️Contributors
19
+ - Havea Crenata ([@crenata](https://github.com/crenata))
20
+ - Ghulje ([@ghulje](https://github.com/ghulje))
21
+
22
+ **Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
23
+
24
+ ---
25
+
26
+ ## [v0.1.35](https://github.com/crenata/bejibun-core/compare/v0.1.23...v0.1.35) - 2025-10-14
27
+
28
+ ### 🩹 Fixes
29
+
30
+ ### 📖 Changes
31
+ What's New :
32
+ Update build indexing
33
+
34
+ ### ❤️Contributors
35
+ - Havea Crenata ([@crenata](https://github.com/crenata))
36
+ - Ghulje ([@ghulje](https://github.com/ghulje))
37
+
38
+ **Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
39
+
40
+ ---
41
+
6
42
  ## [v0.1.23](https://github.com/crenata/bejibun-core/compare/v0.1.18...v0.1.23) - 2025-10-14
7
43
 
8
44
  ### 🩹 Fixes
9
45
 
10
46
  ### 📖 Changes
11
- New Features :
47
+ What's New :
12
48
  - Base class (Controller, Model, Validator)
13
49
  - Bootstrap for startup load
14
50
  - Adding some utils (Chalk, Response, Router, Soft Deletes)
@@ -29,7 +65,7 @@ New Features :
29
65
  ### 🩹 Fixes
30
66
 
31
67
  ### 📖 Changes
32
- New Features :
68
+ What's New :
33
69
  - Enum helper
34
70
  - Str helper
35
71
  - Some util functions
package/README.md CHANGED
@@ -25,4 +25,17 @@ bun ace install @bejibun/core
25
25
  ```
26
26
 
27
27
  ## Contributors
28
- - [Havea Crenata](mailto:havea.crenata@gmail.com)
28
+ - [Havea Crenata](mailto:havea.crenata@gmail.com)
29
+
30
+ ## ☕ Support / Donate
31
+
32
+ If you find this project helpful and want to support it, you can donate via PayPal :
33
+
34
+ [![Donate with PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg?logo=paypal)](https://paypal.me/hafiizhghulam)
35
+
36
+ Or if you are prefer using crypto :
37
+
38
+ | EVM | Solana |
39
+ | --- | ------ |
40
+ | <img src="https://github.com/crenata/bejibun/blob/master/public/images/EVM.png?raw=true" width="150" /> | <img src="https://github.com/crenata/bejibun/blob/master/public/images/SOL.png?raw=true" width="150" /> |
41
+ | 0xdABe8750061410D35cE52EB2a418c8cB004788B3 | GAnoyvy9p3QFyxikWDh9hA3fmSk2uiPLNWyQ579cckMn |
@@ -1,7 +1,7 @@
1
+ import { defineValue, isEmpty, isNotEmpty } from "@bejibun/utils";
1
2
  import { DateTime } from "luxon";
2
3
  import ValidatorException from "../exceptions/ValidatorException";
3
4
  import Response from "../facades/Response";
4
- import { defineValue, isEmpty, isNotEmpty } from "../utils/utils";
5
5
  export default class BaseController {
6
6
  async parse(request) {
7
7
  const contentType = defineValue(request.headers.get("content-type"), "");
@@ -1,11 +1,11 @@
1
+ import { defineValue, isEmpty } from "@bejibun/utils";
2
+ import Str from "@bejibun/utils/facades/Str";
1
3
  import { DateTime } from "luxon";
2
4
  import { Model } from "objection";
3
5
  import { relative, sep } from "path";
4
6
  import { fileURLToPath } from "url";
5
7
  import ModelNotFoundException from "../exceptions/ModelNotFoundException";
6
8
  import SoftDeletes from "../facades/SoftDeletes";
7
- import Str from "../facades/Str";
8
- import { defineValue, isEmpty } from "../utils/utils";
9
9
  class BunQueryBuilder extends SoftDeletes {
10
10
  // @ts-ignore
11
11
  async update(payload) {
@@ -1,4 +1,4 @@
1
- import { cors } from "../utils/utils";
1
+ import Cors from "@bejibun/cors";
2
2
  export default class ResponseBuilder {
3
3
  data;
4
4
  message;
@@ -27,7 +27,7 @@ export default class ResponseBuilder {
27
27
  status: this.status
28
28
  }, {
29
29
  headers: {
30
- ...cors()
30
+ ...Cors.init
31
31
  },
32
32
  status: this.status
33
33
  });
@@ -36,7 +36,7 @@ export default class ResponseBuilder {
36
36
  return new globalThis.Response(Bun.file(this.data), {
37
37
  ...options,
38
38
  headers: {
39
- ...cors()
39
+ ...Cors.init
40
40
  },
41
41
  status: this.status
42
42
  });
@@ -1,6 +1,6 @@
1
+ import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
1
2
  import type { IMiddleware } from "../types/middleware";
2
3
  import type { HandlerType, ResourceAction, RouterGroup } from "../types/router";
3
- import HttpMethodEnum from "../enums/HttpMethodEnum";
4
4
  export interface ResourceOptions {
5
5
  only?: Array<ResourceAction>;
6
6
  except?: Array<ResourceAction>;
@@ -1,6 +1,6 @@
1
- import RouterInvalidException from "../exceptions/RouterInvalidException";
2
- import { isEmpty } from "../utils/utils";
1
+ import { isEmpty } from "@bejibun/utils";
3
2
  import path from "path";
3
+ import RouterInvalidException from "../exceptions/RouterInvalidException";
4
4
  export default class RouterBuilder {
5
5
  basePath = "";
6
6
  middlewares = [];
package/bun.lock CHANGED
@@ -4,6 +4,9 @@
4
4
  "": {
5
5
  "name": "@bejibun/core",
6
6
  "dependencies": {
7
+ "@bejibun/cors": "^0.1.0",
8
+ "@bejibun/logger": "^0.1.13",
9
+ "@bejibun/utils": "^0.1.0",
7
10
  "@vinejs/vine": "^3.0.1",
8
11
  "chalk": "^5.6.2",
9
12
  "knex": "^3.1.0",
@@ -19,6 +22,12 @@
19
22
  },
20
23
  },
21
24
  "packages": {
25
+ "@bejibun/cors": ["@bejibun/cors@0.1.0", "", { "dependencies": { "@bejibun/utils": "^0.1.0" } }, "sha512-tyUraDQkhxjbKPBgo+QnY9ry7t+sJ9j4v8Fwe4kPk++S1P2LpKDBw/5XlBtN/jgHbrfSz1Dor7ENeJsUAuMlYQ=="],
26
+
27
+ "@bejibun/logger": ["@bejibun/logger@0.1.13", "", { "dependencies": { "@bejibun/utils": "^0.1.0", "chalk": "^5.6.2", "luxon": "^3.7.2" } }, "sha512-Vq17rFd10P/jtUdUHVNOP+cdHnMjobgw5t4rQ4iF/vPtS/qtyvBJN6rkmpL+4mtAquVYOdJCycZtk7cSdXhpGw=="],
28
+
29
+ "@bejibun/utils": ["@bejibun/utils@0.1.0", "", {}, "sha512-zH9Sxo1C+y8rzLTf5/t78HfDYp8C34d+gsEzbo98OKKwI9so37ljdz2LDlXxDinp3lDBi9r/l/EmkNLECfP10g=="],
30
+
22
31
  "@nodelib/fs.scandir": ["@nodelib/fs.scandir@2.1.5", "", { "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" } }, "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g=="],
23
32
 
24
33
  "@nodelib/fs.stat": ["@nodelib/fs.stat@2.0.5", "", {}, "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A=="],
@@ -1,4 +1,4 @@
1
- import { defineValue } from "../utils/utils";
1
+ import { defineValue } from "@bejibun/utils";
2
2
  export default class ModelNotFoundException extends Error {
3
3
  code;
4
4
  constructor(message, code) {
@@ -1,4 +1,4 @@
1
- import { defineValue } from "../utils/utils";
1
+ import { defineValue } from "@bejibun/utils";
2
2
  export default class RouterInvalidException extends Error {
3
3
  code;
4
4
  constructor(message, code) {
@@ -1,4 +1,4 @@
1
- import { defineValue } from "../utils/utils";
1
+ import { defineValue } from "@bejibun/utils";
2
2
  export default class ValidatorException extends Error {
3
3
  code;
4
4
  constructor(message, code) {
@@ -1,7 +1,7 @@
1
1
  import type { IMiddleware } from "../types/middleware";
2
2
  import type { HandlerType, RouterGroup } from "../types/router";
3
+ import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
3
4
  import RouterBuilder, { ResourceOptions } from "../builders/RouterBuilder";
4
- import HttpMethodEnum from "../enums/HttpMethodEnum";
5
5
  export default class Router {
6
6
  static prefix(basePath: string): RouterBuilder;
7
7
  static middleware(...middlewares: Array<IMiddleware>): RouterBuilder;
package/facades/Router.js CHANGED
@@ -1,7 +1,7 @@
1
+ import { isEmpty } from "@bejibun/utils";
2
+ import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
3
+ import Enum from "@bejibun/utils/facades/Enum";
1
4
  import RouterBuilder from "../builders/RouterBuilder";
2
- import HttpMethodEnum from "../enums/HttpMethodEnum";
3
- import Enum from "../facades/Enum";
4
- import { isEmpty } from "../utils/utils";
5
5
  export default class Router {
6
6
  static prefix(basePath) {
7
7
  return new RouterBuilder().prefix(basePath);
@@ -1,6 +1,3 @@
1
- export * from "../facades/Chalk";
2
- export * from "../facades/Enum";
3
1
  export * from "../facades/Response";
4
2
  export * from "../facades/Router";
5
3
  export * from "../facades/SoftDeletes";
6
- export * from "../facades/Str";
package/facades/index.js CHANGED
@@ -1,6 +1,3 @@
1
- export * from "../facades/Chalk";
2
- export * from "../facades/Enum";
3
1
  export * from "../facades/Response";
4
2
  export * from "../facades/Router";
5
3
  export * from "../facades/SoftDeletes";
6
- export * from "../facades/Str";
package/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  export * from "./bases/index";
2
- export * from "./enums/index";
3
2
  export * from "./exceptions/index";
4
3
  export * from "./facades/index";
5
- export * from "./utils/utils";
package/index.js CHANGED
@@ -1,5 +1,3 @@
1
1
  export * from "./bases/index";
2
- export * from "./enums/index";
3
2
  export * from "./exceptions/index";
4
3
  export * from "./facades/index";
5
- export * from "./utils/utils";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/core",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "author": "Havea Crenata <havea.crenata@gmail.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,6 +9,9 @@
9
9
  "main": "index.js",
10
10
  "module": "index.js",
11
11
  "dependencies": {
12
+ "@bejibun/cors": "^0.1.0",
13
+ "@bejibun/logger": "^0.1.13",
14
+ "@bejibun/utils": "^0.1.0",
12
15
  "@vinejs/vine": "^3.0.1",
13
16
  "chalk": "^5.6.2",
14
17
  "knex": "^3.1.0",
@@ -1,9 +1,9 @@
1
+ import {defineValue, isEmpty, isNotEmpty} from "@bejibun/utils";
1
2
  import {errors, VineValidator} from "@vinejs/vine";
2
3
  import {BunRequest} from "bun";
3
4
  import {DateTime} from "luxon";
4
5
  import ValidatorException from "@/exceptions/ValidatorException";
5
6
  import Response from "@/facades/Response";
6
- import {defineValue, isEmpty, isNotEmpty} from "@/utils/utils";
7
7
 
8
8
  export default class BaseController {
9
9
  public async parse(request: BunRequest): Promise<Record<string, any>> {
@@ -1,3 +1,5 @@
1
+ import {defineValue, isEmpty} from "@bejibun/utils";
2
+ import Str from "@bejibun/utils/facades/Str";
1
3
  import {DateTime} from "luxon";
2
4
  import {
3
5
  Constructor,
@@ -13,8 +15,6 @@ import {relative, sep} from "path";
13
15
  import {fileURLToPath} from "url";
14
16
  import ModelNotFoundException from "@/exceptions/ModelNotFoundException";
15
17
  import SoftDeletes from "@/facades/SoftDeletes";
16
- import Str from "@/facades/Str";
17
- import {defineValue, isEmpty} from "@/utils/utils";
18
18
 
19
19
  export interface BaseColumns {
20
20
  id: bigint | number;
@@ -1,4 +1,4 @@
1
- import {cors} from "@/utils/utils";
1
+ import Cors from "@bejibun/cors";
2
2
 
3
3
  export default class ResponseBuilder {
4
4
  protected data?: any;
@@ -36,7 +36,7 @@ export default class ResponseBuilder {
36
36
  status: this.status
37
37
  }, {
38
38
  headers: {
39
- ...cors()
39
+ ...Cors.init
40
40
  },
41
41
  status: this.status
42
42
  });
@@ -46,7 +46,7 @@ export default class ResponseBuilder {
46
46
  return new globalThis.Response(Bun.file(this.data), {
47
47
  ...options,
48
48
  headers: {
49
- ...cors()
49
+ ...Cors.init
50
50
  },
51
51
  status: this.status
52
52
  });
@@ -1,9 +1,9 @@
1
+ import {isEmpty} from "@bejibun/utils";
2
+ import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
3
+ import path from "path";
1
4
  import type {IMiddleware} from "@/types/middleware";
2
5
  import type {HandlerType, ResourceAction, RouterGroup} from "@/types/router";
3
- import HttpMethodEnum from "@/enums/HttpMethodEnum";
4
6
  import RouterInvalidException from "@/exceptions/RouterInvalidException";
5
- import {isEmpty} from "@/utils/utils";
6
- import path from "path";
7
7
 
8
8
  export interface ResourceOptions {
9
9
  only?: Array<ResourceAction>;
@@ -1,4 +1,4 @@
1
- import {defineValue} from "@/utils/utils";
1
+ import {defineValue} from "@bejibun/utils";
2
2
 
3
3
  export default class ModelNotFoundException extends Error {
4
4
  public code: number;
@@ -1,4 +1,4 @@
1
- import {defineValue} from "@/utils/utils";
1
+ import {defineValue} from "@bejibun/utils";
2
2
 
3
3
  export default class RouterInvalidException extends Error {
4
4
  public code: number;
@@ -1,4 +1,4 @@
1
- import {defineValue} from "@/utils/utils";
1
+ import {defineValue} from "@bejibun/utils";
2
2
 
3
3
  export default class ValidatorException extends Error {
4
4
  public code: number;
@@ -1,9 +1,9 @@
1
1
  import type {IMiddleware} from "@/types/middleware";
2
2
  import type {HandlerType, RouterGroup} from "@/types/router";
3
+ import {isEmpty} from "@bejibun/utils";
4
+ import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
5
+ import Enum from "@bejibun/utils/facades/Enum";
3
6
  import RouterBuilder, {ResourceOptions} from "@/builders/RouterBuilder";
4
- import HttpMethodEnum from "@/enums/HttpMethodEnum";
5
- import Enum from "@/facades/Enum";
6
- import {isEmpty} from "@/utils/utils";
7
7
 
8
8
  export default class Router {
9
9
  public static prefix(basePath: string): RouterBuilder {
@@ -1,6 +1,3 @@
1
- export * from "@/facades/Chalk";
2
- export * from "@/facades/Enum";
3
1
  export * from "@/facades/Response";
4
2
  export * from "@/facades/Router";
5
- export * from "@/facades/SoftDeletes";
6
- export * from "@/facades/Str";
3
+ export * from "@/facades/SoftDeletes";
package/src/index.ts CHANGED
@@ -1,9 +1,5 @@
1
1
  export * from "@/bases/index";
2
2
 
3
- export * from "@/enums/index";
4
-
5
3
  export * from "@/exceptions/index";
6
4
 
7
- export * from "@/facades/index";
8
-
9
- export * from "@/utils/utils";
5
+ export * from "@/facades/index";
@@ -1,7 +1,7 @@
1
+ import {defineValue, isEmpty} from "@bejibun/utils";
1
2
  import vine, {VineNumber, VineString} from "@vinejs/vine";
2
3
  import {QueryBuilderType} from "objection";
3
4
  import BaseModel from "@/bases/BaseModel";
4
- import {defineValue, isEmpty} from "@/utils/utils";
5
5
 
6
6
  type Options = {
7
7
  table: typeof BaseModel;
@@ -1,7 +1,7 @@
1
+ import {defineValue, isNotEmpty} from "@bejibun/utils";
1
2
  import vine, {VineNumber, VineString} from "@vinejs/vine";
2
3
  import {QueryBuilderType} from "objection";
3
4
  import BaseModel from "@/bases/BaseModel";
4
- import {defineValue, isNotEmpty} from "@/utils/utils";
5
5
 
6
6
  type Options = {
7
7
  table: typeof BaseModel;
@@ -1,6 +1,6 @@
1
+ import { defineValue, isEmpty } from "@bejibun/utils";
1
2
  import vine, { VineNumber, VineString } from "@vinejs/vine";
2
3
  import BaseModel from "../../bases/BaseModel";
3
- import { defineValue, isEmpty } from "../../utils/utils";
4
4
  const exists = async (value, options, field) => {
5
5
  if (!field.isValid)
6
6
  return;
@@ -1,6 +1,6 @@
1
+ import { defineValue, isNotEmpty } from "@bejibun/utils";
1
2
  import vine, { VineNumber, VineString } from "@vinejs/vine";
2
3
  import BaseModel from "../../bases/BaseModel";
3
- import { defineValue, isNotEmpty } from "../../utils/utils";
4
4
  const unique = async (value, options, field) => {
5
5
  if (!field.isValid)
6
6
  return;
@@ -1,14 +0,0 @@
1
- export default class ChalkBuilder {
2
- protected value: string;
3
- protected isNewLine: boolean;
4
- protected clk: any;
5
- constructor();
6
- setValue(value: string): ChalkBuilder;
7
- inline(): ChalkBuilder;
8
- bold(): ChalkBuilder;
9
- danger(): ChalkBuilder;
10
- info(): ChalkBuilder;
11
- line(): void;
12
- show(): string;
13
- private get _value();
14
- }
@@ -1,51 +0,0 @@
1
- import chalk from "chalk";
2
- import os from "os";
3
- export default class ChalkBuilder {
4
- value;
5
- isNewLine;
6
- clk;
7
- constructor() {
8
- this.value = "";
9
- this.isNewLine = true;
10
- }
11
- setValue(value) {
12
- this.value = value;
13
- return this;
14
- }
15
- inline() {
16
- this.isNewLine = false;
17
- return this;
18
- }
19
- bold() {
20
- if (this.clk)
21
- this.clk = this.clk.bold;
22
- else
23
- this.clk = chalk.bold;
24
- return this;
25
- }
26
- danger() {
27
- if (this.clk)
28
- this.clk = this.clk.red;
29
- else
30
- this.clk = chalk.red;
31
- return this;
32
- }
33
- info() {
34
- if (this.clk)
35
- this.clk = this.clk.hex("#0CCAF0");
36
- else
37
- this.clk = chalk.hex("#0CCAF0");
38
- return this;
39
- }
40
- line() {
41
- console.log("-".repeat(process.stdout.columns));
42
- }
43
- show() {
44
- return this.clk(this._value);
45
- }
46
- get _value() {
47
- if (this.isNewLine)
48
- return `${this.value}${os.EOL}`;
49
- return this.value;
50
- }
51
- }
@@ -1,11 +0,0 @@
1
- export type EnumItem = {
2
- name: string;
3
- value: number;
4
- };
5
- export default class EnumBuilder {
6
- protected enums: any;
7
- constructor(enums: any);
8
- getName(value: number): string | undefined;
9
- getValue(key: string): number;
10
- toArray(): Array<any>;
11
- }
@@ -1,23 +0,0 @@
1
- import { isEmpty } from "../utils/utils";
2
- export default class EnumBuilder {
3
- enums;
4
- constructor(enums) {
5
- if (isEmpty(enums))
6
- throw new Error("The enum parameter is required.");
7
- this.enums = enums;
8
- }
9
- getName(value) {
10
- return Object.keys(this.enums).find(item => this.enums[item] === value);
11
- }
12
- getValue(key) {
13
- return this.enums[key];
14
- }
15
- toArray() {
16
- return Object.keys(this.enums)
17
- .filter(key => isNaN(Number(key)))
18
- .map(key => ({
19
- name: key,
20
- value: this.getValue(key)
21
- }));
22
- }
23
- }
@@ -1,6 +0,0 @@
1
- export default class StrBuilder {
2
- protected value: string;
3
- constructor();
4
- setValue(value: string): StrBuilder;
5
- toPascalCase(combine?: boolean): StrBuilder | string;
6
- }
@@ -1,19 +0,0 @@
1
- import { defineValue, isNotEmpty } from "../utils/utils";
2
- export default class StrBuilder {
3
- value;
4
- constructor() {
5
- this.value = "";
6
- }
7
- setValue(value) {
8
- this.value = value;
9
- return this;
10
- }
11
- toPascalCase(combine) {
12
- this.value = defineValue(this.value.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g), [])
13
- .map((x) => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
14
- .join("");
15
- if (isNotEmpty(combine))
16
- return this;
17
- return this.value;
18
- }
19
- }
package/config/cors.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const config: Record<string, any>;
2
- export default config;
package/config/cors.js DELETED
@@ -1,9 +0,0 @@
1
- const config = {
2
- allowedHeaders: "*",
3
- credentials: false,
4
- exposedHeaders: [],
5
- maxAge: 86400,
6
- methods: "*",
7
- origin: "*"
8
- };
9
- export default config;
@@ -1,8 +0,0 @@
1
- declare enum CorsHeaderEnum {
2
- Accept = "Accept",
3
- Authorization = "Authorization",
4
- ContentType = "Content-Type",
5
- Origin = "Origin",
6
- XRequestedWith = "X-Requested-With"
7
- }
8
- export default CorsHeaderEnum;
@@ -1,9 +0,0 @@
1
- var CorsHeaderEnum;
2
- (function (CorsHeaderEnum) {
3
- CorsHeaderEnum["Accept"] = "Accept";
4
- CorsHeaderEnum["Authorization"] = "Authorization";
5
- CorsHeaderEnum["ContentType"] = "Content-Type";
6
- CorsHeaderEnum["Origin"] = "Origin";
7
- CorsHeaderEnum["XRequestedWith"] = "X-Requested-With";
8
- })(CorsHeaderEnum || (CorsHeaderEnum = {}));
9
- export default CorsHeaderEnum;
@@ -1,12 +0,0 @@
1
- declare enum HttpMethodEnum {
2
- Connect = "CONNECT",
3
- Delete = "DELETE",
4
- Get = "GET",
5
- Head = "HEAD",
6
- Options = "OPTIONS",
7
- Patch = "PATCH",
8
- Post = "POST",
9
- Put = "PUT",
10
- Trace = "TRACE"
11
- }
12
- export default HttpMethodEnum;
@@ -1,13 +0,0 @@
1
- var HttpMethodEnum;
2
- (function (HttpMethodEnum) {
3
- HttpMethodEnum["Connect"] = "CONNECT";
4
- HttpMethodEnum["Delete"] = "DELETE";
5
- HttpMethodEnum["Get"] = "GET";
6
- HttpMethodEnum["Head"] = "HEAD";
7
- HttpMethodEnum["Options"] = "OPTIONS";
8
- HttpMethodEnum["Patch"] = "PATCH";
9
- HttpMethodEnum["Post"] = "POST";
10
- HttpMethodEnum["Put"] = "PUT";
11
- HttpMethodEnum["Trace"] = "TRACE";
12
- })(HttpMethodEnum || (HttpMethodEnum = {}));
13
- export default HttpMethodEnum;
package/enums/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "../enums/CorsHeaderEnum";
2
- export * from "../enums/HttpMethodEnum";
package/enums/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "../enums/CorsHeaderEnum";
2
- export * from "../enums/HttpMethodEnum";
@@ -1,4 +0,0 @@
1
- import ChalkBuilder from "../builders/ChalkBuilder";
2
- export default class Chalk {
3
- static setValue(value: string): ChalkBuilder;
4
- }
package/facades/Chalk.js DELETED
@@ -1,6 +0,0 @@
1
- import ChalkBuilder from "../builders/ChalkBuilder";
2
- export default class Chalk {
3
- static setValue(value) {
4
- return new ChalkBuilder().setValue(value);
5
- }
6
- }
package/facades/Enum.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import EnumBuilder from "../builders/EnumBuilder";
2
- import type { EnumItem } from "../builders/EnumBuilder";
3
- export type { EnumItem };
4
- export default class Enum {
5
- static setEnums(enums: any): EnumBuilder;
6
- }
package/facades/Enum.js DELETED
@@ -1,6 +0,0 @@
1
- import EnumBuilder from "../builders/EnumBuilder";
2
- export default class Enum {
3
- static setEnums(enums) {
4
- return new EnumBuilder(enums);
5
- }
6
- }
package/facades/Str.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import StrBuilder from "../builders/StrBuilder";
2
- export default class Str {
3
- static toPascalCase(value: string, combine?: boolean): StrBuilder | string;
4
- }
package/facades/Str.js DELETED
@@ -1,6 +0,0 @@
1
- import StrBuilder from "../builders/StrBuilder";
2
- export default class Str {
3
- static toPascalCase(value, combine) {
4
- return new StrBuilder().setValue(value).toPascalCase(combine);
5
- }
6
- }
@@ -1,60 +0,0 @@
1
- import chalk from "chalk";
2
- import os from "os";
3
-
4
- export default class ChalkBuilder {
5
- protected value: string;
6
- protected isNewLine: boolean;
7
- protected clk: any;
8
-
9
- public constructor() {
10
- this.value = "";
11
- this.isNewLine = true;
12
- }
13
-
14
- public setValue(value: string): ChalkBuilder {
15
- this.value = value;
16
-
17
- return this;
18
- }
19
-
20
- public inline(): ChalkBuilder {
21
- this.isNewLine = false;
22
-
23
- return this;
24
- }
25
-
26
- public bold(): ChalkBuilder {
27
- if (this.clk) this.clk = this.clk.bold;
28
- else this.clk = chalk.bold;
29
-
30
- return this;
31
- }
32
-
33
- public danger(): ChalkBuilder {
34
- if (this.clk) this.clk = this.clk.red;
35
- else this.clk = chalk.red;
36
-
37
- return this;
38
- }
39
-
40
- public info(): ChalkBuilder {
41
- if (this.clk) this.clk = this.clk.hex("#0CCAF0");
42
- else this.clk = chalk.hex("#0CCAF0");
43
-
44
- return this;
45
- }
46
-
47
- public line(): void {
48
- console.log("-".repeat(process.stdout.columns));
49
- }
50
-
51
- public show(): string {
52
- return this.clk(this._value);
53
- }
54
-
55
- private get _value(): string {
56
- if (this.isNewLine) return `${this.value}${os.EOL}`;
57
-
58
- return this.value;
59
- }
60
- }
@@ -1,32 +0,0 @@
1
- import {isEmpty} from "@/utils/utils";
2
-
3
- export type EnumItem = {
4
- name: string;
5
- value: number;
6
- }
7
-
8
- export default class EnumBuilder {
9
- protected enums: any;
10
-
11
- public constructor(enums: any) {
12
- if (isEmpty(enums)) throw new Error("The enum parameter is required.");
13
- this.enums = enums;
14
- }
15
-
16
- public getName(value: number): string | undefined {
17
- return Object.keys(this.enums).find(item => this.enums[item] === value);
18
- }
19
-
20
- public getValue(key: string): number {
21
- return this.enums[key];
22
- }
23
-
24
- public toArray(): Array<any> {
25
- return Object.keys(this.enums)
26
- .filter(key => isNaN(Number(key)))
27
- .map(key => ({
28
- name: key,
29
- value: this.getValue(key)
30
- }));
31
- }
32
- }
@@ -1,25 +0,0 @@
1
- import {defineValue, isNotEmpty} from "@/utils/utils";
2
-
3
- export default class StrBuilder {
4
- protected value: string;
5
-
6
- public constructor() {
7
- this.value = "";
8
- }
9
-
10
- public setValue(value: string): StrBuilder {
11
- this.value = value;
12
-
13
- return this;
14
- }
15
-
16
- public toPascalCase(combine?: boolean): StrBuilder | string {
17
- this.value = defineValue(this.value.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g), [])
18
- .map((x: string) => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
19
- .join("");
20
-
21
- if (isNotEmpty(combine)) return this;
22
-
23
- return this.value;
24
- }
25
- }
@@ -1,10 +0,0 @@
1
- const config: Record<string, any> = {
2
- allowedHeaders: "*",
3
- credentials: false,
4
- exposedHeaders: [],
5
- maxAge: 86400,
6
- methods: "*",
7
- origin: "*"
8
- };
9
-
10
- export default config;
@@ -1,9 +0,0 @@
1
- enum CorsHeaderEnum {
2
- Accept = "Accept",
3
- Authorization = "Authorization",
4
- ContentType = "Content-Type",
5
- Origin = "Origin",
6
- XRequestedWith = "X-Requested-With"
7
- }
8
-
9
- export default CorsHeaderEnum;
@@ -1,13 +0,0 @@
1
- enum HttpMethodEnum {
2
- Connect = "CONNECT",
3
- Delete = "DELETE",
4
- Get = "GET",
5
- Head = "HEAD",
6
- Options = "OPTIONS",
7
- Patch = "PATCH",
8
- Post = "POST",
9
- Put = "PUT",
10
- Trace = "TRACE"
11
- }
12
-
13
- export default HttpMethodEnum;
@@ -1,2 +0,0 @@
1
- export * from "@/enums/CorsHeaderEnum";
2
- export * from "@/enums/HttpMethodEnum";
@@ -1,7 +0,0 @@
1
- import ChalkBuilder from "@/builders/ChalkBuilder";
2
-
3
- export default class Chalk {
4
- public static setValue(value: string): ChalkBuilder {
5
- return new ChalkBuilder().setValue(value);
6
- }
7
- }
@@ -1,10 +0,0 @@
1
- import EnumBuilder from "@/builders/EnumBuilder";
2
- import type {EnumItem} from "@/builders/EnumBuilder";
3
-
4
- export type {EnumItem};
5
-
6
- export default class Enum {
7
- public static setEnums(enums: any): EnumBuilder {
8
- return new EnumBuilder(enums);
9
- }
10
- }
@@ -1,7 +0,0 @@
1
- import StrBuilder from "@/builders/StrBuilder";
2
-
3
- export default class Str {
4
- public static toPascalCase(value: string, combine?: boolean): StrBuilder | string {
5
- return new StrBuilder().setValue(value).toPascalCase(combine);
6
- }
7
- }
@@ -1,72 +0,0 @@
1
- import type {EnumItem} from "@/facades/Enum";
2
- import fs from "fs";
3
- import path from "path";
4
- import readline from "readline";
5
- import CorsHeaderEnum from "@/enums/CorsHeaderEnum";
6
- import HttpMethodEnum from "@/enums/HttpMethodEnum";
7
- import Enum from "@/facades/Enum";
8
-
9
- export const isEmpty = (value: any): boolean => {
10
- return (
11
- value === undefined ||
12
- value === null ||
13
- value === false ||
14
- value === 0 ||
15
- value === 0n ||
16
- (typeof value === "string" && value.trim() === "") ||
17
- (Array.isArray(value) && value.length === 0) ||
18
- (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0)
19
- );
20
- };
21
-
22
- export const isNotEmpty = (value: any): boolean => {
23
- return !isEmpty(value);
24
- };
25
-
26
- export const defineValue = (value: any, defaultValue: any = null): any => {
27
- if (isNotEmpty(value)) return value;
28
-
29
- return defaultValue;
30
- };
31
-
32
- export const ask = (question: string): Promise<string> => {
33
- const rl = readline.createInterface({
34
- input: process.stdin,
35
- output: process.stdout
36
- });
37
-
38
- return new Promise(resolve => {
39
- return rl.question(question, (answer: string) => {
40
- rl.close();
41
-
42
- resolve(answer.trim());
43
- });
44
- });
45
- };
46
-
47
- export const cors = (): Record<string, string> => {
48
- const configPath = path.resolve(process.cwd(), "config/cors.ts");
49
-
50
- let corsConfig: any;
51
-
52
- if (fs.existsSync(configPath)) corsConfig = require(configPath).default;
53
- else corsConfig = require("@/config/cors").default;
54
-
55
- const headers: Record<string, string> = {
56
- "Access-Control-Allow-Origin": corsConfig.origin,
57
- "Access-Control-Allow-Headers": Array.isArray(corsConfig.allowedHeaders)
58
- ? corsConfig.allowedHeaders.join(", ")
59
- : Enum.setEnums(CorsHeaderEnum).toArray().map((value: EnumItem) => value.value).join(", "),
60
- "Access-Control-Allow-Methods": Array.isArray(corsConfig.methods)
61
- ? corsConfig.methods.join(", ")
62
- : Enum.setEnums(HttpMethodEnum).toArray().map((value: EnumItem) => value.value).join(", ")
63
- };
64
-
65
- if (corsConfig.exposedHeaders.length > 0) headers["Access-Control-Expose-Headers"] = corsConfig.exposedHeaders.join(", ");
66
-
67
- if (corsConfig.credentials) headers["Access-Control-Allow-Credentials"] = "true";
68
-
69
- if (corsConfig.maxAge) headers["Access-Control-Max-Age"] = corsConfig.maxAge.toString();
70
-
71
- return headers;
72
- };
package/utils/utils.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export declare const isEmpty: (value: any) => boolean;
2
- export declare const isNotEmpty: (value: any) => boolean;
3
- export declare const defineValue: (value: any, defaultValue?: any) => any;
4
- export declare const ask: (question: string) => Promise<string>;
5
- export declare const cors: () => Record<string, string>;
package/utils/utils.js DELETED
@@ -1,60 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import readline from "readline";
4
- import CorsHeaderEnum from "../enums/CorsHeaderEnum";
5
- import HttpMethodEnum from "../enums/HttpMethodEnum";
6
- import Enum from "../facades/Enum";
7
- export const isEmpty = (value) => {
8
- return (value === undefined ||
9
- value === null ||
10
- value === false ||
11
- value === 0 ||
12
- value === 0n ||
13
- (typeof value === "string" && value.trim() === "") ||
14
- (Array.isArray(value) && value.length === 0) ||
15
- (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0));
16
- };
17
- export const isNotEmpty = (value) => {
18
- return !isEmpty(value);
19
- };
20
- export const defineValue = (value, defaultValue = null) => {
21
- if (isNotEmpty(value))
22
- return value;
23
- return defaultValue;
24
- };
25
- export const ask = (question) => {
26
- const rl = readline.createInterface({
27
- input: process.stdin,
28
- output: process.stdout
29
- });
30
- return new Promise(resolve => {
31
- return rl.question(question, (answer) => {
32
- rl.close();
33
- resolve(answer.trim());
34
- });
35
- });
36
- };
37
- export const cors = () => {
38
- const configPath = path.resolve(process.cwd(), "config/cors.ts");
39
- let corsConfig;
40
- if (fs.existsSync(configPath))
41
- corsConfig = require(configPath).default;
42
- else
43
- corsConfig = require("../config/cors").default;
44
- const headers = {
45
- "Access-Control-Allow-Origin": corsConfig.origin,
46
- "Access-Control-Allow-Headers": Array.isArray(corsConfig.allowedHeaders)
47
- ? corsConfig.allowedHeaders.join(", ")
48
- : Enum.setEnums(CorsHeaderEnum).toArray().map((value) => value.value).join(", "),
49
- "Access-Control-Allow-Methods": Array.isArray(corsConfig.methods)
50
- ? corsConfig.methods.join(", ")
51
- : Enum.setEnums(HttpMethodEnum).toArray().map((value) => value.value).join(", ")
52
- };
53
- if (corsConfig.exposedHeaders.length > 0)
54
- headers["Access-Control-Expose-Headers"] = corsConfig.exposedHeaders.join(", ");
55
- if (corsConfig.credentials)
56
- headers["Access-Control-Allow-Credentials"] = "true";
57
- if (corsConfig.maxAge)
58
- headers["Access-Control-Max-Age"] = corsConfig.maxAge.toString();
59
- return headers;
60
- };