@btravstack/core 0.10.0 → 0.11.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/README.md +1 -1
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +28 -10
- package/dist/index.d.mts +28 -10
- package/dist/index.mjs +0 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -132,7 +132,7 @@ is a module that exports no runtime port at all.
|
|
|
132
132
|
- **A per-unit scope no handler manages** — pass a module as
|
|
133
133
|
`StartOptions.unit` and the kernel forks it around every unit.
|
|
134
134
|
- **An ambient record, not an ambient container** — `currentUnit()` reads
|
|
135
|
-
`{ unitId, traceId, tenantId,
|
|
135
|
+
`{ unitId, traceId, tenantId, signal }`; services never travel
|
|
136
136
|
there. `signal` is the very `AbortSignal` the unit's work callback is handed,
|
|
137
137
|
so a runtime whose work is a library's `next()` — a Temporal activity, an
|
|
138
138
|
AMQP delivery — can still honour the drain deadline.
|
package/dist/index.cjs
CHANGED
|
@@ -386,7 +386,6 @@ const createUnitRegistry = () => {
|
|
|
386
386
|
unitId: nextId(),
|
|
387
387
|
traceId: meta.traceId ?? meta.id,
|
|
388
388
|
tenantId: meta.tenantId,
|
|
389
|
-
deadline: meta.deadline,
|
|
390
389
|
signal: controller.signal
|
|
391
390
|
};
|
|
392
391
|
return (0, unthrown.fromSafePromise)(runWithUnit(record, async () => {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncResult, Result } from "unthrown";
|
|
2
|
-
import { AnyPort, Context, Module, PortClass, Scope, ServiceOf } from "@btravstack/di";
|
|
2
|
+
import { AnyPort, Context, Module, PortClass, PortInstance, Scope, ServiceOf } from "@btravstack/di";
|
|
3
3
|
import { Env, Environment } from "@btravstack/config";
|
|
4
4
|
//#region src/instrumentation.d.ts
|
|
5
5
|
/**
|
|
@@ -315,7 +315,6 @@ type UnitRecord = {
|
|
|
315
315
|
readonly unitId: string;
|
|
316
316
|
readonly traceId: string;
|
|
317
317
|
readonly tenantId: string | undefined;
|
|
318
|
-
readonly deadline: number | undefined;
|
|
319
318
|
readonly signal: AbortSignal;
|
|
320
319
|
};
|
|
321
320
|
declare const currentUnit: () => UnitRecord | undefined;
|
|
@@ -339,7 +338,6 @@ type UnitMeta = {
|
|
|
339
338
|
readonly id: string;
|
|
340
339
|
readonly traceId?: string;
|
|
341
340
|
readonly tenantId?: string;
|
|
342
|
-
readonly deadline?: number;
|
|
343
341
|
};
|
|
344
342
|
type UnitWork<T, E> = (signal: AbortSignal) => AsyncResult<T, E> | Promise<Result<T, E>> | Result<T, E>;
|
|
345
343
|
type UnitRegistry = {
|
|
@@ -600,18 +598,38 @@ type RunningApp<E, Info = never> = {
|
|
|
600
598
|
};
|
|
601
599
|
/**
|
|
602
600
|
* The phantom marker `start`, `runMain` and `Boot` all intersect onto their
|
|
603
|
-
* `module` parameter: `unknown` — and invisible — when the module
|
|
604
|
-
* runtime, its exports cover what that
|
|
605
|
-
* unit module's needs;
|
|
606
|
-
* site as the parameter type the argument did
|
|
601
|
+
* `module` parameter: `unknown` — and invisible — when nothing the module
|
|
602
|
+
* needs is unprovided, it exports a runtime, its exports cover what that
|
|
603
|
+
* runtime resolves and they cover the unit module's needs; a diagnostic
|
|
604
|
+
* otherwise, printed at the call site as the parameter type the argument did
|
|
605
|
+
* not match.
|
|
607
606
|
*
|
|
608
607
|
* `unknown` is the satisfied arm because intersecting it leaves the module
|
|
609
608
|
* type untouched. A runtime's `resolves` is checked against the module's
|
|
610
609
|
* exports only, never the unit module's: `RuntimeHost.ctx` is the application
|
|
611
610
|
* context, so a unit-only port would resolve to nothing there.
|
|
611
|
+
*
|
|
612
|
+
* **Unmet needs are checked FIRST, and answered in di's own words rather than
|
|
613
|
+
* a sentence of the kernel's.** A root that forgot `provides: [router]` used
|
|
614
|
+
* to be told `Type 'HttpRouterPort' is not assignable to type 'Scope'` — an
|
|
615
|
+
* internal phantom nobody has heard of — or, when the port was missing from
|
|
616
|
+
* `exports` too, `UNSATISFIED RUNTIME PORTS`, which is a correct diagnosis of
|
|
617
|
+
* the second mistake that reads as a wrong one of the first and steers the fix
|
|
618
|
+
* into the wrong list. It is the same defect `Module.build` reports, so it
|
|
619
|
+
* prints the same sentence and ends on the port that is missing.
|
|
620
|
+
*/
|
|
621
|
+
/**
|
|
622
|
+
* A port's declared id, which is what a marker names it by: an id is the short
|
|
623
|
+
* string the application wrote in `Port("…")`, where the port TYPE of a
|
|
624
|
+
* starter's own generic port — `AmqpHandlers` over a contract — expands to
|
|
625
|
+
* hundreds of characters of the caller's own schema and truncates before the
|
|
626
|
+
* name is reached.
|
|
612
627
|
*/
|
|
613
|
-
type
|
|
614
|
-
|
|
628
|
+
type PortIdOf<P> = P extends PortInstance<infer Id, infer _Service> ? Id : P;
|
|
629
|
+
type StartGate<X, UnitNeeds = never, 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] ? [Exclude<UnitNeeds, X | Scope | Env>] extends [never] ? unknown : "UNSATISFIED UNIT NEEDS — the unit module needs a port the module does not export" : "UNSATISFIED RUNTIME PORTS — the runtime resolves a port the module does not export" : {
|
|
630
|
+
readonly "UNSATISFIED DEPENDENCIES — nothing provides": PortIdOf<Exclude<N, Scope | Env>>;
|
|
631
|
+
};
|
|
632
|
+
declare const start: <X, E, N, UnitX = never, UnitNeeds = never>(module: Module<X, E, N> & StartGate<X, UnitNeeds, N>, options?: StartOptions<UnitX, UnitNeeds>) => RunningApp<E, RuntimeInfoOf<X>>;
|
|
615
633
|
//#endregion
|
|
616
634
|
//#region src/run-main.d.ts
|
|
617
635
|
/**
|
|
@@ -646,6 +664,6 @@ declare const start: <X, E, UnitX = never, UnitNeeds = never>(module: Module<X,
|
|
|
646
664
|
* await runMain(OrderApi);
|
|
647
665
|
* ```
|
|
648
666
|
*/
|
|
649
|
-
declare const runMain: <X, E, UnitX = never, UnitNeeds = never>(module: Module<X, E,
|
|
667
|
+
declare const runMain: <X, E, N, UnitX = never, UnitNeeds = never>(module: Module<X, E, N> & StartGate<X, UnitNeeds, N>, options?: StartOptions<UnitX, UnitNeeds>, exit?: (code: number) => void) => Promise<void>;
|
|
650
668
|
//#endregion
|
|
651
669
|
export { type Attributes, type Clock, type ComponentHealth, type Counter, type DrainReport, type EventSink, type ExitReport, type HealthCheck, HealthCheckFailed, HealthChecks, type HealthReport, type Histogram, type InstrumentationLoader, Instrumentations, type KernelEvent, LEVELS, type Level, Logger, type LoggerService, Meter, type MeterService, Observers, type Operation, type Phase, type RunUnit, type RunningApp, type Runtime, type RuntimeHost, type RuntimeInfoOf, RuntimePort, RuntimeStartFailed, SPAN_STATUS, type Serving, type Settle, type Settled, type Span, type SpanStatusCode, type StartGate, type StartOptions, type TeardownError, Tracer, type TracerService, type UnitMeta, type UnitRecord, type UnitRegistry, type UnitWork, currentUnit, noObserver, observe, releasedBy, runHealthChecks, runMain, start, stderrSink, systemClock };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyPort, Context, Module, PortClass, Scope, ServiceOf } from "@btravstack/di";
|
|
1
|
+
import { AnyPort, Context, Module, PortClass, PortInstance, Scope, ServiceOf } from "@btravstack/di";
|
|
2
2
|
import { AsyncResult, Result } from "unthrown";
|
|
3
3
|
import { Env, Environment } from "@btravstack/config";
|
|
4
4
|
//#region src/instrumentation.d.ts
|
|
@@ -315,7 +315,6 @@ type UnitRecord = {
|
|
|
315
315
|
readonly unitId: string;
|
|
316
316
|
readonly traceId: string;
|
|
317
317
|
readonly tenantId: string | undefined;
|
|
318
|
-
readonly deadline: number | undefined;
|
|
319
318
|
readonly signal: AbortSignal;
|
|
320
319
|
};
|
|
321
320
|
declare const currentUnit: () => UnitRecord | undefined;
|
|
@@ -339,7 +338,6 @@ type UnitMeta = {
|
|
|
339
338
|
readonly id: string;
|
|
340
339
|
readonly traceId?: string;
|
|
341
340
|
readonly tenantId?: string;
|
|
342
|
-
readonly deadline?: number;
|
|
343
341
|
};
|
|
344
342
|
type UnitWork<T, E> = (signal: AbortSignal) => AsyncResult<T, E> | Promise<Result<T, E>> | Result<T, E>;
|
|
345
343
|
type UnitRegistry = {
|
|
@@ -600,18 +598,38 @@ type RunningApp<E, Info = never> = {
|
|
|
600
598
|
};
|
|
601
599
|
/**
|
|
602
600
|
* The phantom marker `start`, `runMain` and `Boot` all intersect onto their
|
|
603
|
-
* `module` parameter: `unknown` — and invisible — when the module
|
|
604
|
-
* runtime, its exports cover what that
|
|
605
|
-
* unit module's needs;
|
|
606
|
-
* site as the parameter type the argument did
|
|
601
|
+
* `module` parameter: `unknown` — and invisible — when nothing the module
|
|
602
|
+
* needs is unprovided, it exports a runtime, its exports cover what that
|
|
603
|
+
* runtime resolves and they cover the unit module's needs; a diagnostic
|
|
604
|
+
* otherwise, printed at the call site as the parameter type the argument did
|
|
605
|
+
* not match.
|
|
607
606
|
*
|
|
608
607
|
* `unknown` is the satisfied arm because intersecting it leaves the module
|
|
609
608
|
* type untouched. A runtime's `resolves` is checked against the module's
|
|
610
609
|
* exports only, never the unit module's: `RuntimeHost.ctx` is the application
|
|
611
610
|
* context, so a unit-only port would resolve to nothing there.
|
|
611
|
+
*
|
|
612
|
+
* **Unmet needs are checked FIRST, and answered in di's own words rather than
|
|
613
|
+
* a sentence of the kernel's.** A root that forgot `provides: [router]` used
|
|
614
|
+
* to be told `Type 'HttpRouterPort' is not assignable to type 'Scope'` — an
|
|
615
|
+
* internal phantom nobody has heard of — or, when the port was missing from
|
|
616
|
+
* `exports` too, `UNSATISFIED RUNTIME PORTS`, which is a correct diagnosis of
|
|
617
|
+
* the second mistake that reads as a wrong one of the first and steers the fix
|
|
618
|
+
* into the wrong list. It is the same defect `Module.build` reports, so it
|
|
619
|
+
* prints the same sentence and ends on the port that is missing.
|
|
620
|
+
*/
|
|
621
|
+
/**
|
|
622
|
+
* A port's declared id, which is what a marker names it by: an id is the short
|
|
623
|
+
* string the application wrote in `Port("…")`, where the port TYPE of a
|
|
624
|
+
* starter's own generic port — `AmqpHandlers` over a contract — expands to
|
|
625
|
+
* hundreds of characters of the caller's own schema and truncates before the
|
|
626
|
+
* name is reached.
|
|
612
627
|
*/
|
|
613
|
-
type
|
|
614
|
-
|
|
628
|
+
type PortIdOf<P> = P extends PortInstance<infer Id, infer _Service> ? Id : P;
|
|
629
|
+
type StartGate<X, UnitNeeds = never, 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] ? [Exclude<UnitNeeds, X | Scope | Env>] extends [never] ? unknown : "UNSATISFIED UNIT NEEDS — the unit module needs a port the module does not export" : "UNSATISFIED RUNTIME PORTS — the runtime resolves a port the module does not export" : {
|
|
630
|
+
readonly "UNSATISFIED DEPENDENCIES — nothing provides": PortIdOf<Exclude<N, Scope | Env>>;
|
|
631
|
+
};
|
|
632
|
+
declare const start: <X, E, N, UnitX = never, UnitNeeds = never>(module: Module<X, E, N> & StartGate<X, UnitNeeds, N>, options?: StartOptions<UnitX, UnitNeeds>) => RunningApp<E, RuntimeInfoOf<X>>;
|
|
615
633
|
//#endregion
|
|
616
634
|
//#region src/run-main.d.ts
|
|
617
635
|
/**
|
|
@@ -646,6 +664,6 @@ declare const start: <X, E, UnitX = never, UnitNeeds = never>(module: Module<X,
|
|
|
646
664
|
* await runMain(OrderApi);
|
|
647
665
|
* ```
|
|
648
666
|
*/
|
|
649
|
-
declare const runMain: <X, E, UnitX = never, UnitNeeds = never>(module: Module<X, E,
|
|
667
|
+
declare const runMain: <X, E, N, UnitX = never, UnitNeeds = never>(module: Module<X, E, N> & StartGate<X, UnitNeeds, N>, options?: StartOptions<UnitX, UnitNeeds>, exit?: (code: number) => void) => Promise<void>;
|
|
650
668
|
//#endregion
|
|
651
669
|
export { type Attributes, type Clock, type ComponentHealth, type Counter, type DrainReport, type EventSink, type ExitReport, type HealthCheck, HealthCheckFailed, HealthChecks, type HealthReport, type Histogram, type InstrumentationLoader, Instrumentations, type KernelEvent, LEVELS, type Level, Logger, type LoggerService, Meter, type MeterService, Observers, type Operation, type Phase, type RunUnit, type RunningApp, type Runtime, type RuntimeHost, type RuntimeInfoOf, RuntimePort, RuntimeStartFailed, SPAN_STATUS, type Serving, type Settle, type Settled, type Span, type SpanStatusCode, type StartGate, type StartOptions, type TeardownError, Tracer, type TracerService, type UnitMeta, type UnitRecord, type UnitRegistry, type UnitWork, currentUnit, noObserver, observe, releasedBy, runHealthChecks, runMain, start, stderrSink, systemClock };
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btravstack/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"typescript": "7.0.2",
|
|
54
54
|
"unthrown": "5.7.0",
|
|
55
55
|
"vitest": "4.1.11",
|
|
56
|
-
"@btravstack/
|
|
57
|
-
"@btravstack/
|
|
56
|
+
"@btravstack/di": "0.11.0",
|
|
57
|
+
"@btravstack/config": "0.11.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"unthrown": "^5.0.0",
|
|
61
|
-
"@btravstack/config": "^0.
|
|
62
|
-
"@btravstack/di": "^0.
|
|
61
|
+
"@btravstack/config": "^0.11.0",
|
|
62
|
+
"@btravstack/di": "^0.11.0"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=22"
|