@8medusa/framework 2.7.0

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 (274) hide show
  1. package/README.md +0 -0
  2. package/dist/build-tools/compiler.d.ts +64 -0
  3. package/dist/build-tools/compiler.d.ts.map +1 -0
  4. package/dist/build-tools/compiler.js +419 -0
  5. package/dist/build-tools/compiler.js.map +1 -0
  6. package/dist/build-tools/index.d.ts +2 -0
  7. package/dist/build-tools/index.d.ts.map +1 -0
  8. package/dist/build-tools/index.js +18 -0
  9. package/dist/build-tools/index.js.map +1 -0
  10. package/dist/config/config.d.ts +34 -0
  11. package/dist/config/config.d.ts.map +1 -0
  12. package/dist/config/config.js +134 -0
  13. package/dist/config/config.js.map +1 -0
  14. package/dist/config/index.d.ts +5 -0
  15. package/dist/config/index.d.ts.map +1 -0
  16. package/dist/config/index.js +21 -0
  17. package/dist/config/index.js.map +1 -0
  18. package/dist/config/loader.d.ts +11 -0
  19. package/dist/config/loader.d.ts.map +1 -0
  20. package/dist/config/loader.js +35 -0
  21. package/dist/config/loader.js.map +1 -0
  22. package/dist/config/types.d.ts +2 -0
  23. package/dist/config/types.d.ts.map +1 -0
  24. package/dist/config/types.js +3 -0
  25. package/dist/config/types.js.map +1 -0
  26. package/dist/container.d.ts +3 -0
  27. package/dist/container.d.ts.map +1 -0
  28. package/dist/container.js +21 -0
  29. package/dist/container.js.map +1 -0
  30. package/dist/database/index.d.ts +3 -0
  31. package/dist/database/index.d.ts.map +1 -0
  32. package/dist/database/index.js +19 -0
  33. package/dist/database/index.js.map +1 -0
  34. package/dist/database/pg-connection-loader.d.ts +6 -0
  35. package/dist/database/pg-connection-loader.d.ts.map +1 -0
  36. package/dist/database/pg-connection-loader.js +43 -0
  37. package/dist/database/pg-connection-loader.js.map +1 -0
  38. package/dist/feature-flags/feature-flag-loader.d.ts +8 -0
  39. package/dist/feature-flags/feature-flag-loader.d.ts.map +1 -0
  40. package/dist/feature-flags/feature-flag-loader.js +81 -0
  41. package/dist/feature-flags/feature-flag-loader.js.map +1 -0
  42. package/dist/feature-flags/flag-router.d.ts +32 -0
  43. package/dist/feature-flags/flag-router.d.ts.map +1 -0
  44. package/dist/feature-flags/flag-router.js +67 -0
  45. package/dist/feature-flags/flag-router.js.map +1 -0
  46. package/dist/feature-flags/index.d.ts +5 -0
  47. package/dist/feature-flags/index.d.ts.map +1 -0
  48. package/dist/feature-flags/index.js +21 -0
  49. package/dist/feature-flags/index.js.map +1 -0
  50. package/dist/feature-flags/types.d.ts +31 -0
  51. package/dist/feature-flags/types.d.ts.map +1 -0
  52. package/dist/feature-flags/types.js +3 -0
  53. package/dist/feature-flags/types.js.map +1 -0
  54. package/dist/http/express-loader.d.ts +8 -0
  55. package/dist/http/express-loader.d.ts.map +1 -0
  56. package/dist/http/express-loader.js +128 -0
  57. package/dist/http/express-loader.js.map +1 -0
  58. package/dist/http/index.d.ts +15 -0
  59. package/dist/http/index.d.ts.map +1 -0
  60. package/dist/http/index.js +31 -0
  61. package/dist/http/index.js.map +1 -0
  62. package/dist/http/middleware-file-loader.d.ts +33 -0
  63. package/dist/http/middleware-file-loader.d.ts.map +1 -0
  64. package/dist/http/middleware-file-loader.js +173 -0
  65. package/dist/http/middleware-file-loader.js.map +1 -0
  66. package/dist/http/middlewares/apply-default-filters.d.ts +3 -0
  67. package/dist/http/middlewares/apply-default-filters.d.ts.map +1 -0
  68. package/dist/http/middlewares/apply-default-filters.js +32 -0
  69. package/dist/http/middlewares/apply-default-filters.js.map +1 -0
  70. package/dist/http/middlewares/apply-params-as-filters.d.ts +5 -0
  71. package/dist/http/middlewares/apply-params-as-filters.d.ts.map +1 -0
  72. package/dist/http/middlewares/apply-params-as-filters.js +14 -0
  73. package/dist/http/middlewares/apply-params-as-filters.js.map +1 -0
  74. package/dist/http/middlewares/authenticate-middleware.d.ts +13 -0
  75. package/dist/http/middlewares/authenticate-middleware.d.ts.map +1 -0
  76. package/dist/http/middlewares/authenticate-middleware.js +136 -0
  77. package/dist/http/middlewares/authenticate-middleware.js.map +1 -0
  78. package/dist/http/middlewares/bodyparser.d.ts +13 -0
  79. package/dist/http/middlewares/bodyparser.d.ts.map +1 -0
  80. package/dist/http/middlewares/bodyparser.js +62 -0
  81. package/dist/http/middlewares/bodyparser.js.map +1 -0
  82. package/dist/http/middlewares/clear-filters-by-key.d.ts +3 -0
  83. package/dist/http/middlewares/clear-filters-by-key.d.ts.map +1 -0
  84. package/dist/http/middlewares/clear-filters-by-key.js +12 -0
  85. package/dist/http/middlewares/clear-filters-by-key.js.map +1 -0
  86. package/dist/http/middlewares/ensure-publishable-api-key.d.ts +3 -0
  87. package/dist/http/middlewares/ensure-publishable-api-key.d.ts.map +1 -0
  88. package/dist/http/middlewares/ensure-publishable-api-key.js +45 -0
  89. package/dist/http/middlewares/ensure-publishable-api-key.js.map +1 -0
  90. package/dist/http/middlewares/error-handler.d.ts +21 -0
  91. package/dist/http/middlewares/error-handler.d.ts.map +1 -0
  92. package/dist/http/middlewares/error-handler.js +85 -0
  93. package/dist/http/middlewares/error-handler.js.map +1 -0
  94. package/dist/http/middlewares/exception-formatter.d.ts +9 -0
  95. package/dist/http/middlewares/exception-formatter.d.ts.map +1 -0
  96. package/dist/http/middlewares/exception-formatter.js +36 -0
  97. package/dist/http/middlewares/exception-formatter.js.map +1 -0
  98. package/dist/http/middlewares/index.d.ts +8 -0
  99. package/dist/http/middlewares/index.d.ts.map +1 -0
  100. package/dist/http/middlewares/index.js +24 -0
  101. package/dist/http/middlewares/index.js.map +1 -0
  102. package/dist/http/middlewares/set-context.d.ts +3 -0
  103. package/dist/http/middlewares/set-context.d.ts.map +1 -0
  104. package/dist/http/middlewares/set-context.js +18 -0
  105. package/dist/http/middlewares/set-context.js.map +1 -0
  106. package/dist/http/router.d.ts +28 -0
  107. package/dist/http/router.d.ts.map +1 -0
  108. package/dist/http/router.js +252 -0
  109. package/dist/http/router.js.map +1 -0
  110. package/dist/http/routes-finder.d.ts +22 -0
  111. package/dist/http/routes-finder.d.ts.map +1 -0
  112. package/dist/http/routes-finder.js +62 -0
  113. package/dist/http/routes-finder.js.map +1 -0
  114. package/dist/http/routes-loader.d.ts +30 -0
  115. package/dist/http/routes-loader.d.ts.map +1 -0
  116. package/dist/http/routes-loader.js +203 -0
  117. package/dist/http/routes-loader.js.map +1 -0
  118. package/dist/http/routes-sorter.d.ts +105 -0
  119. package/dist/http/routes-sorter.d.ts.map +1 -0
  120. package/dist/http/routes-sorter.js +146 -0
  121. package/dist/http/routes-sorter.js.map +1 -0
  122. package/dist/http/types.d.ts +164 -0
  123. package/dist/http/types.d.ts.map +1 -0
  124. package/dist/http/types.js +16 -0
  125. package/dist/http/types.js.map +1 -0
  126. package/dist/http/utils/define-middlewares.d.ts +22 -0
  127. package/dist/http/utils/define-middlewares.d.ts.map +1 -0
  128. package/dist/http/utils/define-middlewares.js +27 -0
  129. package/dist/http/utils/define-middlewares.js.map +1 -0
  130. package/dist/http/utils/get-query-config.d.ts +42 -0
  131. package/dist/http/utils/get-query-config.d.ts.map +1 -0
  132. package/dist/http/utils/get-query-config.js +183 -0
  133. package/dist/http/utils/get-query-config.js.map +1 -0
  134. package/dist/http/utils/http-compression.d.ts +5 -0
  135. package/dist/http/utils/http-compression.d.ts.map +1 -0
  136. package/dist/http/utils/http-compression.js +33 -0
  137. package/dist/http/utils/http-compression.js.map +1 -0
  138. package/dist/http/utils/maybe-apply-link-filter.d.ts +8 -0
  139. package/dist/http/utils/maybe-apply-link-filter.d.ts.map +1 -0
  140. package/dist/http/utils/maybe-apply-link-filter.js +68 -0
  141. package/dist/http/utils/maybe-apply-link-filter.js.map +1 -0
  142. package/dist/http/utils/refetch-entities.d.ts +5 -0
  143. package/dist/http/utils/refetch-entities.d.ts.map +1 -0
  144. package/dist/http/utils/refetch-entities.js +29 -0
  145. package/dist/http/utils/refetch-entities.js.map +1 -0
  146. package/dist/http/utils/restricted-fields.d.ts +6 -0
  147. package/dist/http/utils/restricted-fields.d.ts.map +1 -0
  148. package/dist/http/utils/restricted-fields.js +30 -0
  149. package/dist/http/utils/restricted-fields.js.map +1 -0
  150. package/dist/http/utils/unless-path.d.ts +9 -0
  151. package/dist/http/utils/unless-path.d.ts.map +1 -0
  152. package/dist/http/utils/unless-path.js +19 -0
  153. package/dist/http/utils/unless-path.js.map +1 -0
  154. package/dist/http/utils/validate-body.d.ts +5 -0
  155. package/dist/http/utils/validate-body.d.ts.map +1 -0
  156. package/dist/http/utils/validate-body.js +23 -0
  157. package/dist/http/utils/validate-body.js.map +1 -0
  158. package/dist/http/utils/validate-query.d.ts +6 -0
  159. package/dist/http/utils/validate-query.d.ts.map +1 -0
  160. package/dist/http/utils/validate-query.js +79 -0
  161. package/dist/http/utils/validate-query.js.map +1 -0
  162. package/dist/http/utils/wrap-handler.d.ts +3 -0
  163. package/dist/http/utils/wrap-handler.d.ts.map +1 -0
  164. package/dist/http/utils/wrap-handler.js +26 -0
  165. package/dist/http/utils/wrap-handler.js.map +1 -0
  166. package/dist/index.d.ts +17 -0
  167. package/dist/index.d.ts.map +1 -0
  168. package/dist/index.js +35 -0
  169. package/dist/index.js.map +1 -0
  170. package/dist/jobs/index.d.ts +2 -0
  171. package/dist/jobs/index.d.ts.map +1 -0
  172. package/dist/jobs/index.js +18 -0
  173. package/dist/jobs/index.js.map +1 -0
  174. package/dist/jobs/job-loader.d.ts +42 -0
  175. package/dist/jobs/job-loader.d.ts.map +1 -0
  176. package/dist/jobs/job-loader.js +78 -0
  177. package/dist/jobs/job-loader.js.map +1 -0
  178. package/dist/links/index.d.ts +2 -0
  179. package/dist/links/index.d.ts.map +1 -0
  180. package/dist/links/index.js +18 -0
  181. package/dist/links/index.js.map +1 -0
  182. package/dist/links/link-loader.d.ts +10 -0
  183. package/dist/links/link-loader.d.ts.map +1 -0
  184. package/dist/links/link-loader.js +74 -0
  185. package/dist/links/link-loader.js.map +1 -0
  186. package/dist/logger/index.d.ts +3 -0
  187. package/dist/logger/index.d.ts.map +1 -0
  188. package/dist/logger/index.js +9 -0
  189. package/dist/logger/index.js.map +1 -0
  190. package/dist/medusa-app-loader.d.ts +51 -0
  191. package/dist/medusa-app-loader.d.ts.map +1 -0
  192. package/dist/medusa-app-loader.js +189 -0
  193. package/dist/medusa-app-loader.js.map +1 -0
  194. package/dist/migrations/index.d.ts +3 -0
  195. package/dist/migrations/index.d.ts.map +1 -0
  196. package/dist/migrations/index.js +19 -0
  197. package/dist/migrations/index.js.map +1 -0
  198. package/dist/migrations/migrator.d.ts +38 -0
  199. package/dist/migrations/migrator.d.ts.map +1 -0
  200. package/dist/migrations/migrator.js +129 -0
  201. package/dist/migrations/migrator.js.map +1 -0
  202. package/dist/migrations/run-migration-scripts.d.ts +17 -0
  203. package/dist/migrations/run-migration-scripts.d.ts.map +1 -0
  204. package/dist/migrations/run-migration-scripts.js +94 -0
  205. package/dist/migrations/run-migration-scripts.js.map +1 -0
  206. package/dist/mikro-orm-cli/bin.d.ts +14 -0
  207. package/dist/mikro-orm-cli/bin.d.ts.map +1 -0
  208. package/dist/mikro-orm-cli/bin.js +54 -0
  209. package/dist/mikro-orm-cli/bin.js.map +1 -0
  210. package/dist/modules-sdk/index.d.ts +2 -0
  211. package/dist/modules-sdk/index.d.ts.map +1 -0
  212. package/dist/modules-sdk/index.js +18 -0
  213. package/dist/modules-sdk/index.js.map +1 -0
  214. package/dist/orchestration/index.d.ts +2 -0
  215. package/dist/orchestration/index.d.ts.map +1 -0
  216. package/dist/orchestration/index.js +18 -0
  217. package/dist/orchestration/index.js.map +1 -0
  218. package/dist/subscribers/index.d.ts +3 -0
  219. package/dist/subscribers/index.d.ts.map +1 -0
  220. package/dist/subscribers/index.js +19 -0
  221. package/dist/subscribers/index.js.map +1 -0
  222. package/dist/subscribers/subscriber-loader.d.ts +12 -0
  223. package/dist/subscribers/subscriber-loader.d.ts.map +1 -0
  224. package/dist/subscribers/subscriber-loader.js +147 -0
  225. package/dist/subscribers/subscriber-loader.js.map +1 -0
  226. package/dist/subscribers/types.d.ts +15 -0
  227. package/dist/subscribers/types.d.ts.map +1 -0
  228. package/dist/subscribers/types.js +3 -0
  229. package/dist/subscribers/types.js.map +1 -0
  230. package/dist/telemetry/index.d.ts +50 -0
  231. package/dist/telemetry/index.d.ts.map +1 -0
  232. package/dist/telemetry/index.js +81 -0
  233. package/dist/telemetry/index.js.map +1 -0
  234. package/dist/types/container.d.ts +62 -0
  235. package/dist/types/container.d.ts.map +1 -0
  236. package/dist/types/container.js +3 -0
  237. package/dist/types/container.js.map +1 -0
  238. package/dist/types/index.d.ts +2 -0
  239. package/dist/types/index.d.ts.map +1 -0
  240. package/dist/types/index.js +18 -0
  241. package/dist/types/index.js.map +1 -0
  242. package/dist/utils/index.d.ts +3 -0
  243. package/dist/utils/index.d.ts.map +1 -0
  244. package/dist/utils/index.js +19 -0
  245. package/dist/utils/index.js.map +1 -0
  246. package/dist/utils/resource-loader.d.ts +26 -0
  247. package/dist/utils/resource-loader.d.ts.map +1 -0
  248. package/dist/utils/resource-loader.js +78 -0
  249. package/dist/utils/resource-loader.js.map +1 -0
  250. package/dist/workflows/index.d.ts +3 -0
  251. package/dist/workflows/index.d.ts.map +1 -0
  252. package/dist/workflows/index.js +19 -0
  253. package/dist/workflows/index.js.map +1 -0
  254. package/dist/workflows/workflow-loader.d.ts +12 -0
  255. package/dist/workflows/workflow-loader.d.ts.map +1 -0
  256. package/dist/workflows/workflow-loader.js +24 -0
  257. package/dist/workflows/workflow-loader.js.map +1 -0
  258. package/dist/workflows-sdk/composer.d.ts +2 -0
  259. package/dist/workflows-sdk/composer.d.ts.map +1 -0
  260. package/dist/workflows-sdk/composer.js +18 -0
  261. package/dist/workflows-sdk/composer.js.map +1 -0
  262. package/dist/workflows-sdk/index.d.ts +3 -0
  263. package/dist/workflows-sdk/index.d.ts.map +1 -0
  264. package/dist/workflows-sdk/index.js +19 -0
  265. package/dist/workflows-sdk/index.js.map +1 -0
  266. package/dist/zod/index.d.ts +2 -0
  267. package/dist/zod/index.d.ts.map +1 -0
  268. package/dist/zod/index.js +18 -0
  269. package/dist/zod/index.js.map +1 -0
  270. package/dist/zod/zod-helpers.d.ts +3 -0
  271. package/dist/zod/zod-helpers.d.ts.map +1 -0
  272. package/dist/zod/zod-helpers.js +95 -0
  273. package/dist/zod/zod-helpers.js.map +1 -0
  274. package/package.json +133 -0
