@rocketmakers/ioc 0.2.4 → 0.3.5
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 +89 -31
- package/lib/binder-legacy.d.ts +9 -0
- package/lib/binder-legacy.js +26 -0
- package/lib/binder.d.ts +22 -0
- package/lib/binder.js +45 -0
- package/lib/curry.d.ts +2 -0
- package/lib/curry.generated.d.ts +60 -0
- package/lib/curry.js +29 -0
- package/lib/error.d.ts +4 -0
- package/lib/error.js +20 -0
- package/lib/index.d.ts +57 -61
- package/lib/index.js +74 -111
- package/lib/inversify.d.ts +30 -0
- package/lib/inversify.js +64 -0
- package/lib/naming/camel.d.ts +6 -0
- package/lib/naming/camel.js +13 -0
- package/lib/naming/none.d.ts +6 -0
- package/lib/naming/none.js +7 -0
- package/lib/tail.generated.d.ts +45 -24
- package/lib/tail.generated.js +20 -0
- package/lib/types.d.ts +9 -0
- package/lib/types.js +2 -0
- package/package.json +1 -1
- package/lib/global.d.ts +0 -9
- package/lib/global.js +0 -13
package/README.md
CHANGED
|
@@ -14,7 +14,11 @@ You should first create a type that describes your Container items, then create
|
|
|
14
14
|
|
|
15
15
|
`service/admin.ts`
|
|
16
16
|
```TypeScript
|
|
17
|
-
export class AdminService {
|
|
17
|
+
export class AdminService {
|
|
18
|
+
doSomething(value: number) {
|
|
19
|
+
return Math.round(value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
18
22
|
|
|
19
23
|
```
|
|
20
24
|
|
|
@@ -30,27 +34,32 @@ export class AdminController {
|
|
|
30
34
|
|
|
31
35
|
`service/external-api.ts`
|
|
32
36
|
```TypeScript
|
|
33
|
-
import {
|
|
37
|
+
import { fetchUserData, IUser } from './external';
|
|
34
38
|
|
|
35
39
|
// NOTE: we want the apiKey param to be provided (curried) from the container - so we never need to explicitly pass this when consuming this function!
|
|
36
|
-
export function
|
|
37
|
-
return
|
|
40
|
+
export function getExternalUserData(apiKey: string, id: number): IUser {
|
|
41
|
+
return fetchUserData(apiKey, id);
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
```
|
|
41
45
|
`ioc/types.ts`
|
|
42
46
|
```TypeScript
|
|
43
|
-
import { Curried1 } from '@rocketmakers/ioc';
|
|
47
|
+
import { Curried1, Curried2 } from '@rocketmakers/ioc';
|
|
44
48
|
|
|
49
|
+
// Application Types
|
|
45
50
|
import type { AdminController } from '../controller/admin';
|
|
46
51
|
import type { AdminService } from '../service/admin';
|
|
47
|
-
import type {
|
|
52
|
+
import type { getExternalUserData } from '../service/external-api';
|
|
48
53
|
|
|
54
|
+
/** Define the types registered within the container */
|
|
49
55
|
export type ControllerContainerTypes = {
|
|
56
|
+
id: number;
|
|
57
|
+
apiKey: string;
|
|
50
58
|
adminService: AdminService;
|
|
51
59
|
adminController: AdminController;
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
getExternalUserData: typeof getExternalUserData;
|
|
61
|
+
getExternalUserData1: Curried1<typeof getExternalUserData>;
|
|
62
|
+
getExternalUserData2: Curried2<typeof getExternalUserData>;
|
|
54
63
|
};
|
|
55
64
|
|
|
56
65
|
```
|
|
@@ -61,40 +70,83 @@ export type ControllerContainerTypes = {
|
|
|
61
70
|
|
|
62
71
|
`ioc/register.ts`
|
|
63
72
|
```TypeScript
|
|
64
|
-
import {
|
|
73
|
+
import { IContainer, register } from '@rocketmakers/ioc';
|
|
65
74
|
|
|
66
75
|
import { AdminController } from '../controller/admin';
|
|
67
76
|
import { AdminService } from '../service/admin';
|
|
68
|
-
import {
|
|
77
|
+
import { getExternalUserData } from '../service/external-api';
|
|
69
78
|
import { ControllerContainerTypes } from './types';
|
|
70
79
|
|
|
71
|
-
export const functionResolver = containerRegisterFunctionResolver<ControllerContainerTypes>();
|
|
72
|
-
|
|
73
80
|
export function makeContainer(): IContainer<ControllerContainerTypes> {
|
|
81
|
+
// Register all the keys of the 'ControllerContainerTypes'
|
|
74
82
|
return register<ControllerContainerTypes>({
|
|
75
|
-
|
|
76
|
-
adminService: b => b.class(AdminService).construct([]),
|
|
83
|
+
id: b => b.constant(31313),
|
|
77
84
|
apiKey: b => b.constant('xyz...'),
|
|
78
|
-
|
|
85
|
+
adminService: b => b.class(AdminService, []),
|
|
86
|
+
adminController: b => b.class(AdminController, ['adminService']),
|
|
87
|
+
getExternalUserData: b => b.function(getExternalUserData),
|
|
88
|
+
getExternalUserData1: b => b.functionCurry(getExternalUserData, ['apiKey']),
|
|
89
|
+
getExternalUserData2: b => b.functionCurry(getExternalUserData, ['apiKey', 'id']),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`ioc/register-with-prefix.ts`
|
|
96
|
+
```TypeScript
|
|
97
|
+
import { registerWithPrefix } from '@rocketmakers/ioc';
|
|
98
|
+
|
|
99
|
+
import { AdminController } from '../controller/admin';
|
|
100
|
+
import { AdminService } from '../service/admin';
|
|
101
|
+
import { getExternalUserData } from '../service/external-api';
|
|
102
|
+
import { ControllerContainerTypes } from './types';
|
|
103
|
+
|
|
104
|
+
export function makeContainerPrefixed<TPrefix extends string>(prefix: TPrefix, id: number, apiKey: string) {
|
|
105
|
+
// Register all the keys of the 'ControllerContainerTypes'
|
|
106
|
+
return registerWithPrefix<TPrefix, ControllerContainerTypes>('none', prefix, {
|
|
107
|
+
id: b => b.constant(id),
|
|
108
|
+
apiKey: b => b.constant(apiKey),
|
|
109
|
+
adminService: b => b.class(AdminService, []),
|
|
110
|
+
adminController: b => b.class(AdminController, ['adminService']),
|
|
111
|
+
getExternalUserData: b => b.function(getExternalUserData),
|
|
112
|
+
getExternalUserData1: b => b.functionCurry(getExternalUserData, ['apiKey']),
|
|
113
|
+
getExternalUserData2: b => b.functionCurry(getExternalUserData, ['apiKey', 'id']),
|
|
79
114
|
});
|
|
80
115
|
}
|
|
81
116
|
|
|
117
|
+
const v1 = makeContainerPrefixed('this-', 31313, 'xyz...');
|
|
118
|
+
v1.get('this-id');
|
|
119
|
+
v1.get('this-apiKey');
|
|
120
|
+
v1.get('this-adminService');
|
|
121
|
+
v1.get('this-adminController');
|
|
122
|
+
v1.get('this-getExternalUserData');
|
|
123
|
+
v1.get('this-getExternalUserData1');
|
|
124
|
+
v1.get('this-getExternalUserData2');
|
|
125
|
+
|
|
126
|
+
const v2 = makeContainerPrefixed('that-', 13131, 'abc...');
|
|
127
|
+
v2.get('that-id');
|
|
128
|
+
v2.get('that-apiKey');
|
|
129
|
+
v2.get('that-adminService');
|
|
130
|
+
v2.get('that-adminController');
|
|
131
|
+
v2.get('that-getExternalUserData');
|
|
132
|
+
v2.get('that-getExternalUserData1');
|
|
133
|
+
v2.get('that-getExternalUserData2');
|
|
134
|
+
|
|
82
135
|
```
|
|
83
136
|
|
|
84
137
|
### Resolving with the container
|
|
85
138
|
|
|
86
139
|
```TypeScript
|
|
87
|
-
import { makeContainer } from './ioc/register
|
|
140
|
+
import { makeContainer } from './ioc/register';
|
|
88
141
|
|
|
89
142
|
export function boot() {
|
|
90
143
|
// Register the container
|
|
91
144
|
const container = makeContainer();
|
|
92
145
|
|
|
93
|
-
//
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const extData = fn(23);
|
|
146
|
+
// getExternalUserData1 has type "(id: number): IUser" as we curried out the apiKey param
|
|
147
|
+
const getExternalUserData1 = container.get('getExternalUserData1');
|
|
148
|
+
const userData = getExternalUserData1(23);
|
|
149
|
+
return userData;
|
|
98
150
|
}
|
|
99
151
|
|
|
100
152
|
boot();
|
|
@@ -110,22 +162,28 @@ boot();
|
|
|
110
162
|
```TypeScript
|
|
111
163
|
import { containerFactory, containerRegister, containerRegisterFunctionResolver } from '@rocketmakers/ioc';
|
|
112
164
|
|
|
165
|
+
// Application Types
|
|
113
166
|
import { AdminController } from '../controller/admin';
|
|
114
167
|
import { AdminService } from '../service/admin';
|
|
115
|
-
import {
|
|
168
|
+
import { getExternalUserData } from '../service/external-api';
|
|
116
169
|
import { ControllerContainerTypes } from './types';
|
|
117
170
|
|
|
171
|
+
/** @deprecated LEGACY: Create register helper */
|
|
118
172
|
export const register = containerRegister<ControllerContainerTypes>();
|
|
173
|
+
/** @deprecated LEGACY: Create function resolver */
|
|
119
174
|
export const functionResolver = containerRegisterFunctionResolver<ControllerContainerTypes>();
|
|
175
|
+
/** @deprecated LEGACY: Create register container */
|
|
120
176
|
export const container = containerFactory<ControllerContainerTypes>();
|
|
121
177
|
|
|
122
178
|
export function registerIoC(): void {
|
|
179
|
+
// Register all the keys of the 'ControllerContainerTypes'
|
|
180
|
+
register.constant('id', 31313);
|
|
181
|
+
register.constant('apiKey', 'xyz...');
|
|
123
182
|
register.class('adminService', AdminService).construct([]).inSingletonScope();
|
|
124
183
|
register.class('adminController', AdminController).construct(['adminService']).inSingletonScope();
|
|
125
|
-
|
|
126
|
-
register.
|
|
127
|
-
|
|
128
|
-
register.function('getExternalData', functionResolver.curry1(getExternalData, 'apiKey'));
|
|
184
|
+
register.function('getExternalUserData', getExternalUserData);
|
|
185
|
+
register.function('getExternalUserData1', functionResolver.curry1(getExternalUserData, 'apiKey'));
|
|
186
|
+
register.function('getExternalUserData2', functionResolver.curry2(getExternalUserData, 'apiKey', 'id'));
|
|
129
187
|
}
|
|
130
188
|
|
|
131
189
|
```
|
|
@@ -133,17 +191,17 @@ export function registerIoC(): void {
|
|
|
133
191
|
### Resolving with the container
|
|
134
192
|
|
|
135
193
|
```TypeScript
|
|
136
|
-
import { container, registerIoC } from './ioc/register';
|
|
194
|
+
import { container, registerIoC } from './ioc/register-legacy';
|
|
137
195
|
|
|
138
196
|
export function boot() {
|
|
139
197
|
// Register the container
|
|
140
198
|
registerIoC();
|
|
141
199
|
|
|
142
|
-
//
|
|
143
|
-
const
|
|
200
|
+
// getExternalUserData has type "(id: number): IUser" as we curried out the apiKey param
|
|
201
|
+
const getExternalUserData1 = container.get('getExternalUserData1');
|
|
144
202
|
|
|
145
|
-
|
|
146
|
-
|
|
203
|
+
const userData = getExternalUserData1(23);
|
|
204
|
+
return userData;
|
|
147
205
|
}
|
|
148
206
|
|
|
149
207
|
boot();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Binder } from './binder';
|
|
2
|
+
import { NewableOf, TupleToKeysOfMapped } from './types';
|
|
3
|
+
/** @deprecated LEGACY: Using older method of class binding */
|
|
4
|
+
export declare class LegacyBinder<T, TItem, TDep> extends Binder<T, TItem, TDep> {
|
|
5
|
+
/** Register a class */
|
|
6
|
+
classOld<C extends NewableOf<TItem>>(cls: C): {
|
|
7
|
+
construct(keys: TupleToKeysOfMapped<ConstructorParameters<C>, T & TDep>): import("./inversify").BindingInWhenOnSyntax<InstanceType<C>>;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LegacyBinder = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var binder_1 = require("./binder");
|
|
6
|
+
var inversify_1 = require("./inversify");
|
|
7
|
+
/** @deprecated LEGACY: Using older method of class binding */
|
|
8
|
+
var LegacyBinder = /** @class */ (function (_super) {
|
|
9
|
+
tslib_1.__extends(LegacyBinder, _super);
|
|
10
|
+
function LegacyBinder() {
|
|
11
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
12
|
+
}
|
|
13
|
+
/** Register a class */
|
|
14
|
+
LegacyBinder.prototype.classOld = function (cls) {
|
|
15
|
+
var k = this.key;
|
|
16
|
+
var t = this.keyTransformer;
|
|
17
|
+
return {
|
|
18
|
+
construct: function (keys) {
|
|
19
|
+
var keys1 = keys;
|
|
20
|
+
return (0, inversify_1.registerClass)(k, cls, keys1.map(t));
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
return LegacyBinder;
|
|
25
|
+
}(binder_1.Binder));
|
|
26
|
+
exports.LegacyBinder = LegacyBinder;
|
package/lib/binder.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Curried1, Param1 } from './curry.generated';
|
|
2
|
+
import { Func, IFunctionResolver } from './tail.generated';
|
|
3
|
+
import { NewableOf, TupleToKeysOfMapped } from './types';
|
|
4
|
+
declare type CollectCurriedParams<TOriginal extends Func, TCurried, TCollect extends any[] = []> = TOriginal extends TCurried ? TCollect : CollectCurriedParams<Curried1<TOriginal>, TCurried, [...TCollect, Param1<Parameters<TOriginal>>]>;
|
|
5
|
+
export declare class Binder<T, TItem, TDep> {
|
|
6
|
+
protected key: string;
|
|
7
|
+
protected keyTransformer: (keyName: string) => string;
|
|
8
|
+
constructor(key: string, keyTransformer: (keyName: string) => string);
|
|
9
|
+
/** Gets the underlying container binding to the specified key */
|
|
10
|
+
get binding(): import("inversify/dts/interfaces/interfaces").interfaces.BindingToSyntax<TItem>;
|
|
11
|
+
/** Register a function */
|
|
12
|
+
function(item: TItem): import("inversify/dts/interfaces/interfaces").interfaces.BindingWhenOnSyntax<TItem>;
|
|
13
|
+
/** Register a function resolver */
|
|
14
|
+
functionResolver(item: IFunctionResolver<TItem>): import("inversify/dts/interfaces/interfaces").interfaces.BindingWhenOnSyntax<TItem>;
|
|
15
|
+
/** Register a constant */
|
|
16
|
+
constant(item: TItem): import("inversify/dts/interfaces/interfaces").interfaces.BindingWhenOnSyntax<TItem>;
|
|
17
|
+
/** Register a curried function */
|
|
18
|
+
functionCurry<TFn extends Func>(item: TFn, params: TupleToKeysOfMapped<CollectCurriedParams<TFn, TItem>, T & TDep>): import("inversify/dts/interfaces/interfaces").interfaces.BindingWhenOnSyntax<TItem>;
|
|
19
|
+
/** Register a class */
|
|
20
|
+
class<C extends NewableOf<TItem>>(cls: C, params: TupleToKeysOfMapped<ConstructorParameters<C>, T & TDep>): import("./inversify").BindingInWhenOnSyntax<InstanceType<C>>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
package/lib/binder.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Binder = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var curry_1 = require("./curry");
|
|
6
|
+
var inversify_1 = require("./inversify");
|
|
7
|
+
var internalContainer = (0, inversify_1.getGlobalContainer)();
|
|
8
|
+
var Binder = /** @class */ (function () {
|
|
9
|
+
function Binder(key, keyTransformer) {
|
|
10
|
+
this.key = key;
|
|
11
|
+
this.keyTransformer = keyTransformer;
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(Binder.prototype, "binding", {
|
|
14
|
+
/** Gets the underlying container binding to the specified key */
|
|
15
|
+
get: function () {
|
|
16
|
+
return internalContainer.bind(this.key);
|
|
17
|
+
},
|
|
18
|
+
enumerable: false,
|
|
19
|
+
configurable: true
|
|
20
|
+
});
|
|
21
|
+
/** Register a function */
|
|
22
|
+
Binder.prototype.function = function (item) {
|
|
23
|
+
return this.binding.toFunction(item);
|
|
24
|
+
};
|
|
25
|
+
/** Register a function resolver */
|
|
26
|
+
Binder.prototype.functionResolver = function (item) {
|
|
27
|
+
return this.binding.toFactory(function () { return item.resolved(); });
|
|
28
|
+
};
|
|
29
|
+
/** Register a constant */
|
|
30
|
+
Binder.prototype.constant = function (item) {
|
|
31
|
+
return this.binding.toConstantValue(item);
|
|
32
|
+
};
|
|
33
|
+
/** Register a curried function */
|
|
34
|
+
Binder.prototype.functionCurry = function (item, params) {
|
|
35
|
+
var keys = params;
|
|
36
|
+
return this.functionResolver(curry_1.curryInner.apply(void 0, tslib_1.__spreadArray([item], keys.map(this.keyTransformer), false)));
|
|
37
|
+
};
|
|
38
|
+
/** Register a class */
|
|
39
|
+
Binder.prototype.class = function (cls, params) {
|
|
40
|
+
var keys = params;
|
|
41
|
+
return (0, inversify_1.registerClass)(this.key, cls, keys.map(this.keyTransformer));
|
|
42
|
+
};
|
|
43
|
+
return Binder;
|
|
44
|
+
}());
|
|
45
|
+
exports.Binder = Binder;
|
package/lib/curry.d.ts
ADDED
package/lib/curry.generated.d.ts
CHANGED
|
@@ -1,83 +1,143 @@
|
|
|
1
|
+
/** Returns a mapped type that removes the first element from the type array */
|
|
1
2
|
export declare type Tail1<T extends any[]> = ((...t: T) => any) extends (_1: any, ...tail: infer TTail) => any ? TTail : [
|
|
2
3
|
];
|
|
4
|
+
/** Returns a mapped type that removes the first 2 elements from the type array */
|
|
3
5
|
export declare type Tail2<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, ...tail: infer TTail) => any ? TTail : [
|
|
4
6
|
];
|
|
7
|
+
/** Returns a mapped type that removes the first 3 elements from the type array */
|
|
5
8
|
export declare type Tail3<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, ...tail: infer TTail) => any ? TTail : [
|
|
6
9
|
];
|
|
10
|
+
/** Returns a mapped type that removes the first 4 elements from the type array */
|
|
7
11
|
export declare type Tail4<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, ...tail: infer TTail) => any ? TTail : [
|
|
8
12
|
];
|
|
13
|
+
/** Returns a mapped type that removes the first 5 elements from the type array */
|
|
9
14
|
export declare type Tail5<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, ...tail: infer TTail) => any ? TTail : [
|
|
10
15
|
];
|
|
16
|
+
/** Returns a mapped type that removes the first 6 elements from the type array */
|
|
11
17
|
export declare type Tail6<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, ...tail: infer TTail) => any ? TTail : [
|
|
12
18
|
];
|
|
19
|
+
/** Returns a mapped type that removes the first 7 elements from the type array */
|
|
13
20
|
export declare type Tail7<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, ...tail: infer TTail) => any ? TTail : [
|
|
14
21
|
];
|
|
22
|
+
/** Returns a mapped type that removes the first 8 elements from the type array */
|
|
15
23
|
export declare type Tail8<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, ...tail: infer TTail) => any ? TTail : [
|
|
16
24
|
];
|
|
25
|
+
/** Returns a mapped type that removes the first 9 elements from the type array */
|
|
17
26
|
export declare type Tail9<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, ...tail: infer TTail) => any ? TTail : [
|
|
18
27
|
];
|
|
28
|
+
/** Returns a mapped type that removes the first 10 elements from the type array */
|
|
19
29
|
export declare type Tail10<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, ...tail: infer TTail) => any ? TTail : [
|
|
20
30
|
];
|
|
31
|
+
/** Returns a mapped type that removes the first 11 elements from the type array */
|
|
21
32
|
export declare type Tail11<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, _11: any, ...tail: infer TTail) => any ? TTail : [
|
|
22
33
|
];
|
|
34
|
+
/** Returns a mapped type that removes the first 12 elements from the type array */
|
|
23
35
|
export declare type Tail12<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, _11: any, _12: any, ...tail: infer TTail) => any ? TTail : [
|
|
24
36
|
];
|
|
37
|
+
/** Returns a mapped type that removes the first 13 elements from the type array */
|
|
25
38
|
export declare type Tail13<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, _11: any, _12: any, _13: any, ...tail: infer TTail) => any ? TTail : [
|
|
26
39
|
];
|
|
40
|
+
/** Returns a mapped type that removes the first 14 elements from the type array */
|
|
27
41
|
export declare type Tail14<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, _11: any, _12: any, _13: any, _14: any, ...tail: infer TTail) => any ? TTail : [
|
|
28
42
|
];
|
|
43
|
+
/** Returns a mapped type that removes the first 15 elements from the type array */
|
|
29
44
|
export declare type Tail15<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, _11: any, _12: any, _13: any, _14: any, _15: any, ...tail: infer TTail) => any ? TTail : [
|
|
30
45
|
];
|
|
46
|
+
/** Returns a mapped type that removes the first 16 elements from the type array */
|
|
31
47
|
export declare type Tail16<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, _11: any, _12: any, _13: any, _14: any, _15: any, _16: any, ...tail: infer TTail) => any ? TTail : [
|
|
32
48
|
];
|
|
49
|
+
/** Returns a mapped type that removes the first 17 elements from the type array */
|
|
33
50
|
export declare type Tail17<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, _11: any, _12: any, _13: any, _14: any, _15: any, _16: any, _17: any, ...tail: infer TTail) => any ? TTail : [
|
|
34
51
|
];
|
|
52
|
+
/** Returns a mapped type that removes the first 18 elements from the type array */
|
|
35
53
|
export declare type Tail18<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, _11: any, _12: any, _13: any, _14: any, _15: any, _16: any, _17: any, _18: any, ...tail: infer TTail) => any ? TTail : [
|
|
36
54
|
];
|
|
55
|
+
/** Returns a mapped type that removes the first 19 elements from the type array */
|
|
37
56
|
export declare type Tail19<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, _11: any, _12: any, _13: any, _14: any, _15: any, _16: any, _17: any, _18: any, _19: any, ...tail: infer TTail) => any ? TTail : [
|
|
38
57
|
];
|
|
58
|
+
/** Returns a mapped type that removes the first 20 elements from the type array */
|
|
39
59
|
export declare type Tail20<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, _4: any, _5: any, _6: any, _7: any, _8: any, _9: any, _10: any, _11: any, _12: any, _13: any, _14: any, _15: any, _16: any, _17: any, _18: any, _19: any, _20: any, ...tail: infer TTail) => any ? TTail : [
|
|
40
60
|
];
|
|
61
|
+
/** Returns a mapped type of the function that removes the first parameter from the method */
|
|
41
62
|
export declare type Curried1<T extends (...args: any[]) => any> = (...tail: Tail1<Parameters<T>>) => ReturnType<T>;
|
|
63
|
+
/** Returns a mapped type of the function that removes the first 2 parameters from the method */
|
|
42
64
|
export declare type Curried2<T extends (...args: any[]) => any> = (...tail: Tail2<Parameters<T>>) => ReturnType<T>;
|
|
65
|
+
/** Returns a mapped type of the function that removes the first 3 parameters from the method */
|
|
43
66
|
export declare type Curried3<T extends (...args: any[]) => any> = (...tail: Tail3<Parameters<T>>) => ReturnType<T>;
|
|
67
|
+
/** Returns a mapped type of the function that removes the first 4 parameters from the method */
|
|
44
68
|
export declare type Curried4<T extends (...args: any[]) => any> = (...tail: Tail4<Parameters<T>>) => ReturnType<T>;
|
|
69
|
+
/** Returns a mapped type of the function that removes the first 5 parameters from the method */
|
|
45
70
|
export declare type Curried5<T extends (...args: any[]) => any> = (...tail: Tail5<Parameters<T>>) => ReturnType<T>;
|
|
71
|
+
/** Returns a mapped type of the function that removes the first 6 parameters from the method */
|
|
46
72
|
export declare type Curried6<T extends (...args: any[]) => any> = (...tail: Tail6<Parameters<T>>) => ReturnType<T>;
|
|
73
|
+
/** Returns a mapped type of the function that removes the first 7 parameters from the method */
|
|
47
74
|
export declare type Curried7<T extends (...args: any[]) => any> = (...tail: Tail7<Parameters<T>>) => ReturnType<T>;
|
|
75
|
+
/** Returns a mapped type of the function that removes the first 8 parameters from the method */
|
|
48
76
|
export declare type Curried8<T extends (...args: any[]) => any> = (...tail: Tail8<Parameters<T>>) => ReturnType<T>;
|
|
77
|
+
/** Returns a mapped type of the function that removes the first 9 parameters from the method */
|
|
49
78
|
export declare type Curried9<T extends (...args: any[]) => any> = (...tail: Tail9<Parameters<T>>) => ReturnType<T>;
|
|
79
|
+
/** Returns a mapped type of the function that removes the first 10 parameters from the method */
|
|
50
80
|
export declare type Curried10<T extends (...args: any[]) => any> = (...tail: Tail10<Parameters<T>>) => ReturnType<T>;
|
|
81
|
+
/** Returns a mapped type of the function that removes the first 11 parameters from the method */
|
|
51
82
|
export declare type Curried11<T extends (...args: any[]) => any> = (...tail: Tail11<Parameters<T>>) => ReturnType<T>;
|
|
83
|
+
/** Returns a mapped type of the function that removes the first 12 parameters from the method */
|
|
52
84
|
export declare type Curried12<T extends (...args: any[]) => any> = (...tail: Tail12<Parameters<T>>) => ReturnType<T>;
|
|
85
|
+
/** Returns a mapped type of the function that removes the first 13 parameters from the method */
|
|
53
86
|
export declare type Curried13<T extends (...args: any[]) => any> = (...tail: Tail13<Parameters<T>>) => ReturnType<T>;
|
|
87
|
+
/** Returns a mapped type of the function that removes the first 14 parameters from the method */
|
|
54
88
|
export declare type Curried14<T extends (...args: any[]) => any> = (...tail: Tail14<Parameters<T>>) => ReturnType<T>;
|
|
89
|
+
/** Returns a mapped type of the function that removes the first 15 parameters from the method */
|
|
55
90
|
export declare type Curried15<T extends (...args: any[]) => any> = (...tail: Tail15<Parameters<T>>) => ReturnType<T>;
|
|
91
|
+
/** Returns a mapped type of the function that removes the first 16 parameters from the method */
|
|
56
92
|
export declare type Curried16<T extends (...args: any[]) => any> = (...tail: Tail16<Parameters<T>>) => ReturnType<T>;
|
|
93
|
+
/** Returns a mapped type of the function that removes the first 17 parameters from the method */
|
|
57
94
|
export declare type Curried17<T extends (...args: any[]) => any> = (...tail: Tail17<Parameters<T>>) => ReturnType<T>;
|
|
95
|
+
/** Returns a mapped type of the function that removes the first 18 parameters from the method */
|
|
58
96
|
export declare type Curried18<T extends (...args: any[]) => any> = (...tail: Tail18<Parameters<T>>) => ReturnType<T>;
|
|
97
|
+
/** Returns a mapped type of the function that removes the first 19 parameters from the method */
|
|
59
98
|
export declare type Curried19<T extends (...args: any[]) => any> = (...tail: Tail19<Parameters<T>>) => ReturnType<T>;
|
|
99
|
+
/** Returns a mapped type of the function that removes the first 20 parameters from the method */
|
|
60
100
|
export declare type Curried20<T extends (...args: any[]) => any> = (...tail: Tail20<Parameters<T>>) => ReturnType<T>;
|
|
101
|
+
/** Returns the type in position 1 of the type array */
|
|
61
102
|
export declare type Param1<T extends any[]> = T extends [
|
|
62
103
|
any,
|
|
63
104
|
...any[]
|
|
64
105
|
] ? T[0] : never;
|
|
106
|
+
/** Returns the type in position 2 of the type array */
|
|
65
107
|
export declare type Param2<T extends any[]> = Param1<Tail1<T>>;
|
|
108
|
+
/** Returns the type in position 3 of the type array */
|
|
66
109
|
export declare type Param3<T extends any[]> = Param1<Tail2<T>>;
|
|
110
|
+
/** Returns the type in position 4 of the type array */
|
|
67
111
|
export declare type Param4<T extends any[]> = Param1<Tail3<T>>;
|
|
112
|
+
/** Returns the type in position 5 of the type array */
|
|
68
113
|
export declare type Param5<T extends any[]> = Param1<Tail4<T>>;
|
|
114
|
+
/** Returns the type in position 6 of the type array */
|
|
69
115
|
export declare type Param6<T extends any[]> = Param1<Tail5<T>>;
|
|
116
|
+
/** Returns the type in position 7 of the type array */
|
|
70
117
|
export declare type Param7<T extends any[]> = Param1<Tail6<T>>;
|
|
118
|
+
/** Returns the type in position 8 of the type array */
|
|
71
119
|
export declare type Param8<T extends any[]> = Param1<Tail7<T>>;
|
|
120
|
+
/** Returns the type in position 9 of the type array */
|
|
72
121
|
export declare type Param9<T extends any[]> = Param1<Tail8<T>>;
|
|
122
|
+
/** Returns the type in position 10 of the type array */
|
|
73
123
|
export declare type Param10<T extends any[]> = Param1<Tail9<T>>;
|
|
124
|
+
/** Returns the type in position 11 of the type array */
|
|
74
125
|
export declare type Param11<T extends any[]> = Param1<Tail10<T>>;
|
|
126
|
+
/** Returns the type in position 12 of the type array */
|
|
75
127
|
export declare type Param12<T extends any[]> = Param1<Tail11<T>>;
|
|
128
|
+
/** Returns the type in position 13 of the type array */
|
|
76
129
|
export declare type Param13<T extends any[]> = Param1<Tail12<T>>;
|
|
130
|
+
/** Returns the type in position 14 of the type array */
|
|
77
131
|
export declare type Param14<T extends any[]> = Param1<Tail13<T>>;
|
|
132
|
+
/** Returns the type in position 15 of the type array */
|
|
78
133
|
export declare type Param15<T extends any[]> = Param1<Tail14<T>>;
|
|
134
|
+
/** Returns the type in position 16 of the type array */
|
|
79
135
|
export declare type Param16<T extends any[]> = Param1<Tail15<T>>;
|
|
136
|
+
/** Returns the type in position 17 of the type array */
|
|
80
137
|
export declare type Param17<T extends any[]> = Param1<Tail16<T>>;
|
|
138
|
+
/** Returns the type in position 18 of the type array */
|
|
81
139
|
export declare type Param18<T extends any[]> = Param1<Tail17<T>>;
|
|
140
|
+
/** Returns the type in position 19 of the type array */
|
|
82
141
|
export declare type Param19<T extends any[]> = Param1<Tail18<T>>;
|
|
142
|
+
/** Returns the type in position 20 of the type array */
|
|
83
143
|
export declare type Param20<T extends any[]> = Param1<Tail19<T>>;
|
package/lib/curry.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.curryInner = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var inversify_1 = require("./inversify");
|
|
6
|
+
var internalContainer = (0, inversify_1.getGlobalContainer)();
|
|
7
|
+
function curryInner(fn) {
|
|
8
|
+
var keys = [];
|
|
9
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
10
|
+
keys[_i - 1] = arguments[_i];
|
|
11
|
+
}
|
|
12
|
+
var curried;
|
|
13
|
+
return {
|
|
14
|
+
resolved: function () {
|
|
15
|
+
if (!curried) {
|
|
16
|
+
var values_1 = keys.map(function (k) { return internalContainer.get(k); });
|
|
17
|
+
curried = function () {
|
|
18
|
+
var p = [];
|
|
19
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
20
|
+
p[_i] = arguments[_i];
|
|
21
|
+
}
|
|
22
|
+
return fn.apply(fn, tslib_1.__spreadArray(tslib_1.__spreadArray([], values_1, true), p, true));
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return curried;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.curryInner = curryInner;
|
package/lib/error.d.ts
ADDED
package/lib/error.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IocDuplicateKeyError = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var IocDuplicateKeyError = /** @class */ (function (_super) {
|
|
6
|
+
tslib_1.__extends(IocDuplicateKeyError, _super);
|
|
7
|
+
function IocDuplicateKeyError(duplicateKeys) {
|
|
8
|
+
var _newTarget = this.constructor;
|
|
9
|
+
var _this = _super.call(this) || this;
|
|
10
|
+
_this.duplicateKeys = duplicateKeys;
|
|
11
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
12
|
+
_this.message = "Duplicate keys found\n".concat(duplicateKeys.join("\n"));
|
|
13
|
+
if (Error.captureStackTrace !== undefined) {
|
|
14
|
+
Error.captureStackTrace(_this, _this.constructor);
|
|
15
|
+
}
|
|
16
|
+
return _this;
|
|
17
|
+
}
|
|
18
|
+
return IocDuplicateKeyError;
|
|
19
|
+
}(Error));
|
|
20
|
+
exports.IocDuplicateKeyError = IocDuplicateKeyError;
|