@izumisy-tailor/omakase-modules 0.1.0 → 0.3.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.
@@ -1,62 +0,0 @@
1
- //#region src/config/module-registry.ts
2
- const registry = /* @__PURE__ */ new Map();
3
- const clearModuleRegistry = () => {
4
- registry.clear();
5
- };
6
- const registerConfiguredModules = (modules) => {
7
- modules.forEach((module) => {
8
- registry.set(module.packageName, module);
9
- });
10
- return modules;
11
- };
12
- const getConfiguredModule = (packageName) => {
13
- return registry.get(packageName);
14
- };
15
-
16
- //#endregion
17
- //#region src/config/module-loader.ts
18
- /**
19
- * Module loader
20
- * Builder for registering modules within loadModules
21
- */
22
- var ModuleLoader = class {
23
- modules = [];
24
- /**
25
- * Add a module to the loader
26
- * @param module Configured module
27
- * @returns The added module (can be used as a dependency for other modules)
28
- */
29
- add(module) {
30
- this.modules.push(module);
31
- return module;
32
- }
33
- /**
34
- * Get all registered modules
35
- * @internal
36
- */
37
- _getModules() {
38
- return this.modules;
39
- }
40
- };
41
- /**
42
- * Load modules with configuration
43
- * @param configurator Function that receives a loader, registers modules, and returns the loader
44
- * @returns Loaded modules and loadConfig function
45
- */
46
- const loadModules = (configurator) => {
47
- clearModuleRegistry();
48
- return {
49
- loadedModules: registerConfiguredModules(configurator(new ModuleLoader())._getModules()).reduce((acc, module) => {
50
- acc[module.packageName] = module;
51
- return acc;
52
- }, {}),
53
- loadConfig: (module) => {
54
- const loadedModule = getConfiguredModule(module.packageName);
55
- if (!loadedModule) throw new Error(`Module "${module.packageName}" has not been configured. Ensure it is added via loadModules.`);
56
- return { config: loadedModule.moduleProps.config };
57
- }
58
- };
59
- };
60
-
61
- //#endregion
62
- export { ModuleLoader, loadModules };
@@ -1,10 +0,0 @@
1
- import { t as LoadedModules } from "../../module-loader-B4sA1i0A.mjs";
2
-
3
- //#region src/config/sdk/paths.d.ts
4
- declare const getModulesReference: (loadedModules: LoadedModules) => {
5
- tailordb: string[];
6
- resolver: string[];
7
- executor: string[];
8
- };
9
- //#endregion
10
- export { getModulesReference };
@@ -1,14 +0,0 @@
1
- import path from "node:path";
2
-
3
- //#region src/config/sdk/paths.ts
4
- const getModulesReference = (loadedModules) => {
5
- const modulePackageNames = Object.keys(loadedModules.loadedModules);
6
- return {
7
- tailordb: modulePackageNames.map((name) => path.join("node_modules", name, "dist", "tailordb", "*.mjs")),
8
- resolver: modulePackageNames.map((name) => path.join("node_modules", name, "dist", "resolvers", "*.mjs")),
9
- executor: modulePackageNames.map((name) => path.join("node_modules", name, "dist", "executors", "*.mjs"))
10
- };
11
- };
12
-
13
- //#endregion
14
- export { getModulesReference };
@@ -1,29 +0,0 @@
1
- //#region src/builder/helpers.d.ts
2
- type ModuleBuilderProps<C$1 extends Record<string, unknown>> = {
3
- config: C$1;
4
- };
5
- type ConfiguredModule<C$1 extends Record<string, unknown> = Record<string, unknown>> = {
6
- packageName: string;
7
- moduleProps: ModuleBuilderProps<C$1>;
8
- };
9
- type DefinedModule<C$1 extends Record<string, unknown>, Tables$1 extends Record<string, unknown> = Record<string, unknown>> = {
10
- packageName: string;
11
- configure: (props: ModuleBuilderProps<C$1>) => ConfiguredModule<C$1>;
12
- /**
13
- * @internal Type-only hook so that table shapes flow through helper utilities.
14
- */
15
- readonly __tablesBrand?: Tables$1;
16
- };
17
- declare const defineModule: <C$1 extends Record<string, unknown>, Tables$1 extends Record<string, unknown> = Record<string, unknown>>(baseProps: {
18
- /**
19
- * The package name of the module.
20
- *
21
- * This is required to be the same as the name field in package.json
22
- */
23
- packageName: string;
24
- }) => DefinedModule<C$1, Tables$1>;
25
- type ModuleDependency<T extends DefinedModule<any, any>> = T extends DefinedModule<infer C, infer Tables> ? ConfiguredModule<C> & {
26
- readonly __tablesBrand?: Tables;
27
- } : never;
28
- //#endregion
29
- export { defineModule as i, DefinedModule as n, ModuleDependency as r, ConfiguredModule as t };
@@ -1,38 +0,0 @@
1
- import { n as DefinedModule } from "./helpers-CNjRbrYN.mjs";
2
-
3
- //#region src/stub-loader/interface.d.ts
4
- type ModuleConfigLoaderReturn<C extends Record<string, unknown>> = Promise<{
5
- config: C;
6
- }>;
7
- /**
8
- * `moduleConfigLoader` is an interface for loading module configurations.
9
- *
10
- * By default, it throws an error indicating that the loader needs to be overridden in tsconfig.json.
11
- * Users should provide their "modules.ts" that calls `loadModules` which implements the actual loading logic.
12
- *
13
- * @example
14
- * ```
15
- * {
16
- * "compilerOptions": {
17
- * // ...
18
- * "paths": {
19
- * "@izumisy-tailor/omakase-modules/config/loader": ["./modules.ts"],
20
- * }
21
- * }
22
- * }
23
- * ```
24
- */
25
- declare const moduleConfigLoader: {
26
- loadConfig: <C extends Record<string, unknown>>(_: DefinedModule<C, any>) => ModuleConfigLoaderReturn<C>;
27
- };
28
- //#endregion
29
- //#region src/builder/register.d.ts
30
- type ModuleFactoryContext<C extends Record<string, unknown>> = Awaited<ModuleConfigLoaderReturn<C>>;
31
- /**
32
- * Load a module's configuration, define something.
33
- *
34
- * THis is a low-level utility composed by a specific builder function.
35
- */
36
- declare const withModuleConfiguration: <C extends Record<string, unknown>, Tables extends Record<string, unknown>, Result>(module: DefinedModule<C, Tables>, factory: (context: ModuleFactoryContext<C>) => Result | Promise<Result>) => Promise<Result>;
37
- //#endregion
38
- export { moduleConfigLoader as n, withModuleConfiguration as t };
@@ -1,38 +0,0 @@
1
- import { t as ConfiguredModule } from "./helpers-CNjRbrYN.mjs";
2
-
3
- //#region src/config/module-loader.d.ts
4
-
5
- /**
6
- * Module loader
7
- * Builder for registering modules within loadModules
8
- */
9
- declare class ModuleLoader {
10
- private modules;
11
- /**
12
- * Add a module to the loader
13
- * @param module Configured module
14
- * @returns The added module (can be used as a dependency for other modules)
15
- */
16
- add<C extends Record<string, unknown>>(module: ConfiguredModule<C>): ConfiguredModule<C>;
17
- /**
18
- * Get all registered modules
19
- * @internal
20
- */
21
- _getModules(): Array<ConfiguredModule<any>>;
22
- }
23
- type LoadedModules = {
24
- loadedModules: Record<string, ConfiguredModule<any>>;
25
- loadConfig: <C extends Record<string, unknown>>(module: {
26
- packageName: string;
27
- }) => {
28
- config: C;
29
- };
30
- };
31
- /**
32
- * Load modules with configuration
33
- * @param configurator Function that receives a loader, registers modules, and returns the loader
34
- * @returns Loaded modules and loadConfig function
35
- */
36
- declare const loadModules: (configurator: (loader: ModuleLoader) => ModuleLoader) => LoadedModules;
37
- //#endregion
38
- export { ModuleLoader as n, loadModules as r, LoadedModules as t };
@@ -1,2 +0,0 @@
1
- import { n as moduleConfigLoader } from "../index-BoAL29Di.mjs";
2
- export { moduleConfigLoader as default };
@@ -1,31 +0,0 @@
1
- //#region src/stub-loader/interface.ts
2
- const loadConfig = async (_) => {
3
- console.warn(`[warn] Empty module configuration loaded. Override "@izumisy-tailor/omakase-modules/config/loader" to "./modules.ts" in tsconfig.json paths in your app`);
4
- return { config: {} };
5
- };
6
- /**
7
- * `moduleConfigLoader` is an interface for loading module configurations.
8
- *
9
- * By default, it throws an error indicating that the loader needs to be overridden in tsconfig.json.
10
- * Users should provide their "modules.ts" that calls `loadModules` which implements the actual loading logic.
11
- *
12
- * @example
13
- * ```
14
- * {
15
- * "compilerOptions": {
16
- * // ...
17
- * "paths": {
18
- * "@izumisy-tailor/omakase-modules/config/loader": ["./modules.ts"],
19
- * }
20
- * }
21
- * }
22
- * ```
23
- */
24
- const moduleConfigLoader = { loadConfig };
25
-
26
- //#endregion
27
- //#region src/stub-loader/index.ts
28
- var stub_loader_default = moduleConfigLoader;
29
-
30
- //#endregion
31
- export { stub_loader_default as default };