import { authContextGenerator, authPluginGenerator, authRolesGenerator, pothosAuthGenerator, prismaAuthorizerUtilsGenerator, prismaQueryFilterUtilsGenerator, userSessionTypesGenerator, } from '@baseplate-dev/fastify-generators';
import { appCompilerSpec, backendAppEntryType, createPluginModule, PluginUtils, webAppEntryType, } from '@baseplate-dev/project-builder-lib';
import { authErrorsGenerator, authIdentifyGenerator, } from '@baseplate-dev/react-generators';
export default createPluginModule({
    name: 'node',
    dependencies: {
        appCompiler: appCompilerSpec,
    },
    initialize: ({ appCompiler }, { pluginKey }) => {
        // register backend compiler
        appCompiler.compilers.push({
            pluginKey,
            appType: backendAppEntryType,
            compile: ({ projectDefinition, appCompiler }) => {
                const auth = PluginUtils.configByKeyOrThrow(projectDefinition, pluginKey);
                appCompiler.addChildrenToFeature(auth.authFeatureRef, {
                    authContext: authContextGenerator({}),
                    authPlugin: authPluginGenerator({}),
                    authRoles: authRolesGenerator({
                        roles: auth.roles.map((r) => ({
                            name: r.name,
                            comment: r.comment,
                            builtIn: r.builtIn,
                        })),
                    }),
                    userSessionTypes: userSessionTypesGenerator({}),
                });
                appCompiler.addRootChildren({
                    pothosAuth: pothosAuthGenerator({}),
                    authorizerUtils: prismaAuthorizerUtilsGenerator({}),
                    queryFilterUtils: prismaQueryFilterUtilsGenerator({}),
                });
            },
        }, {
            pluginKey,
            appType: webAppEntryType,
            compile: ({ appCompiler }) => {
                appCompiler.addRootChildren({
                    authIdentify: authIdentifyGenerator({}),
                    authErrors: authErrorsGenerator({}),
                });
            },
        });
    },
});
//# sourceMappingURL=node.js.map