bazis 0.110.0 → 0.111.0

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.
@@ -6,15 +6,18 @@ import {
6
6
  Global,
7
7
  Module,
8
8
  singletonValue,
9
+ CLASS_PROVIDER_HOOK,
9
10
  type BazisModuleRef,
10
11
  } from "../di";
11
12
  import { loadBazisGeneratedRuntime } from "../generatedRuntime";
12
13
  import { missingCacheModuleCheck } from "../cache/http/missingCacheModuleCheck";
14
+ import { cacheableClassProviderHook } from "../cache/di/classProviderHook";
13
15
  import { httpModule, useModelValidator, type HttpModuleOptions, type ModelValidator } from "../http";
14
16
  import { grpcModule, type GrpcModuleOptions } from "../grpc";
15
17
  import { buildHttpOpenApiDocument } from "../http/OpenApi/openApiDocument";
16
18
  import { defaultAuthorizeChecks } from "../http/Authorization/metadata";
17
19
  import { KernelBuilder, Bazis, KernelError, type KernelOptions, type ValidatableConfig } from "../kernel";
20
+ import { reportBuildFailure } from "../kernel/Bazis";
18
21
  import { websocketModule, type WebSocketOptions } from "../websocket";
19
22
  import {
20
23
  isUiProfileAuthoringClass,
@@ -287,7 +290,14 @@ function normalizeAbsolutePath(path: string): string {
287
290
  */
288
291
  export async function runApp(root: BazisModuleRef, options: RunAppOptions = {}): Promise<number> {
289
292
  await loadBazisGeneratedRuntime();
290
- return Bazis.run(composeApp(root, options), options.kernel, (builder) => {
293
+ let app: BazisModuleRef;
294
+ try {
295
+ app = composeApp(root, options);
296
+ } catch (error) {
297
+ // Composing already reads routes and options: report its errors like the kernel build does.
298
+ return reportBuildFailure(error);
299
+ }
300
+ return Bazis.run(app, options.kernel, (builder) => {
291
301
  builder.useApplicationRoot(root);
292
302
  options.configure?.(builder);
293
303
  });
@@ -314,6 +324,11 @@ export function composeApp(root: BazisModuleRef, options: RunAppOptions = {}): B
314
324
  // Warns about @OutputCache routes when no cache module is installed.
315
325
  globals.push({ global: true, providers: [missingCacheModuleCheck()] });
316
326
  }
327
+ // The cache wrapper of @Cacheable / @CacheableRedis classes, also without a cache
328
+ // module: it then needs ICache, and the graph check names the class and says to add
329
+ // cache: memory(). Without it the decorators would silently do nothing. The cache
330
+ // module registers the same hook, and DI keeps one.
331
+ globals.push({ global: true, providers: [singletonValue(CLASS_PROVIDER_HOOK, cacheableClassProviderHook)] });
317
332
  const appRoot: BazisModuleRef =
318
333
  globals.length > 0 || options.config !== undefined
319
334
  ? {
@@ -232,7 +232,7 @@ export class CodexAppServerClient implements CodexClient {
232
232
  if (method === "account/updated") this.modelCache = undefined;
233
233
  }, () => { this.clearLogin(); this.modelCache = undefined; });
234
234
  const initialized = await client.request("initialize", {
235
- clientInfo: { name: "bazis", title: "Bazis", version: "0.110.0" }, capabilities: { experimentalApi: true },
235
+ clientInfo: { name: "bazis", title: "Bazis", version: "0.111.0" }, capabilities: { experimentalApi: true },
236
236
  }, 15_000, signal);
237
237
  if (resolve(text(initialized.codexHome, 4096)) !== this.paths.home) throw new CodexError("PROTOCOL_ERROR");
238
238
  client.notify("initialized");
@@ -47,17 +47,7 @@ export class Bazis {
47
47
  try {
48
48
  kernel = await builder.build();
49
49
  } catch (error) {
50
- if (screen !== undefined && !(error instanceof ShutdownTimeoutError)) {
51
- screen.failed(error, undefined, builder.report);
52
- process.exitCode = 1;
53
- return 1;
54
- }
55
- if (error instanceof DiError || error instanceof KernelError) {
56
- console.error(`[bazis] configuration error: ${redactSensitiveText(error.message)}`);
57
- process.exitCode = 1;
58
- return 1;
59
- }
60
- throw error;
50
+ return reportBuildFailure(error, screen, builder.report);
61
51
  }
62
52
 
63
53
  try {
@@ -96,3 +86,27 @@ export class Bazis {
96
86
  }
97
87
  }
98
88
  }
89
+
90
+ /**
91
+ * @internal How a start that failed before the kernel was built is reported:
92
+ * the startup screen on a terminal, otherwise one `[bazis] configuration error`
93
+ * line for DI and kernel errors. Returns exit code 1; anything else is rethrown.
94
+ * `runApp` uses it for errors found while it composes the application.
95
+ */
96
+ export function reportBuildFailure(
97
+ error: unknown,
98
+ screen: StartupScreen | undefined = startupScreenEnabled() ? new StartupScreen() : undefined,
99
+ report?: KernelBuilder["report"],
100
+ ): number {
101
+ if (screen !== undefined && !(error instanceof ShutdownTimeoutError)) {
102
+ screen.failed(error, undefined, report);
103
+ process.exitCode = 1;
104
+ return 1;
105
+ }
106
+ if (error instanceof DiError || error instanceof KernelError) {
107
+ console.error(`[bazis] configuration error: ${redactSensitiveText(error.message)}`);
108
+ process.exitCode = 1;
109
+ return 1;
110
+ }
111
+ throw error;
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bazis",
3
- "version": "0.110.0",
3
+ "version": "0.111.0",
4
4
  "description": "Modular backend framework for Bun in TypeScript: DI wired by codegen, HTTP, a PostgreSQL ORM, JWT, WebSocket, agents and a CLI.",
5
5
  "license": "MIT",
6
6
  "author": "Alexander Alenin",