@tsed/di 6.75.11 → 6.77.1

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.
@@ -28,6 +28,8 @@ export declare class Provider<T = any> implements IProvider<T> {
28
28
  get className(): string;
29
29
  get name(): string;
30
30
  get store(): Store;
31
+ get path(): string;
32
+ set path(path: string);
31
33
  /**
32
34
  * Get the scope of the provider.
33
35
  *
@@ -45,8 +47,19 @@ export declare class Provider<T = any> implements IProvider<T> {
45
47
  set scope(scope: ProviderScope);
46
48
  get configuration(): Partial<TsED.Configuration>;
47
49
  set configuration(configuration: Partial<TsED.Configuration>);
50
+ get children(): TokenProvider[];
48
51
  get(key: string): any;
49
52
  isAsync(): boolean;
50
53
  clone(): Provider;
54
+ /**
55
+ *
56
+ * @returns {boolean}
57
+ */
58
+ hasChildren(): boolean;
59
+ /**
60
+ *
61
+ * @returns {boolean}
62
+ */
63
+ hasParent(): boolean;
51
64
  toString(): string;
52
65
  }
package/lib/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  var core = require('@tsed/core');
2
2
  var logger = require('@tsed/logger');
3
+ var schema = require('@tsed/schema');
3
4
  var tslib = require('tslib');
4
5
  var chalk = require('chalk');
5
6
 
@@ -129,6 +130,14 @@ class Provider {
129
130
  get store() {
130
131
  return this._store;
131
132
  }
133
+
134
+ get path() {
135
+ return this.store.get("path", "/");
136
+ }
137
+
138
+ set path(path) {
139
+ this.store.set("path", path);
140
+ }
132
141
  /**
133
142
  * Get the scope of the provider.
134
143
  *
@@ -165,6 +174,10 @@ class Provider {
165
174
  this.store.set("configuration", configuration);
166
175
  }
167
176
 
177
+ get children() {
178
+ return this.store.get("childrenControllers", []);
179
+ }
180
+
168
181
  get(key) {
169
182
  return this.store.get(key) || this._tokenStore.get(key);
170
183
  }
@@ -176,6 +189,24 @@ class Provider {
176
189
  clone() {
177
190
  return new (core.classOf(this))(this._provide, this);
178
191
  }
192
+ /**
193
+ *
194
+ * @returns {boolean}
195
+ */
196
+
197
+
198
+ hasChildren() {
199
+ return !!this.children.length;
200
+ }
201
+ /**
202
+ *
203
+ * @returns {boolean}
204
+ */
205
+
206
+
207
+ hasParent() {
208
+ return !!this.store.get("parentController");
209
+ }
179
210
 
180
211
  toString() {
181
212
  return ["Token", this.name, this.useClass && core.nameOf(this.useClass), this.useFactory && "Factory", this.useValue && "Value", this.useAsyncFactory && "AsyncFactory"].filter(Boolean).join(":");
@@ -1226,7 +1257,7 @@ function UseOpts(options) {
1226
1257
  };
1227
1258
  }
1228
1259
 
1229
- const _excluded = ["children"];
1260
+ const _excluded = ["children", "path"];
1230
1261
 
1231
1262
  function mapOptions(options) {
1232
1263
  if (typeof options === "string" || options instanceof RegExp || core.isArrayOrArrayClass(options)) {
@@ -1270,19 +1301,16 @@ function mapOptions(options) {
1270
1301
  function Controller(options) {
1271
1302
  const _mapOptions = mapOptions(options),
1272
1303
  {
1273
- children = []
1304
+ children = [],
1305
+ path
1274
1306
  } = _mapOptions,
1275
1307
  opts = _objectWithoutPropertiesLoose(_mapOptions, _excluded);
1276
1308
 
1277
- return target => {
1309
+ return core.useDecorators(target => {
1278
1310
  registerController(_extends({
1279
1311
  provide: target
1280
1312
  }, opts));
1281
- core.Store.from(target).set("childrenControllers", children);
1282
- children.forEach(childToken => {
1283
- core.Store.from(childToken).set("parentController", target);
1284
- });
1285
- };
1313
+ }, path && schema.Path(path), schema.Children(...children));
1286
1314
  }
1287
1315
 
1288
1316
  class InjectionError extends Error {
@@ -1771,6 +1799,7 @@ exports.InjectorService = InjectorService_1 = class InjectorService extends Cont
1771
1799
 
1772
1800
 
1773
1801
  locals = this.loadSync(locals);
1802
+ await locals.emit("$beforeInit");
1774
1803
  await locals.emit("$onInit");
1775
1804
  return locals;
1776
1805
  }
@@ -1786,7 +1815,7 @@ exports.InjectorService = InjectorService_1 = class InjectorService extends Cont
1786
1815
 
1787
1816
  const mergedConfiguration = new Map();
1788
1817
  super.forEach(provider => {
1789
- if (provider.configuration) {
1818
+ if (provider.configuration && provider.type !== "server:module") {
1790
1819
  Object.entries(provider.configuration).forEach(([key, value]) => {
1791
1820
  value = mergedConfiguration.has(key) ? core.deepMerge(mergedConfiguration.get(key), value) : core.deepClone(value);
1792
1821
  mergedConfiguration.set(key, value);