@loopback/service-proxy 2.2.1 → 2.3.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.3.0](https://github.com/strongloop/loopback-next/compare/@loopback/service-proxy@2.2.1...@loopback/service-proxy@2.3.0) (2020-05-20)
7
+
8
+
9
+ ### Features
10
+
11
+ * **service-proxy:** refine service mixin ([a6d0e2a](https://github.com/strongloop/loopback-next/commit/a6d0e2a457751568faffc1e733dc15f2e7232d2c))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [2.2.1](https://github.com/strongloop/loopback-next/compare/@loopback/service-proxy@2.2.0...@loopback/service-proxy@2.2.1) (2020-05-19)
7
18
 
8
19
  **Note:** Version bump only for package @loopback/service-proxy
@@ -1,5 +1,7 @@
1
- import { Binding, BindingFromClassOptions, Provider } from '@loopback/context';
2
- import { Application, ServiceOptions } from '@loopback/core';
1
+ import { Binding, BindingFromClassOptions, Provider, Constructor } from '@loopback/context';
2
+ import { Application, MixinTarget, ServiceOptions, Component } from '@loopback/core';
3
+ import { BindingAddress, BindingFilter, JSONObject, Context, ContextSubscriptionManager, ContextEvent, Interceptor, InterceptorBindingOptions, ResolutionOptions, BindingKey, ValueOrPromise, ContextEventObserver, ContextObserver, Subscription, BindingComparator, ContextView, ResolutionSession, BindingCreationPolicy, ContextInspectOptions } from '@loopback/context';
4
+ import { Server, ApplicationConfig, ApplicationMetadata, LifeCycleObserver } from '@loopback/core';
3
5
  /**
4
6
  * Interface for classes with `new` operator.
5
7
  */
@@ -20,9 +22,8 @@ export interface Class<T> {
20
22
  * called <a href="#ServiceMixinDoc">ServiceMixinDoc</a>
21
23
  *
22
24
  */
23
- export declare function ServiceMixin<T extends Class<any>>(superClass: T): {
25
+ export declare function ServiceMixin<T extends MixinTarget<Application>>(superClass: T): {
24
26
  new (...args: any[]): {
25
- [x: string]: any;
26
27
  /**
27
28
  * Add a service to this application.
28
29
  *
@@ -50,7 +51,7 @@ export declare function ServiceMixin<T extends Class<any>>(superClass: T): {
50
51
  * app.serviceProvider(GeocoderServiceProvider);
51
52
  * ```
52
53
  */
53
- serviceProvider<S>(provider: Class<Provider<S>>, nameOrOptions?: string | ServiceOptions | undefined): Binding<S>;
54
+ serviceProvider<S>(provider: Constructor<Provider<S>>, nameOrOptions?: string | ServiceOptions | undefined): Binding<S>;
54
55
  /**
55
56
  * Add a component to this application. Also mounts
56
57
  * all the components services.
@@ -72,7 +73,7 @@ export declare function ServiceMixin<T extends Class<any>>(superClass: T): {
72
73
  * app.component(ProductComponent);
73
74
  * ```
74
75
  */
75
- component(component: Class<unknown>, nameOrOptions?: string | BindingFromClassOptions | undefined): void;
76
+ component<T_1 extends Component = Component>(componentCtor: Constructor<T_1>, nameOrOptions?: string | BindingFromClassOptions | undefined): Binding<T_1>;
76
77
  /**
77
78
  * Get an instance of a component and mount all it's
78
79
  * services. This function is intended to be used internally
@@ -80,7 +81,74 @@ export declare function ServiceMixin<T extends Class<any>>(superClass: T): {
80
81
  *
81
82
  * @param component - The component to mount services of
82
83
  */
83
- mountComponentServices(component: Class<unknown>): void;
84
+ mountComponentServices<T_2 extends Component = Component>(component: Constructor<T_2>, componentBindingKey?: string | BindingKey<T_2> | undefined): void;
85
+ readonly options: ApplicationConfig;
86
+ readonly state: string;
87
+ controller: <T_3>(controllerCtor: Constructor<T_3>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_3>;
88
+ server: <T_4 extends Server>(ctor: Constructor<T_4>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_4>;
89
+ servers: <T_5 extends Server>(ctors: Constructor<T_5>[]) => Binding<any>[];
90
+ getServer: <T_6 extends Server>(target: string | Constructor<T_6>) => Promise<T_6>;
91
+ start: () => Promise<void>;
92
+ stop: () => Promise<void>;
93
+ setMetadata: (metadata: ApplicationMetadata) => void;
94
+ lifeCycleObserver: <T_7 extends LifeCycleObserver>(ctor: Constructor<T_7>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_7>;
95
+ service: <S_2>(cls: Constructor<S_2 | Provider<S_2>>, nameOrOptions?: string | ServiceOptions | undefined) => Binding<S_2>;
96
+ interceptor: (interceptor: Interceptor | Constructor<Provider<Interceptor>>, nameOrOptions?: string | InterceptorBindingOptions | undefined) => Binding<Interceptor>;
97
+ readonly name: string;
98
+ readonly subscriptionManager: ContextSubscriptionManager;
99
+ readonly parent: Context | undefined;
100
+ emitEvent: <T_8 extends ContextEvent>(type: string, event: T_8) => void;
101
+ emitError: (err: unknown) => void;
102
+ bind: <ValueType = any>(key: BindingAddress<ValueType>) => Binding<ValueType>;
103
+ add: (binding: Binding<unknown>) => Application;
104
+ configure: <ConfigValueType = any>(key?: string | BindingKey<unknown> | undefined) => Binding<ConfigValueType>;
105
+ getConfigAsValueOrPromise: <ConfigValueType_1>(key: BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: ResolutionOptions | undefined) => ValueOrPromise<ConfigValueType_1 | undefined>;
106
+ getConfig: <ConfigValueType_2>(key: BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: ResolutionOptions | undefined) => Promise<ConfigValueType_2 | undefined>;
107
+ getConfigSync: <ConfigValueType_3>(key: BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: ResolutionOptions | undefined) => ConfigValueType_3 | undefined;
108
+ unbind: (key: BindingAddress<unknown>) => boolean;
109
+ subscribe: (observer: ContextEventObserver) => Subscription;
110
+ unsubscribe: (observer: ContextEventObserver) => boolean;
111
+ close: () => void;
112
+ isSubscribed: (observer: ContextObserver) => boolean;
113
+ createView: <T_9 = unknown>(filter: BindingFilter, comparator?: BindingComparator | undefined) => ContextView<T_9>;
114
+ contains: (key: BindingAddress<unknown>) => boolean;
115
+ isBound: (key: BindingAddress<unknown>) => boolean;
116
+ getOwnerContext: (key: BindingAddress<unknown>) => Context | undefined;
117
+ find: <ValueType_1 = any>(pattern?: string | RegExp | BindingFilter | undefined) => Readonly<Binding<ValueType_1>>[];
118
+ findByTag: <ValueType_2 = any>(tagFilter: string | RegExp | Record<string, any>) => Readonly<Binding<ValueType_2>>[];
119
+ get: {
120
+ <ValueType_3>(keyWithPath: BindingAddress<ValueType_3>, session?: ResolutionSession | undefined): Promise<ValueType_3>;
121
+ <ValueType_4>(keyWithPath: BindingAddress<ValueType_4>, options: ResolutionOptions): Promise<ValueType_4 | undefined>;
122
+ };
123
+ getSync: {
124
+ <ValueType_5>(keyWithPath: BindingAddress<ValueType_5>, session?: ResolutionSession | undefined): ValueType_5;
125
+ <ValueType_6>(keyWithPath: BindingAddress<ValueType_6>, options?: ResolutionOptions | undefined): ValueType_6 | undefined;
126
+ };
127
+ getBinding: {
128
+ <ValueType_7 = any>(key: BindingAddress<ValueType_7>): Binding<ValueType_7>;
129
+ <ValueType_8>(key: BindingAddress<ValueType_8>, options?: {
130
+ optional?: boolean | undefined;
131
+ } | undefined): Binding<ValueType_8> | undefined;
132
+ };
133
+ findOrCreateBinding: <T_10>(key: BindingAddress<T_10>, policy?: BindingCreationPolicy | undefined) => Binding<T_10>;
134
+ getValueOrPromise: <ValueType_9>(keyWithPath: BindingAddress<ValueType_9>, optionsOrSession?: ResolutionOptions | ResolutionSession | undefined) => ValueOrPromise<ValueType_9 | undefined>;
135
+ toJSON: () => JSONObject;
136
+ inspect: (options?: ContextInspectOptions | undefined) => JSONObject;
137
+ addListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
138
+ on: (event: string | symbol, listener: (...args: any[]) => void) => Application;
139
+ once: (event: string | symbol, listener: (...args: any[]) => void) => Application;
140
+ prependListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
141
+ prependOnceListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
142
+ removeListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
143
+ off: (event: string | symbol, listener: (...args: any[]) => void) => Application;
144
+ removeAllListeners: (event?: string | symbol | undefined) => Application;
145
+ setMaxListeners: (n: number) => Application;
146
+ getMaxListeners: () => number;
147
+ listeners: (event: string | symbol) => Function[];
148
+ rawListeners: (event: string | symbol) => Function[];
149
+ emit: (event: string | symbol, ...args: any[]) => boolean;
150
+ eventNames: () => (string | symbol)[];
151
+ listenerCount: (type: string | symbol) => number;
84
152
  };
85
153
  } & T;
86
154
  /**
@@ -19,7 +19,6 @@ exports.ServiceMixinDoc = exports.ServiceMixin = void 0;
19
19
  * called <a href="#ServiceMixinDoc">ServiceMixinDoc</a>
20
20
  *
21
21
  */
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
22
  function ServiceMixin(superClass) {
24
23
  return class extends superClass {
25
24
  /**
@@ -73,9 +72,14 @@ function ServiceMixin(superClass) {
73
72
  * app.component(ProductComponent);
74
73
  * ```
75
74
  */
76
- component(component, nameOrOptions) {
77
- super.component(component, nameOrOptions);
78
- this.mountComponentServices(component);
75
+ // Unfortunately, TypeScript does not allow overriding methods inherited
76
+ // from mapped types. https://github.com/microsoft/TypeScript/issues/38496
77
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
78
+ // @ts-ignore
79
+ component(componentCtor, nameOrOptions) {
80
+ const binding = super.component(componentCtor, nameOrOptions);
81
+ this.mountComponentServices(componentCtor, binding.key);
82
+ return binding;
79
83
  }
80
84
  /**
81
85
  * Get an instance of a component and mount all it's
@@ -84,8 +88,8 @@ function ServiceMixin(superClass) {
84
88
  *
85
89
  * @param component - The component to mount services of
86
90
  */
87
- mountComponentServices(component) {
88
- const componentKey = `components.${component.name}`;
91
+ mountComponentServices(component, componentBindingKey) {
92
+ const componentKey = componentBindingKey !== null && componentBindingKey !== void 0 ? componentBindingKey : `components.${component.name}`;
89
93
  const compInstance = this.getSync(componentKey);
90
94
  if (compInstance.serviceProviders) {
91
95
  for (const provider of compInstance.serviceProviders) {
@@ -1 +1 @@
1
- {"version":3,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CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;iBAChC;aACF;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AA9FD,oCA8FC;AAWD;;;;;;GAMG;AACH,MAAa,eAAe;IAC1B,8DAA8D;IAC9D,YAAY,GAAG,IAAW;QACxB,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,eAAe,CAAI,QAA4B;QAC7C,MAAM,IAAI,KAAK,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,SAAS,CAAC,SAAyB;QACxC,MAAM,IAAI,KAAK,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,sBAAsB,CAAC,SAAyB,IAAG,CAAC;CACrD;AAtED,0CAsEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loopback/service-proxy",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "Service integration for LoopBack 4",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,14 +24,14 @@
24
24
  "copyright.owner": "IBM Corp.",
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@loopback/build": "^5.4.0",
28
- "@loopback/eslint-config": "^7.0.0",
29
- "@loopback/testlab": "^3.1.4",
30
- "@types/node": "^10.17.21"
27
+ "@loopback/build": "^5.4.1",
28
+ "@loopback/eslint-config": "^7.0.1",
29
+ "@loopback/testlab": "^3.1.5",
30
+ "@types/node": "^10.17.24"
31
31
  },
32
32
  "dependencies": {
33
- "@loopback/context": "^3.8.0",
34
- "@loopback/core": "^2.6.0",
33
+ "@loopback/context": "^3.8.1",
34
+ "@loopback/core": "^2.7.0",
35
35
  "loopback-datasource-juggler": "^4.21.2",
36
36
  "tslib": "^2.0.0"
37
37
  },
@@ -46,5 +46,5 @@
46
46
  "url": "https://github.com/strongloop/loopback-next.git",
47
47
  "directory": "packages/service-proxy"
48
48
  },
49
- "gitHead": "c8681026187471f0ceeee7c101d66feae295116b"
49
+ "gitHead": "62aea854bf85c5a5995b59e6908fe5409f7eea96"
50
50
  }
@@ -3,8 +3,48 @@
3
3
  // This file is licensed under the MIT License.
4
4
  // License text available at https://opensource.org/licenses/MIT
5
5
 
6
- import {Binding, BindingFromClassOptions, Provider} from '@loopback/context';
7
- import {Application, ServiceOptions} from '@loopback/core';
6
+ import {
7
+ Binding,
8
+ BindingFromClassOptions,
9
+ Provider,
10
+ Constructor,
11
+ } from '@loopback/context';
12
+ import {
13
+ Application,
14
+ MixinTarget,
15
+ ServiceOptions,
16
+ Component,
17
+ } from '@loopback/core';
18
+
19
+ // FIXME(rfeng): Workaround for https://github.com/microsoft/rushstack/pull/1867
20
+ /* eslint-disable @typescript-eslint/no-unused-vars */
21
+ import {
22
+ BindingAddress,
23
+ BindingFilter,
24
+ JSONObject,
25
+ Context,
26
+ ContextSubscriptionManager,
27
+ ContextEvent,
28
+ Interceptor,
29
+ InterceptorBindingOptions,
30
+ ResolutionOptions,
31
+ BindingKey,
32
+ ValueOrPromise,
33
+ ContextEventObserver,
34
+ ContextObserver,
35
+ Subscription,
36
+ BindingComparator,
37
+ ContextView,
38
+ ResolutionSession,
39
+ BindingCreationPolicy,
40
+ ContextInspectOptions,
41
+ } from '@loopback/context';
42
+ import {
43
+ Server,
44
+ ApplicationConfig,
45
+ ApplicationMetadata,
46
+ LifeCycleObserver,
47
+ } from '@loopback/core';
8
48
 
9
49
  /**
10
50
  * Interface for classes with `new` operator.
@@ -29,8 +69,9 @@ export interface Class<T> {
29
69
  * called <a href="#ServiceMixinDoc">ServiceMixinDoc</a>
30
70
  *
31
71
  */
32
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
- export function ServiceMixin<T extends Class<any>>(superClass: T) {
72
+ export function ServiceMixin<T extends MixinTarget<Application>>(
73
+ superClass: T,
74
+ ) {
34
75
  return class extends superClass {
35
76
  /**
36
77
  * Add a service to this application.
@@ -60,7 +101,7 @@ export function ServiceMixin<T extends Class<any>>(superClass: T) {
60
101
  * ```
61
102
  */
62
103
  serviceProvider<S>(
63
- provider: Class<Provider<S>>,
104
+ provider: Constructor<Provider<S>>,
64
105
  nameOrOptions?: string | ServiceOptions,
65
106
  ): Binding<S> {
66
107
  return this.service(provider, nameOrOptions);
@@ -87,12 +128,17 @@ export function ServiceMixin<T extends Class<any>>(superClass: T) {
87
128
  * app.component(ProductComponent);
88
129
  * ```
89
130
  */
90
- public component(
91
- component: Class<unknown>,
131
+ // Unfortunately, TypeScript does not allow overriding methods inherited
132
+ // from mapped types. https://github.com/microsoft/TypeScript/issues/38496
133
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
134
+ // @ts-ignore
135
+ component<T extends Component = Component>(
136
+ componentCtor: Constructor<T>,
92
137
  nameOrOptions?: string | BindingFromClassOptions,
93
138
  ) {
94
- super.component(component, nameOrOptions);
95
- this.mountComponentServices(component);
139
+ const binding = super.component(componentCtor, nameOrOptions);
140
+ this.mountComponentServices(componentCtor, binding.key);
141
+ return binding;
96
142
  }
97
143
 
98
144
  /**
@@ -102,9 +148,13 @@ export function ServiceMixin<T extends Class<any>>(superClass: T) {
102
148
  *
103
149
  * @param component - The component to mount services of
104
150
  */
105
- mountComponentServices(component: Class<unknown>) {
106
- const componentKey = `components.${component.name}`;
107
- const compInstance = this.getSync(componentKey);
151
+ mountComponentServices<T extends Component = Component>(
152
+ component: Constructor<T>,
153
+ componentBindingKey?: BindingAddress<T>,
154
+ ) {
155
+ const componentKey =
156
+ componentBindingKey ?? `components.${component.name}`;
157
+ const compInstance = this.getSync<Component>(componentKey);
108
158
 
109
159
  if (compInstance.serviceProviders) {
110
160
  for (const provider of compInstance.serviceProviders) {