@qlever-llc/trellis 0.10.8 → 0.10.9

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.
@@ -49,7 +49,12 @@ import {
49
49
  } from "@qlever-llc/result";
50
50
  import { Type } from "typebox";
51
51
  import { Value } from "typebox/value";
52
- import { type HealthCheckFn, ServiceHealth } from "./health.js";
52
+ import {
53
+ type HealthCheckFn,
54
+ ServiceHealth,
55
+ type ServiceHealthCheck,
56
+ type ServiceHealthInfo,
57
+ } from "./health.js";
53
58
  import { mountStandardHealthRpc } from "./health_rpc.js";
54
59
  import type { EventDesc, RPCDesc } from "../contracts.js";
55
60
  import type {
@@ -1320,6 +1325,23 @@ type BoundJobsFacadeOf<
1320
1325
  >;
1321
1326
  };
1322
1327
 
1328
+ type BoundServiceHealth<TDeps> = Omit<ServiceHealth, "add" | "setInfo"> & {
1329
+ setInfo(
1330
+ info:
1331
+ | ServiceHealthInfo
1332
+ | ((args: { deps: TDeps }) =>
1333
+ | ServiceHealthInfo
1334
+ | undefined
1335
+ | Promise<ServiceHealthInfo | undefined>),
1336
+ ): void;
1337
+ add(
1338
+ name: string,
1339
+ check: (args: { deps: TDeps }) =>
1340
+ | ServiceHealthCheck
1341
+ | Promise<ServiceHealthCheck>,
1342
+ ): () => void;
1343
+ };
1344
+
1323
1345
  /** Service wrapper returned by `TrellisService.with(deps)`. */
1324
1346
  export type BoundTrellisService<
1325
1347
  TOwnedApi extends TrellisAPI = TrellisAPI,
@@ -1335,7 +1357,6 @@ export type BoundTrellisService<
1335
1357
  | "nc"
1336
1358
  | "kv"
1337
1359
  | "store"
1338
- | "health"
1339
1360
  | "connection"
1340
1361
  | "createTransfer"
1341
1362
  | "completeOperation"
@@ -1350,6 +1371,7 @@ export type BoundTrellisService<
1350
1371
  TJobs,
1351
1372
  TDeps
1352
1373
  >;
1374
+ readonly health: BoundServiceHealth<TDeps>;
1353
1375
  readonly jobs: BoundJobsFacadeOf<TJobs, TTrellisApi, TKv, TDeps>;
1354
1376
  readonly handle: BoundTypedServiceHandleFacade<
1355
1377
  TOwnedApi,
@@ -2691,7 +2713,7 @@ export class TrellisService<
2691
2713
  kv: this.kv,
2692
2714
  store: this.store,
2693
2715
  jobs: createBoundJobsFacade({ jobs: this.jobs, deps }),
2694
- health: this.health,
2716
+ health: this.#createBoundHealth(deps),
2695
2717
  handle: this.#createBoundHandleFacade(deps),
2696
2718
  connection: this.connection,
2697
2719
  createTransfer: (args) => this.createTransfer(args),
@@ -2703,6 +2725,33 @@ export class TrellisService<
2703
2725
  };
2704
2726
  }
2705
2727
 
2728
+ #createBoundHealth<TDeps>(deps: TDeps): BoundServiceHealth<TDeps> {
2729
+ const health = this.health;
2730
+ return {
2731
+ serviceName: health.serviceName,
2732
+ kind: health.kind,
2733
+ instanceId: health.instanceId,
2734
+ contractId: health.contractId,
2735
+ contractDigest: health.contractDigest,
2736
+ startedAt: health.startedAt,
2737
+ publishIntervalMs: health.publishIntervalMs,
2738
+ setInfo(info) {
2739
+ if (typeof info !== "function") {
2740
+ health.setInfo(info);
2741
+ return;
2742
+ }
2743
+
2744
+ health.setInfo(() => info({ deps }));
2745
+ },
2746
+ add(name, check) {
2747
+ return health.add(name, () => check({ deps }));
2748
+ },
2749
+ checks: () => health.checks(),
2750
+ response: () => health.response(),
2751
+ heartbeat: () => health.heartbeat(),
2752
+ };
2753
+ }
2754
+
2706
2755
  #createBoundEventFacade<TDeps>(
2707
2756
  deps: TDeps,
2708
2757
  ): BoundActiveEventFacade<TTrellisApi, TTrellisApi, TKv, TJobs, TDeps> {