ditox 2.1.0 → 2.3.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.
@@ -36,8 +36,8 @@ ResolverError is thrown by the resolver when a token is not found in a container
36
36
 
37
37
  #### Parameters
38
38
 
39
- | Name | Type |
40
- | :------ | :------ |
39
+ | Name | Type |
40
+ | :-------- | :------- |
41
41
  | `message` | `string` |
42
42
 
43
43
  #### Overrides
@@ -46,7 +46,7 @@ Error.constructor
46
46
 
47
47
  #### Defined in
48
48
 
49
- [packages/ditox/src/ditox.ts:61](https://github.com/mnasyrov/ditox/blob/aea7a8f/packages/ditox/src/ditox.ts#L61)
49
+ [packages/ditox/src/ditox.ts:61](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/ditox.ts#L61)
50
50
 
51
51
  ## Properties
52
52
 
@@ -60,9 +60,9 @@ Error.message
60
60
 
61
61
  #### Defined in
62
62
 
63
- node_modules/typescript/lib/lib.es5.d.ts:1023
63
+ node_modules/typescript/lib/lib.es5.d.ts:1054
64
64
 
65
- ___
65
+ ---
66
66
 
67
67
  ### name
68
68
 
@@ -74,9 +74,9 @@ Error.name
74
74
 
75
75
  #### Defined in
76
76
 
77
- node_modules/typescript/lib/lib.es5.d.ts:1022
77
+ node_modules/typescript/lib/lib.es5.d.ts:1053
78
78
 
79
- ___
79
+ ---
80
80
 
81
81
  ### stack
82
82
 
@@ -88,9 +88,9 @@ Error.stack
88
88
 
89
89
  #### Defined in
90
90
 
91
- node_modules/typescript/lib/lib.es5.d.ts:1024
91
+ node_modules/typescript/lib/lib.es5.d.ts:1055
92
92
 
93
- ___
93
+ ---
94
94
 
95
95
  ### prepareStackTrace
96
96
 
@@ -102,13 +102,15 @@ ___
102
102
 
103
103
  Optional override for formatting stack traces
104
104
 
105
- **`see`** https://v8.dev/docs/stack-trace-api#customizing-stack-traces
105
+ **`See`**
106
+
107
+ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
106
108
 
107
109
  ##### Parameters
108
110
 
109
- | Name | Type |
110
- | :------ | :------ |
111
- | `err` | `Error` |
111
+ | Name | Type |
112
+ | :------------ | :----------- |
113
+ | `err` | `Error` |
112
114
  | `stackTraces` | `CallSite`[] |
113
115
 
114
116
  ##### Returns
@@ -123,7 +125,7 @@ Error.prepareStackTrace
123
125
 
124
126
  node_modules/@types/node/globals.d.ts:11
125
127
 
126
- ___
128
+ ---
127
129
 
128
130
  ### stackTraceLimit
129
131
 
@@ -147,9 +149,9 @@ Create .stack property on a target object
147
149
 
148
150
  #### Parameters
149
151
 
150
- | Name | Type |
151
- | :------ | :------ |
152
- | `targetObject` | `object` |
152
+ | Name | Type |
153
+ | :---------------- | :--------- |
154
+ | `targetObject` | `object` |
153
155
  | `constructorOpt?` | `Function` |
154
156
 
155
157
  #### Returns
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ditox",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "Powerful dependency injection container for building modular apps.",
5
5
  "license": "MIT",
6
6
  "author": "Mikhail Nasyrov <mikhail@mnasyrov.com> (https://github.com/mnasyrov)",
@@ -47,5 +47,5 @@
47
47
  "build:esm": "tsc -p tsconfig.build.json --outDir dist/esm --module es2015",
48
48
  "build:rollup": "rollup -c"
49
49
  },
50
- "gitHead": "8e8e4d79b6aaf3fa8662e51ecce0511f53e10ea8"
50
+ "gitHead": "3d34ea7a89e0bb599fa2d9dbfa67e75ec68bfba2"
51
51
  }
package/src/index.ts CHANGED
@@ -19,13 +19,6 @@ export {
19
19
  injectableClass,
20
20
  } from './utils';
21
21
 
