ditox 1.4.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{index.d.ts → browser/index.d.ts} +0 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/cjs/ditox.d.ts +125 -0
- package/dist/cjs/ditox.js +210 -0
- package/dist/cjs/ditox.js.map +1 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/modules.d.ts +124 -0
- package/dist/cjs/modules.js +110 -0
- package/dist/cjs/modules.js.map +1 -0
- package/{src/utils.js.flow → dist/cjs/utils.d.ts} +21 -60
- package/dist/cjs/utils.js +98 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/ditox.d.ts +125 -0
- package/{lib/index.js → dist/esm/ditox.js} +10 -201
- package/dist/esm/ditox.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/modules.d.ts +124 -0
- package/dist/esm/modules.js +103 -0
- package/dist/esm/modules.js.map +1 -0
- package/dist/esm/utils.d.ts +74 -0
- package/dist/esm/utils.js +88 -0
- package/dist/esm/utils.js.map +1 -0
- package/{lib → dist/umd}/index.d.ts +0 -0
- package/dist/umd/index.js +2 -0
- package/dist/umd/index.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/README.md +111 -96
- package/docs/classes/{resolvererror.md → ResolverError.md} +14 -12
- package/package.json +15 -16
- package/src/ditox.test.ts +10 -1
- package/src/index.ts +8 -9
- package/src/modules.test.ts +2 -0
- package/CHANGELOG.md +0 -132
- package/dist/index.browser.js +0 -2
- package/dist/index.browser.js.flow +0 -4
- package/dist/index.browser.js.map +0 -1
- package/dist/index.js +0 -411
- package/dist/index.js.flow +0 -4
- package/dist/index.js.map +0 -1
- package/dist/index.module.d.ts +0 -301
- package/dist/index.module.js +0 -393
- package/dist/index.module.js.flow +0 -4
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.d.ts +0 -301
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.flow +0 -4
- package/dist/index.umd.js.map +0 -1
- package/lib/index.js.flow +0 -4
- package/lib/index.js.map +0 -1
- package/mod.ts +0 -2
- package/src/ditox.js.flow +0 -131
- package/src/index.js.flow +0 -34
- package/src/modules.js.flow +0 -156
package/README.md
CHANGED
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=function(n,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(o,n){o.__proto__=n}||function(o,n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(o[t]=n[t])},o(n,t)};var n=function(){return n=Object.assign||function(o){for(var n,t=1,r=arguments.length;t<r;t++)for(var e in n=arguments[t])Object.prototype.hasOwnProperty.call(n,e)&&(o[e]=n[e]);return o},n.apply(this,arguments)};function t(o,n,t){if(t||2===arguments.length)for(var r,e=0,i=n.length;e<i;e++)!r&&e in n||(r||(r=Array.prototype.slice.call(n,0,e)),r[e]=n[e]);return o.concat(r||Array.prototype.slice.call(n))}function r(o){return{symbol:Symbol(o)}}function e(o,n){return{symbol:o.symbol,isOptional:!0,optionalValue:n}}var i=function(n){function t(o){var t=this.constructor,r=n.call(this,o)||this;return Object.setPrototypeOf(r,t.prototype),r.name="ResolverError",r}return function(n,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=n}o(n,t),n.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}(t,n),t}(Error),u=r("ditox.Container"),c=r("ditox.ParentContainer"),a=r("ditox.Resolver"),l=Symbol(),s=function(){throw new Error("FAKE_FACTORY")},f=r("ditox.FactoriesMap");function p(o){return o.symbol===u.symbol||o.symbol===c.symbol||o.symbol===a.symbol}function v(o){var n=new Map,t=new Map,r={bindValue:function(o,t){p(o)||n.set(o.symbol,t)},bindFactory:function(o,n,r){p(o)||t.set(o.symbol,{factory:n,options:r})},remove:function(o){var r;if(!p(o)){var e=null===(r=t.get(o.symbol))||void 0===r?void 0:r.options;e&&v(o.symbol,e),n.delete(o.symbol),t.delete(o.symbol)}},removeAll:function(){t.forEach((function(o,n){o.options&&v(n,o.options)})),n.clear(),t.clear(),y()},hasToken:function(r){var e;return n.has(r.symbol)||t.has(r.symbol)||null!==(e=null==o?void 0:o.hasToken(r))&&void 0!==e&&e},get:function(o){var n=e(o,r);return n!==l?n:o.isOptional?o.optionalValue:void 0},resolve:function(o){var n,t=e(o,r);if(t!==l)return t;if(o.isOptional)return o.optionalValue;throw new i('Token "'.concat(null!==(n=o.symbol.description)&&void 0!==n?n:"",'" is not provided'))}};function e(e,i){var u=n.get(e.symbol),c=void 0!==u||n.has(e.symbol);if(c&&i===r)return u;var f,p,v=t.get(e.symbol);if(v&&v.factory!==s)switch(f=v.options,null!==(p=null==f?void 0:f.scope)&&void 0!==p?p:"singleton"){case"singleton":if(c)return u;if(null==o?void 0:o.hasToken(e))break;var y=v.factory(r);return r.bindValue(e,y),y;case"scoped":var d=v.factory(i);return i.bindValue(e,d),i!==r&&i.bindFactory(e,s,v.options),d;case"transient":return v.factory(i)}if(c)return u;var b=null==o?void 0:o.get(a);return b?b(e,i):l}function v(o,t){var r=function(o){return void 0===o.scope||"scoped"===o.scope||"singleton"===o.scope?o.onRemoved:void 0}(t);if(r){var e=n.get(o);(void 0!==e||n.has(o))&&r(e)}}function y(){n.set(u.symbol,r),n.set(a.symbol,e),n.set(f.symbol,t),o&&n.set(c.symbol,o)}return y(),r}function y(o,n,r){var e,i=t(t([],null!==(e=o.get(n))&&void 0!==e?e:[],!0),[r],!1);o.bindValue(n,i)}function d(o){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];return n.map(o.get)}function b(o){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];return n.map(o.resolve)}function m(o){for(var n=this,r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return function(e){var i=b.apply(void 0,t([e],r,!1));return o.apply(n,i)}}function h(o,t){var r=n({},t);return Object.keys(r).forEach((function(n){return r[n]=o.get(r[n])})),r}function g(o,t){var r=n({},t);return Object.keys(r).forEach((function(n){return r[n]=o.resolve(r[n])})),r}function O(o,n){return function(t){var r=g(t,n);return o(r)}}function w(o,n,t){var r,e=n.token,i=n.imports,u=n.factory,c=n.beforeBinding,a=n.afterBinding,l=null!==(r=n.exports)&&void 0!==r?r:n.exportedProps,s=null==t?void 0:t.scope;c&&c(o),i&&k(o,i);var f=new Set;l&&Object.keys(l).forEach((function(n){var t=l[n];t&&(f.add(t),o.bindFactory(t,m((function(o){return o[n]}),e),{scope:s}))}));o.bindFactory(e,u,{scope:s,onRemoved:function(n){n.destroy&&n.destroy(),f.forEach((function(n){return o.remove(n)})),f.clear()}}),a&&a(o)}function k(o,n){n.forEach((function(n){"module"in n?w(o,n.module,n.options):w(o,n)}))}function E(o){var t;return n(n({},o),{token:null!==(t=o.token)&&void 0!==t?t:r()})}function j(o){return E({factory:function(){return{}},imports:o})}export{i as ResolverError,w as bindModule,k as bindModules,y as bindMultiValue,v as createContainer,E as declareModule,j as declareModuleBindings,h as getProps,d as getValues,m as injectable,O as injectableProps,e as optional,g as resolveProps,b as resolveValues,r as token};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../node_modules/tslib/tslib.es6.js","../../src/ditox.ts","../../src/utils.ts","../../src/modules.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n",null,null,null],"names":["extendStatics","d","b","Object","setPrototypeOf","__proto__","Array","p","prototype","hasOwnProperty","call","__assign","assign","t","s","i","n","arguments","length","apply","this","__spreadArray","to","from","pack","ar","l","slice","concat","token","description","symbol","Symbol","optional","optionalValue","isOptional","message","_super","_this","_newTarget","name","TypeError","String","__","constructor","create","__extends","Error","CONTAINER","PARENT_CONTAINER","RESOLVER","NOT_FOUND","FAKE_FACTORY","FACTORIES_MAP","isInternalToken","createContainer","parentContainer","values","Map","factories","container","bindValue","value","set","bindFactory","factory","options","remove","get","executeOnRemoved","delete","removeAll","forEach","context","tokenSymbol","clear","bindInternalTokens","hasToken","has","resolver","resolve","ResolverError","origin","hasValue","undefined","factoryContext","scope","value_1","value_2","parentResolver","onRemoved","getOnRemoved","bindMultiValue","nextValues","getValues","_i","tokens","map","resolveValues","injectable","getProps","obj","keys","key","resolveProps","injectableProps","bindModule","moduleDeclaration","imports","beforeBinding","afterBinding","exports","exportedProps","bindModules","exportedValueTokens","Set","valueKey","valueToken","add","module","destroy","modules","entry","declareModule","declaration","declareModuleBindings"],"mappings":"AAgBA,IAAIA,EAAgB,SAASC,EAAGC,GAI5B,OAHAF,EAAgBG,OAAOC,gBAClB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BF,gBAD6CG,EAC7CH,eACII,YAAUJ,EAAkBI,uBAAWJ,EAAkBK,cAEzD1B,EAAQpB,MAAAA,SAAAA,EAASoB,MAEnBuB,GACFA,EAAcjD,GAGZgD,GACFK,EAAYrD,EAAWgD,GAGzB,IAAMM,EAAsB,IAAIC,IAE5BJ,GACW5G,OAAOmG,KAAKS,GAEpBvC,SAAQ,SAAC4C,GACZ,IAAMC,EAAaN,EAAQK,GACvBC,IACFH,EAAoBI,IAAID,GAExBzD,EAAUI,YACRqD,EACAlB,GAAW,SAACoB,GAAW,OAAAA,EAAOH,KAAWvF,GACzC,CAACyD,cAMT1B,EAAUI,YAAYnC,EAAOoC,EAAS,CACpCqB,QACAI,UAAW,SAAC6B,GACNA,EAAOC,SACTD,EAAOC,UAGTN,EAAoB1C,SAAQ,SAAC6C,GAAe,OAAAzD,EAAUO,OAAOkD,MAC7DH,EAAoBvC,WAIpBmC,GACFA,EAAalD,YAUDqD,EACdrD,EACA6D,GAEAA,EAAQjD,SAAQ,SAACkD,GACX,WAAYA,EACdhB,EAAW9C,EAAW8D,EAAMH,OAAQG,EAAMxD,SAE1CwC,EAAW9C,EAAW8D,eA2BZC,EACdC,SAGA,cAAWA,IAAa/F,gBAAO+F,EAAY/F,qBAASA,eAQtCgG,EACdJ,GAEA,OAAOE,EAAc,CACnB1D,QAAS,WAAM,UACf2C,QAASa"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ignore
|
|
3
|
+
* Binding token for mandatory value
|
|
4
|
+
*/
|
|
5
|
+
export declare type RequiredToken<T> = {
|
|
6
|
+
symbol: symbol;
|
|
7
|
+
type?: T;
|
|
8
|
+
isOptional?: false;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @ignore
|
|
12
|
+
* Binding token for optional value
|
|
13
|
+
*/
|
|
14
|
+
export declare type OptionalToken<T> = {
|
|
15
|
+
symbol: symbol;
|
|
16
|
+
type?: T;
|
|
17
|
+
isOptional: true;
|
|
18
|
+
optionalValue: T;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Binding token.
|
|
22
|
+
*/
|
|
23
|
+
export declare type Token<T> = RequiredToken<T> | OptionalToken<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new binding token.
|
|
26
|
+
* @param description - Token description for better error messages.
|
|
27
|
+
*/
|
|
28
|
+
export declare function token<T>(description?: string): Token<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Decorate a token with an optional value.
|
|
31
|
+
* This value is be used as default value in case a container does not have registered token.
|
|
32
|
+
* @param token - Existed token.
|
|
33
|
+
* @param optionalValue - Default value for the resolver.
|
|
34
|
+
*/
|
|
35
|
+
export declare function optional<T>(token: Token<T>, optionalValue: T): OptionalToken<T>;
|
|
36
|
+
export declare function optional<T>(token: Token<T>): OptionalToken<T | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* ResolverError is thrown by the resolver when a token is not found in a container.
|
|
39
|
+
*/
|
|
40
|
+
export declare class ResolverError extends Error {
|
|
41
|
+
constructor(message: string);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @see https://github.com/mnasyrov/ditox#factory-lifetimes
|
|
45
|
+
*/
|
|
46
|
+
export declare type FactoryScope = 'scoped' | 'singleton' | 'transient';
|
|
47
|
+
/**
|
|
48
|
+
* Options for factory binding.
|
|
49
|
+
*
|
|
50
|
+
* `scope` types:
|
|
51
|
+
* - `singleton` - **This is the default**. The value is created and cached by the container which registered the factory.
|
|
52
|
+
* - `scoped` - The value is created and cached by the container which starts resolving.
|
|
53
|
+
* - `transient` - The value is created every time it is resolved.
|
|
54
|
+
*
|
|
55
|
+
* `scoped` and `singleton` scopes can have `onRemoved` callback. It is called when a token is removed from the container.
|
|
56
|
+
*/
|
|
57
|
+
export declare type FactoryOptions<T> = {
|
|
58
|
+
scope?: 'scoped' | 'singleton';
|
|
59
|
+
onRemoved?: (value: T) => void;
|
|
60
|
+
} | {
|
|
61
|
+
scope: 'transient';
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Dependency container.
|
|
65
|
+
*/
|
|
66
|
+
export declare type Container = {
|
|
67
|
+
/**
|
|
68
|
+
* Binds a value for the token
|
|
69
|
+
*/
|
|
70
|
+
bindValue<T>(token: Token<T>, value: T): void;
|
|
71
|
+
/**
|
|
72
|
+
* Binds a factory for the token.
|
|
73
|
+
*/
|
|
74
|
+
bindFactory<T>(token: Token<T>, factory: (container: Container) => T, options?: FactoryOptions<T>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if the token is registered in the container hierarchy.
|
|
77
|
+
*/
|
|
78
|
+
hasToken(token: Token<unknown>): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a resolved value by the token, or returns `undefined` in case the token is not found.
|
|
81
|
+
*/
|
|
82
|
+
get<T>(token: Token<T>): T | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Returns a resolved value by the token, or throws `ResolverError` in case the token is not found.
|
|
85
|
+
*/
|
|
86
|
+
resolve<T>(token: Token<T>): T;
|
|
87
|
+
/**
|
|
88
|
+
* Removes a binding for the token.
|
|
89
|
+
*/
|
|
90
|
+
remove<T>(token: Token<T>): void;
|
|
91
|
+
/**
|
|
92
|
+
* Removes all bindings in the container.
|
|
93
|
+
*/
|
|
94
|
+
removeAll(): void;
|
|
95
|
+
};
|
|
96
|
+
/** @internal */
|
|
97
|
+
export declare const CONTAINER: Token<Container>;
|
|
98
|
+
/** @internal */
|
|
99
|
+
export declare const PARENT_CONTAINER: Token<Container>;
|
|
100
|
+
/** @internal */
|
|
101
|
+
export declare const RESOLVER: Token<Resolver>;
|
|
102
|
+
/** @internal */
|
|
103
|
+
declare const NOT_FOUND: unique symbol;
|
|
104
|
+
/** @internal */
|
|
105
|
+
export declare const FAKE_FACTORY: () => never;
|
|
106
|
+
/** @internal */
|
|
107
|
+
declare type FactoryContext<T> = {
|
|
108
|
+
factory: (container: Container) => T;
|
|
109
|
+
options?: FactoryOptions<T>;
|
|
110
|
+
};
|
|
111
|
+
/** @internal */
|
|
112
|
+
export declare type FactoriesMap = Map<symbol, FactoryContext<any>>;
|
|
113
|
+
/** @internal */
|
|
114
|
+
export declare const FACTORIES_MAP: Token<FactoriesMap>;
|
|
115
|
+
/** @internal */
|
|
116
|
+
declare type Resolver = <T>(token: Token<T>, origin: Container) => T | typeof NOT_FOUND;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new dependency container.
|
|
119
|
+
*
|
|
120
|
+
* Container can have an optional parent to chain token resolution. The parent is used in case the current container does not have a registered token.
|
|
121
|
+
*
|
|
122
|
+
* @param parentContainer - Optional parent container.
|
|
123
|
+
*/
|
|
124
|
+
export declare function createContainer(parentContainer?: Container): Container;
|
|
125
|
+
export {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createContainer = exports.FACTORIES_MAP = exports.FAKE_FACTORY = exports.RESOLVER = exports.PARENT_CONTAINER = exports.CONTAINER = exports.ResolverError = exports.optional = exports.token = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new binding token.
|
|
6
|
+
* @param description - Token description for better error messages.
|
|
7
|
+
*/
|
|
8
|
+
function token(description) {
|
|
9
|
+
return { symbol: Symbol(description) };
|
|
10
|
+
}
|
|
11
|
+
exports.token = token;
|
|
12
|
+
function optional(token, optionalValue) {
|
|
13
|
+
return {
|
|
14
|
+
symbol: token.symbol,
|
|
15
|
+
isOptional: true,
|
|
16
|
+
optionalValue,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.optional = optional;
|
|
20
|
+
/**
|
|
21
|
+
* ResolverError is thrown by the resolver when a token is not found in a container.
|
|
22
|
+
*/
|
|
23
|
+
class ResolverError extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
27
|
+
this.name = 'ResolverError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ResolverError = ResolverError;
|
|
31
|
+
/** @internal */
|
|
32
|
+
exports.CONTAINER = token('ditox.Container');
|
|
33
|
+
/** @internal */
|
|
34
|
+
exports.PARENT_CONTAINER = token('ditox.ParentContainer');
|
|
35
|
+
/** @internal */
|
|
36
|
+
exports.RESOLVER = token('ditox.Resolver');
|
|
37
|
+
/** @internal */
|
|
38
|
+
const NOT_FOUND = Symbol();
|
|
39
|
+
/** @internal */
|
|
40
|
+
const FAKE_FACTORY = () => {
|
|
41
|
+
throw new Error('FAKE_FACTORY');
|
|
42
|
+
};
|
|
43
|
+
exports.FAKE_FACTORY = FAKE_FACTORY;
|
|
44
|
+
/** @internal */
|
|
45
|
+
const DEFAULT_SCOPE = 'singleton';
|
|
46
|
+
/** @internal */
|
|
47
|
+
exports.FACTORIES_MAP = token('ditox.FactoriesMap');
|
|
48
|
+
/** @internal */
|
|
49
|
+
function getScope(options) {
|
|
50
|
+
var _a;
|
|
51
|
+
return (_a = options === null || options === void 0 ? void 0 : options.scope) !== null && _a !== void 0 ? _a : DEFAULT_SCOPE;
|
|
52
|
+
}
|
|
53
|
+
/** @internal */
|
|
54
|
+
function getOnRemoved(options) {
|
|
55
|
+
return options.scope === undefined ||
|
|
56
|
+
options.scope === 'scoped' ||
|
|
57
|
+
options.scope === 'singleton'
|
|
58
|
+
? options.onRemoved
|
|
59
|
+
: undefined;
|
|
60
|
+
}
|
|
61
|
+
/** @internal */
|
|
62
|
+
function isInternalToken(token) {
|
|
63
|
+
return (token.symbol === exports.CONTAINER.symbol ||
|
|
64
|
+
token.symbol === exports.PARENT_CONTAINER.symbol ||
|
|
65
|
+
token.symbol === exports.RESOLVER.symbol);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new dependency container.
|
|
69
|
+
*
|
|
70
|
+
* Container can have an optional parent to chain token resolution. The parent is used in case the current container does not have a registered token.
|
|
71
|
+
*
|
|
72
|
+
* @param parentContainer - Optional parent container.
|
|
73
|
+
*/
|
|
74
|
+
function createContainer(parentContainer) {
|
|
75
|
+
const values = new Map();
|
|
76
|
+
const factories = new Map();
|
|
77
|
+
const container = {
|
|
78
|
+
bindValue(token, value) {
|
|
79
|
+
if (isInternalToken(token)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
values.set(token.symbol, value);
|
|
83
|
+
},
|
|
84
|
+
bindFactory(token, factory, options) {
|
|
85
|
+
if (isInternalToken(token)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
factories.set(token.symbol, { factory, options });
|
|
89
|
+
},
|
|
90
|
+
remove(token) {
|
|
91
|
+
var _a;
|
|
92
|
+
if (isInternalToken(token)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const options = (_a = factories.get(token.symbol)) === null || _a === void 0 ? void 0 : _a.options;
|
|
96
|
+
if (options) {
|
|
97
|
+
executeOnRemoved(token.symbol, options);
|
|
98
|
+
}
|
|
99
|
+
values.delete(token.symbol);
|
|
100
|
+
factories.delete(token.symbol);
|
|
101
|
+
},
|
|
102
|
+
removeAll() {
|
|
103
|
+
factories.forEach((context, tokenSymbol) => {
|
|
104
|
+
if (context.options) {
|
|
105
|
+
executeOnRemoved(tokenSymbol, context.options);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
values.clear();
|
|
109
|
+
factories.clear();
|
|
110
|
+
bindInternalTokens();
|
|
111
|
+
},
|
|
112
|
+
hasToken(token) {
|
|
113
|
+
var _a;
|
|
114
|
+
return (values.has(token.symbol) ||
|
|
115
|
+
factories.has(token.symbol) ||
|
|
116
|
+
((_a = parentContainer === null || parentContainer === void 0 ? void 0 : parentContainer.hasToken(token)) !== null && _a !== void 0 ? _a : false));
|
|
117
|
+
},
|
|
118
|
+
get(token) {
|
|
119
|
+
const value = resolver(token, container);
|
|
120
|
+
if (value !== NOT_FOUND) {
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
if (token.isOptional) {
|
|
124
|
+
return token.optionalValue;
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
},
|
|
128
|
+
resolve(token) {
|
|
129
|
+
var _a;
|
|
130
|
+
const value = resolver(token, container);
|
|
131
|
+
if (value !== NOT_FOUND) {
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
if (token.isOptional) {
|
|
135
|
+
return token.optionalValue;
|
|
136
|
+
}
|
|
137
|
+
throw new ResolverError(`Token "${(_a = token.symbol.description) !== null && _a !== void 0 ? _a : ''}" is not provided`);
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
function resolver(token, origin) {
|
|
141
|
+
const value = values.get(token.symbol);
|
|
142
|
+
const hasValue = value !== undefined || values.has(token.symbol);
|
|
143
|
+
if (hasValue && origin === container) {
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
const factoryContext = factories.get(token.symbol);
|
|
147
|
+
if (factoryContext && factoryContext.factory !== exports.FAKE_FACTORY) {
|
|
148
|
+
const scope = getScope(factoryContext.options);
|
|
149
|
+
switch (scope) {
|
|
150
|
+
case 'singleton': {
|
|
151
|
+
if (hasValue) {
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
else if (parentContainer === null || parentContainer === void 0 ? void 0 : parentContainer.hasToken(token)) {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// Cache the value in the same container where the factory is registered.
|
|
159
|
+
const value = factoryContext.factory(container);
|
|
160
|
+
container.bindValue(token, value);
|
|
161
|
+
return value;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
case 'scoped': {
|
|
165
|
+
// Create a value within the origin container and cache it.
|
|
166
|
+
const value = factoryContext.factory(origin);
|
|
167
|
+
origin.bindValue(token, value);
|
|
168
|
+
if (origin !== container) {
|
|
169
|
+
// Bind a fake factory with actual options to make onRemoved() works.
|
|
170
|
+
origin.bindFactory(token, exports.FAKE_FACTORY, factoryContext.options);
|
|
171
|
+
}
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
case 'transient': {
|
|
175
|
+
// Create a value within the origin container and don't cache it.
|
|
176
|
+
return factoryContext.factory(origin);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (hasValue) {
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
const parentResolver = parentContainer === null || parentContainer === void 0 ? void 0 : parentContainer.get(exports.RESOLVER);
|
|
184
|
+
if (parentResolver) {
|
|
185
|
+
return parentResolver(token, origin);
|
|
186
|
+
}
|
|
187
|
+
return NOT_FOUND;
|
|
188
|
+
}
|
|
189
|
+
function executeOnRemoved(tokenSymbol, options) {
|
|
190
|
+
const onRemoved = getOnRemoved(options);
|
|
191
|
+
if (onRemoved) {
|
|
192
|
+
const value = values.get(tokenSymbol);
|
|
193
|
+
if (value !== undefined || values.has(tokenSymbol)) {
|
|
194
|
+
onRemoved(value);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function bindInternalTokens() {
|
|
199
|
+
values.set(exports.CONTAINER.symbol, container);
|
|
200
|
+
values.set(exports.RESOLVER.symbol, resolver);
|
|
201
|
+
values.set(exports.FACTORIES_MAP.symbol, factories);
|
|
202
|
+
if (parentContainer) {
|
|
203
|
+
values.set(exports.PARENT_CONTAINER.symbol, parentContainer);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
bindInternalTokens();
|
|
207
|
+
return container;
|
|
208
|
+
}
|
|
209
|
+
exports.createContainer = createContainer;
|
|
210
|
+
//# sourceMappingURL=ditox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ditox.js","sourceRoot":"","sources":["../../src/ditox.ts"],"names":[],"mappings":";;;AA0BA;;;GAGG;AACH,SAAgB,KAAK,CAAI,WAAoB;IAC3C,OAAO,EAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,EAAC,CAAC;AACvC,CA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AAO,SAAS,CAAC;AACnB,CAAC;AA9KD,0CA8KC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { token, optional, ResolverError, createContainer } from './ditox';
|
|
2
|
+
export type { RequiredToken, OptionalToken, Token, FactoryScope, FactoryOptions, Container, } from './ditox';
|
|
3
|
+
export { bindMultiValue, getValues, resolveValues, injectable, getProps, resolveProps, injectableProps, } from './utils';
|
|
4
|
+
export { bindModule, bindModules, declareModule, declareModuleBindings, } from './modules';
|
|
5
|
+
export type { Module, ModuleDeclaration, BindModuleOptions, ModuleBindingEntry, } from './modules';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.declareModuleBindings = exports.declareModule = exports.bindModules = exports.bindModule = exports.injectableProps = exports.resolveProps = exports.getProps = exports.injectable = exports.resolveValues = exports.getValues = exports.bindMultiValue = exports.createContainer = exports.ResolverError = exports.optional = exports.token = void 0;
|
|
4
|
+
var ditox_1 = require("./ditox");
|
|
5
|
+
Object.defineProperty(exports, "token", { enumerable: true, get: function () { return ditox_1.token; } });
|
|
6
|
+
Object.defineProperty(exports, "optional", { enumerable: true, get: function () { return ditox_1.optional; } });
|
|
7
|
+
Object.defineProperty(exports, "ResolverError", { enumerable: true, get: function () { return ditox_1.ResolverError; } });
|
|
8
|
+
Object.defineProperty(exports, "createContainer", { enumerable: true, get: function () { return ditox_1.createContainer; } });
|
|
9
|
+
var utils_1 = require("./utils");
|
|
10
|
+
Object.defineProperty(exports, "bindMultiValue", { enumerable: true, get: function () { return utils_1.bindMultiValue; } });
|
|
11
|
+
Object.defineProperty(exports, "getValues", { enumerable: true, get: function () { return utils_1.getValues; } });
|
|
12
|
+
Object.defineProperty(exports, "resolveValues", { enumerable: true, get: function () { return utils_1.resolveValues; } });
|
|
13
|
+
Object.defineProperty(exports, "injectable", { enumerable: true, get: function () { return utils_1.injectable; } });
|
|
14
|
+
Object.defineProperty(exports, "getProps", { enumerable: true, get: function () { return utils_1.getProps; } });
|
|
15
|
+
Object.defineProperty(exports, "resolveProps", { enumerable: true, get: function () { return utils_1.resolveProps; } });
|
|
16
|
+
Object.defineProperty(exports, "injectableProps", { enumerable: true, get: function () { return utils_1.injectableProps; } });
|
|
17
|
+
var modules_1 = require("./modules");
|
|
18
|
+
Object.defineProperty(exports, "bindModule", { enumerable: true, get: function () { return modules_1.bindModule; } });
|
|
19
|
+
Object.defineProperty(exports, "bindModules", { enumerable: true, get: function () { return modules_1.bindModules; } });
|
|
20
|
+
Object.defineProperty(exports, "declareModule", { enumerable: true, get: function () { return modules_1.declareModule; } });
|
|
21
|
+
Object.defineProperty(exports, "declareModuleBindings", { enumerable: true, get: function () { return modules_1.declareModuleBindings; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAAwE;AAAhE,8FAAA,KAAK,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAAE,sGAAA,aAAa,OAAA;AAAE,wGAAA,eAAe,OAAA;AAUvD,iCAQiB;AAPf,uGAAA,cAAc,OAAA;AACd,kGAAA,SAAS,OAAA;AACT,sGAAA,aAAa,OAAA;AACb,mGAAA,UAAU,OAAA;AACV,iGAAA,QAAQ,OAAA;AACR,qGAAA,YAAY,OAAA;AACZ,wGAAA,eAAe,OAAA;AAGjB,qCAKmB;AAJjB,qGAAA,UAAU,OAAA;AACV,sGAAA,WAAW,OAAA;AACX,wGAAA,aAAa,OAAA;AACb,gHAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Container, Token } from './ditox';
|
|
2
|
+
declare type AnyObject = Record<string, any>;
|
|
3
|
+
declare type EmptyObject = Record<string, never>;
|
|
4
|
+
declare type ModuleController = {
|
|
5
|
+
/** Dispose the module and clean its resources */
|
|
6
|
+
destroy?: () => void;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Dependency module
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* type LoggerModule = Module<{
|
|
14
|
+
* logger: Logger;
|
|
15
|
+
* }>;
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare type Module<ModuleProps extends AnyObject = EmptyObject> = ModuleController & ModuleProps;
|
|
19
|
+
declare type GetModuleProps<T> = T extends Module<infer Props> ? Props : never;
|
|
20
|
+
/**
|
|
21
|
+
* Description how to bind the module in declarative way.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
|
|
26
|
+
* token: LOGGER_MODULE_TOKEN,
|
|
27
|
+
* factory: (container) => {
|
|
28
|
+
* const transport = container.resolve(TRANSPORT_TOKEN).open();
|
|
29
|
+
* return {
|
|
30
|
+
* logger: { log: (message) => transport.write(message) },
|
|
31
|
+
* destroy: () => transport.close(),
|
|
32
|
+
* }
|
|
33
|
+
* },
|
|
34
|
+
* exports: {
|
|
35
|
+
* logger: LOGGER_TOKEN,
|
|
36
|
+
* },
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare type ModuleDeclaration<T extends Module<AnyObject>> = {
|
|
41
|
+
/** Token for the module */
|
|
42
|
+
token: Token<T>;
|
|
43
|
+
/** Modules for binding */
|
|
44
|
+
imports?: ReadonlyArray<ModuleBindingEntry>;
|
|
45
|
+
/** Factory of the module */
|
|
46
|
+
factory: (container: Container) => T;
|
|
47
|
+
/** Dictionary of module properties which are bound to tokens. */
|
|
48
|
+
exports?: {
|
|
49
|
+
[K in keyof GetModuleProps<T>]?: Token<GetModuleProps<T>[K]>;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Dictionary of module properties which are bound to tokens.
|
|
53
|
+
*
|
|
54
|
+
* @deprecated Use `exports` property.
|
|
55
|
+
*/
|
|
56
|
+
exportedProps?: ModuleDeclaration<T>['exports'];
|
|
57
|
+
/** Callback could be used to prepare an environment. It is called before binding the module. */
|
|
58
|
+
beforeBinding?: (container: Container) => void;
|
|
59
|
+
/** Callback could be used to export complex dependencies from the module. It is called after binding the module. */
|
|
60
|
+
afterBinding?: (container: Container) => void;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Options for module binding.
|
|
64
|
+
*
|
|
65
|
+
* `scope` types:
|
|
66
|
+
* - `singleton` - **This is the default**. The module is created and cached by the container which registered the factory.
|
|
67
|
+
* - `scoped` - The module is created and cached by the container which starts resolving.
|
|
68
|
+
*/
|
|
69
|
+
export declare type BindModuleOptions = {
|
|
70
|
+
scope?: 'scoped' | 'singleton';
|
|
71
|
+
};
|
|
72
|
+
export declare type ModuleBindingEntry = ModuleDeclaration<AnyObject> | {
|
|
73
|
+
module: ModuleDeclaration<AnyObject>;
|
|
74
|
+
options: BindModuleOptions;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Binds the dependency module to the container
|
|
78
|
+
* @param container - Dependency container.
|
|
79
|
+
* @param moduleDeclaration - Declaration of the dependency module.
|
|
80
|
+
* @param options - Options for module binding.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* bindModule(container, LOGGER_MODULE);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function bindModule<T extends Module<AnyObject>>(container: Container, moduleDeclaration: ModuleDeclaration<T>, options?: BindModuleOptions): void;
|
|
88
|
+
/**
|
|
89
|
+
* Binds dependency modules to the container
|
|
90
|
+
*
|
|
91
|
+
* @param container - Dependency container for binding
|
|
92
|
+
* @param modules - Array of module binding entries: module declaration or `{module: ModuleDeclaration, options: BindModuleOptions}` objects.
|
|
93
|
+
*/
|
|
94
|
+
export declare function bindModules(container: Container, modules: ReadonlyArray<ModuleBindingEntry>): void;
|
|
95
|
+
/**
|
|
96
|
+
* Declares a module binding
|
|
97
|
+
*
|
|
98
|
+
* @param declaration - a module declaration
|
|
99
|
+
* @param declaration.token - optional field
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const LOGGER_MODULE = declareModule<LoggerModule>({
|
|
104
|
+
* factory: (container) => {
|
|
105
|
+
* const transport = container.resolve(TRANSPORT_TOKEN).open();
|
|
106
|
+
* return {
|
|
107
|
+
* logger: { log: (message) => transport.write(message) },
|
|
108
|
+
* destroy: () => transport.close(),
|
|
109
|
+
* }
|
|
110
|
+
* },
|
|
111
|
+
* exports: {
|
|
112
|
+
* logger: LOGGER_TOKEN,
|
|
113
|
+
* },
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function declareModule<T>(declaration: Omit<ModuleDeclaration<T>, 'token'> & Partial<Pick<ModuleDeclaration<T>, 'token'>>): ModuleDeclaration<T>;
|
|
118
|
+
/**
|
|
119
|
+
* Declares bindings of several modules
|
|
120
|
+
*
|
|
121
|
+
* @param modules - module declaration entries
|
|
122
|
+
*/
|
|
123
|
+
export declare function declareModuleBindings(modules: ReadonlyArray<ModuleBindingEntry>): ModuleDeclaration<Module>;
|
|
124
|
+
export {};
|