@spinajs/configuration 2.0.521 → 2.0.522
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/lib/cjs/fp.d.ts +5 -1
- package/lib/cjs/fp.d.ts.map +1 -1
- package/lib/cjs/fp.js +7 -20
- package/lib/cjs/fp.js.map +1 -1
- package/lib/cjs/helpers.d.ts +18 -0
- package/lib/cjs/helpers.d.ts.map +1 -0
- package/lib/cjs/helpers.js +47 -0
- package/lib/cjs/helpers.js.map +1 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/mjs/fp.d.ts +5 -1
- package/lib/mjs/fp.d.ts.map +1 -1
- package/lib/mjs/fp.js +7 -20
- package/lib/mjs/fp.js.map +1 -1
- package/lib/mjs/helpers.d.ts +18 -0
- package/lib/mjs/helpers.d.ts.map +1 -0
- package/lib/mjs/helpers.js +43 -0
- package/lib/mjs/helpers.js.map +1 -0
- package/lib/mjs/index.d.ts +1 -0
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +1 -0
- package/lib/mjs/index.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +6 -6
package/lib/cjs/fp.d.ts
CHANGED
|
@@ -3,14 +3,18 @@ import { Class } from '@spinajs/di';
|
|
|
3
3
|
*
|
|
4
4
|
* Get configuration value from path
|
|
5
5
|
*
|
|
6
|
+
* Kept for compatibility - delegates to the imperative {@link cfg}.
|
|
7
|
+
*
|
|
6
8
|
* @param path
|
|
7
9
|
* @returns
|
|
8
10
|
*/
|
|
9
|
-
export declare function _cfg<T>(path: string, defaultValue?: T): () =>
|
|
11
|
+
export declare function _cfg<T>(path: string, defaultValue?: T): () => T;
|
|
10
12
|
/**
|
|
11
13
|
* Resolves service from DI container base on path from configuration
|
|
12
14
|
* eg. _service("email.smtp") will resolve service from DI container registered at "email.smtp" path in configuration
|
|
13
15
|
*
|
|
16
|
+
* Kept for compatibility - delegates to the imperative {@link service}.
|
|
17
|
+
*
|
|
14
18
|
* @param path
|
|
15
19
|
* @returns
|
|
16
20
|
*/
|
package/lib/cjs/fp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp.d.ts","sourceRoot":"","sources":["../../src/fp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fp.d.ts","sourceRoot":"","sources":["../../src/fp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,WAErD;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,CAExF"}
|
package/lib/cjs/fp.js
CHANGED
|
@@ -2,42 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._cfg = _cfg;
|
|
4
4
|
exports._service = _service;
|
|
5
|
-
const
|
|
6
|
-
const di_1 = require("@spinajs/di");
|
|
7
|
-
const util_1 = require("@spinajs/util");
|
|
5
|
+
const helpers_js_1 = require("./helpers.js");
|
|
8
6
|
/**
|
|
9
7
|
*
|
|
10
8
|
* Get configuration value from path
|
|
11
9
|
*
|
|
10
|
+
* Kept for compatibility - delegates to the imperative {@link cfg}.
|
|
11
|
+
*
|
|
12
12
|
* @param path
|
|
13
13
|
* @returns
|
|
14
14
|
*/
|
|
15
15
|
function _cfg(path, defaultValue) {
|
|
16
|
-
|
|
17
|
-
if (!cfg) {
|
|
18
|
-
throw new di_1.ResolveException('Configuration service is not registered in DI container, register it to use _cfg function');
|
|
19
|
-
}
|
|
20
|
-
(0, util_1._check_arg)((0, util_1._non_empty)())(path, 'path');
|
|
21
|
-
// only null / undefined are invalid config values - empty arrays, empty objects
|
|
22
|
-
// and falsy primitives ( 0, '', false ) are legitimate configuration
|
|
23
|
-
return () => (0, util_1._check_arg)((0, util_1._non_null)(), (0, util_1._non_undefined)())(cfg.get(path, defaultValue), path);
|
|
16
|
+
return () => (0, helpers_js_1.cfg)(path, defaultValue);
|
|
24
17
|
}
|
|
25
18
|
/**
|
|
26
19
|
* Resolves service from DI container base on path from configuration
|
|
27
20
|
* eg. _service("email.smtp") will resolve service from DI container registered at "email.smtp" path in configuration
|
|
28
21
|
*
|
|
22
|
+
* Kept for compatibility - delegates to the imperative {@link service}.
|
|
23
|
+
*
|
|
29
24
|
* @param path
|
|
30
25
|
* @returns
|
|
31
26
|
*/
|
|
32
27
|
function _service(path, type, options) {
|
|
33
|
-
return () => (0,
|
|
34
|
-
const t = types.find((x) => x.name === service);
|
|
35
|
-
if (!t) {
|
|
36
|
-
throw new di_1.ResolveException(`Service ${service} is not registered for type ${type.name}`);
|
|
37
|
-
}
|
|
38
|
-
return t;
|
|
39
|
-
}, (t) => di_1.DI.resolve(t, options)), (err) => {
|
|
40
|
-
throw new di_1.ResolveException(`Cannot resolve service from ${path}: ${err.message}. Check your configuration file at this path.`, err);
|
|
41
|
-
}));
|
|
28
|
+
return () => (0, helpers_js_1.service)(path, type, options);
|
|
42
29
|
}
|
|
43
30
|
//# sourceMappingURL=fp.js.map
|
package/lib/cjs/fp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp.js","sourceRoot":"","sources":["../../src/fp.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"fp.js","sourceRoot":"","sources":["../../src/fp.ts"],"names":[],"mappings":";;;;AACA,6CAA4C;AAE5C;;;;;;;;GAQG;AACH,cAAwB,IAAY,EAAE,YAAgB;IACpD,OAAO,GAAG,EAAE,CAAC,IAAA,gBAAG,EAAI,IAAI,EAAE,YAAY,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;GAQG;AACH,kBAA4B,IAAY,EAAE,IAAc,EAAE,OAAY;IACpE,OAAO,GAAG,EAAE,CAAC,IAAA,oBAAO,EAAI,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Class } from '@spinajs/di';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Get configuration value from path
|
|
5
|
+
*
|
|
6
|
+
* @param path
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function cfg<T>(path: string, defaultValue?: T): T;
|
|
10
|
+
/**
|
|
11
|
+
* Resolves service from DI container base on path from configuration
|
|
12
|
+
* eg. service("email.smtp") will resolve service from DI container registered at "email.smtp" path in configuration
|
|
13
|
+
*
|
|
14
|
+
* @param path
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function service<T>(path: string, type: Class<T>, options?: []): Promise<T>;
|
|
18
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAmE,MAAM,aAAa,CAAC;AAGrG;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,CAWxD;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAmBvF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cfg = cfg;
|
|
4
|
+
exports.service = service;
|
|
5
|
+
const configuration_common_1 = require("@spinajs/configuration-common");
|
|
6
|
+
const di_1 = require("@spinajs/di");
|
|
7
|
+
const util_1 = require("@spinajs/util");
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* Get configuration value from path
|
|
11
|
+
*
|
|
12
|
+
* @param path
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
function cfg(path, defaultValue) {
|
|
16
|
+
const configuration = (0, di_1.get)(configuration_common_1.Configuration);
|
|
17
|
+
if (!configuration) {
|
|
18
|
+
throw new di_1.ResolveException('Configuration service is not registered in DI container, register it to use cfg function');
|
|
19
|
+
}
|
|
20
|
+
(0, util_1._check_arg)((0, util_1._non_empty)())(path, 'path');
|
|
21
|
+
// only null / undefined are invalid config values - empty arrays, empty objects
|
|
22
|
+
// and falsy primitives ( 0, '', false ) are legitimate configuration
|
|
23
|
+
return (0, util_1._check_arg)((0, util_1._non_null)(), (0, util_1._non_undefined)())(configuration.get(path, defaultValue), path);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolves service from DI container base on path from configuration
|
|
27
|
+
* eg. service("email.smtp") will resolve service from DI container registered at "email.smtp" path in configuration
|
|
28
|
+
*
|
|
29
|
+
* @param path
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
async function service(path, type, options) {
|
|
33
|
+
// configuration errors propagate raw - only resolution errors below are wrapped
|
|
34
|
+
const { service: serviceName } = cfg(path);
|
|
35
|
+
try {
|
|
36
|
+
const types = (0, di_1.getRegisteredTypes)(type);
|
|
37
|
+
const t = types.find((x) => x.name === serviceName);
|
|
38
|
+
if (!t) {
|
|
39
|
+
throw new di_1.ResolveException(`Service ${serviceName} is not registered for type ${type.name}`);
|
|
40
|
+
}
|
|
41
|
+
return (await (0, di_1.resolve)(t, options));
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
throw new di_1.ResolveException(`Cannot resolve service from ${path}: ${err.message}. Check your configuration file at this path.`, err);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;;;AAAA,wEAA8D;AAC9D,oCAAqG;AACrG,wCAAkF;AAElF;;;;;;GAMG;AACH,aAAuB,IAAY,EAAE,YAAgB;IACnD,MAAM,aAAa,GAAG,IAAA,QAAG,EAAC,oCAAa,CAAC,CAAC;IACzC,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,qBAAgB,CAAC,0FAA0F,CAAC,CAAC;IACzH,CAAC;IAED,IAAA,iBAAU,EAAC,IAAA,iBAAU,GAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEvC,gFAAgF;IAChF,qEAAqE;IACrE,OAAO,IAAA,iBAAU,EAAC,IAAA,gBAAS,GAAE,EAAE,IAAA,qBAAc,GAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAI,IAAI,EAAE,YAAY,CAAC,EAAE,IAAI,CAAC,CAAC;AACnG,CAAC;AAED;;;;;;GAMG;AACI,KAAK,kBAAqB,IAAY,EAAE,IAAc,EAAE,OAAY;IACzE,gFAAgF;IAChF,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,GAAG,CAAsB,IAAI,CAAC,CAAC;IAEhE,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAA,uBAAkB,EAAC,IAAI,CAAC,CAAC;QACvC,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;QAEpD,IAAI,CAAC,CAAC,EAAE,CAAC;YACP,MAAM,IAAI,qBAAgB,CAAC,WAAW,WAAW,+BAA+B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/F,CAAC;QAED,OAAO,CAAC,MAAM,IAAA,YAAO,EAAC,CAAyB,EAAE,OAAO,CAAC,CAAM,CAAC;IAClE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,qBAAgB,CACxB,+BAA+B,IAAI,KAAM,GAAa,CAAC,OAAO,+CAA+C,EAC7G,GAAG,CACJ,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/lib/cjs/index.d.ts
CHANGED
package/lib/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -23,5 +23,6 @@ __exportStar(require("./sources.js"), exports);
|
|
|
23
23
|
__exportStar(require("./decorators.js"), exports);
|
|
24
24
|
__exportStar(require("./configuration.js"), exports);
|
|
25
25
|
__exportStar(require("./exception.js"), exports);
|
|
26
|
+
__exportStar(require("./helpers.js"), exports);
|
|
26
27
|
__exportStar(require("./fp.js"), exports);
|
|
27
28
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;GAGG;AACH,gEAA8C;AAC9C,+CAA6B;AAC7B,kDAAgC;AAChC,qDAAmC;AACnC,iDAA+B;AAC/B,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;GAGG;AACH,gEAA8C;AAC9C,+CAA6B;AAC7B,kDAAgC;AAChC,qDAAmC;AACnC,iDAA+B;AAC/B,+CAA6B;AAC7B,0CAAwB"}
|
package/lib/mjs/fp.d.ts
CHANGED
|
@@ -3,14 +3,18 @@ import { Class } from '@spinajs/di';
|
|
|
3
3
|
*
|
|
4
4
|
* Get configuration value from path
|
|
5
5
|
*
|
|
6
|
+
* Kept for compatibility - delegates to the imperative {@link cfg}.
|
|
7
|
+
*
|
|
6
8
|
* @param path
|
|
7
9
|
* @returns
|
|
8
10
|
*/
|
|
9
|
-
export declare function _cfg<T>(path: string, defaultValue?: T): () =>
|
|
11
|
+
export declare function _cfg<T>(path: string, defaultValue?: T): () => T;
|
|
10
12
|
/**
|
|
11
13
|
* Resolves service from DI container base on path from configuration
|
|
12
14
|
* eg. _service("email.smtp") will resolve service from DI container registered at "email.smtp" path in configuration
|
|
13
15
|
*
|
|
16
|
+
* Kept for compatibility - delegates to the imperative {@link service}.
|
|
17
|
+
*
|
|
14
18
|
* @param path
|
|
15
19
|
* @returns
|
|
16
20
|
*/
|
package/lib/mjs/fp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp.d.ts","sourceRoot":"","sources":["../../src/fp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fp.d.ts","sourceRoot":"","sources":["../../src/fp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,WAErD;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,CAExF"}
|
package/lib/mjs/fp.js
CHANGED
|
@@ -1,39 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DI, ResolveException } from '@spinajs/di';
|
|
3
|
-
import { _catch, _chain, _check_arg, _non_empty, _non_null, _non_undefined } from '@spinajs/util';
|
|
1
|
+
import { cfg, service } from './helpers.js';
|
|
4
2
|
/**
|
|
5
3
|
*
|
|
6
4
|
* Get configuration value from path
|
|
7
5
|
*
|
|
6
|
+
* Kept for compatibility - delegates to the imperative {@link cfg}.
|
|
7
|
+
*
|
|
8
8
|
* @param path
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
11
|
export function _cfg(path, defaultValue) {
|
|
12
|
-
|
|
13
|
-
if (!cfg) {
|
|
14
|
-
throw new ResolveException('Configuration service is not registered in DI container, register it to use _cfg function');
|
|
15
|
-
}
|
|
16
|
-
_check_arg(_non_empty())(path, 'path');
|
|
17
|
-
// only null / undefined are invalid config values - empty arrays, empty objects
|
|
18
|
-
// and falsy primitives ( 0, '', false ) are legitimate configuration
|
|
19
|
-
return () => _check_arg(_non_null(), _non_undefined())(cfg.get(path, defaultValue), path);
|
|
12
|
+
return () => cfg(path, defaultValue);
|
|
20
13
|
}
|
|
21
14
|
/**
|
|
22
15
|
* Resolves service from DI container base on path from configuration
|
|
23
16
|
* eg. _service("email.smtp") will resolve service from DI container registered at "email.smtp" path in configuration
|
|
24
17
|
*
|
|
18
|
+
* Kept for compatibility - delegates to the imperative {@link service}.
|
|
19
|
+
*
|
|
25
20
|
* @param path
|
|
26
21
|
* @returns
|
|
27
22
|
*/
|
|
28
23
|
export function _service(path, type, options) {
|
|
29
|
-
return () =>
|
|
30
|
-
const t = types.find((x) => x.name === service);
|
|
31
|
-
if (!t) {
|
|
32
|
-
throw new ResolveException(`Service ${service} is not registered for type ${type.name}`);
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
}, (t) => DI.resolve(t, options)), (err) => {
|
|
36
|
-
throw new ResolveException(`Cannot resolve service from ${path}: ${err.message}. Check your configuration file at this path.`, err);
|
|
37
|
-
}));
|
|
24
|
+
return () => service(path, type, options);
|
|
38
25
|
}
|
|
39
26
|
//# sourceMappingURL=fp.js.map
|
package/lib/mjs/fp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp.js","sourceRoot":"","sources":["../../src/fp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fp.js","sourceRoot":"","sources":["../../src/fp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAI,IAAY,EAAE,YAAgB;IACpD,OAAO,GAAG,EAAE,CAAC,GAAG,CAAI,IAAI,EAAE,YAAY,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAI,IAAY,EAAE,IAAc,EAAE,OAAY;IACpE,OAAO,GAAG,EAAE,CAAC,OAAO,CAAI,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Class } from '@spinajs/di';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Get configuration value from path
|
|
5
|
+
*
|
|
6
|
+
* @param path
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function cfg<T>(path: string, defaultValue?: T): T;
|
|
10
|
+
/**
|
|
11
|
+
* Resolves service from DI container base on path from configuration
|
|
12
|
+
* eg. service("email.smtp") will resolve service from DI container registered at "email.smtp" path in configuration
|
|
13
|
+
*
|
|
14
|
+
* @param path
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function service<T>(path: string, type: Class<T>, options?: []): Promise<T>;
|
|
18
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAmE,MAAM,aAAa,CAAC;AAGrG;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,CAWxD;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAmBvF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Configuration } from '@spinajs/configuration-common';
|
|
2
|
+
import { get, getRegisteredTypes, resolve, ResolveException } from '@spinajs/di';
|
|
3
|
+
import { _check_arg, _non_empty, _non_null, _non_undefined } from '@spinajs/util';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* Get configuration value from path
|
|
7
|
+
*
|
|
8
|
+
* @param path
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export function cfg(path, defaultValue) {
|
|
12
|
+
const configuration = get(Configuration);
|
|
13
|
+
if (!configuration) {
|
|
14
|
+
throw new ResolveException('Configuration service is not registered in DI container, register it to use cfg function');
|
|
15
|
+
}
|
|
16
|
+
_check_arg(_non_empty())(path, 'path');
|
|
17
|
+
// only null / undefined are invalid config values - empty arrays, empty objects
|
|
18
|
+
// and falsy primitives ( 0, '', false ) are legitimate configuration
|
|
19
|
+
return _check_arg(_non_null(), _non_undefined())(configuration.get(path, defaultValue), path);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolves service from DI container base on path from configuration
|
|
23
|
+
* eg. service("email.smtp") will resolve service from DI container registered at "email.smtp" path in configuration
|
|
24
|
+
*
|
|
25
|
+
* @param path
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export async function service(path, type, options) {
|
|
29
|
+
// configuration errors propagate raw - only resolution errors below are wrapped
|
|
30
|
+
const { service: serviceName } = cfg(path);
|
|
31
|
+
try {
|
|
32
|
+
const types = getRegisteredTypes(type);
|
|
33
|
+
const t = types.find((x) => x.name === serviceName);
|
|
34
|
+
if (!t) {
|
|
35
|
+
throw new ResolveException(`Service ${serviceName} is not registered for type ${type.name}`);
|
|
36
|
+
}
|
|
37
|
+
return (await resolve(t, options));
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
throw new ResolveException(`Cannot resolve service from ${path}: ${err.message}. Check your configuration file at this path.`, err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAsB,GAAG,EAAE,kBAAkB,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAElF;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,CAAI,IAAY,EAAE,YAAgB;IACnD,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC;IACzC,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,gBAAgB,CAAC,0FAA0F,CAAC,CAAC;IACzH,CAAC;IAED,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEvC,gFAAgF;IAChF,qEAAqE;IACrE,OAAO,UAAU,CAAC,SAAS,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAI,IAAI,EAAE,YAAY,CAAC,EAAE,IAAI,CAAC,CAAC;AACnG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAI,IAAY,EAAE,IAAc,EAAE,OAAY;IACzE,gFAAgF;IAChF,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,GAAG,CAAsB,IAAI,CAAC,CAAC;IAEhE,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;QAEpD,IAAI,CAAC,CAAC,EAAE,CAAC;YACP,MAAM,IAAI,gBAAgB,CAAC,WAAW,WAAW,+BAA+B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/F,CAAC;QAED,OAAO,CAAC,MAAM,OAAO,CAAC,CAAyB,EAAE,OAAO,CAAC,CAAM,CAAC;IAClE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,gBAAgB,CACxB,+BAA+B,IAAI,KAAM,GAAa,CAAC,OAAO,+CAA+C,EAC7G,GAAG,CACJ,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/lib/mjs/index.d.ts
CHANGED
package/lib/mjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
package/lib/mjs/index.js
CHANGED
package/lib/mjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|