@spinajs/reflection
Advanced tools
Comparing version 2.0.46 to 2.0.50
@@ -1,2 +0,2 @@ | ||
import { Exception } from '@spinajs/exceptions'; | ||
import { Exception } from '../../exceptions/lib/index.js'; | ||
export * from 'typescript-mix'; | ||
@@ -56,9 +56,2 @@ /** | ||
export declare function ResolveFromFiles(filter: string, configPath: string, typeMatcher?: (fileName: string) => string): (target: any, propertyKey: string | symbol) => void; | ||
/** | ||
* Returns list of class types found in specified path. It do not resolve / create instances | ||
* | ||
* @param filter - files to look at, uses glob pattern to search | ||
* @param configPath - dir paths taken from app config eg. "system.dirs.controllers". Path MUST be avaible in configuration | ||
* | ||
*/ | ||
export declare function ListFromFiles(filter: string, configPath: string, typeMatcher?: (fileName: string) => string): (target: any, propertyKey: string | symbol) => void; | ||
//# sourceMappingURL=index.d.ts.map |
123
lib/index.js
@@ -1,55 +0,24 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ListFromFiles = exports.ResolveFromFiles = exports.TypescriptCompiler = exports.ReflectionException = exports.ClassInfo = void 0; | ||
const fs = __importStar(require("fs")); | ||
const glob = __importStar(require("glob")); | ||
const path = __importStar(require("path")); | ||
const ts = __importStar(require("typescript")); | ||
const configuration_1 = require("@spinajs/configuration"); | ||
const di_1 = require("@spinajs/di"); | ||
const exceptions_1 = require("@spinajs/exceptions"); | ||
const log_1 = require("@spinajs/log"); | ||
__exportStar(require("typescript-mix"), exports); | ||
import * as fs from 'fs'; | ||
import glob from 'glob'; | ||
import * as path from 'path'; | ||
import * as ts from 'typescript'; | ||
import { Configuration } from '@spinajs/configuration'; | ||
import { AsyncService, DI } from '@spinajs/di'; | ||
import { InvalidArgument, Exception } from '../../exceptions/lib/index.js'; | ||
import { Log } from '@spinajs/log'; | ||
export * from 'typescript-mix'; | ||
/** | ||
* Class info structure | ||
*/ | ||
class ClassInfo { | ||
export class ClassInfo { | ||
} | ||
exports.ClassInfo = ClassInfo; | ||
/** | ||
* Exception thrown when some error during reflection occurs | ||
*/ | ||
class ReflectionException extends exceptions_1.Exception { | ||
export class ReflectionException extends Exception { | ||
} | ||
exports.ReflectionException = ReflectionException; | ||
/** | ||
* Helper class for extracting various information from typescript source code | ||
*/ | ||
class TypescriptCompiler { | ||
export class TypescriptCompiler { | ||
constructor(filename) { | ||
@@ -101,3 +70,2 @@ this.tsFile = filename; | ||
} | ||
exports.TypescriptCompiler = TypescriptCompiler; | ||
/** | ||
@@ -112,24 +80,12 @@ * Returns resolved instances of classes from specified files. | ||
*/ | ||
function ResolveFromFiles(filter, configPath, typeMatcher) { | ||
return _listOrResolveFromFiles(filter, configPath, true, typeMatcher); | ||
export function ResolveFromFiles(filter, configPath, typeMatcher) { | ||
return _listOrResolveFromFiles(filter, configPath, typeMatcher); | ||
} | ||
exports.ResolveFromFiles = ResolveFromFiles; | ||
/** | ||
* Returns list of class types found in specified path. It do not resolve / create instances | ||
* | ||
* @param filter - files to look at, uses glob pattern to search | ||
* @param configPath - dir paths taken from app config eg. "system.dirs.controllers". Path MUST be avaible in configuration | ||
* | ||
*/ | ||
function ListFromFiles(filter, configPath, typeMatcher) { | ||
return _listOrResolveFromFiles(filter, configPath, false, typeMatcher); | ||
} | ||
exports.ListFromFiles = ListFromFiles; | ||
function _listOrResolveFromFiles(filter, configPath, resolve, typeMatcher) { | ||
function _listOrResolveFromFiles(filter, configPath, typeMatcher) { | ||
return (target, propertyKey) => { | ||
if (!filter) { | ||
throw new exceptions_1.InvalidArgument('filter parameter is null or empty'); | ||
throw new InvalidArgument('filter parameter is null or empty'); | ||
} | ||
if (!configPath) { | ||
throw new exceptions_1.InvalidArgument('configPath parameter is null or empty'); | ||
throw new InvalidArgument('configPath parameter is null or empty'); | ||
} | ||
@@ -147,5 +103,5 @@ let instances = null; | ||
}); | ||
function _loadInstances() { | ||
const config = di_1.DI.get(configuration_1.Configuration); | ||
const logger = di_1.DI.resolve(log_1.Log, ['reflection']); | ||
async function _loadInstances() { | ||
const config = DI.get(Configuration); | ||
const logger = DI.resolve(Log, ['reflection']); | ||
let directories = config.get(configPath); | ||
@@ -158,4 +114,4 @@ if (!directories || directories.length === 0) { | ||
} | ||
let promised = false; | ||
const result = directories | ||
// eslint-disable -next-line @typescript-eslint/await-thenable | ||
const fPromises = directories | ||
.filter((d) => { | ||
@@ -173,11 +129,8 @@ /* eslint-disable */ | ||
/* eslint-disable */ | ||
const fTypes = require(f); | ||
const types = []; | ||
for (const key of Object.keys(fTypes)) { | ||
const nameToResolve = typeMatcher ? typeMatcher(path.parse(f).name, key) : key; | ||
const type = fTypes[`${nameToResolve}`]; | ||
if (resolve) { | ||
if (type.prototype instanceof di_1.AsyncService) { | ||
promised = true; | ||
return di_1.DI.resolve(type).then((instance) => { | ||
return import(`file://${f}`).then((fTypes) => { | ||
for (const key of Object.keys(fTypes)) { | ||
const nameToResolve = typeMatcher ? typeMatcher(path.parse(f).name, key) : key; | ||
const type = fTypes[`${nameToResolve}`]; | ||
if (type.prototype instanceof AsyncService) { | ||
return DI.resolve(type).then((instance) => { | ||
return { | ||
@@ -191,16 +144,12 @@ file: f, | ||
} | ||
return Promise.resolve({ | ||
file: f, | ||
instance: DI.resolve(type), | ||
name: nameToResolve, | ||
type, | ||
}); | ||
} | ||
types.push({ | ||
file: f, | ||
instance: resolve ? di_1.DI.resolve(type) : null, | ||
name: nameToResolve, | ||
type, | ||
}); | ||
} | ||
if (types.length === 0) { | ||
throw new ReflectionException(`cannot find any exported class in file ${f}`); | ||
} | ||
return types; | ||
}); | ||
}); | ||
return promised && resolve ? Promise.all(result) : result; | ||
return Promise.all(fPromises); | ||
} | ||
@@ -207,0 +156,0 @@ }; |
{ | ||
"name": "@spinajs/reflection", | ||
"version": "2.0.46", | ||
"version": "2.0.50", | ||
"description": "SpinaJS reflection helpers", | ||
"main": "lib/index.js", | ||
"exports": "./lib/index.js", | ||
"type": "module", | ||
"private": false, | ||
"engines": { | ||
"node": ">=16.11" | ||
}, | ||
"scripts": { | ||
"build": "npm run clean && npm run compile", | ||
"compile": "tsc -b tsconfig.json", | ||
"rimraf": "./node_modules/rimraf/bin.js", | ||
"clean": "rimraf lib/ && rimraf tsconfig.tsbuildinfo", | ||
"test": "ts-mocha -p tsconfig.json test/**/*.test.ts", | ||
"coverage": "nyc npm run test", | ||
"build-docs": "rimraf docs && typedoc --options typedoc.json src/", | ||
"build": "npm run clean && npm run compile", | ||
"compile": "tsc -p tsconfig.build.json", | ||
"clean": "", | ||
"prepare": "npm run build", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
"lint": "eslint -c .eslintrc.js --ext .ts src", | ||
"prepublishOnly": "npm test && npm run lint", | ||
"lint": "eslint -c .eslintrc.cjs --ext .ts src --fix", | ||
"preversion": "npm run lint", | ||
"version": "npm run format && git add -A src", | ||
"postversion": "git push && git push --tags" | ||
"postinstall": "npm run build" | ||
}, | ||
@@ -36,12 +39,12 @@ "files": [ | ||
"@spinajs/log": "^2.0.46", | ||
"glob": "^8.0.3", | ||
"glob": "^8.1.0", | ||
"lodash": "^4.17.21", | ||
"typescript": "^4.7.4", | ||
"typescript": "^4.9.4", | ||
"typescript-mix": "^3.1.3" | ||
}, | ||
"devDependencies": { | ||
"@types/glob": "7.2.0", | ||
"@types/node": "^16.11.11" | ||
"@types/glob": "8.0.1", | ||
"@types/node": "^18.11.18" | ||
}, | ||
"gitHead": "bd560afd6c9a156071102cc6b4f36115b5498e9d" | ||
"gitHead": "002dc553b0ffffd72193d0121ac425a4083bc9ee" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5
2
Yes
14077
206
1
Updatedglob@^8.1.0
Updatedtypescript@^4.9.4