nest-hex 0.2.0 → 0.3.2
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 +155 -267
- package/dist/src/cli/bin.js +2644 -0
- package/dist/src/cli/commands/index.d.ts +23 -0
- package/dist/src/cli/commands/index.js +2609 -0
- package/dist/src/cli/config/defaults.d.ts +74 -0
- package/dist/src/cli/config/defaults.js +76 -0
- package/dist/src/cli/config/define-config.d.ts +74 -0
- package/dist/src/cli/config/define-config.js +62 -0
- package/dist/src/cli/config/loader.d.ts +74 -0
- package/dist/src/cli/config/loader.js +106 -0
- package/dist/src/cli/config/validator.d.ts +81 -0
- package/dist/src/cli/config/validator.js +108 -0
- package/dist/src/cli/generators/adapter.generator.d.ts +235 -0
- package/dist/src/cli/generators/adapter.generator.js +377 -0
- package/dist/src/cli/generators/base.generator.d.ts +190 -0
- package/dist/src/cli/generators/base.generator.js +312 -0
- package/dist/src/cli/generators/index.d.ts +264 -0
- package/dist/src/cli/generators/index.js +467 -0
- package/dist/src/cli/generators/port.generator.d.ts +211 -0
- package/dist/src/cli/generators/port.generator.js +364 -0
- package/dist/src/cli/generators/service.generator.d.ts +208 -0
- package/dist/src/cli/generators/service.generator.js +340 -0
- package/dist/src/cli/index.d.ts +74 -0
- package/dist/src/cli/index.js +69 -0
- package/dist/src/cli/types/config.types.d.ts +73 -0
- package/dist/src/cli/types/config.types.js +56 -0
- package/dist/src/cli/types/generator.types.d.ts +46 -0
- package/dist/src/cli/types/generator.types.js +56 -0
- package/dist/src/cli/types/index.d.ts +121 -0
- package/dist/src/cli/types/index.js +56 -0
- package/dist/src/cli/types/template.types.d.ts +28 -0
- package/dist/src/cli/types/template.types.js +56 -0
- package/dist/src/cli/ui/components/index.d.ts +97 -0
- package/dist/src/cli/ui/components/index.js +1507 -0
- package/dist/src/cli/utils/file-writer.d.ts +17 -0
- package/dist/src/cli/utils/file-writer.js +100 -0
- package/dist/src/cli/utils/linter-detector.d.ts +12 -0
- package/dist/src/cli/utils/linter-detector.js +128 -0
- package/dist/src/cli/utils/linter-runner.d.ts +17 -0
- package/dist/src/cli/utils/linter-runner.js +101 -0
- package/dist/src/cli/utils/name-transformer.d.ts +18 -0
- package/dist/src/cli/utils/name-transformer.js +90 -0
- package/dist/src/cli/utils/path-resolver.d.ts +5 -0
- package/dist/src/cli/utils/path-resolver.js +78 -0
- package/dist/src/cli/utils/port-scanner.d.ts +93 -0
- package/dist/src/cli/utils/port-scanner.js +104 -0
- package/dist/src/cli/utils/template-renderer.d.ts +30 -0
- package/dist/src/cli/utils/template-renderer.js +95 -0
- package/dist/{index.d.ts → src/index.d.ts} +60 -30
- package/dist/{index.js → src/index.js} +45 -13
- package/package.json +10 -10
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var import_node_module = require("node:module");
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
+
for (let key of __getOwnPropNames(mod))
|
|
12
|
+
if (!__hasOwnProp.call(to, key))
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => mod[key],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
20
|
+
var __toCommonJS = (from) => {
|
|
21
|
+
var entry = __moduleCache.get(from), desc;
|
|
22
|
+
if (entry)
|
|
23
|
+
return entry;
|
|
24
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
26
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
27
|
+
get: () => from[key],
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
}));
|
|
30
|
+
__moduleCache.set(from, entry);
|
|
31
|
+
return entry;
|
|
32
|
+
};
|
|
33
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
34
|
+
var __export = (target, all) => {
|
|
35
|
+
for (var name in all)
|
|
36
|
+
__defProp(target, name, {
|
|
37
|
+
get: all[name],
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
set: (newValue) => all[name] = () => newValue
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
44
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
45
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
46
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
47
|
+
else
|
|
48
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
49
|
+
if (d = decorators[i])
|
|
50
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
51
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/cli/utils/port-scanner.ts
|
|
55
|
+
var exports_port_scanner = {};
|
|
56
|
+
__export(exports_port_scanner, {
|
|
57
|
+
scanAvailablePorts: () => scanAvailablePorts,
|
|
58
|
+
findPortByName: () => findPortByName
|
|
59
|
+
});
|
|
60
|
+
module.exports = __toCommonJS(exports_port_scanner);
|
|
61
|
+
var import_node_fs = require("node:fs");
|
|
62
|
+
var import_node_path = require("node:path");
|
|
63
|
+
function scanAvailablePorts(config, projectRoot = process.cwd()) {
|
|
64
|
+
const portsDir = config.output?.portsDir || "src/ports";
|
|
65
|
+
const portsDirPath = import_node_path.join(projectRoot, portsDir);
|
|
66
|
+
if (!import_node_fs.existsSync(portsDirPath)) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const ports = [];
|
|
70
|
+
const entries = import_node_fs.readdirSync(portsDirPath, { withFileTypes: true });
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
if (!entry.isDirectory()) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const portName = entry.name;
|
|
76
|
+
const portPath = import_node_path.join(portsDirPath, portName);
|
|
77
|
+
const tokenFileName = `${portName}.token.ts`;
|
|
78
|
+
const tokenFilePath = import_node_path.join(portPath, tokenFileName);
|
|
79
|
+
if (!import_node_fs.existsSync(tokenFilePath)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const tokenFileContent = import_node_fs.readFileSync(tokenFilePath, "utf-8");
|
|
83
|
+
const tokenMatch = tokenFileContent.match(/export\s+const\s+([A-Z_]+)\s*=\s*Symbol/);
|
|
84
|
+
if (!tokenMatch || !tokenMatch[1]) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const tokenName = tokenMatch[1];
|
|
88
|
+
const pascalName = portName.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
89
|
+
const portsDirName = portsDir.split("/").pop() || "ports";
|
|
90
|
+
const tokenImportPath = `../../${portsDirName}/${portName}`;
|
|
91
|
+
ports.push({
|
|
92
|
+
name: portName,
|
|
93
|
+
pascalName,
|
|
94
|
+
tokenName,
|
|
95
|
+
tokenImportPath,
|
|
96
|
+
portPath
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return ports;
|
|
100
|
+
}
|
|
101
|
+
function findPortByName(portName, config, projectRoot = process.cwd()) {
|
|
102
|
+
const ports = scanAvailablePorts(config, projectRoot);
|
|
103
|
+
return ports.find((p) => p.name === portName) || null;
|
|
104
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface GeneratorContext extends Record<string, unknown> {
|
|
2
|
+
original: string;
|
|
3
|
+
kebab: string;
|
|
4
|
+
camel: string;
|
|
5
|
+
pascal: string;
|
|
6
|
+
snake: string;
|
|
7
|
+
screamingSnake: string;
|
|
8
|
+
nameKebab: string;
|
|
9
|
+
nameCamel: string;
|
|
10
|
+
namePascal: string;
|
|
11
|
+
nameSnake: string;
|
|
12
|
+
nameScreamingSnake: string;
|
|
13
|
+
portSuffix: string;
|
|
14
|
+
adapterSuffix: string;
|
|
15
|
+
fileCase: "kebab" | "camel" | "pascal";
|
|
16
|
+
indent: "tab" | number;
|
|
17
|
+
quotes: "single" | "double";
|
|
18
|
+
semicolons: boolean;
|
|
19
|
+
includeModule: boolean;
|
|
20
|
+
includeService: boolean;
|
|
21
|
+
registrationType: "sync" | "async";
|
|
22
|
+
generateExample: boolean;
|
|
23
|
+
coreImportPath: string;
|
|
24
|
+
}
|
|
25
|
+
interface TemplateContext extends GeneratorContext {
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
declare function renderTemplate(templatePath: string, context: TemplateContext): Promise<string>;
|
|
29
|
+
declare function renderTemplateString(templateString: string, context: TemplateContext): Promise<string>;
|
|
30
|
+
export { renderTemplateString, renderTemplate };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var import_node_module = require("node:module");
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
+
for (let key of __getOwnPropNames(mod))
|
|
12
|
+
if (!__hasOwnProp.call(to, key))
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => mod[key],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
20
|
+
var __toCommonJS = (from) => {
|
|
21
|
+
var entry = __moduleCache.get(from), desc;
|
|
22
|
+
if (entry)
|
|
23
|
+
return entry;
|
|
24
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
26
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
27
|
+
get: () => from[key],
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
}));
|
|
30
|
+
__moduleCache.set(from, entry);
|
|
31
|
+
return entry;
|
|
32
|
+
};
|
|
33
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
34
|
+
var __export = (target, all) => {
|
|
35
|
+
for (var name in all)
|
|
36
|
+
__defProp(target, name, {
|
|
37
|
+
get: all[name],
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
set: (newValue) => all[name] = () => newValue
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
44
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
45
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
46
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
47
|
+
else
|
|
48
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
49
|
+
if (d = decorators[i])
|
|
50
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
51
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/cli/utils/template-renderer.ts
|
|
55
|
+
var exports_template_renderer = {};
|
|
56
|
+
__export(exports_template_renderer, {
|
|
57
|
+
renderTemplateString: () => renderTemplateString,
|
|
58
|
+
renderTemplate: () => renderTemplate
|
|
59
|
+
});
|
|
60
|
+
module.exports = __toCommonJS(exports_template_renderer);
|
|
61
|
+
var import_handlebars = __toESM(require("handlebars"));
|
|
62
|
+
async function renderTemplate(templatePath, context) {
|
|
63
|
+
try {
|
|
64
|
+
const file = Bun.file(templatePath);
|
|
65
|
+
if (!await file.exists()) {
|
|
66
|
+
throw new Error(`Template file not found: ${templatePath}
|
|
67
|
+
` + "Please ensure the template exists or report this as a bug.");
|
|
68
|
+
}
|
|
69
|
+
const templateSource = await file.text();
|
|
70
|
+
try {
|
|
71
|
+
const template = import_handlebars.default.compile(templateSource);
|
|
72
|
+
return template(context);
|
|
73
|
+
} catch (compileError) {
|
|
74
|
+
throw new Error(`Failed to compile template ${templatePath}: ` + `${compileError instanceof Error ? compileError.message : String(compileError)}
|
|
75
|
+
` + "This may indicate invalid Handlebars syntax in the template.");
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error instanceof Error && error.message.includes("Template file not found")) {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
if (error instanceof Error && error.message.includes("Failed to compile template")) {
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`Failed to read template ${templatePath}: ` + `${error instanceof Error ? error.message : String(error)}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function renderTemplateString(templateString, context) {
|
|
88
|
+
try {
|
|
89
|
+
const template = import_handlebars.default.compile(templateString);
|
|
90
|
+
return template(context);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
throw new Error("Failed to compile template string: " + `${error instanceof Error ? error.message : String(error)}
|
|
93
|
+
` + "This may indicate invalid Handlebars syntax.");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -30,31 +30,43 @@ type PortConfig<
|
|
|
30
30
|
*
|
|
31
31
|
* Adapters are dynamic modules that provide a port token and hide infrastructure details.
|
|
32
32
|
* This base class automatically handles provider registration, token aliasing, and exports
|
|
33
|
-
* by reading metadata from the @
|
|
33
|
+
* by reading metadata from the @Adapter decorator.
|
|
34
34
|
*
|
|
35
35
|
* @template TOptions - The options type for configuring this adapter
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
|
+
* Basic adapter with decorator options:
|
|
38
39
|
* ```typescript
|
|
39
|
-
* @
|
|
40
|
-
*
|
|
40
|
+
* @Adapter({
|
|
41
|
+
* portToken: STORAGE_PORT,
|
|
42
|
+
* implementation: S3Service,
|
|
43
|
+
* imports: [HttpModule],
|
|
44
|
+
* providers: [{ provide: 'CONFIG', useValue: {...} }]
|
|
45
|
+
* })
|
|
46
|
+
* class S3Adapter extends AdapterBase<S3Options> {}
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* Advanced adapter with dynamic configuration:
|
|
50
|
+
* ```typescript
|
|
51
|
+
* @Adapter({
|
|
52
|
+
* portToken: STORAGE_PORT,
|
|
41
53
|
* implementation: S3Service
|
|
42
54
|
* })
|
|
43
|
-
* class S3Adapter extends
|
|
44
|
-
* protected
|
|
45
|
-
* return [
|
|
55
|
+
* class S3Adapter extends AdapterBase<S3Options> {
|
|
56
|
+
* protected imports(options: S3Options) {
|
|
57
|
+
* return [HttpModule.register({ timeout: options.timeout })]
|
|
46
58
|
* }
|
|
47
59
|
*
|
|
48
|
-
* protected
|
|
49
|
-
* return [
|
|
60
|
+
* protected extraProviders(options: S3Options) {
|
|
61
|
+
* return [{ provide: 'S3_CONFIG', useValue: options }]
|
|
50
62
|
* }
|
|
51
63
|
* }
|
|
52
64
|
* ```
|
|
53
65
|
*/
|
|
54
|
-
declare class
|
|
66
|
+
declare class AdapterBase<TOptions> {
|
|
55
67
|
/**
|
|
56
68
|
* Optional hook to import other NestJS modules.
|
|
57
|
-
* Override this method to add module dependencies.
|
|
69
|
+
* Override this method to add module dependencies based on options.
|
|
58
70
|
*
|
|
59
71
|
* @param _options - The adapter configuration options
|
|
60
72
|
* @returns Array of modules to import
|
|
@@ -62,31 +74,31 @@ declare class Adapter<TOptions> {
|
|
|
62
74
|
protected imports(_options?: TOptions): unknown[];
|
|
63
75
|
/**
|
|
64
76
|
* Optional hook to provide additional providers.
|
|
65
|
-
* Override this method to add helper services, factories, or initialization logic.
|
|
77
|
+
* Override this method to add helper services, factories, or initialization logic based on options.
|
|
66
78
|
*
|
|
67
79
|
* @param _options - The adapter configuration options
|
|
68
80
|
* @returns Array of additional providers
|
|
69
81
|
*/
|
|
70
|
-
protected
|
|
82
|
+
protected extraProviders(_options: TOptions): Provider[];
|
|
71
83
|
/**
|
|
72
84
|
* Synchronous registration method.
|
|
73
85
|
* Creates a dynamic module with the adapter's port token and implementation.
|
|
74
86
|
*
|
|
75
87
|
* @param options - The adapter configuration options
|
|
76
88
|
* @returns An AdapterModule with compile-time token proof
|
|
77
|
-
* @throws Error if @
|
|
89
|
+
* @throws Error if @Adapter decorator is missing or incomplete
|
|
78
90
|
*/
|
|
79
91
|
static register<
|
|
80
92
|
TToken,
|
|
81
93
|
TOptions
|
|
82
|
-
>(this: new () =>
|
|
94
|
+
>(this: new () => AdapterBase<TOptions>, options: TOptions): AdapterModule<TToken>;
|
|
83
95
|
/**
|
|
84
96
|
* Asynchronous registration method with dependency injection support.
|
|
85
97
|
* Creates a dynamic module where options are resolved via DI.
|
|
86
98
|
*
|
|
87
99
|
* @param options - Async configuration with factory, imports, and inject
|
|
88
100
|
* @returns An AdapterModule with compile-time token proof
|
|
89
|
-
* @throws Error if @
|
|
101
|
+
* @throws Error if @Adapter decorator is missing or incomplete
|
|
90
102
|
*
|
|
91
103
|
* @example
|
|
92
104
|
* ```typescript
|
|
@@ -100,35 +112,53 @@ declare class Adapter<TOptions> {
|
|
|
100
112
|
static registerAsync<
|
|
101
113
|
TToken,
|
|
102
114
|
TOptions
|
|
103
|
-
>(this: new () =>
|
|
115
|
+
>(this: new () => AdapterBase<TOptions>, options: {
|
|
104
116
|
imports?: unknown[];
|
|
105
117
|
inject?: unknown[];
|
|
106
118
|
useFactory: (...args: unknown[]) => TOptions | Promise<TOptions>;
|
|
107
119
|
}): AdapterModule<TToken>;
|
|
108
120
|
}
|
|
109
|
-
import { Type } from "@nestjs/common";
|
|
121
|
+
import { DynamicModule as DynamicModule2, Provider as Provider2, Type } from "@nestjs/common";
|
|
110
122
|
/**
|
|
111
|
-
* Declares the
|
|
123
|
+
* Declares the adapter configuration (port token, implementation, imports, and extra providers).
|
|
112
124
|
*
|
|
113
|
-
* This decorator stores
|
|
114
|
-
* which is read at runtime by the Adapter base
|
|
125
|
+
* This decorator stores the port token, implementation class, optional imports, and
|
|
126
|
+
* optional extra providers in metadata, which is read at runtime by the Adapter base
|
|
127
|
+
* class's register() and registerAsync() methods.
|
|
115
128
|
*
|
|
116
|
-
* @param config -
|
|
117
|
-
* @param config.
|
|
129
|
+
* @param config - Adapter configuration object
|
|
130
|
+
* @param config.portToken - The port token this adapter provides
|
|
118
131
|
* @param config.implementation - The concrete implementation class that provides the port functionality
|
|
132
|
+
* @param config.imports - Optional array of NestJS modules to import (module classes or DynamicModule objects)
|
|
133
|
+
* @param config.providers - Optional array of additional providers to register
|
|
119
134
|
*
|
|
120
135
|
* @example
|
|
136
|
+
* Basic adapter:
|
|
121
137
|
* ```typescript
|
|
122
|
-
* @
|
|
123
|
-
*
|
|
138
|
+
* @Adapter({
|
|
139
|
+
* portToken: OBJECT_STORAGE_PORT,
|
|
124
140
|
* implementation: S3ObjectStorageService
|
|
125
141
|
* })
|
|
126
|
-
* class S3Adapter extends
|
|
142
|
+
* class S3Adapter extends AdapterBase<S3Options> {}
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* Adapter with imports and extra providers:
|
|
147
|
+
* ```typescript
|
|
148
|
+
* @Adapter({
|
|
149
|
+
* portToken: HTTP_CLIENT_PORT,
|
|
150
|
+
* implementation: AxiosHttpClient,
|
|
151
|
+
* imports: [HttpModule],
|
|
152
|
+
* providers: [{ provide: 'HTTP_CONFIG', useValue: { timeout: 5000 } }]
|
|
153
|
+
* })
|
|
154
|
+
* class AxiosAdapter extends AdapterBase<AxiosOptions> {}
|
|
127
155
|
* ```
|
|
128
156
|
*/
|
|
129
|
-
declare function
|
|
130
|
-
|
|
157
|
+
declare function Adapter<C extends PortConfig<any, any>>(config: {
|
|
158
|
+
portToken: C["token"];
|
|
131
159
|
implementation: Type<C["port"]>;
|
|
160
|
+
imports?: Array<Type<any> | DynamicModule2 | Promise<DynamicModule2>>;
|
|
161
|
+
providers?: Provider2[];
|
|
132
162
|
}): ClassDecorator;
|
|
133
163
|
/**
|
|
134
164
|
* DX decorator for injecting a port token into service constructors.
|
|
@@ -148,7 +178,7 @@ declare function Port2<C extends PortConfig<any, any>>(config: {
|
|
|
148
178
|
* ```
|
|
149
179
|
*/
|
|
150
180
|
declare function InjectPort<TToken>(token: TToken): ParameterDecorator;
|
|
151
|
-
import { DynamicModule as
|
|
181
|
+
import { DynamicModule as DynamicModule3 } from "@nestjs/common";
|
|
152
182
|
declare class PortModule<_TService> {
|
|
153
183
|
/**
|
|
154
184
|
* Registers the port module with an adapter.
|
|
@@ -159,6 +189,6 @@ declare class PortModule<_TService> {
|
|
|
159
189
|
*/
|
|
160
190
|
static register<TToken>({ adapter }: {
|
|
161
191
|
adapter?: AdapterModule<TToken>;
|
|
162
|
-
}):
|
|
192
|
+
}): DynamicModule3;
|
|
163
193
|
}
|
|
164
|
-
export { PortModule, PortConfig,
|
|
194
|
+
export { PortModule, PortConfig, InjectPort, AdapterModule, AdapterBase, Adapter };
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
var import_node_module = require("node:module");
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
2
4
|
var __defProp = Object.defineProperty;
|
|
3
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
+
for (let key of __getOwnPropNames(mod))
|
|
12
|
+
if (!__hasOwnProp.call(to, key))
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => mod[key],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
6
19
|
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
20
|
var __toCommonJS = (from) => {
|
|
8
21
|
var entry = __moduleCache.get(from), desc;
|
|
@@ -17,6 +30,7 @@ var __toCommonJS = (from) => {
|
|
|
17
30
|
__moduleCache.set(from, entry);
|
|
18
31
|
return entry;
|
|
19
32
|
};
|
|
33
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
20
34
|
var __export = (target, all) => {
|
|
21
35
|
for (var name in all)
|
|
22
36
|
__defProp(target, name, {
|
|
@@ -41,8 +55,8 @@ var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
|
41
55
|
var exports_src = {};
|
|
42
56
|
__export(exports_src, {
|
|
43
57
|
PortModule: () => PortModule,
|
|
44
|
-
Port: () => Port,
|
|
45
58
|
InjectPort: () => InjectPort,
|
|
59
|
+
AdapterBase: () => AdapterBase,
|
|
46
60
|
Adapter: () => Adapter
|
|
47
61
|
});
|
|
48
62
|
module.exports = __toCommonJS(exports_src);
|
|
@@ -53,32 +67,37 @@ var import_reflect_metadata = require("reflect-metadata");
|
|
|
53
67
|
// src/core/constants.ts
|
|
54
68
|
var PORT_TOKEN_METADATA = Symbol("PORT_TOKEN_METADATA");
|
|
55
69
|
var PORT_IMPLEMENTATION_METADATA = Symbol("PORT_IMPLEMENTATION_METADATA");
|
|
70
|
+
var ADAPTER_IMPORTS_METADATA = Symbol("ADAPTER_IMPORTS_METADATA");
|
|
71
|
+
var ADAPTER_PROVIDERS_METADATA = Symbol("ADAPTER_PROVIDERS_METADATA");
|
|
56
72
|
|
|
57
73
|
// src/core/adapter.base.ts
|
|
58
|
-
class
|
|
74
|
+
class AdapterBase {
|
|
59
75
|
imports(_options) {
|
|
60
76
|
return [];
|
|
61
77
|
}
|
|
62
|
-
|
|
78
|
+
extraProviders(_options) {
|
|
63
79
|
return [];
|
|
64
80
|
}
|
|
65
81
|
static register(options) {
|
|
66
82
|
const instance = new this;
|
|
67
83
|
const token = Reflect.getMetadata(PORT_TOKEN_METADATA, this);
|
|
68
84
|
const implementation = Reflect.getMetadata(PORT_IMPLEMENTATION_METADATA, this);
|
|
85
|
+
const decoratorImports = Reflect.getMetadata(ADAPTER_IMPORTS_METADATA, this) ?? [];
|
|
86
|
+
const decoratorProviders = Reflect.getMetadata(ADAPTER_PROVIDERS_METADATA, this) ?? [];
|
|
69
87
|
if (!token) {
|
|
70
|
-
throw new Error(`${this.name} must be decorated with @
|
|
88
|
+
throw new Error(`${this.name} must be decorated with @Adapter() and specify 'portToken'`);
|
|
71
89
|
}
|
|
72
90
|
if (!implementation) {
|
|
73
|
-
throw new Error(`${this.name} must be decorated with @
|
|
91
|
+
throw new Error(`${this.name} must be decorated with @Adapter() and specify 'implementation'`);
|
|
74
92
|
}
|
|
75
93
|
return {
|
|
76
94
|
module: this,
|
|
77
|
-
imports: instance.imports(options),
|
|
95
|
+
imports: [...decoratorImports, ...instance.imports(options)],
|
|
78
96
|
providers: [
|
|
79
97
|
implementation,
|
|
80
98
|
{ provide: token, useExisting: implementation },
|
|
81
|
-
...
|
|
99
|
+
...decoratorProviders,
|
|
100
|
+
...instance.extraProviders(options)
|
|
82
101
|
],
|
|
83
102
|
exports: [token],
|
|
84
103
|
__provides: token
|
|
@@ -88,19 +107,26 @@ class Adapter {
|
|
|
88
107
|
const instance = new this;
|
|
89
108
|
const token = Reflect.getMetadata(PORT_TOKEN_METADATA, this);
|
|
90
109
|
const implementation = Reflect.getMetadata(PORT_IMPLEMENTATION_METADATA, this);
|
|
110
|
+
const decoratorImports = Reflect.getMetadata(ADAPTER_IMPORTS_METADATA, this) ?? [];
|
|
111
|
+
const decoratorProviders = Reflect.getMetadata(ADAPTER_PROVIDERS_METADATA, this) ?? [];
|
|
91
112
|
if (!token) {
|
|
92
|
-
throw new Error(`${this.name} must be decorated with @
|
|
113
|
+
throw new Error(`${this.name} must be decorated with @Adapter() and specify 'portToken'`);
|
|
93
114
|
}
|
|
94
115
|
if (!implementation) {
|
|
95
|
-
throw new Error(`${this.name} must be decorated with @
|
|
116
|
+
throw new Error(`${this.name} must be decorated with @Adapter() and specify 'implementation'`);
|
|
96
117
|
}
|
|
97
118
|
return {
|
|
98
119
|
module: this,
|
|
99
|
-
imports: [
|
|
120
|
+
imports: [
|
|
121
|
+
...decoratorImports,
|
|
122
|
+
...instance.imports(),
|
|
123
|
+
...options.imports ?? []
|
|
124
|
+
],
|
|
100
125
|
providers: [
|
|
101
126
|
implementation,
|
|
102
127
|
{ provide: token, useExisting: implementation },
|
|
103
|
-
...
|
|
128
|
+
...decoratorProviders,
|
|
129
|
+
...instance.extraProviders({})
|
|
104
130
|
],
|
|
105
131
|
exports: [token],
|
|
106
132
|
__provides: token
|
|
@@ -110,10 +136,16 @@ class Adapter {
|
|
|
110
136
|
// src/core/decorators.ts
|
|
111
137
|
var import_reflect_metadata2 = require("reflect-metadata");
|
|
112
138
|
var import_common = require("@nestjs/common");
|
|
113
|
-
function
|
|
139
|
+
function Adapter(config) {
|
|
114
140
|
return (target) => {
|
|
115
|
-
Reflect.defineMetadata(PORT_TOKEN_METADATA, config.
|
|
141
|
+
Reflect.defineMetadata(PORT_TOKEN_METADATA, config.portToken, target);
|
|
116
142
|
Reflect.defineMetadata(PORT_IMPLEMENTATION_METADATA, config.implementation, target);
|
|
143
|
+
if (config.imports) {
|
|
144
|
+
Reflect.defineMetadata(ADAPTER_IMPORTS_METADATA, config.imports, target);
|
|
145
|
+
}
|
|
146
|
+
if (config.providers) {
|
|
147
|
+
Reflect.defineMetadata(ADAPTER_PROVIDERS_METADATA, config.providers, target);
|
|
148
|
+
}
|
|
117
149
|
};
|
|
118
150
|
}
|
|
119
151
|
function InjectPort(token) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nest-hex",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "A tiny NestJS-native library for building pluggable adapters (Ports & Adapters / Hexagonal) using class-based Dynamic Modules, with great DX and strong type safety.",
|
|
5
5
|
"homepage": "https://github.com/LiorVainer/nest-hex#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"bin": {
|
|
17
|
-
"nest-hex": "./dist/cli/bin.js"
|
|
17
|
+
"nest-hex": "./dist/src/cli/bin.js"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -64,18 +64,18 @@
|
|
|
64
64
|
"optional": true
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
|
-
"main": "./dist/index.js",
|
|
68
|
-
"types": "./dist/index.d.ts",
|
|
67
|
+
"main": "./dist/src/index.js",
|
|
68
|
+
"types": "./dist/src/index.d.ts",
|
|
69
69
|
"exports": {
|
|
70
70
|
".": {
|
|
71
|
-
"types": "./dist/index.d.ts",
|
|
72
|
-
"require": "./dist/index.js",
|
|
73
|
-
"import": "./dist/index.js"
|
|
71
|
+
"types": "./dist/src/index.d.ts",
|
|
72
|
+
"require": "./dist/src/index.js",
|
|
73
|
+
"import": "./dist/src/index.js"
|
|
74
74
|
},
|
|
75
75
|
"./cli": {
|
|
76
|
-
"types": "./dist/cli/index.d.ts",
|
|
77
|
-
"require": "./dist/cli/index.js",
|
|
78
|
-
"import": "./dist/cli/index.js"
|
|
76
|
+
"types": "./dist/src/cli/index.d.ts",
|
|
77
|
+
"require": "./dist/src/cli/index.js",
|
|
78
|
+
"import": "./dist/src/cli/index.js"
|
|
79
79
|
},
|
|
80
80
|
"./package.json": "./package.json"
|
|
81
81
|
},
|