@codefast/di 0.5.0-canary.7 → 0.5.0-canary.8
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/CHANGELOG.md +68 -0
- package/README.md +3 -1
- package/dist/binding.d.ts +47 -5
- package/dist/binding.d.ts.map +1 -1
- package/dist/binding.js +44 -0
- package/dist/binding.js.map +1 -1
- package/dist/constructor-type.d.ts +4 -5
- package/dist/constructor-type.d.ts.map +1 -1
- package/dist/container/binding-builders.d.ts +32 -11
- package/dist/container/binding-builders.d.ts.map +1 -1
- package/dist/container/binding-builders.js +140 -191
- package/dist/container/binding-builders.js.map +1 -1
- package/dist/container/container.d.ts.map +1 -1
- package/dist/container/container.js +75 -92
- package/dist/container/container.js.map +1 -1
- package/dist/decorators/inject.d.ts +2 -4
- package/dist/decorators/inject.d.ts.map +1 -1
- package/dist/decorators/inject.js.map +1 -1
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +17 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/introspection/inspector.js +1 -1
- package/dist/introspection/inspector.js.map +1 -1
- package/dist/metadata/metadata-keys.d.ts +3 -6
- package/dist/metadata/metadata-keys.d.ts.map +1 -1
- package/dist/metadata/metadata-keys.js +3 -6
- package/dist/metadata/metadata-keys.js.map +1 -1
- package/dist/registry.d.ts +14 -2
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +35 -45
- package/dist/registry.js.map +1 -1
- package/dist/resolution/activation-need.d.ts +25 -0
- package/dist/resolution/activation-need.d.ts.map +1 -0
- package/dist/resolution/activation-need.js +64 -0
- package/dist/resolution/activation-need.js.map +1 -0
- package/dist/resolution/binding-lookup-cache.d.ts +41 -0
- package/dist/resolution/binding-lookup-cache.d.ts.map +1 -0
- package/dist/resolution/binding-lookup-cache.js +102 -0
- package/dist/resolution/binding-lookup-cache.js.map +1 -0
- package/dist/resolution/binding-select.js +1 -4
- package/dist/resolution/binding-select.js.map +1 -1
- package/dist/resolution/class-introspector.d.ts +27 -0
- package/dist/resolution/class-introspector.d.ts.map +1 -0
- package/dist/resolution/class-introspector.js +60 -0
- package/dist/resolution/class-introspector.js.map +1 -0
- package/dist/resolution/diagnostics.d.ts +41 -0
- package/dist/resolution/diagnostics.d.ts.map +1 -0
- package/dist/resolution/diagnostics.js +18 -0
- package/dist/resolution/diagnostics.js.map +1 -0
- package/dist/resolution/environment.d.ts +22 -1
- package/dist/resolution/environment.d.ts.map +1 -1
- package/dist/resolution/environment.js +27 -1
- package/dist/resolution/environment.js.map +1 -1
- package/dist/resolution/instantiation-plan.d.ts +15 -15
- package/dist/resolution/instantiation-plan.d.ts.map +1 -1
- package/dist/resolution/instantiation-plan.js +68 -48
- package/dist/resolution/instantiation-plan.js.map +1 -1
- package/dist/resolution/lifecycle.d.ts +2 -0
- package/dist/resolution/lifecycle.d.ts.map +1 -1
- package/dist/resolution/lifecycle.js +16 -11
- package/dist/resolution/lifecycle.js.map +1 -1
- package/dist/resolution/resolution-path.d.ts +4 -13
- package/dist/resolution/resolution-path.d.ts.map +1 -1
- package/dist/resolution/resolution-path.js +3 -16
- package/dist/resolution/resolution-path.js.map +1 -1
- package/dist/resolution/resolver.d.ts +7 -2
- package/dist/resolution/resolver.d.ts.map +1 -1
- package/dist/resolution/resolver.js +116 -328
- package/dist/resolution/resolver.js.map +1 -1
- package/dist/resolution/scope.d.ts +7 -15
- package/dist/resolution/scope.d.ts.map +1 -1
- package/dist/resolution/scope.js +48 -44
- package/dist/resolution/scope.js.map +1 -1
- package/package.json +7 -97
- package/src/binding.ts +104 -5
- package/src/constructor-type.ts +4 -5
- package/src/container/binding-builders.ts +180 -283
- package/src/container/container.ts +90 -103
- package/src/decorators/inject.ts +3 -5
- package/src/errors.ts +21 -0
- package/src/index.ts +1 -0
- package/src/introspection/inspector.ts +1 -1
- package/src/metadata/metadata-keys.ts +3 -6
- package/src/registry.ts +38 -59
- package/src/resolution/activation-need.ts +81 -0
- package/src/resolution/binding-lookup-cache.ts +132 -0
- package/src/resolution/binding-select.ts +1 -4
- package/src/resolution/class-introspector.ts +74 -0
- package/src/resolution/diagnostics.ts +43 -0
- package/src/resolution/environment.ts +31 -1
- package/src/resolution/instantiation-plan.ts +113 -61
- package/src/resolution/lifecycle.ts +16 -11
- package/src/resolution/resolution-path.ts +5 -20
- package/src/resolution/resolver.ts +142 -371
- package/src/resolution/scope.ts +50 -49
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,73 @@
|
|
|
1
1
|
# @codefast/di
|
|
2
2
|
|
|
3
|
+
## 0.5.0-canary.8
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#646](https://github.com/codefastlabs/codefast/pull/646) [`0093b99`](https://github.com/codefastlabs/codefast/commit/0093b99ed711ad037b0e98e7343dee89786d328b) Thanks [@thevuong](https://github.com/thevuong)! - Build a container's rarely-used collaborators on first use instead of in its constructor: the inspector, the module ref/binding tables, the scope's in-flight and scoped caches, the registry's named and tagged slot indexes, and the class introspector's metadata caches. A container that only binds and resolves — the common case, and every per-request child container — no longer allocates eleven `Map`s it never reads.
|
|
8
|
+
|
|
9
|
+
A fresh `Container.create()` retains 2.7 KB instead of 4.8 KB (**43% lighter**), and `parent.createChild()` the same, measured by retention against a forced collection. Every deferred collaborator behaves identically whether or not something touched it first, which `tests/unit/container/deferred-subsystems.test.ts` pins by exercising each one as the first thing a fresh container does.
|
|
10
|
+
|
|
11
|
+
It is a throughput win too, on the paths that actually build containers: `Container.create()` is **1.80×** faster (230 ns → 127 ns) and a per-request child container plus a resolve through it — `createChild()` + resolve, the shape a web app runs once per request — is **1.31×** faster. Measured by an interleaved A/B with both builds loaded into one process, 13 trials in alternating order, against a control scenario that resolves from a pre-built container and so cannot benefit; the control sat at 0.997–1.009, and median and best-of agreed on both figures.
|
|
12
|
+
|
|
13
|
+
**Breaking:** `ScopeManager.getAllScoped()` is removed from the `./resolution/scope` subpath. Deferring the scoped cache raised the question of what a bulk reader returns when the cache was never allocated, and this reader had no callers anywhere in the package — so it is gone rather than carrying an empty-map fallback for nobody. `getAllSingletons()` is unaffected; its cache is still eager.
|
|
14
|
+
|
|
15
|
+
What it does **not** do is close the `realistic-graph-cold-resolve` loss against tsyringe, and the arithmetic says why: 103 ns off container construction is 2.5% of that row's 4.06 µs iteration, so the row moves ~1.5% — measured, and inside the noise floor. That row's gap is GC-attributable (the two libraries are at mutator parity; di only loses once a forced collection is in the loop), so a 13.7% allocation cut was never going to carry it.
|
|
16
|
+
|
|
17
|
+
- [#646](https://github.com/codefastlabs/codefast/pull/646) [`de80bad`](https://github.com/codefastlabs/codefast/commit/de80bad63f14afda1bd64a6d247852b24aac8e16) Thanks [@thevuong](https://github.com/thevuong)! - Publish an intentional export surface: 13 subpaths instead of 36. The engine's collaborators — `resolution/*`, `registry`, `container/*`, `binding`, `constructor-type`, and the `metadata` internals — are no longer entry points. They carry the invariants documented in ARCHITECTURE.md, and publishing them meant every internal refactor was technically a breaking change. Everything a consumer needs stays reachable from the root export, which already re-exports the builder interfaces, `Constructor`, `MetadataReader`, `effectiveBindingScope`, and the resolve-options helpers.
|
|
18
|
+
|
|
19
|
+
**This also repairs a silent break.** The surface was generated from `dist/`, so reorganising `src/` into `container/`, `resolution/` and `introspection/` renamed twelve already-published entry points — `./inspector` → `./introspection/inspector`, `./dependency-graph` → `./introspection/dependency-graph`, `./graph-adapters/*` → `./introspection/graph-adapters/*`, `./container` → `./container/container`, and the whole flat `./resolver`/`./scope`/`./lifecycle`/`./environment`/`./constraints`/`./binding-select`/`./binding-scope`/`./resolve-options` set — with no changeset saying so. The consumer-facing ones (`./inspector`, `./dependency-graph`, `./graph-adapters/*`) are back at the specifiers they shipped under; `examples/tanstack-start` imports two of them and would have broken on its next upgrade.
|
|
20
|
+
|
|
21
|
+
**Breaking:** the internal subpaths listed above are gone. Import from the package root instead.
|
|
22
|
+
|
|
23
|
+
- [#646](https://github.com/codefastlabs/codefast/pull/646) [`4ba70d1`](https://github.com/codefastlabs/codefast/commit/4ba70d1724e19580ee93ee392e413c23e669f310) Thanks [@thevuong](https://github.com/thevuong)! - Keep a singleton's instance on its binding instead of in a per-container table. A binding belongs to exactly one container, so its singleton slot is per-binding — which turns every cached-singleton read from a keyed `Map` lookup into a field read, on the most common resolve shape there is. The scope manager keeps only a lazily-created list of the bindings that have materialized, so disposal and `inspect()` can still enumerate them, and the singleton `Map` is gone entirely.
|
|
24
|
+
|
|
25
|
+
In the suite, `realistic-graph-resolve-root` — a transient controller over eight cached singletons — went from 10.66M to **12.19M** hz/op, and the `realistic` group geomean from 2.24× to **2.54×** of InversifyJS. That row carries a 2.9% IQR, so it is one of the numbers here worth reading precisely. `singleton-class-1-dep` and cold container build both moved up as well, on rows whose IQR is too wide to attribute confidently.
|
|
26
|
+
|
|
27
|
+
An interleaved A/B against the previous build, both in one process with a control that cannot benefit, put the same row between 1.09× and 1.40× across four runs — never slower, median and best-of agreeing inside each run, but with a spread that depends on what else the process had run. The suite's figure is the one to cite; the A/B established the direction. A trap worth recording: the control first read 0.88×, which was an artifact of timing an 11 ns call one at a time — batched the way the harness does it, the same control reads 1.02× with a 4% spread.
|
|
28
|
+
|
|
29
|
+
**Breaking:** `ScopeManager`'s singleton API takes a `Binding` rather than a `BindingIdentifier`, and `hasSingleton`/`getSingleton`/`peekSingleton`/`setSingleton(id, …)`/`getAllSingletons` are replaced by `setSingleton(binding, …)`, `deleteSingleton(binding)` and `cachedSingletons()`. The `SINGLETON_MISS` sentinel is gone; `NO_INSTANCE` on the binding replaces it. None of this is a published entry point any more, so it is internal — but a fork reaching into `./resolution/scope` would notice. `InstantiationPlanDependencyEntry` also drops its `ownerScope` field, which a compiled thunk no longer needs.
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- [#646](https://github.com/codefastlabs/codefast/pull/646) [`d27b76f`](https://github.com/codefastlabs/codefast/commit/d27b76fb14200ae5226ec2a05b77d44ab91b016c) Thanks [@thevuong](https://github.com/thevuong)! - Thread an async chain's resolution context through the call and pool it, instead of parking chain identity on the resolver. `ctx.resolveAsync()` now hands the callee the context it used, so an inner level reuses it when the owner matches — which removes the resolver's path-identity heuristic, its shared settle callback and its active-level counter, and makes two concurrent chains correct by construction rather than by a fallback branch.
|
|
34
|
+
|
|
35
|
+
The contexts are pooled, and that is load-bearing rather than an allocation micro-optimization: a per-chain context survives its chain's microtask hops, so under a collecting profile a freshly allocated one is promoted out of the nursery and then collected the expensive way. An ablation that allocated per chain cost **2.5×** on `dynamic-async-chain-8` under a forced GC every 100 samples, which is the reason for the shape.
|
|
36
|
+
|
|
37
|
+
It does **not** close that row. An earlier draft of this changeset claimed it went from 0.98× to 1.18× of InversifyJS; that figure came from a probe running both library builds in one process, which this harness's README warns is worth ~30% on async chains, and from a 3-trial suite run on a loaded machine. At 5 trials on a quiet machine the row is **0.87×** with a 0.6% / 0.3% IQR — among the tightest numbers in the suite. The mechanism above is real; the win over inversify was not.
|
|
38
|
+
|
|
39
|
+
A competing hypothesis was tested and rejected: a forced full GC costs the two libraries the same (1.35 ms / 9.76 MB live for di, 1.41 ms / 9.89 MB for inversify), so the cost was never the collection but what di re-established afterwards.
|
|
40
|
+
|
|
41
|
+
- [#646](https://github.com/codefastlabs/codefast/pull/646) [`864d213`](https://github.com/codefastlabs/codefast/commit/864d213a4253346dae5799ebba06fc2726e933d2) Thanks [@thevuong](https://github.com/thevuong)! - Fold the fluent chain's registry committer into the chain itself. `bind()` now allocates a `BindingEntry` that carries only the `to*()` calls, and `to*()` a `BindingChain` that commits to the registry directly — one object per bind less than the entry/chain/committer trio, and one `Map` lookup less per binding registered by a module.
|
|
42
|
+
|
|
43
|
+
The two classes now share a `BindingRegistration` describing where the chain registers, built once per container rather than once per `bind()`. Threading that instead of a loose `(registry, moduleBindingIds, moduleRef)` triple makes the module invariant type-enforced — the id list is present exactly when the chain belongs to a module load — which removes both non-null assertions from the commit path, and drops the constructors from 4 and 5 positional parameters to 2 and 3.
|
|
44
|
+
|
|
45
|
+
`BindingCommitter` is gone and `BindingEntry`'s constructor now takes `(token, registration)`. Neither is a published entry point any more, so this is internal.
|
|
46
|
+
|
|
47
|
+
This is a simplification, **not** a throughput win: removing only the committer measured no change above noise. The chain stays two objects because `tests/unit/container/bind-to-builder-order.test.ts` requires `bind()`'s result to lack `when*()` at runtime — that is the test's own guarantee, stricter than SPEC §2.4, which only claims compiler enforcement. The measured ceiling for removing every builder object is ~19% on `realistic-graph-cold-resolve` under a forced GC — recorded in ARCHITECTURE so the lead is not re-tried blind.
|
|
48
|
+
|
|
49
|
+
- [#646](https://github.com/codefastlabs/codefast/pull/646) [`d27b76f`](https://github.com/codefastlabs/codefast/commit/d27b76fb14200ae5226ec2a05b77d44ab91b016c) Thanks [@thevuong](https://github.com/thevuong)! - Compile instantiation plans around dependencies the compiler cannot see through, instead of refusing to compile the graph at all. A factory, a scoped binding, an activation hook, a class past the depth limit, or a multi/optional/named parameter now compiles to an _escape_ — a re-entry into the runtime resolver seeded with exactly the ancestors the interpreted path would have pushed at that point, dispatched through exactly the resolve the interpreter would have called. Cycle detection, constraint contexts and error paths are therefore identical to never having compiled, and only the opaque dependency pays the runtime price while its siblings and ancestors stay compiled.
|
|
50
|
+
|
|
51
|
+
Previously a single `toDynamic` dependency anywhere in a class graph dropped the whole graph to the interpreted path — a 13.9× cliff on a shape applications write constantly (a factory-provided config injected into a class tree). That graph is now ~2× faster, and the first-materialization path of a singleton dependency inside a plan gained cycle detection it did not have.
|
|
52
|
+
|
|
53
|
+
- [#646](https://github.com/codefastlabs/codefast/pull/646) [`d27b76f`](https://github.com/codefastlabs/codefast/commit/d27b76fb14200ae5226ec2a05b77d44ab91b016c) Thanks [@thevuong](https://github.com/thevuong)! - Split the resolver's self-contained caches into named collaborators — `BindingLookupCache` (the chain-versioned options-less lookup memo), `ClassIntrospector` (per-class metadata, `@postConstruct` discovery, accessor injection, instantiation) and `ActivationNeedCache` (per-binding activation need, versioned on the lifecycle manager). The engine class keeps the sync and async pipelines, which genuinely need the same private state on every hop, and `ARCHITECTURE.md` now records the layering, the invariants each hot path depends on, and the rule that separates a legitimate threshold (choosing an implementation) from the kind that was removed (choosing a semantics).
|
|
54
|
+
|
|
55
|
+
New subpaths `@codefast/di/resolution/{activation-need,binding-lookup-cache,class-introspector}`; `@codefast/di/resolution/class-plan` is now `@codefast/di/resolution/instantiation-plan`, correcting an export map that had been stale since the module was renamed.
|
|
56
|
+
|
|
57
|
+
- [#646](https://github.com/codefastlabs/codefast/pull/646) [`a720c62`](https://github.com/codefastlabs/codefast/commit/a720c6297d041ffd2d0bba2e6146af894007a367) Thanks [@thevuong](https://github.com/thevuong)! - Collapse the fluent binding chain into one object. A single `BindingChain` is now the `BindToBuilder` that `bind()` returns and the kind-specific builder that `to*()` returns, so a `bind()` allocates one builder instead of two.
|
|
58
|
+
|
|
59
|
+
The `to*()`-before-`when*()` ordering stays enforced, as a type-level guarantee — which is what SPEC §2.4 actually claims. `bind()` is typed `BindToBuilder`, so a refinement before `to*()` does not compile; `tests/types/container-api.test.ts` pins that. For a caller without types, or one who casts past them, every refinement now throws the new **`ChainNotRegisteredError`** naming the token and pointing at `to*()`, rather than silently doing nothing. `whenDefault()` asserts registration for that reason alone, since it otherwise has nothing to do.
|
|
60
|
+
|
|
61
|
+
The previous revision kept two objects because a unit test asserted the refinement methods were _absent from the object_ `bind()` returns — a stricter reading than the spec, and one that pinned an implementation detail. That test now asserts the contract instead: every refinement throws before `to*()`, nothing is registered when it does, and the chain still works normally afterwards.
|
|
62
|
+
|
|
63
|
+
This is an API simplification, **not** a throughput win: going from four builder objects per bind to three measured no change above noise, and a fluent API cannot go below one, so the ~19% ceiling recorded in ARCHITECTURE for removing all of them is unreachable rather than pending.
|
|
64
|
+
|
|
65
|
+
- [#646](https://github.com/codefastlabs/codefast/pull/646) [`1241f82`](https://github.com/codefastlabs/codefast/commit/1241f82bdb40613667c781111f2ce20409ddfd89) Thanks [@thevuong](https://github.com/thevuong)! - Register a fluent binding chain once instead of once per refinement. `bind(T).toDynamic(f).singleton()` used to insert a binding, remove it, and insert a replacement — two registry mutations, two version bumps, and a full index churn per binding. The chain now registers on its `to*()` call and refines that same registered object in place; only `when*()` re-slots, and it re-registers under the chain's original id, so `id()` stays valid for the whole chain instead of the intermediate ids being dead. Binding construction also funnels through a single `createBinding()` literal, which is what guarantees the one V8 hidden class the resolver's hot property reads depend on — so the registry stores what it is handed rather than re-copying it.
|
|
66
|
+
|
|
67
|
+
Cold container build (build, bind 10 nodes, resolve the root) went from the suite's only loss to a win against every competitor: 0.76× → 3.0× of InversifyJS, 0.43× → 1.9× of Awilix, 0.22× → 1.07× of tsyringe.
|
|
68
|
+
|
|
69
|
+
The builder's `CommitFn` type is replaced by a `BindingCommitter` interface (`commit` plus `refine`, the latter for in-place refinements the registry indexes do not care about), and `createBinding` / `refinableFields` are new exports from `@codefast/di/binding`.
|
|
70
|
+
|
|
3
71
|
## 0.5.0-canary.7
|
|
4
72
|
|
|
5
73
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -245,7 +245,9 @@ The root entry re-exports the full public API — prefer it (`import { Container
|
|
|
245
245
|
|
|
246
246
|
## Benchmarks
|
|
247
247
|
|
|
248
|
-
A head-to-head benchmark suite lives in the monorepo: [benchmarks/di-inversify](https://github.com/codefastlabs/codefast/tree/main/benchmarks/di-inversify). It compares `@codefast/di` against **InversifyJS 8** on the full scenario set, plus **Awilix** and **tsyringe** on a shared core subset. Each library runs in its canonical mode, in isolated subprocesses, reported as per-trial medians with interquartile range — designed so the results are re-runnable rather than taken on faith.
|
|
248
|
+
A head-to-head benchmark suite lives in the monorepo: [benchmarks/di-inversify](https://github.com/codefastlabs/codefast/tree/main/benchmarks/di-inversify). It compares `@codefast/di` against **InversifyJS 8** on the full scenario set, plus **Awilix** and **tsyringe** on a shared core subset. Each library runs in its canonical mode, in isolated subprocesses, reported as per-trial medians with interquartile range — designed so the results are re-runnable rather than taken on faith.
|
|
249
|
+
|
|
250
|
+
Against InversifyJS — the only one of the three that covers a comparable feature surface — `@codefast/di` currently wins **all 43 comparable scenarios** in both profiles, at a median of 1.86×–2.21× and a geometric mean of 2.38×–2.76×. Against the two deliberately leaner containers it wins the shared core subset as well, with one exception: cold container build against tsyringe under the forced-GC profile. See [RESULTS.md](https://github.com/codefastlabs/codefast/blob/main/benchmarks/di-inversify/RESULTS.md) for the full tables, the caveats, and the losses that earlier revisions reported — or run `pnpm bench` in that package to reproduce them on your machine.
|
|
249
251
|
|
|
250
252
|
## Contributing
|
|
251
253
|
|
package/dist/binding.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ export interface BindingSlot {
|
|
|
12
12
|
* @since 0.3.16-canary.0
|
|
13
13
|
*/
|
|
14
14
|
export declare function bindingSlotEquals(left: BindingSlot, right: BindingSlot): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Cached singleton absent — distinguishes "not resolved yet" from a cached `undefined`.
|
|
17
|
+
*
|
|
18
|
+
* @since 0.5.0-canary.8
|
|
19
|
+
*/
|
|
20
|
+
export declare const NO_INSTANCE: unique symbol;
|
|
15
21
|
/**
|
|
16
22
|
* @since 0.3.16-canary.0
|
|
17
23
|
*/
|
|
@@ -26,12 +32,10 @@ export declare function bindingSlotToString(slot: BindingSlot): string;
|
|
|
26
32
|
interface BindingBase<Value> {
|
|
27
33
|
readonly id: BindingIdentifier;
|
|
28
34
|
/**
|
|
29
|
-
* True while this binding's factory is on the sync resolution stack
|
|
30
|
-
* it on enter and clears it on exit, making cycle detection an O(1) field read with no hashing,
|
|
31
|
-
* no path scan, and no side table. Sync resolution is single-threaded, so the flag is exactly
|
|
32
|
-
* path membership; the async lane keeps its own per-path check because chains can interleave.
|
|
35
|
+
* True while this binding's factory is on the sync resolution stack — the sync lane's cycle check.
|
|
33
36
|
*
|
|
34
|
-
* @remarks Resolver-owned bookkeeping
|
|
37
|
+
* @remarks Resolver-owned bookkeeping; callers never set it. See `ARCHITECTURE.md` for why the
|
|
38
|
+
* sync and async lanes detect cycles differently.
|
|
35
39
|
*/
|
|
36
40
|
inFlight?: boolean | undefined;
|
|
37
41
|
/**
|
|
@@ -42,6 +46,13 @@ interface BindingBase<Value> {
|
|
|
42
46
|
* @remarks Resolver-owned bookkeeping — `registry.add` normalizes it, so callers never set it.
|
|
43
47
|
*/
|
|
44
48
|
frame?: ResolutionFrame | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Cached singleton instance, or {@link NO_INSTANCE}.
|
|
51
|
+
*
|
|
52
|
+
* @remarks A binding belongs to exactly one container, so its singleton slot is per-binding —
|
|
53
|
+
* a field read replaces a keyed lookup on the hottest resolve shape there is.
|
|
54
|
+
*/
|
|
55
|
+
instance?: unknown;
|
|
45
56
|
readonly token: Token<Value> | Constructor<Value>;
|
|
46
57
|
readonly slot: BindingSlot;
|
|
47
58
|
readonly predicate?: ((ctx: ConstraintContext) => boolean) | undefined;
|
|
@@ -130,6 +141,37 @@ export type PartialBinding<Value> = Omit<ClassBinding<Value>, BindingBaseKeys> |
|
|
|
130
141
|
* @since 0.3.16-canary.0
|
|
131
142
|
*/
|
|
132
143
|
export declare function generateBindingId(): BindingIdentifier;
|
|
144
|
+
/**
|
|
145
|
+
* The single construction site for bindings — one literal, one V8 hidden class.
|
|
146
|
+
*
|
|
147
|
+
* @see `ARCHITECTURE.md` — why the field order and the single site are load-bearing.
|
|
148
|
+
*
|
|
149
|
+
* @param source - the kind-specific payload, or an existing binding to re-slot
|
|
150
|
+
* @param id - reuse a caller's id to keep a fluent chain's `id()` stable across refinements
|
|
151
|
+
*
|
|
152
|
+
* @since 0.5.0-canary.8
|
|
153
|
+
*/
|
|
154
|
+
export declare function createBinding<Value>(source: PartialBinding<Value> | Binding<Value>, token: Token<Value> | Constructor<Value>, slot: BindingSlot, predicate: ((ctx: ConstraintContext) => boolean) | undefined, id?: BindingIdentifier): Binding<Value>;
|
|
155
|
+
/**
|
|
156
|
+
* Writable view of the only fields a fluent chain may refine after registration.
|
|
157
|
+
*
|
|
158
|
+
* @remarks No registry index is keyed on these, so a builder that owns the registered object
|
|
159
|
+
* can write them directly instead of re-registering. `token`, `slot`, `predicate` and `id`
|
|
160
|
+
* are excluded on purpose — changing those means re-indexing.
|
|
161
|
+
*
|
|
162
|
+
* @since 0.5.0-canary.8
|
|
163
|
+
*/
|
|
164
|
+
export interface RefinableBindingFields<Value> {
|
|
165
|
+
onActivation: ActivationHandler<Value> | undefined;
|
|
166
|
+
onDeactivation: DeactivationHandler<Value> | undefined;
|
|
167
|
+
scope: BindingScope;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Narrows a registered binding to the fields a fluent chain may still refine.
|
|
171
|
+
*
|
|
172
|
+
* @since 0.5.0-canary.8
|
|
173
|
+
*/
|
|
174
|
+
export declare function refinableFields<Value>(binding: Binding<Value>): RefinableBindingFields<Value>;
|
|
133
175
|
/**
|
|
134
176
|
* Common slot-constraint + id methods shared by all concrete binding builders.
|
|
135
177
|
*
|
package/dist/binding.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9G,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,UAAU,CA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AAG,IAAI,CAAC;IACjD,EAAE,IAAI,iBAAiB,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,KAAK,CAAE,SAAQ,uBAAuB,CAAC,KAAK,CAAC;CAAG;AAEtF;;GAEG;AACH,MAAM,WAAW,yBAAyB,CAAC,KAAK;IAC9C,YAAY,CAAC,EAAE,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACjD,cAAc,CAAC,EAAE,EAAE,mBAAmB,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACrD,EAAE,IAAI,iBAAiB,CAAC;CACzB"}
|
package/dist/binding.js
CHANGED
|
@@ -15,6 +15,12 @@ export function bindingSlotEquals(left, right) {
|
|
|
15
15
|
}
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Cached singleton absent — distinguishes "not resolved yet" from a cached `undefined`.
|
|
20
|
+
*
|
|
21
|
+
* @since 0.5.0-canary.8
|
|
22
|
+
*/
|
|
23
|
+
export const NO_INSTANCE = Symbol("di:no-instance");
|
|
18
24
|
/**
|
|
19
25
|
* @since 0.3.16-canary.0
|
|
20
26
|
*/
|
|
@@ -43,4 +49,42 @@ let bindingIdCounter = 0;
|
|
|
43
49
|
export function generateBindingId() {
|
|
44
50
|
return String(++bindingIdCounter);
|
|
45
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* The single construction site for bindings — one literal, one V8 hidden class.
|
|
54
|
+
*
|
|
55
|
+
* @see `ARCHITECTURE.md` — why the field order and the single site are load-bearing.
|
|
56
|
+
*
|
|
57
|
+
* @param source - the kind-specific payload, or an existing binding to re-slot
|
|
58
|
+
* @param id - reuse a caller's id to keep a fluent chain's `id()` stable across refinements
|
|
59
|
+
*
|
|
60
|
+
* @since 0.5.0-canary.8
|
|
61
|
+
*/
|
|
62
|
+
export function createBinding(source, token, slot, predicate, id = generateBindingId()) {
|
|
63
|
+
const fields = source;
|
|
64
|
+
return {
|
|
65
|
+
kind: fields.kind,
|
|
66
|
+
id,
|
|
67
|
+
inFlight: false,
|
|
68
|
+
frame: undefined,
|
|
69
|
+
instance: source.instance ?? NO_INSTANCE,
|
|
70
|
+
token,
|
|
71
|
+
slot,
|
|
72
|
+
predicate,
|
|
73
|
+
scope: fields.scope,
|
|
74
|
+
target: fields.target,
|
|
75
|
+
factory: fields.factory,
|
|
76
|
+
deps: fields.deps,
|
|
77
|
+
value: fields.value,
|
|
78
|
+
onActivation: fields.onActivation,
|
|
79
|
+
onDeactivation: fields.onDeactivation,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Narrows a registered binding to the fields a fluent chain may still refine.
|
|
84
|
+
*
|
|
85
|
+
* @since 0.5.0-canary.8
|
|
86
|
+
*/
|
|
87
|
+
export function refinableFields(binding) {
|
|
88
|
+
return binding;
|
|
89
|
+
}
|
|
46
90
|
//# sourceMappingURL=binding.js.map
|
package/dist/binding.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAwBA;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAiB,EAAE,KAAkB;IACrE,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,KAAK,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QAC3C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,QAAQ,KAAK,MAAM,IAAI,MAAM,CAAC,EAA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AC;AACzB;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,MAAM,CAAC,EAAE,gBAAgB,CAAsB,CAAC;AACzD,CAAC;AA4BD;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA8C,EAC9C,KAAwC,EACxC,IAAiB,EACjB,SAA4D,EAC5D,EAAE,GAAsB,iBAAiB,EAAE;IAE3C,MAAM,MAAM,GAAG,MAA8B,CAAC;IAC9C,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,EAAE;QACF,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,SAAS;QAChB,QAAQ,EAAG,MAAiC,CAAC,QAAQ,IAAI,WAAW;QACpE,KAAK;QACL,IAAI;QACJ,SAAS;QACT,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,cAAc,EAAE,MAAM,CAAC,cAAc;KACe,CAAC;AACzD,CAAC;AAiBD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAQ,OAAuB;IAC5D,OAAO,OAAwC,CAAC;AAClD,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A class
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* this alias is the DI “class token” surface only.
|
|
2
|
+
* A class token: newable, producing `Value`.
|
|
3
|
+
*
|
|
4
|
+
* @remarks Rest parameters are `never[]` so classes with typed constructors stay assignable under
|
|
5
|
+
* `strictFunctionTypes`. Construction uses the real shape; this alias is the token surface only.
|
|
7
6
|
*
|
|
8
7
|
* @since 0.3.16-canary.0
|
|
9
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constructor-type.d.ts","sourceRoot":"","sources":["../src/constructor-type.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"constructor-type.d.ts","sourceRoot":"","sources":["../src/constructor-type.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,CAAC,KAAK,GAAG,OAAO,IAAI,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;AAEhF;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC"}
|
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The fluent chain `bind()` returns: it registers the binding and refines it in place.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* previous binding by id) whenever a later fluent call refines the binding —
|
|
6
|
-
* so a chain left half-finished is still a valid registration.
|
|
4
|
+
* @see `ARCHITECTURE.md` — why one object plays every role, and what pins the ordering.
|
|
7
5
|
*/
|
|
8
|
-
import type { AliasBindingBuilder,
|
|
6
|
+
import type { AliasBindingBuilder, BindingBuilder, BindToBuilder, ConstantBindingBuilder, ScopedBindingBuilder, SingletonBindingBuilder, SingletonLifecycleBuilder, TransientBindingBuilder } from "#/binding";
|
|
9
7
|
import type { InjectableDependency, ResolvedDependencyValue } from "#/decorators/inject";
|
|
8
|
+
import type { BindingRegistry } from "#/registry";
|
|
10
9
|
import type { Token } from "#/token";
|
|
11
|
-
import type { BindingIdentifier, Constructor, ResolutionContext } from "#/types";
|
|
10
|
+
import type { ActivationHandler, BindingIdentifier, ConstraintContext, Constructor, DeactivationHandler, ResolutionContext } from "#/types";
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
12
|
+
* Where a chain registers, and on whose behalf.
|
|
13
|
+
*
|
|
14
|
+
* @remarks Built once per container and shared by every chain it creates. `moduleBindingIds` is
|
|
15
|
+
* present exactly when the chain belongs to a module load.
|
|
16
|
+
*
|
|
17
|
+
* @since 0.5.0-canary.8
|
|
14
18
|
*/
|
|
15
|
-
export
|
|
19
|
+
export interface BindingRegistration {
|
|
20
|
+
readonly registry: BindingRegistry;
|
|
21
|
+
readonly moduleBindingIds: Array<BindingIdentifier> | undefined;
|
|
22
|
+
}
|
|
16
23
|
/**
|
|
17
|
-
*
|
|
24
|
+
* The one builder behind `bind()` and every `to*()` return type. Each interface exposes only the
|
|
25
|
+
* calls that are legal at that point in the chain; the runtime object is shared because every
|
|
26
|
+
* refinement is the same operation — narrow the registered binding, keep its id.
|
|
27
|
+
*
|
|
28
|
+
* @since 0.5.0-canary.8
|
|
18
29
|
*/
|
|
19
|
-
export declare class
|
|
30
|
+
export declare class BindingChain<Value> implements AliasBindingBuilder, BindingBuilder<Value>, BindToBuilder<Value>, ConstantBindingBuilder<Value>, ScopedBindingBuilder<Value>, SingletonBindingBuilder<Value>, SingletonLifecycleBuilder<Value>, TransientBindingBuilder<Value> {
|
|
20
31
|
#private;
|
|
21
|
-
constructor(token: Token<Value> | Constructor<Value>,
|
|
32
|
+
constructor(token: Token<Value> | Constructor<Value>, registration: BindingRegistration);
|
|
22
33
|
to(type: Constructor<Value>): BindingBuilder<Value>;
|
|
23
34
|
toSelf(): BindingBuilder<Value>;
|
|
24
35
|
toConstantValue(value: Value): ConstantBindingBuilder<Value>;
|
|
@@ -31,5 +42,15 @@ export declare class BindingEntry<Value> implements BindToBuilder<Value> {
|
|
|
31
42
|
[K in keyof Deps]: ResolvedDependencyValue<NoInfer<Deps>[K]>;
|
|
32
43
|
}) => Promise<Value>, deps: Deps): BindingBuilder<Value>;
|
|
33
44
|
toAlias(target: Token<Value> | Constructor<Value>): AliasBindingBuilder;
|
|
45
|
+
when(predicate: (ctx: ConstraintContext) => boolean): this;
|
|
46
|
+
whenNamed(name: string): this;
|
|
47
|
+
whenTagged(tag: string, value: unknown): this;
|
|
48
|
+
whenDefault(): this;
|
|
49
|
+
singleton(): SingletonBindingBuilder<Value>;
|
|
50
|
+
transient(): TransientBindingBuilder<Value>;
|
|
51
|
+
scoped(): ScopedBindingBuilder<Value>;
|
|
52
|
+
onActivation(fn: ActivationHandler<Value>): this;
|
|
53
|
+
onDeactivation(fn: DeactivationHandler<Value>): this;
|
|
54
|
+
id(): BindingIdentifier;
|
|
34
55
|
}
|
|
35
56
|
//# sourceMappingURL=binding-builders.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding-builders.d.ts","sourceRoot":"","sources":["../../src/container/binding-builders.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"binding-builders.d.ts","sourceRoot":"","sources":["../../src/container/binding-builders.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EACV,mBAAmB,EAEnB,cAAc,EAEd,aAAa,EACb,sBAAsB,EAEtB,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAGzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAEjB,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAyCjB;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,gBAAgB,EAAE,KAAK,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;CACjE;AAID;;;;;;GAMG;AACH,qBAAa,YAAY,CAAC,KAAK,CAC7B,YACE,mBAAmB,EACnB,cAAc,CAAC,KAAK,CAAC,EACrB,aAAa,C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