import { FluentConfiguration } from "./FluentConfiguration"; import { ContainerServices, ContainerServicesConstraint, IDestroyable } from "./interfaces"; export function fluent>() { return new FluentConfiguration(); } export type key = string | number | symbol; export const isKey = (v: unknown): v is key => typeof v === "string" || typeof v === "number" || typeof v === "symbol"; export const isString = (v: unknown): v is string => typeof v === "string"; export const isNotNull = (v: T): v is NonNullable => v !== null && v !== undefined; export const each = (obj: T, cb: >(v: NonNullable, k: X) => void) => (Object.keys(obj) as (Extract)[]) .forEach(k => { const v = obj[k]; isNotNull(v) && cb(v, k); }); export const argumentNotNull = (arg: unknown, name: string) => { if (arg === null || arg === undefined) throw new Error("The argument " + name + " can't be null or undefined"); }; export const isPromise = (val: unknown): val is PromiseLike => isNotNull(val) && typeof (val as PromiseLike).then === "function"; export const isDestroyable = (d: unknown): d is IDestroyable => isNotNull(d) && typeof (d as IDestroyable).destroy === "function"; let _nextOid = 0; const _oid = typeof Symbol === "function" ? Symbol.for("__implab__oid__") : "__implab__oid__"; type OidSlot = { [k in typeof _oid]?: string }; export const oid = (instance: T): string => { argumentNotNull(instance, "instance"); const val = (instance as OidSlot)[_oid]; return val ? val : ((instance as OidSlot)[_oid] = `oid_${++_nextOid}`); };