@supacloud/elysia 0.44.0 → 0.45.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.
package/dist/bun-aot.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { Elysia as Elysia4, setupTypebox, Validator as Validator2 } from "elysia";
2
+ import { Elysia as Elysia5, setupTypebox, Validator as Validator2 } from "elysia";
3
3
  import { requireFeatureRequestContext } from "@supacloud/app";
4
4
  import { composeAspects as composeApplicationAspects, invokeAspect, freezeAspectData } from "@supacloud/app/execution";
5
5
  import { PendingWorkRegistry as PendingWorkRegistry2, PendingWorkTimeoutError, PendingWorkCapacityError } from "@supacloud/app/pending-work";
@@ -2268,6 +2268,103 @@ class SupaCloudWorker {
2268
2268
  function createWorker(options) {
2269
2269
  return new SupaCloudWorker(options);
2270
2270
  }
2271
+ // src/health-probe.ts
2272
+ import { Elysia as Elysia4 } from "elysia";
2273
+ async function runSingleProbe(indicator, probe) {
2274
+ if (!probe) {
2275
+ return {
2276
+ id: indicator.id,
2277
+ kind: indicator.kind,
2278
+ resourceName: indicator.resourceName,
2279
+ critical: indicator.critical,
2280
+ status: "unbound",
2281
+ durationMs: 0,
2282
+ detail: `No health probe registered for "${indicator.id}"`
2283
+ };
2284
+ }
2285
+ const startedAt = performance.now();
2286
+ let timer = null;
2287
+ const timeoutPromise = new Promise((resolve) => {
2288
+ timer = setTimeout(() => resolve("__PROBE_TIMEOUT__"), Math.max(1, indicator.timeoutMs));
2289
+ });
2290
+ try {
2291
+ const outcome = await Promise.race([Promise.resolve().then(() => probe()), timeoutPromise]);
2292
+ const durationMs = Math.round((performance.now() - startedAt) * 100) / 100;
2293
+ if (outcome === "__PROBE_TIMEOUT__") {
2294
+ return {
2295
+ id: indicator.id,
2296
+ kind: indicator.kind,
2297
+ resourceName: indicator.resourceName,
2298
+ critical: indicator.critical,
2299
+ status: "timeout",
2300
+ durationMs,
2301
+ detail: `Probe timed out after ${indicator.timeoutMs}ms`
2302
+ };
2303
+ }
2304
+ if (outcome === false) {
2305
+ return {
2306
+ id: indicator.id,
2307
+ kind: indicator.kind,
2308
+ resourceName: indicator.resourceName,
2309
+ critical: indicator.critical,
2310
+ status: "down",
2311
+ durationMs,
2312
+ detail: "Probe returned false"
2313
+ };
2314
+ }
2315
+ return {
2316
+ id: indicator.id,
2317
+ kind: indicator.kind,
2318
+ resourceName: indicator.resourceName,
2319
+ critical: indicator.critical,
2320
+ status: "up",
2321
+ durationMs,
2322
+ ...typeof outcome === "string" && outcome ? { detail: outcome } : {}
2323
+ };
2324
+ } catch (err) {
2325
+ const durationMs = Math.round((performance.now() - startedAt) * 100) / 100;
2326
+ return {
2327
+ id: indicator.id,
2328
+ kind: indicator.kind,
2329
+ resourceName: indicator.resourceName,
2330
+ critical: indicator.critical,
2331
+ status: "down",
2332
+ durationMs,
2333
+ detail: err instanceof Error ? err.message : String(err)
2334
+ };
2335
+ } finally {
2336
+ if (timer !== null)
2337
+ clearTimeout(timer);
2338
+ }
2339
+ }
2340
+ function createHealthProbePlugin(options) {
2341
+ const livePath = options.livePath ?? options.graph.livePath ?? "/health/live";
2342
+ const readyPath = options.readyPath ?? options.graph.readyPath ?? "/health/ready";
2343
+ const startedAtMs = options.startedAtMs ?? Date.now();
2344
+ return new Elysia4({ name: "supacloud-health-probes" }).get(livePath, () => ({
2345
+ status: "ok",
2346
+ uptimeSec: Math.max(0, Math.floor((Date.now() - startedAtMs) / 1000))
2347
+ })).get(readyPath, async ({ set }) => {
2348
+ if (options.isDraining?.()) {
2349
+ set.status = 503;
2350
+ return {
2351
+ status: "draining",
2352
+ checks: []
2353
+ };
2354
+ }
2355
+ const checks = await Promise.all(options.graph.indicators.map((indicator) => runSingleProbe(indicator, options.probes[indicator.id])));
2356
+ const criticalDown = checks.some((c) => c.critical && c.status !== "up");
2357
+ const anyDown = checks.some((c) => c.status !== "up");
2358
+ const summaryStatus = criticalDown ? "unhealthy" : anyDown ? "degraded" : "ok";
2359
+ if (criticalDown) {
2360
+ set.status = 503;
2361
+ }
2362
+ return {
2363
+ status: summaryStatus,
2364
+ checks
2365
+ };
2366
+ });
2367
+ }
2271
2368
 
2272
2369
  // src/index.ts
2273
2370
  setupTypebox();
@@ -2410,10 +2507,10 @@ function contextPlugin(http) {
2410
2507
  seed = ++nextHttpPluginId;
2411
2508
  httpPluginIds.set(http, seed);
2412
2509
  }
2413
- return new Elysia4({ name: "supacloud:http-context", seed }).use(http ?? new Elysia4).as("plugin");
2510
+ return new Elysia5({ name: "supacloud:http-context", seed }).use(http ?? new Elysia5).as("plugin");
2414
2511
  }
