@dooboostore/simple-boot-http-server 1.0.22 → 1.0.24

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 (181) hide show
  1. package/README.MD +27 -3
  2. package/dist/cjs/SimpleBootHttpServer.js +93 -36
  3. package/dist/cjs/SimpleBootHttpServer.js.map +3 -3
  4. package/dist/cjs/codes/HttpHeaders.js +14 -3
  5. package/dist/cjs/codes/HttpHeaders.js.map +2 -2
  6. package/dist/cjs/codes/HttpStatus.js +1 -0
  7. package/dist/cjs/codes/HttpStatus.js.map +2 -2
  8. package/dist/cjs/codes/Mimes.js +2 -0
  9. package/dist/cjs/codes/Mimes.js.map +2 -2
  10. package/dist/cjs/decorators/MethodMapping.js +8 -6
  11. package/dist/cjs/decorators/MethodMapping.js.map +3 -3
  12. package/dist/cjs/endpoints/WebSocketEndPoint.js +16 -0
  13. package/dist/cjs/endpoints/WebSocketEndPoint.js.map +7 -0
  14. package/dist/cjs/filters/CacheFilter.js +75 -35
  15. package/dist/cjs/filters/CacheFilter.js.map +3 -3
  16. package/dist/cjs/filters/IntentSchemeFilter.js +98 -0
  17. package/dist/cjs/filters/IntentSchemeFilter.js.map +7 -0
  18. package/dist/cjs/filters/ResourceFilter.js +4 -1
  19. package/dist/cjs/filters/ResourceFilter.js.map +2 -2
  20. package/dist/cjs/filters/TopicProtocolFilter.js +343 -0
  21. package/dist/cjs/filters/TopicProtocolFilter.js.map +7 -0
  22. package/dist/cjs/filters/index.js +2 -0
  23. package/dist/cjs/filters/index.js.map +2 -2
  24. package/dist/cjs/index.js +28 -0
  25. package/dist/cjs/index.js.map +2 -2
  26. package/dist/cjs/models/RequestResponse.js +56 -89
  27. package/dist/cjs/models/RequestResponse.js.map +3 -3
  28. package/dist/cjs/models/datas/body/ReqPathData.js +29 -0
  29. package/dist/cjs/models/datas/body/ReqPathData.js.map +7 -0
  30. package/dist/cjs/models/datas/search/ReqSearchParamsObj.js +29 -0
  31. package/dist/cjs/models/datas/search/ReqSearchParamsObj.js.map +7 -0
  32. package/dist/cjs/option/HttpServerOption.js +25 -5
  33. package/dist/cjs/option/HttpServerOption.js.map +2 -2
  34. package/dist/cjs/proxy/SymbolIntentApiServiceProxy.js +141 -0
  35. package/dist/cjs/proxy/SymbolIntentApiServiceProxy.js.map +7 -0
  36. package/dist/cjs/proxy/SymbolIntentApiServiceProxyBase.js +35 -0
  37. package/dist/cjs/proxy/SymbolIntentApiServiceProxyBase.js.map +7 -0
  38. package/dist/cjs/proxy/TopicProtocolApiServiceProxy.js +324 -0
  39. package/dist/cjs/proxy/TopicProtocolApiServiceProxy.js.map +7 -0
  40. package/dist/cjs/proxy/index.js +26 -0
  41. package/dist/cjs/proxy/index.js.map +7 -0
  42. package/dist/cjs/resolvers/ResourceResolver.js +2 -2
  43. package/dist/cjs/resolvers/ResourceResolver.js.map +2 -2
  44. package/dist/cjs/session/SessionManager.js +2 -2
  45. package/dist/cjs/session/SessionManager.js.map +2 -2
  46. package/dist/cjs/websocket/WebSocketClient.js +554 -0
  47. package/dist/cjs/websocket/WebSocketClient.js.map +7 -0
  48. package/dist/cjs/websocket/WebSocketManager.js +652 -0
  49. package/dist/cjs/websocket/WebSocketManager.js.map +7 -0
  50. package/dist/cjs/websocket/index.js +24 -0
  51. package/dist/cjs/websocket/index.js.map +7 -0
  52. package/dist/esm/SimpleBootHttpServer.js +76 -19
  53. package/dist/esm/SimpleBootHttpServer.js.map +2 -2
  54. package/dist/esm/codes/HttpHeaders.js +12 -2
  55. package/dist/esm/codes/HttpHeaders.js.map +2 -2
  56. package/dist/esm/codes/HttpStatus.js +1 -0
  57. package/dist/esm/codes/HttpStatus.js.map +2 -2
  58. package/dist/esm/codes/Mimes.js +2 -0
  59. package/dist/esm/codes/Mimes.js.map +2 -2
  60. package/dist/esm/decorators/MethodMapping.js +3 -1
  61. package/dist/esm/decorators/MethodMapping.js.map +2 -2
  62. package/dist/esm/endpoints/WebSocketEndPoint.js +1 -0
  63. package/dist/esm/endpoints/WebSocketEndPoint.js.map +7 -0
  64. package/dist/esm/filters/CacheFilter.js +67 -27
  65. package/dist/esm/filters/CacheFilter.js.map +2 -2
  66. package/dist/esm/filters/IntentSchemeFilter.js +75 -0
  67. package/dist/esm/filters/IntentSchemeFilter.js.map +7 -0
  68. package/dist/esm/filters/ResourceFilter.js +4 -1
  69. package/dist/esm/filters/ResourceFilter.js.map +2 -2
  70. package/dist/esm/filters/TopicProtocolFilter.js +310 -0
  71. package/dist/esm/filters/TopicProtocolFilter.js.map +7 -0
  72. package/dist/esm/filters/index.js +1 -0
  73. package/dist/esm/filters/index.js.map +2 -2
  74. package/dist/esm/index.js +12 -0
  75. package/dist/esm/index.js.map +2 -2
  76. package/dist/esm/models/RequestResponse.js +52 -85
  77. package/dist/esm/models/RequestResponse.js.map +2 -2
  78. package/dist/esm/models/datas/body/ReqPathData.js +6 -0
  79. package/dist/esm/models/datas/body/ReqPathData.js.map +7 -0
  80. package/dist/esm/models/datas/search/ReqSearchParamsObj.js +6 -0
  81. package/dist/esm/models/datas/search/ReqSearchParamsObj.js.map +7 -0
  82. package/dist/esm/option/HttpServerOption.js +24 -4
  83. package/dist/esm/option/HttpServerOption.js.map +2 -2
  84. package/dist/esm/proxy/SymbolIntentApiServiceProxy.js +118 -0
  85. package/dist/esm/proxy/SymbolIntentApiServiceProxy.js.map +7 -0
  86. package/dist/esm/proxy/SymbolIntentApiServiceProxyBase.js +12 -0
  87. package/dist/esm/proxy/SymbolIntentApiServiceProxyBase.js.map +7 -0
  88. package/dist/esm/proxy/TopicProtocolApiServiceProxy.js +301 -0
  89. package/dist/esm/proxy/TopicProtocolApiServiceProxy.js.map +7 -0
  90. package/dist/esm/proxy/index.js +4 -0
  91. package/dist/esm/proxy/index.js.map +7 -0
  92. package/dist/esm/resolvers/ResourceResolver.js +1 -1
  93. package/dist/esm/resolvers/ResourceResolver.js.map +1 -1
  94. package/dist/esm/session/SessionManager.js +1 -1
  95. package/dist/esm/session/SessionManager.js.map +1 -1
  96. package/dist/esm/websocket/WebSocketClient.js +529 -0
  97. package/dist/esm/websocket/WebSocketClient.js.map +7 -0
  98. package/dist/esm/websocket/WebSocketManager.js +622 -0
  99. package/dist/esm/websocket/WebSocketManager.js.map +7 -0
  100. package/dist/esm/websocket/index.js +3 -0
  101. package/dist/esm/websocket/index.js.map +7 -0
  102. package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js +13563 -5071
  103. package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js.map +4 -4
  104. package/dist/types/SimpleBootHttpServer.d.ts +5 -3
  105. package/dist/types/SimpleBootHttpServer.d.ts.map +1 -1
  106. package/dist/types/codes/HttpHeaders.d.ts +3 -0
  107. package/dist/types/codes/HttpHeaders.d.ts.map +1 -1
  108. package/dist/types/codes/HttpStatus.d.ts +13 -1
  109. package/dist/types/codes/HttpStatus.d.ts.map +1 -1
  110. package/dist/types/codes/Mimes.d.ts +3 -1
  111. package/dist/types/codes/Mimes.d.ts.map +1 -1
  112. package/dist/types/decorators/MethodMapping.d.ts +4 -2
  113. package/dist/types/decorators/MethodMapping.d.ts.map +1 -1
  114. package/dist/types/endpoints/WebSocketEndPoint.d.ts +17 -0
  115. package/dist/types/endpoints/WebSocketEndPoint.d.ts.map +1 -0
  116. package/dist/types/filters/CacheFilter.d.ts +6 -0
  117. package/dist/types/filters/CacheFilter.d.ts.map +1 -1
  118. package/dist/types/filters/IntentSchemeFilter.d.ts +20 -0
  119. package/dist/types/filters/IntentSchemeFilter.d.ts.map +1 -0
  120. package/dist/types/filters/ResourceFilter.d.ts.map +1 -1
  121. package/dist/types/filters/TopicProtocolFilter.d.ts +34 -0
  122. package/dist/types/filters/TopicProtocolFilter.d.ts.map +1 -0
  123. package/dist/types/filters/index.d.ts +1 -0
  124. package/dist/types/filters/index.d.ts.map +1 -1
  125. package/dist/types/index.d.ts +12 -0
  126. package/dist/types/index.d.ts.map +1 -1
  127. package/dist/types/models/RequestResponse.d.ts +10 -6
  128. package/dist/types/models/RequestResponse.d.ts.map +1 -1
  129. package/dist/types/models/datas/body/ReqPathData.d.ts +4 -0
  130. package/dist/types/models/datas/body/ReqPathData.d.ts.map +1 -0
  131. package/dist/types/models/datas/search/ReqSearchParamsObj.d.ts +4 -0
  132. package/dist/types/models/datas/search/ReqSearchParamsObj.d.ts.map +1 -0
  133. package/dist/types/option/HttpServerOption.d.ts +30 -20
  134. package/dist/types/option/HttpServerOption.d.ts.map +1 -1
  135. package/dist/types/proxy/SymbolIntentApiServiceProxy.d.ts +18 -0
  136. package/dist/types/proxy/SymbolIntentApiServiceProxy.d.ts.map +1 -0
  137. package/dist/types/proxy/SymbolIntentApiServiceProxyBase.d.ts +5 -0
  138. package/dist/types/proxy/SymbolIntentApiServiceProxyBase.d.ts.map +1 -0
  139. package/dist/types/proxy/TopicProtocolApiServiceProxy.d.ts +28 -0
  140. package/dist/types/proxy/TopicProtocolApiServiceProxy.d.ts.map +1 -0
  141. package/dist/types/proxy/index.d.ts +4 -0
  142. package/dist/types/proxy/index.d.ts.map +1 -0
  143. package/dist/types/session/SessionManager.d.ts +2 -17
  144. package/dist/types/session/SessionManager.d.ts.map +1 -1
  145. package/dist/types/websocket/WebSocketClient.d.ts +88 -0
  146. package/dist/types/websocket/WebSocketClient.d.ts.map +1 -0
  147. package/dist/types/websocket/WebSocketManager.d.ts +163 -0
  148. package/dist/types/websocket/WebSocketManager.d.ts.map +1 -0
  149. package/dist/types/websocket/index.d.ts +3 -0
  150. package/dist/types/websocket/index.d.ts.map +1 -0
  151. package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js +13638 -5146
  152. package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js.map +4 -4
  153. package/dist/umd-bundle/websocket-client.umd.js +11194 -0
  154. package/dist/umd-bundle/websocket-client.umd.js.map +7 -0
  155. package/package.json +24 -15
  156. package/src/SimpleBootHttpServer.ts +367 -296
  157. package/src/codes/HttpHeaders.ts +13 -2
  158. package/src/codes/HttpStatus.ts +19 -1
  159. package/src/codes/Mimes.ts +27 -25
  160. package/src/decorators/MethodMapping.ts +6 -3
  161. package/src/endpoints/WebSocketEndPoint.ts +12 -0
  162. package/src/filters/CacheFilter.ts +112 -67
  163. package/src/filters/IntentSchemeFilter.ts +69 -0
  164. package/src/filters/ResourceFilter.ts +7 -1
  165. package/src/filters/TopicProtocolFilter.ts +349 -0
  166. package/src/filters/index.ts +1 -0
  167. package/src/index.ts +12 -12
  168. package/src/models/RequestResponse.ts +113 -240
  169. package/src/models/datas/body/ReqPathData.ts +3 -0
  170. package/src/models/datas/search/ReqSearchParamsObj.ts +3 -0
  171. package/src/option/HttpServerOption.ts +73 -23
  172. package/src/proxy/SymbolIntentApiServiceProxy.ts +120 -0
  173. package/src/proxy/SymbolIntentApiServiceProxyBase.ts +16 -0
  174. package/src/proxy/TopicProtocolApiServiceProxy.ts +328 -0
  175. package/src/proxy/index.ts +3 -0
  176. package/src/resolvers/ResourceResolver.ts +1 -1
  177. package/src/session/SessionManager.ts +3 -3
  178. package/src/websocket/WebSocketClient.ts +637 -0
  179. package/src/websocket/WebSocketManager.ts +713 -0
  180. package/src/websocket/index.ts +2 -0
  181. package/tsconfig.json +3 -1
