@btravstack/core 0.25.0 → 0.27.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/index.cjs CHANGED
@@ -1007,14 +1007,14 @@ const dispatchUnit = (dispatch) => observed(dispatch.observers, dispatch.operati
1007
1007
  * record the piece declared. The starter keeps the types; this keeps the body.
1008
1008
  */
1009
1009
  const mintPiece = (port, withUnit) => (options) => (0, _btravstack_di.Provider)(port)({
1010
- inject: options.inject,
1010
+ inject: options.inject ?? {},
1011
1011
  sync: (services) => withUnit(options.unit ?? {}, options.sync(services))
1012
1012
  });
1013
1013
  /**
1014
1014
  * The runtime half of a starter's composing provider — `AmqpHandlers(contract)`,
1015
1015
  * `TemporalActivities(contract)` — and its two arms. An array of pieces is
1016
1016
  * composed into one record keyed by each piece's port id less `prefix`, so the
1017
- * services record IS the composed record; a `{ inject, unit?, sync }` record
1017
+ * services record IS the composed record; a `{ inject?, unit?, sync }` record
1018
1018
  * has `withUnit` applied to every entry `sync` answers.
1019
1019
  */
1020
1020
  const composeByPrefix = (port, prefix, withUnit) => {
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AsyncResult, FailureView, Result } from "unthrown";
2
2
  import { AnyPort, AnyProvider, Context, DependencyGate, Module, PortClass, PortInstance, Provider, Scope, SeedEntry, ServiceOf } from "@btravstack/di";
3
- import { Env, Environment } from "@btravstack/config";
3
+ import { Env, Environment, EnvironmentFor } from "@btravstack/config";
4
4
  //#region src/instrumentation.d.ts
5
5
  /**
6
6
  * One package's offer of an OpenTelemetry instrumentation.
@@ -761,12 +761,34 @@ type ExitReport = {
761
761
  */
762
762
  readonly abandonedAt?: "build" | "stop";
763
763
  };