2415
2512
  function mountHttp(http, name, normalize = true) {
2416
- return new Elysia4({ name, normalize }).use(contextPlugin(http));
2513
+ return new Elysia5({ name, normalize }).use(contextPlugin(http));
2417
2514
  }
2418
2515
  function resolveCompiledCommand(module, reference) {
2419
2516
  const matches = (module.commands ?? []).filter((command) => command.className === reference || command.name === reference);
@@ -3358,7 +3455,7 @@ function isPublicApplicationError(error) {
3358
3455
  }
3359
3456
  function createApplication(options) {
3360
3457
  const pendingWork = new PendingWorkRegistry2(options.pendingWork ? { capacity: options.pendingWork.capacity } : {});
3361
- const app = new Elysia4({ name: options.name ?? "supacloud:app", normalize: options.normalize ?? true }).use(contextPlugin(options.http).as("global"));
3458
+ const app = new Elysia5({ name: options.name ?? "supacloud:app", normalize: options.normalize ?? true }).use(contextPlugin(options.http).as("global"));
3362
3459
  if (options.documentation)
3363
3460
  app.use(createDocumentationPlugin(options.documentation));
3364
3461
  const ctxFactory = options.requestContext === undefined ? defaultRequestContext : (() => {
@@ -0,0 +1,67 @@
1
+ export interface HealthIndicatorLike {
2
+ readonly id: string;
3
+ readonly kind: string;
4
+ readonly resourceName: string;
5
+ readonly critical: boolean;
6
+ readonly timeoutMs: number;
7
+ }
8
+ export interface HealthCheckGraphLike {
9
+ readonly livePath?: string;
10
+ readonly readyPath?: string;
11
+ readonly indicators: readonly HealthIndicatorLike[];
12
+ }
13
+ export type HealthProbeFn = () => boolean | string | undefined | void | Promise<boolean | string | undefined | void>;
14
+ export type HealthIndicatorCheckStatus = "up" | "down" | "timeout" | "unbound";
15
+ export interface HealthIndicatorCheckResult {
16
+ readonly id: string;
17
+ readonly kind: string;
18
+ readonly resourceName: string;
19
+ readonly critical: boolean;
20
+ readonly status: HealthIndicatorCheckStatus;
21
+ readonly durationMs: number;
22
+ readonly detail?: string;
23
+ }
24
+ export interface HealthProbePluginOptions {
25
+ readonly graph: HealthCheckGraphLike;
26
+ readonly probes: Readonly<Record<string, HealthProbeFn>>;
27
+ readonly livePath?: string;
28
+ readonly readyPath?: string;
29
+ readonly startedAtMs?: number;
30
+ readonly isDraining?: () => boolean;
31
+ }
32
+ /**
33
+ * Registers Terminus-style `/health/live` (zero-I/O liveness) and `/health/ready`
34
+ * (parallel bounded-timeout dependency probes) driven by the compile-time
35
+ * `HealthCheckGraph`.
36
+ */
37
+ export declare function createHealthProbePlugin(options: HealthProbePluginOptions): import("elysia/types").AddRoute<"", "local", import("elysia").DefaultSingleton, {
38
+ typebox: {};
39
+ error: [];
40
+ }, import("elysia").DefaultMetadata, {}, import("elysia").DefaultEphemeral, import("elysia").DefaultEphemeral, "get", string, import("elysia/types").IntersectIfObjectSchema<import("elysia").UnwrapRoute<{}, {}, `/${string}`>, import("elysia/types").MergeScopedSchemas<{}, {}, {}>>, {}, ({ set }: {
41
+ server: import("elysia").Server | null;
42
+ redirect: import("elysia").redirect;
43
+ set: {
44
+ headers: import("elysia").HTTPHeaders;
45
+ status?: number | keyof import("elysia").StatusMap;
46
+ cookie?: Record<string, import("elysia").BaseCookie>;
47
+ redirect?: never;
48
+ };
49
+ status: <const Code extends number | keyof import("elysia").StatusMap, const T = import("elysia").StatusResponse<Code>>(code: Code, response?: T) => import("elysia").ElysiaStatus<Code, T, import("elysia").NumericStatus<Code>>;
50
+ problem: typeof import("elysia").problem;
51
+ defer: (fn: import("elysia/types").AfterResponseHandler<NoInfer<import("elysia/types").IntersectIfObjectSchema<import("elysia").UnwrapRoute<{}, {}, `/${string}`>, import("elysia/types").MergeScopedSchemas<{}, {}, {}>>>, NoInfer<import("elysia").DefaultSingleton & {
52
+ derive: {};
53
+ }>>) => import("elysia/types").MaybePromise<void>;
54
+ readonly path: string;
55
+ route?: string;
56
+ rid?: string;
57
+ request: Request;
58
+ store: {};
59
+ body: unknown;
60
+ query: Record<string, string | undefined>;
61
+ params: {};
62
+ headers: Record<string, string | undefined>;
63
+ cookie: Record<string, import("elysia").Cookie<unknown>>;
64
+ }) => Promise<{
65
+ status: string;
66
+ checks: HealthIndicatorCheckResult[];
67
+ }>>;
package/dist/index.d.ts CHANGED
@@ -509,3 +509,5 @@ export { createMemoryPolicy } from "./memory_policy";
509
509
  export type { MemoryPolicy } from "./memory_policy";
510
510
  export { createQueueWorkerTransport, createRabbitMqQueuePort, createWorker, SupaCloudWorker, WorkerRegistrationError, WorkerReceiptUnconfirmedError, } from "./worker";
511
511
  export type { WorkerAcknowledge, WorkerClaim, WorkerFail, WorkerOptions, QueueWorkerTransportOptions, WorkerQueueFailureOptions, WorkerQueueMessage, WorkerQueuePort, WorkerQueueReceiveOptions, RabbitMqChannel, RabbitMqMessage, RabbitMqQueuePortOptions, WorkerReceiptContext, WorkerReceiptOperation, WorkerRunResult, WorkerState, WorkerTransport, } from "./worker";
512
+ export { createHealthProbePlugin } from "./health-probe";
513
+ export type { HealthCheckGraphLike, HealthIndicatorCheckResult, HealthIndicatorCheckStatus, HealthIndicatorLike, HealthProbeFn, HealthProbePluginOptions, } from "./health-probe";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { Elysia as Elysia4, setupTypebox, Validator as Validator2 } from "elysia";
2
+ import { Elysia as Elysia5, setupTypebox, Validator as Validator2 } from "elysia";
3
3
  import { requireFeatureRequestContext } from "@supacloud/app";
4
4
  import { composeAspects as composeApplicationAspects, invokeAspect, freezeAspectData } from "@supacloud/app/execution";
5
5
  import { PendingWorkRegistry as PendingWorkRegistry2, PendingWorkTimeoutError, PendingWorkCapacityError } from "@supacloud/app/pending-work";
@@ -2268,6 +2268,103 @@ class SupaCloudWorker {
2268
2268
  function createWorker(options) {
2269
2269
  return new SupaCloudWorker(options);
2270
2270
  }
2271
+ // src/health-probe.ts
2272
+ import { Elysia as Elysia4 } from "elysia";
2273
+ async function runSingleProbe(indicator, probe) {
2274
+ if (!probe) {
2275
+ return {
2276
+ id: indicator.id,
2277
+ kind: indicator.kind,
2278
+ resourceName: indicator.resourceName,
2279
+ critical: indicator.critical,
2280
+ status: "unbound",
2281
+ durationMs: 0,
2282
+ detail: `No health probe registered for "${indicator.id}"`
2283
+ };
2284
+ }
2285
+ const startedAt = performance.now();
2286
+ let timer = null;
2287
+ const timeoutPromise = new Promise((resolve) => {
2288
+ timer = setTimeout(() => resolve("__PROBE_TIMEOUT__"), Math.max(1, indicator.timeoutMs));
2289
+ });
2290
+ try {
2291
+ const outcome = await Promise.race([Promise.resolve().then(() => probe()), timeoutPromise]);
2292
+ const durationMs = Math.round((performance.now() - startedAt) * 100) / 100;
2293
+ if (outcome === "__PROBE_TIMEOUT__") {
2294
+ return {
2295
+ id: indicator.id,
2296
+ kind: indicator.kind,
2297
+ resourceName: indicator.resourceName,
2298
+ critical: indicator.critical,
2299
+ status: "timeout",
2300
+ durationMs,
2301
+ detail: `Probe timed out after ${indicator.timeoutMs}ms`
2302
+ };
2303
+ }
2304
+ if (outcome === false) {
2305
+ return {
2306
+ id: indicator.id,
2307
+ kind: indicator.kind,
2308
+ resourceName: indicator.resourceName,
2309
+ critical: indicator.critical,
2310
+ status: "down",
2311
+ durationMs,
2312
+ detail: "Probe returned false"
2313
+ };
2314
+ }
2315
+ return {
2316
+ id: indicator.id,
2317
+ kind: indicator.kind,
2318
+ resourceName: indicator.resourceName,
2319
+ critical: indicator.critical,
2320
+ status: "up",
2321
+ durationMs,
2322
+ ...typeof outcome === "string" && outcome ? { detail: outcome } : {}
2323
+ };
2324
+ } catch (err) {
2325
+ const durationMs = Math.round((performance.now() - startedAt) * 100) / 100;
2326
+ return {
2327
+ id: indicator.id,
2328
+ kind: indicator.kind,
2329
+ resourceName: indicator.resourceName,
2330
+ critical: indicator.critical,
2331
+ status: "down",
2332
+ durationMs,
2333
+ detail: err instanceof Error ? err.message : String(err)
2334
+ };
2335
+ } finally {
2336
+ if (timer !== null)
2337
+ clearTimeout(timer);
2338
+ }
2339
+ }
2340
+ function createHealthProbePlugin(options) {
2341
+ const livePath = options.livePath ?? options.graph.livePath ?? "/health/live";
2342
+ const readyPath = options.readyPath ?? options.graph.readyPath ?? "/health/ready";
2343
+ const startedAtMs = options.startedAtMs ?? Date.now();
2344
+ return new Elysia4({ name: "supacloud-health-probes" }).get(livePath, () => ({
2345
+ status: "ok",
2346
+ uptimeSec: Math.max(0, Math.floor((Date.now() - startedAtMs) / 1000))
2347
+ })).get(readyPath, async ({ set }) => {
2348
+ if (options.isDraining?.()) {
2349
+ set.status = 503;
2350
+ return {
2351
+ status: "draining",
2352
+ checks: []
2353
+ };
2354
+ }
2355
+ const checks = await Promise.all(options.graph.indicators.map((indicator) => runSingleProbe(indicator, options.probes[indicator.id])));
2356
+ const criticalDown = checks.some((c) => c.critical && c.status !== "up");
2357
+ const anyDown = checks.some((c) => c.status !== "up");
2358
+ const summaryStatus = criticalDown ? "unhealthy" : anyDown ? "degraded" : "ok";
2359
+ if (criticalDown) {
2360
+ set.status = 503;
2361
+ }
2362
+ return {
2363
+ status: summaryStatus,
2364
+ checks
2365
+ };
2366
+ });
2367
+ }
2271
2368
 
2272
2369
  // src/index.ts
2273
2370
  setupTypebox();
@@ -2410,10 +2507,10 @@ function contextPlugin(http) {
2410
2507
  seed = ++nextHttpPluginId;
2411
2508
  httpPluginIds.set(http, seed);
2412
2509
  }
2413
- return new Elysia4({ name: "supacloud:http-context", seed }).use(http ?? new Elysia4).as("plugin");
2510
+ return new Elysia5({ name: "supacloud:http-context", seed }).use(http ?? new Elysia5).as("plugin");
2414
2511
  }
2415
2512
  function mountHttp(http, name, normalize = true) {
2416
- return new Elysia4({ name, normalize }).use(contextPlugin(http));
2513
+ return new Elysia5({ name, normalize }).use(contextPlugin(http));
2417
2514
  }
2418
2515
  function resolveCompiledCommand(module, reference) {
2419
2516
  const matches = (module.commands ?? []).filter((command) => command.className === reference || command.name === reference);
@@ -3358,7 +3455,7 @@ function isPublicApplicationError(error) {
3358
3455
  }
3359
3456
  function createApplication(options) {
3360
3457
  const pendingWork = new PendingWorkRegistry2(options.pendingWork ? { capacity: options.pendingWork.capacity } : {});
3361
- const app = new Elysia4({ name: options.name ?? "supacloud:app", normalize: options.normalize ?? true }).use(contextPlugin(options.http).as("global"));
3458
+ const app = new Elysia5({ name: options.name ?? "supacloud:app", normalize: options.normalize ?? true }).use(contextPlugin(options.http).as("global"));
3362
3459
  if (options.documentation)
3363
3460
  app.use(createDocumentationPlugin(options.documentation));
3364
3461
  const ctxFactory = options.requestContext === undefined ? defaultRequestContext : (() => {
@@ -3489,6 +3586,7 @@ export {
3489
3586
  createDefaultEffectRuntime,
3490
3587
  createDocumentationPlugin,
3491
3588
  createEffectRuntimeFromLayer,
3589
+ createHealthProbePlugin,
3492
3590
  createHttpPolicySuite,
3493
3591
  createHttpTelemetry,
3494
3592
  createMemoryHttpCacheStore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/elysia",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "description": "Elysia runtime adapter for SupaCloud compiled modules: application/request scopes, route registration and validation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -54,8 +54,8 @@
54
54
  "directory": "packages/elysia"
55
55
  },
56
56
  "dependencies": {
57
- "@supacloud/app": "0.40.1",
58
- "@supacloud/commands": "0.14.0",
57
+ "@supacloud/app": "0.41.0",
58
+ "@supacloud/commands": "0.15.0",
59
59
  "@supacloud/contracts": "0.17.0",
60
60
  "effect": "4.0.5",
61
61
  "exact-mirror": "1.2.7",
@@ -65,7 +65,7 @@
65
65
  "overrides": {
66
66
  "@supacloud/delivery": "0.30.1",
67
67
  "@supacloud/contracts": "0.17.0",
68
- "@supacloud/commands": "0.14.0",
68
+ "@supacloud/commands": "0.15.0",
69
69
  "@graphql-tools/utils": "^12.0.4",
70
70
  "deepmerge-ts": "8.0.2",
71
71
  "prisma": "6.19.3"
@@ -74,9 +74,9 @@
74
74
  "elysia": "2.0.0-rc.6"
75
75
  },
76
76
  "devDependencies": {
77
- "@supacloud/compiler": "0.68.0",
77
+ "@supacloud/compiler": "0.69.0",
78
78
  "@supacloud/delivery": "0.30.1",
79
- "@supacloud/db": "0.28.0",
79
+ "@supacloud/db": "0.29.0",
80
80
  "@types/bun": "^1.4.5",
81
81
  "elysia": "2.0.0-rc.6",
82
82
  "typescript": "7.1.0-beta"