@loopback/context 3.16.0 → 3.17.0

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.
@@ -92,20 +92,6 @@ export class ResolutionSession {
92
92
  return copy;
93
93
  }
94
94
 
95
- /**
96
- * Start to resolve a binding within the session
97
- * @param binding - The current binding
98
- * @param session - The current resolution session
99
- */
100
- private static enterBinding(
101
- binding: Readonly<Binding>,
102
- session?: ResolutionSession,
103
- ): ResolutionSession {
104
- session = session ?? new ResolutionSession();
105
- session.pushBinding(binding);
106
- return session;
107
- }
108
-
109
95
  /**
110
96
  * Run the given action with the given binding and session
111
97
  * @param action - A function to do some work with the resolution session
@@ -115,29 +101,16 @@ export class ResolutionSession {
115
101
  static runWithBinding(
116
102
  action: ResolutionAction,
117
103
  binding: Readonly<Binding>,
118
- session?: ResolutionSession,
104
+ session = new ResolutionSession(),
119
105
  ) {
120
- const resolutionSession = ResolutionSession.enterBinding(binding, session);
106
+ // Start to resolve a binding within the session
107
+ session.pushBinding(binding);
121
108
  return tryWithFinally(
122
- () => action(resolutionSession),
123
- () => resolutionSession.popBinding(),
109
+ () => action(session),
110
+ () => session.popBinding(),
124
111
  );
125
112
  }
126
113
 
127
- /**
128
- * Push an injection into the session
129
- * @param injection - The current injection
130
- * @param session - The current resolution session
131
- */
132
- private static enterInjection(
133
- injection: Readonly<Injection>,
134
- session?: ResolutionSession,
135
- ): ResolutionSession {
136
- session = session ?? new ResolutionSession();
137
- session.pushInjection(injection);
138
- return session;
139
- }
140
-
141
114
  /**
142
115
  * Run the given action with the given injection and session
143
116
  * @param action - A function to do some work with the resolution session
@@ -147,15 +120,12 @@ export class ResolutionSession {
147
120
  static runWithInjection(
148
121
  action: ResolutionAction,
149
122
  injection: Readonly<Injection>,
150
- session?: ResolutionSession,
123
+ session = new ResolutionSession(),
151
124
  ) {
152
- const resolutionSession = ResolutionSession.enterInjection(
153
- injection,
154
- session,
155
- );
125
+ session.pushInjection(injection);
156
126
  return tryWithFinally(
157
- () => action(resolutionSession),
158
- () => resolutionSession.popInjection(),
127
+ () => action(session),
128
+ () => session.popInjection(),
159
129
  );
160
130
  }
161
131
 
@@ -299,7 +269,7 @@ export class ResolutionSession {
299
269
  * Get the binding path as `bindingA --> bindingB --> bindingC`.
300
270
  */
301
271
  getBindingPath() {
302
- return this.bindingStack.map(b => b.key).join(' --> ');
272
+ return this.stack.filter(isBinding).map(describe).join(' --> ');
303
273
  }
304
274
 
305
275
  /**
@@ -311,22 +281,13 @@ export class ResolutionSession {
311
281
  .join(' --> ');
312
282
  }
313
283
 
314
- private static describe(e: ResolutionElement) {
315
- switch (e.type) {
316
- case 'injection':
317
- return '@' + ResolutionSession.describeInjection(e.value).targetName;
318
- case 'binding':
319
- return e.value.key;
320
- }
321
- }
322
-
323
284
  /**
324
285
  * Get the resolution path including bindings and injections, for example:
325
286
  * `bindingA --> @ClassA[0] --> bindingB --> @ClassB.prototype.prop1
326
287
  * --> bindingC`.
327
288
  */
328
289
  getResolutionPath() {
329
- return this.stack.map(i => ResolutionSession.describe(i)).join(' --> ');
290
+ return this.stack.map(describe).join(' --> ');
330
291
  }
331
292
 
332
293
  toString() {
@@ -334,6 +295,15 @@ export class ResolutionSession {
334
295
  }
335
296
  }
336
297
 
298
+ function describe(e: ResolutionElement) {
299
+ switch (e.type) {
300
+ case 'injection':
301
+ return '@' + ResolutionSession.describeInjection(e.value).targetName;
302
+ case 'binding':
303
+ return e.value.key;
304
+ }
305
+ }
306
+
337
307
  /**
338
308
  * Options for binding/dependency resolution
339
309
  */
@@ -314,4 +314,5 @@ export function uuid() {
314
314
  * @deprecated This pattern is an internal helper used by unit-tests, we are no
315
315
  * longer using it.
316
316
  */
317
- export const UUID_PATTERN = /[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}/i;
317
+ export const UUID_PATTERN =
318
+ /[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}/i;