Initial commit - Event Planner application
This commit is contained in:
5
node_modules/@nestjs/core/repl/assign-to-object.util.d.ts
generated
vendored
Normal file
5
node_modules/@nestjs/core/repl/assign-to-object.util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Similar to `Object.assign` but copying properties descriptors from `source`
|
||||
* as well.
|
||||
*/
|
||||
export declare function assignToObject<T, U extends object>(target: T, source: U): T & U;
|
||||
14
node_modules/@nestjs/core/repl/assign-to-object.util.js
generated
vendored
Normal file
14
node_modules/@nestjs/core/repl/assign-to-object.util.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.assignToObject = assignToObject;
|
||||
/**
|
||||
* Similar to `Object.assign` but copying properties descriptors from `source`
|
||||
* as well.
|
||||
*/
|
||||
function assignToObject(target, source) {
|
||||
Object.defineProperties(target, Object.keys(source).reduce((descriptors, key) => {
|
||||
descriptors[key] = Object.getOwnPropertyDescriptor(source, key);
|
||||
return descriptors;
|
||||
}, Object.create(null)));
|
||||
return target;
|
||||
}
|
||||
1
node_modules/@nestjs/core/repl/constants.d.ts
generated
vendored
Normal file
1
node_modules/@nestjs/core/repl/constants.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const REPL_INITIALIZED_MESSAGE = "REPL initialized";
|
||||
4
node_modules/@nestjs/core/repl/constants.js
generated
vendored
Normal file
4
node_modules/@nestjs/core/repl/constants.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.REPL_INITIALIZED_MESSAGE = void 0;
|
||||
exports.REPL_INITIALIZED_MESSAGE = 'REPL initialized';
|
||||
1
node_modules/@nestjs/core/repl/index.d.ts
generated
vendored
Normal file
1
node_modules/@nestjs/core/repl/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './repl';
|
||||
4
node_modules/@nestjs/core/repl/index.js
generated
vendored
Normal file
4
node_modules/@nestjs/core/repl/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./repl"), exports);
|
||||
9
node_modules/@nestjs/core/repl/native-functions/debug-repl-fn.d.ts
generated
vendored
Normal file
9
node_modules/@nestjs/core/repl/native-functions/debug-repl-fn.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { Type } from '@nestjs/common';
|
||||
import { ReplFunction } from '../repl-function';
|
||||
import type { ReplFnDefinition } from '../repl.interfaces';
|
||||
export declare class DebugReplFn extends ReplFunction {
|
||||
fnDefinition: ReplFnDefinition;
|
||||
action(moduleCls?: Type<unknown> | string): void;
|
||||
private printCtrlsAndProviders;
|
||||
private printCollection;
|
||||
}
|
||||
46
node_modules/@nestjs/core/repl/native-functions/debug-repl-fn.js
generated
vendored
Normal file
46
node_modules/@nestjs/core/repl/native-functions/debug-repl-fn.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DebugReplFn = void 0;
|
||||
const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
|
||||
const repl_function_1 = require("../repl-function");
|
||||
class DebugReplFn extends repl_function_1.ReplFunction {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.fnDefinition = {
|
||||
name: 'debug',
|
||||
description: 'Print all registered modules as a list together with their controllers and providers.\nIf the argument is passed in, for example, "debug(MyModule)" then it will only print components of this specific module.',
|
||||
signature: '(moduleCls?: ClassRef | string) => void',
|
||||
};
|
||||
}
|
||||
action(moduleCls) {
|
||||
this.ctx.writeToStdout('\n');
|
||||
if (moduleCls) {
|
||||
const token = typeof moduleCls === 'function' ? moduleCls.name : moduleCls;
|
||||
const moduleEntry = this.ctx.debugRegistry[token];
|
||||
if (!moduleEntry) {
|
||||
return this.logger.error(`"${token}" has not been found in the modules registry`);
|
||||
}
|
||||
this.printCtrlsAndProviders(token, moduleEntry);
|
||||
}
|
||||
else {
|
||||
Object.keys(this.ctx.debugRegistry).forEach(moduleKey => {
|
||||
this.printCtrlsAndProviders(moduleKey, this.ctx.debugRegistry[moduleKey]);
|
||||
});
|
||||
}
|
||||
this.ctx.writeToStdout('\n');
|
||||
}
|
||||
printCtrlsAndProviders(moduleName, moduleDebugEntry) {
|
||||
this.ctx.writeToStdout(`${cli_colors_util_1.clc.green(moduleName)}:\n`);
|
||||
this.printCollection('controllers', moduleDebugEntry['controllers']);
|
||||
this.printCollection('providers', moduleDebugEntry['providers']);
|
||||
}
|
||||
printCollection(title, collectionValue) {
|
||||
const collectionEntries = Object.keys(collectionValue);
|
||||
if (collectionEntries.length <= 0) {
|
||||
return;
|
||||
}
|
||||
this.ctx.writeToStdout(` ${cli_colors_util_1.clc.yellow(`- ${title}`)}:\n`);
|
||||
collectionEntries.forEach(provider => this.ctx.writeToStdout(` ${cli_colors_util_1.clc.green('◻')} ${provider}\n`));
|
||||
}
|
||||
}
|
||||
exports.DebugReplFn = DebugReplFn;
|
||||
7
node_modules/@nestjs/core/repl/native-functions/get-repl-fn.d.ts
generated
vendored
Normal file
7
node_modules/@nestjs/core/repl/native-functions/get-repl-fn.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { Type } from '@nestjs/common';
|
||||
import { ReplFunction } from '../repl-function';
|
||||
import type { ReplFnDefinition } from '../repl.interfaces';
|
||||
export declare class GetReplFn extends ReplFunction {
|
||||
fnDefinition: ReplFnDefinition;
|
||||
action(token: string | symbol | Function | Type<any>): any;
|
||||
}
|
||||
19
node_modules/@nestjs/core/repl/native-functions/get-repl-fn.js
generated
vendored
Normal file
19
node_modules/@nestjs/core/repl/native-functions/get-repl-fn.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetReplFn = void 0;
|
||||
const repl_function_1 = require("../repl-function");
|
||||
class GetReplFn extends repl_function_1.ReplFunction {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.fnDefinition = {
|
||||
name: 'get',
|
||||
signature: '(token: InjectionToken) => any',
|
||||
description: 'Retrieves an instance of either injectable or controller, otherwise, throws exception.',
|
||||
aliases: ['$'],
|
||||
};
|
||||
}
|
||||
action(token) {
|
||||
return this.ctx.app.get(token);
|
||||
}
|
||||
}
|
||||
exports.GetReplFn = GetReplFn;
|
||||
7
node_modules/@nestjs/core/repl/native-functions/help-repl-fn.d.ts
generated
vendored
Normal file
7
node_modules/@nestjs/core/repl/native-functions/help-repl-fn.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { ReplFunction } from '../repl-function';
|
||||
import type { ReplFnDefinition } from '../repl.interfaces';
|
||||
export declare class HelpReplFn extends ReplFunction {
|
||||
fnDefinition: ReplFnDefinition;
|
||||
static buildHelpMessage: ({ name, description }: ReplFnDefinition) => string;
|
||||
action(): void;
|
||||
}
|
||||
29
node_modules/@nestjs/core/repl/native-functions/help-repl-fn.js
generated
vendored
Normal file
29
node_modules/@nestjs/core/repl/native-functions/help-repl-fn.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HelpReplFn = void 0;
|
||||
const iterare_1 = require("iterare");
|
||||
const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
|
||||
const repl_function_1 = require("../repl-function");
|
||||
class HelpReplFn extends repl_function_1.ReplFunction {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.fnDefinition = {
|
||||
name: 'help',
|
||||
signature: '() => void',
|
||||
description: 'Display all available REPL native functions.',
|
||||
};
|
||||
}
|
||||
action() {
|
||||
const sortedNativeFunctions = (0, iterare_1.iterate)(this.ctx.nativeFunctions)
|
||||
.map(([, nativeFunction]) => nativeFunction.fnDefinition)
|
||||
.toArray()
|
||||
.sort((a, b) => (a.name < b.name ? -1 : 1));
|
||||
this.ctx.writeToStdout(`You can call ${cli_colors_util_1.clc.bold('.help')} on any function listed below (e.g.: ${cli_colors_util_1.clc.bold('help.help')}):\n\n` +
|
||||
sortedNativeFunctions.map(HelpReplFn.buildHelpMessage).join('\n') +
|
||||
// Without the following LF the last item won't be displayed
|
||||
'\n');
|
||||
}
|
||||
}
|
||||
exports.HelpReplFn = HelpReplFn;
|
||||
HelpReplFn.buildHelpMessage = ({ name, description }) => cli_colors_util_1.clc.cyanBright(name) +
|
||||
(description ? ` ${cli_colors_util_1.clc.bold('-')} ${description}` : '');
|
||||
6
node_modules/@nestjs/core/repl/native-functions/index.d.ts
generated
vendored
Normal file
6
node_modules/@nestjs/core/repl/native-functions/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export * from './help-repl-fn';
|
||||
export * from './get-repl-fn';
|
||||
export * from './resolve-repl-fn';
|
||||
export * from './select-relp-fn';
|
||||
export * from './debug-repl-fn';
|
||||
export * from './methods-repl-fn';
|
||||
9
node_modules/@nestjs/core/repl/native-functions/index.js
generated
vendored
Normal file
9
node_modules/@nestjs/core/repl/native-functions/index.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./help-repl-fn"), exports);
|
||||
tslib_1.__exportStar(require("./get-repl-fn"), exports);
|
||||
tslib_1.__exportStar(require("./resolve-repl-fn"), exports);
|
||||
tslib_1.__exportStar(require("./select-relp-fn"), exports);
|
||||
tslib_1.__exportStar(require("./debug-repl-fn"), exports);
|
||||
tslib_1.__exportStar(require("./methods-repl-fn"), exports);
|
||||
8
node_modules/@nestjs/core/repl/native-functions/methods-repl-fn.d.ts
generated
vendored
Normal file
8
node_modules/@nestjs/core/repl/native-functions/methods-repl-fn.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { Type } from '@nestjs/common';
|
||||
import { ReplFunction } from '../repl-function';
|
||||
import type { ReplFnDefinition } from '../repl.interfaces';
|
||||
export declare class MethodsReplFn extends ReplFunction {
|
||||
fnDefinition: ReplFnDefinition;
|
||||
private readonly metadataScanner;
|
||||
action(token: Type<unknown> | string): void;
|
||||
}
|
||||
28
node_modules/@nestjs/core/repl/native-functions/methods-repl-fn.js
generated
vendored
Normal file
28
node_modules/@nestjs/core/repl/native-functions/methods-repl-fn.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MethodsReplFn = void 0;
|
||||
const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
|
||||
const metadata_scanner_1 = require("../../metadata-scanner");
|
||||
const repl_function_1 = require("../repl-function");
|
||||
class MethodsReplFn extends repl_function_1.ReplFunction {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.fnDefinition = {
|
||||
name: 'methods',
|
||||
description: 'Display all public methods available on a given provider or controller.',
|
||||
signature: '(token: ClassRef | string) => void',
|
||||
};
|
||||
this.metadataScanner = new metadata_scanner_1.MetadataScanner();
|
||||
}
|
||||
action(token) {
|
||||
const proto = typeof token !== 'function'
|
||||
? Object.getPrototypeOf(this.ctx.app.get(token))
|
||||
: token?.prototype;
|
||||
const methods = this.metadataScanner.getAllMethodNames(proto);
|
||||
this.ctx.writeToStdout('\n');
|
||||
this.ctx.writeToStdout(`${cli_colors_util_1.clc.green('Methods')}:\n`);
|
||||
methods.forEach(methodName => this.ctx.writeToStdout(` ${cli_colors_util_1.clc.yellow('◻')} ${methodName}\n`));
|
||||
this.ctx.writeToStdout('\n');
|
||||
}
|
||||
}
|
||||
exports.MethodsReplFn = MethodsReplFn;
|
||||
7
node_modules/@nestjs/core/repl/native-functions/resolve-repl-fn.d.ts
generated
vendored
Normal file
7
node_modules/@nestjs/core/repl/native-functions/resolve-repl-fn.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { Type } from '@nestjs/common';
|
||||
import { ReplFunction } from '../repl-function';
|
||||
import type { ReplFnDefinition } from '../repl.interfaces';
|
||||
export declare class ResolveReplFn extends ReplFunction {
|
||||
fnDefinition: ReplFnDefinition;
|
||||
action(token: string | symbol | Function | Type<any>, contextId: any): Promise<any>;
|
||||
}
|
||||
18
node_modules/@nestjs/core/repl/native-functions/resolve-repl-fn.js
generated
vendored
Normal file
18
node_modules/@nestjs/core/repl/native-functions/resolve-repl-fn.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ResolveReplFn = void 0;
|
||||
const repl_function_1 = require("../repl-function");
|
||||
class ResolveReplFn extends repl_function_1.ReplFunction {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.fnDefinition = {
|
||||
name: 'resolve',
|
||||
description: 'Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.',
|
||||
signature: '(token: InjectionToken, contextId: any) => Promise<any>',
|
||||
};
|
||||
}
|
||||
action(token, contextId) {
|
||||
return this.ctx.app.resolve(token, contextId);
|
||||
}
|
||||
}
|
||||
exports.ResolveReplFn = ResolveReplFn;
|
||||
7
node_modules/@nestjs/core/repl/native-functions/select-relp-fn.d.ts
generated
vendored
Normal file
7
node_modules/@nestjs/core/repl/native-functions/select-relp-fn.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { DynamicModule, INestApplicationContext, Type } from '@nestjs/common';
|
||||
import { ReplFunction } from '../repl-function';
|
||||
import type { ReplFnDefinition } from '../repl.interfaces';
|
||||
export declare class SelectReplFn extends ReplFunction {
|
||||
fnDefinition: ReplFnDefinition;
|
||||
action(token: DynamicModule | Type<unknown>): INestApplicationContext;
|
||||
}
|
||||
18
node_modules/@nestjs/core/repl/native-functions/select-relp-fn.js
generated
vendored
Normal file
18
node_modules/@nestjs/core/repl/native-functions/select-relp-fn.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SelectReplFn = void 0;
|
||||
const repl_function_1 = require("../repl-function");
|
||||
class SelectReplFn extends repl_function_1.ReplFunction {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.fnDefinition = {
|
||||
name: 'select',
|
||||
description: 'Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.',
|
||||
signature: '(token: DynamicModule | ClassRef) => INestApplicationContext',
|
||||
};
|
||||
}
|
||||
action(token) {
|
||||
return this.ctx.app.select(token);
|
||||
}
|
||||
}
|
||||
exports.SelectReplFn = SelectReplFn;
|
||||
26
node_modules/@nestjs/core/repl/repl-context.d.ts
generated
vendored
Normal file
26
node_modules/@nestjs/core/repl/repl-context.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { INestApplicationContext, InjectionToken, Logger } from '@nestjs/common';
|
||||
import { ReplFunction } from './repl-function';
|
||||
import type { ReplFunctionClass } from './repl.interfaces';
|
||||
type ModuleKey = string;
|
||||
export type ModuleDebugEntry = {
|
||||
controllers: Record<string, InjectionToken>;
|
||||
providers: Record<string, InjectionToken>;
|
||||
};
|
||||
type ReplScope = Record<string, any>;
|
||||
export declare class ReplContext {
|
||||
readonly app: INestApplicationContext;
|
||||
readonly logger: Logger;
|
||||
debugRegistry: Record<ModuleKey, ModuleDebugEntry>;
|
||||
readonly globalScope: ReplScope;
|
||||
readonly nativeFunctions: Map<string, ReplFunction<unknown[], any>>;
|
||||
private readonly container;
|
||||
constructor(app: INestApplicationContext, nativeFunctionsClassRefs?: ReplFunctionClass[]);
|
||||
writeToStdout(text: string): void;
|
||||
private initializeContext;
|
||||
private introspectCollection;
|
||||
private stringifyToken;
|
||||
private addNativeFunction;
|
||||
private registerFunctionIntoGlobalScope;
|
||||
private initializeNativeFunctions;
|
||||
}
|
||||
export {};
|
||||
126
node_modules/@nestjs/core/repl/repl-context.js
generated
vendored
Normal file
126
node_modules/@nestjs/core/repl/repl-context.js
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ReplContext = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const application_config_1 = require("../application-config");
|
||||
const injector_1 = require("../injector");
|
||||
const internal_core_module_1 = require("../injector/internal-core-module/internal-core-module");
|
||||
const native_functions_1 = require("./native-functions");
|
||||
class ReplContext {
|
||||
constructor(app, nativeFunctionsClassRefs) {
|
||||
this.app = app;
|
||||
this.logger = new common_1.Logger(ReplContext.name);
|
||||
this.debugRegistry = {};
|
||||
this.globalScope = Object.create(null);
|
||||
this.nativeFunctions = new Map();
|
||||
this.container = app.container; // Using `any` because `app.container` is not public.
|
||||
this.initializeContext();
|
||||
this.initializeNativeFunctions(nativeFunctionsClassRefs || []);
|
||||
}
|
||||
writeToStdout(text) {
|
||||
process.stdout.write(text);
|
||||
}
|
||||
initializeContext() {
|
||||
const modules = this.container.getModules();
|
||||
modules.forEach(moduleRef => {
|
||||
let moduleName = moduleRef.metatype.name;
|
||||
if (moduleName === internal_core_module_1.InternalCoreModule.name) {
|
||||
return;
|
||||
}
|
||||
if (this.globalScope[moduleName]) {
|
||||
moduleName += ` (${moduleRef.token})`;
|
||||
}
|
||||
this.introspectCollection(moduleRef, moduleName, 'providers');
|
||||
this.introspectCollection(moduleRef, moduleName, 'controllers');
|
||||
// For in REPL auto-complete functionality
|
||||
Object.defineProperty(this.globalScope, moduleName, {
|
||||
value: moduleRef.metatype,
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
introspectCollection(moduleRef, moduleKey, collection) {
|
||||
const moduleDebugEntry = {};
|
||||
moduleRef[collection].forEach(({ token }) => {
|
||||
const stringifiedToken = this.stringifyToken(token);
|
||||
if (stringifiedToken === application_config_1.ApplicationConfig.name ||
|
||||
stringifiedToken === moduleRef.metatype.name) {
|
||||
return;
|
||||
}
|
||||
if (!this.globalScope[stringifiedToken]) {
|
||||
// For in REPL auto-complete functionality
|
||||
Object.defineProperty(this.globalScope, stringifiedToken, {
|
||||
value: token,
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
});
|
||||
}
|
||||
if (stringifiedToken === injector_1.ModuleRef.name) {
|
||||
return;
|
||||
}
|
||||
moduleDebugEntry[stringifiedToken] = token;
|
||||
});
|
||||
this.debugRegistry[moduleKey] = {
|
||||
...this.debugRegistry?.[moduleKey],
|
||||
[collection]: moduleDebugEntry,
|
||||
};
|
||||
}
|
||||
stringifyToken(token) {
|
||||
return typeof token !== 'string'
|
||||
? typeof token === 'function'
|
||||
? token.name
|
||||
: token?.toString()
|
||||
: `"${token}"`;
|
||||
}
|
||||
addNativeFunction(NativeFunctionRef) {
|
||||
const nativeFunction = new NativeFunctionRef(this);
|
||||
const nativeFunctions = [nativeFunction];
|
||||
this.nativeFunctions.set(nativeFunction.fnDefinition.name, nativeFunction);
|
||||
nativeFunction.fnDefinition.aliases?.forEach(aliasName => {
|
||||
const aliasNativeFunction = Object.create(nativeFunction);
|
||||
aliasNativeFunction.fnDefinition = {
|
||||
name: aliasName,
|
||||
description: aliasNativeFunction.fnDefinition.description,
|
||||
signature: aliasNativeFunction.fnDefinition.signature,
|
||||
};
|
||||
this.nativeFunctions.set(aliasName, aliasNativeFunction);
|
||||
nativeFunctions.push(aliasNativeFunction);
|
||||
});
|
||||
return nativeFunctions;
|
||||
}
|
||||
registerFunctionIntoGlobalScope(nativeFunction) {
|
||||
// Bind the method to REPL's context:
|
||||
this.globalScope[nativeFunction.fnDefinition.name] =
|
||||
nativeFunction.action.bind(nativeFunction);
|
||||
// Load the help trigger as a `help` getter on each native function:
|
||||
const functionBoundRef = this.globalScope[nativeFunction.fnDefinition.name];
|
||||
Object.defineProperty(functionBoundRef, 'help', {
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
get: () =>
|
||||
// Dynamically builds the help message as will unlikely to be called
|
||||
// several times.
|
||||
this.writeToStdout(nativeFunction.makeHelpMessage()),
|
||||
});
|
||||
}
|
||||
initializeNativeFunctions(nativeFunctionsClassRefs) {
|
||||
const builtInFunctionsClassRefs = [
|
||||
native_functions_1.HelpReplFn,
|
||||
native_functions_1.GetReplFn,
|
||||
native_functions_1.ResolveReplFn,
|
||||
native_functions_1.SelectReplFn,
|
||||
native_functions_1.DebugReplFn,
|
||||
native_functions_1.MethodsReplFn,
|
||||
];
|
||||
builtInFunctionsClassRefs
|
||||
.concat(nativeFunctionsClassRefs)
|
||||
.forEach(NativeFunction => {
|
||||
const nativeFunctions = this.addNativeFunction(NativeFunction);
|
||||
nativeFunctions.forEach(nativeFunction => {
|
||||
this.registerFunctionIntoGlobalScope(nativeFunction);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ReplContext = ReplContext;
|
||||
18
node_modules/@nestjs/core/repl/repl-function.d.ts
generated
vendored
Normal file
18
node_modules/@nestjs/core/repl/repl-function.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { ReplContext } from './repl-context';
|
||||
import type { ReplFnDefinition } from './repl.interfaces';
|
||||
export declare abstract class ReplFunction<ActionParams extends Array<unknown> = Array<unknown>, ActionReturn = any> {
|
||||
protected readonly ctx: ReplContext;
|
||||
/** Metadata that describes the built-in function itself. */
|
||||
abstract fnDefinition: ReplFnDefinition;
|
||||
protected readonly logger: Logger;
|
||||
constructor(ctx: ReplContext);
|
||||
/**
|
||||
* Method called when the function is invoked from the REPL by the user.
|
||||
*/
|
||||
abstract action(...args: ActionParams): ActionReturn;
|
||||
/**
|
||||
* @returns A message displayed by calling `<fnName>.help`
|
||||
*/
|
||||
makeHelpMessage(): string;
|
||||
}
|
||||
19
node_modules/@nestjs/core/repl/repl-function.js
generated
vendored
Normal file
19
node_modules/@nestjs/core/repl/repl-function.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ReplFunction = void 0;
|
||||
const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
|
||||
class ReplFunction {
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
this.logger = ctx.logger;
|
||||
}
|
||||
/**
|
||||
* @returns A message displayed by calling `<fnName>.help`
|
||||
*/
|
||||
makeHelpMessage() {
|
||||
const { description, name, signature } = this.fnDefinition;
|
||||
const fnSignatureWithName = `${name}${signature}`;
|
||||
return `${cli_colors_util_1.clc.yellow(description)}\n${cli_colors_util_1.clc.magentaBright('Interface:')} ${cli_colors_util_1.clc.bold(fnSignatureWithName)}\n`;
|
||||
}
|
||||
}
|
||||
exports.ReplFunction = ReplFunction;
|
||||
5
node_modules/@nestjs/core/repl/repl-logger.d.ts
generated
vendored
Normal file
5
node_modules/@nestjs/core/repl/repl-logger.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { ConsoleLogger } from '@nestjs/common';
|
||||
export declare class ReplLogger extends ConsoleLogger {
|
||||
private static readonly ignoredContexts;
|
||||
log(_message: any, context?: string): void;
|
||||
}
|
||||
22
node_modules/@nestjs/core/repl/repl-logger.js
generated
vendored
Normal file
22
node_modules/@nestjs/core/repl/repl-logger.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ReplLogger = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const nest_application_1 = require("../nest-application");
|
||||
const router_explorer_1 = require("../router/router-explorer");
|
||||
const routes_resolver_1 = require("../router/routes-resolver");
|
||||
class ReplLogger extends common_1.ConsoleLogger {
|
||||
log(_message, context) {
|
||||
if (ReplLogger.ignoredContexts.includes(context)) {
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
return super.log.apply(this, Array.from(arguments));
|
||||
}
|
||||
}
|
||||
exports.ReplLogger = ReplLogger;
|
||||
ReplLogger.ignoredContexts = [
|
||||
routes_resolver_1.RoutesResolver.name,
|
||||
router_explorer_1.RouterExplorer.name,
|
||||
nest_application_1.NestApplication.name,
|
||||
];
|
||||
2
node_modules/@nestjs/core/repl/repl-native-commands.d.ts
generated
vendored
Normal file
2
node_modules/@nestjs/core/repl/repl-native-commands.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { REPLServer } from 'repl';
|
||||
export declare function defineDefaultCommandsOnRepl(replServer: REPLServer): void;
|
||||
46
node_modules/@nestjs/core/repl/repl-native-commands.js
generated
vendored
Normal file
46
node_modules/@nestjs/core/repl/repl-native-commands.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defineDefaultCommandsOnRepl = defineDefaultCommandsOnRepl;
|
||||
/**
|
||||
* Displays a list of available commands in the REPL alongside with their
|
||||
* descriptions.
|
||||
* (c) This code was inspired by the 'help' command from Node.js core:
|
||||
* {@link https://github.com/nodejs/node/blob/58b60c1393dd65cd228a8b0084a19acd2c1d16aa/lib/repl.js#L1741-L1759}
|
||||
*/
|
||||
function listAllCommands(replServer) {
|
||||
Object.keys(replServer.commands)
|
||||
.sort()
|
||||
.forEach(name => {
|
||||
const cmd = replServer.commands[name];
|
||||
if (cmd) {
|
||||
replServer.output.write(`${name}\t${cmd.help || ''}\n`);
|
||||
}
|
||||
});
|
||||
}
|
||||
function defineDefaultCommandsOnRepl(replServer) {
|
||||
replServer.defineCommand('help', {
|
||||
help: 'Show REPL options',
|
||||
action(name) {
|
||||
this.clearBufferedCommand();
|
||||
if (name) {
|
||||
// Considering native commands before native nestjs injected functions.
|
||||
const nativeCommandOrFunction = this.commands[name] || this.context[name];
|
||||
// NOTE: If the command was retrieve from the context, it will have a `help`
|
||||
// getter property that outputs the helper message and returns undefined.
|
||||
// But if the command was retrieve from the `commands` object, it will
|
||||
// have a `help` property that returns the helper message.
|
||||
const helpMessage = nativeCommandOrFunction?.help;
|
||||
if (helpMessage) {
|
||||
this.output.write(`${helpMessage}\n`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
listAllCommands(this);
|
||||
this.output.write('\n\n');
|
||||
this.context.help();
|
||||
this.output.write('\nPress Ctrl+C to abort current expression, Ctrl+D to exit the REPL\n');
|
||||
}
|
||||
this.displayPrompt();
|
||||
},
|
||||
});
|
||||
}
|
||||
3
node_modules/@nestjs/core/repl/repl.d.ts
generated
vendored
Normal file
3
node_modules/@nestjs/core/repl/repl.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { DynamicModule, Type } from '@nestjs/common';
|
||||
import type { ReplOptions } from 'repl';
|
||||
export declare function repl(module: Type | DynamicModule, replOptions?: ReplOptions): Promise<import("node:repl").REPLServer>;
|
||||
16
node_modules/@nestjs/core/repl/repl.interfaces.d.ts
generated
vendored
Normal file
16
node_modules/@nestjs/core/repl/repl.interfaces.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { ReplContext } from './repl-context';
|
||||
import type { ReplFunction } from './repl-function';
|
||||
export type ReplFnDefinition = {
|
||||
/** Function's name. Note that this should be a valid JavaScript function name. */
|
||||
name: string;
|
||||
/** Alternative names to the function. */
|
||||
aliases?: ReplFnDefinition['name'][];
|
||||
/** Function's description to display when `<function>.help` is entered. */
|
||||
description: string;
|
||||
/**
|
||||
* Function's signature following TypeScript _function type expression_ syntax.
|
||||
* @example '(token: InjectionToken) => any'
|
||||
*/
|
||||
signature: string;
|
||||
};
|
||||
export type ReplFunctionClass = new (replContext: ReplContext) => ReplFunction;
|
||||
2
node_modules/@nestjs/core/repl/repl.interfaces.js
generated
vendored
Normal file
2
node_modules/@nestjs/core/repl/repl.interfaces.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
32
node_modules/@nestjs/core/repl/repl.js
generated
vendored
Normal file
32
node_modules/@nestjs/core/repl/repl.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.repl = repl;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
|
||||
const nest_factory_1 = require("../nest-factory");
|
||||
const assign_to_object_util_1 = require("./assign-to-object.util");
|
||||
const constants_1 = require("./constants");
|
||||
const repl_context_1 = require("./repl-context");
|
||||
const repl_logger_1 = require("./repl-logger");
|
||||
const repl_native_commands_1 = require("./repl-native-commands");
|
||||
async function repl(module, replOptions = {}) {
|
||||
const app = await nest_factory_1.NestFactory.createApplicationContext(module, {
|
||||
abortOnError: false,
|
||||
logger: new repl_logger_1.ReplLogger(),
|
||||
});
|
||||
await app.init();
|
||||
const replContext = new repl_context_1.ReplContext(app);
|
||||
common_1.Logger.log(constants_1.REPL_INITIALIZED_MESSAGE);
|
||||
const _repl = await Promise.resolve().then(() => require('repl'));
|
||||
const replServer = _repl.start({
|
||||
prompt: cli_colors_util_1.clc.green('> '),
|
||||
ignoreUndefined: true,
|
||||
...replOptions,
|
||||
});
|
||||
(0, assign_to_object_util_1.assignToObject)(replServer.context, replContext.globalScope);
|
||||
(0, repl_native_commands_1.defineDefaultCommandsOnRepl)(replServer);
|
||||
replServer.on('exit', async () => {
|
||||
await app.close();
|
||||
});
|
||||
return replServer;
|
||||
}
|
||||
Reference in New Issue
Block a user