@izumisy-tailor/omakase-modules 0.3.0 → 0.4.1
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.
- package/README.md +0 -16
- package/docs/generated/README.md +35 -0
- package/docs/{tutorials → generated/_media}/creating-modules.md +192 -17
- package/docs/{tutorials → generated/_media}/using-modules.md +17 -18
- package/docs/generated/builder/README.md +25 -0
- package/docs/generated/builder/functions/defineModule.md +60 -0
- package/docs/generated/builder/functions/withModuleConfiguration.md +68 -0
- package/docs/generated/builder/type-aliases/AnyDefinedModule.md +57 -0
- package/docs/generated/builder/type-aliases/ConfiguredDependencies.md +44 -0
- package/docs/generated/builder/type-aliases/ConfiguredModule.md +60 -0
- package/docs/generated/builder/type-aliases/DefinedModule.md +93 -0
- package/docs/generated/builder/type-aliases/DependencyModules.md +29 -0
- package/docs/generated/builder/type-aliases/EmptyDependencies.md +34 -0
- package/docs/generated/builder/type-aliases/ModuleBuilder.md +124 -0
- package/docs/generated/builder/type-aliases/ModuleBuilderProps.md +42 -0
- package/docs/generated/builder/type-aliases/ModuleFactoryContext.md +40 -0
- package/docs/generated/builder/type-aliases/TablesFromNames.md +28 -0
- package/docs/generated/config/README.md +19 -0
- package/docs/generated/config/classes/ModuleLoader.md +128 -0
- package/docs/generated/config/functions/loadModules.md +79 -0
- package/docs/generated/config/sdk/README.md +16 -0
- package/docs/generated/config/sdk/functions/getModulesReference.md +81 -0
- package/docs/generated/config/sdk/functions/loadModuleForDev.md +53 -0
- package/docs/generated/config/sdk/type-aliases/GetModulesReferenceOptions.md +60 -0
- package/docs/generated/config/type-aliases/LoadedModules.md +162 -0
- package/docs/generated/modules.md +11 -0
- package/package.json +11 -7
- package/src/builder/helpers.ts +347 -27
- package/src/builder/index.ts +6 -1
- package/src/builder/register.ts +3 -6
- package/src/config/module-loader.ts +234 -12
- package/src/config/sdk/dev-context.ts +82 -0
- package/src/config/sdk/index.ts +2 -1
- package/src/config/sdk/paths.ts +85 -3
- package/src/config/sdk/wrapper/base.ts +68 -15
- package/src/config/sdk/wrapper/generator.ts +40 -3
- package/src/config/sdk/wrapper/strategies.ts +32 -13
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { WrapperStrategy, type Category } from "./base";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Strategy for tailordb category
|
|
7
7
|
*/
|
|
8
8
|
class TailorDBStrategy extends WrapperStrategy {
|
|
9
9
|
readonly category = "tailordb" as const;
|
|
10
|
+
|
|
10
11
|
filterFiles(files: string[]) {
|
|
11
12
|
return files.filter((file) => file === "index.ts");
|
|
12
13
|
}
|
|
@@ -24,20 +25,20 @@ class TailorDBStrategy extends WrapperStrategy {
|
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Import tableNames from a module's tailordb/index.ts using dynamic import.
|
|
27
|
-
* Uses createRequire to leverage Node.js module resolution from the app's context
|
|
28
|
+
* Uses createRequire to leverage Node.js module resolution from the app's context,
|
|
29
|
+
* or local src path for the module being developed.
|
|
28
30
|
*/
|
|
29
31
|
private async importTableNames(): Promise<readonly string[]> {
|
|
30
32
|
try {
|
|
31
|
-
const
|
|
32
|
-
path.join(this.basePath, "package.json")
|
|
33
|
-
);
|
|
34
|
-
const modulePath = appRequire.resolve(
|
|
35
|
-
`${this.packageName}/backend/tailordb`
|
|
36
|
-
);
|
|
33
|
+
const modulePath = this.resolveTailorDBModulePath();
|
|
37
34
|
const module = await import(`file://${modulePath}`);
|
|
38
35
|
if (!module.tableNames) {
|
|
39
36
|
console.warn(
|
|
40
|
-
`[warn] tableNames not found in ${
|
|
37
|
+
`[warn] tableNames not found in ${
|
|
38
|
+
this.isLocalModule
|
|
39
|
+
? "local src/tailordb/index.ts"
|
|
40
|
+
: `${this.packageName}/backend/tailordb`
|
|
41
|
+
}. Expected: export const tableNames = [...] as const;`
|
|
41
42
|
);
|
|
42
43
|
return [];
|
|
43
44
|
}
|
|
@@ -50,6 +51,20 @@ class TailorDBStrategy extends WrapperStrategy {
|
|
|
50
51
|
return [];
|
|
51
52
|
}
|
|
52
53
|
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Resolve the module path for tailordb/index.ts.
|
|
57
|
+
* Returns local src path for the module being developed,
|
|
58
|
+
* or uses Node.js module resolution for dependencies.
|
|
59
|
+
*/
|
|
60
|
+
private resolveTailorDBModulePath(): string {
|
|
61
|
+
if (this.isLocalModule) {
|
|
62
|
+
return path.join(this.basePath, "src", "tailordb", "index.ts");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const appRequire = createRequire(path.join(this.basePath, "package.json"));
|
|
66
|
+
return appRequire.resolve(`${this.packageName}/backend/tailordb`);
|
|
67
|
+
}
|
|
53
68
|
}
|
|
54
69
|
|
|
55
70
|
/**
|
|
@@ -87,16 +102,20 @@ class ExecutorsStrategy extends WrapperStrategy {
|
|
|
87
102
|
/**
|
|
88
103
|
* Factory to create strategy instance for each category.
|
|
89
104
|
* Returns a function that takes a category and returns a strategy.
|
|
105
|
+
*
|
|
106
|
+
* @param packageName The package name of the module to generate wrappers for
|
|
107
|
+
* @param basePath The base path of the project
|
|
108
|
+
* @param devModuleName The package name of the module being developed locally (from __devContext)
|
|
90
109
|
*/
|
|
91
110
|
export const createStrategy =
|
|
92
|
-
(packageName: string, basePath: string) =>
|
|
111
|
+
(packageName: string, basePath: string, devModuleName?: string) =>
|
|
93
112
|
(category: Category): WrapperStrategy => {
|
|
94
113
|
switch (category) {
|
|
95
114
|
case "tailordb":
|
|
96
|
-
return new TailorDBStrategy(packageName, basePath);
|
|
115
|
+
return new TailorDBStrategy(packageName, basePath, devModuleName);
|
|
97
116
|
case "resolvers":
|
|
98
|
-
return new ResolversStrategy(packageName, basePath);
|
|
117
|
+
return new ResolversStrategy(packageName, basePath, devModuleName);
|
|
99
118
|
case "executors":
|
|
100
|
-
return new ExecutorsStrategy(packageName, basePath);
|
|
119
|
+
return new ExecutorsStrategy(packageName, basePath, devModuleName);
|
|
101
120
|
}
|
|
102
121
|
};
|