Two entry points giving
resolve/resolveAlla type narrowed by module name, without changing the runtime's actual behavior.
Module typed | Source packages/front/fw/src/typed.js | Deps runtime | Worker-safe yes (pure functions; createRuntime only constructs a ModuleRuntime)
Resolve
import { asTyped, createRuntime } from '@awacloud/fw/typed';
Not a DI module — imported directly by subpath, like sanity/lockdown.
API
Exactly the two exports of src/typed.js:
| Export | Signature | Returns |
|---|---|---|
asTyped |
(runtime: *) => * |
identity cast — re-types an existing ModuleRuntime at the type level; no runtime effect |
createRuntime |
(modules?: *) => * |
builds a fresh ModuleRuntime, deep-registers modules (via registerAllDeep, so transitive deps come along) when provided, and returns it typed |
createRuntime's modules argument accepts either an array of module
definitions or a namespace object whose values are module definitions (the
shape of @awacloud/fw/core/modules).
Narrowing caveat (quoted from src/typed.js's file header): "resolve
is typed against the FULL catalog, not against what you actually
registered (module name is string in the emitted .d.ts, not a
literal, so the registered set can't be tracked at the type level). Only
call resolve(name) for modules you injected — resolving an unregistered
name type-checks but throws 'Module not found' at runtime."
Types
The precise return types live in types/typed.d.ts plus the generated
types/registry.generated.d.ts (module-name → instance-shape map), rebuilt
with:
bun run types:registry
Examples
import { createRuntime } from '@awacloud/fw/typed';
import modules from '@awacloud/fw/core/modules';
const rt = createRuntime(modules);
const hex = rt.resolve('hex'); // narrowed to hex's instance shape
import { runtime } from '@awacloud/fw';
import { asTyped } from '@awacloud/fw/typed';
const typedRuntime = asTyped(runtime); // same instance, typed
Notes
asTypedimports nothing;createRuntimepulls inModuleRuntime. Consumers using onlyasTypedtree-shakecreateRuntime(andModuleRuntime) away.- Both exports are runtime no-ops beyond
createRuntime's actual registration work — the typing value is entirely at the TypeScript level, resolved viatypes/typed.d.tsand the generated registry map.
See also
- TypeScript guide
- runtime — the
ModuleRuntimeclass both exports wrap - main — the default
@awacloud/fwentry point