@@ -50,19 +50,21 @@ __export(MethodMapping_exports, {
50
50
  getUrlMappings: () => getUrlMappings
51
51
  });
52
52
  module.exports = __toCommonJS(MethodMapping_exports);
53
- var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
53
+ var import_core2 = require("@dooboostore/core");
54
54
  var import_HttpMethod = require("../codes/HttpMethod");
55
55
  var UrlMappingSituationType = /* @__PURE__ */ ((UrlMappingSituationType2) => {
56
56
  UrlMappingSituationType2["REQ_JSON_BODY"] = "SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_JSON_BODY";
57
+ UrlMappingSituationType2["REQ_PATH_DATA"] = "SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_PATH_DATA";
58
+ UrlMappingSituationType2["REQ_URL_SEARCH_PARAMS_OBJ"] = "SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_URL_SEARCH_PARAMS_OBJ";
57
59
  UrlMappingSituationType2["REQ_FORM_URL_BODY"] = "SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_FORM_URL_BODY";
58
60
  return UrlMappingSituationType2;
59
61
  })(UrlMappingSituationType || {});
60
62
  const MappingMetadataKey = Symbol("MappingMetadataKey");
61
63
  const process = (config, target, propertyKey, descriptor) => {
62
- const saveMappingConfigs = import_ReflectUtils.ReflectUtils.getMetadata(MappingMetadataKey, target.constructor) ?? [];
64
+ const saveMappingConfigs = import_core2.ReflectUtils.getMetadata(MappingMetadataKey, target.constructor) ?? [];
63
65
  saveMappingConfigs.push({ propertyKey, config });
64
- import_ReflectUtils.ReflectUtils.defineMetadata(MappingMetadataKey, saveMappingConfigs, target.constructor);
65
- import_ReflectUtils.ReflectUtils.defineMetadata(MappingMetadataKey, config, target, propertyKey);
66
+ import_core2.ReflectUtils.defineMetadata(MappingMetadataKey, saveMappingConfigs, target.constructor);
67
+ import_core2.ReflectUtils.defineMetadata(MappingMetadataKey, config, target, propertyKey);
66
68
  };
