MCPcopy Index your code
hub / github.com/loopbackio/loopback-next /

Class

packages/boot/src/mixins/boot.mixin.ts:47–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45 */
46export function BootMixin<T extends MixinTarget<Application>>(superClass: T) {
47 return class extends superClass implements Bootable {
48 projectRoot: string;
49 bootOptions?: BootOptions;
50
51 // eslint-disable-next-line @typescript-eslint/no-explicit-any
52 constructor(...args: any[]) {
53 super(...args);
54 this.component(BootComponent);
55
56 // We Dynamically bind the Project Root and Boot Options so these values can
57 // be used to resolve an instance of the Bootstrapper (as they are dependencies)
58 this.bind(BootBindings.PROJECT_ROOT).toDynamicValue(
59 () => this.projectRoot,
60 );
61 this.bind(BootBindings.BOOT_OPTIONS).toDynamicValue(
62 () => this.bootOptions ?? {},
63 );
64 }
65
66 booted: boolean;
67
68 /**
69 * Override to detect and warn about starting without booting.
70 */
71 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
72 // @ts-ignore
73 public async start(): Promise<void> {
74 await super.start();
75 if (!this.booted) {
76 process.emitWarning(
77 'App started without booting. Did you forget to call ' +
78 '`await app.boot()`?',
79 'LoopBackWarning',
80 );
81 }
82 }
83
84 /**
85 * Convenience method to call bootstrapper.boot() by resolving bootstrapper
86 */
87 async boot(): Promise<void> {
88 /* eslint-disable @typescript-eslint/ban-ts-comment */
89 // A workaround to access protected Application methods
90 const self = this as unknown as Application;
91
92 if (this.state === 'booting') {
93 // @ts-ignore
94 return self.awaitState('booted');
95 }
96 // @ts-ignore
97 self.assertNotInProcess('boot');
98 // @ts-ignore
99 self.assertInStates('boot', 'created', 'booted');
100
101 if (this.state === 'booted') return;
102 // @ts-ignore
103 self.setState('booting');
104

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected