@getstrata/starter 1.0.9 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,95 +0,0 @@
1
- import { runProviderPhase } from "@getstrata/bootstrap/context";
2
- import {
3
- type AppContext,
4
- type AppDependencies,
5
- type AppRouteMap,
6
- assertAppDependenciesComplete,
7
- type ConfigStore,
8
- type MutableAppDependencies,
9
- type ProviderContext,
10
- ServiceContainer,
11
- } from "@getstrata/bootstrap/contracts";
12
- import { createWebServer } from "@getstrata/bootstrap/web/server";
13
- import { isProductionEnv } from "@getstrata/core/runtime/appEnv";
14
- import { setActiveApplicationContext } from "@getstrata/core/runtime/applicationRegistry";
15
- import { migrate } from "../db/migrate.ts";
16
- import { buildRoutes } from "../routes.ts";
17
- import { loadConfig } from "./config.ts";
18
- import { starterProviders } from "./providers/index.ts";
19
-
20
- export interface BootstrapOptions {
21
- migrate?: boolean;
22
- }
23
-
24
- export interface BootstrappedApp {
25
- context: AppContext;
26
- routes: AppRouteMap;
27
- config: ReturnType<typeof loadConfig>;
28
- }
29
-
30
- class AppConfigStore {
31
- private readonly values = new Map<string, unknown>();
32
-
33
- set<T>(key: string, value: T): T {
34
- this.values.set(key, value);
35
- return value;
36
- }
37
-
38
- get<T>(key: string): T | undefined {
39
- return this.values.get(key) as T | undefined;
40
- }
41
-
42
- require<T>(key: string): T {
43
- const value = this.get<T>(key);
44
- if (value === undefined) {
45
- throw new Error(`Missing required config value "${key}".`);
46
- }
47
- return value;
48
- }
49
-
50
- has(key: string): boolean {
51
- return this.values.has(key);
52
- }
53
- }
54
-
55
- function createAppContext(): AppContext {
56
- const container = new ServiceContainer();
57
- const config = new AppConfigStore() as unknown as ConfigStore;
58
- const dependencies: MutableAppDependencies = { container };
59
- const context: ProviderContext = { container, config, dependencies };
60
-
61
- runProviderPhase(starterProviders, "register", context);
62
- runProviderPhase(starterProviders, "boot", context);
63
-
64
- assertAppDependenciesComplete(dependencies);
65
-
66
- const appContext = { container, config, dependencies: dependencies as AppDependencies };
67
- setActiveApplicationContext(appContext as never);
68
- return appContext;
69
- }
70
-
71
- export async function bootstrapApp(options: BootstrapOptions = {}): Promise<BootstrappedApp> {
72
- const isProduction = isProductionEnv();
73
- const { migrate: runMigrate = !isProduction } = options;
74
-
75
- const appConfig = loadConfig();
76
- const context = createAppContext();
77
-
78
- if (runMigrate) {
79
- await migrate();
80
- }
81
-
82
- const routes = buildRoutes(context.dependencies);
83
-
84
- return { context, routes, config: appConfig };
85
- }
86
-
87
- export function createAppServer(routes: AppRouteMap, port = 0) {
88
- return createWebServer({
89
- port,
90
- publicDir: "./public",
91
- routes,
92
- });
93
- }
94
-
95
- export { createAppContext };