22
- export {
23
- getValues,
24
- getProps,
25
- resolveProps,
26
- injectableProps,
27
- } from './utils-deprecated';
28
-
29
22
  export {
30
23
  bindModule,
31
24
  bindModules,
package/src/modules.ts CHANGED
@@ -59,13 +59,6 @@ export type ModuleDeclaration<T extends Module<AnyObject>> = {
59
59
  [K in keyof GetModuleProps<T>]?: Token<GetModuleProps<T>[K]>;
60
60
  };
61
61
 
62
- /**
63
- * Dictionary of module properties which are bound to tokens.
64
- *
65
- * @deprecated Use `exports` property.
66
- */
67
- exportedProps?: ModuleDeclaration<T>['exports'];
68
-
69
62
  /** Callback could be used to prepare an environment. It is called before binding the module. */
70
63
  beforeBinding?: (container: Container) => void;
71
64
 
@@ -73,6 +66,8 @@ export type ModuleDeclaration<T extends Module<AnyObject>> = {
73
66
  afterBinding?: (container: Container) => void;
74
67
  };
75
68
 
69
+ export type AnyModuleDeclaration = ModuleDeclaration<Module<AnyObject>>;
70
+
76
71
  /**
77
72
  * Options for module binding.
78
73
  *
@@ -109,7 +104,7 @@ export function bindModule<T extends Module<AnyObject>>(
109
104
  ): void {
110
105
  const {token, imports, factory, beforeBinding, afterBinding} =
111
106
  moduleDeclaration;
112
- const exports = moduleDeclaration.exports ?? moduleDeclaration.exportedProps;
107
+ const exports = moduleDeclaration.exports;
113
108
 
114
109
  const scope = options?.scope;
115
110
 
@@ -198,7 +193,7 @@ export function bindModules(
198
193
  * });
199
194
  * ```
200
195
  */
201
- export function declareModule<T>(
196
+ export function declareModule<T extends Module<AnyObject>>(
202
197
  declaration: Omit<ModuleDeclaration<T>, 'token'> &
203
198
  Partial<Pick<ModuleDeclaration<T>, 'token'>>,
204
199
  ): ModuleDeclaration<T> {
@@ -1,59 +0,0 @@
1
- import type { Container, Token } from './ditox';
2
- declare type ValuesProps = {
3
- [key: string]: unknown;
4
- };
5
- declare type TokenProps<Props extends ValuesProps> = {
6
- [K in keyof Props]: Token<Props[K]>;
7
- };
8
- /**
9
- * Returns an array of resolved values by the specified token.
10
- * If a token is not found, then `undefined` value is used.
11
- *
12
- * @deprecated Use `tryResolveValues()` function.
13
- */
14
- export declare function getValues<Tokens extends Token<unknown>[], Values extends {
15
- [K in keyof Tokens]: Tokens[K] extends Token<infer V> ? V : never;
16
- }>(container: Container, ...tokens: Tokens): Values;
17
- /**
18
- * Returns an object with resolved properties which are specified by token properties.
19
- * If a token is not found, then `undefined` value is used.
20
- *
21
- * @deprecated Use `tryResolveValue()` function.
22
- *
23
- * @example
24
- * ```ts
25
- * const props = getProps(container, {a: tokenA, b: tokenB});
26
- * console.log(props); // {a: 1, b: 2}
27
- * ```
28
- */
29
- export declare function getProps<Props extends ValuesProps>(container: Container, tokens: TokenProps<Props>): Partial<Props>;
30
- /**
31
- * Returns an object with resolved properties which are specified by token properties.
32
- * If a token is not found, then `ResolverError` is thrown.
33
- *
34
- * @deprecated Use `resolveValue()` function.
35
- *
36
- * @example
37
- * ```ts
38
- * const props = resolveProps(container, {a: tokenA, b: tokenB});
39
- * console.log(props); // {a: 1, b: 2}
40
- * ```
41
- */
42
- export declare function resolveProps<Props extends ValuesProps>(container: Container, tokens: TokenProps<Props>): Props;
43
- /**
44
- * Decorates a factory by passing a resolved object with tokens as the first argument.
45
- * @param factory - A factory.
46
- * @param tokens - Object with tokens.
47
- * @return Decorated factory which takes a dependency container as a single argument.
48
- *
49
- * @deprecated Use `injectable()` function.
50
- *
51
- * @example
52
- * ```ts
53
- * const factory = ({a, b}: {a: number, b: number}) => a + b;
54
- * const decoratedFactory = injectableProps(factory, {a: tokenA, b: tokenB});
55
- * const result = decoratedFactory(container);
56
- * ```
57
- */
58
- export declare function injectableProps<Props extends ValuesProps, Result>(factory: (props: Props) => Result, tokens: TokenProps<Props>): (container: Container) => Result;
59
- export {};
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.injectableProps = exports.resolveProps = exports.getProps = exports.getValues = void 0;
4
- const utils_1 = require("./utils");
5
- /**
6
- * Returns an array of resolved values by the specified token.
7
- * If a token is not found, then `undefined` value is used.
8
- *
9
- * @deprecated Use `tryResolveValues()` function.
10
- */
11
- function getValues(container, ...tokens) {
12
- return (0, utils_1.tryResolveValues)(container, ...tokens);
13
- }
14
- exports.getValues = getValues;
15
- /**
16
- * Returns an object with resolved properties which are specified by token properties.
17
- * If a token is not found, then `undefined` value is used.
18
- *
19
- * @deprecated Use `tryResolveValue()` function.
20
- *
21
- * @example
22
- * ```ts
23
- * const props = getProps(container, {a: tokenA, b: tokenB});
24
- * console.log(props); // {a: 1, b: 2}
25
- * ```
26
- */
27
- function getProps(container, tokens) {
28
- return (0, utils_1.tryResolveValue)(container, tokens);
29
- }
30
- exports.getProps = getProps;
31
- /**
32
- * Returns an object with resolved properties which are specified by token properties.
33
- * If a token is not found, then `ResolverError` is thrown.
34
- *
35
- * @deprecated Use `resolveValue()` function.
36
- *
37
- * @example
38
- * ```ts
39
- * const props = resolveProps(container, {a: tokenA, b: tokenB});
40
- * console.log(props); // {a: 1, b: 2}
41
- * ```
42
- */
43
- function resolveProps(container, tokens) {
44
- return (0, utils_1.resolveValue)(container, tokens);
45
- }
46
- exports.resolveProps = resolveProps;
47
- /**
48
- * Decorates a factory by passing a resolved object with tokens as the first argument.
49
- * @param factory - A factory.
50
- * @param tokens - Object with tokens.
51
- * @return Decorated factory which takes a dependency container as a single argument.
52
- *
53
- * @deprecated Use `injectable()` function.
54
- *
55
- * @example
56
- * ```ts
57
- * const factory = ({a, b}: {a: number, b: number}) => a + b;
58
- * const decoratedFactory = injectableProps(factory, {a: tokenA, b: tokenB});
59
- * const result = decoratedFactory(container);
60
- * ```
61
- */
62
- function injectableProps(factory, tokens) {
63
- return (0, utils_1.injectable)(factory, tokens);
64
- }
65
- exports.injectableProps = injectableProps;
66
- //# sourceMappingURL=utils-deprecated.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils-deprecated.js","sourceRoot":"","sources":["../../src/utils-deprecated.ts"],"names":[],"mappings":";;;AACA,mCAKiB;AAOjB;;;;;GAKG;AACH,SAAgB,SAAS,CAKvB,SAAoB,EAAE,GAAG,MAAc;IACvC,OAAO,IAAA,wBAAgB,EAAC,SAAS,EAAE,GAAG,MAAM,CAAC,CAAC;AAChD,CAAC;AAPD,8BAOC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,QAAQ,CACtB,SAAoB,EACpB,MAAyB;IAEzB,OAAO,IAAA,uBAAe,EAAC,SAAS,EAAE,MAAM,CAAmB,CAAC;AAC9D,CAAC;AALD,4BAKC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,YAAY,CAC1B,SAAoB,EACpB,MAAyB;IAEzB,OAAO,IAAA,oBAAY,EAAC,SAAS,EAAE,MAAM,CAAU,CAAC;AAClD,CAAC;AALD,oCAKC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,eAAe,CAC7B,OAAiC,EACjC,MAAyB;IAEzB,OAAO,IAAA,kBAAU,EAAC,OAAc,EAAE,MAAM,CAAC,CAAC;AAC5C,CAAC;AALD,0CAKC"}
@@ -1,59 +0,0 @@
1
- import type { Container, Token } from './ditox';
2
- declare type ValuesProps = {
3
- [key: string]: unknown;
4
- };
5
- declare type TokenProps<Props extends ValuesProps> = {
6
- [K in keyof Props]: Token<Props[K]>;
7
- };
8
- /**
9
- * Returns an array of resolved values by the specified token.
10
- * If a token is not found, then `undefined` value is used.
11
- *
12
- * @deprecated Use `tryResolveValues()` function.
13
- */
14
- export declare function getValues<Tokens extends Token<unknown>[], Values extends {
15
- [K in keyof Tokens]: Tokens[K] extends Token<infer V> ? V : never;
16
- }>(container: Container, ...tokens: Tokens): Values;
17
- /**
18
- * Returns an object with resolved properties which are specified by token properties.
19
- * If a token is not found, then `undefined` value is used.
20
- *
21
- * @deprecated Use `tryResolveValue()` function.
22
- *
23
- * @example
24
- * ```ts
25
- * const props = getProps(container, {a: tokenA, b: tokenB});
26
- * console.log(props); // {a: 1, b: 2}
27
- * ```
28
- */
29
- export declare function getProps<Props extends ValuesProps>(container: Container, tokens: TokenProps<Props>): Partial<Props>;
30
- /**
31
- * Returns an object with resolved properties which are specified by token properties.
32
- * If a token is not found, then `ResolverError` is thrown.
33
- *
34
- * @deprecated Use `resolveValue()` function.
35
- *
36
- * @example
37
- * ```ts
38
- * const props = resolveProps(container, {a: tokenA, b: tokenB});
39
- * console.log(props); // {a: 1, b: 2}
40
- * ```
41
- */
42
- export declare function resolveProps<Props extends ValuesProps>(container: Container, tokens: TokenProps<Props>): Props;
43
- /**
44
- * Decorates a factory by passing a resolved object with tokens as the first argument.
45
- * @param factory - A factory.
46
- * @param tokens - Object with tokens.
47
- * @return Decorated factory which takes a dependency container as a single argument.
48
- *
49
- * @deprecated Use `injectable()` function.
50
- *
51
- * @example
52
- * ```ts
53
- * const factory = ({a, b}: {a: number, b: number}) => a + b;
54
- * const decoratedFactory = injectableProps(factory, {a: tokenA, b: tokenB});
55
- * const result = decoratedFactory(container);
56
- * ```
57
- */
58
- export declare function injectableProps<Props extends ValuesProps, Result>(factory: (props: Props) => Result, tokens: TokenProps<Props>): (container: Container) => Result;
59
- export {};
@@ -1,59 +0,0 @@
1
- import { injectable, resolveValue, tryResolveValue, tryResolveValues, } from './utils';
2
- /**
3
- * Returns an array of resolved values by the specified token.
4
- * If a token is not found, then `undefined` value is used.
5
- *
6
- * @deprecated Use `tryResolveValues()` function.
7
- */
8
- export function getValues(container, ...tokens) {
9
- return tryResolveValues(container, ...tokens);
10
- }
11
- /**
12
- * Returns an object with resolved properties which are specified by token properties.
13
- * If a token is not found, then `undefined` value is used.
14
- *
15
- * @deprecated Use `tryResolveValue()` function.
16
- *
17
- * @example
18
- * ```ts
19
- * const props = getProps(container, {a: tokenA, b: tokenB});
20
- * console.log(props); // {a: 1, b: 2}
21
- * ```
22
- */
23
- export function getProps(container, tokens) {
24
- return tryResolveValue(container, tokens);
25
- }
26
- /**
27
- * Returns an object with resolved properties which are specified by token properties.
28
- * If a token is not found, then `ResolverError` is thrown.
29
- *
30
- * @deprecated Use `resolveValue()` function.
31
- *
32
- * @example
33
- * ```ts
34
- * const props = resolveProps(container, {a: tokenA, b: tokenB});
35
- * console.log(props); // {a: 1, b: 2}
36
- * ```
37
- */
38
- export function resolveProps(container, tokens) {
39
- return resolveValue(container, tokens);
40
- }
41
- /**
42
- * Decorates a factory by passing a resolved object with tokens as the first argument.
43
- * @param factory - A factory.
44
- * @param tokens - Object with tokens.
45
- * @return Decorated factory which takes a dependency container as a single argument.
46
- *
47
- * @deprecated Use `injectable()` function.
48
- *
49
- * @example
50
- * ```ts
51
- * const factory = ({a, b}: {a: number, b: number}) => a + b;
52
- * const decoratedFactory = injectableProps(factory, {a: tokenA, b: tokenB});
53
- * const result = decoratedFactory(container);
54
- * ```
55
- */
56
- export function injectableProps(factory, tokens) {
57
- return injectable(factory, tokens);
58
- }
59
- //# sourceMappingURL=utils-deprecated.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils-deprecated.js","sourceRoot":"","sources":["../../src/utils-deprecated.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAOjB;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAKvB,SAAoB,EAAE,GAAG,MAAc;IACvC,OAAO,gBAAgB,CAAC,SAAS,EAAE,GAAG,MAAM,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CACtB,SAAoB,EACpB,MAAyB;IAEzB,OAAO,eAAe,CAAC,SAAS,EAAE,MAAM,CAAmB,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAoB,EACpB,MAAyB;IAEzB,OAAO,YAAY,CAAC,SAAS,EAAE,MAAM,CAAU,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAiC,EACjC,MAAyB;IAEzB,OAAO,UAAU,CAAC,OAAc,EAAE,MAAM,CAAC,CAAC;AAC5C,CAAC"}