Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@artusjs/injection

Package Overview
Dependencies
Maintainers
9
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@artusjs/injection - npm Package Compare versions

Comparing version 0.0.1-alpha.0 to 0.0.1-alpha.1

lib/person.d.ts

16

lib/container.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
const types_1 = require("./types");

@@ -20,4 +21,15 @@ const constant_1 = require("./constant");

async getAsync(id) {
const instance = this.get(id);
await instance.init();
var _a;
const md = this.registry.get(id);
// TODO: custom error
if (!md) {
throw new Error('not found');
}
const instance = this.getValue(md);
let methodName = 'init';
if (md.type) {
const initMd = (0, util_1.getMetadata)(_1.CLASS_ASYNC_INIT_METHOD, md.type);
methodName = (initMd === null || initMd === void 0 ? void 0 : initMd.propertyName) || methodName;
}
await ((_a = instance[methodName]) === null || _a === void 0 ? void 0 : _a.call(instance));
return instance;

@@ -24,0 +36,0 @@ }

2

lib/decorator/init.d.ts

@@ -1,1 +0,1 @@

export declare function init(): MethodDecorator;
export declare function Init(): MethodDecorator;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
function init() {
return (_target, _property, _descriptor) => {
exports.Init = void 0;
const util_1 = require("../util");
const constant_1 = require("../constant");
function Init() {
return (target, property) => {
var _a;
target = (_a = target.construct) !== null && _a !== void 0 ? _a : target;
(0, util_1.setMetadata)(constant_1.CLASS_ASYNC_INIT_METHOD, { id: target, propertyName: property }, target);
};
}
exports.init = init;
exports.Init = Init;
import { Identifier } from "..";
export declare function inject(id?: Identifier): PropertyDecorator | ParameterDecorator;
export declare function Inject(id?: Identifier): (target: any, propertyKey: string | symbol, index?: number | undefined) => void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.inject = void 0;
exports.Inject = void 0;
const util_1 = require("../util");
const constant_1 = require("../constant");
function inject(id) {
function Inject(id) {
return (target, propertyKey, index) => {

@@ -33,2 +33,2 @@ var _a;

}
exports.inject = inject;
exports.Inject = Inject;
import { Identifier } from "../types";
export declare function injectable(id?: Identifier): ClassDecorator;
export declare function Injectable(id?: Identifier): ClassDecorator;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.injectable = void 0;
exports.Injectable = void 0;
const util_1 = require("../util");
const constant_1 = require("../constant");
function injectable(id) {
function Injectable(id) {
return (target) => {

@@ -11,2 +11,2 @@ (0, util_1.setMetadata)(constant_1.CLASS_CONSTRUCTOR, { id: id !== null && id !== void 0 ? id : target.name }, target);

}
exports.injectable = injectable;
exports.Injectable = Injectable;
{
"name": "@artusjs/injection",
"version": "0.0.1-alpha.0",
"version": "0.0.1-alpha.1",
"description": "A IoC Implemention for Artus.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

import { InjectableOptions, ReflectMetadataType } from ".";
import { CLASS_ASYNC_INIT_METHOD, InjectableOptions, ReflectMetadataType } from ".";
import { Identifier, InjectableMetadata, ScopeEnum, Constructable } from "./types";

@@ -26,4 +26,14 @@ import { CLASS_CONSTRUCTOR, CLASS_PROPERTY, CLASS_CONSTRUCTOR_ARGS } from './constant';

public async getAsync(id: Identifier) {
const instance = this.get(id);
await instance.init();
const md = this.registry.get(id);
// TODO: custom error
if (!md) {
throw new Error('not found');
}
const instance = this.getValue(md);
let methodName: string | symbol = 'init';
if (md.type) {
const initMd = getMetadata(CLASS_ASYNC_INIT_METHOD, md.type) as ReflectMetadataType;
methodName = initMd?.propertyName || methodName;
}
await instance[methodName]?.();
return instance;

@@ -30,0 +40,0 @@ }

@@ -1,5 +0,9 @@

export function init(): MethodDecorator {
return (_target: any, _property: string | symbol, _descriptor: PropertyDescriptor) => {
import { setMetadata } from "../util";
import { CLASS_ASYNC_INIT_METHOD } from '../constant';
export function Init(): MethodDecorator {
return (target: any, property: string | symbol) => {
target = target.construct ?? target;
setMetadata(CLASS_ASYNC_INIT_METHOD, { id: target, propertyName: property }, target);
};
}

@@ -5,3 +5,4 @@ import { Identifier, ReflectMetadataType } from "..";

export function inject(id?: Identifier): PropertyDecorator | ParameterDecorator {
export function Inject(id?: Identifier) {
return (target: any, propertyKey: string | symbol, index?: number) => {

@@ -8,0 +9,0 @@ target = target.constructor ?? target;

@@ -6,3 +6,3 @@ import { Identifier } from "../types";

export function injectable(id?: Identifier): ClassDecorator {
export function Injectable(id?: Identifier): ClassDecorator {
return (target: any) => {

@@ -9,0 +9,0 @@ setMetadata(CLASS_CONSTRUCTOR, { id: id ?? target.name }, target);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc