@livx.cc/native-kit 0.42.0 → 0.43.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/package.json +1 -1
- package/src/core/module-registry.ts +13 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livx.cc/native-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "Isomorphic native-capabilities kit for PWAs \u2014 same API in browser and in an appwrap native shell. Zero dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Elya Livshitz",
|
|
@@ -43,8 +43,14 @@ export class ModuleRegistry {
|
|
|
43
43
|
return [...new Set([...this.instances.keys(), ...this.factories.keys()])].sort();
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Typed, string-keyed lookup. STRICT by design: the ONLY public signature is keyed to
|
|
48
|
+
* `keyof KitModuleRegistry`, so `getModule('billing')` is a COMPILE ERROR unless the billing pack's
|
|
49
|
+
* kit client has been imported (its `declare module` augments the registry) — you get compile-time
|
|
50
|
+
* verification + autocomplete of exactly the modules you've wired, never a runtime surprise. For a
|
|
51
|
+
* genuinely dynamic name, use {@link getModuleUnsafe}.
|
|
52
|
+
*/
|
|
46
53
|
getModule<K extends keyof KitModuleRegistry>(name: K): KitModuleRegistry[K];
|
|
47
|
-
getModule<T = unknown>(name: string): T;
|
|
48
54
|
getModule(name: string): unknown {
|
|
49
55
|
if (this.instances.has(name)) return this.instances.get(name);
|
|
50
56
|
const factory = this.factories.get(name);
|
|
@@ -61,4 +67,10 @@ export class ModuleRegistry {
|
|
|
61
67
|
`Did you list its pack in modulePacks?`
|
|
62
68
|
);
|
|
63
69
|
}
|
|
70
|
+
|
|
71
|
+
/** Escape hatch for a genuinely DYNAMIC module name (not a compile-time literal) — bypasses the
|
|
72
|
+
* keyed check. Prefer {@link getModule}; reach for this only when the name isn't statically known. */
|
|
73
|
+
getModuleUnsafe<T = unknown>(name: string): T {
|
|
74
|
+
return (this.getModule as (n: string) => unknown)(name) as T;
|
|
75
|
+
}
|
|
64
76
|
}
|