diff options
Diffstat (limited to 'src/node_modules/inversify/lib/syntax')
7 files changed, 381 insertions, 0 deletions
diff --git a/src/node_modules/inversify/lib/syntax/binding_in_syntax.js b/src/node_modules/inversify/lib/syntax/binding_in_syntax.js new file mode 100644 index 0000000..8494e36 --- /dev/null +++ b/src/node_modules/inversify/lib/syntax/binding_in_syntax.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var literal_types_1 = require("../constants/literal_types"); +var binding_when_on_syntax_1 = require("./binding_when_on_syntax"); +var BindingInSyntax = (function () { + function BindingInSyntax(binding) { + this._binding = binding; + } + BindingInSyntax.prototype.inRequestScope = function () { + this._binding.scope = literal_types_1.BindingScopeEnum.Request; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingInSyntax.prototype.inSingletonScope = function () { + this._binding.scope = literal_types_1.BindingScopeEnum.Singleton; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingInSyntax.prototype.inTransientScope = function () { + this._binding.scope = literal_types_1.BindingScopeEnum.Transient; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + return BindingInSyntax; +}()); +exports.BindingInSyntax = BindingInSyntax; diff --git a/src/node_modules/inversify/lib/syntax/binding_in_when_on_syntax.js b/src/node_modules/inversify/lib/syntax/binding_in_when_on_syntax.js new file mode 100644 index 0000000..fba0d06 --- /dev/null +++ b/src/node_modules/inversify/lib/syntax/binding_in_when_on_syntax.js @@ -0,0 +1,72 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var binding_in_syntax_1 = require("./binding_in_syntax"); +var binding_on_syntax_1 = require("./binding_on_syntax"); +var binding_when_syntax_1 = require("./binding_when_syntax"); +var BindingInWhenOnSyntax = (function () { + function BindingInWhenOnSyntax(binding) { + this._binding = binding; + this._bindingWhenSyntax = new binding_when_syntax_1.BindingWhenSyntax(this._binding); + this._bindingOnSyntax = new binding_on_syntax_1.BindingOnSyntax(this._binding); + this._bindingInSyntax = new binding_in_syntax_1.BindingInSyntax(binding); + } + BindingInWhenOnSyntax.prototype.inRequestScope = function () { + return this._bindingInSyntax.inRequestScope(); + }; + BindingInWhenOnSyntax.prototype.inSingletonScope = function () { + return this._bindingInSyntax.inSingletonScope(); + }; + BindingInWhenOnSyntax.prototype.inTransientScope = function () { + return this._bindingInSyntax.inTransientScope(); + }; + BindingInWhenOnSyntax.prototype.when = function (constraint) { + return this._bindingWhenSyntax.when(constraint); + }; + BindingInWhenOnSyntax.prototype.whenTargetNamed = function (name) { + return this._bindingWhenSyntax.whenTargetNamed(name); + }; + BindingInWhenOnSyntax.prototype.whenTargetIsDefault = function () { + return this._bindingWhenSyntax.whenTargetIsDefault(); + }; + BindingInWhenOnSyntax.prototype.whenTargetTagged = function (tag, value) { + return this._bindingWhenSyntax.whenTargetTagged(tag, value); + }; + BindingInWhenOnSyntax.prototype.whenInjectedInto = function (parent) { + return this._bindingWhenSyntax.whenInjectedInto(parent); + }; + BindingInWhenOnSyntax.prototype.whenParentNamed = function (name) { + return this._bindingWhenSyntax.whenParentNamed(name); + }; + BindingInWhenOnSyntax.prototype.whenParentTagged = function (tag, value) { + return this._bindingWhenSyntax.whenParentTagged(tag, value); + }; + BindingInWhenOnSyntax.prototype.whenAnyAncestorIs = function (ancestor) { + return this._bindingWhenSyntax.whenAnyAncestorIs(ancestor); + }; + BindingInWhenOnSyntax.prototype.whenNoAncestorIs = function (ancestor) { + return this._bindingWhenSyntax.whenNoAncestorIs(ancestor); + }; + BindingInWhenOnSyntax.prototype.whenAnyAncestorNamed = function (name) { + return this._bindingWhenSyntax.whenAnyAncestorNamed(name); + }; + BindingInWhenOnSyntax.prototype.whenAnyAncestorTagged = function (tag, value) { + return this._bindingWhenSyntax.whenAnyAncestorTagged(tag, value); + }; + BindingInWhenOnSyntax.prototype.whenNoAncestorNamed = function (name) { + return this._bindingWhenSyntax.whenNoAncestorNamed(name); + }; + BindingInWhenOnSyntax.prototype.whenNoAncestorTagged = function (tag, value) { + return this._bindingWhenSyntax.whenNoAncestorTagged(tag, value); + }; + BindingInWhenOnSyntax.prototype.whenAnyAncestorMatches = function (constraint) { + return this._bindingWhenSyntax.whenAnyAncestorMatches(constraint); + }; + BindingInWhenOnSyntax.prototype.whenNoAncestorMatches = function (constraint) { + return this._bindingWhenSyntax.whenNoAncestorMatches(constraint); + }; + BindingInWhenOnSyntax.prototype.onActivation = function (handler) { + return this._bindingOnSyntax.onActivation(handler); + }; + return BindingInWhenOnSyntax; +}()); +exports.BindingInWhenOnSyntax = BindingInWhenOnSyntax; diff --git a/src/node_modules/inversify/lib/syntax/binding_on_syntax.js b/src/node_modules/inversify/lib/syntax/binding_on_syntax.js new file mode 100644 index 0000000..d47728d --- /dev/null +++ b/src/node_modules/inversify/lib/syntax/binding_on_syntax.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var binding_when_syntax_1 = require("./binding_when_syntax"); +var BindingOnSyntax = (function () { + function BindingOnSyntax(binding) { + this._binding = binding; + } + BindingOnSyntax.prototype.onActivation = function (handler) { + this._binding.onActivation = handler; + return new binding_when_syntax_1.BindingWhenSyntax(this._binding); + }; + return BindingOnSyntax; +}()); +exports.BindingOnSyntax = BindingOnSyntax; diff --git a/src/node_modules/inversify/lib/syntax/binding_to_syntax.js b/src/node_modules/inversify/lib/syntax/binding_to_syntax.js new file mode 100644 index 0000000..fd00a74 --- /dev/null +++ b/src/node_modules/inversify/lib/syntax/binding_to_syntax.js @@ -0,0 +1,73 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var ERROR_MSGS = require("../constants/error_msgs"); +var literal_types_1 = require("../constants/literal_types"); +var binding_in_when_on_syntax_1 = require("./binding_in_when_on_syntax"); +var binding_when_on_syntax_1 = require("./binding_when_on_syntax"); +var BindingToSyntax = (function () { + function BindingToSyntax(binding) { + this._binding = binding; + } + BindingToSyntax.prototype.to = function (constructor) { + this._binding.type = literal_types_1.BindingTypeEnum.Instance; + this._binding.implementationType = constructor; + return new binding_in_when_on_syntax_1.BindingInWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toSelf = function () { + if (typeof this._binding.serviceIdentifier !== "function") { + throw new Error("" + ERROR_MSGS.INVALID_TO_SELF_VALUE); + } + var self = this._binding.serviceIdentifier; + return this.to(self); + }; + BindingToSyntax.prototype.toConstantValue = function (value) { + this._binding.type = literal_types_1.BindingTypeEnum.ConstantValue; + this._binding.cache = value; + this._binding.dynamicValue = null; + this._binding.implementationType = null; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toDynamicValue = function (func) { + this._binding.type = literal_types_1.BindingTypeEnum.DynamicValue; + this._binding.cache = null; + this._binding.dynamicValue = func; + this._binding.implementationType = null; + return new binding_in_when_on_syntax_1.BindingInWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toConstructor = function (constructor) { + this._binding.type = literal_types_1.BindingTypeEnum.Constructor; + this._binding.implementationType = constructor; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toFactory = function (factory) { + this._binding.type = literal_types_1.BindingTypeEnum.Factory; + this._binding.factory = factory; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toFunction = function (func) { + if (typeof func !== "function") { + throw new Error(ERROR_MSGS.INVALID_FUNCTION_BINDING); + } + var bindingWhenOnSyntax = this.toConstantValue(func); + this._binding.type = literal_types_1.BindingTypeEnum.Function; + return bindingWhenOnSyntax; + }; + BindingToSyntax.prototype.toAutoFactory = function (serviceIdentifier) { + this._binding.type = literal_types_1.BindingTypeEnum.Factory; + this._binding.factory = function (context) { + var autofactory = function () { return context.container.get(serviceIdentifier); }; + return autofactory; + }; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toProvider = function (provider) { + this._binding.type = literal_types_1.BindingTypeEnum.Provider; + this._binding.provider = provider; + return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding); + }; + BindingToSyntax.prototype.toService = function (service) { + this.toDynamicValue(function (context) { return context.container.get(service); }); + }; + return BindingToSyntax; +}()); +exports.BindingToSyntax = BindingToSyntax; diff --git a/src/node_modules/inversify/lib/syntax/binding_when_on_syntax.js b/src/node_modules/inversify/lib/syntax/binding_when_on_syntax.js new file mode 100644 index 0000000..ea690ee --- /dev/null +++ b/src/node_modules/inversify/lib/syntax/binding_when_on_syntax.js @@ -0,0 +1,61 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var binding_on_syntax_1 = require("./binding_on_syntax"); +var binding_when_syntax_1 = require("./binding_when_syntax"); +var BindingWhenOnSyntax = (function () { + function BindingWhenOnSyntax(binding) { + this._binding = binding; + this._bindingWhenSyntax = new binding_when_syntax_1.BindingWhenSyntax(this._binding); + this._bindingOnSyntax = new binding_on_syntax_1.BindingOnSyntax(this._binding); + } + BindingWhenOnSyntax.prototype.when = function (constraint) { + return this._bindingWhenSyntax.when(constraint); + }; + BindingWhenOnSyntax.prototype.whenTargetNamed = function (name) { + return this._bindingWhenSyntax.whenTargetNamed(name); + }; + BindingWhenOnSyntax.prototype.whenTargetIsDefault = function () { + return this._bindingWhenSyntax.whenTargetIsDefault(); + }; + BindingWhenOnSyntax.prototype.whenTargetTagged = function (tag, value) { + return this._bindingWhenSyntax.whenTargetTagged(tag, value); + }; + BindingWhenOnSyntax.prototype.whenInjectedInto = function (parent) { + return this._bindingWhenSyntax.whenInjectedInto(parent); + }; + BindingWhenOnSyntax.prototype.whenParentNamed = function (name) { + return this._bindingWhenSyntax.whenParentNamed(name); + }; + BindingWhenOnSyntax.prototype.whenParentTagged = function (tag, value) { + return this._bindingWhenSyntax.whenParentTagged(tag, value); + }; + BindingWhenOnSyntax.prototype.whenAnyAncestorIs = function (ancestor) { + return this._bindingWhenSyntax.whenAnyAncestorIs(ancestor); + }; + BindingWhenOnSyntax.prototype.whenNoAncestorIs = function (ancestor) { + return this._bindingWhenSyntax.whenNoAncestorIs(ancestor); + }; + BindingWhenOnSyntax.prototype.whenAnyAncestorNamed = function (name) { + return this._bindingWhenSyntax.whenAnyAncestorNamed(name); + }; + BindingWhenOnSyntax.prototype.whenAnyAncestorTagged = function (tag, value) { + return this._bindingWhenSyntax.whenAnyAncestorTagged(tag, value); + }; + BindingWhenOnSyntax.prototype.whenNoAncestorNamed = function (name) { + return this._bindingWhenSyntax.whenNoAncestorNamed(name); + }; + BindingWhenOnSyntax.prototype.whenNoAncestorTagged = function (tag, value) { + return this._bindingWhenSyntax.whenNoAncestorTagged(tag, value); + }; + BindingWhenOnSyntax.prototype.whenAnyAncestorMatches = function (constraint) { + return this._bindingWhenSyntax.whenAnyAncestorMatches(constraint); + }; + BindingWhenOnSyntax.prototype.whenNoAncestorMatches = function (constraint) { + return this._bindingWhenSyntax.whenNoAncestorMatches(constraint); + }; + BindingWhenOnSyntax.prototype.onActivation = function (handler) { + return this._bindingOnSyntax.onActivation(handler); + }; + return BindingWhenOnSyntax; +}()); +exports.BindingWhenOnSyntax = BindingWhenOnSyntax; diff --git a/src/node_modules/inversify/lib/syntax/binding_when_syntax.js b/src/node_modules/inversify/lib/syntax/binding_when_syntax.js new file mode 100644 index 0000000..75bbcff --- /dev/null +++ b/src/node_modules/inversify/lib/syntax/binding_when_syntax.js @@ -0,0 +1,98 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var binding_on_syntax_1 = require("./binding_on_syntax"); +var constraint_helpers_1 = require("./constraint_helpers"); +var BindingWhenSyntax = (function () { + function BindingWhenSyntax(binding) { + this._binding = binding; + } + BindingWhenSyntax.prototype.when = function (constraint) { + this._binding.constraint = constraint; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenTargetNamed = function (name) { + this._binding.constraint = constraint_helpers_1.namedConstraint(name); + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenTargetIsDefault = function () { + this._binding.constraint = function (request) { + var targetIsDefault = (request.target !== null) && + (!request.target.isNamed()) && + (!request.target.isTagged()); + return targetIsDefault; + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenTargetTagged = function (tag, value) { + this._binding.constraint = constraint_helpers_1.taggedConstraint(tag)(value); + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenInjectedInto = function (parent) { + this._binding.constraint = function (request) { + return constraint_helpers_1.typeConstraint(parent)(request.parentRequest); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenParentNamed = function (name) { + this._binding.constraint = function (request) { + return constraint_helpers_1.namedConstraint(name)(request.parentRequest); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenParentTagged = function (tag, value) { + this._binding.constraint = function (request) { + return constraint_helpers_1.taggedConstraint(tag)(value)(request.parentRequest); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenAnyAncestorIs = function (ancestor) { + this._binding.constraint = function (request) { + return constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.typeConstraint(ancestor)); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenNoAncestorIs = function (ancestor) { + this._binding.constraint = function (request) { + return !constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.typeConstraint(ancestor)); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenAnyAncestorNamed = function (name) { + this._binding.constraint = function (request) { + return constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.namedConstraint(name)); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenNoAncestorNamed = function (name) { + this._binding.constraint = function (request) { + return !constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.namedConstraint(name)); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenAnyAncestorTagged = function (tag, value) { + this._binding.constraint = function (request) { + return constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.taggedConstraint(tag)(value)); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenNoAncestorTagged = function (tag, value) { + this._binding.constraint = function (request) { + return !constraint_helpers_1.traverseAncerstors(request, constraint_helpers_1.taggedConstraint(tag)(value)); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenAnyAncestorMatches = function (constraint) { + this._binding.constraint = function (request) { + return constraint_helpers_1.traverseAncerstors(request, constraint); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + BindingWhenSyntax.prototype.whenNoAncestorMatches = function (constraint) { + this._binding.constraint = function (request) { + return !constraint_helpers_1.traverseAncerstors(request, constraint); + }; + return new binding_on_syntax_1.BindingOnSyntax(this._binding); + }; + return BindingWhenSyntax; +}()); +exports.BindingWhenSyntax = BindingWhenSyntax; diff --git a/src/node_modules/inversify/lib/syntax/constraint_helpers.js b/src/node_modules/inversify/lib/syntax/constraint_helpers.js new file mode 100644 index 0000000..8b04e0f --- /dev/null +++ b/src/node_modules/inversify/lib/syntax/constraint_helpers.js @@ -0,0 +1,40 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var METADATA_KEY = require("../constants/metadata_keys"); +var metadata_1 = require("../planning/metadata"); +var traverseAncerstors = function (request, constraint) { + var parent = request.parentRequest; + if (parent !== null) { + return constraint(parent) ? true : traverseAncerstors(parent, constraint); + } + else { + return false; + } +}; +exports.traverseAncerstors = traverseAncerstors; +var taggedConstraint = function (key) { return function (value) { + var constraint = function (request) { + return request !== null && request.target !== null && request.target.matchesTag(key)(value); + }; + constraint.metaData = new metadata_1.Metadata(key, value); + return constraint; +}; }; +exports.taggedConstraint = taggedConstraint; +var namedConstraint = taggedConstraint(METADATA_KEY.NAMED_TAG); +exports.namedConstraint = namedConstraint; +var typeConstraint = function (type) { return function (request) { + var binding = null; + if (request !== null) { + binding = request.bindings[0]; + if (typeof type === "string") { + var serviceIdentifier = binding.serviceIdentifier; + return serviceIdentifier === type; + } + else { + var constructor = request.bindings[0].implementationType; + return type === constructor; + } + } + return false; +}; }; +exports.typeConstraint = typeConstraint; |