@dipscope/type-manager
Version:
Transform JSON strings or plain objects into JS class instances.
64 lines • 2.64 kB
JavaScript
import { EMPTY_ARRAY } from './constants/empty-array';
import { getOwnReflectMetadata } from './functions/get-own-reflect-metadata';
import { ResolvedInjectState } from './inject-states/resolved-inject-state';
import { UnresolvedInjectState } from './inject-states/unresolved-inject-state';
import { Metadata } from './metadata';
export class InjectMetadata extends Metadata {
constructor(typeManager, typeFnMap, declaringTypeMetadata, injectIndex, injectOptions) {
var _a;
super(typeManager, typeFnMap);
this.declaringTypeMetadata = declaringTypeMetadata;
this.injectIndex = injectIndex;
this.injectOptions = injectOptions;
this.reflectTypeFn = ((_a = getOwnReflectMetadata('design:paramtypes', declaringTypeMetadata.typeFn)) !== null && _a !== void 0 ? _a : EMPTY_ARRAY)[injectIndex];
this.currentInjectState = new UnresolvedInjectState(this);
this.configure(injectOptions);
return;
}
get injectState() {
return this.currentInjectState;
}
get key() {
return this.currentInjectState.key;
}
get typeArgument() {
return this.currentInjectState.typeArgument;
}
get typeMetadata() {
return this.currentInjectState.typeMetadata;
}
resolveInjectState() {
const injectOptions = this.injectOptions;
const key = injectOptions.key;
const typeArgument = injectOptions.typeArgument === undefined ? this.reflectTypeFn : injectOptions.typeArgument;
const typeMetadata = this.resolveTypeMetadata(typeArgument);
const resolvedInjectState = new ResolvedInjectState(this, key, typeArgument, typeMetadata);
this.currentInjectState = resolvedInjectState;
return resolvedInjectState;
}
unresolveInjectState() {
const unresolvedInjectState = new UnresolvedInjectState(this);
this.currentInjectState = unresolvedInjectState;
return unresolvedInjectState;
}
hasKey(key) {
this.injectOptions.key = key;
this.currentInjectState = new UnresolvedInjectState(this);
return this;
}
hasTypeArgument(typeArgument) {
this.injectOptions.typeArgument = typeArgument;
this.currentInjectState = new UnresolvedInjectState(this);
return this;
}
configure(injectOptions) {
if (injectOptions.key !== undefined) {
this.hasKey(injectOptions.key);
}
if (injectOptions.typeArgument !== undefined) {
this.hasTypeArgument(injectOptions.typeArgument);
}
return this;
}
}
//# sourceMappingURL=inject-metadata.js.map