summaryrefslogtreecommitdiff
path: root/src/node_modules/inversify/lib/container
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
committerMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
commit46e43f4bde4a35785b4997b81e86cd19f046b69b (patch)
treec53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/inversify/lib/container
downloadlangdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip
Commit
Diffstat (limited to 'src/node_modules/inversify/lib/container')
-rw-r--r--src/node_modules/inversify/lib/container/container.js325
-rw-r--r--src/node_modules/inversify/lib/container/container_module.js19
-rw-r--r--src/node_modules/inversify/lib/container/container_snapshot.js14
-rw-r--r--src/node_modules/inversify/lib/container/lookup.js79
4 files changed, 437 insertions, 0 deletions
diff --git a/src/node_modules/inversify/lib/container/container.js b/src/node_modules/inversify/lib/container/container.js
new file mode 100644
index 0000000..83d372e
--- /dev/null
+++ b/src/node_modules/inversify/lib/container/container.js
@@ -0,0 +1,325 @@
+"use strict";
+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
+ return new (P || (P = Promise))(function (resolve, reject) {
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+var __generator = (this && this.__generator) || function (thisArg, body) {
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
+ function verb(n) { return function (v) { return step([n, v]); }; }
+ function step(op) {
+ if (f) throw new TypeError("Generator is already executing.");
+ while (_) try {
+ if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
+ if (y = 0, t) op = [0, t.value];
+ switch (op[0]) {
+ case 0: case 1: t = op; break;
+ case 4: _.label++; return { value: op[1], done: false };
+ case 5: _.label++; y = op[1]; op = [0]; continue;
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
+ default:
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
+ if (t[2]) _.ops.pop();
+ _.trys.pop(); continue;
+ }
+ op = body.call(thisArg, _);
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
+ }
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+var binding_1 = require("../bindings/binding");
+var ERROR_MSGS = require("../constants/error_msgs");
+var literal_types_1 = require("../constants/literal_types");
+var METADATA_KEY = require("../constants/metadata_keys");
+var metadata_reader_1 = require("../planning/metadata_reader");
+var planner_1 = require("../planning/planner");
+var resolver_1 = require("../resolution/resolver");
+var binding_to_syntax_1 = require("../syntax/binding_to_syntax");
+var id_1 = require("../utils/id");
+var serialization_1 = require("../utils/serialization");
+var container_snapshot_1 = require("./container_snapshot");
+var lookup_1 = require("./lookup");
+var Container = (function () {
+ function Container(containerOptions) {
+ var options = containerOptions || {};
+ if (typeof options !== "object") {
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
+ }
+ if (options.defaultScope === undefined) {
+ options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
+ }
+ else if (options.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
+ options.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
+ options.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
+ }
+ if (options.autoBindInjectable === undefined) {
+ options.autoBindInjectable = false;
+ }
+ else if (typeof options.autoBindInjectable !== "boolean") {
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
+ }
+ if (options.skipBaseClassChecks === undefined) {
+ options.skipBaseClassChecks = false;
+ }
+ else if (typeof options.skipBaseClassChecks !== "boolean") {
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
+ }
+ this.options = {
+ autoBindInjectable: options.autoBindInjectable,
+ defaultScope: options.defaultScope,
+ skipBaseClassChecks: options.skipBaseClassChecks
+ };
+ this.id = id_1.id();
+ this._bindingDictionary = new lookup_1.Lookup();
+ this._snapshots = [];
+ this._middleware = null;
+ this.parent = null;
+ this._metadataReader = new metadata_reader_1.MetadataReader();
+ }
+ Container.merge = function (container1, container2) {
+ var container = new Container();
+ var bindingDictionary = planner_1.getBindingDictionary(container);
+ var bindingDictionary1 = planner_1.getBindingDictionary(container1);
+ var bindingDictionary2 = planner_1.getBindingDictionary(container2);
+ function copyDictionary(origin, destination) {
+ origin.traverse(function (key, value) {
+ value.forEach(function (binding) {
+ destination.add(binding.serviceIdentifier, binding.clone());
+ });
+ });
+ }
+ copyDictionary(bindingDictionary1, bindingDictionary);
+ copyDictionary(bindingDictionary2, bindingDictionary);
+ return container;
+ };
+ Container.prototype.load = function () {
+ var modules = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ modules[_i] = arguments[_i];
+ }
+ var getHelpers = this._getContainerModuleHelpersFactory();
+ for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
+ var currentModule = modules_1[_a];
+ var containerModuleHelpers = getHelpers(currentModule.id);
+ currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
+ }
+ };
+ Container.prototype.loadAsync = function () {
+ var modules = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ modules[_i] = arguments[_i];
+ }
+ return __awaiter(this, void 0, void 0, function () {
+ var getHelpers, _a, modules_2, currentModule, containerModuleHelpers;
+ return __generator(this, function (_b) {
+ switch (_b.label) {
+ case 0:
+ getHelpers = this._getContainerModuleHelpersFactory();
+ _a = 0, modules_2 = modules;
+ _b.label = 1;
+ case 1:
+ if (!(_a < modules_2.length)) return [3, 4];
+ currentModule = modules_2[_a];
+ containerModuleHelpers = getHelpers(currentModule.id);
+ return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
+ case 2:
+ _b.sent();
+ _b.label = 3;
+ case 3:
+ _a++;
+ return [3, 1];
+ case 4: return [2];
+ }
+ });
+ });
+ };
+ Container.prototype.unload = function () {
+ var _this = this;
+ var modules = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ modules[_i] = arguments[_i];
+ }
+ var conditionFactory = function (expected) { return function (item) {
+ return item.moduleId === expected;
+ }; };
+ modules.forEach(function (module) {
+ var condition = conditionFactory(module.id);
+ _this._bindingDictionary.removeByCondition(condition);
+ });
+ };
+ Container.prototype.bind = function (serviceIdentifier) {
+ var scope = this.options.defaultScope || literal_types_1.BindingScopeEnum.Transient;
+ var binding = new binding_1.Binding(serviceIdentifier, scope);
+ this._bindingDictionary.add(serviceIdentifier, binding);
+ return new binding_to_syntax_1.BindingToSyntax(binding);
+ };
+ Container.prototype.rebind = function (serviceIdentifier) {
+ this.unbind(serviceIdentifier);
+ return this.bind(serviceIdentifier);
+ };
+ Container.prototype.unbind = function (serviceIdentifier) {
+ try {
+ this._bindingDictionary.remove(serviceIdentifier);
+ }
+ catch (e) {
+ throw new Error(ERROR_MSGS.CANNOT_UNBIND + " " + serialization_1.getServiceIdentifierAsString(serviceIdentifier));
+ }
+ };
+ Container.prototype.unbindAll = function () {
+ this._bindingDictionary = new lookup_1.Lookup();
+ };
+ Container.prototype.isBound = function (serviceIdentifier) {
+ var bound = this._bindingDictionary.hasKey(serviceIdentifier);
+ if (!bound && this.parent) {
+ bound = this.parent.isBound(serviceIdentifier);
+ }
+ return bound;
+ };
+ Container.prototype.isBoundNamed = function (serviceIdentifier, named) {
+ return this.isBoundTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
+ };
+ Container.prototype.isBoundTagged = function (serviceIdentifier, key, value) {
+ var bound = false;
+ if (this._bindingDictionary.hasKey(serviceIdentifier)) {
+ var bindings = this._bindingDictionary.get(serviceIdentifier);
+ var request_1 = planner_1.createMockRequest(this, serviceIdentifier, key, value);
+ bound = bindings.some(function (b) { return b.constraint(request_1); });
+ }
+ if (!bound && this.parent) {
+ bound = this.parent.isBoundTagged(serviceIdentifier, key, value);
+ }
+ return bound;
+ };
+ Container.prototype.snapshot = function () {
+ this._snapshots.push(container_snapshot_1.ContainerSnapshot.of(this._bindingDictionary.clone(), this._middleware));
+ };
+ Container.prototype.restore = function () {
+ var snapshot = this._snapshots.pop();
+ if (snapshot === undefined) {
+ throw new Error(ERROR_MSGS.NO_MORE_SNAPSHOTS_AVAILABLE);
+ }
+ this._bindingDictionary = snapshot.bindings;
+ this._middleware = snapshot.middleware;
+ };
+ Container.prototype.createChild = function (containerOptions) {
+ var child = new Container(containerOptions || this.options);
+ child.parent = this;
+ return child;
+ };
+ Container.prototype.applyMiddleware = function () {
+ var middlewares = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ middlewares[_i] = arguments[_i];
+ }
+ var initial = (this._middleware) ? this._middleware : this._planAndResolve();
+ this._middleware = middlewares.reduce(function (prev, curr) { return curr(prev); }, initial);
+ };
+ Container.prototype.applyCustomMetadataReader = function (metadataReader) {
+ this._metadataReader = metadataReader;
+ };
+ Container.prototype.get = function (serviceIdentifier) {
+ return this._get(false, false, literal_types_1.TargetTypeEnum.Variable, serviceIdentifier);
+ };
+ Container.prototype.getTagged = function (serviceIdentifier, key, value) {
+ return this._get(false, false, literal_types_1.TargetTypeEnum.Variable, serviceIdentifier, key, value);
+ };
+ Container.prototype.getNamed = function (serviceIdentifier, named) {
+ return this.getTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
+ };
+ Container.prototype.getAll = function (serviceIdentifier) {
+ return this._get(true, true, literal_types_1.TargetTypeEnum.Variable, serviceIdentifier);
+ };
+ Container.prototype.getAllTagged = function (serviceIdentifier, key, value) {
+ return this._get(false, true, literal_types_1.TargetTypeEnum.Variable, serviceIdentifier, key, value);
+ };
+ Container.prototype.getAllNamed = function (serviceIdentifier, named) {
+ return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
+ };
+ Container.prototype.resolve = function (constructorFunction) {
+ var tempContainer = this.createChild();
+ tempContainer.bind(constructorFunction).toSelf();
+ return tempContainer.get(constructorFunction);
+ };
+ Container.prototype._getContainerModuleHelpersFactory = function () {
+ var _this = this;
+ var setModuleId = function (bindingToSyntax, moduleId) {
+ bindingToSyntax._binding.moduleId = moduleId;
+ };
+ var getBindFunction = function (moduleId) {
+ return function (serviceIdentifier) {
+ var _bind = _this.bind.bind(_this);
+ var bindingToSyntax = _bind(serviceIdentifier);
+ setModuleId(bindingToSyntax, moduleId);
+ return bindingToSyntax;
+ };
+ };
+ var getUnbindFunction = function (moduleId) {
+ return function (serviceIdentifier) {
+ var _unbind = _this.unbind.bind(_this);
+ _unbind(serviceIdentifier);
+ };
+ };
+ var getIsboundFunction = function (moduleId) {
+ return function (serviceIdentifier) {
+ var _isBound = _this.isBound.bind(_this);
+ return _isBound(serviceIdentifier);
+ };
+ };
+ var getRebindFunction = function (moduleId) {
+ return function (serviceIdentifier) {
+ var _rebind = _this.rebind.bind(_this);
+ var bindingToSyntax = _rebind(serviceIdentifier);
+ setModuleId(bindingToSyntax, moduleId);
+ return bindingToSyntax;
+ };
+ };
+ return function (mId) { return ({
+ bindFunction: getBindFunction(mId),
+ isboundFunction: getIsboundFunction(mId),
+ rebindFunction: getRebindFunction(mId),
+ unbindFunction: getUnbindFunction(mId)
+ }); };
+ };
+ Container.prototype._get = function (avoidConstraints, isMultiInject, targetType, serviceIdentifier, key, value) {
+ var result = null;
+ var defaultArgs = {
+ avoidConstraints: avoidConstraints,
+ contextInterceptor: function (context) { return context; },
+ isMultiInject: isMultiInject,
+ key: key,
+ serviceIdentifier: serviceIdentifier,
+ targetType: targetType,
+ value: value
+ };
+ if (this._middleware) {
+ result = this._middleware(defaultArgs);
+ if (result === undefined || result === null) {
+ throw new Error(ERROR_MSGS.INVALID_MIDDLEWARE_RETURN);
+ }
+ }
+ else {
+ result = this._planAndResolve()(defaultArgs);
+ }
+ return result;
+ };
+ Container.prototype._planAndResolve = function () {
+ var _this = this;
+ return function (args) {
+ var context = planner_1.plan(_this._metadataReader, _this, args.isMultiInject, args.targetType, args.serviceIdentifier, args.key, args.value, args.avoidConstraints);
+ context = args.contextInterceptor(context);
+ var result = resolver_1.resolve(context);
+ return result;
+ };
+ };
+ return Container;
+}());
+exports.Container = Container;
diff --git a/src/node_modules/inversify/lib/container/container_module.js b/src/node_modules/inversify/lib/container/container_module.js
new file mode 100644
index 0000000..64d3f84
--- /dev/null
+++ b/src/node_modules/inversify/lib/container/container_module.js
@@ -0,0 +1,19 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+var id_1 = require("../utils/id");
+var ContainerModule = (function () {
+ function ContainerModule(registry) {
+ this.id = id_1.id();
+ this.registry = registry;
+ }
+ return ContainerModule;
+}());
+exports.ContainerModule = ContainerModule;
+var AsyncContainerModule = (function () {
+ function AsyncContainerModule(registry) {
+ this.id = id_1.id();
+ this.registry = registry;
+ }
+ return AsyncContainerModule;
+}());
+exports.AsyncContainerModule = AsyncContainerModule;
diff --git a/src/node_modules/inversify/lib/container/container_snapshot.js b/src/node_modules/inversify/lib/container/container_snapshot.js
new file mode 100644
index 0000000..eef2b5e
--- /dev/null
+++ b/src/node_modules/inversify/lib/container/container_snapshot.js
@@ -0,0 +1,14 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+var ContainerSnapshot = (function () {
+ function ContainerSnapshot() {
+ }
+ ContainerSnapshot.of = function (bindings, middleware) {
+ var snapshot = new ContainerSnapshot();
+ snapshot.bindings = bindings;
+ snapshot.middleware = middleware;
+ return snapshot;
+ };
+ return ContainerSnapshot;
+}());
+exports.ContainerSnapshot = ContainerSnapshot;
diff --git a/src/node_modules/inversify/lib/container/lookup.js b/src/node_modules/inversify/lib/container/lookup.js
new file mode 100644
index 0000000..912504d
--- /dev/null
+++ b/src/node_modules/inversify/lib/container/lookup.js
@@ -0,0 +1,79 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+var ERROR_MSGS = require("../constants/error_msgs");
+var Lookup = (function () {
+ function Lookup() {
+ this._map = new Map();
+ }
+ Lookup.prototype.getMap = function () {
+ return this._map;
+ };
+ Lookup.prototype.add = function (serviceIdentifier, value) {
+ if (serviceIdentifier === null || serviceIdentifier === undefined) {
+ throw new Error(ERROR_MSGS.NULL_ARGUMENT);
+ }
+ if (value === null || value === undefined) {
+ throw new Error(ERROR_MSGS.NULL_ARGUMENT);
+ }
+ var entry = this._map.get(serviceIdentifier);
+ if (entry !== undefined) {
+ entry.push(value);
+ this._map.set(serviceIdentifier, entry);
+ }
+ else {
+ this._map.set(serviceIdentifier, [value]);
+ }
+ };
+ Lookup.prototype.get = function (serviceIdentifier) {
+ if (serviceIdentifier === null || serviceIdentifier === undefined) {
+ throw new Error(ERROR_MSGS.NULL_ARGUMENT);
+ }
+ var entry = this._map.get(serviceIdentifier);
+ if (entry !== undefined) {
+ return entry;
+ }
+ else {
+ throw new Error(ERROR_MSGS.KEY_NOT_FOUND);
+ }
+ };
+ Lookup.prototype.remove = function (serviceIdentifier) {
+ if (serviceIdentifier === null || serviceIdentifier === undefined) {
+ throw new Error(ERROR_MSGS.NULL_ARGUMENT);
+ }
+ if (!this._map.delete(serviceIdentifier)) {
+ throw new Error(ERROR_MSGS.KEY_NOT_FOUND);
+ }
+ };
+ Lookup.prototype.removeByCondition = function (condition) {
+ var _this = this;
+ this._map.forEach(function (entries, key) {
+ var updatedEntries = entries.filter(function (entry) { return !condition(entry); });
+ if (updatedEntries.length > 0) {
+ _this._map.set(key, updatedEntries);
+ }
+ else {
+ _this._map.delete(key);
+ }
+ });
+ };
+ Lookup.prototype.hasKey = function (serviceIdentifier) {
+ if (serviceIdentifier === null || serviceIdentifier === undefined) {
+ throw new Error(ERROR_MSGS.NULL_ARGUMENT);
+ }
+ return this._map.has(serviceIdentifier);
+ };
+ Lookup.prototype.clone = function () {
+ var copy = new Lookup();
+ this._map.forEach(function (value, key) {
+ value.forEach(function (b) { return copy.add(key, b.clone()); });
+ });
+ return copy;
+ };
+ Lookup.prototype.traverse = function (func) {
+ this._map.forEach(function (value, key) {
+ func(key, value);
+ });
+ };
+ return Lookup;
+}());
+exports.Lookup = Lookup;