Socket
Socket
Sign inDemoInstall

inversify-binding-decorators

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inversify-binding-decorators - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

3

amd/decorator/provide.js

@@ -21,3 +21,4 @@ define(["require", "exports", "inversify"], function (require, exports, inversify_1) {

catch (e) {
throw new Error(e.message + " " +
throw new Error("Cannot apply @provide decorator multiple times but is has been used " +
("multiple times in " + target.name + " ") +
"Please use @provide(ID, true) if you are trying to declare multiple bindings!");

@@ -24,0 +25,0 @@ }

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

define(["require", "exports", "inversify"], function (require, exports, inversify_1) {
define(["require", "exports", "inversify", "inversify"], function (require, exports, inversify_1, inversify_2) {
"use strict";

@@ -8,7 +8,24 @@ Object.defineProperty(exports, "__esModule", { value: true });

}
ProvideDoneSyntax.prototype.done = function () {
var _this = this;
ProvideDoneSyntax.prototype.done = function (force) {
var that = this;
return function (target) {
inversify_1.decorate(inversify_1.injectable(), target);
_this._binding.implementationType = target;
var isAlreadyDecorated = Reflect.hasOwnMetadata(inversify_2.METADATA_KEY.PARAM_TYPES, target);
var redecorateWithInject = force === true;
if (redecorateWithInject === true && isAlreadyDecorated === false) {
inversify_1.decorate(inversify_1.injectable(), target);
}
else if (redecorateWithInject === true && isAlreadyDecorated === true) {
// Do nothing
}
else {
try {
inversify_1.decorate(inversify_1.injectable(), target);
}
catch (e) {
throw new Error("Cannot apply @provideFluent decorator multiple times but is has been used " +
("multiple times in " + target.name + " ") +
"Please use @done(true) if you are trying to declare multiple bindings!");
}
}
that._binding.implementationType = target;
return target;

@@ -15,0 +32,0 @@ };

@@ -21,6 +21,6 @@ define(["require", "exports", "./provide_when_on_syntax", "./provide_when_syntax", "./provide_on_syntax", "./provide_done_syntax"], function (require, exports, provide_when_on_syntax_1, provide_when_syntax_1, provide_on_syntax_1, provide_done_syntax_1) {

};
ProvideInSyntax.prototype.done = function () {
ProvideInSyntax.prototype.done = function (force) {
var binding = this._bindingInSyntax._binding;
var provideDoneSyntax = new provide_done_syntax_1.default(binding);
return provideDoneSyntax.done();
return provideDoneSyntax.done(force);
};

@@ -27,0 +27,0 @@ return ProvideInSyntax;

@@ -61,4 +61,4 @@ define(["require", "exports"], function (require, exports) {

};
ProvideInWhenOnSyntax.prototype.done = function () {
return this._provideInSyntax.done();
ProvideInWhenOnSyntax.prototype.done = function (force) {
return this._provideInSyntax.done(force);
};

@@ -65,0 +65,0 @@ return ProvideInWhenOnSyntax;

@@ -13,4 +13,4 @@ define(["require", "exports", "./provide_when_syntax"], function (require, exports, provide_when_syntax_1) {

};
ProvideOnSyntax.prototype.done = function () {
return this._provideDoneSyntax.done();
ProvideOnSyntax.prototype.done = function (force) {
return this._provideDoneSyntax.done(force);
};

@@ -17,0 +17,0 @@ return ProvideOnSyntax;

@@ -54,4 +54,4 @@ define(["require", "exports"], function (require, exports) {

};
ProvideWhenOnSyntax.prototype.done = function () {
return this._provideWhenSyntax.done();
ProvideWhenOnSyntax.prototype.done = function (force) {
return this._provideWhenSyntax.done(force);
};

@@ -58,0 +58,0 @@ return ProvideWhenOnSyntax;

@@ -65,4 +65,4 @@ define(["require", "exports", "./provide_on_syntax"], function (require, exports, provide_on_syntax_1) {

};
ProvideWhenSyntax.prototype.done = function () {
return this._provideDoneSyntax.done();
ProvideWhenSyntax.prototype.done = function (force) {
return this._provideDoneSyntax.done(force);
};

@@ -69,0 +69,0 @@ return ProvideWhenSyntax;

import { interfaces as inversifyInterfaces } from "inversify";
declare namespace interfaces {
interface ProvideDoneSyntax {
done(): (target: any) => any;
done(force?: boolean): (target: any) => any;
}

@@ -6,0 +6,0 @@ interface ProvideInSyntax<T> extends ProvideDoneSyntax {

@@ -6,4 +6,4 @@ import interfaces from "../interfaces/interfaces";

constructor(binding: inversifyInterfaces.Binding<T>);
done(): (target: any) => any;
done(force?: boolean): (target: any) => any;
}
export default ProvideDoneSyntax;

@@ -9,4 +9,4 @@ import interfaces from "../interfaces/interfaces";

inTransientScope(): interfaces.ProvideWhenOnSyntax<T>;
done(): (target: any) => any;
done(force?: boolean): (target: any) => any;
}
export default ProvideInSyntax;

@@ -25,4 +25,4 @@ import interfaces from "../interfaces/interfaces";

inTransientScope(): interfaces.ProvideWhenOnSyntax<T>;
done(): (target: any) => any;
done(force?: boolean): (target: any) => any;
}
export default ProvideInWhenOnSyntax;

@@ -8,4 +8,4 @@ import interfaces from "../interfaces/interfaces";

onActivation(fn: (context: inversifyInterfaces.Context, injectable: T) => T): interfaces.ProvideWhenSyntax<T>;
done(): (target: any) => any;
done(force?: boolean): (target: any) => any;
}
export default ProvideOnSyntax;

@@ -22,4 +22,4 @@ import interfaces from "../interfaces/interfaces";

onActivation(fn: (context: inversifyInterfaces.Context, injectable: T) => T): interfaces.ProvideWhenSyntax<T>;
done(): (target: any) => any;
done(force?: boolean): (target: any) => any;
}
export default ProvideWhenOnSyntax;

@@ -21,4 +21,4 @@ import interfaces from "../interfaces/interfaces";

whenNoAncestorMatches(constraint: (request: inversifyInterfaces.Request) => boolean): interfaces.ProvideOnSyntax<T>;
done(): (target: any) => any;
done(force?: boolean): (target: any) => any;
}
export default ProvideWhenSyntax;

@@ -19,3 +19,4 @@ import { decorate, injectable, METADATA_KEY } from "inversify";

catch (e) {
throw new Error(e.message + " " +
throw new Error("Cannot apply @provide decorator multiple times but is has been used " +
("multiple times in " + target.name + " ") +
"Please use @provide(ID, true) if you are trying to declare multiple bindings!");

@@ -22,0 +23,0 @@ }

import { decorate, injectable } from "inversify";
import { METADATA_KEY } from "inversify";
var ProvideDoneSyntax = /** @class */ (function () {

@@ -6,7 +7,24 @@ function ProvideDoneSyntax(binding) {

}
ProvideDoneSyntax.prototype.done = function () {
var _this = this;
ProvideDoneSyntax.prototype.done = function (force) {
var that = this;
return function (target) {
decorate(injectable(), target);
_this._binding.implementationType = target;
var isAlreadyDecorated = Reflect.hasOwnMetadata(METADATA_KEY.PARAM_TYPES, target);
var redecorateWithInject = force === true;
if (redecorateWithInject === true && isAlreadyDecorated === false) {
decorate(injectable(), target);
}
else if (redecorateWithInject === true && isAlreadyDecorated === true) {
// Do nothing
}
else {
try {
decorate(injectable(), target);
}
catch (e) {
throw new Error("Cannot apply @provideFluent decorator multiple times but is has been used " +
("multiple times in " + target.name + " ") +
"Please use @done(true) if you are trying to declare multiple bindings!");
}
}
that._binding.implementationType = target;
return target;

@@ -13,0 +31,0 @@ };

@@ -22,6 +22,6 @@ import ProvideWhenOnSyntax from "./provide_when_on_syntax";

};
ProvideInSyntax.prototype.done = function () {
ProvideInSyntax.prototype.done = function (force) {
var binding = this._bindingInSyntax._binding;
var provideDoneSyntax = new ProvideDoneSyntax(binding);
return provideDoneSyntax.done();
return provideDoneSyntax.done(force);
};

@@ -28,0 +28,0 @@ return ProvideInSyntax;

@@ -58,4 +58,4 @@ var ProvideInWhenOnSyntax = /** @class */ (function () {

};
ProvideInWhenOnSyntax.prototype.done = function () {
return this._provideInSyntax.done();
ProvideInWhenOnSyntax.prototype.done = function (force) {
return this._provideInSyntax.done(force);
};

@@ -62,0 +62,0 @@ return ProvideInWhenOnSyntax;

@@ -11,4 +11,4 @@ import ProvideWhenSyntax from "./provide_when_syntax";

};
ProvideOnSyntax.prototype.done = function () {
return this._provideDoneSyntax.done();
ProvideOnSyntax.prototype.done = function (force) {
return this._provideDoneSyntax.done(force);
};

@@ -15,0 +15,0 @@ return ProvideOnSyntax;

@@ -51,4 +51,4 @@ var ProvideWhenOnSyntax = /** @class */ (function () {

};
ProvideWhenOnSyntax.prototype.done = function () {
return this._provideWhenSyntax.done();
ProvideWhenOnSyntax.prototype.done = function (force) {
return this._provideWhenSyntax.done(force);
};

@@ -55,0 +55,0 @@ return ProvideWhenOnSyntax;

@@ -63,4 +63,4 @@ import ProvideOnSyntax from "./provide_on_syntax";

};
ProvideWhenSyntax.prototype.done = function () {
return this._provideDoneSyntax.done();
ProvideWhenSyntax.prototype.done = function (force) {
return this._provideDoneSyntax.done(force);
};

@@ -67,0 +67,0 @@ return ProvideWhenSyntax;

@@ -21,3 +21,4 @@ "use strict";

catch (e) {
throw new Error(e.message + " " +
throw new Error("Cannot apply @provide decorator multiple times but is has been used " +
("multiple times in " + target.name + " ") +
"Please use @provide(ID, true) if you are trying to declare multiple bindings!");

@@ -24,0 +25,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var inversify_1 = require("inversify");
var inversify_2 = require("inversify");
var ProvideDoneSyntax = /** @class */ (function () {

@@ -8,7 +9,24 @@ function ProvideDoneSyntax(binding) {

}
ProvideDoneSyntax.prototype.done = function () {
var _this = this;
ProvideDoneSyntax.prototype.done = function (force) {
var that = this;
return function (target) {
inversify_1.decorate(inversify_1.injectable(), target);
_this._binding.implementationType = target;
var isAlreadyDecorated = Reflect.hasOwnMetadata(inversify_2.METADATA_KEY.PARAM_TYPES, target);
var redecorateWithInject = force === true;
if (redecorateWithInject === true && isAlreadyDecorated === false) {
inversify_1.decorate(inversify_1.injectable(), target);
}
else if (redecorateWithInject === true && isAlreadyDecorated === true) {
// Do nothing
}
else {
try {
inversify_1.decorate(inversify_1.injectable(), target);
}
catch (e) {
throw new Error("Cannot apply @provideFluent decorator multiple times but is has been used " +
("multiple times in " + target.name + " ") +
"Please use @done(true) if you are trying to declare multiple bindings!");
}
}
that._binding.implementationType = target;
return target;

@@ -15,0 +33,0 @@ };

@@ -24,6 +24,6 @@ "use strict";

};
ProvideInSyntax.prototype.done = function () {
ProvideInSyntax.prototype.done = function (force) {
var binding = this._bindingInSyntax._binding;
var provideDoneSyntax = new provide_done_syntax_1.default(binding);
return provideDoneSyntax.done();
return provideDoneSyntax.done(force);
};

@@ -30,0 +30,0 @@ return ProvideInSyntax;

@@ -60,4 +60,4 @@ "use strict";

};
ProvideInWhenOnSyntax.prototype.done = function () {
return this._provideInSyntax.done();
ProvideInWhenOnSyntax.prototype.done = function (force) {
return this._provideInSyntax.done(force);
};

@@ -64,0 +64,0 @@ return ProvideInWhenOnSyntax;

@@ -13,4 +13,4 @@ "use strict";

};
ProvideOnSyntax.prototype.done = function () {
return this._provideDoneSyntax.done();
ProvideOnSyntax.prototype.done = function (force) {
return this._provideDoneSyntax.done(force);
};

@@ -17,0 +17,0 @@ return ProvideOnSyntax;

@@ -53,4 +53,4 @@ "use strict";

};
ProvideWhenOnSyntax.prototype.done = function () {
return this._provideWhenSyntax.done();
ProvideWhenOnSyntax.prototype.done = function (force) {
return this._provideWhenSyntax.done(force);
};

@@ -57,0 +57,0 @@ return ProvideWhenOnSyntax;

@@ -65,4 +65,4 @@ "use strict";

};
ProvideWhenSyntax.prototype.done = function () {
return this._provideDoneSyntax.done();
ProvideWhenSyntax.prototype.done = function (force) {
return this._provideDoneSyntax.done(force);
};

@@ -69,0 +69,0 @@ return ProvideWhenSyntax;

{
"name": "inversify-binding-decorators",
"version": "3.1.0",
"version": "3.2.0",
"description": "An utility that allows developers to declare InversifyJS bindings using ES2016 decorators",

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

@@ -299,2 +299,51 @@ # inversify-binding-decorators

### Using @provideFluent multiple times
If you try to apply `@provideFluent` multiple times:
```ts
let container = new Container();
let provideFluent = fluentProvide(container);
const provideSingleton = (identifier: any) => {
return provideFluent(identifier)
.inSingletonScope()
.done();
};
function shouldThrow() {
@provideSingleton("Ninja")
@provideSingleton("SilentNinja")
class Ninja {}
return Ninja;
}
```
The library will throw an exception:
> Cannot apply @provideFluent decorator multiple times but is has been used multiple times in Ninja Please use @done(true) if you are trying to declare multiple bindings!
We throw an exception to ensure that you are are not trying to apply `@fluentProvide` multiple times by mistake.
You can overcome this by passing the `force` argument to `done()`:
```ts
let container = new Container();
let provideFluent = fluentProvide(container);
const provideSingleton = (identifier: any) => {
return provideFluent(identifier)
.inSingletonScope()
.done(true); // IMPORTANT!
};
function shouldThrow() {
@provideSingleton("Ninja")
@provideSingleton("SilentNinja")
class Ninja {}
return Ninja;
}
```
## The auto provide utility

@@ -301,0 +350,0 @@ This library includes a small utility apply to add the default `@provide` decorator to all

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