@etohq/framework 1.0.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 (234) hide show
  1. package/README.md +0 -0
  2. package/dist/build-tools/compiler.d.ts +49 -0
  3. package/dist/build-tools/compiler.d.ts.map +1 -0
  4. package/dist/build-tools/compiler.js +291 -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 +132 -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 +901 -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 +37 -0
  37. package/dist/database/pg-connection-loader.js.map +1 -0
  38. package/dist/eto-app-loader.d.ts +51 -0
  39. package/dist/eto-app-loader.d.ts.map +1 -0
  40. package/dist/eto-app-loader.js +183 -0
  41. package/dist/eto-app-loader.js.map +1 -0
  42. package/dist/feature-flags/feature-flag-loader.d.ts +8 -0
  43. package/dist/feature-flags/feature-flag-loader.d.ts.map +1 -0
  44. package/dist/feature-flags/feature-flag-loader.js +81 -0
  45. package/dist/feature-flags/feature-flag-loader.js.map +1 -0
  46. package/dist/feature-flags/flag-router.d.ts +32 -0
  47. package/dist/feature-flags/flag-router.d.ts.map +1 -0
  48. package/dist/feature-flags/flag-router.js +67 -0
  49. package/dist/feature-flags/flag-router.js.map +1 -0
  50. package/dist/feature-flags/index.d.ts +5 -0
  51. package/dist/feature-flags/index.d.ts.map +1 -0
  52. package/dist/feature-flags/index.js +21 -0
  53. package/dist/feature-flags/index.js.map +1 -0
  54. package/dist/feature-flags/types.d.ts +31 -0
  55. package/dist/feature-flags/types.d.ts.map +1 -0
  56. package/dist/feature-flags/types.js +3 -0
  57. package/dist/feature-flags/types.js.map +1 -0
  58. package/dist/http/express-loader.d.ts +8 -0
  59. package/dist/http/express-loader.d.ts.map +1 -0
  60. package/dist/http/express-loader.js +85 -0
  61. package/dist/http/express-loader.js.map +1 -0
  62. package/dist/http/index.d.ts +15 -0
  63. package/dist/http/index.d.ts.map +1 -0
  64. package/dist/http/index.js +31 -0
  65. package/dist/http/index.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 +11 -0
  75. package/dist/http/middlewares/authenticate-middleware.d.ts.map +1 -0
  76. package/dist/http/middlewares/authenticate-middleware.js +135 -0
  77. package/dist/http/middlewares/authenticate-middleware.js.map +1 -0
  78. package/dist/http/middlewares/clear-filters-by-key.d.ts +3 -0
  79. package/dist/http/middlewares/clear-filters-by-key.d.ts.map +1 -0
  80. package/dist/http/middlewares/clear-filters-by-key.js +12 -0
  81. package/dist/http/middlewares/clear-filters-by-key.js.map +1 -0
  82. package/dist/http/middlewares/ensure-publishable-api-key.d.ts +3 -0
  83. package/dist/http/middlewares/ensure-publishable-api-key.d.ts.map +1 -0
  84. package/dist/http/middlewares/ensure-publishable-api-key.js +49 -0
  85. package/dist/http/middlewares/ensure-publishable-api-key.js.map +1 -0
  86. package/dist/http/middlewares/error-handler.d.ts +23 -0
  87. package/dist/http/middlewares/error-handler.d.ts.map +1 -0
  88. package/dist/http/middlewares/error-handler.js +85 -0
  89. package/dist/http/middlewares/error-handler.js.map +1 -0
  90. package/dist/http/middlewares/exception-formatter.d.ts +9 -0
  91. package/dist/http/middlewares/exception-formatter.d.ts.map +1 -0
  92. package/dist/http/middlewares/exception-formatter.js +36 -0
  93. package/dist/http/middlewares/exception-formatter.js.map +1 -0
  94. package/dist/http/middlewares/index.d.ts +8 -0
  95. package/dist/http/middlewares/index.d.ts.map +1 -0
  96. package/dist/http/middlewares/index.js +24 -0
  97. package/dist/http/middlewares/index.js.map +1 -0
  98. package/dist/http/middlewares/set-context.d.ts +3 -0
  99. package/dist/http/middlewares/set-context.d.ts.map +1 -0
  100. package/dist/http/middlewares/set-context.js +18 -0
  101. package/dist/http/middlewares/set-context.js.map +1 -0
  102. package/dist/http/router.d.ts +100 -0
  103. package/dist/http/router.d.ts.map +1 -0
  104. package/dist/http/router.js +764 -0
  105. package/dist/http/router.js.map +1 -0
  106. package/dist/http/types.d.ts +141 -0
  107. package/dist/http/types.d.ts.map +1 -0
  108. package/dist/http/types.js +16 -0
  109. package/dist/http/types.js.map +1 -0
  110. package/dist/http/utils/define-middlewares.d.ts +18 -0
  111. package/dist/http/utils/define-middlewares.d.ts.map +1 -0
  112. package/dist/http/utils/define-middlewares.js +40 -0
  113. package/dist/http/utils/define-middlewares.js.map +1 -0
  114. package/dist/http/utils/get-query-config.d.ts +42 -0
  115. package/dist/http/utils/get-query-config.d.ts.map +1 -0
  116. package/dist/http/utils/get-query-config.js +183 -0
  117. package/dist/http/utils/get-query-config.js.map +1 -0
  118. package/dist/http/utils/http-compression.d.ts +5 -0
  119. package/dist/http/utils/http-compression.d.ts.map +1 -0
  120. package/dist/http/utils/http-compression.js +33 -0
  121. package/dist/http/utils/http-compression.js.map +1 -0
  122. package/dist/http/utils/maybe-apply-link-filter.d.ts +8 -0
  123. package/dist/http/utils/maybe-apply-link-filter.d.ts.map +1 -0
  124. package/dist/http/utils/maybe-apply-link-filter.js +71 -0
  125. package/dist/http/utils/maybe-apply-link-filter.js.map +1 -0
  126. package/dist/http/utils/refetch-entities.d.ts +5 -0
  127. package/dist/http/utils/refetch-entities.d.ts.map +1 -0
  128. package/dist/http/utils/refetch-entities.js +29 -0
  129. package/dist/http/utils/refetch-entities.js.map +1 -0
  130. package/dist/http/utils/restricted-fields.d.ts +6 -0
  131. package/dist/http/utils/restricted-fields.d.ts.map +1 -0
  132. package/dist/http/utils/restricted-fields.js +30 -0
  133. package/dist/http/utils/restricted-fields.js.map +1 -0
  134. package/dist/http/utils/unless-path.d.ts +9 -0
  135. package/dist/http/utils/unless-path.d.ts.map +1 -0
  136. package/dist/http/utils/unless-path.js +19 -0
  137. package/dist/http/utils/unless-path.js.map +1 -0
  138. package/dist/http/utils/validate-body.d.ts +5 -0
  139. package/dist/http/utils/validate-body.d.ts.map +1 -0
  140. package/dist/http/utils/validate-body.js +23 -0
  141. package/dist/http/utils/validate-body.js.map +1 -0
  142. package/dist/http/utils/validate-query.d.ts +6 -0
  143. package/dist/http/utils/validate-query.d.ts.map +1 -0
  144. package/dist/http/utils/validate-query.js +79 -0
  145. package/dist/http/utils/validate-query.js.map +1 -0
  146. package/dist/index.d.ts +16 -0
  147. package/dist/index.d.ts.map +1 -0
  148. package/dist/index.js +34 -0
  149. package/dist/index.js.map +1 -0
  150. package/dist/jobs/index.d.ts +2 -0
  151. package/dist/jobs/index.d.ts.map +1 -0
  152. package/dist/jobs/index.js +18 -0
  153. package/dist/jobs/index.js.map +1 -0
  154. package/dist/jobs/job-loader.d.ts +37 -0
  155. package/dist/jobs/job-loader.d.ts.map +1 -0
  156. package/dist/jobs/job-loader.js +130 -0
  157. package/dist/jobs/job-loader.js.map +1 -0
  158. package/dist/links/index.d.ts +2 -0
  159. package/dist/links/index.d.ts.map +1 -0
  160. package/dist/links/index.js +18 -0
  161. package/dist/links/index.js.map +1 -0
  162. package/dist/links/link-loader.d.ts +10 -0
  163. package/dist/links/link-loader.d.ts.map +1 -0
  164. package/dist/links/link-loader.js +74 -0
  165. package/dist/links/link-loader.js.map +1 -0
  166. package/dist/logger/index.d.ts +3 -0
  167. package/dist/logger/index.d.ts.map +1 -0
  168. package/dist/logger/index.js +9 -0
  169. package/dist/logger/index.js.map +1 -0
  170. package/dist/mikro-orm-cli/bin.d.ts +14 -0
  171. package/dist/mikro-orm-cli/bin.d.ts.map +1 -0
  172. package/dist/mikro-orm-cli/bin.js +54 -0
  173. package/dist/mikro-orm-cli/bin.js.map +1 -0
  174. package/dist/modules-sdk/index.d.ts +2 -0
  175. package/dist/modules-sdk/index.d.ts.map +1 -0
  176. package/dist/modules-sdk/index.js +18 -0
  177. package/dist/modules-sdk/index.js.map +1 -0
  178. package/dist/orchestration/index.d.ts +2 -0
  179. package/dist/orchestration/index.d.ts.map +1 -0
  180. package/dist/orchestration/index.js +18 -0
  181. package/dist/orchestration/index.js.map +1 -0
  182. package/dist/subscribers/index.d.ts +3 -0
  183. package/dist/subscribers/index.d.ts.map +1 -0
  184. package/dist/subscribers/index.js +19 -0
  185. package/dist/subscribers/index.js.map +1 -0
  186. package/dist/subscribers/subscriber-loader.d.ts +11 -0
  187. package/dist/subscribers/subscriber-loader.d.ts.map +1 -0
  188. package/dist/subscribers/subscriber-loader.js +196 -0
  189. package/dist/subscribers/subscriber-loader.js.map +1 -0
  190. package/dist/subscribers/types.d.ts +15 -0
  191. package/dist/subscribers/types.d.ts.map +1 -0
  192. package/dist/subscribers/types.js +3 -0
  193. package/dist/subscribers/types.js.map +1 -0
  194. package/dist/telemetry/index.d.ts +50 -0
  195. package/dist/telemetry/index.d.ts.map +1 -0
  196. package/dist/telemetry/index.js +81 -0
  197. package/dist/telemetry/index.js.map +1 -0
  198. package/dist/types/container.d.ts +62 -0
  199. package/dist/types/container.d.ts.map +1 -0
  200. package/dist/types/container.js +3 -0
  201. package/dist/types/container.js.map +1 -0
  202. package/dist/types/index.d.ts +2 -0
  203. package/dist/types/index.d.ts.map +1 -0
  204. package/dist/types/index.js +18 -0
  205. package/dist/types/index.js.map +1 -0
  206. package/dist/utils/index.d.ts +3 -0
  207. package/dist/utils/index.d.ts.map +1 -0
  208. package/dist/utils/index.js +19 -0
  209. package/dist/utils/index.js.map +1 -0
  210. package/dist/workflows/index.d.ts +3 -0
  211. package/dist/workflows/index.d.ts.map +1 -0
  212. package/dist/workflows/index.js +19 -0
  213. package/dist/workflows/index.js.map +1 -0
  214. package/dist/workflows/workflow-loader.d.ts +10 -0
  215. package/dist/workflows/workflow-loader.d.ts.map +1 -0
  216. package/dist/workflows/workflow-loader.js +74 -0
  217. package/dist/workflows/workflow-loader.js.map +1 -0
  218. package/dist/workflows-sdk/composer.d.ts +2 -0
  219. package/dist/workflows-sdk/composer.d.ts.map +1 -0
  220. package/dist/workflows-sdk/composer.js +18 -0
  221. package/dist/workflows-sdk/composer.js.map +1 -0
  222. package/dist/workflows-sdk/index.d.ts +3 -0
  223. package/dist/workflows-sdk/index.d.ts.map +1 -0
  224. package/dist/workflows-sdk/index.js +19 -0
  225. package/dist/workflows-sdk/index.js.map +1 -0
  226. package/dist/zod/index.d.ts +2 -0
  227. package/dist/zod/index.d.ts.map +1 -0
  228. package/dist/zod/index.js +18 -0
  229. package/dist/zod/index.js.map +1 -0
  230. package/dist/zod/zod-helpers.d.ts +3 -0
  231. package/dist/zod/zod-helpers.d.ts.map +1 -0
  232. package/dist/zod/zod-helpers.js +95 -0
  233. package/dist/zod/zod-helpers.js.map +1 -0
  234. package/package.json +120 -0
