@currentjs/gen 0.5.2 → 0.5.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.3] - 2026-04-07
4
+
5
+ - expand autowiring (DI) for providers
6
+
3
7
  ## [0.5.2] - 2026-03-21
4
8
 
5
9
  - skip templates on generation; introduced a flag to regenerate templates
@@ -191,14 +191,38 @@ async function handleGenerateAll(yamlPathArg, _outArg, moduleName, opts) {
191
191
  // --- Build DI instantiation order ---
192
192
  const providerVarByType = new Map();
193
193
  providerVarByType.set('ISqlProvider', (_c = dbVarByKey[allDatabaseKeys[0]]) !== null && _c !== void 0 ? _c : 'dbMysql');
194
+ // Scan local providers and register their class names + implemented interfaces
195
+ const providerCastLines = [];
196
+ if (providersConfig) {
197
+ const GENERIC_INTERFACES = new Set(['IProvider', 'ISqlProvider']);
198
+ for (const [provName, mod] of Object.entries(providersConfig)) {
199
+ if (!mod || typeof mod !== 'string')
200
+ continue;
201
+ const isLocal = mod.startsWith('.') || mod.startsWith('/');
202
+ if (!isLocal)
203
+ continue;
204
+ const providerDir = path.resolve(srcDir, mod);
205
+ const providerClasses = (0, diResolver_1.scanModuleClasses)(providerDir);
206
+ for (const cls of providerClasses) {
207
+ const varName = provName.charAt(0).toLowerCase() + provName.slice(1);
208
+ providerVarByType.set(cls.className, varName);
209
+ for (const iface of cls.implementedInterfaces) {
210
+ if (!GENERIC_INTERFACES.has(iface)) {
211
+ providerVarByType.set(iface, varName);
212
+ }
213
+ }
214
+ providerCastLines.push(`const ${varName} = providers['${provName}'] as ${cls.className};`);
215
+ }
216
+ }
217
+ }
194
218
  // Per-class provider var: map each class to its module's database variable
195
219
  const classProviderVar = new Map();
196
220
  for (const scan of moduleScans) {
197
221
  const dbVar = (_d = dbVarByKey[scan.databaseKey]) !== null && _d !== void 0 ? _d : dbVarByKey[Object.keys(dbVarByKey)[0]];
198
222
  const classes = allClasses.filter(c => c.filePath.startsWith(scan.moduleDir + path.sep));
199
223
  for (const cls of classes) {
200
- const hasProviderParam = cls.constructorParams.some(p => providerVarByType.has(p.type));
201
- if (hasProviderParam) {
224
+ const hasSqlProviderParam = cls.constructorParams.some(p => p.type === 'ISqlProvider');
225
+ if (hasSqlProviderParam) {
202
226
  classProviderVar.set(cls.className, dbVar);
203
227
  }
204
228
  }
@@ -226,6 +250,9 @@ async function handleGenerateAll(yamlPathArg, _outArg, moduleName, opts) {
226
250
  // --- Build wiring block ---
227
251
  const wiringLines = [];
228
252
  wiringLines.push(dbLines.join('\n'));
253
+ if (providerCastLines.length > 0) {
254
+ wiringLines.push(providerCastLines.join('\n'));
255
+ }
229
256
  const nonControllers = steps.filter(s => !s.isController);
230
257
  const controllers = steps.filter(s => s.isController);
231
258
  for (const step of nonControllers) {
@@ -8,6 +8,7 @@ export interface ClassInfo {
8
8
  isController: boolean;
9
9
  isInjectable: boolean;
10
10
  constructorParams: ConstructorParam[];
11
+ implementedInterfaces: string[];
11
12
  }
12
13
  export interface InstantiationStep {
13
14
  className: string;
@@ -42,6 +42,7 @@ const path = __importStar(require("path"));
42
42
  const INJECTABLE_RE = /@Injectable\s*\(/;
43
43
  const CONTROLLER_RE = /@Controller\s*\(/;
44
44
  const EXPORT_CLASS_RE = /export\s+class\s+(\w+)/;
45
+ const IMPLEMENTS_RE = /\bimplements\s+([^{]+)/;
45
46
  const CONSTRUCTOR_PARAMS_RE = /constructor\s*\(([^)]*)\)/s;
46
47
  const PARAM_RE = /(?:private|protected|public)\s+(\w+)\s*:\s*([A-Za-z_]\w*)/g;
47
48
  function parseClassFile(filePath) {
@@ -70,7 +71,11 @@ function parseClassFile(filePath) {
70
71
  constructorParams.push({ name: match[1], type: match[2] });
71
72
  }
72
73
  }
73
- return { className, filePath, isController, isInjectable, constructorParams };
74
+ const implMatch = content.match(IMPLEMENTS_RE);
75
+ const implementedInterfaces = implMatch
76
+ ? implMatch[1].split(',').map(s => s.trim().replace(/<[^>]*>/g, '').trim()).filter(Boolean)
77
+ : [];
78
+ return { className, filePath, isController, isInjectable, constructorParams, implementedInterfaces };
74
79
  }
75
80
  function walkTsFiles(dir) {
76
81
  const results = [];
@@ -135,7 +140,7 @@ function buildInstantiationOrder(classes, providerVarByType, classProviderVar, s
135
140
  varNames.set(className, varName);
136
141
  const constructorArgs = [];
137
142
  for (const param of cls.constructorParams) {
138
- if (classProviderVar.has(className) && providerVarByType.has(param.type)) {
143
+ if (classProviderVar.has(className) && param.type === 'ISqlProvider') {
139
144
  constructorArgs.push(classProviderVar.get(className));
140
145
  }
141
146
  else if (providerVarByType.has(param.type)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@currentjs/gen",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "CLI code generator",
5
5
  "license": "LGPL-3.0",
6
6
  "author": "Konstantin Zavalny",