create-strata 2.2.59 → 3.0.4
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.
- package/dist/cli.js +2087 -1636
- package/dist/templates/overlays/spa-react/frontend/src/examples/notes.ts +4 -7
- package/dist/templates/package.json +3 -3
- package/dist/templates/src/bootstrap/preload.ts +0 -4
- package/dist/templates/src/bootstrap/providers/cache.ts +11 -29
- package/dist/templates/src/bootstrap/providers/storage.ts +9 -9
- package/dist/templates/src/bootstrap/server.ts +13 -32
- package/dist/templates/src/modules/site/index.ts +4 -7
- package/dist/templates/src/routes.ts +6 -3
- package/package.json +1 -1
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
/** Displayed source only; business handlers execute after the developer adds this module. */
|
|
2
2
|
export function notesModuleExample(tenancy: boolean): string {
|
|
3
|
-
const
|
|
4
|
-
? 'import { currentTenantId } from "@getstrata/core/tenant/tenantContext";\n'
|
|
5
|
-
: "";
|
|
6
|
-
const scope = tenancy ? ".where({ tenant_id: currentTenantId() })" : "";
|
|
3
|
+
const scope = tenancy ? ".where({ tenant_id: ports.established.tenant.id })" : "";
|
|
7
4
|
return `// src/modules/notes/index.ts
|
|
8
5
|
import type { AppModule } from "@getstrata/bootstrap/contracts";
|
|
9
6
|
import { jsonResponse } from "@getstrata/core/http/response";
|
|
10
|
-
|
|
7
|
+
import { Note } from "../../models/Note.ts";
|
|
11
8
|
|
|
12
9
|
export default {
|
|
13
10
|
name: "notes",
|
|
14
11
|
routes({ kernel }) {
|
|
15
12
|
return {
|
|
16
13
|
"/api/v1/notes": {
|
|
17
|
-
GET: kernel.wrapApi(async () => {
|
|
18
|
-
const rows = await Note.query()${scope}.orderBy({ column: "id", direction: "DESC" }).limit(100).get();
|
|
14
|
+
GET: kernel.wrapApi(async (_request, ports) => {
|
|
15
|
+
const rows = await ports.database.model(Note).query()${scope}.orderBy({ column: "id", direction: "DESC" }).limit(100).get();
|
|
19
16
|
return jsonResponse({ data: rows.map(row => row.toObject()) });
|
|
20
17
|
}),
|
|
21
18
|
},
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"check": "tsc --noEmit"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@getstrata/bootstrap": "^
|
|
16
|
-
"@getstrata/cli": "^
|
|
17
|
-
"@getstrata/core": "^
|
|
15
|
+
"@getstrata/bootstrap": "^3.0.4",
|
|
16
|
+
"@getstrata/cli": "^3.0.4",
|
|
17
|
+
"@getstrata/core": "^3.0.4",
|
|
18
18
|
"eta": "^4.6.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { configureModulesDirectory } from "@getstrata/bootstrap/discoverModules";
|
|
3
|
-
|
|
4
1
|
process.env.DATABASE_URL ??=
|
|
5
2
|
"postgresql://postgres:dev-postgres-change-me@localhost:5432/{{PROJECT_NAME}}";
|
|
6
|
-
configureModulesDirectory(join(import.meta.dir, "../modules"));
|
|
@@ -1,30 +1,12 @@
|
|
|
1
1
|
import { CORE_CACHE_TOKEN } from "@getstrata/bootstrap/config";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const cache = new CacheRepository(
|
|
15
|
-
createCacheStore({
|
|
16
|
-
driver,
|
|
17
|
-
ttlMs,
|
|
18
|
-
maxEntries,
|
|
19
|
-
redisUrl: process.env.REDIS_URL,
|
|
20
|
-
}),
|
|
21
|
-
);
|
|
22
|
-
onCleanup(() => cache.close());
|
|
23
|
-
return cache;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
Reflect.set(dependencies, "cache", container.resolve(CORE_CACHE_TOKEN));
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default cacheProvider;
|
|
2
|
+
import type { AppDependencies, ServiceProvider } from "@getstrata/bootstrap/contracts";
|
|
3
|
+
/** Adapt the already graph-owned cache; this provider never creates or closes it. */
|
|
4
|
+
export function createCacheProvider(cache: AppDependencies["cache"]): ServiceProvider {
|
|
5
|
+
return {
|
|
6
|
+
name: "starter.cache",
|
|
7
|
+
register({ container, dependencies }) {
|
|
8
|
+
container.set(CORE_CACHE_TOKEN, cache);
|
|
9
|
+
dependencies.cache = cache;
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ServiceProvider } from "@getstrata/core/contracts/di";
|
|
2
|
-
import {
|
|
2
|
+
import type { StorageManager } from "@getstrata/core/storage/storage";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
export function createStorageProvider(storage: StorageManager): ServiceProvider {
|
|
5
|
+
return {
|
|
6
|
+
name: "starter.storage",
|
|
7
|
+
register({ dependencies }) {
|
|
8
|
+
Reflect.set(dependencies, "storage", storage);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -3,38 +3,19 @@ import {
|
|
|
3
3
|
installGracefulShutdownSignals,
|
|
4
4
|
LifecycleCoordinator,
|
|
5
5
|
} from "@getstrata/core/lifecycle/gracefulShutdown";
|
|
6
|
-
import {
|
|
7
|
-
import { closeDatabase } from "./database.ts";
|
|
6
|
+
import { createAppServer } from "./createApp.ts";
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
// HTTP is declared before start and acquired by this application's journal.
|
|
9
|
+
const app = await createAppServer();
|
|
10
|
+
if (!app.server) throw new Error("HTTP transport did not start.");
|
|
11
|
+
console.log(`Listening on ${app.server.url.origin} (APP_URL ${app.config.appUrl})`);
|
|
10
12
|
const lifecycle = new LifecycleCoordinator();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} catch (error) {
|
|
20
|
-
const failures: unknown[] = [];
|
|
21
|
-
for (const cleanup of [() => context.dispose(), closeDatabase]) {
|
|
22
|
-
try {
|
|
23
|
-
await cleanup();
|
|
24
|
-
} catch (failure) {
|
|
25
|
-
failures.push(failure);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (failures.length)
|
|
29
|
-
throw new AggregateError([error, ...failures], "Application startup and cleanup failed.", {
|
|
30
|
-
cause: error,
|
|
31
|
-
});
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
console.log(`Listening on ${server.url.origin} (APP_URL ${config.appUrl})`);
|
|
35
|
-
|
|
36
|
-
lifecycle.register("providers:drain", () => context.drain(), "drain");
|
|
37
|
-
lifecycle.register("providers:flush", () => context.flush(), "flush");
|
|
38
|
-
lifecycle.register("providers:close", () => context.dispose(), "close");
|
|
39
|
-
lifecycle.register("database", closeDatabase, "close");
|
|
13
|
+
lifecycle.register(
|
|
14
|
+
"application",
|
|
15
|
+
async () => {
|
|
16
|
+
const result = await app.application.stop({ reason: "SIGNAL" });
|
|
17
|
+
if (!result.successful) throw new Error("Application shutdown did not complete cleanly.");
|
|
18
|
+
},
|
|
19
|
+
"stop",
|
|
20
|
+
);
|
|
40
21
|
installGracefulShutdownSignals(undefined, lifecycle);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AppModule } from "@getstrata/bootstrap/contracts";
|
|
2
|
-
import { withErrorHandling } from "@getstrata/core/http/response";
|
|
3
2
|
import { CORE_VIEW_RENDERER_TOKEN, textResponse } from "@getstrata/core/view";
|
|
4
3
|
import { pingDatabase } from "../../bootstrap/database.ts";
|
|
5
4
|
|
|
@@ -21,12 +20,10 @@ const siteModule: AppModule = {
|
|
|
21
20
|
{ request },
|
|
22
21
|
),
|
|
23
22
|
),
|
|
24
|
-
"/health": kernel.wrapWeb(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}),
|
|
29
|
-
),
|
|
23
|
+
"/health": kernel.wrapWeb(async (_request, { database }) => {
|
|
24
|
+
const dbOk = await pingDatabase(database);
|
|
25
|
+
return textResponse(dbOk ? "ok" : "degraded", { status: dbOk ? 200 : 503 });
|
|
26
|
+
}),
|
|
30
27
|
};
|
|
31
28
|
},
|
|
32
29
|
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { buildWebModuleRoutes } from "@getstrata/bootstrap/buildWebModuleRoutes";
|
|
2
|
-
import type { AppDependencies, AppRouteMap } from "@getstrata/bootstrap/contracts";
|
|
2
|
+
import type { AppDependencies, AppModule, AppRouteMap } from "@getstrata/bootstrap/contracts";
|
|
3
3
|
import { isViewsEnabled } from "@getstrata/core/runtime/frontendMode";
|
|
4
4
|
|
|
5
|
-
export function buildRoutes(
|
|
6
|
-
|
|
5
|
+
export function buildRoutes(
|
|
6
|
+
dependencies: AppDependencies,
|
|
7
|
+
modules: readonly AppModule[],
|
|
8
|
+
): AppRouteMap {
|
|
9
|
+
return isViewsEnabled() ? buildWebModuleRoutes(dependencies, { modules }) : {};
|
|
7
10
|
}
|