Add Typedoc support and improve documentation

Upgraded the package version to 0.0.9. Introduced Typedoc for generating documentation with added script in package.json. Enhanced exception handling by introducing `DependencyResolutionError`. Refined TSinjex comments and README structure for better readability. Updated index file exports for better module organization.
This commit is contained in:
2024-08-15 17:57:07 +02:00
parent f0d1db6fa1
commit b9a75a36f5
7 changed files with 189 additions and 13 deletions

View File

@@ -1,8 +1,10 @@
# TSinjex
## Configuration
## Jest
### Jest
### Example jest setup
#### Example jest setup
```ts
module.exports = {

153
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "ts-injex",
"version": "0.0.7",
"version": "0.0.8",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ts-injex",
"version": "0.0.7",
"version": "0.0.8",
"license": "MIT",
"dependencies": {
"eslint-plugin-prettier": "^5.2.1",
@@ -24,6 +24,7 @@
"eslint-plugin-override": "https://github.com/PxaMMaxP/eslint-plugin-override",
"jest": "^29.7.0",
"ts-jest": "^29.2.3",
"typedoc": "^0.26.5",
"typescript": "^5.5.4"
}
},
@@ -1184,6 +1185,15 @@
"url": "https://opencollective.com/unts"
}
},
"node_modules/@shikijs/core": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-1.13.0.tgz",
"integrity": "sha512-Mj5NVfbAXcD1GnwOTSPl8hBn/T8UDpfFQTptp+p41n/CbUcJtOq98WaRD7Lz3hCglYotUTHUWtzu3JhK6XlkAA==",
"dev": true,
"dependencies": {
"@types/hast": "^3.0.4"
}
},
"node_modules/@sinclair/typebox": {
"version": "0.27.8",
"resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz",
@@ -1405,6 +1415,15 @@
"@types/node": "*"
}
},
"node_modules/@types/hast": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.4.tgz",
"integrity": "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==",
"dev": true,
"dependencies": {
"@types/unist": "*"
}
},
"node_modules/@types/istanbul-lib-coverage": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz",
@@ -1476,6 +1495,12 @@
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz",
"integrity": "sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA=="
},
"node_modules/@types/unist": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz",
"integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==",
"dev": true
},
"node_modules/@types/yargs": {
"version": "17.0.33",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz",
@@ -1847,8 +1872,7 @@
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
"peer": true
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
},
"node_modules/array-buffer-byte-length": {
"version": "1.0.1",
@@ -5163,6 +5187,15 @@
"integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==",
"dev": true
},
"node_modules/linkify-it": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz",
"integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==",
"dev": true,
"dependencies": {
"uc.micro": "^2.0.0"
}
},
"node_modules/locate-path": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",
@@ -5199,6 +5232,12 @@
"yallist": "^3.0.2"
}
},
"node_modules/lunr": {
"version": "2.3.9",
"resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz",
"integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==",
"dev": true
},
"node_modules/make-dir": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz",
@@ -5229,6 +5268,29 @@
"tmpl": "1.0.5"
}
},
"node_modules/markdown-it": {
"version": "14.1.0",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz",
"integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==",
"dev": true,
"dependencies": {
"argparse": "^2.0.1",
"entities": "^4.4.0",
"linkify-it": "^5.0.0",
"mdurl": "^2.0.0",
"punycode.js": "^2.3.1",
"uc.micro": "^2.1.0"
},
"bin": {
"markdown-it": "bin/markdown-it.mjs"
}
},
"node_modules/mdurl": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz",
"integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==",
"dev": true
},
"node_modules/merge-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
@@ -5794,6 +5856,15 @@
"node": ">=6"
}
},
"node_modules/punycode.js": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz",
"integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/pure-rand": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-6.1.0.tgz",
@@ -6088,6 +6159,16 @@
"node": ">=8"
}
},
"node_modules/shiki": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/shiki/-/shiki-1.13.0.tgz",
"integrity": "sha512-e0dWfnONbEv6xl7FJy3XIhsVHQ/65XHDZl92+6H9+4xWjfdo7pmkqG7Kg47KWtDiEtzM5Z+oEfb4vtRvoZ/X9w==",
"dev": true,
"dependencies": {
"@shikijs/core": "1.13.0",
"@types/hast": "^3.0.4"
}
},
"node_modules/side-channel": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz",
@@ -6631,6 +6712,52 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/typedoc": {
"version": "0.26.5",
"resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.26.5.tgz",
"integrity": "sha512-Vn9YKdjKtDZqSk+by7beZ+xzkkr8T8CYoiasqyt4TTRFy5+UHzL/mF/o4wGBjRF+rlWQHDb0t6xCpA3JNL5phg==",
"dev": true,
"dependencies": {
"lunr": "^2.3.9",
"markdown-it": "^14.1.0",
"minimatch": "^9.0.5",
"shiki": "^1.9.1",
"yaml": "^2.4.5"
},
"bin": {
"typedoc": "bin/typedoc"
},
"engines": {
"node": ">= 18"
},
"peerDependencies": {
"typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x"
}
},
"node_modules/typedoc/node_modules/brace-expansion": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
"dev": true,
"dependencies": {
"balanced-match": "^1.0.0"
}
},
"node_modules/typedoc/node_modules/minimatch": {
"version": "9.0.5",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz",
"integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==",
"dev": true,
"dependencies": {
"brace-expansion": "^2.0.1"
},
"engines": {
"node": ">=16 || 14 >=14.17"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/typescript": {
"version": "5.5.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
@@ -6644,6 +6771,12 @@
"node": ">=14.17"
}
},
"node_modules/uc.micro": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",
"integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==",
"dev": true
},
"node_modules/unbox-primitive": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz",
@@ -6934,6 +7067,18 @@
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
"dev": true
},
"node_modules/yaml": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.0.tgz",
"integrity": "sha512-2wWLbGbYDiSqqIKoPjar3MPgB94ErzCtrNE1FdqGuaO0pi2JGjmE8aW8TDZwzU7vuxcGRdL/4gPQwQ7hD5AMSw==",
"dev": true,
"bin": {
"yaml": "bin.mjs"
},
"engines": {
"node": ">= 14"
}
},
"node_modules/yargs": {
"version": "17.7.2",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",

View File

@@ -1,6 +1,6 @@
{
"name": "ts-injex",
"version": "0.0.8",
"version": "0.0.9",
"description": "",
"type": "module",
"main": "./dist/index.js",
@@ -11,7 +11,8 @@
"lint:fix": "eslint --fix --ext .ts .",
"test:file": "jest --watch --onlyChanged --coverage=true --verbose",
"test:verbose": "jest --verbose",
"version:show": "node -e \"console.log(require('./package.json').version)\""
"version:show": "node -e \"console.log(require('./package.json').version)\"",
"docs": "typedoc"
},
"repository": {
"type": "git",
@@ -32,7 +33,8 @@
"eslint-plugin-jsdoc": "^50.2.2",
"eslint-plugin-override": "https://github.com/PxaMMaxP/eslint-plugin-override",
"jest": "^29.7.0",
"ts-jest": "^29.2.3"
"ts-jest": "^29.2.3",
"typedoc": "^0.26.5"
},
"dependencies": {
"eslint-plugin-prettier": "^5.2.1",

View File

@@ -1,4 +1,5 @@
import { ImplementsStatic } from './helper/ImplementsStatic';
import { DependencyResolutionError } from './interfaces/Exceptions';
import { IDependency } from './interfaces/IDependency';
import { ITSinjex, ITSinjex_ } from './interfaces/ITSinjex';
@@ -31,7 +32,7 @@ export class TSinjex implements ITSinjex {
/**
* @inheritdoc
* @see {@link ITSInjexRegister.register}
* @see {@link ITSinjex.register}
*/
public static register<T>(
identifier: string,
@@ -46,7 +47,7 @@ export class TSinjex implements ITSinjex {
/**
* @inheritdoc
* @see {@link ITSInjexResolve.resolve}
* @see {@link ITSinjex.resolve}
*/
public static resolve<T>(
identifier: string,
@@ -83,7 +84,7 @@ export class TSinjex implements ITSinjex {
const dependency = this._dependencies.get(identifier);
if (necessary && !dependency) {
throw new Error(`Dependency ${identifier} not found`);
throw new DependencyResolutionError(identifier);
} else if (!dependency) {
return undefined;
}

View File

@@ -1,5 +1,6 @@
/**
* Decorator to enforce static implementation of an interface
* Decorator to enforce static implementation of an interface.
* Warns on compile time if the interface is not implemented.
* @returns A decorator function
*/
export function ImplementsStatic<I>() {

View File

@@ -1,9 +1,16 @@
// Main
export * from './TSinjex';
// Decorators
export * from './decorators/Inject';
export * from './decorators/Register';
export * from './decorators/RegisterInstance';
// Functions
export * from './functions/resolve';
export * from './functions/register';
// Interfaces & Types
export type * from './interfaces/ITSinjex';
export type * from './types/InitDelegate';
export type * from './types/GenericContructor';

18
typedoc.json Normal file
View File

@@ -0,0 +1,18 @@
{
"entryPoints": [
"src/**/*.ts"
],
"out": ".locale/docs",
"tsconfig": "tsconfig.json",
"excludePrivate": false,
"excludeProtected": false,
"excludeExternals": false,
"includeVersion": true,
"readme": "README.md",
"exclude": [
"**/*.test.ts",
"**/*.spec.ts"
],
"theme": "default",
"hideGenerator": true
}