@@ -0,0 +1,105 @@
1
+ import { MiddlewareVerb, RouteVerb } from "./types";
2
+ /**
3
+ * Route represents both the middleware/routes defined via the
4
+ * "defineMiddlewares" method and the routes scanned from
5
+ * the filesystem.
6
+ */
7
+ type Route = {
8
+ /**
9
+ * The route path.
10
+ */
11
+ matcher: string;
12
+ /**
13
+ * Function to handle the request
14
+ */
15
+ handler?: any;
16
+ /**
17
+ * The HTTP method specified as a single value
18
+ */
19
+ method?: RouteVerb;
20
+ /**
21
+ * The HTTP methods this route is supposed to handle.
22
+ */
23
+ methods?: MiddlewareVerb | MiddlewareVerb[];
24
+ };
25
+ /**
26
+ * RoutesBranch represents a branch in a tree of routes. All routes are
27
+ * part of a node in a branch. Following is the list of nodes a branch
28
+ * can have.
29
+ *
30
+ * - global: Global routes for the current branch
31
+ * - regex: Routes using Regex patterns for the current branch
32
+ * - wildcard: Routes using the wildcard character for the current branch
33
+ * - params: Routes using params for the current branch
34
+ * - static: Routes with no dynamic segments for the current branch
35
+ *
36
+ * We separate routes under these nodes, so that we can register them with
37
+ * their priority. Priorities are as follows:
38
+ *
39
+ * - global
40
+ * - regex
41
+ * - wildcard
42
+ * - static
43
+ * - params
44
+ */
45
+ type RoutesBranch<T extends Route> = {
46
+ global: {
47
+ routes: T[];
48
+ children?: {
49
+ [segment: string]: RoutesBranch<T>;
50
+ };
51
+ };
52
+ regex: {
53
+ routes: T[];
54
+ children?: {
55
+ [segment: string]: RoutesBranch<T>;
56
+ };
57
+ };
58
+ wildcard: {
59
+ routes: T[];
60
+ children?: {
61
+ [segment: string]: RoutesBranch<T>;
62
+ };
63
+ };
64
+ params: {
65
+ routes: T[];
66
+ children?: {
67
+ [segment: string]: RoutesBranch<T>;
68
+ };
69
+ };
70
+ static: {
71
+ routes: T[];
72
+ children?: {
73
+ [segment: string]: RoutesBranch<T>;
74
+ };
75
+ };
76
+ };
77
+ /**
78
+ * RoutesSorter exposes the API to sort middleware and inApp route handlers
79
+ * by their priorities. The class converts an array of matchers to a tree
80
+ * like structure and then sort them back to a flat array based upon the
81
+ * priorities of different types of nodes.
82
+ */
83
+ export declare class RoutesSorter<T extends Route> {
84
+ #private;
85
+ constructor(routes: T[]);
86
+ /**
87
+ * Returns the intermediate representation of routes as a tree.
88
+ */
89
+ getTree(): {
90
+ [segment: string]: RoutesBranch<T>;
91
+ };
92
+ /**
93
+ * Sort the input routes. You can optionally specify a custom
94
+ * orderBy array. Defaults to: ["global", "wildcard", "regex", "static", "params"]
95
+ */
96
+ sort(orderBy?: [
97
+ keyof RoutesBranch<T>,
98
+ keyof RoutesBranch<T>,
99
+ keyof RoutesBranch<T>,
100
+ keyof RoutesBranch<T>,
101
+ keyof RoutesBranch<T>
102
+ ]): T[];
103
+ }
104
+ export {};
105
+ //# sourceMappingURL=routes-sorter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes-sorter.d.ts","sourceRoot":"","sources":["../../src/http/routes-sorter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnD;;;;GAIG;AACH,KAAK,KAAK,GAAG;IACX;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAA;IAEb;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAA;CAC5C,CAAA;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,KAAK,YAAY,CAAC,CAAC,SAAS,KAAK,IAAI;IACnC,MAAM,EAAE;QACN,MAAM,EAAE,CAAC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receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _RoutesSorter_instances, _RoutesSorter_orderBy, _RoutesSorter_routesToProcess, _RoutesSorter_routesTree, _RoutesSorter_createBranch, _RoutesSorter_processRoute, _RoutesSorter_sortBranch;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.RoutesSorter = void 0;
16
+ /**
17
+ * RoutesSorter exposes the API to sort middleware and inApp route handlers
18
+ * by their priorities. The class converts an array of matchers to a tree
19
+ * like structure and then sort them back to a flat array based upon the
20
+ * priorities of different types of nodes.
21
+ */
22
+ class RoutesSorter {
23
+ constructor(routes) {
24
+ _RoutesSorter_instances.add(this);
25
+ /**
26
+ * The order in which the routes will be sorted. This
27
+ * can be overridden at the time of call the sort
28
+ * method.
29
+ */
30
+ _RoutesSorter_orderBy.set(this, ["global", "wildcard", "regex", "static", "params"]
31
+ /**
32
+ * Input routes
33
+ */
34
+ );
35
+ /**
36
+ * Input routes
37
+ */
38
+ _RoutesSorter_routesToProcess.set(this, void 0);
39
+ /**
40
+ * Intermediate tree representation for sorting routes
41
+ */
42
+ _RoutesSorter_routesTree.set(this, {
43
+ root: __classPrivateFieldGet(this, _RoutesSorter_instances, "m", _RoutesSorter_createBranch).call(this),
44
+ });
45
+ __classPrivateFieldSet(this, _RoutesSorter_routesToProcess, routes, "f");
46
+ }
47
+ /**
48
+ * Returns the intermediate representation of routes as a tree.
49
+ */
50
+ getTree() {
51
+ return __classPrivateFieldGet(this, _RoutesSorter_routesTree, "f");
52
+ }
53
+ /**
54
+ * Sort the input routes. You can optionally specify a custom
55
+ * orderBy array. Defaults to: ["global", "wildcard", "regex", "static", "params"]
56
+ */
57
+ sort(orderBy) {
58
+ __classPrivateFieldGet(this, _RoutesSorter_routesToProcess, "f").map((route) => __classPrivateFieldGet(this, _RoutesSorter_instances, "m", _RoutesSorter_processRoute).call(this, route));
59
+ return __classPrivateFieldGet(this, _RoutesSorter_instances, "m", _RoutesSorter_sortBranch).call(this, __classPrivateFieldGet(this, _RoutesSorter_routesTree, "f"), orderBy ?? __classPrivateFieldGet(this, _RoutesSorter_orderBy, "f"));
60
+ }
61
+ }
62
+ exports.RoutesSorter = RoutesSorter;
63
+ _RoutesSorter_orderBy = new WeakMap(), _RoutesSorter_routesToProcess = new WeakMap(), _RoutesSorter_routesTree = new WeakMap(), _RoutesSorter_instances = new WeakSet(), _RoutesSorter_createBranch = function _RoutesSorter_createBranch() {
64
+ return {
65
+ global: {
66
+ routes: [],
67
+ },
68
+ regex: {
69
+ routes: [],
70
+ },
71
+ wildcard: {
72
+ routes: [],
73
+ },
74
+ static: {
75
+ routes: [],
76
+ },
77
+ params: {
78
+ routes: [],
79
+ },
80
+ };
81
+ }, _RoutesSorter_processRoute = function _RoutesSorter_processRoute(route) {
82
+ const segments = route.matcher.split("/").filter((s) => s.length);
83
+ let parent = __classPrivateFieldGet(this, _RoutesSorter_routesTree, "f")["root"];
84
+ segments.forEach((segment, index) => {
85
+ let bucket = "static";
86
+ if (!route.methods && !route.method) {
87
+ bucket = "global";
88
+ }
89
+ else if (segment.startsWith("*")) {
90
+ bucket = "wildcard";
91
+ }
92
+ else if (segment.startsWith(":")) {
93
+ bucket = "params";
94
+ }
95
+ else if (/[\(\+\*\[\]\)\!]/.test(segment)) {
96
+ bucket = "regex";
97
+ }
98
+ if (index + 1 === segments.length) {
99
+ parent[bucket].routes.push(route);
100
+ return;
101
+ }
102
+ parent[bucket].children = parent[bucket].children ?? {};
103
+ parent[bucket].children[segment] =
104
+ parent[bucket].children[segment] ?? __classPrivateFieldGet(this, _RoutesSorter_instances, "m", _RoutesSorter_createBranch).call(this);
105
+ parent = parent[bucket].children[segment];
106
+ });
107
+ }, _RoutesSorter_sortBranch = function _RoutesSorter_sortBranch(routeBranch, orderBy) {
108
+ const branchRoutes = Object.keys(routeBranch).reduce((result, branchKey) => {
109
+ const node = routeBranch[branchKey];
110
+ result.global.push(...node.global.routes);
111
+ if (node.global.children) {
112
+ result.global.push(...__classPrivateFieldGet(this, _RoutesSorter_instances, "m", _RoutesSorter_sortBranch).call(this, node.global.children, orderBy));
113
+ }
114
+ result.wildcard.push(...node.wildcard.routes);
115
+ if (node.wildcard.children) {
116
+ result.wildcard.push(...__classPrivateFieldGet(this, _RoutesSorter_instances, "m", _RoutesSorter_sortBranch).call(this, node.wildcard.children, orderBy));
117
+ }
118
+ result.regex.push(...node.regex.routes);
119
+ if (node.regex.children) {
120
+ result.regex.push(...__classPrivateFieldGet(this, _RoutesSorter_instances, "m", _RoutesSorter_sortBranch).call(this, node.regex.children, orderBy));
121
+ }
122
+ result.static.push(...node.static.routes);
123
+ if (node.static.children) {
124
+ result.static.push(...__classPrivateFieldGet(this, _RoutesSorter_instances, "m", _RoutesSorter_sortBranch).call(this, node.static.children, orderBy));
125
+ }
126
+ result.params.push(...node.params.routes);
127
+ if (node.params.children) {
128
+ result.params.push(...__classPrivateFieldGet(this, _RoutesSorter_instances, "m", _RoutesSorter_sortBranch).call(this, node.params.children, orderBy));
129
+ }
130
+ return result;
131
+ }, {
132
+ global: [],
133
+ wildcard: [],
134
+ regex: [],
135
+ params: [],
136
+ static: [],
137
+ });
138
+ /**
139
+ * Concatenating routes as per their priority.
140
+ */
141
+ return orderBy.reduce((result, branch) => {
142
+ result = result.concat(branchRoutes[branch]);
143
+ return result;
144
+ }, []);
145
+ };
146
+ //# sourceMappingURL=routes-sorter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes-sorter.js","sourceRoot":"","sources":["../../src/http/routes-sorter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsFA;;;;;GAKG;AACH,MAAa,YAAY;IA4BvB,YAAY,MAAW;;QA3BvB;;;;WAIG;QACH,gCAMI,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC;QAEvD;;WAEG;UAJoD;QAEvD;;WAEG;QACH,gDAAqB;QAErB;;WAEG;QACH,mCAEI;YACF,IAAI,EAAE,uBAAA,IAAI,2DAAc,MAAlB,IAAI,CAAgB;SAC3B,EAAA;QAGC,uBAAA,IAAI,iCAAoB,MAAM,MAAA,CAAA;IAChC,CAAC;IAyJD;;OAEG;IACH,OAAO;QACL,OAAO,uBAAA,IAAI,gCAAY,CAAA;IACzB,CAAC;IAED;;;OAGG;IACH,IAAI,CACF,OAMC;QAED,uBAAA,IAAI,qCAAiB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,uBAAA,IAAI,2DAAc,MAAlB,IAAI,EAAe,KAAK,CAAC,CAAC,CAAA;QAC/D,OAAO,uBAAA,IAAI,yDAAY,MAAhB,IAAI,EAAa,uBAAA,IAAI,gCAAY,EAAE,OAAO,IAAI,uBAAA,IAAI,6BAAS,CAAC,CAAA;IACrE,CAAC;CACF;AA9MD,oCA8MC;;IA1KG,OAAO;QACL,MAAM,EAAE;YACN,MAAM,EAAE,EAAE;SACX;QACD,KAAK,EAAE;YACL,MAAM,EAAE,EAAE;SACX;QACD,QAAQ,EAAE;YACR,MAAM,EAAE,EAAE;SACX;QACD,MAAM,EAAE;YACN,MAAM,EAAE,EAAE;SACX;QACD,MAAM,EAAE;YACN,MAAM,EAAE,EAAE;SACX;KACF,CAAA;AACH,CAAC,mEA+Ba,KAAQ;I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,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACzC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,uBAAA,IAAI,yDAAY,MAAhB,IAAI,EAAa,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;QACxE,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACzC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,uBAAA,IAAI,yDAAY,MAAhB,IAAI,EAAa,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;QACxE,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,EACD;QACE,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,EAAE;KACX,CACF,CAAA;IAED;;OAEG;IACH,OAAO,OAAO,CAAC,MAAM,CAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QAC5C,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;QAC5C,OAAO,MAAM,CAAA;IACf,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC"}
@@ -0,0 +1,164 @@
1
+ import type { NextFunction, Request, Response } from "express";
2
+ import type { ZodNullable, ZodObject, ZodOptional, ZodRawShape } from "zod";
3
+ import { FindConfig, MedusaPricingContext, RequestQueryFields } from "@8medusa/types";
4
+ import { MedusaContainer } from "../container";
5
+ import { RestrictedFields } from "./utils/restricted-fields";
6
+ /**
7
+ * List of all the supported HTTP methods
8
+ */
9
+ export declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
10
+ export type RouteVerb = (typeof HTTP_METHODS)[number];
11
+ export type MiddlewareVerb = "USE" | "ALL" | RouteVerb;
12
+ type SyncRouteHandler = (req: MedusaRequest, res: MedusaResponse) => void;
13
+ export type AsyncRouteHandler = (req: MedusaRequest, res: MedusaResponse) => Promise<void>;
14
+ export type RouteHandler = SyncRouteHandler | AsyncRouteHandler;
15
+ export type MiddlewareFunction = MedusaRequestHandler | ((...args: any[]) => any);
16
+ export type MedusaErrorHandlerFunction = (error: any, req: MedusaRequest, res: MedusaResponse, next: MedusaNextFunction) => Promise<void> | void;
17
+ export type ParserConfigArgs = {
18
+ sizeLimit?: string | number | undefined;
19
+ preserveRawBody?: boolean;
20
+ };
21
+ export type ParserConfig = false | ParserConfigArgs;
22
+ export type MiddlewareRoute = {
23
+ /**
24
+ * @deprecated. Instead use {@link MiddlewareRoute.methods}
25
+ */
26
+ method?: MiddlewareVerb | MiddlewareVerb[];
27
+ methods?: MiddlewareVerb[];
28
+ matcher: string | RegExp;
29
+ bodyParser?: ParserConfig;
30
+ additionalDataValidator?: ZodRawShape;
31
+ middlewares?: MiddlewareFunction[];
32
+ };
33
+ export type MiddlewaresConfig = {
34
+ errorHandler?: false | MedusaErrorHandlerFunction;
35
+ routes?: MiddlewareRoute[];
36
+ };
37
+ /**
38
+ * Route descriptor refers represents a route either scanned
39
+ * from the filesystem or registered manually. It does not
40
+ * represent a middleware
41
+ */
42
+ export type RouteDescriptor = {
43
+ matcher: string;
44
+ method: RouteVerb;
45
+ handler: RouteHandler;
46
+ optedOutOfAuth: boolean;
47
+ isRoute: true;
48
+ routeType?: "admin" | "store" | "auth";
49
+ absolutePath?: string;
50
+ relativePath?: string;
51
+ shouldAppendAdminCors: boolean;
52
+ shouldAppendStoreCors: boolean;
53
+ shouldAppendAuthCors: boolean;
54
+ };
55
+ /**
56
+ * Represents a middleware
57
+ */
58
+ export type MiddlewareDescriptor = {
59
+ matcher: string;
60
+ methods?: MiddlewareVerb | MiddlewareVerb[];
61
+ handler: MiddlewareFunction;
62
+ };
63
+ export type BodyParserConfigRoute = {
64
+ matcher: string;
65
+ methods: MiddlewareVerb | MiddlewareVerb[];
66
+ config: ParserConfig;
67
+ };
68
+ export type AdditionalDataValidatorRoute = {
69
+ matcher: string;
70
+ methods: MiddlewareVerb | MiddlewareVerb[];
71
+ schema: ZodRawShape;
72
+ validator: ZodOptional<ZodNullable<ZodObject<any, any>>>;
73
+ };
74
+ export type GlobalMiddlewareDescriptor = {
75
+ config?: MiddlewaresConfig;
76
+ };
77
+ export interface MedusaRequest<Body = unknown, QueryFields = Record<string, unknown>> extends Request<{
78
+ [key: string]: string;
79
+ }, any, Body> {
80
+ validatedBody: Body;
81
+ validatedQuery: RequestQueryFields & QueryFields;
82
+ /**
83
+ * TODO: shouldn't this correspond to returnable fields instead of allowed fields? also it is used by the cleanResponseData util
84
+ */
85
+ allowedProperties: string[];
86
+ /**
87
+ * An object containing the select, relation, skip, take and order to be used with medusa internal services
88
+ */
89
+ listConfig: FindConfig<unknown>;
90
+ /**
91
+ * An object containing the select, relation to be used with medusa internal services
92
+ */
93
+ retrieveConfig: FindConfig<unknown>;
94
+ /**
95
+ * An object containing fields and variables to be used with the remoteQuery
96
+ *
97
+ * @version 2.2.0
98
+ */
99
+ queryConfig: {
100
+ fields: string[];
101
+ pagination: {
102
+ order?: Record<string, string>;
103
+ skip: number;
104
+ take?: number;
105
+ };
106
+ };
107
+ /**
108
+ * @deprecated Use {@link queryConfig} instead.
109
+ */
110
+ remoteQueryConfig: MedusaRequest["queryConfig"];
111
+ /**
112
+ * An object containing the fields that are filterable e.g `{ id: Any<String> }`
113
+ */
114
+ filterableFields: QueryFields;
115
+ includes?: Record<string, boolean>;
116
+ /**
117
+ * An array of fields and relations that are allowed to be queried, this can be set by the
118
+ * consumer as part of a middleware and it will take precedence over the req.allowed set
119
+ * by the api
120
+ */
121
+ allowed?: string[];
122
+ errors: string[];
123
+ scope: MedusaContainer;
124
+ session?: any;
125
+ rawBody?: any;
126
+ requestId?: string;
127
+ restrictedFields?: RestrictedFields;
128
+ /**
129
+ * An object that carries the context that is used to calculate prices for variants
130
+ */
131
+ pricingContext?: MedusaPricingContext;
132
+ /**
133
+ * A generic context object that can be used across the request lifecycle
134
+ */
135
+ context?: Record<string, any>;
136
+ /**
137
+ * Custom validator to validate the `additional_data` property in
138
+ * requests that allows for additional_data
139
+ */
140
+ additionalDataValidator?: ZodOptional<ZodNullable<ZodObject<any, any>>>;
141
+ }
142
+ export interface AuthContext {
143
+ actor_id: string;
144
+ actor_type: string;
145
+ auth_identity_id: string;
146
+ app_metadata: Record<string, unknown>;
147
+ }
148
+ export interface PublishableKeyContext {
149
+ key: string;
150
+ sales_channel_ids: string[];
151
+ }
152
+ export interface AuthenticatedMedusaRequest<Body = unknown, QueryFields = Record<string, unknown>> extends MedusaRequest<Body, QueryFields> {
153
+ auth_context: AuthContext;
154
+ publishable_key_context?: PublishableKeyContext;
155
+ }
156
+ export interface MedusaStoreRequest<Body = unknown, QueryFields = Record<string, unknown>> extends MedusaRequest<Body, QueryFields> {
157
+ auth_context?: AuthContext;
158
+ publishable_key_context: PublishableKeyContext;
159
+ }
160
+ export type MedusaResponse<Body = unknown> = Response<Body>;
161
+ export type MedusaNextFunction = NextFunction;
162
+ export type MedusaRequestHandler<Body = unknown, Res = unknown> = (req: MedusaRequest<Body>, res: MedusaResponse<Res>, next: MedusaNextFunction) => Promise<void> | void;
163
+ export {};
164
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/http/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,E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AI,CAAC,CAAA;AAE3D,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAA;AAE7C,MAAM,MAAM,oBAAoB,CAAC,IAAI,GAAG,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,CAChE,GAAG,EAAE,aAAa,CAAC,IAAI,CAAC,EACxB,GAAG,EAAE,cAAc,CAAC,GAAG,CAAC,EACxB,IAAI,EAAE,kBAAkB,KACrB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HTTP_METHODS = void 0;
4
+ /**
5
+ * List of all the supported HTTP methods
6
+ */
7
+ exports.HTTP_METHODS = [
8
+ "GET",
9
+ "POST",
10
+ "PUT",
11
+ "PATCH",
12
+ "DELETE",
13
+ "OPTIONS",
14
+ "HEAD",
15
+ ];
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/http/types.ts"],"names":[],"mappings":";;;AAWA;;GAEG;AACU,QAAA,YAAY,GAAG;IAC1B,KAAK;IACL,MAAM;IACN,KAAK;IACL,OAAO;IACP,QAAQ;IACR,SAAS;IACT,MAAM;CACE,CAAA"}
@@ -0,0 +1,22 @@
1
+ import { MedusaNextFunction, MedusaRequest, MedusaResponse, MiddlewaresConfig, MiddlewareVerb, ParserConfig } from "../types";
2
+ import { ZodRawShape } from "zod";
3
+ /**
4
+ * A helper function to configure the routes by defining custom middleware,
5
+ * bodyparser config and validators to be merged with the pre-existing
6
+ * route validators.
7
+ */
8
+ export declare function defineMiddlewares<Route extends {
9
+ /**
10
+ * @deprecated. Instead use {@link MiddlewareRoute.methods}
11
+ */
12
+ method?: MiddlewareVerb | MiddlewareVerb[];
13
+ methods?: MiddlewareVerb[];
14
+ matcher: string | RegExp;
15
+ bodyParser?: ParserConfig;
16
+ additionalDataValidator?: ZodRawShape;
17
+ middlewares?: (<Req extends MedusaRequest>(req: Req, res: MedusaResponse, next: MedusaNextFunction) => any)[];
18
+ }>(config: Route[] | {
19
+ routes?: Route[];
20
+ errorHandler?: MiddlewaresConfig["errorHandler"];
21
+ }): MiddlewaresConfig;
22
+ //# sourceMappingURL=define-middlewares.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-middlewares.d.ts","sourceRoot":"","sources":["../../../src/http/utils/define-middlewares.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,YAAY,EACb,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAA;AAEjC;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,SAAS;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAA;IAC1C,OAAO,CAAC,EAAE,cAAc,EAAE,CAAA;IAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,UAAU,CAAC,EAAE,YAAY,CAAA;IACzB,uBAAuB,CAAC,EAAE,WAAW,CAAA;IAErC,WAAW,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,aAAa,EACvC,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,kBAAkB,KACrB,GAAG,CAAC,EAAE,CAAA;CACZ,EAED,MAAM,EACF,KAAK,EAAE,GACP;IAAE,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IAAC,YAAY,CAAC,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAA;CAAE,GACzE,iBAAiB,CAmBnB"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineMiddlewares = defineMiddlewares;
4
+ /**
5
+ * A helper function to configure the routes by defining custom middleware,
6
+ * bodyparser config and validators to be merged with the pre-existing
7
+ * route validators.
8
+ */
9
+ function defineMiddlewares(config) {
10
+ const routes = Array.isArray(config) ? config : config.routes || [];
11
+ const errorHandler = Array.isArray(config) ? undefined : config.errorHandler;
12
+ return {
13
+ errorHandler,
14
+ routes: routes.map((route) => {
15
+ let { middlewares, method, methods, ...rest } = route;
16
+ if (!methods) {
17
+ methods = Array.isArray(method) ? method : method ? [method] : method;
18
+ }
19
+ return {
20
+ ...rest,
21
+ methods,
22
+ middlewares: [...(middlewares ?? [])],
23
+ };
24
+ }),
25
+ };
26
+ }
27
+ //# sourceMappingURL=define-middlewares.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-middlewares.js","sourceRoot":"","sources":["../../../src/http/utils/define-middlewares.ts"],"names":[],"mappings":";;AAeA,8CAwCC;AA7CD;;;;GAIG;AACH,SAAgB,iBAAiB,CAkB/B,MAE0E;IAE1E,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAA;IACnE,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAA;IAE5E,OAAO;QACL,YAAY;QACZ,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC3B,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAA;YACrD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;YACvE,CAAC;YAED,OAAO;gBACL,GAAG,IAAI;gBACP,OAAO;gBACP,WAAW,EAAE,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;aACtC,CAAA;QACH,CAAC,CAAC;KACH,CAAA;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { FindConfig, QueryConfig, RequestQueryFields } from "@8medusa/types";
2
+ export declare function pickByConfig<TModel>(obj: TModel | TModel[], config: FindConfig<TModel>): Partial<TModel> | Partial<TModel>[];
3
+ export declare function prepareListQuery<T extends RequestQueryFields, TEntity>(validated: T, queryConfig?: QueryConfig<TEntity> & {
4
+ restricted?: string[];
5
+ }): {
6
+ listConfig: {
7
+ select: string[] | undefined;
8
+ relations: string[];
9
+ skip: number;
10
+ take: number;
11
+ order: {
12
+ [k: symbol]: "DESC" | "ASC";
13
+ } | undefined;
14
+ };
15
+ remoteQueryConfig: {
16
+ fields: string[];
17
+ pagination: {
18
+ skip: number;
19
+ take: number;
20
+ order: {
21
+ [k: symbol]: "DESC" | "ASC";
22
+ } | undefined;
23
+ } | {
24
+ skip?: undefined;
25
+ take?: undefined;
26
+ order?: undefined;
27
+ };
28
+ };
29
+ };
30
+ export declare function prepareRetrieveQuery<T extends RequestQueryFields, TEntity>(validated: T, queryConfig?: QueryConfig<TEntity> & {
31
+ restricted?: string[];
32
+ }): {
33
+ retrieveConfig: {
34
+ select: string[] | undefined;
35
+ relations: string[];
36
+ };
37
+ remoteQueryConfig: {
38
+ fields: string[];
39
+ pagination: {};
40
+ };
41
+ };
42
+ //# sourceMappingURL=get-query-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-query-config.d.ts","sourceRoot":"","sources":["../../../src/http/utils/get-query-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAS5E,wBAAgB,YAAY,CAAC,MAAM,EACjC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EACtB,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,GACzB,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAWrC;AAoED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,kBAAkB,EAAE,OAAO,EACpE,SAAS,EAAE,CAAC,EACZ,WAAW,GAAE,WAAW,CAAC,OAAO,CAAC,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO;;;;;;;;;;;;;;;;;;;;;;;;EAiJnE;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,kBAAkB,EAAE,OAAO,EACxE,SAAS,EAAE,CAAC,EACZ,WAAW,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE;;;;;;;;;EAiB/D"}