@bool-ts/core 1.7.6 → 1.7.8

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.
@@ -21,6 +21,9 @@ export type TBoolFactoryOptions = Required<{
21
21
  methods: Array<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS">;
22
22
  }>;
23
23
  queryParser: Parameters<typeof Qs.parse>[1];
24
+ static: Required<{
25
+ path: string;
26
+ }> & Partial<{}>;
24
27
  }>;
25
28
  export declare const responseConverter: (response: Response) => Response;
26
29
  export declare const controllerCreator: (controllerConstructor: new (...args: any[]) => unknown, group: RouterGroup, injector: Injector, prefix?: string) => RouterGroup;
@@ -568,8 +568,9 @@ const fetcher = async (bun, bool) => {
568
568
  export const BoolFactory = async (modules, options) => {
569
569
  try {
570
570
  const modulesConverted = !Array.isArray(modules) ? [modules] : modules;
571
- const { allowLogsMethods } = Object.freeze({
572
- allowLogsMethods: options?.log?.methods
571
+ const { allowLogsMethods, staticOption } = Object.freeze({
572
+ allowLogsMethods: options?.log?.methods,
573
+ staticOption: options.static
573
574
  });
574
575
  const moduleResolutions = await Promise.all(modulesConverted.map((moduleConverted) => moduleResolution(moduleConverted, options)));
575
576
  const availableModuleResolutions = moduleResolutions.filter((moduleResolution) => typeof moduleResolution !== "undefined");
@@ -586,6 +587,19 @@ export const BoolFactory = async (modules, options) => {
586
587
  const url = new URL(request.url);
587
588
  const query = Qs.parse(url.searchParams.toString(), options.queryParser);
588
589
  try {
590
+ if (staticOption) {
591
+ const file = Bun.file(`${staticOption.path}/${url.pathname}`);
592
+ const isFileExists = await file.exists();
593
+ if (isFileExists) {
594
+ return new Response(await file.arrayBuffer(), {
595
+ status: 200,
596
+ statusText: "SUCCESS",
597
+ headers: {
598
+ "Content-Type": file.type
599
+ }
600
+ });
601
+ }
602
+ }
589
603
  let collection;
590
604
  for (let i = 0; i < availableModuleResolutions.length; i++) {
591
605
  const routeResult = availableModuleResolutions[i].routerGroup.find(url.pathname, request.method);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bool-ts/core",
3
- "version": "1.7.6",
3
+ "version": "1.7.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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<{