@k8slens/injectable 26.0.0 → 26.2.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 +19 -0
- package/dist/index.js +147 -60
- package/index.d.ts +53 -6
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -430,7 +430,13 @@ export const lifecycleEnum: {
|
|
|
430
430
|
};
|
|
431
431
|
};
|
|
432
432
|
|
|
433
|
-
|
|
433
|
+
// Called with what was (de)registered and the token it was registered under:
|
|
434
|
+
// the resolved one when `injectionToken` was given as a function, which the
|
|
435
|
+
// injectable alone would not reveal.
|
|
436
|
+
type RegistrationCallback = (
|
|
437
|
+
injectable: Injectable<any, any, any> | Injectable2<any>,
|
|
438
|
+
injectionToken: InjectionToken<any, any, any> | Token2<Factory, any, any> | undefined,
|
|
439
|
+
) => void;
|
|
434
440
|
|
|
435
441
|
// --- injectionDecoratorToken ---
|
|
436
442
|
//
|
|
@@ -681,6 +687,20 @@ export function getTypedSpecifier
|
|
|
681
687
|
|
|
682
688
|
// ---- Injectable2 / InjectionToken2 ----
|
|
683
689
|
|
|
690
|
+
// The scope an injectable is being registered under, as handed to an
|
|
691
|
+
// `injectionToken` given as a function: the ids of the scopes, outermost first
|
|
692
|
+
// and the immediate owner last — what the injectable's own `di.scopeIds` will
|
|
693
|
+
// read as. Resolved once per registration, so the same injectable registered
|
|
694
|
+
// by two scopes ends up under two tokens.
|
|
695
|
+
export interface RegistrationScope {
|
|
696
|
+
readonly scopeIds: string[];
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// An `injectionToken` is a token, or a function of the registration's scope
|
|
700
|
+
// producing one — for token families keyed by something only the registration
|
|
701
|
+
// knows, `({ scopeIds }) => someToken.for(...)`.
|
|
702
|
+
export type InjectionTokenOf<T> = T | ((scope: RegistrationScope) => T);
|
|
703
|
+
|
|
684
704
|
export interface Injectable2<F extends Factory = Factory> {
|
|
685
705
|
readonly aliasType: 'injectable2';
|
|
686
706
|
readonly id: string;
|
|
@@ -690,7 +710,7 @@ export interface Injectable2<F extends Factory = Factory> {
|
|
|
690
710
|
// `getInjectable2` keeps the relationship sound; precise per-injectable
|
|
691
711
|
// token typing isn't observably useful here (runtime reads only token-level
|
|
692
712
|
// fields like `.id`, `.abstract`, `.maxCacheSize`).
|
|
693
|
-
readonly injectionToken?: Token2<Factory, any, any
|
|
713
|
+
readonly injectionToken?: InjectionTokenOf<Token2<Factory, any, any>>;
|
|
694
714
|
readonly consumptions?: ReadonlyArray<Consumption>;
|
|
695
715
|
readonly transient?: boolean;
|
|
696
716
|
readonly causesSideEffects?: boolean;
|
|
@@ -716,8 +736,10 @@ export type Consumption =
|
|
|
716
736
|
|
|
717
737
|
// The `.for()` derivatives of a declared token are covered by declaring the
|
|
718
738
|
// token itself — otherwise a specifier only known at runtime could not be
|
|
719
|
-
// declared at all.
|
|
720
|
-
//
|
|
739
|
+
// declared at all. Families nest (`token.for(kind).for(scopeIds)`), so the
|
|
740
|
+
// descendants are walked a few levels down; the walk is bounded because the
|
|
741
|
+
// default `.for()` factory is self-similar, and a child's own `for` yields
|
|
742
|
+
// the same shape again, which an unbounded walk would never finish.
|
|
721
743
|
type NotAny<T> = 0 extends 1 & T ? never : T;
|
|
722
744
|
|
|
723
745
|
export type ConsumptionChildOf<C> = C extends {
|
|
@@ -728,9 +750,14 @@ export type ConsumptionChildOf<C> = C extends {
|
|
|
728
750
|
: never
|
|
729
751
|
: never;
|
|
730
752
|
|
|
753
|
+
type ConsumptionDescendantOf<C, Depth extends unknown[] = [0, 0, 0, 0]> =
|
|
754
|
+
Depth extends [unknown, ...infer Shallower]
|
|
755
|
+
? ConsumptionChildOf<C> | ConsumptionDescendantOf<ConsumptionChildOf<C>, Shallower>
|
|
756
|
+
: never;
|
|
757
|
+
|
|
731
758
|
type Consumable<Cons extends Consumption> =
|
|
732
759
|
| Cons
|
|
733
|
-
|
|
|
760
|
+
| ConsumptionDescendantOf<Cons>;
|
|
734
761
|
|
|
735
762
|
// The injection surface of `instantiate`'s `di`: the same cardinality gating as
|
|
736
763
|
// the container's, narrowed to what the injectable declared. Injectables pass
|
|
@@ -843,7 +870,7 @@ export function getInjectable2<
|
|
|
843
870
|
readonly id: string;
|
|
844
871
|
readonly consumptions?: ReadonlyArray<Cons>;
|
|
845
872
|
readonly instantiate: (di: ConsumptionDi<Cons>) => F;
|
|
846
|
-
readonly injectionToken: Token2<TF, any, undefined, any
|
|
873
|
+
readonly injectionToken: InjectionTokenOf<Token2<TF, any, undefined, any>>;
|
|
847
874
|
readonly transient?: boolean;
|
|
848
875
|
readonly causesSideEffects?: boolean;
|
|
849
876
|
readonly tags?: string[];
|
|
@@ -1580,6 +1607,26 @@ export interface DiContainerForInjection2 {
|
|
|
1580
1607
|
injectManyWithMeta: InjectManyWithMeta2;
|
|
1581
1608
|
injectMaybeWithMeta: InjectMaybeWithMeta2;
|
|
1582
1609
|
|
|
1610
|
+
// ---- Identity of the injectable being instantiated ----
|
|
1611
|
+
//
|
|
1612
|
+
// For instantiate-code shared across injectables: decorators, and
|
|
1613
|
+
// factories producing many injectables from one `instantiate`. An
|
|
1614
|
+
// imperative override sees the identity of the injectable it stands in
|
|
1615
|
+
// for, since that is what was registered.
|
|
1616
|
+
|
|
1617
|
+
// The injectable's own id, as given to `getInjectable2`.
|
|
1618
|
+
readonly id: string;
|
|
1619
|
+
|
|
1620
|
+
// The ids of the scopes the injectable was registered under, outermost
|
|
1621
|
+
// first and the immediate owner last — the segments of its namespaced id
|
|
1622
|
+
// minus its own; empty at container level. Each read walks the
|
|
1623
|
+
// registration tree and returns a fresh array.
|
|
1624
|
+
readonly scopeIds: string[];
|
|
1625
|
+
|
|
1626
|
+
// `scopeIds` followed by `id`: the segments of the namespaced id. Each read
|
|
1627
|
+
// walks the registration tree and returns a fresh array.
|
|
1628
|
+
readonly scopedId: string[];
|
|
1629
|
+
|
|
1583
1630
|
register(...injectables: (Alias | InjectableBunch)[]): void;
|
|
1584
1631
|
|
|
1585
1632
|
deregister(...injectables: (Alias | InjectableBunch)[]): void;
|