764
- type StartOptions = {
764
+ /**
765
+ * The kernel's own variables, all optional: each has a default, and each is
766
+ * pinned by the matching {@link StartOptions} field.
767
+ */
768
+ type KernelEnvironment = {
769
+ readonly PROBE_PORT?: string | undefined;
770
+ readonly PROBE_HOST?: string | undefined;
771
+ readonly PRE_DRAIN_DELAY_MS?: string | undefined;
772
+ readonly DRAIN_TIMEOUT_MS?: string | undefined;
773
+ readonly STOP_TIMEOUT_MS?: string | undefined;
774
+ };
775
+ /**
776
+ * The `env` a `start` of `M` accepts — what the module's configuration reads,
777
+ * plus the kernel's own variables. For typing an environment kept apart from
778
+ * the call, such as a test's shared one.
779
+ */
780
+ type StartEnvironment<M> = M extends Module<infer _X, infer _E, infer N> ? EnvironmentFor<N> & KernelEnvironment : never;
781
+ type StartOptions<Ev = Environment> = {
765
782
  /**
766
783
  * The environment the graph is configured from, provided to it as the `Env`
767
784
  * port and read for the kernel's own variables. Defaults to `process.env`.
785
+ *
786
+ * Typed by what the graph reads: at `start(module, { env })` it accepts the
787
+ * variables the module's configuration names and the kernel's own, requires
788
+ * the ones nothing defaults or pins, and refuses any other — unless some
789
+ * reader named none, when any record is accepted.
768
790
  */
769
- readonly env?: Environment;
791
+ readonly env?: Ev;
770
792
  readonly clock?: Clock;
771
793
  readonly signals?: boolean;
772
794
  /**
@@ -875,7 +897,7 @@ type PortIdOf<P> = P extends PortInstance<infer Id, infer _Service> ? Id : P;
875
897
  type StartGate<X, N = never> = [Exclude<N, Scope | Env>] extends [never] ? [Extract<X, RuntimeInstance>] extends [never] ? "NO RUNTIME — the module exports no port declared over RuntimePort" : [InstanceType<RuntimeResolvesOf<X>>] extends [X] ? unknown : "UNSATISFIED RUNTIME PORTS — the runtime resolves a port the module does not export" : {
876
898
  readonly "UNSATISFIED DEPENDENCIES — nothing provides": PortIdOf<Exclude<N, Scope | Env>>;
877
899
  };
878
- export declare const start: <X, E, N>(module: Module<X, E, N> & StartGate<X, N>, options?: StartOptions) => RunningApp<E, RuntimeInfoOf<X>>;
900
+ export declare const start: <X, E, N>(module: Module<X, E, N> & StartGate<X, N>, options?: StartOptions<EnvironmentFor<N> & KernelEnvironment>) => RunningApp<E, RuntimeInfoOf<X>>;
879
901
  //#endregion
880
902
  //#region src/run-main.d.ts
881
903
  /**
@@ -911,7 +933,7 @@ export declare const start: <X, E, N>(module: Module<X, E, N> & StartGate<X, N>,
911
933
  * await runMain(OrderApi);
912
934
  * ```
913
935
  */
914
- export declare const runMain: <X, E, N>(module: Module<X, E, N> & StartGate<X, N>, options?: StartOptions, exit?: (code: number) => void) => Promise<void>;
936
+ export declare const runMain: <X, E, N>(module: Module<X, E, N> & StartGate<X, N>, options?: StartOptions<EnvironmentFor<N> & KernelEnvironment>, exit?: (code: number) => void) => Promise<void>;
915
937
  //#endregion
916
938
  //#region src/unit-overrides.d.ts
917
939
  declare const UnitOverrides_base: import("@btravstack/di").ManyPortClass<"UnitOverrides">;
@@ -944,9 +966,9 @@ export declare class UnitOverrides extends UnitOverrides_base<Readonly<Record<st
944
966
  type Refuse<T extends readonly unknown[], Marker extends string, Detail> = T extends readonly [...infer Head, unknown] ? readonly [...Head, readonly [Marker, Detail]] : readonly [readonly [Marker, Detail]];
945
967
  /** How a starter puts a piece's declared `unit:` record on one of its entries. */
946
968
  type EntryWrapper = (record: Readonly<Record<string, AnyPort>>, entry: unknown) => unknown;
947
- /** A piece's `{ inject, unit?, sync }` options, with the types each starter states erased. */
969
+ /** A piece's `{ inject?, unit?, sync }` options, with the types each starter states erased. */
948
970
  type PieceOptions = {
949
- readonly inject: Readonly<Record<string, AnyPort>>;
971
+ readonly inject?: Readonly<Record<string, AnyPort>>;
950
972
  readonly unit?: Readonly<Record<string, AnyPort>>;
951
973
  readonly sync: (services: never) => unknown;
952
974
  };
@@ -961,7 +983,7 @@ export declare const mintPiece: (port: AnyPort, withUnit: EntryWrapper) => (opti
961
983
  * The runtime half of a starter's composing provider — `AmqpHandlers(contract)`,
962
984
  * `TemporalActivities(contract)` — and its two arms. An array of pieces is
963
985
  * composed into one record keyed by each piece's port id less `prefix`, so the
964
- * services record IS the composed record; a `{ inject, unit?, sync }` record
986
+ * services record IS the composed record; a `{ inject?, unit?, sync }` record
965
987
  * has `withUnit` applied to every entry `sync` answers.
966
988
  */
967
989
  export declare const composeByPrefix: (port: AnyPort, prefix: string, withUnit: EntryWrapper) => ((first: unknown) => unknown);
@@ -978,4 +1000,4 @@ export declare const noObserverMember: Provider<Observers, never, never> & {
978
1000
  readonly port: typeof Observers;
979
1001
  };
980
1002
  //#endregion
981
- export type { AnyUnitModule, Attributes, Clock, ComponentHealth, Counter, DrainReport, EventSink, ExitReport, HealthCheck, HealthReport, Histogram, InstrumentationLoader, KernelEvent, Level, LoggerService, MeterService, Operation, Phase, Refuse, RunUnit, RunningApp, Runtime, RuntimeHost, RuntimeInfoOf, Serving, Settle, Settled, Span, SpanStatusCode, StartGate, StartOptions, TeardownError, TracerService, UnitExportsOf, UnitGate, UnitHost, UnitMeta, UnitNeedsOf, UnitOutcome, UnitRecord, UnitRecordOf, UnitRegistry, UnitWork };
1003
+ export type { AnyUnitModule, Attributes, Clock, ComponentHealth, Counter, DrainReport, EventSink, ExitReport, HealthCheck, HealthReport, Histogram, InstrumentationLoader, KernelEnvironment, KernelEvent, Level, LoggerService, MeterService, Operation, Phase, Refuse, RunUnit, RunningApp, Runtime, RuntimeHost, RuntimeInfoOf, Serving, Settle, Settled, Span, SpanStatusCode, StartEnvironment, StartGate, StartOptions, TeardownError, TracerService, UnitExportsOf, UnitGate, UnitHost, UnitMeta, UnitNeedsOf, UnitOutcome, UnitRecord, UnitRecordOf, UnitRegistry, UnitWork };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AnyPort, AnyProvider, Context, DependencyGate, Module, PortClass, PortInstance, Provider, Scope, SeedEntry, ServiceOf } from "@btravstack/di";
2
2
  import { AsyncResult, FailureView, Result } from "unthrown";
3
- import { Env, Environment } from "@btravstack/config";
3
+ import { Env, Environment, EnvironmentFor } from "@btravstack/config";
4
4
  //#region src/instrumentation.d.ts
5
5
  /**
6
6
  * One package's offer of an OpenTelemetry instrumentation.
@@ -761,12 +761,34 @@ type ExitReport = {
761
761
  */
762
762
  readonly abandonedAt?: "build" | "stop";
763
763
  };
764
- type StartOptions = {
764
+ /**
765
+ * The kernel's own variables, all optional: each has a default, and each is
766
+ * pinned by the matching {@link StartOptions} field.
767
+ */
768
+ type KernelEnvironment = {
769
+ readonly PROBE_PORT?: string | undefined;
770
+ readonly PROBE_HOST?: string | undefined;
771
+ readonly PRE_DRAIN_DELAY_MS?: string | undefined;
772
+ readonly DRAIN_TIMEOUT_MS?: string | undefined;
773
+ readonly STOP_TIMEOUT_MS?: string | undefined;
774
+ };
775
+ /**
776
+ * The `env` a `start` of `M` accepts — what the module's configuration reads,
777
+ * plus the kernel's own variables. For typing an environment kept apart from
778
+ * the call, such as a test's shared one.
779
+ */
780
+ type StartEnvironment<M> = M extends Module<infer _X, infer _E, infer N> ? EnvironmentFor<N> & KernelEnvironment : never;
781
+ type StartOptions<Ev = Environment> = {
765
782
  /**
766
783
  * The environment the graph is configured from, provided to it as the `Env`
767
784
  * port and read for the kernel's own variables. Defaults to `process.env`.
785
+ *
786
+ * Typed by what the graph reads: at `start(module, { env })` it accepts the
787
+ * variables the module's configuration names and the kernel's own, requires
788
+ * the ones nothing defaults or pins, and refuses any other — unless some
789
+ * reader named none, when any record is accepted.
768
790
  */
769
- readonly env?: Environment;
791
+ readonly env?: Ev;
770
792
  readonly clock?: Clock;
771
793
  readonly signals?: boolean;
772
794
  /**
@@ -875,7 +897,7 @@ type PortIdOf<P> = P extends PortInstance<infer Id, infer _Service> ? Id : P;
875
897
  type StartGate<X, N = never> = [Exclude<N, Scope | Env>] extends [never] ? [Extract<X, RuntimeInstance>] extends [never] ? "NO RUNTIME — the module exports no port declared over RuntimePort" : [InstanceType<RuntimeResolvesOf<X>>] extends [X] ? unknown : "UNSATISFIED RUNTIME PORTS — the runtime resolves a port the module does not export" : {
876
898
  readonly "UNSATISFIED DEPENDENCIES — nothing provides": PortIdOf<Exclude<N, Scope | Env>>;
877
899
  };
878
- export declare const start: <X, E, N>(module: Module<X, E, N> & StartGate<X, N>, options?: StartOptions) => RunningApp<E, RuntimeInfoOf<X>>;
900
+ export declare const start: <X, E, N>(module: Module<X, E, N> & StartGate<X, N>, options?: StartOptions<EnvironmentFor<N> & KernelEnvironment>) => RunningApp<E, RuntimeInfoOf<X>>;
879
901
  //#endregion
880
902
  //#region src/run-main.d.ts
881
903
  /**
@@ -911,7 +933,7 @@ export declare const start: <X, E, N>(module: Module<X, E, N> & StartGate<X, N>,
911
933
  * await runMain(OrderApi);
912
934
  * ```
913
935
  */
914
- export declare const runMain: <X, E, N>(module: Module<X, E, N> & StartGate<X, N>, options?: StartOptions, exit?: (code: number) => void) => Promise<void>;
936
+ export declare const runMain: <X, E, N>(module: Module<X, E, N> & StartGate<X, N>, options?: StartOptions<EnvironmentFor<N> & KernelEnvironment>, exit?: (code: number) => void) => Promise<void>;
915
937
  //#endregion
916
938
  //#region src/unit-overrides.d.ts
917
939
  declare const UnitOverrides_base: import("@btravstack/di").ManyPortClass<"UnitOverrides">;
@@ -944,9 +966,9 @@ export declare class UnitOverrides extends UnitOverrides_base<Readonly<Record<st
944
966
  type Refuse<T extends readonly unknown[], Marker extends string, Detail> = T extends readonly [...infer Head, unknown] ? readonly [...Head, readonly [Marker, Detail]] : readonly [readonly [Marker, Detail]];
945
967
  /** How a starter puts a piece's declared `unit:` record on one of its entries. */
946
968
  type EntryWrapper = (record: Readonly<Record<string, AnyPort>>, entry: unknown) => unknown;
947
- /** A piece's `{ inject, unit?, sync }` options, with the types each starter states erased. */
969
+ /** A piece's `{ inject?, unit?, sync }` options, with the types each starter states erased. */
948
970
  type PieceOptions = {
949
- readonly inject: Readonly<Record<string, AnyPort>>;
971
+ readonly inject?: Readonly<Record<string, AnyPort>>;
950
972
  readonly unit?: Readonly<Record<string, AnyPort>>;
951
973
  readonly sync: (services: never) => unknown;
952
974
  };
@@ -961,7 +983,7 @@ export declare const mintPiece: (port: AnyPort, withUnit: EntryWrapper) => (opti
961
983
  * The runtime half of a starter's composing provider — `AmqpHandlers(contract)`,
962
984
  * `TemporalActivities(contract)` — and its two arms. An array of pieces is
963
985
  * composed into one record keyed by each piece's port id less `prefix`, so the
964
- * services record IS the composed record; a `{ inject, unit?, sync }` record
986
+ * services record IS the composed record; a `{ inject?, unit?, sync }` record
965
987
  * has `withUnit` applied to every entry `sync` answers.
966
988
  */
967
989
  export declare const composeByPrefix: (port: AnyPort, prefix: string, withUnit: EntryWrapper) => ((first: unknown) => unknown);
@@ -978,4 +1000,4 @@ export declare const noObserverMember: Provider<Observers, never, never> & {
978
1000
  readonly port: typeof Observers;
979
1001
  };
980
1002
  //#endregion
981
- export type { AnyUnitModule, Attributes, Clock, ComponentHealth, Counter, DrainReport, EventSink, ExitReport, HealthCheck, HealthReport, Histogram, InstrumentationLoader, KernelEvent, Level, LoggerService, MeterService, Operation, Phase, Refuse, RunUnit, RunningApp, Runtime, RuntimeHost, RuntimeInfoOf, Serving, Settle, Settled, Span, SpanStatusCode, StartGate, StartOptions, TeardownError, TracerService, UnitExportsOf, UnitGate, UnitHost, UnitMeta, UnitNeedsOf, UnitOutcome, UnitRecord, UnitRecordOf, UnitRegistry, UnitWork };
1003
+ export type { AnyUnitModule, Attributes, Clock, ComponentHealth, Counter, DrainReport, EventSink, ExitReport, HealthCheck, HealthReport, Histogram, InstrumentationLoader, KernelEnvironment, KernelEvent, Level, LoggerService, MeterService, Operation, Phase, Refuse, RunUnit, RunningApp, Runtime, RuntimeHost, RuntimeInfoOf, Serving, Settle, Settled, Span, SpanStatusCode, StartEnvironment, StartGate, StartOptions, TeardownError, TracerService, UnitExportsOf, UnitGate, UnitHost, UnitMeta, UnitNeedsOf, UnitOutcome, UnitRecord, UnitRecordOf, UnitRegistry, UnitWork };
package/dist/index.mjs CHANGED
@@ -1006,14 +1006,14 @@ const dispatchUnit = (dispatch) => observed(dispatch.observers, dispatch.operati
1006
1006
  * record the piece declared. The starter keeps the types; this keeps the body.
1007
1007
  */
1008
1008
  const mintPiece = (port, withUnit) => (options) => Provider(port)({
1009
- inject: options.inject,
1009
+ inject: options.inject ?? {},
1010
1010
  sync: (services) => withUnit(options.unit ?? {}, options.sync(services))
1011
1011
  });
1012
1012
  /**
1013
1013
  * The runtime half of a starter's composing provider — `AmqpHandlers(contract)`,
1014
1014
  * `TemporalActivities(contract)` — and its two arms. An array of pieces is
1015
1015
  * composed into one record keyed by each piece's port id less `prefix`, so the
1016
- * services record IS the composed record; a `{ inject, unit?, sync }` record
1016
+ * services record IS the composed record; a `{ inject?, unit?, sync }` record
1017
1017
  * has `withUnit` applied to every entry `sync` answers.
1018
1018
  */
1019
1019
  const composeByPrefix = (port, prefix, withUnit) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btravstack/core",
3
- "version": "0.25.0",
3
+ "version": "0.27.0",
4
4
  "description": "The application kernel: boot a di module into a running process, and stop it without losing work",
5
5
  "keywords": [
6
6
  "application",
@@ -45,8 +45,8 @@
45
45
  "./package.json": "./package.json"
46
46
  },
47
47
  "devDependencies": {
48
- "@btravstack/config": "0.25.0",
49
- "@btravstack/di": "0.25.0",
48
+ "@btravstack/config": "0.27.0",
49
+ "@btravstack/di": "0.27.0",
50
50
  "@btravstack/tsconfig": "0.4.0",
51
51
  "@stryker-mutator/core": "10.0.0",
52
52
  "@stryker-mutator/vitest-runner": "10.0.0",
@@ -60,8 +60,8 @@
60
60
  "vitest": "5.0.3"
61
61
  },
62
62
  "peerDependencies": {
63
- "@btravstack/config": "^0.25.0",
64
- "@btravstack/di": "^0.25.0",
63
+ "@btravstack/config": "^0.27.0",
64
+ "@btravstack/di": "^0.27.0",
65
65
  "unthrown": "^5.0.0"
66
66
  },
67
67
  "engines": {