API Reference

value-metadata

API entries in this module: 9

Current value-metadata implementation

The ValueMetadata service provides information about how rs-x should handle a value type at runtime, such as whether it should be proxied and whether it is async. It retrieves providers from IValueMetadataList, sorts them by priority (highest first), and selects the first provider for which applies(value) returns true.

Default providers are: ArrayMetadata (8), DateMetadata (7), MapMetadata (6), ObservableMetadata (5), PromiseMetadata (4), SetMetadata (3), and fallback DummyMetadata (-1000).

Rs-x use this metadata to decide whether a value is async (isAsync) and whether it should be proxied (needsProxy).

Example: use IValueMetadata

import {
  InjectionContainer,
  RsXCoreInjectionTokens,
  RsXCoreModule,
  type IValueMetadata,
} from '@rs-x/core';

await InjectionContainer.load(RsXCoreModule);

const valueMetadata = InjectionContainer.get<IValueMetadata>(
  RsXCoreInjectionTokens.IValueMetadata,
);

console.log(valueMetadata.isAsync(Promise.resolve(1))); // true
console.log(valueMetadata.needsProxy(new Map())); // true
console.log(valueMetadata.needsProxy(42)); // false (DummyMetadata fallback)

How to extend or modify

Add your own metadata class and override IValueMetadataList order so your custom type is checked before generic handlers.

Override metadata strategy list

import {
  ArrayMetadata,
  DateMetadata,
  DummyMetadata,
  InjectionContainer,
  MapMetadata,
  ObservableMetadata,
  overrideMultiInjectServices,
  PromiseMetadata,
  RsXCoreInjectionTokens,
  RsXCoreModule,
  SetMetadata,
  type IMultiInjectService,
  type IValueMetadata,
} from '@rs-x/core';

class UrlMetadata implements IValueMetadata {
  public readonly priority = 9;
  public isAsync(): boolean { return false; }
  public needsProxy(): boolean { return false; }
  public applies(value: unknown): boolean { return value instanceof URL; }
}

Module API entries