package/README.md ADDED
File without changes
@@ -0,0 +1,49 @@
1
+ import type tsStatic from "typescript";
2
+ import type { AdminOptions, Logger } from "@etohq/types";
3
+ /**
4
+ * The compiler exposes the opinionated APIs for compiling Eto
5
+ * applications and plugins. You can perform the following
6
+ * actions.
7
+ *
8
+ * - loadTSConfigFile: Load and parse the TypeScript config file. All errors
9
+ * will be reported using the logger.
10
+ *
11
+ * - buildAppBackend: Compile the Eto application backend source code to the
12
+ * ".eto/server" directory. The admin source and integration-tests are
13
+ * skipped.
14
+ *
15
+ * - buildAppFrontend: Compile the admin extensions using the "@etohq/admin-bundler"
16
+ * package. Admin can be compiled for self hosting (aka adminOnly), or can be compiled
17
+ * to be bundled with the backend output.
18
+ */
19
+ export declare class Compiler {
20
+ #private;
21
+ constructor(projectRoot: string, logger: Logger);
22
+ /**
23
+ * Loads and parses the TypeScript config file. In case of an error, the errors
24
+ * will be logged using the logger and undefined it returned
25
+ */
26
+ loadTSConfigFile(): Promise<tsStatic.ParsedCommandLine | undefined>;
27
+ /**
28
+ * Builds the application backend source code using
29
+ * TypeScript's official compiler. Also performs
30
+ * type-checking
31
+ */
32
+ buildAppBackend(tsConfig: tsStatic.ParsedCommandLine): Promise<boolean>;
33
+ /**
34
+ * Builds the frontend source code of a Eto application
35
+ * using the "@etohq/admin-bundler" package.
36
+ */
37
+ buildAppFrontend(adminOnly: boolean, tsConfig: tsStatic.ParsedCommandLine, adminBundler: {
38
+ build: (options: AdminOptions & {
39
+ sources: string[];
40
+ outDir: string;
41
+ }) => Promise<void>;
42
+ }): Promise<boolean>;
43
+ /**
44
+ * @todo. To be implemented
45
+ */
46
+ buildPluginBackend(): void;
47
+ developPluginBacked(): void;
48
+ }
49
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/build-tools/compiler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA;AAGtC,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAA;AAEtE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,QAAQ;;gBAOP,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAkK/C;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,QAAQ,CAAC,iBAAiB,GAAG,SAAS,CAAC;IA4CzE;;;;OAIG;IACG,eAAe,CACnB,QAAQ,EAAE,QAAQ,CAAC,iBAAiB,GACnC,OAAO,CAAC,OAAO,CAAC;IAmDnB;;;OAGG;IACG,gBAAgB,CACpB,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,QAAQ,CAAC,iBAAiB,EACpC,YAAY,EAAE;QACZ,KAAK,EAAE,CACL,OAAO,EAAE,YAAY,GAAG;YACtB,OAAO,EAAE,MAAM,EAAE,CAAA;YACjB,MAAM,EAAE,MAAM,CAAA;SACf,KACE,OAAO,CAAC,IAAI,CAAC,CAAA;KACnB,GACA,OAAO,CAAC,OAAO,CAAC;IAuDnB;;OAEG;IACH,kBAAkB;IAClB,mBAAmB;CACpB"}
@@ -0,0 +1,291 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (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 __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _Compiler_instances, _Compiler_logger, _Compiler_projectRoot, _Compiler_adminSourceFolder, _Compiler_adminOnlyDistFolder, _Compiler_tsCompiler, _Compiler_trackDuration, _Compiler_computeDist, _Compiler_loadTSCompiler, _Compiler_copy, _Compiler_copyPkgManagerFiles, _Compiler_clean, _Compiler_loadEtoConfig, _Compiler_emitBuildOutput;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Compiler = void 0;
19
+ const path_1 = __importDefault(require("path"));
20
+ const utils_1 = require("@etohq/utils");
21
+ const promises_1 = require("fs/promises");
22
+ /**
23
+ * The compiler exposes the opinionated APIs for compiling Eto
24
+ * applications and plugins. You can perform the following
25
+ * actions.
26
+ *
27
+ * - loadTSConfigFile: Load and parse the TypeScript config file. All errors
28
+ * will be reported using the logger.
29
+ *
30
+ * - buildAppBackend: Compile the Eto application backend source code to the
31
+ * ".eto/server" directory. The admin source and integration-tests are
32
+ * skipped.
33
+ *
34
+ * - buildAppFrontend: Compile the admin extensions using the "@etohq/admin-bundler"
35
+ * package. Admin can be compiled for self hosting (aka adminOnly), or can be compiled
36
+ * to be bundled with the backend output.
37
+ */
38
+ class Compiler {
39
+ constructor(projectRoot, logger) {
40
+ _Compiler_instances.add(this);
41
+ _Compiler_logger.set(this, void 0);
42
+ _Compiler_projectRoot.set(this, void 0);
43
+ _Compiler_adminSourceFolder.set(this, void 0);
44
+ _Compiler_adminOnlyDistFolder.set(this, void 0);
45
+ _Compiler_tsCompiler.set(this, void 0);
46
+ __classPrivateFieldSet(this, _Compiler_projectRoot, projectRoot, "f");
47
+ __classPrivateFieldSet(this, _Compiler_logger, logger, "f");
48
+ __classPrivateFieldSet(this, _Compiler_adminSourceFolder, path_1.default.join(__classPrivateFieldGet(this, _Compiler_projectRoot, "f"), "src/admin"), "f");
49
+ __classPrivateFieldSet(this, _Compiler_adminOnlyDistFolder, path_1.default.join(__classPrivateFieldGet(this, _Compiler_projectRoot, "f"), ".eto/admin"), "f");
50
+ }
51
+ /**
52
+ * Loads and parses the TypeScript config file. In case of an error, the errors
53
+ * will be logged using the logger and undefined it returned
54
+ */
55
+ async loadTSConfigFile() {
56
+ const ts = await __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_loadTSCompiler).call(this);
57
+ let tsConfigErrors = [];
58
+ const tsConfig = ts.getParsedCommandLineOfConfigFile(path_1.default.join(__classPrivateFieldGet(this, _Compiler_projectRoot, "f"), "tsconfig.json"), {
59
+ inlineSourceMap: true,
60
+ excludes: [],
61
+ }, {
62
+ ...ts.sys,
63
+ useCaseSensitiveFileNames: true,
64
+ getCurrentDirectory: () => __classPrivateFieldGet(this, _Compiler_projectRoot, "f"),
65
+ onUnRecoverableConfigFileDiagnostic: (error) => (tsConfigErrors = [error]),
66
+ });
67
+ /**
68
+ * Push errors from the tsConfig parsed output to the
69
+ * tsConfigErrors array.
70
+ */
71
+ if (tsConfig?.errors.length) {
72
+ tsConfigErrors.push(...tsConfig.errors);
73
+ }
74
+ /**
75
+ * Display all config errors using the diagnostics reporter
76
+ */
77
+ if (tsConfigErrors.length) {
78
+ const compilerHost = ts.createCompilerHost({});
79
+ __classPrivateFieldGet(this, _Compiler_logger, "f").error(ts.formatDiagnosticsWithColorAndContext(tsConfigErrors, compilerHost));
80
+ return;
81
+ }
82
+ /**
83
+ * If there are no errors, the `tsConfig` object will always exist.
84
+ */
85
+ return tsConfig;
86
+ }
87
+ /**
88
+ * Builds the application backend source code using
89
+ * TypeScript's official compiler. Also performs
90
+ * type-checking
91
+ */
92
+ async buildAppBackend(tsConfig) {
93
+ const tracker = __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_trackDuration).call(this);
94
+ const dist = __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_computeDist).call(this, tsConfig);
95
+ __classPrivateFieldGet(this, _Compiler_logger, "f").info("Compiling backend source...");
96
+ /**
97
+ * Step 1: Cleanup existing build output
98
+ */
99
+ __classPrivateFieldGet(this, _Compiler_logger, "f").info(`Removing existing "${path_1.default.relative(__classPrivateFieldGet(this, _Compiler_projectRoot, "f"), dist)}" folder`);
100
+ await __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_clean).call(this, dist);
101
+ /**
102
+ * Step 2: Compile TypeScript source code
103
+ */
104
+ const { emitResult, diagnostics } = await __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_emitBuildOutput).call(this, tsConfig, ["integration-tests", "test", "unit-tests", "src/admin"], dist);
105
+ /**
106
+ * Exit early if no output is written to the disk
107
+ */
108
+ if (emitResult.emitSkipped) {
109
+ __classPrivateFieldGet(this, _Compiler_logger, "f").warn("Backend build completed without emitting any output");
110
+ return false;
111
+ }
112
+ /**
113
+ * Step 3: Copy package manager files to the output folder
114
+ */
115
+ await __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_copyPkgManagerFiles).call(this, dist);
116
+ /**
117
+ * Notify about the state of build
118
+ */
119
+ if (diagnostics.length) {
120
+ __classPrivateFieldGet(this, _Compiler_logger, "f").warn(`Backend build completed with errors (${tracker.getSeconds()}s)`);
121
+ }
122
+ else {
123
+ __classPrivateFieldGet(this, _Compiler_logger, "f").info(`Backend build completed successfully (${tracker.getSeconds()}s)`);
124
+ }
125
+ return true;
126
+ }
127
+ /**
128
+ * Builds the frontend source code of a Eto application
129
+ * using the "@etohq/admin-bundler" package.
130
+ */
131
+ async buildAppFrontend(adminOnly, tsConfig, adminBundler) {
132
+ const tracker = __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_trackDuration).call(this);
133
+ /**
134
+ * Step 1: Load the eto config file to read
135
+ * admin options
136
+ */
137
+ const configFile = await __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_loadEtoConfig).call(this);
138
+ if (!configFile) {
139
+ return false;
140
+ }
141
+ /**
142
+ * Return early when admin is disabled and we are trying to
143
+ * create a bundled build for the admin.
144
+ */
145
+ if (configFile.configModule.admin.disable && !adminOnly) {
146
+ __classPrivateFieldGet(this, _Compiler_logger, "f").info("Skipping admin build, since its disabled inside the eto-config file");
147
+ return false;
148
+ }
149
+ /**
150
+ * Warn when we are creating an admin only build, but forgot to disable
151
+ * the admin inside the config file
152
+ */
153
+ if (!configFile.configModule.admin.disable && adminOnly) {
154
+ __classPrivateFieldGet(this, _Compiler_logger, "f").warn(`You are building using the flag --admin-only but the admin is enabled in your eto-config, If you intend to host the dashboard separately you should disable the admin in your eto config`);
155
+ }
156
+ try {
157
+ __classPrivateFieldGet(this, _Compiler_logger, "f").info("Compiling frontend source...");
158
+ await adminBundler.build({
159
+ disable: false,
160
+ sources: [__classPrivateFieldGet(this, _Compiler_adminSourceFolder, "f")],
161
+ ...configFile.configModule.admin,
162
+ outDir: adminOnly
163
+ ? __classPrivateFieldGet(this, _Compiler_adminOnlyDistFolder, "f")
164
+ : path_1.default.join(__classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_computeDist).call(this, tsConfig), "./public/admin"),
165
+ });
166
+ __classPrivateFieldGet(this, _Compiler_logger, "f").info(`Frontend build completed successfully (${tracker.getSeconds()}s)`);
167
+ return true;
168
+ }
169
+ catch (error) {
170
+ __classPrivateFieldGet(this, _Compiler_logger, "f").error("Unable to compile frontend source");
171
+ __classPrivateFieldGet(this, _Compiler_logger, "f").error(error);
172
+ return false;
173
+ }
174
+ }
175
+ /**
176
+ * @todo. To be implemented
177
+ */
178
+ buildPluginBackend() { }
179
+ developPluginBacked() { }
180
+ }
181
+ exports.Compiler = Compiler;
182
+ _Compiler_logger = new WeakMap(), _Compiler_projectRoot = new WeakMap(), _Compiler_adminSourceFolder = new WeakMap(), _Compiler_adminOnlyDistFolder = new WeakMap(), _Compiler_tsCompiler = new WeakMap(), _Compiler_instances = new WeakSet(), _Compiler_trackDuration = function _Compiler_trackDuration() {
183
+ const startTime = process.hrtime();
184
+ return {
185
+ getSeconds() {
186
+ const duration = process.hrtime(startTime);
187
+ return (duration[0] + duration[1] / 1e9).toFixed(2);
188
+ },
189
+ };
190
+ }, _Compiler_computeDist = function _Compiler_computeDist(tsConfig) {
191
+ const distFolder = tsConfig.options.outDir ?? ".eto/server";
192
+ return path_1.default.isAbsolute(distFolder)
193
+ ? distFolder
194
+ : path_1.default.join(__classPrivateFieldGet(this, _Compiler_projectRoot, "f"), distFolder);
195
+ }, _Compiler_loadTSCompiler =
196
+ /**
197
+ * Imports and stores a reference to the TypeScript compiler.
198
+ * We dynamically import "typescript", since its is a dev
199
+ * only dependency
200
+ */
201
+ async function _Compiler_loadTSCompiler() {
202
+ if (!__classPrivateFieldGet(this, _Compiler_tsCompiler, "f")) {
203
+ __classPrivateFieldSet(this, _Compiler_tsCompiler, await import("typescript"), "f");
204
+ }
205
+ return __classPrivateFieldGet(this, _Compiler_tsCompiler, "f");
206
+ }, _Compiler_copy =
207
+ /**
208
+ * Copies the file to the destination without throwing any
209
+ * errors if the source file is missing
210
+ */
211
+ async function _Compiler_copy(source, destination) {
212
+ let sourceExists = false;
213
+ try {
214
+ await (0, promises_1.access)(source, promises_1.constants.F_OK);
215
+ sourceExists = true;
216
+ }
217
+ catch (error) {
218
+ if (error.code !== "ENOENT") {
219
+ throw error;
220
+ }
221
+ }
222
+ if (sourceExists) {
223
+ await (0, promises_1.copyFile)(path_1.default.join(source), path_1.default.join(destination));
224
+ }
225
+ }, _Compiler_copyPkgManagerFiles =
226
+ /**
227
+ * Copies package manager files from the project root
228
+ * to the specified dist folder
229
+ */
230
+ async function _Compiler_copyPkgManagerFiles(dist) {
231
+ /**
232
+ * Copying package manager files
233
+ */
234
+ await __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_copy).call(this, path_1.default.join(__classPrivateFieldGet(this, _Compiler_projectRoot, "f"), "package.json"), path_1.default.join(dist, "package.json"));
235
+ await __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_copy).call(this, path_1.default.join(__classPrivateFieldGet(this, _Compiler_projectRoot, "f"), "yarn.lock"), path_1.default.join(dist, "yarn.lock"));
236
+ await __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_copy).call(this, path_1.default.join(__classPrivateFieldGet(this, _Compiler_projectRoot, "f"), "pnpm.lock"), path_1.default.join(dist, "pnpm.lock"));
237
+ await __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_copy).call(this, path_1.default.join(__classPrivateFieldGet(this, _Compiler_projectRoot, "f"), "package-lock.json"), path_1.default.join(dist, "package-lock.json"));
238
+ }, _Compiler_clean =
239
+ /**
240
+ * Removes the directory and its children recursively and
241
+ * ignores any errors
242
+ */
243
+ async function _Compiler_clean(path) {
244
+ await (0, promises_1.rm)(path, { recursive: true }).catch(() => { });
245
+ }, _Compiler_loadEtoConfig =
246
+ /**
247
+ * Loads the eto config file and prints the error to
248
+ * the console (in case of any errors). Otherwise, the
249
+ * file path and the parsed config is returned
250
+ */
251
+ async function _Compiler_loadEtoConfig() {
252
+ const { configModule, configFilePath, error } = await (0, utils_1.getConfigFile)(__classPrivateFieldGet(this, _Compiler_projectRoot, "f"), "eto-config");
253
+ if (error) {
254
+ __classPrivateFieldGet(this, _Compiler_logger, "f").error(`Failed to load eto-config.(js|ts) file`);
255
+ __classPrivateFieldGet(this, _Compiler_logger, "f").error(error);
256
+ return;
257
+ }
258
+ return { configFilePath, configModule };
259
+ }, _Compiler_emitBuildOutput =
260
+ /**
261
+ * Given a tsconfig file, this method will write the compiled
262
+ * output to the specified destination
263
+ */
264
+ async function _Compiler_emitBuildOutput(tsConfig, chunksToIgnore, dist) {
265
+ const ts = await __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_loadTSCompiler).call(this);
266
+ const filesToCompile = tsConfig.fileNames.filter((fileName) => {
267
+ return !chunksToIgnore.some((chunk) => fileName.includes(`${chunk}/`));
268
+ });
269
+ /**
270
+ * Create emit program to compile and emit output
271
+ */
272
+ const program = ts.createProgram(filesToCompile, {
273
+ ...tsConfig.options,
274
+ ...{
275
+ outDir: dist,
276
+ inlineSourceMap: !tsConfig.options.sourceMap,
277
+ },
278
+ });
279
+ const emitResult = program.emit();
280
+ const diagnostics = ts
281
+ .getPreEmitDiagnostics(program)
282
+ .concat(emitResult.diagnostics);
283
+ /**
284
+ * Log errors (if any)
285
+ */
286
+ if (diagnostics.length) {
287
+ console.error(ts.formatDiagnosticsWithColorAndContext(diagnostics, ts.createCompilerHost({})));
288
+ }
289
+ return { emitResult, diagnostics };
290
+ };
291
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../src/build-tools/compiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,gDAAuB;AAEvB,wCAA4C;AAC5C,0CAA6D;AAG7D;;;;;;;;;;;;;;;GAeG;AACH,MAAa,QAAQ;IAOnB,YAAY,WAAmB,EAAE,MAAc;;QAN/C,mCAAe;QACf,wCAAoB;QACpB,8CAA0B;QAC1B,gDAA4B;QAC5B,uCAA6B;QAG3B,uBAAA,IAAI,yBAAgB,WAAW,MAAA,CAAA;QAC/B,uBAAA,IAAI,oBAAW,MAAM,MAAA,CAAA;QACrB,uBAAA,IAAI,+BAAsB,cAAI,CAAC,IAAI,CAAC,uBAAA,IAAI,6BAAa,EAAE,WAAW,CAAC,MAAA,CAAA;QACnE,uBAAA,IAAI,iCAAwB,cAAI,CAAC,IAAI,CAAC,uBAAA,IAAI,6BAAa,EAAE,YAAY,CAAC,MAAA,CAAA;IACxE,CAAC;IA6JD;;;OAGG;IACH,KAAK,CAAC,gBAAgB;QACpB,MAAM,EAAE,GAAG,MAAM,uBAAA,IAAI,qDAAgB,MAApB,IAAI,CAAkB,CAAA;QACvC,IAAI,cAAc,GAA0B,EAAE,CAAA;QAE9C,MAAM,QAAQ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file":"index.d.ts","sourceRoot":"","sources":["../../src/build-tools/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./compiler"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/build-tools/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B"}
@@ -0,0 +1,34 @@
1
+ import { ConfigModule } from "./types";
2
+ export declare class ConfigManager {
3
+ #private;
4
+ get config(): ConfigModule;
5
+ get baseDir(): string;
6
+ get isProduction(): boolean;
7
+ constructor();
8
+ /**
9
+ * Rejects an error either by throwing when in production or by logging the error as a warning
10
+ * @param error
11
+ * @protected
12
+ */
13
+ protected rejectErrors(error: string): never | void;
14
+ /**
15
+ * Builds the http config object and assign the defaults if needed
16
+ * @param projectConfig
17
+ * @protected
18
+ */
19
+ protected buildHttpConfig(projectConfig: Partial<ConfigModule["projectConfig"]>): ConfigModule["projectConfig"]["http"];
20
+ /**
21
+ * Normalizes the project config object and assign the defaults if needed
22
+ * @param projectConfig
23
+ * @protected
24
+ */
25
+ protected normalizeProjectConfig(projectConfig: Partial<ConfigModule["projectConfig"]>): ConfigModule["projectConfig"];
26
+ /**
27
+ * Prepare the full configuration after validation and normalization
28
+ */
29
+ loadConfig({ projectConfig, baseDir, }: {
30
+ projectConfig: Partial<ConfigModule>;
31
+ baseDir: string;
32
+ }): ConfigModule;
33
+ }
34
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAItC,qBAAa,aAAa;;IA8BxB,IAAI,MAAM,IAAI,YAAY,CAOzB;IAED,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,YAAY,IAAI,OAAO,CAE1B;;IAID;;;;OAIG;IACH,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAQnD;;;;OAIG;IACH,SAAS,CAAC,eAAe,CACvB,aAAa,EAAE,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,GACpD,YAAY,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC;IAqCxC;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,CAC9B,aAAa,EAAE,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,GACpD,YAAY,CAAC,eAAe,CAAC;IA+BhC;;OAEG;IACH,UAAU,CAAC,EACT,aAAkB,EAClB,OAAO,GACR,EAAE;QACD,aAAa,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;QACpC,OAAO,EAAE,MAAM,CAAA;KAChB,GAAG,YAAY;CAiBjB"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ 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");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var _ConfigManager_instances, _ConfigManager_baseDir, _ConfigManager_isProduction_get, _ConfigManager_envWorkMode_get, _ConfigManager_config;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ConfigManager = void 0;
16
+ const utils_1 = require("@etohq/utils");
17
+ const logger_1 = require("../logger");
18
+ class ConfigManager {
19
+ get config() {
20
+ if (!__classPrivateFieldGet(this, _ConfigManager_config, "f")) {
21
+ this.rejectErrors(`Config not loaded. Make sure the config have been loaded first using the 'configLoader' or 'configManager.loadConfig'.`);
22
+ }
23
+ return __classPrivateFieldGet(this, _ConfigManager_config, "f");
24
+ }
25
+ get baseDir() {
26
+ return __classPrivateFieldGet(this, _ConfigManager_baseDir, "f");
27
+ }
28
+ get isProduction() {
29
+ return __classPrivateFieldGet(this, _ConfigManager_instances, "a", _ConfigManager_isProduction_get);
30
+ }
31
+ constructor() {
32
+ _ConfigManager_instances.add(this);
33
+ /**
34
+ * Root dir from where to start
35
+ * @private
36
+ */
37
+ _ConfigManager_baseDir.set(this, void 0);
38
+ /**
39
+ * The config object after loading it
40
+ * @private
41
+ */
42
+ _ConfigManager_config.set(this, void 0);
43
+ }
44
+ /**
45
+ * Rejects an error either by throwing when in production or by logging the error as a warning
46
+ * @param error
47
+ * @protected
48
+ */
49
+ rejectErrors(error) {
50
+ if (__classPrivateFieldGet(this, _ConfigManager_instances, "a", _ConfigManager_isProduction_get)) {
51
+ throw new Error(`[config] ⚠️ ${error}`);
52
+ }
53
+ logger_1.logger.warn(error);
54
+ }
55
+ /**
56
+ * Builds the http config object and assign the defaults if needed
57
+ * @param projectConfig
58
+ * @protected
59
+ */
60
+ buildHttpConfig(projectConfig) {
61
+ const http = (projectConfig.http ??
62
+ {});
63
+ http.jwtExpiresIn = http?.jwtExpiresIn ?? "1d";
64
+ http.authCors = http.authCors ?? "";
65
+ http.storeCors = http.storeCors ?? "";
66
+ http.adminCors = http.adminCors ?? "";
67
+ http.jwtSecret = http?.jwtSecret ?? process.env.JWT_SECRET;
68
+ if (!http.jwtSecret) {
69
+ this.rejectErrors(`http.jwtSecret not found.${__classPrivateFieldGet(this, _ConfigManager_instances, "a", _ConfigManager_isProduction_get) ? "" : "Using default 'supersecret'."}`);
70
+ http.jwtSecret = "supersecret";
71
+ }
72
+ http.cookieSecret = (projectConfig.http?.cookieSecret ??
73
+ process.env.COOKIE_SECRET);
74
+ if (!http.cookieSecret) {
75
+ this.rejectErrors(`http.cookieSecret not found.${__classPrivateFieldGet(this, _ConfigManager_instances, "a", _ConfigManager_isProduction_get) ? "" : " Using default 'supersecret'."}`);
76
+ http.cookieSecret = "supersecret";
77
+ }
78
+ return http;
79
+ }
80
+ /**
81
+ * Normalizes the project config object and assign the defaults if needed
82
+ * @param projectConfig
83
+ * @protected
84
+ */
85
+ normalizeProjectConfig(projectConfig) {
86
+ const outputConfig = (0, utils_1.deepCopy)(projectConfig);
87
+ if (!outputConfig?.redisUrl) {
88
+ console.log(`redisUrl not found. A fake redis instance will be used.`);
89
+ }
90
+ outputConfig.http = this.buildHttpConfig(projectConfig);
91
+ let workerMode = outputConfig?.workerMode;
92
+ if (!(0, utils_1.isDefined)(workerMode)) {
93
+ const env = __classPrivateFieldGet(this, _ConfigManager_instances, "a", _ConfigManager_envWorkMode_get);
94
+ if ((0, utils_1.isDefined)(env)) {
95
+ const workerModes = ["shared", "worker", "server"];
96
+ if (workerModes.includes(env)) {
97
+ workerMode = env;
98
+ }
99
+ }
100
+ else {
101
+ workerMode = "shared";
102
+ }
103
+ }
104
+ return {
105
+ ...outputConfig,
106
+ workerMode,
107
+ };
108
+ }
109
+ /**
110
+ * Prepare the full configuration after validation and normalization
111
+ */
112
+ loadConfig({ projectConfig = {}, baseDir, }) {
113
+ __classPrivateFieldSet(this, _ConfigManager_baseDir, baseDir, "f");
114
+ const normalizedProjectConfig = this.normalizeProjectConfig(projectConfig.projectConfig ?? {});
115
+ __classPrivateFieldSet(this, _ConfigManager_config, {
116
+ projectConfig: normalizedProjectConfig,
117
+ admin: projectConfig.admin ?? {},
118
+ modules: projectConfig.modules ?? {},
119
+ featureFlags: projectConfig.featureFlags ?? {},
120
+ plugins: projectConfig.plugins ?? [],
121
+ }, "f");
122
+ return __classPrivateFieldGet(this, _ConfigManager_config, "f");
123
+ }
124
+ }
125
+ exports.ConfigManager = ConfigManager;
126
+ _ConfigManager_baseDir = new WeakMap(), _ConfigManager_config = new WeakMap(), _ConfigManager_instances = new WeakSet(), _ConfigManager_isProduction_get = function _ConfigManager_isProduction_get() {
127
+ return ["production", "prod"].includes(process.env.NODE_ENV || "");
128
+ }, _ConfigManager_envWorkMode_get = function _ConfigManager_envWorkMode_get() {
129
+ return process.env
130
+ .ETO_WORKER_MODE;
131
+ };
132
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,wCAAkD;AAClD,sCAAkC;AAElC,MAAa,aAAa;IA8BxB,IAAI,MAAM;QACR,IAAI,CAAC,uBAAA,IAAI,6BAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,YAAY,CACf,wHAAwH,CACzH,CAAA;QACH,CAAC;QACD,OAAO,uBAAA,IAAI,6BAAQ,CAAA;IACrB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,uBAAA,IAAI,8BAAS,CAAA;IACtB,CAAC;IAED,IAAI,YAAY;QACd,OAA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I,yBAAW;YACb,aAAa,EAAE,uBAAuB;YACtC,KAAK,EAAE,aAAa,CAAC,KAAK,IAAI,EAAE;YAChC,OAAO,EAAE,aAAa,CAAC,OAAO,IAAI,EAAE;YACpC,YAAY,EAAE,aAAa,CAAC,YAAY,IAAI,EAAE;YAC9C,OAAO,EAAE,aAAa,CAAC,OAAO,IAAI,EAAE;SACrC,MAAA,CAAA;QAED,OAAO,uBAAA,IAAI,6BAAQ,CAAA;IACrB,CAAC;CACF;AA1KD,sCA0KC;;IA9JG,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;AACpE,CAAC;IAOC,OAAO,OAAO,CAAC,GAAG;SACf,eAA8D,CAAA;AACnE,CAAC"}
@@ -0,0 +1,5 @@
1
+ import "../types/container";
2
+ export * from "./loader";
3
+ export * from "./config";
4
+ export * from "./types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAA;AAE3B,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ require("../types/container");
18
+ __exportStar(require("./loader"), exports);
19
+ __exportStar(require("./config"), exports);
20
+ __exportStar(require("./types"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8BAA2B;AAE3B,2CAAwB;AACxB,2CAAwB;AACxB,0CAAuB"}
@@ -0,0 +1,11 @@
1
+ import { ConfigModule } from "./types";
2
+ import { ConfigManager } from "./config";
3
+ export declare const configManager: ConfigManager;
4
+ /**
5
+ * Loads the config file and returns the config module after validating, normalizing the configurations
6
+ *
7
+ * @param entryDirectory The directory to find the config file from
8
+ * @param configFileName The name of the config file to search for in the entry directory
9
+ */
10
+ export declare function configLoader(entryDirectory: string, configFileName: string): Promise<ConfigModule>;
11
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAGtC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAYxC,eAAO,MAAM,aAAa,eAAsB,CAAA;AAOhD;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,YAAY,CAAC,CAcvB"}