fix versions and logger
This commit is contained in:
@ -139,7 +139,7 @@
|
||||
"private-static-method",
|
||||
"private-method"
|
||||
],
|
||||
"order": "alphabetically"
|
||||
"order": "as-written"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
6
.prettierrc
Normal file
6
.prettierrc
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 2,
|
||||
"semi": true,
|
||||
"singleQuote": false
|
||||
}
|
||||
46
package.json
46
package.json
@ -5,7 +5,7 @@
|
||||
"main": "server.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node ./dist/app.js",
|
||||
"start": "node --no-warnings --trace-warnings --es-module-specifier-resolution=node ./dist/app.js",
|
||||
"dev": "cross-env TS_NODE_COMPILER=ttypescript node --no-warnings --loader ./src/myloader.mjs --es-module-specifier-resolution=node ./src/app.ts",
|
||||
"build": "ttsc -p tsconfig.json && tsc-alias -p tsconfig.json",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
@ -25,42 +25,44 @@
|
||||
"author": "Joshua Schnabel",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@automapper/classes": "^8.3.0",
|
||||
"@automapper/core": "^8.3.0",
|
||||
"@gquittet/graceful-server": "^2.5.2",
|
||||
"@nestjs/common": "^8.4.3",
|
||||
"@nestjs/core": "^8.4.3",
|
||||
"@nestjs/passport": "^8.2.1",
|
||||
"@nestjs/platform-fastify": "^8.4.3",
|
||||
"@automapper/classes": "^8.5.0",
|
||||
"@automapper/core": "^8.5.0",
|
||||
"@fastify/helmet": "9.1.0",
|
||||
"@fastify/sensible": "^5.1.0",
|
||||
"@gquittet/graceful-server": "^3.0.2",
|
||||
"@nestjs/common": "^9.0.2",
|
||||
"@nestjs/core": "^9.0.2",
|
||||
"@nestjs/passport": "^9.0.0",
|
||||
"@nestjs/platform-fastify": "^9.0.2",
|
||||
"args-command-parser": "^1.2.4",
|
||||
"cli-color": "^2.0.1",
|
||||
"fastify": "^3.25.3",
|
||||
"cli-color": "^2.0.3",
|
||||
"fastify-helmet": "^7.1.0",
|
||||
"fastify-plugin": "^3.0.0",
|
||||
"fastify-sensible": "^3.1.2",
|
||||
"passport": "^0.5.2",
|
||||
"passport": "^0.6.0",
|
||||
"passport-http": "^0.3.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rxjs": "^7.5.5",
|
||||
"winston": "^3.4.0"
|
||||
"typescript-rtti": "^0.8.0",
|
||||
"winston": "^3.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node16": "^1.0.2",
|
||||
"@tsconfig/node16": "^1.0.3",
|
||||
"@types/cli-color": "^2.0.2",
|
||||
"@types/node": "^17.0.9",
|
||||
"@types/passport": "^1.0.7",
|
||||
"@types/node": "^18.0.3",
|
||||
"@types/passport": "^1.0.9",
|
||||
"@types/passport-http": "^0.3.9",
|
||||
"@types/triple-beam": "^1.3.2",
|
||||
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
||||
"@typescript-eslint/parser": "^5.10.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.30.5",
|
||||
"@typescript-eslint/parser": "^5.30.5",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.7.0",
|
||||
"eslint": "^8.19.0",
|
||||
"eslint-import-resolver-alias": "^1.1.2",
|
||||
"eslint-plugin-import": "^2.25.4",
|
||||
"eslint-plugin-promise": "^6.0.0",
|
||||
"eslint-plugin-unused-imports": "^2.0.0",
|
||||
"ts-node": "^10.4.0",
|
||||
"tsc-alias": "^1.6.6",
|
||||
"ts-node": "^10.8.2",
|
||||
"tsc-alias": "^1.6.11",
|
||||
"ttypescript": "^1.5.13",
|
||||
"typescript": "^4.5.4"
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
||||
/* eslint-disable no-console */
|
||||
import "reflect-metadata";
|
||||
import clc from "cli-color";
|
||||
import App, { AppCommand } from "#app";
|
||||
import ConfigurationDefinition, { DefinitionType } from "#configuration/configurationDefinition";
|
||||
|
||||
@ -51,13 +51,6 @@ export default class Repo extends Aggregate<RepoId>{
|
||||
// }
|
||||
}
|
||||
|
||||
export type RepoBuilder = {
|
||||
[k in keyof Repo]-?: (arg: Repo[k]) => RepoBuilder
|
||||
}
|
||||
& {
|
||||
build(): Repo;
|
||||
};
|
||||
|
||||
export class RepoIdGenerator implements IdentifierGenerator<RepoId> {
|
||||
public generate (): RepoId {
|
||||
return new RepoId(randomUUID());
|
||||
|
||||
@ -1,13 +1,4 @@
|
||||
import { Identifier, Aggregate} from "#ddd";
|
||||
import { ITest } from "#framework/hello/test";
|
||||
|
||||
interface YYYY {
|
||||
}
|
||||
|
||||
export class XXX implements ITest, YYYY {
|
||||
public xxx = "yyy";
|
||||
|
||||
}
|
||||
|
||||
export default class User extends Aggregate<UserId> {
|
||||
private readonly _id: UserId | undefined;
|
||||
@ -34,14 +25,6 @@ export default class User extends Aggregate<UserId> {
|
||||
public get password (): string {
|
||||
return this._password;
|
||||
}
|
||||
|
||||
public xxx (): XXX {
|
||||
return new XXX();
|
||||
}
|
||||
|
||||
// public static builder (): Test {
|
||||
// return (<unknown> Builder(User)) as Test;
|
||||
// }
|
||||
}
|
||||
|
||||
export class UserId extends Identifier<string> {
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import User, { UserId } from "#domain/user/user.entity";
|
||||
import { UserRepository } from "#domain/user/user.repo";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { ITest } from "#framework/hello/test";
|
||||
|
||||
@Injectable()
|
||||
export default class UserFilePersistence implements UserRepository, ITest {
|
||||
export default class UserFilePersistence implements UserRepository {
|
||||
public xxx = "";
|
||||
|
||||
private readonly values: Map<UserId, User> = new Map();
|
||||
|
||||
@ -7,17 +7,20 @@ import getLogger from "#logger";
|
||||
import { Logger } from "winston";
|
||||
import AppHelp from "./appHelp";
|
||||
|
||||
// TODO: move to App
|
||||
const ENV_PREFIX = "ANT";
|
||||
|
||||
export abstract class AppCommand {
|
||||
public abstract getDescriptions (): string;
|
||||
public abstract getName (): string;
|
||||
public abstract run (): void;
|
||||
|
||||
public abstract getName (): string;
|
||||
}
|
||||
|
||||
export default abstract class App {
|
||||
|
||||
private readonly commands: Map<string, AppCommand> = new Map();
|
||||
private readonly appHelp: AppHelp;
|
||||
private readonly commands: Map<string, AppCommand> = new Map();
|
||||
private readonly logger: Logger;
|
||||
|
||||
public constructor () {
|
||||
@ -26,20 +29,23 @@ export default abstract class App {
|
||||
this.appHelp = new AppHelp();
|
||||
this.logger = getLogger("app");
|
||||
this.addCommmand(new (class implements AppCommand {
|
||||
public getName (): string {
|
||||
return "help";
|
||||
}
|
||||
|
||||
public getDescriptions (): string {
|
||||
return "Show help for this application.";
|
||||
}
|
||||
|
||||
public getName (): string {
|
||||
return "help";
|
||||
}
|
||||
|
||||
public run (): void {
|
||||
that.appHelp.printHelp(that.commands);
|
||||
that.appHelp.printHelp(that.commands, ENV_PREFIX);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public abstract commmands (setCommands: (...commands: AppCommand[]) => void): void;
|
||||
|
||||
/**
|
||||
* It executes the commands and options.
|
||||
*/
|
||||
@ -51,7 +57,7 @@ export default abstract class App {
|
||||
console.log();
|
||||
});
|
||||
this.options((...defs): void => {
|
||||
initConfiguration("XXX", ...defs);
|
||||
initConfiguration(ENV_PREFIX, ...defs);
|
||||
});
|
||||
this.printBanner();
|
||||
configuration().validate();
|
||||
@ -65,13 +71,12 @@ export default abstract class App {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract options (setDefinitions: (...definitions: ConfigurationDefinition[]) => void): void;
|
||||
|
||||
public abstract printBanner (): void;
|
||||
|
||||
private addCommmand (command: AppCommand): void {
|
||||
this.commands.set(command.getName(), command);
|
||||
}
|
||||
|
||||
public abstract options (setDefinitions: (...definitions: ConfigurationDefinition[]) => void): void;
|
||||
|
||||
public abstract commmands (setCommands: (...commands: AppCommand[]) => void): void;
|
||||
public abstract printBanner (): void;
|
||||
|
||||
}
|
||||
@ -13,7 +13,7 @@ export default class AppHelp {
|
||||
* Prints the help message
|
||||
* @param commands - A map of all the commands that the program can run.
|
||||
*/
|
||||
public printHelp (commands: Map<string, AppCommand>): void {
|
||||
public printHelp (commands: Map<string, AppCommand>, envPrefix: string): void {
|
||||
const programm = process.argv.slice(0, 2).join(" ");
|
||||
const underline = clc.underline;
|
||||
console.log(underline("Usage") + "\n");
|
||||
@ -23,50 +23,11 @@ export default class AppHelp {
|
||||
console.log();
|
||||
console.log(underline("Options"));
|
||||
console.log();
|
||||
this.printOptions((def) => def.getCommands().length >= 1);
|
||||
this.printOptions(envPrefix, (def) => def.getCommands().length >= 1);
|
||||
console.log();
|
||||
console.log(underline("Rules & Behavior"));
|
||||
console.log();
|
||||
this.printOptions((def) => def.getCommands().length == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints all commands and their descriptions
|
||||
* @param commands - Map<string, AppCommand>
|
||||
*/
|
||||
private printCommands (commands: Map<string, AppCommand>): void {
|
||||
commands.forEach((v, k, _m) => {
|
||||
console.log("\t" + k + " - " + v.getDescriptions());
|
||||
const paramaters: string[] = [];
|
||||
// Find parameters for current command
|
||||
for (const def of this.getConfigurationDefinitions()) {
|
||||
if (def.getCommands().includes(k)) {
|
||||
paramaters.push(this.generateParameters(def));
|
||||
}
|
||||
}
|
||||
console.log("\t↳ " + k + " " + paramaters.join(" "));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints out all the options that are available to the user
|
||||
* @param condition - Select witch options are printed.
|
||||
*/
|
||||
private printOptions (condition: (a: ConfigurationDefinition) => boolean): void {
|
||||
let maxLength = 0;
|
||||
/* Find longest String */
|
||||
for (const def of this.getConfigurationDefinitions()) {
|
||||
if (condition(def)) {
|
||||
const option = " -" + def.getArgName().sort((a, b) => a.length - b.length).join(" -");
|
||||
maxLength = Math.max(maxLength, option.length);
|
||||
}
|
||||
}
|
||||
for (const def of this.getConfigurationDefinitions()) {
|
||||
if (condition(def)) {
|
||||
const option = " -" + def.getArgName().sort((a, b) => a.length - b.length).join(" -");
|
||||
console.log("\t↳ " + (option.padEnd(maxLength, " ")) + " - " + def.getDescription());
|
||||
}
|
||||
}
|
||||
this.printOptions(envPrefix, (def) => def.getCommands().length == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,4 +68,46 @@ export default class AppHelp {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints all commands and their descriptions
|
||||
* @param commands - Map<string, AppCommand>
|
||||
*/
|
||||
private printCommands (commands: Map<string, AppCommand>): void {
|
||||
commands.forEach((v, k, _m) => {
|
||||
console.log("\t" + k + " - " + v.getDescriptions());
|
||||
const paramaters: string[] = [];
|
||||
// Find parameters for current command
|
||||
for (const def of this.getConfigurationDefinitions()) {
|
||||
if (def.getCommands().includes(k)) {
|
||||
paramaters.push(this.generateParameters(def));
|
||||
}
|
||||
}
|
||||
console.log("\t↳ " + k + " " + paramaters.join(" "));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints out all the options that are available to the user
|
||||
* @param condition - Select witch options are printed.
|
||||
*/
|
||||
private printOptions (envPrefix: string, condition: (a: ConfigurationDefinition) => boolean): void {
|
||||
let maxLength = 0;
|
||||
/* Find longest String */
|
||||
for (const def of this.getConfigurationDefinitions()) {
|
||||
if (condition(def)) {
|
||||
let option = " -" + def.getArgName().sort((a, b) => a.length - b.length).join(" -");
|
||||
option += " (" + envPrefix + "_" + def.getEnvName().toUpperCase()+")";
|
||||
maxLength =
|
||||
Math.max(maxLength, option.length);
|
||||
}
|
||||
}
|
||||
for (const def of this.getConfigurationDefinitions()) {
|
||||
if (condition(def)) {
|
||||
let option = " -" + def.getArgName().sort((a, b) => a.length - b.length).join(" -");
|
||||
option += " (" + envPrefix + "_" + def.getEnvName().toUpperCase()+")";
|
||||
console.log("\t↳ " + (option.padEnd(maxLength, " ")) + " - " + def.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
26
src/framework/builder/builder.ts
Normal file
26
src/framework/builder/builder.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import Repo from "#domain/repo/repo.entity";
|
||||
import { reflect } from "typescript-rtti";
|
||||
|
||||
export type IBuilder<T> = {
|
||||
[k in keyof T]-?: (arg: T[k]) => IBuilder<T>
|
||||
}
|
||||
& {
|
||||
build(): T;
|
||||
};
|
||||
|
||||
type Clazz<T> = new(...args: unknown[]) => T;
|
||||
|
||||
type Constructor<Params extends readonly any[] = readonly any[], Result = any> = new (...params: Params) => Result;
|
||||
|
||||
export function Builder<Type> (type: Constructor): IBuilder<Type> {
|
||||
console.log(reflect(type).class.prototype);
|
||||
const builder = new Proxy(
|
||||
{},
|
||||
{}
|
||||
);
|
||||
|
||||
return builder as IBuilder<Type>;
|
||||
}
|
||||
|
||||
const builder = Builder<Repo>(Repo);
|
||||
builder.name("").build();
|
||||
@ -3,11 +3,11 @@ import {parser, ArgCollection} from "args-command-parser";
|
||||
|
||||
class Configuration {
|
||||
|
||||
private readonly definitions: Map<string, ConfigurationDefinition> = new Map();
|
||||
private readonly values: Map<string, string[] | undefined> = new Map();
|
||||
private readonly defaultCommand: string;
|
||||
private readonly envPrefix: string;
|
||||
private readonly arguments: ArgCollection;
|
||||
private readonly defaultCommand: string;
|
||||
private readonly definitions: Map<string, ConfigurationDefinition> = new Map();
|
||||
private readonly envPrefix: string;
|
||||
private readonly values: Map<string, string[] | undefined> = new Map();
|
||||
public constructor (defaultCommand: string, envPrefix: string, ...definitions: ConfigurationDefinition[]) {
|
||||
this.arguments = parser();
|
||||
for (const definition of definitions) {
|
||||
@ -18,23 +18,22 @@ class Configuration {
|
||||
this.envPrefix = envPrefix;
|
||||
}
|
||||
|
||||
public validate (): void {
|
||||
this.definitions.forEach((v, _k, _m) => {
|
||||
const def = v;
|
||||
const values = this.values.get(def.getName()) ?? [];
|
||||
if(!def.getMultiple() && values.length > 1)
|
||||
throw new Error("No more than one value may be assigned to parameter '" + def.getName() + "'.");
|
||||
if(def.getRequired() && (def.getCommands().length === 0 || def.getCommands().includes(this.getCommand())) && values.length === 0)
|
||||
throw new Error("Parameter '" + def.getName() + "' is required.");
|
||||
for (const value of values) {
|
||||
if(!def.getValidator().validate(value))
|
||||
throw new Error("Parameter '" + def.getName() + "' does not meet the requirements: " + def.getValidator().description());
|
||||
/**
|
||||
* Get the value of a boolean parameter
|
||||
* @param {string} name - The name of the parameter.
|
||||
* @returns The value of the parameter.
|
||||
*/
|
||||
public getBooleanValue (name: string): boolean | boolean[] | undefined {
|
||||
const def = this.definitions.get(name);
|
||||
if(def?.getType() == DefinitionType.Boolean) {
|
||||
const value = this.values.get(name) ?? [];
|
||||
const result: boolean[] = this.toBoolean(value);
|
||||
if(def.getMultiple()) {
|
||||
return result;
|
||||
}
|
||||
});
|
||||
return result[0];
|
||||
}
|
||||
|
||||
public getDefinitions (): ConfigurationDefinition[] {
|
||||
return Array.from(this.definitions.values());
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,6 +47,35 @@ class Configuration {
|
||||
return this.defaultCommand;
|
||||
}
|
||||
|
||||
public getDefinitions (): ConfigurationDefinition[] {
|
||||
return Array.from(this.definitions.values());
|
||||
}
|
||||
|
||||
public getNumberValue (name: string): number | number[] | undefined {
|
||||
const def = this.definitions.get(name);
|
||||
if(def?.getType() == DefinitionType.Number) {
|
||||
const value = this.values.get(name) ?? [];
|
||||
const result: number[] = this.toInteger(value);
|
||||
if(def.getMultiple()) {
|
||||
return result;
|
||||
}
|
||||
return result[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public getStringValue (name: string): string | string[] | undefined {
|
||||
const def = this.definitions.get(name);
|
||||
if(def?.getType() == DefinitionType.String) {
|
||||
const value = this.values.get(name) ?? [];
|
||||
if(def.getMultiple()) {
|
||||
return value;
|
||||
}
|
||||
return value[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a parameter
|
||||
* @param {string} name - The name of the parameter.
|
||||
@ -80,54 +108,56 @@ class Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a boolean parameter
|
||||
* @param {string} name - The name of the parameter.
|
||||
* @returns The value of the parameter.
|
||||
*/
|
||||
public getBooleanValue (name: string): boolean | boolean[] | undefined {
|
||||
const def = this.definitions.get(name);
|
||||
if(def?.getType() == DefinitionType.Boolean) {
|
||||
const value = this.values.get(name) ?? [];
|
||||
const result: boolean[] = this.toBoolean(value);
|
||||
if(def.getMultiple()) {
|
||||
return result;
|
||||
public validate (): void {
|
||||
this.definitions.forEach((v, _k, _m) => {
|
||||
const def = v;
|
||||
const values = this.values.get(def.getName()) ?? [];
|
||||
if(!def.getMultiple() && values.length > 1)
|
||||
throw new Error("No more than one value may be assigned to parameter '" + def.getName() + "'.");
|
||||
if(def.getRequired() && (def.getCommands().length === 0 || def.getCommands().includes(this.getCommand())) && values.length === 0)
|
||||
throw new Error("Parameter '" + def.getName() + "' is required.");
|
||||
for (const value of values) {
|
||||
if(!def.getValidator().validate(value))
|
||||
throw new Error("Parameter '" + def.getName() + "' does not meet the requirements: " + def.getValidator().description());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getArgValue (def: ConfigurationDefinition): string[] | undefined{
|
||||
for (const arg of def.getArgName()) {
|
||||
if(arg.length >= 2 && this.arguments.hasLongSwitch(arg)) {
|
||||
return this.arguments.getLongSwitch(arg).values;
|
||||
} else if (this.arguments.hasShortSwitch(arg)) {
|
||||
return this.arguments.getShortSwitch(arg).values;
|
||||
}
|
||||
return result[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public getNumberValue (name: string): number | number[] | undefined {
|
||||
const def = this.definitions.get(name);
|
||||
if(def?.getType() == DefinitionType.Number) {
|
||||
const value = this.values.get(name) ?? [];
|
||||
const result: number[] = this.toInteger(value);
|
||||
if(def.getMultiple()) {
|
||||
return result;
|
||||
}
|
||||
return result[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public getStringValue (name: string): string | string[] | undefined {
|
||||
const def = this.definitions.get(name);
|
||||
if(def?.getType() == DefinitionType.String) {
|
||||
const value = this.values.get(name) ?? [];
|
||||
if(def.getMultiple()) {
|
||||
return value;
|
||||
}
|
||||
return value[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Convert a string array to a boolean array
|
||||
* @param {string[]} value - The value of the parameter.
|
||||
* @returns The `toBoolean` function returns an array of booleans.
|
||||
*/
|
||||
|
||||
private getEnvValue (def: ConfigurationDefinition): string[] | undefined {
|
||||
const value = process.env[this.envPrefix + "_" + def.getEnvName().toUpperCase()];
|
||||
if(value !== undefined)
|
||||
return [value];
|
||||
else
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private getInternalValue (def: ConfigurationDefinition): string[] | undefined {
|
||||
let value = this.getArgValue(def);
|
||||
value = (value === undefined)?this.getEnvValue(def):value;
|
||||
value = (value === undefined)?def.getDefaultValue():value;
|
||||
if(value !== undefined) {
|
||||
return value;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private toBoolean (value: string[]): boolean[] {
|
||||
const result: boolean[] = [];
|
||||
for (const v of value) {
|
||||
@ -150,34 +180,6 @@ class Configuration {
|
||||
return result;
|
||||
}
|
||||
|
||||
private getInternalValue (def: ConfigurationDefinition): string[] | undefined {
|
||||
let value = this.getArgValue(def);
|
||||
value = (value === undefined)?this.getEnvValue(def):value;
|
||||
value = (value === undefined)?def.getDefaultValue():value;
|
||||
if(value !== undefined) {
|
||||
return value;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private getEnvValue (def: ConfigurationDefinition): string[] | undefined {
|
||||
const value = process.env[this.envPrefix + "_" + def.getEnvName().toUpperCase()];
|
||||
if(value !== undefined)
|
||||
return [value];
|
||||
else
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private getArgValue (def: ConfigurationDefinition): string[] | undefined{
|
||||
for (const arg of def.getArgName()) {
|
||||
if(arg.length >= 2 && this.arguments.hasLongSwitch(arg)) {
|
||||
return this.arguments.getLongSwitch(arg).values;
|
||||
} else if (this.arguments.hasShortSwitch(arg)) {
|
||||
return this.arguments.getShortSwitch(arg).values;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
let configInstance: Configuration;
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
export interface ITest {
|
||||
xxx: string;
|
||||
}
|
||||
@ -1,55 +1,10 @@
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
import { FastifyLogFn, FastifyLoggerInstance, FastifyPluginAsync, FastifyRequest} from "fastify";
|
||||
import { FastifyPluginAsync, FastifyRequest} from "fastify";
|
||||
import fastifyPlugin from "fastify-plugin";
|
||||
import { Bindings } from "fastify/types/logger";
|
||||
import getlogger from "./logger";
|
||||
import chalk from "chalk";
|
||||
import logadapter from "./pinoLoggerAdapter";
|
||||
|
||||
const logger = getlogger("fastify");
|
||||
const customLogger: FastifyLoggerInstance = {
|
||||
info: function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if(typeof obj === "string")
|
||||
logger.info(obj, msg, ...args);
|
||||
else if(msg)
|
||||
logger.info(msg, obj, ...args);
|
||||
} as FastifyLogFn,
|
||||
warn: function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if(typeof obj === "string")
|
||||
logger.warning(obj, msg, ...args);
|
||||
else if(msg)
|
||||
logger.warning(msg, obj, ...args);
|
||||
} as FastifyLogFn,
|
||||
error: function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if(typeof obj === "string")
|
||||
logger.error(obj, msg, ...args);
|
||||
else if(msg)
|
||||
logger.error(msg, obj, ...args);
|
||||
} as FastifyLogFn,
|
||||
fatal: function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if(typeof obj === "string")
|
||||
logger.fatal(obj, msg, ...args);
|
||||
else if(msg)
|
||||
logger.fatal(msg, obj, ...args);
|
||||
} as FastifyLogFn,
|
||||
trace: function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if(typeof obj === "string")
|
||||
logger.trace(obj, msg, ...args);
|
||||
else if(msg)
|
||||
logger.trace(msg, obj, ...args);
|
||||
} as FastifyLogFn,
|
||||
debug: function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if(typeof obj === "string")
|
||||
logger.debug(obj, msg, ...args);
|
||||
else if(msg)
|
||||
logger.debug(msg, obj, ...args);
|
||||
} as FastifyLogFn,
|
||||
child: function (_bindings: Bindings): FastifyLoggerInstance {
|
||||
return customLogger;
|
||||
},
|
||||
setBindings: function (_bindings: Bindings): void {
|
||||
// OK
|
||||
}
|
||||
};
|
||||
// const logger = getlogger("fastify");
|
||||
|
||||
export type FastifyRequestLoggerOptions = {
|
||||
logBody?: boolean;
|
||||
@ -153,15 +108,9 @@ export const plugin: FastifyPluginAsync<FastifyRequestLoggerOptions> = async (fa
|
||||
});
|
||||
};
|
||||
|
||||
declare module "fastify" {
|
||||
interface FastifyLoggerInstance {
|
||||
setBindings(bindings: Bindings): void;
|
||||
}
|
||||
}
|
||||
|
||||
export const fastifyRequestLogger = fastifyPlugin(plugin, {
|
||||
fastify: "3.x",
|
||||
fastify: "4.x",
|
||||
name: "fastify-request-logger",
|
||||
});
|
||||
|
||||
export const fastifyLogger = customLogger;
|
||||
export const fastifyLogger = logadapter;
|
||||
@ -1,5 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
import { LoggerService } from "@nestjs/common";
|
||||
import getlogger from "./logger";
|
||||
|
||||
|
||||
37
src/framework/logger/pinoLoggerAdapter.ts
Normal file
37
src/framework/logger/pinoLoggerAdapter.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { FastifyLogFn, FastifyLoggerInstance } from "fastify";
|
||||
import getlogger from "./logger";
|
||||
import pino, { ChildLoggerOptions, LoggerOptions } from "pino";
|
||||
|
||||
const pinoLogger = pino();
|
||||
|
||||
const logger = getlogger("fastify");
|
||||
const customLogger: FastifyLoggerInstance = pinoLogger;
|
||||
customLogger.info = function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if (typeof obj === "string") logger.info(obj, msg, ...args);
|
||||
else if (msg) logger.info(msg, obj, ...args);
|
||||
} as FastifyLogFn;
|
||||
customLogger.warn = function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if (typeof obj === "string") logger.warning(obj, msg, ...args);
|
||||
else if (msg) logger.warning(msg, obj, ...args);
|
||||
} as FastifyLogFn;
|
||||
customLogger.error = function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if (typeof obj === "string") logger.error(obj, msg, ...args);
|
||||
else if (msg) logger.error(msg, obj, ...args);
|
||||
} as FastifyLogFn;
|
||||
customLogger.fatal = function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if (typeof obj === "string") logger.fatal(obj, msg, ...args);
|
||||
else if (msg) logger.fatal(msg, obj, ...args);
|
||||
} as FastifyLogFn;
|
||||
customLogger.trace = function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if (typeof obj === "string") logger.trace(obj, msg, ...args);
|
||||
else if (msg) logger.trace(msg, obj, ...args);
|
||||
} as FastifyLogFn;
|
||||
customLogger.debug = function (obj: unknown, msg?: string, ...args: unknown[]): void {
|
||||
if (typeof obj === "string") logger.debug(obj, msg, ...args);
|
||||
else if (msg) logger.debug(msg, obj, ...args);
|
||||
} as FastifyLogFn;
|
||||
customLogger.child = function <ChildOptions extends pino.ChildLoggerOptions>(_bindings: pino.Bindings, _options?: ChildLoggerOptions): pino.Logger<LoggerOptions & ChildOptions> {
|
||||
return <pino.Logger<LoggerOptions & ChildOptions>>customLogger;
|
||||
};
|
||||
|
||||
export default customLogger;
|
||||
@ -1,14 +1,20 @@
|
||||
import fastifySensible from "fastify-sensible";
|
||||
import GracefulServer from "@gquittet/graceful-server";
|
||||
import getlogger from "#logger";
|
||||
import {fastifyLogger, fastifyRequestLogger} from "#logger/fastifyLogger";
|
||||
import {fastifyRequestLogger, fastifyLogger} from "#logger/fastifyLogger";
|
||||
import { Logger } from "winston";
|
||||
import IGracefulServer from "@gquittet/graceful-server/lib/types/interface/gracefulServer";
|
||||
import configuration from "#configuration";
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import { FastifyAdapter, NestFastifyApplication } from "@nestjs/platform-fastify";
|
||||
import { AppModule } from "../../app.module";
|
||||
import NestLogger from "#framework/logger/nestLogger";
|
||||
import { EventEmitter } from "events";
|
||||
import fastifySensible from "@fastify/sensible";
|
||||
|
||||
interface IGracefulServer {
|
||||
isReady: () => boolean;
|
||||
setReady: () => void;
|
||||
on: (name: string, callback: (...args: any[]) => void) => EventEmitter;
|
||||
}
|
||||
|
||||
export default class Server {
|
||||
private readonly logger: Logger;
|
||||
@ -40,7 +46,8 @@ export default class Server {
|
||||
new FastifyAdapter({
|
||||
logger: fastifyLogger,
|
||||
disableRequestLogging: true
|
||||
}), {
|
||||
}),
|
||||
{
|
||||
logger: new NestLogger(),
|
||||
}
|
||||
);
|
||||
|
||||
@ -24,8 +24,9 @@
|
||||
"plugins": [
|
||||
{
|
||||
"transform": "@automapper/classes/transformer-plugin",
|
||||
"modelFileNameSuffix": [".types2.js", ".entity2.ts", ".dto2.ts"]
|
||||
}
|
||||
"modelFileNameSuffix": [".types.js", ".entity.ts", ".dto.ts"]
|
||||
},
|
||||
{ "transform": "typescript-rtti/dist/transformer" }
|
||||
]
|
||||
},
|
||||
"tsc-alias": {
|
||||
|
||||
Reference in New Issue
Block a user