@equinor/fusion-framework-module-service-discovery
Advanced tools
Comparing version 3.0.11 to 3.1.0
@@ -6,2 +6,8 @@ # Change Log | ||
## [3.1.0](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module-service-discovery@3.0.11...@equinor/fusion-framework-module-service-discovery@3.1.0) (2022-11-14) | ||
### Features | ||
- update packages to use observable ([98024aa](https://github.com/equinor/fusion-framework/commit/98024aa466c68f03bd793bd564cf7b6bf65def72)) | ||
## 3.0.11 (2022-11-11) | ||
@@ -8,0 +14,0 @@ |
@@ -10,9 +10,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _ServiceDiscoveryClient_query; | ||
import { Query } from '@equinor/fusion-observable/query'; | ||
import { tap } from 'rxjs/operators'; | ||
import { firstValueFrom } from 'rxjs'; | ||
export class ServiceDiscoveryClient { | ||
constructor({ http, endpoint }) { | ||
_ServiceDiscoveryClient_query.set(this, void 0); | ||
this.http = http; | ||
this.endpoint = endpoint; | ||
__classPrivateFieldSet(this, _ServiceDiscoveryClient_query, new Query({ | ||
client: { | ||
fn: () => http | ||
.fetch$(endpoint, { selector: this.selector.bind(this) }) | ||
.pipe(tap((x) => console.log('🔥', x))), | ||
}, | ||
key: () => 'services', | ||
expire: 5 * 60 * 1000, | ||
}), "f"); | ||
} | ||
get environment() { | ||
return Object.assign({}, this._getEnvironment()); | ||
return firstValueFrom(Query.extractQueryValue(__classPrivateFieldGet(this, _ServiceDiscoveryClient_query, "f").query(undefined, { cache: { suppressInvalid: true } }))); | ||
} | ||
@@ -36,21 +61,6 @@ selector(response) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { services } = yield this._getEnvironment(); | ||
const service = services[key]; | ||
return service; | ||
}); | ||
} | ||
_getEnvironment() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this._environment) { | ||
this._environment = yield this._fetchServiceDescription(); | ||
} | ||
return this._environment; | ||
}); | ||
} | ||
_fetchServiceDescription() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const { http, selector, endpoint } = this; | ||
const result = yield http.fetch(endpoint, { selector }); | ||
return result; | ||
const { services } = yield this.environment; | ||
const service = services[key]; | ||
return service; | ||
} | ||
@@ -64,2 +74,3 @@ catch (err) { | ||
} | ||
_ServiceDiscoveryClient_query = new WeakMap(); | ||
//# sourceMappingURL=client.js.map |
@@ -15,3 +15,3 @@ import { IHttpClient } from '@equinor/fusion-framework-module-http'; | ||
export declare class ServiceDiscoveryClient<T extends Environment = Environment> implements IServiceDiscoveryClient { | ||
protected _environment?: T; | ||
#private; | ||
endpoint: string; | ||
@@ -23,5 +23,3 @@ http: IHttpClient; | ||
resolveService(key: string): Promise<Service>; | ||
protected _getEnvironment(): Promise<T>; | ||
protected _fetchServiceDescription(): Promise<T>; | ||
} | ||
export {}; |
{ | ||
"name": "@equinor/fusion-framework-module-service-discovery", | ||
"version": "3.0.11", | ||
"version": "3.1.0", | ||
"description": "", | ||
@@ -27,3 +27,5 @@ "main": "dist/esm/index.js", | ||
"@equinor/fusion-framework-module": "^1.2.9", | ||
"@equinor/fusion-framework-module-http": "^2.1.4" | ||
"@equinor/fusion-framework-module-http": "^2.1.4", | ||
"@equinor/fusion-observable": "^1.4.0", | ||
"rxjs": "^7.5.7" | ||
}, | ||
@@ -33,3 +35,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "676b6bab4e586885185d21b14bd61f392e76f74d" | ||
"gitHead": "8d6faac0a36f2e1792e4112e362c6ce3cf98371e" | ||
} |
import { IHttpClient } from '@equinor/fusion-framework-module-http'; | ||
import { Query } from '@equinor/fusion-observable/query'; | ||
import { Environment, EnvironmentResponse, Service } from './types'; | ||
import { tap } from 'rxjs/operators'; | ||
import { firstValueFrom } from 'rxjs'; | ||
export interface IServiceDiscoveryClient { | ||
@@ -21,3 +26,4 @@ readonly environment: Promise<Environment>; | ||
{ | ||
protected _environment?: T; | ||
// TODO - make better | ||
#query: Query<T, void>; | ||
@@ -28,3 +34,7 @@ public endpoint: string; | ||
get environment(): Promise<Environment> { | ||
return { ...this._getEnvironment() }; | ||
return firstValueFrom( | ||
Query.extractQueryValue( | ||
this.#query.query(undefined, { cache: { suppressInvalid: true } }) | ||
) | ||
); | ||
} | ||
@@ -35,2 +45,13 @@ | ||
this.endpoint = endpoint; | ||
this.#query = new Query<T, void>({ | ||
client: { | ||
fn: () => | ||
http | ||
.fetch$(endpoint, { selector: this.selector.bind(this) }) | ||
.pipe(tap((x) => console.log('🔥', x))), | ||
}, | ||
key: () => 'services', | ||
expire: 5 * 60 * 1000, | ||
// queueOperator: (_) => ($) => $.pipe(throttleTime(100)), | ||
}); | ||
} | ||
@@ -53,20 +74,6 @@ | ||
public async resolveService(key: string): Promise<Service> { | ||
const { services } = await this._getEnvironment(); | ||
// TODO - not found error | ||
const service = services[key]; | ||
return service; | ||
} | ||
protected async _getEnvironment(): Promise<T> { | ||
if (!this._environment) { | ||
this._environment = await this._fetchServiceDescription(); | ||
} | ||
return this._environment; | ||
} | ||
protected async _fetchServiceDescription(): Promise<T> { | ||
try { | ||
const { http, selector, endpoint } = this; | ||
const result = await http.fetch(endpoint, { selector }); | ||
return result; | ||
const { services } = await this.environment; | ||
const service = services[key]; | ||
return service; | ||
} catch (err) { | ||
@@ -73,0 +80,0 @@ console.error(err); |
@@ -15,2 +15,5 @@ { | ||
"path": "../module-http" | ||
}, | ||
{ | ||
"path": "../observable" | ||
} | ||
@@ -17,0 +20,0 @@ ], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
146545
566
4
+ Addedrxjs@^7.5.7
+ Added@equinor/fusion-observable@1.5.1(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedreact@18.3.1(transitive)
+ Addeduuid@8.3.2(transitive)