@kanjijs/testing 0.2.0-beta.15 → 0.2.0-beta.17
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/dist/index.js
CHANGED
|
@@ -1174,12 +1174,14 @@ class KanjijsIoC {
|
|
|
1174
1174
|
KanjijsIoC.providers.set(target, provider);
|
|
1175
1175
|
}
|
|
1176
1176
|
if (!provider) {
|
|
1177
|
-
|
|
1177
|
+
const targetName2 = typeof target === "function" ? target.name ?? "anonymous" : String(target);
|
|
1178
|
+
throw new Error(`Provider not found for token: ${targetName2}`);
|
|
1178
1179
|
}
|
|
1179
1180
|
if (provider.instance) {
|
|
1180
1181
|
return provider.instance;
|
|
1181
1182
|
}
|
|
1182
|
-
|
|
1183
|
+
const targetName = typeof target === "function" ? target.name ?? "anonymous" : String(target);
|
|
1184
|
+
console.log(`[DI] Creating NEW instance for ${targetName}`);
|
|
1183
1185
|
if (provider.useValue !== undefined) {
|
|
1184
1186
|
provider.instance = provider.useValue;
|
|
1185
1187
|
} else if (provider.useClass) {
|
|
@@ -1208,7 +1210,8 @@ class Container {
|
|
|
1208
1210
|
resolve(token) {
|
|
1209
1211
|
const provider = this.providers.get(token);
|
|
1210
1212
|
if (!provider) {
|
|
1211
|
-
|
|
1213
|
+
const tokenName = typeof token === "function" ? token.name ?? "anonymous" : String(token);
|
|
1214
|
+
throw new Error(`[DI] Provider not found for token: ${tokenName}`);
|
|
1212
1215
|
}
|
|
1213
1216
|
if (provider.instance) {
|
|
1214
1217
|
return provider.instance;
|
|
@@ -1240,12 +1243,11 @@ class ModuleCompiler {
|
|
|
1240
1243
|
this.scan(rootModule);
|
|
1241
1244
|
this.validate();
|
|
1242
1245
|
const container = new Container;
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
container.register(token, definition);
|
|
1247
|
-
}
|
|
1246
|
+
const rootNode = this.nodes.get(rootModule);
|
|
1247
|
+
if (!rootNode) {
|
|
1248
|
+
return container;
|
|
1248
1249
|
}
|
|
1250
|
+
this.registerProviders(rootNode, container, new Set);
|
|
1249
1251
|
return container;
|
|
1250
1252
|
}
|
|
1251
1253
|
scan(target) {
|
|
@@ -1332,16 +1334,28 @@ class ModuleCompiler {
|
|
|
1332
1334
|
return overrideToken || paramType;
|
|
1333
1335
|
});
|
|
1334
1336
|
} else if ("useFactory" in provider) {
|
|
1335
|
-
targetName = typeof provider.provide === "function" ? provider.provide.name : String(provider.provide);
|
|
1337
|
+
targetName = typeof provider.provide === "function" ? provider.provide.name ?? "anonymous" : String(provider.provide);
|
|
1336
1338
|
dependencies = provider.inject || [];
|
|
1337
1339
|
}
|
|
1338
1340
|
for (const dep of dependencies) {
|
|
1339
1341
|
if (!visibleTokens.has(dep)) {
|
|
1340
|
-
const depName = typeof dep === "function" ? dep.name : String(dep);
|
|
1342
|
+
const depName = typeof dep === "function" ? dep.name ?? "anonymous" : String(dep);
|
|
1341
1343
|
throw new Error(`[Kanjijs] strict-di-error: Provider '${targetName}' in Module '${moduleName}' ` + `depends on '${depName}', but it is not visible. ` + `Make sure it is imported and exported by the source module.`);
|
|
1342
1344
|
}
|
|
1343
1345
|
}
|
|
1344
1346
|
}
|
|
1347
|
+
registerProviders(node, container, visited) {
|
|
1348
|
+
if (visited.has(node))
|
|
1349
|
+
return;
|
|
1350
|
+
visited.add(node);
|
|
1351
|
+
for (const imp of node.imports) {
|
|
1352
|
+
this.registerProviders(imp, container, visited);
|
|
1353
|
+
}
|
|
1354
|
+
for (const [token, provider] of node.providers) {
|
|
1355
|
+
const { provide: _provide, ...definition } = provider;
|
|
1356
|
+
container.register(token, definition);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1345
1359
|
}
|
|
1346
1360
|
// ../core/src/exceptions/http.exception.ts
|
|
1347
1361
|
class HttpException extends Error {
|
|
@@ -3444,19 +3458,8 @@ class TestingModuleBuilder {
|
|
|
3444
3458
|
}
|
|
3445
3459
|
async compile() {
|
|
3446
3460
|
KanjijsIoC.clear();
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
const index = providers.findIndex((p) => {
|
|
3450
|
-
return p === token || typeof p === "object" && "provide" in p && p.provide === token;
|
|
3451
|
-
});
|
|
3452
|
-
const mockProvider = { provide: token, useValue: value };
|
|
3453
|
-
if (index > -1) {
|
|
3454
|
-
providers[index] = mockProvider;
|
|
3455
|
-
} else {
|
|
3456
|
-
providers.push(mockProvider);
|
|
3457
|
-
}
|
|
3458
|
-
}
|
|
3459
|
-
this.metadata.providers = providers;
|
|
3461
|
+
this.metadata.providers = this.applyOverridesToProviders(this.metadata.providers);
|
|
3462
|
+
this.applyOverridesToImports(this.metadata.imports || [], new Set);
|
|
3460
3463
|
|
|
3461
3464
|
class TestModule {
|
|
3462
3465
|
}
|
|
@@ -3474,6 +3477,38 @@ class TestingModuleBuilder {
|
|
|
3474
3477
|
}
|
|
3475
3478
|
};
|
|
3476
3479
|
}
|
|
3480
|
+
applyOverridesToImports(imports, visited) {
|
|
3481
|
+
for (const imp of imports) {
|
|
3482
|
+
const moduleClass = "module" in imp ? imp.module : imp;
|
|
3483
|
+
if (visited.has(moduleClass))
|
|
3484
|
+
continue;
|
|
3485
|
+
visited.add(moduleClass);
|
|
3486
|
+
const meta = MetadataStorage.getModule(moduleClass);
|
|
3487
|
+
if (meta) {
|
|
3488
|
+
meta.providers = this.applyOverridesToProviders(meta.providers);
|
|
3489
|
+
}
|
|
3490
|
+
if ("module" in imp) {
|
|
3491
|
+
imp.providers = this.applyOverridesToProviders(imp.providers);
|
|
3492
|
+
}
|
|
3493
|
+
const nextImports = [...meta?.imports || [], ..."module" in imp ? imp.imports || [] : []];
|
|
3494
|
+
this.applyOverridesToImports(nextImports, visited);
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
applyOverridesToProviders(providers) {
|
|
3498
|
+
const list = providers ? [...providers] : [];
|
|
3499
|
+
for (const [token, value] of this.overrides) {
|
|
3500
|
+
const index = list.findIndex((p) => {
|
|
3501
|
+
return p === token || typeof p === "object" && "provide" in p && p.provide === token;
|
|
3502
|
+
});
|
|
3503
|
+
const mockProvider = { provide: token, useValue: value };
|
|
3504
|
+
if (index > -1) {
|
|
3505
|
+
list[index] = mockProvider;
|
|
3506
|
+
} else {
|
|
3507
|
+
list.push(mockProvider);
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3510
|
+
return list;
|
|
3511
|
+
}
|
|
3477
3512
|
}
|
|
3478
3513
|
export {
|
|
3479
3514
|
TestingModuleBuilder,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanjijs/testing",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"build": "bun build src/index.ts --outdir dist --target bun && tsc --emitDeclarationOnly --declaration --outDir dist"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@kanjijs/core": "^0.2.0-beta.
|
|
17
|
-
"@kanjijs/platform-hono": "^0.2.0-beta.
|
|
16
|
+
"@kanjijs/core": "^0.2.0-beta.17",
|
|
17
|
+
"@kanjijs/platform-hono": "^0.2.0-beta.17",
|
|
18
18
|
"hono": "^4.0.0"
|
|
19
19
|
}
|
|
20
20
|
}
|