@loopback/context 1.25.0 → 2.1.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/dist/binding-filter.d.ts +20 -2
  3. package/dist/binding-filter.js +58 -9
  4. package/dist/binding-filter.js.map +1 -1
  5. package/dist/binding.d.ts +50 -2
  6. package/dist/binding.js +33 -1
  7. package/dist/binding.js.map +1 -1
  8. package/dist/context-event.d.ts +23 -0
  9. package/dist/context-event.js +7 -0
  10. package/dist/context-event.js.map +1 -0
  11. package/dist/context-observer.d.ts +1 -36
  12. package/dist/context-subscription.d.ts +147 -0
  13. package/dist/context-subscription.js +336 -0
  14. package/dist/context-subscription.js.map +1 -0
  15. package/dist/context-tag-indexer.d.ts +42 -0
  16. package/dist/context-tag-indexer.js +134 -0
  17. package/dist/context-tag-indexer.js.map +1 -0
  18. package/dist/context-view.d.ts +2 -1
  19. package/dist/context-view.js.map +1 -1
  20. package/dist/context.d.ts +44 -68
  21. package/dist/context.js +69 -249
  22. package/dist/context.js.map +1 -1
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.js +1 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/inject.d.ts +9 -2
  27. package/dist/inject.js +60 -0
  28. package/dist/inject.js.map +1 -1
  29. package/dist/interceptor.js +4 -4
  30. package/dist/interceptor.js.map +1 -1
  31. package/dist/invocation.d.ts +0 -1
  32. package/dist/invocation.js +1 -5
  33. package/dist/invocation.js.map +1 -1
  34. package/dist/json-types.d.ts +28 -0
  35. package/dist/json-types.js +7 -0
  36. package/dist/json-types.js.map +1 -0
  37. package/dist/resolution-session.d.ts +2 -6
  38. package/dist/resolution-session.js +0 -4
  39. package/dist/resolution-session.js.map +1 -1
  40. package/dist/value-promise.d.ts +1 -3
  41. package/package.json +9 -9
  42. package/src/binding-filter.ts +83 -11
  43. package/src/binding.ts +79 -3
  44. package/src/context-event.ts +30 -0
  45. package/src/context-observer.ts +1 -38
  46. package/src/context-subscription.ts +403 -0
  47. package/src/context-tag-indexer.ts +149 -0
  48. package/src/context-view.ts +2 -5
  49. package/src/context.ts +104 -290
  50. package/src/index.ts +3 -0
  51. package/src/inject.ts +65 -0
  52. package/src/interceptor.ts +7 -6
  53. package/src/invocation.ts +1 -3
  54. package/src/json-types.ts +35 -0
  55. package/src/resolution-session.ts +4 -7
  56. package/src/value-promise.ts +1 -1
@@ -0,0 +1,35 @@
1
+ // Copyright IBM Corp. 2020. All Rights Reserved.
2
+ // Node module: @loopback/context
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ /**
7
+ * Type definition for JSON types
8
+ */
9
+
10
+ /**
11
+ * JSON primitive types:
12
+ * - string
13
+ * - number
14
+ * - boolean
15
+ * - null
16
+ */
17
+ export type JSONPrimitive = string | number | boolean | null;
18
+
19
+ /**
20
+ * JSON values
21
+ * - primitive
22
+ * - object
23
+ * - array
24
+ */
25
+ export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
26
+
27
+ /**
28
+ * JSON object
29
+ */
30
+ export interface JSONObject extends Record<string, JSONValue> {}
31
+
32
+ /**
33
+ * JSON array
34
+ */
35
+ export interface JSONArray extends Array<JSONValue> {}
@@ -155,9 +155,7 @@ export class ResolutionSession {
155
155
  * Describe the injection for debugging purpose
156
156
  * @param injection - Injection object
157
157
  */
158
- static describeInjection(injection?: Readonly<Injection>) {
159
- /* istanbul ignore if */
160
- if (injection == null) return {};
158
+ static describeInjection(injection: Readonly<Injection>) {
161
159
  const name = getTargetName(
162
160
  injection.target,
163
161
  injection.member,
@@ -166,8 +164,7 @@ export class ResolutionSession {
166
164
  return {
167
165
  targetName: name,
168
166
  bindingSelector: injection.bindingSelector,
169
- // Cast to Object so that we don't have to expose InjectionMetadata
170
- metadata: injection.metadata as object,
167
+ metadata: injection.metadata,
171
168
  };
172
169
  }
173
170
 
@@ -300,14 +297,14 @@ export class ResolutionSession {
300
297
  */
301
298
  getInjectionPath() {
302
299
  return this.injectionStack
303
- .map(i => ResolutionSession.describeInjection(i)!.targetName)
300
+ .map(i => ResolutionSession.describeInjection(i).targetName)
304
301
  .join(' --> ');
305
302
  }
306
303
 
307
304
  private static describe(e: ResolutionElement) {
308
305
  switch (e.type) {
309
306
  case 'injection':
310
- return '@' + ResolutionSession.describeInjection(e.value)!.targetName;
307
+ return '@' + ResolutionSession.describeInjection(e.value).targetName;
311
308
  case 'binding':
312
309
  return e.value.key;
313
310
  }
@@ -29,7 +29,7 @@ export type BoundValue = any;
29
29
  */
30
30
  export type ValueOrPromise<T> = T | PromiseLike<T>;
31
31
 
32
- export type MapObject<T> = {[name: string]: T};
32
+ export type MapObject<T> = Record<string, T>;
33
33
 
34
34
  /**
35
35
  * Check whether a value is a Promise-like instance.