67
69
  function UrlMapping(configOrtarget, propertyKey, descriptor) {
68
70
  if (propertyKey && descriptor) {
@@ -74,13 +76,13 @@ function UrlMapping(configOrtarget, propertyKey, descriptor) {
74
76
  }
75
77
  }
76
78
  const getUrlMapping = (target, propertyKey) => {
77
- return import_ReflectUtils.ReflectUtils.getMetadata(MappingMetadataKey, target, propertyKey);
79
+ return import_core2.ReflectUtils.getMetadata(MappingMetadataKey, target, propertyKey);
78
80
  };
79
81
  const getUrlMappings = (target) => {
80
82
  if (target !== null && void 0 !== target && typeof target === "object") {
81
83
  target = target.constructor;
82
84
  }
83
- return import_ReflectUtils.ReflectUtils.getMetadata(MappingMetadataKey, target);
85
+ return import_core2.ReflectUtils.getMetadata(MappingMetadataKey, target);
84
86
  };
85
87
  function GET(configOrTarget, propertyKey, descriptor) {
86
88
  if (propertyKey && descriptor) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/decorators/MethodMapping.ts"],
4
- "sourcesContent": ["import { ConstructorType } from '@dooboostore/core/types';\nimport { ReflectMethod } from '@dooboostore/simple-boot/types/Types';\nimport { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\nimport { Resolver } from '../resolvers/Resolver';\nimport { Mimes } from '../codes/Mimes';\nimport { HttpMethod } from '../codes/HttpMethod';\n\nexport enum UrlMappingSituationType {\n REQ_JSON_BODY = 'SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_JSON_BODY',\n REQ_FORM_URL_BODY = 'SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_FORM_URL_BODY'\n}\nexport type MappingConfig = {\n method: HttpMethod | string,\n description?: {\n name?: string;\n detail?: string;\n };\n\n req?: {\n contentType?: (Mimes|string)[];\n accept?: (Mimes|string)[];\n };\n\n res?: {\n status?: number;\n header?: {[key: string]: string};\n contentType?: Mimes | string;\n }\n resolver?: Resolver|ConstructorType<Resolver>;\n}\nexport type SaveMappingConfig = {propertyKey: string | symbol; config: MappingConfig}\nconst MappingMetadataKey = Symbol('MappingMetadataKey');\n// const GETSMappingMetadataKey = Symbol('GET_METHODS');\n// const GETMappingMetadataKey = Symbol('GET_METHOD');\n\nconst process = (config: MappingConfig, target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const saveMappingConfigs = (ReflectUtils.getMetadata(MappingMetadataKey, target.constructor) ?? []) as SaveMappingConfig[];\n saveMappingConfigs.push({propertyKey, config});\n ReflectUtils.defineMetadata(MappingMetadataKey, saveMappingConfigs, target.constructor);\n ReflectUtils.defineMetadata(MappingMetadataKey, config, target, propertyKey);\n}\nexport function UrlMapping(config: MappingConfig): ReflectMethod;\nexport function UrlMapping(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function UrlMapping(configOrtarget?: MappingConfig | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.GET}, configOrtarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n process(configOrtarget, target, propertyKey, descriptor);\n }\n }\n}\nexport const getUrlMapping = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return ReflectUtils.getMetadata(MappingMetadataKey, target, propertyKey);\n}\n\nexport const getUrlMappings = (target: any): SaveMappingConfig[] => {\n if (target !== null && undefined !== target && typeof target === 'object') {\n target = target.constructor;\n }\n return ReflectUtils.getMetadata(MappingMetadataKey, target);\n}\nexport function GET(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function GET(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function GET(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.GET}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.GET;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getGET = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getGETS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.GET);\n}\nexport function POST(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function POST(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function POST(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.POST}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.POST;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getPOST = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getPOSTS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.POST);\n}\nexport function DELETE(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function DELETE(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function DELETE(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.DELETE}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.DELETE;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getDELETE = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getDELETES = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.DELETE);\n}\nexport function PUT(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function PUT(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function PUT(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.PUT}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.PUT;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getPUT = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getPUTS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.PUT);\n}\nexport function PATCH(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function PATCH(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function PATCH(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.PATCH}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.PATCH;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getPATCH = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getPATCHS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.GET);\n}\nexport function OPTIONS(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function OPTIONS(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function OPTIONS(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.OPTIONS}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.OPTIONS;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getOPTIONS = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getOPTIONSS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.OPTIONS);\n}\nexport function HEAD(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function HEAD(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function HEAD(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.HEAD}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.HEAD;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getHEAD = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getHEADS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.GET);\n}\nexport function TRACE(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function TRACE(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function TRACE(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.TRACE}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.TRACE;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getTRACE = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getTRACES = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.TRACE);\n}\nexport function CONNECT(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function CONNECT(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function CONNECT(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.CONNECT}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.CONNECT;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getCONNECT = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getCONNECTS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.CONNECT);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAA6B;AAG7B,wBAA2B;AAEpB,IAAK,0BAAL,kBAAKA,6BAAL;AACH,EAAAA,yBAAA,mBAAgB;AAChB,EAAAA,yBAAA,uBAAoB;AAFZ,SAAAA;AAAA,GAAA;AAwBZ,MAAM,qBAAqB,OAAO,oBAAoB;AAItD,MAAM,UAAU,CAAC,QAAuB,QAAa,aAA8B,eAAmC;AAClH,QAAM,qBAAsB,iCAAa,YAAY,oBAAoB,OAAO,WAAW,KAAK,CAAC;AACjG,qBAAmB,KAAK,EAAC,aAAa,OAAM,CAAC;AAC7C,mCAAa,eAAe,oBAAoB,oBAAoB,OAAO,WAAW;AACtF,mCAAa,eAAe,oBAAoB,QAAQ,QAAQ,WAAW;AAC/E;AAGO,SAAS,WAAW,gBAAsC,aAA+B,YAAuD;AACnJ,MAAI,eAAe,YAAY;AAC3B,YAAQ,EAAC,QAAQ,6BAAW,IAAG,GAAG,gBAAgB,aAAa,UAAU;AAAA,EAC7E,OAAO;AACH,WAAO,CAAC,QAAaC,cAA8BC,gBAAmC;AAClF,c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AC1D,SAAO,eAAe,MAAM,GAAG,OAAO,QAAM,GAAG,QAAQ,OAAO,YAAY,MAAM,6BAAW,GAAG;AAClG;AAGO,SAAS,MAAM,gBAAsD,aAA+B,YAAuD;AAC9J,MAAI,eAAe,YAAY;AAC3B,YAAQ,EAAC,QAAQ,6BAAW,MAAK,GAAG,gBAAgB,aAAa,UAAU;AAAA,EAC/E,OAAO;AACH,WAAO,CAAC,QAAaD,cAA8BC,gBAAmC;AAClF,qBAAe,SAAS,6BAAW;AACnC,cAAQ,gBAAgB,QAAQD,cAAaC,WAAU;AAAA,IAC3D;AAAA,EACJ;AACJ;AAEO,MAAM,WAAW,CAAC,QAAa,gBAA4D;AAC9F,SAAO,cAAc,QAAQ,WAAW;AAC5C;AACO,MAAM,YAAY,CAAC,WAAqC;AAC3D,SAAO,eAAe,MAAM,GAAG,OAAO,QAAM,GAAG,QAAQ,OAAO,YAAY,MAAM,6BAAW,KAAK;AACpG;AAGO,SAAS,QAAQ,gBAAsD,aAA+B,YAAuD;AAChK,MAAI,eAAe,YAAY;AAC3B,YAAQ,EAAC,QAAQ,6BAAW,QAAO,GAAG,gBAAgB,aAAa,UAAU;AAAA,EACjF,OAAO;AACH,WAAO,CAAC,QAAaD,cAA8BC,gBAAmC;AAClF,qBAAe,SAAS,6BAAW;AACnC,cAAQ,gBAAgB,QAAQD,cAAaC,WAAU;AAAA,IAC3D;AAAA,EACJ;AACJ;AAEO,MAAM,aAAa,CAAC,QAAa,gBAA4D;AAChG,SAAO,cAAc,QAAQ,WAAW;AAC5C;AACO,MAAM,cAAc,CAAC,WAAqC;AAC7D,SAAO,eAAe,MAAM,GAAG,OAAO,QAAM,GAAG,QAAQ,OAAO,YAAY,MAAM,6BAAW,OAAO;AACtG;",
6
- "names": ["UrlMappingSituationType", "propertyKey", "descriptor"]
4
+ "sourcesContent": ["import { ConstructorType } from '@dooboostore/core';\nimport { ReflectMethod } from '@dooboostore/simple-boot';\nimport { ReflectUtils } from '@dooboostore/core';\nimport { Resolver } from '../resolvers/Resolver';\nimport { Mimes } from '../codes/Mimes';\nimport { HttpMethod } from '../codes/HttpMethod';\n\nexport enum UrlMappingSituationType {\n REQ_JSON_BODY = 'SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_JSON_BODY',\n REQ_PATH_DATA = 'SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_PATH_DATA',\n // REQ_URL_SEARCH_PARAMS = 'SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_URL_SEARCH_PARAMS',\n REQ_URL_SEARCH_PARAMS_OBJ = 'SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_URL_SEARCH_PARAMS_OBJ',\n REQ_FORM_URL_BODY = 'SIMPLE_BOOT_HTTP_SERVER://URLMAPPING/REQ_FORM_URL_BODY'\n}\nexport type MappingConfig = {\n method: HttpMethod | string,\n description?: {\n name?: string;\n detail?: string;\n };\n\n req?: {\n contentType?: (Mimes|string)[];\n accept?: (Mimes|string)[];\n };\n\n res?: {\n status?: number;\n header?: {[key: string]: string};\n contentType?: Mimes | string;\n }\n resolver?: Resolver|ConstructorType<Resolver>;\n}\nexport type SaveMappingConfig = {propertyKey: string | symbol; config: MappingConfig}\nconst MappingMetadataKey = Symbol('MappingMetadataKey');\n// const GETSMappingMetadataKey = Symbol('GET_METHODS');\n// const GETMappingMetadataKey = Symbol('GET_METHOD');\n\nconst process = (config: MappingConfig, target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const saveMappingConfigs = (ReflectUtils.getMetadata(MappingMetadataKey, target.constructor) ?? []) as SaveMappingConfig[];\n saveMappingConfigs.push({propertyKey, config});\n ReflectUtils.defineMetadata(MappingMetadataKey, saveMappingConfigs, target.constructor);\n ReflectUtils.defineMetadata(MappingMetadataKey, config, target, propertyKey);\n}\nexport function UrlMapping(config: MappingConfig): ReflectMethod;\nexport function UrlMapping(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function UrlMapping(configOrtarget?: MappingConfig | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.GET}, configOrtarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n process(configOrtarget, target, propertyKey, descriptor);\n }\n }\n}\nexport const getUrlMapping = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return ReflectUtils.getMetadata(MappingMetadataKey, target, propertyKey);\n}\n\nexport const getUrlMappings = (target: any): SaveMappingConfig[] => {\n if (target !== null && undefined !== target && typeof target === 'object') {\n target = target.constructor;\n }\n return ReflectUtils.getMetadata(MappingMetadataKey, target);\n}\nexport function GET(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function GET(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function GET(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.GET}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.GET;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getGET = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getGETS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.GET);\n}\nexport function POST(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function POST(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function POST(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.POST}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.POST;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getPOST = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getPOSTS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.POST);\n}\nexport function DELETE(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function DELETE(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function DELETE(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.DELETE}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.DELETE;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getDELETE = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getDELETES = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.DELETE);\n}\nexport function PUT(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function PUT(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function PUT(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.PUT}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.PUT;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getPUT = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getPUTS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.PUT);\n}\nexport function PATCH(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function PATCH(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function PATCH(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.PATCH}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.PATCH;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getPATCH = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getPATCHS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.GET);\n}\nexport function OPTIONS(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function OPTIONS(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function OPTIONS(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.OPTIONS}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.OPTIONS;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getOPTIONS = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getOPTIONSS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.OPTIONS);\n}\nexport function HEAD(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function HEAD(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function HEAD(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.HEAD}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.HEAD;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getHEAD = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getHEADS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.GET);\n}\nexport function TRACE(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function TRACE(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function TRACE(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.TRACE}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.TRACE;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getTRACE = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getTRACES = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.TRACE);\n}\nexport function CONNECT(config: Omit<MappingConfig, 'method'>): ReflectMethod;\nexport function CONNECT(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function CONNECT(configOrTarget?: Omit<MappingConfig, 'method'> | any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): ReflectMethod | void {\n if (propertyKey && descriptor) {\n process({method: HttpMethod.CONNECT}, configOrTarget, propertyKey, descriptor);\n } else {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n configOrTarget.method = HttpMethod.CONNECT;\n process(configOrTarget, target, propertyKey, descriptor);\n }\n }\n}\n\nexport const getCONNECT = (target: any, propertyKey: string | symbol): MappingConfig | undefined => {\n return getUrlMapping(target, propertyKey);\n}\nexport const getCONNECTS = (target: any): SaveMappingConfig[] => {\n return getUrlMappings(target)?.filter(it => it.config?.method.toUpperCase() === HttpMethod.CONNECT);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAAA,eAA6B;AAG7B,wBAA2B;AAEpB,IAAK,0BAAL,kBAAKC,6BAAL;AACH,EAAAA,yBAAA,mBAAgB;AAChB,EAAAA,yBAAA,mBAAgB;AAEhB,EAAAA,yBAAA,+BAA4B;AAC5B,EAAAA,yBAAA,uBAAoB;AALZ,SAAAA;AAAA,GAAA;AA2BZ,MAAM,qBAAqB,OAAO,oBAAoB;AAItD,MAAM,UAAU,CAAC,QAAuB,QAAa,aAA8B,eAAmC;AAClH,QAAM,qBAAsB,0BAAa,YAAY,oBAAoB,OAAO,WAAW,KAAK,CAAC;AACjG,qBAAmB,KAAK,EAAC,aAAa,OAAM,CAAC;AAC7C,4BAAa,eAAe,oBAAoB,oBAAoB,OAAO,WAAW;AACtF,4BAAa,eAAe,oBAAoB,QAAQ,QAAQ,WAAW;AAC/E;AAGO,SAAS,WAAW,gBAAsC,aAA+B,YAAuD;AACnJ,MAAI,eAAe,YAAY;AAC3B,YAAQ,EAAC,QAAQ,6BAA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]
7
7
  }
@@ -0,0 +1,16 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var WebSocketEndPoint_exports = {};
15
+ module.exports = __toCommonJS(WebSocketEndPoint_exports);
16
+ //# sourceMappingURL=WebSocketEndPoint.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/endpoints/WebSocketEndPoint.ts"],
4
+ "sourcesContent": ["import { RawData, WebSocket } from 'ws';\nimport { IncomingMessage } from 'http';\n\nexport type WebSocketSet ={ socket: WebSocket, request: IncomingMessage };\nexport interface WebSocketEndPoint {\n\n connect?(wsSet: WebSocketSet): void;\n ping?(wsSet: WebSocketSet): void;\n close?(wsSet: WebSocketSet): void;\n message(wsSet: WebSocketSet, data: {data: RawData, isBinary: boolean}): void;\n error?(wsSet: WebSocketSet, error: Error): void;\n}"],
5
+ "mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -20,17 +20,20 @@ __export(CacheFilter_exports, {
20
20
  CacheFilter: () => CacheFilter
21
21
  });
22
22
  module.exports = __toCommonJS(CacheFilter_exports);
23
- var import_FileUtils = require("@dooboostore/core-node/file/FileUtils");
24
- var import_ConvertUtils = require("@dooboostore/core-node/convert/ConvertUtils");
25
- var import_RandomUtils = require("@dooboostore/core/random/RandomUtils");
23
+ var import_core_node = require("@dooboostore/core-node");
24
+ var import_core_node2 = require("@dooboostore/core-node");
25
+ var import_core = require("@dooboostore/core");
26
26
  class CacheFilter {
27
27
  constructor(config) {
28
28
  this.config = config;
29
29
  this.storage = /* @__PURE__ */ new Map();
30
30
  if (config.config.cacheDir && config.config.startUpClean) {
31
- import_FileUtils.FileUtils.deleteSync(config.config.cacheDir, { options: { recursive: true } });
31
+ import_core_node.FileUtils.deleteSync(config.config.cacheDir, { options: { recursive: true } });
32
32
  }
33
33
  }
34
+ static {
35
+ this.SYMBOL = Symbol.for("CacheFilter");
36
+ }
34
37
  static {
35
38
  this.CARRIER_KEY_NAME = "_CARRIER_CACHE_FILTER_KEY_NAME";
36
39
  }
@@ -41,34 +44,15 @@ class CacheFilter {
41
44
  if (!filter) {
42
45
  return true;
43
46
  }
44
- if (this.config.config.cacheDir) {
45
- import_FileUtils.FileUtils.mkdirSync(this.config.config.cacheDir, { recursive: true });
46
- }
47
- if (!this.cacheConfig && this.config.config.cacheDir) {
48
- try {
49
- this.cacheConfig = JSON.parse(import_ConvertUtils.ConvertUtils.toString(import_FileUtils.FileUtils.readSync([this.config.config.cacheDir, "cacheConfig.json"], { option: { encoding: "utf-8" } })));
50
- } catch (e) {
51
- }
52
- }
53
- const date = (/* @__PURE__ */ new Date()).toISOString();
54
- this.cacheConfig ??= {
55
- createDate: date,
56
- updateDate: date,
57
- // accessDate: date,
58
- caches: {}
59
- };
60
- this.cacheConfig.createDate ??= date;
61
- this.cacheConfig.updateDate ??= date;
62
- this.cacheConfig.caches ??= {};
47
+ this.initCacheConfig();
63
48
  const rkey = this.config.key(rr, app);
64
49
  const sessionData = { key: rkey.key, lifeTime: rkey.lifeTime ?? this.config.config.lifeTime, isUpdate: false, responseHeaders: rkey.responseHeaders };
65
50
  const cache = this.cacheConfig.caches[sessionData.key];
66
51
  if (cache) {
67
- const existes = this.config.config.cacheDir ? import_FileUtils.FileUtils.existsSync(cache.path) : this.storage.has(cache.path);
52
+ const existes = this.config.config.cacheDir ? import_core_node.FileUtils.existsSync(cache.path) : this.storage.has(cache.path);
68
53
  const diffTime = Date.now() - cache.createTime;
69
54
  if (!existes || diffTime > cache.lifeTime) {
70
- delete this.cacheConfig[sessionData.key];
71
- this.deleteChunk(cache.path);
55
+ this.clear(sessionData.key);
72
56
  sessionData.isUpdate = true;
73
57
  } else {
74
58
  rr.resSetHeaders({
@@ -88,29 +72,87 @@ class CacheFilter {
88
72
  carrier.set(CacheFilter.CARRIER_KEY_NAME, sessionData);
89
73
  return sessionData.isUpdate;
90
74
  }
75
+ async refresh(path2, app) {
76
+ this.clear(path2);
77
+ const url = `${app.option.protocol}://${app.option.hostname}:${app.option.port}${path2}`;
78
+ try {
79
+ await fetch(url, {
80
+ method: "GET",
81
+ headers: {
82
+ "x-cache-force-refresh": "true",
83
+ "User-Agent": "SimpleBootHttpServer-Internal-Refresh"
84
+ }
85
+ });
86
+ } catch (e) {
87
+ console.error("CacheFilter.refresh fetch error:", e);
88
+ }
89
+ }
90
+ clear(key) {
91
+ this.initCacheConfig();
92
+ const cache = this.cacheConfig.caches[key];
93
+ if (cache) {
94
+ this.deleteChunk(cache.path);
95
+ delete this.cacheConfig.caches[key];
96
+ this.saveCacheConfig();
97
+ }
98
+ }
99
+ clearAll() {
100
+ this.initCacheConfig();
101
+ Object.keys(this.cacheConfig.caches).forEach((key) => {
102
+ this.deleteChunk(this.cacheConfig.caches[key].path);
103
+ });
104
+ this.cacheConfig.caches = {};
105
+ this.saveCacheConfig();
106
+ }
107
+ initCacheConfig() {
108
+ if (this.config.config.cacheDir) {
109
+ import_core_node.FileUtils.mkdirSync(this.config.config.cacheDir, { recursive: true });
110
+ }
111
+ if (!this.cacheConfig && this.config.config.cacheDir) {
112
+ try {
113
+ this.cacheConfig = JSON.parse(import_core_node2.ConvertUtils.toString(import_core_node.FileUtils.readSync([this.config.config.cacheDir, "cacheConfig.json"], { option: { encoding: "utf-8" } })));
114
+ } catch (e) {
115
+ }
116
+ }
117
+ const date = (/* @__PURE__ */ new Date()).toISOString();
118
+ this.cacheConfig ??= {
119
+ createDate: date,
120
+ updateDate: date,
121
+ // accessDate: date,
122
+ caches: {}
123
+ };
124
+ this.cacheConfig.createDate ??= date;
125
+ this.cacheConfig.updateDate ??= date;
126
+ this.cacheConfig.caches ??= {};
127
+ }
128
+ saveCacheConfig() {
129
+ if (this.config.config.cacheDir && this.cacheConfig) {
130
+ import_core_node.FileUtils.write(JSON.stringify(this.cacheConfig), { path: [this.config.config.cacheDir, "cacheConfig.json"] });
131
+ }
132
+ }
91
133
  deleteChunk(path2) {
92
- if (this.config.config.cacheDir && import_FileUtils.FileUtils.existsSync(path2)) {
93
- import_FileUtils.FileUtils.deleteFileSync(path2);
134
+ if (this.config.config.cacheDir && import_core_node.FileUtils.existsSync(path2)) {
135
+ import_core_node.FileUtils.deleteFileSync(path2);
94
136
  } else if (this.storage.has(path2)) {
95
137
  this.storage.delete(path2);
96
138
  }
97
139
  }
98
140
  getChunk(path2) {
99
- return this.config.config.cacheDir ? import_FileUtils.FileUtils.readSync(path2) : this.storage.get(path2);
141
+ return this.config.config.cacheDir ? import_core_node.FileUtils.readSync(path2) : this.storage.get(path2);
100
142
  }
101
143
  async proceedAfter({ rr, app, carrier }) {
102
144
  const sessionData = carrier.get(CacheFilter.CARRIER_KEY_NAME);
103
145
  if (sessionData && sessionData.isUpdate) {
104
146
  try {
105
147
  if (this.config.config.cacheDir) {
106
- import_FileUtils.FileUtils.mkdirSync([this.config.config.cacheDir, "caches"], { recursive: true });
148
+ import_core_node.FileUtils.mkdirSync([this.config.config.cacheDir, "caches"], { recursive: true });
107
149
  }
108
150
  const resBody = rr.resBodyData();
109
151
  if (!resBody) {
110
152
  return true;
111
153
  }
112
154
  let p = void 0;
113
- const destFileUUID = import_RandomUtils.RandomUtils.uuid4();
155
+ const destFileUUID = import_core.RandomUtils.uuid4();
114
156
  p = this.writeChunk(destFileUUID, resBody);
115
157
  const updateDateNow = Date.now();
116
158
  const updateDate = new Date(updateDateNow).toISOString();
@@ -126,9 +168,7 @@ class CacheFilter {
126
168
  lifeTime: sessionData.lifeTime,
127
169
  responseHeader: responseHeaders
128
170
  };
129
- if (this.config.config.cacheDir) {
130
- import_FileUtils.FileUtils.write(JSON.stringify(this.cacheConfig), { path: [this.config.config.cacheDir, "cacheConfig.json"] });
131
- }
171
+ this.saveCacheConfig();
132
172
  } catch (e) {
133
173
  console.log("---", e);
134
174
  }
@@ -137,7 +177,7 @@ class CacheFilter {
137
177
  }
138
178
  writeChunk(destFileUUID, resBody) {
139
179
  if (this.config.config.cacheDir) {
140
- return import_FileUtils.FileUtils.write(resBody, { path: [this.config.config.cacheDir, "caches", destFileUUID] });
180
+ return import_core_node.FileUtils.write(resBody, { path: [this.config.config.cacheDir, "caches", destFileUUID] });
141
181
  } else {
142
182
  this.storage.set(destFileUUID, resBody);
143
183
  return destFileUUID;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/filters/CacheFilter.ts"],
4
- "sourcesContent": ["import { Filter } from '../filters/Filter';\nimport { HttpStatus } from '../codes/HttpStatus';\nimport { RequestResponse } from '../models/RequestResponse';\nimport { SimpleBootHttpServer } from '../SimpleBootHttpServer';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { FileUtils } from '@dooboostore/core-node/file/FileUtils';\nimport { ConvertUtils } from '@dooboostore/core-node/convert/ConvertUtils';\nimport { RandomUtils } from '@dooboostore/core/random/RandomUtils';\n\nexport type CacheFilterSessionType = { key: string, lifeTime: number, isUpdate: boolean, responseHeaders?: string[] };\n\ntype CacheConfigCacheItemType = { path: string, createTime: number, lifeTime: number, responseHeader: { [key: string]: string | number | string[] } };\n\ntype KeyAndConfig = { key: string, lifeTime?: number, responseHeaders?: string[] } ;\n\nexport class CacheFilter implements Filter {\n public static readonly CARRIER_KEY_NAME = '_CARRIER_CACHE_FILTER_KEY_NAME';\n private storage = new Map<string, string | Buffer>();\n private cacheConfig: {\n createDate: string;\n updateDate: string;\n caches: { [key: string]: CacheConfigCacheItemType }\n }\n\n constructor(private config: {\n config: {\n cacheDir?: string;\n lifeTime: number;\n startUpClean?: boolean;\n },\n filter?: (rr: RequestResponse, app: SimpleBootHttpServer) => boolean;\n key: (rr: RequestResponse, app: SimpleBootHttpServer) => KeyAndConfig;\n }) {\n\n if (config.config.cacheDir && config.config.startUpClean) {\n FileUtils.deleteSync(config.config.cacheDir, {options: {recursive: true}});\n }\n }\n\n async onInit(app: SimpleBootHttpServer) {\n }\n\n async proceedBefore({rr, app, carrier}: {rr: RequestResponse, app: SimpleBootHttpServer, carrier: Map<string, any>}) {\n // this.key = undefined;\n // this.lifeTime = undefined;\n // this.isUpdate = false;\n const filter = this.config.filter?.(rr,app);\n if (!filter) {\n return true;\n }\n if (this.config.config.cacheDir) {\n FileUtils.mkdirSync(this.config.config.cacheDir, {recursive: true});\n }\n if (!this.cacheConfig && this.config.config.cacheDir) {\n try {\n this.cacheConfig = JSON.parse(ConvertUtils.toString(FileUtils.readSync([this.config.config.cacheDir, 'cacheConfig.json'], { option: {encoding: 'utf-8'}})));\n } catch (e) {\n }\n }\n const date = new Date().toISOString();\n this.cacheConfig ??= {\n createDate: date,\n updateDate: date,\n // accessDate: date,\n caches: {}\n };\n this.cacheConfig.createDate ??= date;\n this.cacheConfig.updateDate ??= date;\n // this.cacheConfig.accessDate ??= date;\n this.cacheConfig.caches ??= {};\n\n\n const rkey = this.config.key(rr, app);\n // console.log('--path filter', rr.reqMethod(), rr.reqUrlPathName, filter, rkey)\n const sessionData: CacheFilterSessionType = {key: rkey.key, lifeTime: rkey.lifeTime ?? this.config.config.lifeTime, isUpdate: false, responseHeaders: rkey.responseHeaders};\n\n\n const cache = this.cacheConfig.caches[sessionData.key];\n if (cache) {\n const existes = this.config.config.cacheDir ? FileUtils.existsSync(cache.path) : this.storage.has(cache.path);\n const diffTime = Date.now() - cache.createTime;\n if (!existes || diffTime > cache.lifeTime) {\n delete this.cacheConfig[sessionData.key];\n this.deleteChunk(cache.path);\n sessionData.isUpdate = true;\n } else {\n rr.resSetHeaders({\n ...cache.responseHeader,\n cacheFilter: `true;remainTime=${cache.lifeTime - diffTime}`\n });\n // console.log('chunk--->', cache.path);\n try {\n const chunk = this.getChunk(cache.path);\n // console.log('chunk--->', chunk);\n await rr.resEnd(chunk);\n } catch (e) {\n console.log('--------e', e)\n }\n }\n } else {\n sessionData.isUpdate = true;\n }\n carrier.set(CacheFilter.CARRIER_KEY_NAME, sessionData);\n return sessionData.isUpdate;\n }\n\n private deleteChunk(path: string) {\n if (this.config.config.cacheDir && FileUtils.existsSync(path)) {\n FileUtils.deleteFileSync(path);\n } else if (this.storage.has(path)) {\n this.storage.delete(path);\n }\n }\n\n private getChunk(path: string) {\n return this.config.config.cacheDir ? FileUtils.readSync(path) : this.storage.get(path);\n }\n\n async proceedAfter({rr, app, carrier}: {rr: RequestResponse, app: SimpleBootHttpServer, carrier: Map<string, any>}) {\n // const data = await rr.resBodyStringData()\n const sessionData = carrier.get(CacheFilter.CARRIER_KEY_NAME) as CacheFilterSessionType ;\n if (sessionData && sessionData.isUpdate) {\n try {\n if (this.config.config.cacheDir) {\n FileUtils.mkdirSync([this.config.config.cacheDir, 'caches'], {recursive: true});\n }\n const resBody = rr.resBodyData();\n if (!resBody) {\n return true;\n }\n let p: string | undefined = undefined;\n const destFileUUID = RandomUtils.uuid4();\n p = this.writeChunk(destFileUUID, resBody);\n const updateDateNow = Date.now();\n const updateDate = new Date(updateDateNow).toISOString();\n this.cacheConfig.createDate ??= updateDate;\n this.cacheConfig.updateDate = updateDate;\n const responseHeaders: {[key: string]: string | number | string[]} = {}\n sessionData.responseHeaders?.map(it=>it.toLowerCase()).forEach(it => {\n responseHeaders[it] = rr.resHeader(it);\n })\n this.cacheConfig.caches[sessionData.key] = {\n path: p,\n createTime: updateDateNow,\n lifeTime: sessionData.lifeTime,\n responseHeader: responseHeaders\n };\n\n if (this.config.config.cacheDir) {\n FileUtils.write(JSON.stringify(this.cacheConfig), {path: [this.config.config.cacheDir, 'cacheConfig.json']});\n }\n } catch (e) {\n console.log('---', e)\n }\n }\n\n return true;\n }\n\n private writeChunk(destFileUUID: string, resBody: string | Buffer ) {\n if (this.config.config.cacheDir) {\n return FileUtils.write(resBody, {path: [this.config.config.cacheDir, 'caches', destFileUUID]});\n } else {\n this.storage.set(destFileUUID, resBody);\n return destFileUUID;\n }\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,uBAA2B;AAC3B,0BAA6B;AAC7B,yBAA4B;AAQrB,MAAM,YAA8B;AAAA,EASzC,YAAoB,QAQjB;AARiB;AAPpB,SAAQ,UAAU,oBAAI,IAA6B;AAiBjD,QAAI,OAAO,OAAO,YAAY,OAAO,OAAO,cAAc;AACxD,iCAAU,WAAW,OAAO,OAAO,UAAU,EAAC,SAAS,EAAC,WAAW,KAAI,EAAC,CAAC;AAAA,IAC3E;AAAA,EACF;AAAA,EArBA;AAAA,SAAuB,mBAAmB;AAAA;AAAA,EAuB1C,MAAM,OAAO,KAA2B;AAAA,EACxC;AAAA,EAEA,MAAM,cAAc,EAAC,IAAI,KAAK,QAAO,GAAgF;AAInH,UAAM,SAAS,KAAK,OAAO,SAAS,IAAG,GAAG;AAC1C,QAAI,CAAC,QAAQ;AACX,aAAO;AAAA,IACT;AACA,QAAI,KAAK,OAAO,OAAO,UAAU;AAC/B,iCAAU,UAAU,KAAK,OAAO,OAAO,UAAU,EAAC,WAAW,KAAI,CAAC;AAAA,IACpE;AACA,QAAI,CAAC,KAAK,eAAe,KAAK,OAAO,OAAO,UAAU;AACpD,UAAI;AACF,aAAK,cAAc,KAAK,MAAM,iCAAa,SAAS,2BAAU,SAAS,CAAC,KAAK,OAAO,OAAO,UAAU,kBAAkB,GAAG,EAAE,QAAQ,EAAC,UAAU,QAAO,EAAC,CAAC,CAAC,CAAC;AAAA,MAC5J,SAAS,GAAG;AAAA,MACZ;AAAA,IACF;AACA,UAAM,QAAO,oBAAI,KAAK,G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C,CAAC;AAAA,QAC7G;AAAA,MACF,SAAS,GAAG;AACV,gBAAQ,IAAI,OAAO,CAAC;AAAA,MACtB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEQ,WAAW,cAAsB,SAA2B;AAClE,QAAI,KAAK,OAAO,OAAO,UAAU;AAC/B,aAAO,2BAAU,MAAM,SAAS,EAAC,MAAM,CAAC,KAAK,OAAO,OAAO,UAAU,UAAU,YAAY,EAAC,CAAC;AAAA,IAC/F,OAAO;AACL,WAAK,QAAQ,IAAI,cAAc,OAAO;AACtC,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
6
- "names": ["path"]
4
+ "sourcesContent": ["import { Filter } from '../filters/Filter';\nimport { HttpStatus } from '../codes/HttpStatus';\nimport { RequestResponse } from '../models/RequestResponse';\nimport { SimpleBootHttpServer } from '../SimpleBootHttpServer';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { FileUtils } from '@dooboostore/core-node';\nimport { ConvertUtils } from '@dooboostore/core-node';\nimport { RandomUtils } from '@dooboostore/core';\n\nexport type CacheFilterSessionType = { key: string; lifeTime: number; isUpdate: boolean; responseHeaders?: string[] };\n\ntype CacheConfigCacheItemType = { path: string; createTime: number; lifeTime: number; responseHeader: { [key: string]: string | number | string[] } };\n\ntype KeyAndConfig = { key: string; lifeTime?: number; responseHeaders?: string[] };\n\nexport class CacheFilter implements Filter {\n public static readonly SYMBOL = Symbol.for('CacheFilter');\n public static readonly CARRIER_KEY_NAME = '_CARRIER_CACHE_FILTER_KEY_NAME';\n private storage = new Map<string, string | Buffer>();\n private cacheConfig: {\n createDate: string;\n updateDate: string;\n caches: { [key: string]: CacheConfigCacheItemType };\n };\n\n constructor(\n private config: {\n config: {\n cacheDir?: string;\n lifeTime: number;\n startUpClean?: boolean;\n };\n filter?: (rr: RequestResponse, app: SimpleBootHttpServer) => boolean;\n key: (rr: RequestResponse, app: SimpleBootHttpServer) => KeyAndConfig;\n }\n ) {\n if (config.config.cacheDir && config.config.startUpClean) {\n FileUtils.deleteSync(config.config.cacheDir, { options: { recursive: true } });\n }\n }\n\n async onInit(app: SimpleBootHttpServer) {}\n\n async proceedBefore({ rr, app, carrier }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n // this.key = undefined;\n // this.lifeTime = undefined;\n // this.isUpdate = false;\n const filter = this.config.filter?.(rr, app);\n if (!filter) {\n return true;\n }\n this.initCacheConfig();\n const rkey = this.config.key(rr, app);\n // console.log('--path filter', rr.reqMethod(), rr.reqUrlPathName, filter, rkey)\n const sessionData: CacheFilterSessionType = { key: rkey.key, lifeTime: rkey.lifeTime ?? this.config.config.lifeTime, isUpdate: false, responseHeaders: rkey.responseHeaders };\n\n const cache = this.cacheConfig.caches[sessionData.key];\n if (cache) {\n const existes = this.config.config.cacheDir ? FileUtils.existsSync(cache.path) : this.storage.has(cache.path);\n const diffTime = Date.now() - cache.createTime;\n if (!existes || diffTime > cache.lifeTime) {\n this.clear(sessionData.key);\n sessionData.isUpdate = true;\n } else {\n rr.resSetHeaders({\n ...cache.responseHeader,\n cacheFilter: `true;remainTime=${cache.lifeTime - diffTime}`\n });\n // console.log('chunk--->', cache.path);\n try {\n const chunk = this.getChunk(cache.path);\n // console.log('chunk--->', chunk);\n await rr.resEnd(chunk);\n } catch (e) {\n console.log('--------e', e);\n }\n }\n } else {\n sessionData.isUpdate = true;\n }\n carrier.set(CacheFilter.CARRIER_KEY_NAME, sessionData);\n return sessionData.isUpdate;\n }\n\n public async refresh(path: string, app: SimpleBootHttpServer) {\n // 1. \uAE30\uC874 \uCE90\uC2DC \uD30C\uC77C \uC0AD\uC81C\n this.clear(path);\n\n // 2. HTTP Fetch\uB97C \uD1B5\uD55C \uC678\uBD80 \uD638\uCD9C (GET)\n // \uC544\uD0A4\uD14D\uD2B8\uB2D8\uC758 \uC9C0\uC2DC\uC5D0 \uB530\uB77C \uB124\uD2B8\uC6CC\uD06C \uB808\uC774\uC5B4\uB97C \uD1B5\uD574 \uC815\uC11D\uB300\uB85C \uD638\uCD9C\uD569\uB2C8\uB2E4.\n const url = `${app.option.protocol}://${app.option.hostname}:${app.option.port}${path}`;\n try {\n await fetch(url, {\n method: 'GET',\n headers: {\n 'x-cache-force-refresh': 'true',\n 'User-Agent': 'SimpleBootHttpServer-Internal-Refresh'\n }\n });\n } catch (e) {\n console.error('CacheFilter.refresh fetch error:', e);\n }\n }\n\n public clear(key: string) {\n this.initCacheConfig();\n const cache = this.cacheConfig.caches[key];\n if (cache) {\n this.deleteChunk(cache.path);\n delete this.cacheConfig.caches[key];\n this.saveCacheConfig();\n }\n }\n\n public clearAll() {\n this.initCacheConfig();\n Object.keys(this.cacheConfig.caches).forEach(key => {\n this.deleteChunk(this.cacheConfig.caches[key].path);\n });\n this.cacheConfig.caches = {};\n this.saveCacheConfig();\n }\n\n private initCacheConfig() {\n if (this.config.config.cacheDir) {\n FileUtils.mkdirSync(this.config.config.cacheDir, { recursive: true });\n }\n if (!this.cacheConfig && this.config.config.cacheDir) {\n try {\n this.cacheConfig = JSON.parse(ConvertUtils.toString(FileUtils.readSync([this.config.config.cacheDir, 'cacheConfig.json'], { option: { encoding: 'utf-8' } })));\n } catch (e) {}\n }\n const date = new Date().toISOString();\n this.cacheConfig ??= {\n createDate: date,\n updateDate: date,\n // accessDate: date,\n caches: {}\n };\n this.cacheConfig.createDate ??= date;\n this.cacheConfig.updateDate ??= date;\n // this.cacheConfig.accessDate ??= date;\n this.cacheConfig.caches ??= {};\n }\n\n private saveCacheConfig() {\n if (this.config.config.cacheDir && this.cacheConfig) {\n FileUtils.write(JSON.stringify(this.cacheConfig), { path: [this.config.config.cacheDir, 'cacheConfig.json'] });\n }\n }\n\n private deleteChunk(path: string) {\n if (this.config.config.cacheDir && FileUtils.existsSync(path)) {\n FileUtils.deleteFileSync(path);\n } else if (this.storage.has(path)) {\n this.storage.delete(path);\n }\n }\n\n private getChunk(path: string) {\n return this.config.config.cacheDir ? FileUtils.readSync(path) : this.storage.get(path);\n }\n\n async proceedAfter({ rr, app, carrier }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n // const data = await rr.resBodyStringData()\n const sessionData = carrier.get(CacheFilter.CARRIER_KEY_NAME) as CacheFilterSessionType;\n if (sessionData && sessionData.isUpdate) {\n try {\n if (this.config.config.cacheDir) {\n FileUtils.mkdirSync([this.config.config.cacheDir, 'caches'], { recursive: true });\n }\n const resBody = rr.resBodyData();\n if (!resBody) {\n return true;\n }\n let p: string | undefined = undefined;\n const destFileUUID = RandomUtils.uuid4();\n p = this.writeChunk(destFileUUID, resBody);\n const updateDateNow = Date.now();\n const updateDate = new Date(updateDateNow).toISOString();\n this.cacheConfig.createDate ??= updateDate;\n this.cacheConfig.updateDate = updateDate;\n const responseHeaders: { [key: string]: string | number | string[] } = {};\n sessionData.responseHeaders\n ?.map(it => it.toLowerCase())\n .forEach(it => {\n responseHeaders[it] = rr.resHeader(it);\n });\n this.cacheConfig.caches[sessionData.key] = {\n path: p,\n createTime: updateDateNow,\n lifeTime: sessionData.lifeTime,\n responseHeader: responseHeaders\n };\n\n this.saveCacheConfig();\n } catch (e) {\n console.log('---', e);\n }\n }\n\n return true;\n }\n\n private writeChunk(destFileUUID: string, resBody: string | Buffer) {\n if (this.config.config.cacheDir) {\n return FileUtils.write(resBody, { path: [this.config.config.cacheDir, 'caches', destFileUUID] });\n } else {\n this.storage.set(destFileUUID, resBody);\n return destFileUUID;\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,uBAA0B;AAC1B,IAAAA,oBAA6B;AAC7B,kBAA4B;AAQrB,MAAM,YAA8B;AAAA,EAUzC,YACU,QASR;AATQ;AARV,SAAQ,UAAU,oBAAI,IAA6B;AAkBjD,QAAI,OAAO,OAAO,YAAY,OAAO,OAAO,cAAc;AACxD,iCAAU,WAAW,OAAO,OAAO,UAAU,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CAAC;AAA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,cAAM,gBAAgB,KAAK,IAAI;AAC/B,cAAM,aAAa,IAAI,KAAK,aAAa,EAAE,YAAY;AACvD,aAAK,YAAY,eAAe;AAChC,aAAK,YAAY,aAAa;AAC9B,cAAM,kBAAiE,CAAC;AACxE,oBAAY,iBACR,IAAI,QAAM,GAAG,YAAY,CAAC,EAC3B,QAAQ,QAAM;AACb,0BAAgB,EAAE,IAAI,GAAG,UAAU,EAAE;AAAA,QACvC,CAAC;AACH,aAAK,YAAY,OAAO,YAAY,GAAG,IAAI;AAAA,UACzC,MAAM;AAAA,UACN,YAAY;AAAA,UACZ,UAAU,YAAY;AAAA,UACtB,gBAAgB;AAAA,QAClB;AAEA,aAAK,gBAAgB;AAAA,MACvB,SAAS,GAAG;AACV,gBAAQ,IAAI,OAAO,CAAC;AAAA,MACtB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEQ,WAAW,cAAsB,SAA0B;AACjE,QAAI,KAAK,OAAO,OAAO,UAAU;AAC/B,aAAO,2BAAU,MAAM,SAAS,EAAE,MAAM,CAAC,KAAK,OAAO,OAAO,UAAU,UAAU,YAAY,EAAE,CAAC;AAAA,IACjG,OAAO;AACL,WAAK,QAAQ,IAAI,cAAc,OAAO;AACtC,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
6
+ "names": ["import_core_node", "path"]
7
7
  }
@@ -0,0 +1,98 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var IntentSchemeFilter_exports = {};
19
+ __export(IntentSchemeFilter_exports, {
20
+ IntentSchemeFilter: () => IntentSchemeFilter
21
+ });
22
+ module.exports = __toCommonJS(IntentSchemeFilter_exports);
23
+ var import_HttpHeaders = require("../codes/HttpHeaders");
24
+ var import_simple_boot = require("@dooboostore/simple-boot");
25
+ var import_simple_boot2 = require("@dooboostore/simple-boot");
26
+ var import_simple_boot3 = require("@dooboostore/simple-boot");
27
+ var import_HttpStatus = require("../codes/HttpStatus");
28
+ var import_Mimes = require("../codes/Mimes");
29
+ var import_NotFoundError = require("../errors/NotFoundError");
30
+ var __decorate = function(decorators, target, key, desc) {
31
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
32
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
33
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
34
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
35
+ };
36
+ var __metadata = function(k, v) {
37
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
38
+ };
39
+ var _a;
40
+ let IntentSchemeFilter = class IntentSchemeFilter2 {
41
+ constructor(intentManager) {
42
+ this.intentManager = intentManager;
43
+ }
44
+ async onInit(app) {
45
+ }
46
+ async proceedBefore({ rr, app }) {
47
+ const url = rr.reqUrl;
48
+ const contentLength = Number(rr.reqHeader(import_HttpHeaders.HttpHeaders.ContentLength.toLowerCase() ?? "0"));
49
+ const acceptType = rr.reqHeader(import_HttpHeaders.HttpHeaders.Accept);
50
+ const contentType = rr.reqHeader(import_HttpHeaders.HttpHeaders.ContentType);
51
+ const intentScheme = rr.reqHeader(import_HttpHeaders.HttpHeaders.XSimpleBootSsrIntentScheme);
52
+ if (acceptType === import_Mimes.Mimes.ApplicationJsonPostSimpleBootSsrIntentScheme && intentScheme) {
53
+ let intent = new import_simple_boot.Intent(`${intentScheme}:/${url}`);
54
+ if (contentLength > 0) {
55
+ if (contentType.includes(import_Mimes.Mimes.ApplicationJson)) {
56
+ intent.data = [await rr.reqBodyJsonData(), rr];
57
+ } else if (contentType.includes(import_Mimes.Mimes.MultipartFormData)) {
58
+ intent.data = [await rr.reqBodyMultipartFormDataObject(), rr];
59
+ }
60
+ const { return: rdatas, target } = await this.intentManager.publishMeta(intent);
61
+ if (target.length <= 0) {
62
+ throw new import_NotFoundError.NotFoundError({ message: "Not found intent target" });
63
+ }
64
+ const rdata = rdatas[0];
65
+ const wdata = rdata instanceof Promise ? await rdata : rdata;
66
+ rr.resStatusCode(import_HttpStatus.HttpStatus.Ok);
67
+ rr.resSetHeader(import_HttpHeaders.HttpHeaders.ContentType, [import_Mimes.Mimes.ApplicationJson]);
68
+ await rr.resEnd(wdata ? JSON.stringify(wdata) : void 0);
69
+ } else {
70
+ intent.data = rr.reqUrlSearchParamTuples.length > 0 ? [rr.reqUrlSearchParamsObj, rr] : [rr];
71
+ const { return: rdatas, target } = await this.intentManager.publishMeta(intent);
72
+ if (target.length <= 0) {
73
+ throw new import_NotFoundError.NotFoundError({ message: "Not found intent target" });
74
+ }
75
+ const rdata = rdatas[0];
76
+ const wdata = rdata instanceof Promise ? await rdata : rdata;
77
+ rr.resStatusCode(import_HttpStatus.HttpStatus.Ok);
78
+ rr.resSetHeader(import_HttpHeaders.HttpHeaders.ContentType, [import_Mimes.Mimes.ApplicationJson]);
79
+ await rr.resEnd(wdata ? JSON.stringify(wdata) : void 0);
80
+ }
81
+ return false;
82
+ } else {
83
+ return true;
84
+ }
85
+ }
86
+ async proceedAfter({ rr, app }) {
87
+ return true;
88
+ }
89
+ };
90
+ IntentSchemeFilter = __decorate([
91
+ import_simple_boot3.Sim,
92
+ __metadata("design:paramtypes", [typeof (_a = typeof import_simple_boot2.IntentManager !== "undefined" && import_simple_boot2.IntentManager) === "function" ? _a : Object])
93
+ ], IntentSchemeFilter);
94
+ // Annotate the CommonJS export names for ESM import in node:
95
+ 0 && (module.exports = {
96
+ IntentSchemeFilter
97
+ });
98
+ //# sourceMappingURL=IntentSchemeFilter.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/filters/IntentSchemeFilter.ts"],
4
+ "sourcesContent": ["import { Filter } from './Filter';\nimport { HttpHeaders } from '../codes/HttpHeaders';\nimport { Intent } from '@dooboostore/simple-boot';\nimport { IntentManager } from '@dooboostore/simple-boot';\nimport { Sim } from '@dooboostore/simple-boot';\nimport { HttpStatus } from '../codes/HttpStatus';\nimport { RequestResponse } from '../models/RequestResponse';\nimport { SimpleBootHttpServer } from '../SimpleBootHttpServer';\nimport { Mimes } from '../codes/Mimes';\nimport { NotFoundError } from '../errors/NotFoundError';\n\n@Sim\nexport class IntentSchemeFilter implements Filter {\n constructor(private intentManager: IntentManager) {}\n\n async onInit(app: SimpleBootHttpServer) {}\n\n async proceedBefore({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n // const rr = rrr;\n const url = rr.reqUrl;\n const contentLength = Number(rr.reqHeader(HttpHeaders.ContentLength.toLowerCase() ?? '0'));\n const acceptType = rr.reqHeader(HttpHeaders.Accept);\n const contentType = rr.reqHeader(HttpHeaders.ContentType);\n const intentScheme = rr.reqHeader(HttpHeaders.XSimpleBootSsrIntentScheme);\n if (acceptType === Mimes.ApplicationJsonPostSimpleBootSsrIntentScheme && intentScheme) {\n let intent = new Intent(`${intentScheme}:/${url}`);\n // console.log('---------1--intent request', intentScheme, url, contentLength, contentType );\n // const responseHeader = {} as any;\n // responseHeader[HttpHeaders.ContentType] = Mimes.ApplicationJson;\n if (contentLength > 0) {\n if (contentType.includes(Mimes.ApplicationJson)) {\n intent.data = [await rr.reqBodyJsonData(), rr];\n } else if (contentType.includes(Mimes.MultipartFormData)) {\n intent.data = [await rr.reqBodyMultipartFormDataObject(), rr];\n }\n // console.log('---------2--intent request',intent);\n const { return: rdatas, target } = await this.intentManager.publishMeta(intent);\n if (target.length <= 0) {\n throw new NotFoundError({ message: 'Not found intent target' });\n }\n const rdata = rdatas[0];\n const wdata = rdata instanceof Promise ? await rdata : rdata;\n rr.resStatusCode(HttpStatus.Ok);\n rr.resSetHeader(HttpHeaders.ContentType, [Mimes.ApplicationJson]);\n await rr.resEnd(wdata ? JSON.stringify(wdata) : undefined);\n } else {\n intent.data = rr.reqUrlSearchParamTuples.length > 0 ? [rr.reqUrlSearchParamsObj, rr] : [rr];\n const { return: rdatas, target } = await this.intentManager.publishMeta(intent);\n if (target.length <= 0) {\n throw new NotFoundError({ message: 'Not found intent target' });\n }\n const rdata = rdatas[0];\n const wdata = rdata instanceof Promise ? await rdata : rdata;\n // const wdata =undefined;\n rr.resStatusCode(HttpStatus.Ok);\n rr.resSetHeader(HttpHeaders.ContentType, [Mimes.ApplicationJson]);\n await rr.resEnd(wdata ? JSON.stringify(wdata) : undefined);\n }\n // console.log('---------3--intent request', rr.req.readable, rr.req.readableLength);\n return false;\n } else {\n return true;\n }\n }\n\n async proceedAfter({ rr, app }: { rr: RequestResponse; app: SimpleBootHttpServer; carrier: Map<string, any> }) {\n return true;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AACA,yBAA4B;AAC5B,yBAAuB;AACvB,IAAAA,sBAA8B;AAC9B,IAAAA,sBAAoB;AACpB,wBAA2B;AAG3B,mBAAsB;AACtB,2BAA8B;;;;;;;;;;;AAGvB,IAAM,qBAAN,MAAMC,oBAAkB;EAC7B,YAAoB,eAA4B;AAA5B,SAAA,gBAAA;EAA+B;EAEnD,MAAM,OAAO,KAAyB;EAAG;EAEzC,MAAM,cAAc,EAAE,IAAI,IAAG,GAAiF;AAE5G,UAAM,MAAM,GAAG;AAC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AC;AACtB,cAAM,QAAQ,iBAAiB,UAAU,MAAM,QAAQ;AAEvD,WAAG,cAAc,6BAAW,EAAE;AAC9B,WAAG,aAAa,+BAAY,aAAa,CAAC,mBAAM,eAAe,CAAC;AAChE,cAAM,GAAG,OAAO,QAAQ,KAAK,UAAU,KAAK,IAAI,MAAS;MAC3D;AAEA,aAAO;IACT,OAAO;AACL,aAAO;IACT;EACF;EAEA,MAAM,aAAa,EAAE,IAAI,IAAG,GAAiF;AAC3G,WAAO;EACT;;AAvDW,qBAAkB,WAAA;EAD9B;uDAEoC,sCAAa,eAAb,uCAAa,aAAA,KAAA,MAAA,CAAA;GADrC,kBAAkB;",
6
+ "names": ["import_simple_boot", "IntentSchemeFilter"]
7
+ }
@@ -74,8 +74,11 @@ class ResourceFilter {
74
74
  if (typeof it === "object" && "request" in it) {
75
75
  if (typeof it.request === "function") {
76
76
  return it.request(rr, app);
77
+ } else if (it.request instanceof RegExp) {
78
+ return it.request.test(url);
79
+ } else {
80
+ return RegExp(it.request).test(url);
77
81
  }
78
- return RegExp(it.request).test(url);
79
82
  }
80
83
  }) ?? [];
81
84
  for (const it of regExps) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/filters/ResourceFilter.ts"],
4
- "sourcesContent": ["import { Filter } from '../filters/Filter';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport mime from 'mime-types';\nimport { HttpHeaders } from '../codes/HttpHeaders';\nimport { HttpStatus } from '../codes/HttpStatus';\nimport { SimpleBootHttpServer } from '../SimpleBootHttpServer';\nimport { RequestResponse } from '../models/RequestResponse';\nimport { Blob } from 'node:buffer';\n\nexport type RequestFilterType = string | RegExp | ((rr: RequestResponse, app: SimpleBootHttpServer) => boolean) | ((rr: RequestResponse, app: SimpleBootHttpServer) => Promise<boolean>);\n\ntype PathDist = RequestFilterType|{request: RequestFilterType, dist: string | ((rr: RequestResponse, app: SimpleBootHttpServer) => string)};\n\ntype DataDist = {request: RequestFilterType, response: (rr: RequestResponse, app: SimpleBootHttpServer) => (string | Promise<Blob | ArrayBuffer | Response>)};\nexport const isPathDist = (item: any): item is PathDist => {\n return typeof item === 'object' && ('request' in item) && ('dist' in item);\n};\nexport const isDataDist = (item: any): item is DataDist => {\n return typeof item === 'object' && ('request' in item) && ('response' in item);\n};\nexport class ResourceFilter implements Filter {\n // private requestFilter: RequestFilterType;\n private resourceDistPath?: string;\n private resources?: (DataDist|PathDist)[];\n constructor(resourceDistPath: string, resourceRegex: PathDist[]);\n constructor(resourceRegex: DataDist[]);\n constructor(resourceDistPathOrResourceRegex: string | DataDist[], resourceRegex?: PathDist[]) {\n if (typeof resourceDistPathOrResourceRegex === 'string') {\n this.resourceDistPath = resourceDistPathOrResourceRegex;\n this.resources = resourceRegex;\n } else {\n this.resources = resourceDistPathOrResourceRegex;\n // this.requestFilter = resourceDistPathOrResourceRegex\n }\n }\n // constructor(private resourceDistPath: string, private resourceRegex: (RequestFilterType | { request: RequestFilterType, dist: string | ((rr: RequestResponse, app: SimpleBootHttpServer) => (string|Promise<Blob |ArrayBuffer| Response>)) })[] = []) {\n // }\n\n async onInit(app: SimpleBootHttpServer) {\n }\n\n async proceedBefore({rr, app}: {rr: RequestResponse, app: SimpleBootHttpServer, carrier: Map<string, any>}) {\n const url = (rr.reqUrlPathName ?? '').replace(/\\.\\./g, '');\n const urlObj = rr.reqUrlObject;\n // const requestUrl = parse(rr.reqUrl ?? '', true);\n // console.log('resource filter!!**-------', url);\n let sw = true;\n const regExps = this.resources?.filter(it => {\n if (it instanceof RegExp) {\n return it.test(url);\n }\n\n if (typeof it === 'string') {\n return RegExp(it).test(url);\n }\n\n if (typeof it === 'function') {\n return it(rr, app);\n }\n\n if (typeof it === 'object' && 'request' in it) {\n if (typeof it.request === 'function') {\n return it.request(rr, app);\n }\n return RegExp(it.request).test(url);\n }\n })??[]\n // console.log('regExps', regExps, url);\n // eslint-disable-next-line no-unused-vars\n for (const it of regExps) {\n sw = false;\n //DataDist\n if (isDataDist(it)) {\n let distValue = typeof it.response === 'function' ? it.response(rr,app) : it.response;\n if (distValue instanceof Promise) {\n const result = await distValue;\n if (result instanceof Response) {\n await rr.resEnd(result);\n break;\n } else if (result instanceof Blob) {\n rr.resStatusCode(HttpStatus.Ok);\n await rr.resEnd(result);\n break;\n }\n }\n } else {\n //PathDist or undefined\n const dist = typeof it === 'object' && 'dist' in it ? it.dist : urlObj.pathname;\n let distValue = typeof dist === 'function' ? dist(rr, app) : dist;\n if (this.resourceDistPath) {\n // It's a string path\n const resourcePath = path.join(this.resourceDistPath, distValue);\n if (fs.existsSync(resourcePath)) {\n rr.resStatusCode(HttpStatus.Ok);\n rr.resSetHeader(HttpHeaders.ContentType, mime.lookup(resourcePath).toString());\n await rr.resEnd(fs.readFileSync(resourcePath));\n break;\n } else {\n rr.resStatusCode(HttpStatus.NotFound);\n await rr.resEnd();\n break;\n }\n } else {\n rr.resStatusCode(HttpStatus.InternalServerError);\n await rr.resEnd();\n break;\n }\n }\n sw = true;\n }\n return sw;\n }\n\n async proceedAfter({rr, app}: {rr: RequestResponse, app: SimpleBootHttpServer, carrier: Map<string, any>}) {\n // console.log('resource filter!!end@@**-------');\n return true;\n }\n}"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAe;AACf,uBAAiB;AACjB,wBAAiB;AACjB,yBAA4B;AAC5B,wBAA2B;AAG3B,yBAAqB;AAOd,MAAM,aAAa,CAAC,SAAgC;AACvD,SAAO,OAAO,SAAS,YAAa,aAAa,QAAU,UAAU;AACzE;AACO,MAAM,aAAa,CAAC,SAAgC;AACvD,SAAO,OAAO,SAAS,YAAa,aAAa,QAAU,cAAc;AAC7E;AACO,MAAM,eAAiC;AAAA,EAM5C,YAAY,iCAAuD,eAA4B;AAC7F,QAAI,OAAO,oCAAoC,UAAU;AACvD,WAAK,mBAAmB;AACxB,WAAK,YAAY;AAAA,IACnB,O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SAAS,aAAa,KAAK,IAAI,GAAG,IAAI;AAC7D,YAAI,KAAK,kBAAkB;AAEzB,gBAAM,eAAe,iBAAAA,QAAK,KAAK,KAAK,kBAAkB,SAAS;AAC/D,cAAI,eAAAC,QAAG,WAAW,YAAY,GAAG;AAC/B,eAAG,cAAc,6BAAW,EAAE;AAC9B,eAAG,aAAa,+BAAY,aAAa,kBAAAC,QAAK,OAAO,YAAY,EAAE,SAAS,CAAC;AAC7E,kBAAM,GAAG,OAAO,eAAAD,QAAG,aAAa,YAAY,CAAC;AAC7C;AAAA,UACF,OAAO;AACL,eAAG,cAAc,6BAAW,QAAQ;AACpC,kBAAM,GAAG,OAAO;AAChB;AAAA,UACF;AAAA,QACF,OAAO;AACL,aAAG,cAAc,6BAAW,mBAAmB;AAC/C,gBAAM,GAAG,OAAO;AAChB;AAAA,QACF;AAAA,MACF;AACF,WAAK;AAAA,IACP;AACA,WAAO;AAAA,EACX;AAAA,EAEA,MAAM,aAAa,EAAC,IAAI,IAAG,GAAgF;AAEvG,WAAO;AAAA,EACX;AACJ;",
4
+ "sourcesContent": ["import { Filter } from '../filters/Filter';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport mime from 'mime-types';\nimport { HttpHeaders } from '../codes/HttpHeaders';\nimport { HttpStatus } from '../codes/HttpStatus';\nimport { SimpleBootHttpServer } from '../SimpleBootHttpServer';\nimport { RequestResponse } from '../models/RequestResponse';\nimport { Blob } from 'node:buffer';\n\nexport type RequestFilterType = string | RegExp | ((rr: RequestResponse, app: SimpleBootHttpServer) => boolean) | ((rr: RequestResponse, app: SimpleBootHttpServer) => Promise<boolean>);\n\ntype PathDist = RequestFilterType|{request: RequestFilterType, dist: string | ((rr: RequestResponse, app: SimpleBootHttpServer) => string)};\n\ntype DataDist = {request: RequestFilterType, response: (rr: RequestResponse, app: SimpleBootHttpServer) => (string | Promise<Blob | ArrayBuffer | Response>)};\nexport const isPathDist = (item: any): item is PathDist => {\n return typeof item === 'object' && ('request' in item) && ('dist' in item);\n};\nexport const isDataDist = (item: any): item is DataDist => {\n return typeof item === 'object' && ('request' in item) && ('response' in item);\n};\nexport class ResourceFilter implements Filter {\n // private requestFilter: RequestFilterType;\n private resourceDistPath?: string;\n private resources?: (DataDist|PathDist)[];\n constructor(resourceDistPath: string, resourceRegex: PathDist[]);\n constructor(resourceRegex: DataDist[]);\n constructor(resourceDistPathOrResourceRegex: string | DataDist[], resourceRegex?: PathDist[]) {\n if (typeof resourceDistPathOrResourceRegex === 'string') {\n this.resourceDistPath = resourceDistPathOrResourceRegex;\n this.resources = resourceRegex;\n } else {\n this.resources = resourceDistPathOrResourceRegex;\n // this.requestFilter = resourceDistPathOrResourceRegex\n }\n }\n // constructor(private resourceDistPath: string, private resourceRegex: (RequestFilterType | { request: RequestFilterType, dist: string | ((rr: RequestResponse, app: SimpleBootHttpServer) => (string|Promise<Blob |ArrayBuffer| Response>)) })[] = []) {\n // }\n\n async onInit(app: SimpleBootHttpServer) {\n }\n\n async proceedBefore({rr, app}: {rr: RequestResponse, app: SimpleBootHttpServer, carrier: Map<string, any>}) {\n const url = (rr.reqUrlPathName ?? '').replace(/\\.\\./g, '');\n const urlObj = rr.reqUrlObject;\n // const requestUrl = parse(rr.reqUrl ?? '', true);\n // console.log('resource filter!!**-------', url);\n let sw = true;\n const regExps = this.resources?.filter(it => {\n // console.log('---it', it, it instanceof RegExp, typeof it)\n if (it instanceof RegExp) {\n // console.log('--------', it.test(url))\n return it.test(url);\n }\n\n if (typeof it === 'string') {\n return RegExp(it).test(url);\n }\n\n if (typeof it === 'function') {\n return it(rr, app);\n }\n\n if (typeof it === 'object' && 'request' in it) {\n if (typeof it.request === 'function') {\n return it.request(rr, app);\n } else if (it .request instanceof RegExp) {\n return it.request.test(url);\n } else {\n return RegExp(it.request).test(url);\n }\n }\n })??[]\n // console.log('regExps', regExps, url);\n // eslint-disable-next-line no-unused-vars\n for (const it of regExps) {\n sw = false;\n //DataDist\n if (isDataDist(it)) {\n let distValue = typeof it.response === 'function' ? it.response(rr,app) : it.response;\n if (distValue instanceof Promise) {\n const result = await distValue;\n if (result instanceof Response) {\n await rr.resEnd(result);\n break;\n } else if (result instanceof Blob) {\n rr.resStatusCode(HttpStatus.Ok);\n await rr.resEnd(result);\n break;\n }\n }\n } else {\n //PathDist or undefined\n const dist = typeof it === 'object' && 'dist' in it ? it.dist : urlObj.pathname;\n let distValue = typeof dist === 'function' ? dist(rr, app) : dist;\n if (this.resourceDistPath) {\n // It's a string path\n const resourcePath = path.join(this.resourceDistPath, distValue);\n // console.log('-----------',this.resourceDistPath, resourcePath);\n if (fs.existsSync(resourcePath)) {\n rr.resStatusCode(HttpStatus.Ok);\n rr.resSetHeader(HttpHeaders.ContentType, mime.lookup(resourcePath).toString());\n await rr.resEnd(fs.readFileSync(resourcePath));\n break;\n } else {\n rr.resStatusCode(HttpStatus.NotFound);\n await rr.resEnd();\n break;\n }\n } else {\n rr.resStatusCode(HttpStatus.InternalServerError);\n await rr.resEnd();\n break;\n }\n }\n sw = true;\n }\n return sw;\n }\n\n async proceedAfter({rr, app}: {rr: RequestResponse, app: SimpleBootHttpServer, carrier: Map<string, any>}) {\n // console.log('resource filter!!end@@**-------');\n return true;\n }\n}"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAe;AACf,uBAAiB;AACjB,wBAAiB;AACjB,yBAA4B;AAC5B,wBAA2B;AAG3B,yBAAqB;AAOd,MAAM,aAAa,CAAC,SAAgC;AACvD,SAAO,OAAO,SAAS,YAAa,aAAa,QAAU,UAAU;AACzE;AACO,MAAM,aAAa,CAAC,SAAgC;AACvD,SAAO,OAAO,SAAS,YAAa,aAAa,QAAU,cAAc;AAC7E;AACO,MAAM,eAAiC;AAAA,EAM5C,YAAY,iCAAuD,eAA4B;AAC7F,QAAI,OAAO,oCAAoC,UAAU;AACvD,WAAK,mBAAmB;AACxB,WAAK,YAAY;AAAA,IACnB,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