@k8slens/injectable 26.1.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/index.d.ts CHANGED
@@ -430,7 +430,13 @@ export const lifecycleEnum: {
430
430
  };
431
431
  };
432
432
 
433
- type RegistrationCallback = (injectable: Injectable<any, any, any>) => void;
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. One level suffices: the default `.for()` factory is
720
- // self-similar, so a child's own `for` yields the same shape again.
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
- | ConsumptionChildOf<Cons>;
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[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@k8slens/injectable",
3
3
  "private": false,
4
- "version": "26.1.0",
4
+ "version": "26.2.0",
5
5
  "description": "A brutal dependency injection container",
6
6
  "lens": {
7
7
  "env": "agnostic",