##// END OF EJS Templates
working on multi-platform support
cin -
r48:2ef1241803ee di-typescript
parent child
Show More
@@ -0,0 +1,46
1 import { Uuid } from "../Uuid";
2 import { argumentNotEmptyString } from "../safe";
3 import { TraceSource } from "../log/TraceSource";
4
5 export interface RequireFn {
6 (module: string): any;
7 (modules: string[], cb?: (...args: any[]) => any): void;
8 }
9
10 declare const require: RequireFn;
11
12 export const rjs = require;
13
14 declare function define(name: string, modules: string[], cb?: (...args: any[]) => any, eb?: (e) => any): void;
15 declare function define(modules: string[], cb?: (...args: any[]) => any, eb?: (e) => any): void;
16
17 interface RequireJsResolverParams {
18 contextRequire: RequireFn;
19 }
20
21 const trace = TraceSource.get("@implab/core/di/RequireJsHelper");
22
23 export async function createContextRequire(moduleName: string): Promise<RequireFn> {
24 argumentNotEmptyString(moduleName, "moduleName");
25
26 const parts = moduleName.split("/");
27 if (parts[0] === ".")
28 throw new Error("An absolute module path is required");
29
30 if (parts.length > 1)
31 parts.splice(-1, 1, Uuid());
32 else
33 parts.push(Uuid());
34
35 const shim = parts.join("/");
36
37 trace.debug(`define shim ${shim}`);
38
39 return new Promise<RequireFn>(fulfill => {
40 define(shim, ["require"], r => {
41 trace.debug("shim resolved");
42 return r;
43 });
44 require([shim], fulfill);
45 });
46 }
@@ -1,105 +1,111
1 1 if (release != 'rtm') {
2 2 version += "-$release"
3 3 }
4 4
5 5 if(!npmName)
6 6 npmName = name;
7 7
8 8 ext.packageName="$npmScope/$npmName";
9 9
10 10 def packageDir = "$buildDir/dist"
11 11 def distDir = "$packageDir/$platform"
12 12 def testDir = "$packageDir/$platform"
13 13
14 14 task printVersion {
15 println "version: $version"
16 println "packageName: $packageName"
17 println "platform: $platform"
15 doLast {
16 println "version: $version"
17 println "packageName: $packageName"
18 println "platform: $platform"
19 }
18 20 }
19 21
20 22
21 23 task clean {
22 24 doLast {
23 25 delete buildDir
24 26 delete "node_modules/$packageName"
25 27 }
26 28 }
27 29
28 30 task cleanNpm {
29 31 doLast {
30 32 delete 'node_modules'
31 33 }
32 34 }
33 35
34 36 task _npmInstall() {
35 37 inputs.file("package.json")
36 38 outputs.dir("node_modules")
37 39 doLast {
38 40 exec {
39 41 commandLine 'npm', 'install'
40 42 }
41 43 }
42 44 }
43 45
44 46 task _legacyJs(type:Copy) {
45 47 from 'src/js/'
46 48 into distDir
47 49 }
48 50
49 51 task _buildTs(dependsOn: _npmInstall, type:Exec) {
50 52 inputs.dir('src/ts')
51 inputs.file('tsconfig.json')
53 inputs.file('src/tsconfig.json')
52 54 outputs.dir(distDir)
53 55
54 commandLine 'node_modules/.bin/tsc', '-p', 'src/tsconfig.json', '--outDir', distDir
56 commandLine 'node_modules/.bin/tsc',
57 '-p', 'src/tsconfig.json',
58 '--outDir', distDir,
59 '--listFiles',
60 '--traceResolution'
55 61 }
56 62
57 63 task _packageMeta(type: Copy) {
58 64 inputs.property("version", version)
59 65 from('.') {
60 66 include 'package.json', '.npmignore', 'readme.md', 'license', 'history.md'
61 67 }
62 68 into distDir
63 69 doLast {
64 70 exec {
65 71 workingDir distDir
66 72 commandLine 'npm', 'version', version
67 73 }
68 74 }
69 75 }
70 76
71 77 task build(dependsOn: [_legacyJs, _npmInstall, _buildTs, _packageMeta]) {
72 78
73 79 }
74 80
75 81 task _localInstall(dependsOn: build, type: Exec) {
76 82 inputs.file("$distDir/package.json")
77 83 outputs.upToDateWhen {
78 84 new File("$projectDir/node_modules/$packageName").exists()
79 85 }
80 86
81 87 commandLine 'npm', 'install', '--no-save', '--force', distDir
82 88 }
83 89
84 90 task copyJsTests(type: Copy) {
85 91 from 'test/js'
86 92 into testDir
87 93 }
88 94
89 95 task buildTests(dependsOn: _localInstall, type: Exec) {
90 96 inputs.dir('test/ts')
91 97 inputs.file('test/tsconfig.json')
92 98 outputs.dir(testDir)
93 99
94 100 commandLine 'node_modules/.bin/tsc', '-p', 'test/tsconfig.json', '--outDir', distDir
95 101 }
96 102
97 103 task test(dependsOn: [copyJsTests, buildTests], type: Exec) {
98 104 commandLine 'node', 'run-amd-tests.js'
99 105 }
100 106
101 107 task pack(dependsOn: build, type: Exec) {
102 108 workingDir = distDir
103 109
104 110 commandLine 'npm', 'pack'
105 111 } No newline at end of file
@@ -1,450 +1,450
1 1 {
2 2 "name": "@implab/core",
3 3 "version": "0.0.1-dev",
4 4 "lockfileVersion": 1,
5 5 "requires": true,
6 6 "dependencies": {
7 7 "@types/node": {
8 8 "version": "10.12.12",
9 9 "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.12.tgz",
10 10 "integrity": "sha512-Pr+6JRiKkfsFvmU/LK68oBRCQeEg36TyAbPhc2xpez24OOZZCuoIhWGTd39VZy6nGafSbxzGouFPTFD/rR1A0A==",
11 11 "dev": true
12 12 },
13 13 "@types/tape": {
14 14 "version": "4.2.32",
15 15 "resolved": "http://registry.npmjs.org/@types/tape/-/tape-4.2.32.tgz",
16 16 "integrity": "sha512-xil0KO5wkPoixdBWGIGolPv9dekf6dVkjjJLAFYchfKcd4DICou67rgGCIO7wAh3i5Ff/6j9IDgZz+GU9cMaqQ==",
17 17 "dev": true,
18 18 "requires": {
19 19 "@types/node": "*"
20 20 }
21 21 },
22 22 "balanced-match": {
23 23 "version": "1.0.0",
24 24 "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
25 25 "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
26 26 "dev": true
27 27 },
28 28 "brace-expansion": {
29 29 "version": "1.1.11",
30 30 "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
31 31 "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
32 32 "dev": true,
33 33 "requires": {
34 34 "balanced-match": "^1.0.0",
35 35 "concat-map": "0.0.1"
36 36 }
37 37 },
38 38 "concat-map": {
39 39 "version": "0.0.1",
40 40 "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
41 41 "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
42 42 "dev": true
43 43 },
44 44 "core-util-is": {
45 45 "version": "1.0.2",
46 46 "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
47 47 "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
48 48 "dev": true
49 49 },
50 50 "deep-equal": {
51 51 "version": "0.1.2",
52 52 "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-0.1.2.tgz",
53 53 "integrity": "sha1-skbCuApXCkfBG+HZvRBw7IeLh84=",
54 54 "dev": true
55 55 },
56 56 "define-properties": {
57 57 "version": "1.1.3",
58 58 "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
59 59 "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==",
60 60 "dev": true,
61 61 "requires": {
62 62 "object-keys": "^1.0.12"
63 63 },
64 64 "dependencies": {
65 65 "object-keys": {
66 66 "version": "1.0.12",
67 67 "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.12.tgz",
68 68 "integrity": "sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag==",
69 69 "dev": true
70 70 }
71 71 }
72 72 },
73 73 "defined": {
74 74 "version": "0.0.0",
75 75 "resolved": "https://registry.npmjs.org/defined/-/defined-0.0.0.tgz",
76 76 "integrity": "sha1-817qfXBekzuvE7LwOz+D2SFAOz4=",
77 77 "dev": true
78 78 },
79 79 "dojo": {
80 80 "version": "1.14.2",
81 81 "resolved": "https://registry.npmjs.org/dojo/-/dojo-1.14.2.tgz",
82 82 "integrity": "sha512-TI+Ytgfh/VfmHWERp45Jte6NFMdoJTPsvUP/uzJUvAXET8FP2h442LePWWJ/q/xZ4V0V8OtdJhx8It/GB+Zbxg==",
83 83 "dev": true
84 84 },
85 85 "duplexer": {
86 86 "version": "0.1.1",
87 "resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
87 "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
88 88 "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=",
89 89 "dev": true
90 90 },
91 91 "es-abstract": {
92 92 "version": "1.12.0",
93 93 "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.12.0.tgz",
94 94 "integrity": "sha512-C8Fx/0jFmV5IPoMOFPA9P9G5NtqW+4cOPit3MIuvR2t7Ag2K15EJTpxnHAYTzL+aYQJIESYeXZmDBfOBE1HcpA==",
95 95 "dev": true,
96 96 "requires": {
97 97 "es-to-primitive": "^1.1.1",
98 98 "function-bind": "^1.1.1",
99 99 "has": "^1.0.1",
100 100 "is-callable": "^1.1.3",
101 101 "is-regex": "^1.0.4"
102 102 }
103 103 },
104 104 "es-to-primitive": {
105 105 "version": "1.2.0",
106 106 "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz",
107 107 "integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==",
108 108 "dev": true,
109 109 "requires": {
110 110 "is-callable": "^1.1.4",
111 111 "is-date-object": "^1.0.1",
112 112 "is-symbol": "^1.0.2"
113 113 }
114 114 },
115 115 "faucet": {
116 116 "version": "0.0.1",
117 117 "resolved": "https://registry.npmjs.org/faucet/-/faucet-0.0.1.tgz",
118 118 "integrity": "sha1-WX3PHSGJosBiMhtZHo8VHtIDnZw=",
119 119 "dev": true,
120 120 "requires": {
121 121 "defined": "0.0.0",
122 122 "duplexer": "~0.1.1",
123 123 "minimist": "0.0.5",
124 124 "sprintf": "~0.1.3",
125 125 "tap-parser": "~0.4.0",
126 126 "tape": "~2.3.2",
127 127 "through2": "~0.2.3"
128 128 },
129 129 "dependencies": {
130 130 "tape": {
131 131 "version": "2.3.3",
132 "resolved": "http://registry.npmjs.org/tape/-/tape-2.3.3.tgz",
132 "resolved": "https://registry.npmjs.org/tape/-/tape-2.3.3.tgz",
133 133 "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=",
134 134 "dev": true,
135 135 "requires": {
136 136 "deep-equal": "~0.1.0",
137 137 "defined": "~0.0.0",
138 138 "inherits": "~2.0.1",
139 139 "jsonify": "~0.0.0",
140 140 "resumer": "~0.0.0",
141 141 "through": "~2.3.4"
142 142 }
143 143 }
144 144 }
145 145 },
146 146 "for-each": {
147 147 "version": "0.3.3",
148 148 "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",
149 149 "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==",
150 150 "dev": true,
151 151 "requires": {
152 152 "is-callable": "^1.1.3"
153 153 }
154 154 },
155 155 "fs.realpath": {
156 156 "version": "1.0.0",
157 157 "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
158 158 "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
159 159 "dev": true
160 160 },
161 161 "function-bind": {
162 162 "version": "1.1.1",
163 163 "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
164 164 "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
165 165 "dev": true
166 166 },
167 167 "glob": {
168 168 "version": "7.1.3",
169 169 "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
170 170 "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
171 171 "dev": true,
172 172 "requires": {
173 173 "fs.realpath": "^1.0.0",
174 174 "inflight": "^1.0.4",
175 175 "inherits": "2",
176 176 "minimatch": "^3.0.4",
177 177 "once": "^1.3.0",
178 178 "path-is-absolute": "^1.0.0"
179 179 }
180 180 },
181 181 "has": {
182 182 "version": "1.0.3",
183 183 "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
184 184 "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
185 185 "dev": true,
186 186 "requires": {
187 187 "function-bind": "^1.1.1"
188 188 }
189 189 },
190 190 "has-symbols": {
191 191 "version": "1.0.0",
192 192 "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz",
193 193 "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=",
194 194 "dev": true
195 195 },
196 196 "inflight": {
197 197 "version": "1.0.6",
198 198 "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
199 199 "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
200 200 "dev": true,
201 201 "requires": {
202 202 "once": "^1.3.0",
203 203 "wrappy": "1"
204 204 }
205 205 },
206 206 "inherits": {
207 207 "version": "2.0.3",
208 208 "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
209 209 "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
210 210 "dev": true
211 211 },
212 212 "is-callable": {
213 213 "version": "1.1.4",
214 214 "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz",
215 215 "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==",
216 216 "dev": true
217 217 },
218 218 "is-date-object": {
219 219 "version": "1.0.1",
220 220 "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz",
221 221 "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=",
222 222 "dev": true
223 223 },
224 224 "is-regex": {
225 225 "version": "1.0.4",
226 226 "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz",
227 227 "integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=",
228 228 "dev": true,
229 229 "requires": {
230 230 "has": "^1.0.1"
231 231 }
232 232 },
233 233 "is-symbol": {
234 234 "version": "1.0.2",
235 235 "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz",
236 236 "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==",
237 237 "dev": true,
238 238 "requires": {
239 239 "has-symbols": "^1.0.0"
240 240 }
241 241 },
242 242 "isarray": {
243 243 "version": "0.0.1",
244 244 "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
245 245 "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=",
246 246 "dev": true
247 247 },
248 248 "jsonify": {
249 249 "version": "0.0.0",
250 250 "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz",
251 251 "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=",
252 252 "dev": true
253 253 },
254 254 "minimatch": {
255 255 "version": "3.0.4",
256 256 "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
257 257 "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
258 258 "dev": true,
259 259 "requires": {
260 260 "brace-expansion": "^1.1.7"
261 261 }
262 262 },
263 263 "minimist": {
264 264 "version": "0.0.5",
265 265 "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.5.tgz",
266 266 "integrity": "sha1-16oye87PUY+RBqxrjwA/o7zqhWY=",
267 267 "dev": true
268 268 },
269 269 "object-inspect": {
270 270 "version": "1.6.0",
271 271 "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.6.0.tgz",
272 272 "integrity": "sha512-GJzfBZ6DgDAmnuaM3104jR4s1Myxr3Y3zfIyN4z3UdqN69oSRacNK8UhnobDdC+7J2AHCjGwxQubNJfE70SXXQ==",
273 273 "dev": true
274 274 },
275 275 "object-keys": {
276 276 "version": "0.4.0",
277 277 "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-0.4.0.tgz",
278 278 "integrity": "sha1-KKaq50KN0sOpLz2V8hM13SBOAzY=",
279 279 "dev": true
280 280 },
281 281 "once": {
282 282 "version": "1.4.0",
283 283 "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
284 284 "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
285 285 "dev": true,
286 286 "requires": {
287 287 "wrappy": "1"
288 288 }
289 289 },
290 290 "path-is-absolute": {
291 291 "version": "1.0.1",
292 "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
292 "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
293 293 "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
294 294 "dev": true
295 295 },
296 296 "path-parse": {
297 297 "version": "1.0.6",
298 298 "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
299 299 "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
300 300 "dev": true
301 301 },
302 302 "readable-stream": {
303 303 "version": "1.1.14",
304 "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
304 "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
305 305 "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
306 306 "dev": true,
307 307 "requires": {
308 308 "core-util-is": "~1.0.0",
309 309 "inherits": "~2.0.1",
310 310 "isarray": "0.0.1",
311 311 "string_decoder": "~0.10.x"
312 312 }
313 313 },
314 314 "requirejs": {
315 315 "version": "2.3.6",
316 316 "resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.6.tgz",
317 317 "integrity": "sha512-ipEzlWQe6RK3jkzikgCupiTbTvm4S0/CAU5GlgptkN5SO6F3u0UD0K18wy6ErDqiCyP4J4YYe1HuAShvsxePLg==",
318 318 "dev": true
319 319 },
320 320 "resolve": {
321 321 "version": "1.7.1",
322 322 "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.7.1.tgz",
323 323 "integrity": "sha512-c7rwLofp8g1U+h1KNyHL/jicrKg1Ek4q+Lr33AL65uZTinUZHe30D5HlyN5V9NW0JX1D5dXQ4jqW5l7Sy/kGfw==",
324 324 "dev": true,
325 325 "requires": {
326 326 "path-parse": "^1.0.5"
327 327 }
328 328 },
329 329 "resumer": {
330 330 "version": "0.0.0",
331 331 "resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz",
332 332 "integrity": "sha1-8ej0YeQGS6Oegq883CqMiT0HZ1k=",
333 333 "dev": true,
334 334 "requires": {
335 335 "through": "~2.3.4"
336 336 }
337 337 },
338 338 "sprintf": {
339 339 "version": "0.1.5",
340 340 "resolved": "https://registry.npmjs.org/sprintf/-/sprintf-0.1.5.tgz",
341 341 "integrity": "sha1-j4PjmpMXwaUCy324BQ5Rxnn27c8=",
342 342 "dev": true
343 343 },
344 344 "string.prototype.trim": {
345 345 "version": "1.1.2",
346 346 "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.1.2.tgz",
347 347 "integrity": "sha1-0E3iyJ4Tf019IG8Ia17S+ua+jOo=",
348 348 "dev": true,
349 349 "requires": {
350 350 "define-properties": "^1.1.2",
351 351 "es-abstract": "^1.5.0",
352 352 "function-bind": "^1.0.2"
353 353 }
354 354 },
355 355 "string_decoder": {
356 356 "version": "0.10.31",
357 "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
357 "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
358 358 "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
359 359 "dev": true
360 360 },
361 361 "tap-parser": {
362 362 "version": "0.4.3",
363 363 "resolved": "https://registry.npmjs.org/tap-parser/-/tap-parser-0.4.3.tgz",
364 364 "integrity": "sha1-pOrhkMENdsehEZIf84u+TVjwnuo=",
365 365 "dev": true,
366 366 "requires": {
367 367 "inherits": "~2.0.1",
368 368 "readable-stream": "~1.1.11"
369 369 }
370 370 },
371 371 "tape": {
372 372 "version": "4.9.1",
373 373 "resolved": "https://registry.npmjs.org/tape/-/tape-4.9.1.tgz",
374 374 "integrity": "sha512-6fKIXknLpoe/Jp4rzHKFPpJUHDHDqn8jus99IfPnHIjyz78HYlefTGD3b5EkbQzuLfaEvmfPK3IolLgq2xT3kw==",
375 375 "dev": true,
376 376 "requires": {
377 377 "deep-equal": "~1.0.1",
378 378 "defined": "~1.0.0",
379 379 "for-each": "~0.3.3",
380 380 "function-bind": "~1.1.1",
381 381 "glob": "~7.1.2",
382 382 "has": "~1.0.3",
383 383 "inherits": "~2.0.3",
384 384 "minimist": "~1.2.0",
385 385 "object-inspect": "~1.6.0",
386 386 "resolve": "~1.7.1",
387 387 "resumer": "~0.0.0",
388 388 "string.prototype.trim": "~1.1.2",
389 389 "through": "~2.3.8"
390 390 },
391 391 "dependencies": {
392 392 "deep-equal": {
393 393 "version": "1.0.1",
394 394 "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
395 395 "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=",
396 396 "dev": true
397 397 },
398 398 "defined": {
399 399 "version": "1.0.0",
400 400 "resolved": "https://registry.npmjs.org/defined/-/defined-1.0.0.tgz",
401 401 "integrity": "sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=",
402 402 "dev": true
403 403 },
404 404 "minimist": {
405 405 "version": "1.2.0",
406 406 "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
407 407 "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
408 408 "dev": true
409 409 }
410 410 }
411 411 },
412 412 "through": {
413 413 "version": "2.3.8",
414 "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
414 "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
415 415 "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
416 416 "dev": true
417 417 },
418 418 "through2": {
419 419 "version": "0.2.3",
420 "resolved": "http://registry.npmjs.org/through2/-/through2-0.2.3.tgz",
420 "resolved": "https://registry.npmjs.org/through2/-/through2-0.2.3.tgz",
421 421 "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=",
422 422 "dev": true,
423 423 "requires": {
424 424 "readable-stream": "~1.1.9",
425 425 "xtend": "~2.1.1"
426 426 }
427 427 },
428 428 "typescript": {
429 429 "version": "3.2.1",
430 430 "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.1.tgz",
431 431 "integrity": "sha512-jw7P2z/h6aPT4AENXDGjcfHTu5CSqzsbZc6YlUIebTyBAq8XaKp78x7VcSh30xwSCcsu5irZkYZUSFP1MrAMbg==",
432 432 "dev": true
433 433 },
434 434 "wrappy": {
435 435 "version": "1.0.2",
436 436 "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
437 437 "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
438 438 "dev": true
439 439 },
440 440 "xtend": {
441 441 "version": "2.1.2",
442 442 "resolved": "https://registry.npmjs.org/xtend/-/xtend-2.1.2.tgz",
443 443 "integrity": "sha1-bv7MKk2tjmlixJAbM3znuoe10os=",
444 444 "dev": true,
445 445 "requires": {
446 446 "object-keys": "~0.4.0"
447 447 }
448 448 }
449 449 }
450 450 }
@@ -1,267 +1,269
1 1 // Typescript port of the uuid.js
2 2 // Copyright (c) 2018 Sergey Smirnov
3 3 // BSD-2-Clause License https://opensource.org/licenses/BSD-2-Clause
4 4 //
5 5 // uuid.js
6 6 // Copyright (c) 2010-2012 Robert Kieffer
7 7 // MIT License - http://opensource.org/licenses/mit-license.php
8 8
9 declare var window: any;
9 declare const window: any;
10 declare const require;
11 declare const Buffer;
10 12
11 13 const _window: any = "undefined" !== typeof window ? window : null;
12 14
13 15 // Unique ID creation requires a high quality random # generator. We
14 16 // feature
15 17 // detect to determine the best RNG source, normalizing to a function
16 18 // that
17 19 // returns 128-bits of randomness, since that's what's usually required
18 20 let _rng;
19 21
20 22 function setupBrowser() {
21 23 // Allow for MSIE11 msCrypto
22 24 const _crypto = _window.crypto || _window.msCrypto;
23 25
24 26 if (!_rng && _crypto && _crypto.getRandomValues) {
25 27 // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
26 28 //
27 29 // Moderately fast, high quality
28 30 try {
29 31 const _rnds8 = new Uint8Array(16);
30 32 _rng = function whatwgRNG() {
31 33 _crypto.getRandomValues(_rnds8);
32 34 return _rnds8;
33 35 };
34 36 _rng();
35 37 } catch (e) { /**/ }
36 38 }
37 39
38 40 if (!_rng) {
39 41 // Math.random()-based (RNG)
40 42 //
41 43 // If all else fails, use Math.random(). It's fast, but is of
42 44 // unspecified
43 45 // quality.
44 46 const _rnds = new Array(16);
45 47 _rng = () => {
46 48 for (let i = 0, r; i < 16; i++) {
47 49 if ((i & 0x03) === 0) {
48 50 r = Math.random() * 0x100000000;
49 51 }
50 52 _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
51 53 }
52 54
53 55 return _rnds;
54 56 };
55 57 if ("undefined" !== typeof console && console.warn) {
56 58 console.warn("[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()");
57 59 }
58 60 }
59 61 }
60 62
61 63 function setupNode() {
62 64 // Node.js crypto-based RNG -
63 65 // http://nodejs.org/docs/v0.6.2/api/crypto.html
64 66 //
65 67 // Moderately fast, high quality
66 68 if ("function" === typeof require) {
67 69 try {
68 70 const _rb = require("crypto").randomBytes;
69 71 _rng = _rb && (() => _rb(16));
70 72 _rng();
71 73 } catch (e) { /**/ }
72 74 }
73 75 }
74 76
75 77 if (_window) {
76 78 setupBrowser();
77 79 } else {
78 80 setupNode();
79 81 }
80 82
81 83 // Buffer class to use
82 84 const BufferClass = ("function" === typeof Buffer) ? Buffer : Array;
83 85
84 86 // Maps for number <-> hex string conversion
85 87 const _byteToHex = [];
86 88 const _hexToByte = {};
87 89 for (let i = 0; i < 256; i++) {
88 90 _byteToHex[i] = (i + 0x100).toString(16).substr(1);
89 91 _hexToByte[_byteToHex[i]] = i;
90 92 }
91 93
92 94 // **`parse()` - Parse a UUID into it's component bytes**
93 95 export function _parse(s, buf?, offset?): Array<string> {
94 96 const i = (buf && offset) || 0; let ii = 0;
95 97
96 98 buf = buf || [];
97 99 s.toLowerCase().replace(/[0-9a-f]{2}/g, oct => {
98 100 if (ii < 16) { // Don't overflow!
99 101 buf[i + ii++] = _hexToByte[oct];
100 102 }
101 103 });
102 104
103 105 // Zero out remaining bytes if string was short
104 106 while (ii < 16) {
105 107 buf[i + ii++] = 0;
106 108 }
107 109
108 110 return buf;
109 111 }
110 112
111 113 // **`unparse()` - Convert UUID byte array (ala parse()) into a string**
112 114 function _unparse(buf, offset?): string {
113 115 let i = offset || 0; const bth = _byteToHex;
114 116 return bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] +
115 117 bth[buf[i++]] + "-" + bth[buf[i++]] + bth[buf[i++]] + "-" +
116 118 bth[buf[i++]] + bth[buf[i++]] + "-" + bth[buf[i++]] +
117 119 bth[buf[i++]] + "-" + bth[buf[i++]] + bth[buf[i++]] +
118 120 bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]];
119 121 }
120 122
121 123 // **`v1()` - Generate time-based UUID**
122 124 //
123 125 // Inspired by https://github.com/LiosK/UUID.js
124 126 // and http://docs.python.org/library/uuid.html
125 127
126 128 // random #'s we need to init node and clockseq
127 129 const _seedBytes = _rng();
128 130
129 131 // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit =
130 132 // 1)
131 133 const _nodeId = [
132 134 _seedBytes[0] | 0x01,
133 135 _seedBytes[1],
134 136 _seedBytes[2],
135 137 _seedBytes[3],
136 138 _seedBytes[4],
137 139 _seedBytes[5]
138 140 ];
139 141
140 142 // Per 4.2.2, randomize (14 bit) clockseq
141 143 let _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;
142 144
143 145 // Previous uuid creation time
144 146 let _lastMSecs = 0; let _lastNSecs = 0;
145 147
146 148 // See https://github.com/broofa/node-uuid for API details
147 149 export function _v1(options?, buf?, offset?): string {
148 150 let i = buf && offset || 0;
149 151 const b = buf || [];
150 152
151 153 options = options || {};
152 154
153 155 let clockseq = (options.clockseq != null) ? options.clockseq : _clockseq;
154 156
155 157 // UUID timestamps are 100 nano-second units since the Gregorian
156 158 // epoch,
157 159 // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
158 160 // time is handled internally as 'msecs' (integer milliseconds) and
159 161 // 'nsecs'
160 162 // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01
161 163 // 00:00.
162 164 let msecs = (options.msecs != null) ? options.msecs : new Date()
163 165 .getTime();
164 166
165 167 // Per 4.2.1.2, use count of uuid's generated during the current
166 168 // clock
167 169 // cycle to simulate higher resolution clock
168 170 let nsecs = (options.nsecs != null) ? options.nsecs : _lastNSecs + 1;
169 171
170 172 // Time since last uuid creation (in msecs)
171 173 const dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs) / 10000;
172 174
173 175 // Per 4.2.1.2, Bump clockseq on clock regression
174 176 if (dt < 0 && options.clockseq == null) {
175 177 clockseq = clockseq + 1 & 0x3fff;
176 178 }
177 179
178 180 // Reset nsecs if clock regresses (new clockseq) or we've moved onto
179 181 // a new
180 182 // time interval
181 183 if ((dt < 0 || msecs > _lastMSecs) && options.nsecs == null) {
182 184 nsecs = 0;
183 185 }
184 186
185 187 // Per 4.2.1.2 Throw error if too many uuids are requested
186 188 if (nsecs >= 10000) {
187 189 throw new Error(
188 190 "uuid.v1(): Can't create more than 10M uuids/sec");
189 191 }
190 192
191 193 _lastMSecs = msecs;
192 194 _lastNSecs = nsecs;
193 195 _clockseq = clockseq;
194 196
195 197 // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
196 198 msecs += 12219292800000;
197 199
198 200 // `time_low`
199 201 const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
200 202 b[i++] = tl >>> 24 & 0xff;
201 203 b[i++] = tl >>> 16 & 0xff;
202 204 b[i++] = tl >>> 8 & 0xff;
203 205 b[i++] = tl & 0xff;
204 206
205 207 // `time_mid`
206 208 const tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
207 209 b[i++] = tmh >>> 8 & 0xff;
208 210 b[i++] = tmh & 0xff;
209 211
210 212 // `time_high_and_version`
211 213 b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
212 214 b[i++] = tmh >>> 16 & 0xff;
213 215
214 216 // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
215 217 b[i++] = clockseq >>> 8 | 0x80;
216 218
217 219 // `clock_seq_low`
218 220 b[i++] = clockseq & 0xff;
219 221
220 222 // `node`
221 223 const node = options.node || _nodeId;
222 224 for (let n = 0; n < 6; n++) {
223 225 b[i + n] = node[n];
224 226 }
225 227
226 228 return buf ? buf : _unparse(b);
227 229 }
228 230
229 231 // **`v4()` - Generate random UUID**
230 232
231 233 // See https://github.com/broofa/node-uuid for API details
232 234 export function _v4(options?, buf?, offset?): string {
233 235 // Deprecated - 'format' argument, as supported in v1.2
234 236 const i = buf && offset || 0;
235 237
236 238 if (typeof (options) === "string") {
237 239 buf = (options === "binary") ? new BufferClass(16) : null;
238 240 options = null;
239 241 }
240 242 options = options || {};
241 243
242 244 const rnds = options.random || (options.rng || _rng)();
243 245
244 246 // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
245 247 rnds[6] = (rnds[6] & 0x0f) | 0x40;
246 248 rnds[8] = (rnds[8] & 0x3f) | 0x80;
247 249
248 250 // Copy bytes to buffer, if provided
249 251 if (buf) {
250 252 for (let ii = 0; ii < 16; ii++) {
251 253 buf[i + ii] = rnds[ii];
252 254 }
253 255 }
254 256
255 257 return buf || _unparse(rnds);
256 258 }
257 259
258 260 export function Uuid() {
259 261 return _v4();
260 262 }
261 263
262 264 export namespace Uuid {
263 265 export const v4 = _v4;
264 266 export const v1 = _v1;
265 267 export const empty = "00000000-0000-0000-0000-000000000000";
266 268 export const parse = _parse;
267 269 }
@@ -1,353 +1,353
1 1 import {
2 2 ServiceRegistration,
3 3 TypeRegistration,
4 4 FactoryRegistration,
5 5 ServiceMap,
6 6 isDescriptor,
7 7 isDependencyRegistration,
8 8 DependencyRegistration,
9 9 ValueRegistration,
10 10 ActivationType,
11 11 isValueRegistration,
12 12 isTypeRegistration,
13 13 isFactoryRegistration
14 14 } from "./interfaces";
15 15
16 16 import { argumentNotEmptyString, isPrimitive, isPromise, delegate, argumentOfType, argumentNotNull, get } from "../safe";
17 17 import { AggregateDescriptor } from "./AggregateDescriptor";
18 18 import { ValueDescriptor } from "./ValueDescriptor";
19 19 import { Container } from "./Container";
20 20 import { ReferenceDescriptor } from "./ReferenceDescriptor";
21 21 import { TypeServiceDescriptor } from "./TypeServiceDescriptor";
22 22 import { FactoryServiceDescriptor } from "./FactoryServiceDescriptor";
23 import { rjs, createContextRequire, RequireFn } from "./RequireJsHelper";
23 import { rjs, createContextRequire, RequireFn } from "../../amd/ts/RequireJsHelper";
24 24 import { TraceSource } from "../log/TraceSource";
25 25 import { ConfigError } from "./ConfigError";
26 26 import { Cancellation } from "../Cancellation";
27 27
28 28 const trace = TraceSource.get("@implab/core/di/Configuration");
29 29
30 30 async function mapAll(data: object | any[], map?: (v, k) => any): Promise<any> {
31 31 if (data instanceof Array) {
32 32 return Promise.all(map ? data.map(map) : data);
33 33 } else {
34 34 const keys = Object.keys(data);
35 35
36 36 const o: any = {};
37 37
38 38 await Promise.all(keys.map(async k => {
39 39 const v = map ? map(data[k], k) : data[k];
40 40 o[k] = isPromise(v) ? await v : v;
41 41 }));
42 42
43 43 return o;
44 44 }
45 45 }
46 46
47 47 interface MapOf<T> {
48 48 [key: string]: T;
49 49 }
50 50
51 51 type _key = string | number;
52 52
53 53 export class Configuration {
54 54
55 55 _hasInnerDescriptors = false;
56 56
57 57 _container: Container;
58 58
59 59 _path: Array<_key>;
60 60
61 61 _configName: string;
62 62
63 63 _require = rjs;
64 64
65 65 constructor(container: Container) {
66 66 argumentNotNull(container, container);
67 67 this._container = container;
68 68 this._path = [];
69 69 }
70 70
71 71 async loadConfiguration(moduleName: string, ct = Cancellation.none) {
72 72 argumentNotEmptyString(moduleName, "moduleName");
73 73
74 74 trace.log("loadConfiguration {0}", moduleName);
75 75
76 76 this._configName = moduleName;
77 77
78 78 const config = await this._loadModule(moduleName);
79 79
80 80 this._require = await this._createContextRequire(moduleName);
81 81
82 82 let services: ServiceMap;
83 83
84 84 try {
85 85 services = await this._visitRegistrations(config, moduleName);
86 86 } catch (e) {
87 87 throw this._makeError(e);
88 88 }
89 89
90 90 this._container.register(services);
91 91 }
92 92
93 93 async applyConfiguration(data: object, contextRequire?: RequireFn, ct = Cancellation.none) {
94 94 argumentNotNull(data, "data");
95 95
96 96 trace.log("applyConfiguration");
97 97
98 98 this._configName = "$";
99 99
100 100 if (contextRequire)
101 101 this._require = contextRequire;
102 102
103 103 let services: ServiceMap;
104 104
105 105 try {
106 106 services = await this._visitRegistrations(data, "$");
107 107 } catch (e) {
108 108 throw this._makeError(e);
109 109 }
110 110
111 111 this._container.register(services);
112 112 }
113 113
114 114 _makeError(inner) {
115 115 const e = new ConfigError("Failed to load configuration", inner);
116 116 e.configName = this._configName;
117 117 e.path = this._makePath();
118 118 return e;
119 119 }
120 120
121 121 _makePath() {
122 122 return this._path
123 123 .reduce(
124 124 (prev, cur) => typeof cur === "number" ?
125 125 `${prev}[${cur}]` :
126 126 `${prev}.${cur}`
127 127 )
128 128 .toString();
129 129 }
130 130
131 131 async _resolveType(moduleName: string, localName: string) {
132 132 trace.log("resolveType moduleName={0}, localName={1}", moduleName, localName);
133 133 try {
134 134 const m = await this._loadModule(moduleName);
135 135 return localName ? get(localName, m) : m;
136 136 } catch (e) {
137 137 trace.error("Failed to resolve type moduleName={0}, localName={1}", moduleName, localName);
138 138 throw e;
139 139 }
140 140 }
141 141
142 142 async _loadModule(moduleName: string) {
143 143 trace.debug("loadModule {0}", moduleName);
144 144
145 145 const m = await new Promise(fulfill => {
146 146 this._require([moduleName], fulfill);
147 147 });
148 148
149 149 return m;
150 150 }
151 151
152 152 _createContextRequire(moduleName: string) {
153 153 return createContextRequire(moduleName);
154 154 }
155 155
156 156 async _visitRegistrations(data, name: _key) {
157 157 this._enter(name);
158 158
159 159 if (data.constructor &&
160 160 data.constructor.prototype !== Object.prototype)
161 161 throw new Error("Configuration must be a simple object");
162 162
163 163 const o: ServiceMap = {};
164 164 const keys = Object.keys(data);
165 165
166 166 const services = await mapAll(data, async (v, k) => {
167 167 const d = await this._visit(v, k);
168 168 return isDescriptor(d) ? d : new AggregateDescriptor(d);
169 169 }) as ServiceMap;
170 170
171 171 this._leave();
172 172
173 173 return services;
174 174 }
175 175
176 176 _enter(name: _key) {
177 177 this._path.push(name);
178 178 trace.debug(">{0}", name);
179 179 }
180 180
181 181 _leave() {
182 182 const name = this._path.pop();
183 183 trace.debug("<{0}", name);
184 184 }
185 185
186 186 async _visit(data, name: string): Promise<any> {
187 187 if (isPrimitive(data) || isDescriptor(data))
188 188 return data;
189 189
190 190 if (isDependencyRegistration(data)) {
191 191 return this._visitDependencyRegistration(data, name);
192 192 } else if (isValueRegistration(data)) {
193 193 return this._visitValueRegistration(data, name);
194 194 } else if (isTypeRegistration(data)) {
195 195 return this._visitTypeRegistration(data, name);
196 196 } else if (isFactoryRegistration(data)) {
197 197 return this._visitFactoryRegistration(data, name);
198 198 } else if (data instanceof Array) {
199 199 return this._visitArray(data, name);
200 200 }
201 201
202 202 return this._visitObject(data, name);
203 203 }
204 204
205 205 async _visitObject(data: object, name: _key) {
206 206 if (data.constructor &&
207 207 data.constructor.prototype !== Object.prototype)
208 208 return new ValueDescriptor(data);
209 209
210 210 this._enter(name);
211 211
212 212 const v = await mapAll(data, delegate(this, "_visit"));
213 213
214 214 // TODO: handle inline descriptors properly
215 215 // const ex = {
216 216 // activate(ctx) {
217 217 // const value = ctx.activate(this.prop, "prop");
218 218 // // some code
219 219 // },
220 220 // // will be turned to ReferenceDescriptor
221 221 // prop: { $dependency: "depName" }
222 222 // };
223 223
224 224 this._leave();
225 225 return v;
226 226 }
227 227
228 228 async _visitArray(data: any[], name: _key) {
229 229 if (data.constructor &&
230 230 data.constructor.prototype !== Array.prototype)
231 231 return new ValueDescriptor(data);
232 232
233 233 this._enter(name);
234 234
235 235 const v = await mapAll(data, delegate(this, "_visit"));
236 236 this._leave();
237 237
238 238 return v;
239 239 }
240 240
241 241 _makeServiceParams(data: ServiceRegistration) {
242 242 const opts: any = {
243 243 owner: this._container
244 244 };
245 245 if (data.services)
246 246 opts.services = this._visitRegistrations(data.services, "services");
247 247
248 248 if (data.inject) {
249 249 this._path.push("inject");
250 250 opts.inject = mapAll(
251 251 data.inject instanceof Array ?
252 252 data.inject :
253 253 [data.inject],
254 254 delegate(this, "_visitObject")
255 255 );
256 256 this._leave();
257 257 }
258 258
259 259 if ("params" in data)
260 260 opts.params = data.params instanceof Array ?
261 261 this._visitArray(data.params, "params") :
262 262 this._visit(data.params, "params");
263 263
264 264 if (data.activation) {
265 265 if (typeof (data.activation) === "string") {
266 266 switch (data.activation.toLowerCase()) {
267 267 case "singleton":
268 268 opts.activation = ActivationType.Singleton;
269 269 break;
270 270 case "container":
271 271 opts.activation = ActivationType.Container;
272 272 break;
273 273 case "hierarchy":
274 274 opts.activation = ActivationType.Hierarchy;
275 275 break;
276 276 case "context":
277 277 opts.activation = ActivationType.Context;
278 278 break;
279 279 case "call":
280 280 opts.activation = ActivationType.Call;
281 281 break;
282 282 default:
283 283 throw new Error("Unknown activation type: " +
284 284 data.activation);
285 285 }
286 286 } else {
287 287 opts.activation = Number(data.activation);
288 288 }
289 289 }
290 290
291 291 if (data.cleanup)
292 292 opts.cleanup = data.cleanup;
293 293
294 294 return opts;
295 295 }
296 296
297 297 async _visitValueRegistration(data: ValueRegistration, name: _key) {
298 298 this._enter(name);
299 299 const d = data.parse ? new AggregateDescriptor(data.$value) : new ValueDescriptor(data.$value);
300 300 this._leave();
301 301 return d;
302 302 }
303 303
304 304 async _visitDependencyRegistration(data: DependencyRegistration, name: _key) {
305 305 argumentNotEmptyString(data && data.$dependency, "data.$dependency");
306 306 this._enter(name);
307 307 const d = new ReferenceDescriptor({
308 308 name: data.$dependency,
309 309 lazy: data.lazy,
310 310 optional: data.optional,
311 311 default: data.default,
312 312 services: data.services && await this._visitRegistrations(data.services, "services")
313 313 });
314 314 this._leave();
315 315 return d;
316 316 }
317 317
318 318 async _visitTypeRegistration(data: TypeRegistration, name: _key) {
319 319 argumentNotNull(data.$type, "data.$type");
320 320 this._enter(name);
321 321
322 322 const opts = this._makeServiceParams(data);
323 323 if (data.$type instanceof Function) {
324 324 opts.type = data.$type;
325 325 } else {
326 326 const [moduleName, typeName] = data.$type.split(":", 2);
327 327 opts.type = this._resolveType(moduleName, typeName);
328 328 }
329 329
330 330 const d = new TypeServiceDescriptor(
331 331 await mapAll(opts)
332 332 );
333 333
334 334 this._leave();
335 335
336 336 return d;
337 337 }
338 338
339 339 async _visitFactoryRegistration(data: FactoryRegistration, name: _key) {
340 340 argumentOfType(data.$factory, Function, "data.$type");
341 341 this._enter(name);
342 342
343 343 const opts = this._makeServiceParams(data);
344 344 opts.factory = opts.$factory;
345 345
346 346 const d = new FactoryServiceDescriptor(
347 347 await mapAll(opts)
348 348 );
349 349
350 350 this._leave();
351 351 return d;
352 352 }
353 353 }
@@ -1,16 +1,22
1 1 {
2 2 "compilerOptions": {
3 3 "target": "es3",
4 4 "module": "amd",
5 5 "sourceMap": true,
6 6 "declaration": true,
7 7 "lib": [
8 8 "es5",
9 9 "es2015.promise",
10 "es2015.symbol"
11 ]
10 "es2015.symbol",
11 "dom"
12 ],
13 "rootDirs": [
14 "ts",
15 "amd/ts"
16 ],
17 "types": []
12 18 },
13 19 "include" : [
14 "ts/**/*.ts"
20 "ts/**/*.ts", "amd/ts/**/*.ts"
15 21 ]
16 22 } No newline at end of file
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now