@rocketmakers/ioc 0.1.7 → 0.3.3
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 +150 -29
- 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 +143 -0
- package/lib/curry.generated.js +2 -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 +61 -116
- package/lib/index.js +90 -149
- package/lib/inversify.d.ts +30 -0
- package/lib/inversify.js +64 -0
- package/lib/prefix.d.ts +17 -0
- package/lib/prefix.js +23 -0
- package/lib/tail.generated.d.ts +51 -0
- package/lib/tail.generated.js +88 -0
- package/lib/types.d.ts +9 -0
- package/lib/types.js +2 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -10,12 +10,16 @@ This package provides helper methods for inversify (https://inversify.io/) to:
|
|
|
10
10
|
|
|
11
11
|
You should first create a type that describes your Container items, then create a `containerRegister` to help you to register those types.
|
|
12
12
|
|
|
13
|
+
## Application
|
|
13
14
|
|
|
14
15
|
`service/admin.ts`
|
|
15
16
|
```TypeScript
|
|
16
17
|
export class AdminService {
|
|
17
|
-
|
|
18
|
+
doSomething(value: number) {
|
|
19
|
+
return Math.round(value);
|
|
20
|
+
}
|
|
18
21
|
}
|
|
22
|
+
|
|
19
23
|
```
|
|
20
24
|
|
|
21
25
|
`controller/admin.ts`
|
|
@@ -23,68 +27,185 @@ export class AdminService {
|
|
|
23
27
|
import { AdminService } from '../service/admin';
|
|
24
28
|
|
|
25
29
|
export class AdminController {
|
|
26
|
-
constructor(private
|
|
30
|
+
constructor(private adminService: AdminService) {}
|
|
27
31
|
}
|
|
32
|
+
|
|
28
33
|
```
|
|
29
34
|
|
|
30
35
|
`service/external-api.ts`
|
|
31
36
|
```TypeScript
|
|
37
|
+
import { fetchUserData, IUser } from './external';
|
|
38
|
+
|
|
32
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!
|
|
33
|
-
export function
|
|
34
|
-
|
|
40
|
+
export function getExternalUserData(apiKey: string, id: number): IUser {
|
|
41
|
+
return fetchUserData(apiKey, id);
|
|
35
42
|
}
|
|
36
|
-
```
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
```
|
|
45
|
+
`ioc/types.ts`
|
|
39
46
|
```TypeScript
|
|
40
|
-
import
|
|
41
|
-
import type { getExternalData } from '../service/external-api';
|
|
42
|
-
import type { AdminController } from '../controller/admin';
|
|
47
|
+
import { Curried1, Curried2 } from '@rocketmakers/ioc';
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
// Application Types
|
|
50
|
+
import type { AdminController } from '../controller/admin';
|
|
51
|
+
import type { AdminService } from '../service/admin';
|
|
52
|
+
import type { getExternalUserData } from '../service/external-api';
|
|
45
53
|
|
|
54
|
+
/** Define the types registered within the container */
|
|
46
55
|
export type ControllerContainerTypes = {
|
|
56
|
+
id: number;
|
|
57
|
+
apiKey: string;
|
|
47
58
|
adminService: AdminService;
|
|
48
59
|
adminController: AdminController;
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
getExternalUserData: typeof getExternalUserData;
|
|
61
|
+
getExternalUserData1: Curried1<typeof getExternalUserData>;
|
|
62
|
+
getExternalUserData2: Curried2<typeof getExternalUserData>;
|
|
51
63
|
};
|
|
52
64
|
|
|
53
|
-
export const register = containerRegister<ControllerContainerTypes>();
|
|
54
|
-
export const functionResolver = containerRegisterFunctionResolver<ContainerTypes>();
|
|
55
|
-
export const container = containerFactory<ContainerTypes>();
|
|
56
65
|
```
|
|
57
66
|
|
|
58
|
-
## Registration
|
|
67
|
+
## Registration (IoC Container Modules)
|
|
59
68
|
|
|
69
|
+
### Building the container
|
|
60
70
|
|
|
61
71
|
`ioc/register.ts`
|
|
62
72
|
```TypeScript
|
|
73
|
+
import { IContainer, register } from '@rocketmakers/ioc';
|
|
74
|
+
|
|
75
|
+
import { AdminController } from '../controller/admin';
|
|
63
76
|
import { AdminService } from '../service/admin';
|
|
64
|
-
import {
|
|
77
|
+
import { getExternalUserData } from '../service/external-api';
|
|
78
|
+
import { ControllerContainerTypes } from './types';
|
|
79
|
+
|
|
80
|
+
export function makeContainer(): IContainer<ControllerContainerTypes> {
|
|
81
|
+
// Register all the keys of the 'ControllerContainerTypes'
|
|
82
|
+
return register<ControllerContainerTypes>({
|
|
83
|
+
id: b => b.constant(31313),
|
|
84
|
+
apiKey: b => b.constant('xyz...'),
|
|
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
|
+
|
|
65
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']),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
66
116
|
|
|
67
|
-
|
|
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');
|
|
68
134
|
|
|
69
|
-
|
|
70
|
-
register.class('adminService', AdminService).construct([]).inSingletonScope();
|
|
71
|
-
register.class('adminController', AdminController).construct(['adminService']).inSingletonScope();
|
|
135
|
+
```
|
|
72
136
|
|
|
73
|
-
|
|
137
|
+
### Resolving with the container
|
|
74
138
|
|
|
75
|
-
|
|
139
|
+
```TypeScript
|
|
140
|
+
import { makeContainer } from './ioc/register';
|
|
141
|
+
|
|
142
|
+
export function boot() {
|
|
143
|
+
// Register the container
|
|
144
|
+
const container = makeContainer();
|
|
145
|
+
|
|
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;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
boot();
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
## Registration (Legacy)
|
|
158
|
+
|
|
159
|
+
### Building the container
|
|
160
|
+
|
|
161
|
+
`ioc/register.ts`
|
|
162
|
+
```TypeScript
|
|
163
|
+
import { containerFactory, containerRegister, containerRegisterFunctionResolver } from '@rocketmakers/ioc';
|
|
164
|
+
|
|
165
|
+
// Application Types
|
|
166
|
+
import { AdminController } from '../controller/admin';
|
|
167
|
+
import { AdminService } from '../service/admin';
|
|
168
|
+
import { getExternalUserData } from '../service/external-api';
|
|
169
|
+
import { ControllerContainerTypes } from './types';
|
|
170
|
+
|
|
171
|
+
/** @deprecated LEGACY: Create register helper */
|
|
172
|
+
export const register = containerRegister<ControllerContainerTypes>();
|
|
173
|
+
/** @deprecated LEGACY: Create function resolver */
|
|
174
|
+
export const functionResolver = containerRegisterFunctionResolver<ControllerContainerTypes>();
|
|
175
|
+
/** @deprecated LEGACY: Create register container */
|
|
176
|
+
export const container = containerFactory<ControllerContainerTypes>();
|
|
177
|
+
|
|
178
|
+
export function registerIoC(): void {
|
|
179
|
+
// Register all the keys of the 'ControllerContainerTypes'
|
|
180
|
+
register.constant('id', 31313);
|
|
181
|
+
register.constant('apiKey', 'xyz...');
|
|
182
|
+
register.class('adminService', AdminService).construct([]).inSingletonScope();
|
|
183
|
+
register.class('adminController', AdminController).construct(['adminService']).inSingletonScope();
|
|
184
|
+
register.function('getExternalUserData', getExternalUserData);
|
|
185
|
+
register.function('getExternalUserData1', functionResolver.curry1(getExternalUserData, 'apiKey'));
|
|
186
|
+
register.function('getExternalUserData2', functionResolver.curry2(getExternalUserData, 'apiKey', 'id'));
|
|
76
187
|
}
|
|
188
|
+
|
|
77
189
|
```
|
|
78
190
|
|
|
79
|
-
|
|
191
|
+
### Resolving with the container
|
|
80
192
|
|
|
81
193
|
```TypeScript
|
|
82
|
-
import { container } from '
|
|
194
|
+
import { container, registerIoC } from './ioc/register-legacy';
|
|
195
|
+
|
|
196
|
+
export function boot() {
|
|
197
|
+
// Register the container
|
|
198
|
+
registerIoC();
|
|
83
199
|
|
|
84
|
-
|
|
200
|
+
// getExternalUserData has type "(id: number): IUser" as we curried out the apiKey param
|
|
201
|
+
const getExternalUserData1 = container.get('getExternalUserData1');
|
|
85
202
|
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
// ...
|
|
203
|
+
const userData = getExternalUserData1(23);
|
|
204
|
+
return userData;
|
|
89
205
|
}
|
|
206
|
+
|
|
207
|
+
boot();
|
|
208
|
+
|
|
90
209
|
```
|
|
210
|
+
|
|
211
|
+
|
|
@@ -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
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/** Returns a mapped type that removes the first element from the type array */
|
|
2
|
+
export declare type Tail1<T extends any[]> = ((...t: T) => any) extends (_1: any, ...tail: infer TTail) => any ? TTail : [
|
|
3
|
+
];
|
|
4
|
+
/** Returns a mapped type that removes the first 2 elements from the type array */
|
|
5
|
+
export declare type Tail2<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, ...tail: infer TTail) => any ? TTail : [
|
|
6
|
+
];
|
|
7
|
+
/** Returns a mapped type that removes the first 3 elements from the type array */
|
|
8
|
+
export declare type Tail3<T extends any[]> = ((...t: T) => any) extends (_1: any, _2: any, _3: any, ...tail: infer TTail) => any ? TTail : [
|
|
9
|
+
];
|
|
10
|
+
/** Returns a mapped type that removes the first 4 elements from the type array */
|
|
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 : [
|
|
12
|
+
];
|
|
13
|
+
/** Returns a mapped type that removes the first 5 elements from the type array */
|
|
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 : [
|
|
15
|
+
];
|
|
16
|
+
/** Returns a mapped type that removes the first 6 elements from the type array */
|
|
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 : [
|
|
18
|
+
];
|
|
19
|
+
/** Returns a mapped type that removes the first 7 elements from the type array */
|
|
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 : [
|
|
21
|
+
];
|
|
22
|
+
/** Returns a mapped type that removes the first 8 elements from the type array */
|
|
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 : [
|
|
24
|
+
];
|
|
25
|
+
/** Returns a mapped type that removes the first 9 elements from the type array */
|
|
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 : [
|
|
27
|
+
];
|
|
28
|
+
/** Returns a mapped type that removes the first 10 elements from the type array */
|
|
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 : [
|
|
30
|
+
];
|
|
31
|
+
/** Returns a mapped type that removes the first 11 elements from the type array */
|
|
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 : [
|
|
33
|
+
];
|
|
34
|
+
/** Returns a mapped type that removes the first 12 elements from the type array */
|
|
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 : [
|
|
36
|
+
];
|
|
37
|
+
/** Returns a mapped type that removes the first 13 elements from the type array */
|
|
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 : [
|
|
39
|
+
];
|
|
40
|
+
/** Returns a mapped type that removes the first 14 elements from the type array */
|
|
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 : [
|
|
42
|
+
];
|
|
43
|
+
/** Returns a mapped type that removes the first 15 elements from the type array */
|
|
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 : [
|
|
45
|
+
];
|
|
46
|
+
/** Returns a mapped type that removes the first 16 elements from the type array */
|
|
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 : [
|
|
48
|
+
];
|
|
49
|
+
/** Returns a mapped type that removes the first 17 elements from the type array */
|
|
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 : [
|
|
51
|
+
];
|
|
52
|
+
/** Returns a mapped type that removes the first 18 elements from the type array */
|
|
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 : [
|
|
54
|
+
];
|
|
55
|
+
/** Returns a mapped type that removes the first 19 elements from the type array */
|
|
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 : [
|
|
57
|
+
];
|
|
58
|
+
/** Returns a mapped type that removes the first 20 elements from the type array */
|
|
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 : [
|
|
60
|
+
];
|
|
61
|
+
/** Returns a mapped type of the function that removes the first parameter from the method */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
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 */
|
|
102
|
+
export declare type Param1<T extends any[]> = T extends [
|
|
103
|
+
any,
|
|
104
|
+
...any[]
|
|
105
|
+
] ? T[0] : never;
|
|
106
|
+
/** Returns the type in position 2 of the type array */
|
|
107
|
+
export declare type Param2<T extends any[]> = Param1<Tail1<T>>;
|
|
108
|
+
/** Returns the type in position 3 of the type array */
|
|
109
|
+
export declare type Param3<T extends any[]> = Param1<Tail2<T>>;
|
|
110
|
+
/** Returns the type in position 4 of the type array */
|
|
111
|
+
export declare type Param4<T extends any[]> = Param1<Tail3<T>>;
|
|
112
|
+
/** Returns the type in position 5 of the type array */
|
|
113
|
+
export declare type Param5<T extends any[]> = Param1<Tail4<T>>;
|
|
114
|
+
/** Returns the type in position 6 of the type array */
|
|
115
|
+
export declare type Param6<T extends any[]> = Param1<Tail5<T>>;
|
|
116
|
+
/** Returns the type in position 7 of the type array */
|
|
117
|
+
export declare type Param7<T extends any[]> = Param1<Tail6<T>>;
|
|
118
|
+
/** Returns the type in position 8 of the type array */
|
|
119
|
+
export declare type Param8<T extends any[]> = Param1<Tail7<T>>;
|
|
120
|
+
/** Returns the type in position 9 of the type array */
|
|
121
|
+
export declare type Param9<T extends any[]> = Param1<Tail8<T>>;
|
|
122
|
+
/** Returns the type in position 10 of the type array */
|
|
123
|
+
export declare type Param10<T extends any[]> = Param1<Tail9<T>>;
|
|
124
|
+
/** Returns the type in position 11 of the type array */
|
|
125
|
+
export declare type Param11<T extends any[]> = Param1<Tail10<T>>;
|
|
126
|
+
/** Returns the type in position 12 of the type array */
|
|
127
|
+
export declare type Param12<T extends any[]> = Param1<Tail11<T>>;
|
|
128
|
+
/** Returns the type in position 13 of the type array */
|
|
129
|
+
export declare type Param13<T extends any[]> = Param1<Tail12<T>>;
|
|
130
|
+
/** Returns the type in position 14 of the type array */
|
|
131
|
+
export declare type Param14<T extends any[]> = Param1<Tail13<T>>;
|
|
132
|
+
/** Returns the type in position 15 of the type array */
|
|
133
|
+
export declare type Param15<T extends any[]> = Param1<Tail14<T>>;
|
|
134
|
+
/** Returns the type in position 16 of the type array */
|
|
135
|
+
export declare type Param16<T extends any[]> = Param1<Tail15<T>>;
|
|
136
|
+
/** Returns the type in position 17 of the type array */
|
|
137
|
+
export declare type Param17<T extends any[]> = Param1<Tail16<T>>;
|
|
138
|
+
/** Returns the type in position 18 of the type array */
|
|
139
|
+
export declare type Param18<T extends any[]> = Param1<Tail17<T>>;
|
|
140
|
+
/** Returns the type in position 19 of the type array */
|
|
141
|
+
export declare type Param19<T extends any[]> = Param1<Tail18<T>>;
|
|
142
|
+
/** Returns the type in position 20 of the type array */
|
|
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;
|