import * as path from "https://deno.land/std@0.159.0/path/mod.ts";
export {MigrationsBuilder} from './migrations.ts';export {RoutesBuilder, AuthAllow} from './approutes.ts';export type {Context} from './approutes.ts';
import type {User} from './users.ts';
import type {AppRoute as AppRouteInternal} from 'https://deno.land/x/dropserver_lib_support@v0.2.0/mod.ts';import type {Migrations} from './migrations.ts';
import mustGetLibSupport from './getlibsupport.ts';
export class DropserverApp { appPath(p:string) :string { const internal = mustGetLibSupport(); return path.join(internal.appPath, p); } appspacePath(p:string) :string { const internal = mustGetLibSupport(); return path.join(internal.appspacePath, p); } avatarsPath(p:string) :string { return path.join(mustGetLibSupport().avatarsPath, p); }
async getUsers() :Promise<User[]> { const l = mustGetLibSupport(); return await l.users.getAll(); } async getUser(proxyId:string) :Promise<User> { const l = mustGetLibSupport(); return await l.users.get(proxyId); }}
type AppRoutesFn = ()=>AppRouteInternal[];
type MigrationsFn = () => Migrations;type MigrationsPr = () => Promise<Migrations>;
export interface AppConfig { routes : AppRouteInternal[] | AppRoutesFn migrations? :Migrations | MigrationsFn | MigrationsPr}
export function createApp(config:AppConfig) :DropserverApp { const libSupport = mustGetLibSupport(); let routes :AppRoutesFn|undefined; if( typeof config.routes === "function" ) routes = config.routes; else if( Array.isArray(config.routes) ) routes = (() => <AppRouteInternal[]>config.routes); if( routes === undefined ) throw new Error("routes is missing or not recognized type"); libSupport.appRoutes.setCallback(routes);
let migrations : MigrationsFn | MigrationsPr | undefined; if( typeof config.migrations === "function" ) migrations = config.migrations; else if( Array.isArray(config.migrations) ) migrations = () => <Migrations>config.migrations; else if( config.migrations !== undefined ) throw new Error("Wrong type for migrations"); libSupport.migrations.setCallback(migrations);
return new DropserverApp;}