"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__ΩReplContext = void 0;
exports.buildReplContext = buildReplContext;
const __ΩRecord = ['K', 'T', 'Record', 'l\'e#"Rb!b"Pde"!N#!w#y'];
function __assignType(fn, args) {
    fn.__type = args;
    return fn;
}
const orm_1 = require("@deepkit/orm");
const resolver_1 = require("../../app/resolver");
const injection_1 = require("../../helpers/framework/injection");
const __ΩReplContext = [() => __ΩRecord, 'classProvider', () => __ΩRecord, 'instanceProvider', 'ReplContext', 'P&#o!#4"&#o##4$Mw%y'];
exports.__ΩReplContext = __ΩReplContext;
/**
 * Build the REPL context with `$` (class providers) and `$$` (instance providers + entity classes).
 * Also sets `global.$` and `global.$$` for use in eval contexts.
 */
function buildReplContext() {
    const databaseRegistry = (0, resolver_1.r)(orm_1.DatabaseRegistry);
    databaseRegistry.init();
    const providers = (0, injection_1.getProviderTree)((0, resolver_1.getAppModule)());
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const classProvider = {};
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const instanceProvider = {};
    for (const provider of providers) {
        if (!(provider.name in classProvider)) {
            Object.defineProperty(classProvider, provider.name, {
                get: __assignType(function get() {
                    return provider.provide;
                }, ['get', 'P"/!'])
            });
        }
        if (!(provider.name in instanceProvider)) {
            Object.defineProperty(instanceProvider, provider.name, {
                get: __assignType(function get() {
                    const injector = (0, resolver_1.getOrCreateInjectorForModule)(provider.module);
                    return injector.get(provider.provide);
                }, ['get', 'P"/!'])
            });
        }
    }
    for (const database of databaseRegistry.getDatabases()) {
        for (const entity of database.entityRegistry.all()) {
            Object.defineProperty(instanceProvider, entity.type.typeName, {
                get: __assignType(function get() {
                    return entity.getClassType();
                }, ['get', 'P"/!'])
            });
        }
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    global.$ = classProvider;
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    global.$$ = instanceProvider;
    return { classProvider, instanceProvider };
}
buildReplContext.__type = [() => __ΩReplContext, 'buildReplContext', 'Pn!/"'];
//# sourceMappingURL=repl-context.js.map