@bool-ts/core 1.7.5 → 1.7.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.
@@ -58,13 +58,13 @@ export class TestController {
58
58
  console.log("testInject", testInject);
59
59
  }
60
60
 
61
- @Get("abc/:id")
61
+ @Get("abc/:id.xml")
62
62
  public get(@Param("id") id: string) {
63
63
  console.log("HEHE", id, typeof id);
64
64
  console.log("this.testService", this.testService.exec());
65
65
  }
66
66
 
67
- @Post("abc/:id/provider/:providerId")
67
+ @Post("abc/:id/provider/:providerId.xml")
68
68
  public async post(
69
69
  @RequestHeaders(headersSchema)
70
70
  headers: Zod.infer<typeof headersSchema>,
@@ -75,7 +75,7 @@ export class TestController {
75
75
  @RequestBody(bodySchema)
76
76
  body: Zod.infer<typeof bodySchema>
77
77
  ) {
78
- console.log("req.headers", headers);
78
+ console.log("req.headers", params);
79
79
  console.log("===========================");
80
80
  }
81
81
 
@@ -6,6 +6,7 @@ export type TRouteModel<T = unknown> = Readonly<{
6
6
  }>;
7
7
  export declare class Route {
8
8
  static rootPattern: string;
9
+ static innerRootPattern: string;
9
10
  readonly alias: string;
10
11
  private _map;
11
12
  constructor(alias: string);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  export class Route {
3
3
  static rootPattern = ":([a-z0-9A-Z_-]{1,})";
4
+ static innerRootPattern = "([a-z0-9A-Z_-]{1,})";
4
5
  alias;
5
6
  _map = new Map();
6
7
  constructor(alias) {
@@ -19,6 +20,10 @@ export class Route {
19
20
  return undefined;
20
21
  }
21
22
  const parameters = Object();
23
+ const matchingRegex = this.alias.replace(new RegExp(Route.rootPattern, "g"), Route.innerRootPattern);
24
+ if (!new RegExp(matchingRegex).test(this._thinAlias(pathname))) {
25
+ return undefined;
26
+ }
22
27
  for (let index = 0; index < aliasSplitted.length; index++) {
23
28
  const aliasPart = aliasSplitted[index];
24
29
  const pathnamePart = currentPathNameSplitted[index];
@@ -31,8 +36,13 @@ export class Route {
31
36
  let isFailed = false;
32
37
  aliasPart.replace(new RegExp(Route.rootPattern, "g"), (match, key, offset) => {
33
38
  if (offset === 0) {
34
- Object.assign(parameters, {
35
- [key]: pathnamePart
39
+ pathnamePart.replace(new RegExp(Route.innerRootPattern, "g"), (innerMatch, innerKey, innerOffset) => {
40
+ if (innerOffset === 0) {
41
+ Object.assign(parameters, {
42
+ [key]: innerMatch
43
+ });
44
+ }
45
+ return innerMatch;
36
46
  });
37
47
  }
38
48
  return match;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bool-ts/core",
3
- "version": "1.7.5",
3
+ "version": "1.7.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -10,6 +10,7 @@ export type TRouteModel<T = unknown> = Readonly<{
10
10
 
11
11
  export class Route {
12
12
  public static rootPattern = ":([a-z0-9A-Z_-]{1,})";
13
+ public static innerRootPattern = "([a-z0-9A-Z_-]{1,})";
13
14
 
14
15
  public readonly alias: string;
15
16
 
@@ -38,6 +39,11 @@ export class Route {
38
39
  }
39
40
 
40
41
  const parameters: Record<string, string> = Object();
42
+ const matchingRegex = this.alias.replace(new RegExp(Route.rootPattern, "g"), Route.innerRootPattern);
43
+
44
+ if (!new RegExp(matchingRegex).test(this._thinAlias(pathname))) {
45
+ return undefined;
46
+ }
41
47
 
42
48
  for (let index = 0; index < aliasSplitted.length; index++) {
43
49
  const aliasPart = aliasSplitted[index];
@@ -51,9 +57,18 @@ export class Route {
51
57
 
52
58
  aliasPart.replace(new RegExp(Route.rootPattern, "g"), (match, key, offset) => {
53
59
  if (offset === 0) {
54
- Object.assign(parameters, {
55
- [key]: pathnamePart
56
- });
60
+ pathnamePart.replace(
61
+ new RegExp(Route.innerRootPattern, "g"),
62
+ (innerMatch, innerKey, innerOffset) => {
63
+ if (innerOffset === 0) {
64
+ Object.assign(parameters, {
65
+ [key]: innerMatch
66
+ });
67
+ }
68
+
69
+ return innerMatch;
70
+ }
71
+ );
57
72
  }
58
73
 
59
74
  return match;
@@ -52,6 +52,10 @@ export type TBoolFactoryOptions = Required<{
52
52
  methods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
53
53
  }>;
54
54
  queryParser: Parameters<typeof Qs.parse>[1];
55
+ static: Required<{
56
+ path: string;
57
+ }> &
58
+ Partial<{}>;
55
59
  }>;
56
60
 
57
61
  export const responseConverter = (response: Response) => {
@@ -916,8 +920,9 @@ export const BoolFactory = async (
916
920
  ) => {
917
921
  try {
918
922
  const modulesConverted = !Array.isArray(modules) ? [modules] : modules;
919
- const { allowLogsMethods } = Object.freeze({
920
- allowLogsMethods: options?.log?.methods
923
+ const { allowLogsMethods, staticOption } = Object.freeze({
924
+ allowLogsMethods: options?.log?.methods,
925
+ staticOption: options.static
921
926
  });
922
927
 
923
928
  const moduleResolutions = await Promise.all(
@@ -944,6 +949,21 @@ export const BoolFactory = async (
944
949
  const query = Qs.parse(url.searchParams.toString(), options.queryParser);
945
950
 
946
951
  try {
952
+ if (staticOption) {
953
+ const file = Bun.file(`${staticOption.path}/${url.pathname}`);
954
+ const isFileExists = await file.exists();
955
+
956
+ if (isFileExists) {
957
+ return new Response(await file.arrayBuffer(), {
958
+ status: 200,
959
+ statusText: "SUCCESS",
960
+ headers: {
961
+ "Content-Type": file.type
962
+ }
963
+ });
964
+ }
965
+ }
966
+
947
967
  let collection:
948
968
  | undefined
949
969
  | Required<{
package/test.http CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
 
4
4
  ### Send test GET method
5
- GET http://{{baseUrl}}/test/abc/23234
5
+ GET http://{{baseUrl}}/test/abc/test-case.html
6
6
 
7
7
  ### Send test POST method
8
- POST http://{{baseUrl}}/test/abc/123/provider/23234?options[page]=1&options[limit]=6&options[sort][metadata.latestReviewAt]=desc&options[sort][info.searchCount]=desc&options[sort][createdAt]=desc&populate[0]=__headquarters&populate[1]=__logoMedia HTTP/1.1
8
+ POST http://{{baseUrl}}/test/abc/123/provider/1111.xml?options[page]=1&options[limit]=6&options[sort][metadata.latestReviewAt]=desc&options[sort][info.searchCount]=desc&options[sort][createdAt]=desc&populate[0]=__headquarters&populate[1]=__logoMedia HTTP/1.1
9
9
  content-type: application/json
10
10
 
11
11
  {