@equinor/fusion-framework-module-context
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -6,2 +6,8 @@ # Change Log | ||
## [0.5.0](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module-context@0.4.1...@equinor/fusion-framework-module-context@0.5.0) (2022-11-16) | ||
### Features | ||
- **module-context:** allow query filter ([1a89ee5](https://github.com/equinor/fusion-framework/commit/1a89ee57277af3853ce802da9b5e0956bff8ceaa)) | ||
## 0.4.1 (2022-11-14) | ||
@@ -8,0 +14,0 @@ |
@@ -15,6 +15,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
createContextClientGet(init) { | ||
_createContextClientGet(apiProvider) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const provider = yield init.requireInstance('services'); | ||
const contextClient = yield provider.createContextClient('json$'); | ||
const contextClient = yield apiProvider.createContextClient('json$'); | ||
return { | ||
@@ -27,6 +26,5 @@ fn: (args) => { | ||
} | ||
createContextClientQuery(init) { | ||
_createContextClientQuery(apiProvider) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const provider = yield init.requireInstance('services'); | ||
const contextClient = yield provider.createContextClient('json$'); | ||
const contextClient = yield apiProvider.createContextClient('json$'); | ||
return { | ||
@@ -39,8 +37,24 @@ fn: (query) => { | ||
} | ||
_getServiceProvider(init) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (init.hasModule('services')) { | ||
return init.requireInstance('services'); | ||
} | ||
else { | ||
const parentServiceModule = (_a = init.ref) === null || _a === void 0 ? void 0 : _a.services; | ||
if (parentServiceModule) { | ||
return parentServiceModule; | ||
} | ||
throw Error('no service services provider configures [ServicesModule]'); | ||
} | ||
}); | ||
} | ||
createConfig(init) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const apiProvider = yield this._getServiceProvider(init); | ||
const config = { | ||
getContext: { | ||
query: { | ||
client: yield this.createContextClientGet(init), | ||
client: yield this._createContextClientGet(apiProvider), | ||
key: ({ id }) => id, | ||
@@ -51,3 +65,3 @@ expire: this.defaultExpireTime, | ||
queryContext: { | ||
client: yield this.createContextClientQuery(init), | ||
client: yield this._createContextClientQuery(apiProvider), | ||
key: (args) => JSON.stringify(args), | ||
@@ -54,0 +68,0 @@ expire: this.defaultExpireTime, |
import { module } from './module'; | ||
export const enableContext = (config) => { | ||
config.addConfig({ module }); | ||
export const enableContext = (configurator, options) => { | ||
configurator.addConfig({ | ||
module, | ||
configure: (contextConfigurator) => { | ||
contextConfigurator.processConfig = (config) => { | ||
return Object.assign(Object.assign({}, config), options); | ||
}; | ||
}, | ||
}); | ||
}; | ||
@@ -5,0 +12,0 @@ export { ContextModuleConfigurator, } from './configurator'; |
@@ -12,4 +12,5 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
}; | ||
var _ContextProvider_contextClient, _ContextProvider_contextQuery, _ContextProvider_event, _ContextProvider_subscriptions; | ||
import { pairwise, Subscription } from 'rxjs'; | ||
var _ContextProvider_contextClient, _ContextProvider_contextQuery, _ContextProvider_event, _ContextProvider_subscriptions, _ContextProvider_contextType, _ContextProvider_contextFilter; | ||
import { lastValueFrom, Subscription } from 'rxjs'; | ||
import { map, pairwise } from 'rxjs/operators'; | ||
import { ContextClient } from './client/ContextClient'; | ||
@@ -23,3 +24,7 @@ import Query from '@equinor/fusion-observable/query'; | ||
_ContextProvider_subscriptions.set(this, new Subscription()); | ||
_ContextProvider_contextType.set(this, void 0); | ||
_ContextProvider_contextFilter.set(this, void 0); | ||
const { config, event, parentContext } = args; | ||
__classPrivateFieldSet(this, _ContextProvider_contextType, config.contextType, "f"); | ||
__classPrivateFieldSet(this, _ContextProvider_contextFilter, config.contextFilter, "f"); | ||
__classPrivateFieldSet(this, _ContextProvider_contextClient, new ContextClient(config.getContext), "f"); | ||
@@ -54,2 +59,16 @@ __classPrivateFieldSet(this, _ContextProvider_contextQuery, new Query(config.queryContext), "f"); | ||
} | ||
queryContext(search) { | ||
const query$ = this.queryClient | ||
.query({ | ||
search, | ||
filter: { | ||
type: __classPrivateFieldGet(this, _ContextProvider_contextType, "f"), | ||
}, | ||
}) | ||
.pipe(map((x) => x.value)); | ||
return __classPrivateFieldGet(this, _ContextProvider_contextFilter, "f") ? query$.pipe(map(__classPrivateFieldGet(this, _ContextProvider_contextFilter, "f"))) : query$; | ||
} | ||
queryContextAsync(search) { | ||
return lastValueFrom(this.queryContext(search)); | ||
} | ||
get currentContext$() { | ||
@@ -84,4 +103,4 @@ return __classPrivateFieldGet(this, _ContextProvider_contextClient, "f").currentContext$; | ||
} | ||
_ContextProvider_contextClient = new WeakMap(), _ContextProvider_contextQuery = new WeakMap(), _ContextProvider_event = new WeakMap(), _ContextProvider_subscriptions = new WeakMap(); | ||
_ContextProvider_contextClient = new WeakMap(), _ContextProvider_contextQuery = new WeakMap(), _ContextProvider_event = new WeakMap(), _ContextProvider_subscriptions = new WeakMap(), _ContextProvider_contextType = new WeakMap(), _ContextProvider_contextFilter = new WeakMap(); | ||
export default ContextProvider; | ||
//# sourceMappingURL=provider.js.map |
import { AnyModule, ModuleInitializerArgs } from '@equinor/fusion-framework-module'; | ||
import { ServicesModule } from '@equinor/fusion-framework-module-services'; | ||
import { ServicesModule, IApiProvider } from '@equinor/fusion-framework-module-services'; | ||
import { QueryCtorOptions } from '@equinor/fusion-observable/query'; | ||
@@ -9,2 +9,4 @@ import { ContextClientOptions } from './client/ContextClient'; | ||
queryContext: QueryCtorOptions<ContextItem[], QueryContextParameters>; | ||
contextType?: string[]; | ||
contextFilter?: (items: Array<ContextItem>) => Array<ContextItem>; | ||
} | ||
@@ -14,6 +16,2 @@ export interface IContextModuleConfigurator<TDeps extends Array<AnyModule> = [ServicesModule]> { | ||
processConfig: (config: IContextModuleConfig) => IContextModuleConfig; | ||
createContextClientGet(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<QueryCtorOptions<ContextItem, { | ||
id: string; | ||
}>['client']>; | ||
createContextClientQuery(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']>; | ||
} | ||
@@ -23,6 +21,7 @@ export declare class ContextModuleConfigurator implements IContextModuleConfigurator<[ServicesModule]> { | ||
defaultExpireTime: number; | ||
createContextClientGet(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<QueryCtorOptions<ContextItem, { | ||
protected _createContextClientGet(apiProvider: IApiProvider): Promise<QueryCtorOptions<ContextItem, { | ||
id: string; | ||
}>['client']>; | ||
createContextClientQuery(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']>; | ||
protected _createContextClientQuery(apiProvider: IApiProvider): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']>; | ||
protected _getServiceProvider(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<IApiProvider>; | ||
createConfig(init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>): Promise<IContextModuleConfig>; | ||
@@ -29,0 +28,0 @@ processConfig(config: IContextModuleConfig): IContextModuleConfig; |
import { IModulesConfigurator } from '@equinor/fusion-framework-module'; | ||
export declare const enableContext: (config: IModulesConfigurator) => void; | ||
import { IContextModuleConfig } from './configurator'; | ||
export declare const enableContext: (configurator: IModulesConfigurator, options?: Pick<IContextModuleConfig, 'contextFilter' | 'contextType'>) => void; | ||
export { ContextModuleConfigurator, IContextModuleConfigurator, IContextModuleConfig, } from './configurator'; | ||
@@ -4,0 +5,0 @@ export { IContextProvider, ContextProvider } from './provider'; |
@@ -18,2 +18,4 @@ import { Observable } from 'rxjs'; | ||
get queryClient(): Query<ContextItem<Record<string, unknown>>[], QueryContextParameters>; | ||
queryContext(search: string): Observable<Array<ContextItem>>; | ||
queryContextAsync(search: string): Promise<Array<ContextItem>>; | ||
get currentContext$(): Observable<ContextItem | undefined>; | ||
@@ -20,0 +22,0 @@ get currentContext(): ContextItem | undefined; |
{ | ||
"name": "@equinor/fusion-framework-module-context", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "", | ||
@@ -45,3 +45,3 @@ "main": "./dist/esm/index.js", | ||
}, | ||
"gitHead": "98a8a5c6f02ac739adda41bb26f43e3255d450bb" | ||
"gitHead": "9721ee0033c59a26292b63f19fc6ed23a6a6136b" | ||
} |
@@ -1,3 +0,7 @@ | ||
import { AnyModule, ModuleInitializerArgs } from '@equinor/fusion-framework-module'; | ||
import { ServicesModule } from '@equinor/fusion-framework-module-services'; | ||
import { | ||
AnyModule, | ||
ModuleInitializerArgs, | ||
ModulesInstanceType, | ||
} from '@equinor/fusion-framework-module'; | ||
import { ServicesModule, IApiProvider } from '@equinor/fusion-framework-module-services'; | ||
import { QueryCtorOptions } from '@equinor/fusion-observable/query'; | ||
@@ -11,2 +15,4 @@ import { ContextClientOptions } from './client/ContextClient'; | ||
queryContext: QueryCtorOptions<ContextItem[], QueryContextParameters>; | ||
contextType?: string[]; | ||
contextFilter?: (items: Array<ContextItem>) => Array<ContextItem>; | ||
} | ||
@@ -19,13 +25,5 @@ | ||
) => Promise<IContextModuleConfig>; | ||
/** post process function for altering created config */ | ||
processConfig: (config: IContextModuleConfig) => IContextModuleConfig; | ||
/** fired on initialize of module */ | ||
createContextClientGet( | ||
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]> | ||
): Promise<QueryCtorOptions<ContextItem, { id: string }>['client']>; | ||
/** fired on initialize of module */ | ||
createContextClientQuery( | ||
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]> | ||
): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']>; | ||
} | ||
@@ -38,7 +36,6 @@ | ||
public async createContextClientGet( | ||
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]> | ||
protected async _createContextClientGet( | ||
apiProvider: IApiProvider | ||
): Promise<QueryCtorOptions<ContextItem, { id: string }>['client']> { | ||
const provider = await init.requireInstance('services'); | ||
const contextClient = await provider.createContextClient('json$'); | ||
const contextClient = await apiProvider.createContextClient('json$'); | ||
return { | ||
@@ -51,7 +48,6 @@ fn: (args) => { | ||
public async createContextClientQuery( | ||
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]> | ||
protected async _createContextClientQuery( | ||
apiProvider: IApiProvider | ||
): Promise<QueryCtorOptions<ContextItem[], QueryContextParameters>['client']> { | ||
const provider = await init.requireInstance('services'); | ||
const contextClient = await provider.createContextClient('json$'); | ||
const contextClient = await apiProvider.createContextClient('json$'); | ||
return { | ||
@@ -64,9 +60,25 @@ fn: (query) => { | ||
protected async _getServiceProvider( | ||
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]> | ||
): Promise<IApiProvider> { | ||
if (init.hasModule('services')) { | ||
return init.requireInstance('services'); | ||
} else { | ||
const parentServiceModule = (init.ref as ModulesInstanceType<[ServicesModule]>) | ||
?.services; | ||
if (parentServiceModule) { | ||
return parentServiceModule; | ||
} | ||
throw Error('no service services provider configures [ServicesModule]'); | ||
} | ||
} | ||
public async createConfig( | ||
init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]> | ||
) { | ||
const apiProvider = await this._getServiceProvider(init); | ||
const config: IContextModuleConfig = { | ||
getContext: { | ||
query: { | ||
client: await this.createContextClientGet(init), | ||
client: await this._createContextClientGet(apiProvider), | ||
key: ({ id }) => id, | ||
@@ -77,3 +89,3 @@ expire: this.defaultExpireTime, | ||
queryContext: { | ||
client: await this.createContextClientQuery(init), | ||
client: await this._createContextClientQuery(apiProvider), | ||
key: (args) => JSON.stringify(args), | ||
@@ -80,0 +92,0 @@ expire: this.defaultExpireTime, |
import { IModulesConfigurator } from '@equinor/fusion-framework-module'; | ||
import { IContextModuleConfig } from './configurator'; | ||
@@ -6,6 +7,19 @@ import { module } from './module'; | ||
* Method for enabling the Service module | ||
* @param config - configuration object | ||
* @param configurator - configuration object | ||
*/ | ||
export const enableContext = (config: IModulesConfigurator): void => { | ||
config.addConfig({ module }); | ||
export const enableContext = ( | ||
configurator: IModulesConfigurator, | ||
options?: Pick<IContextModuleConfig, 'contextFilter' | 'contextType'> | ||
): void => { | ||
configurator.addConfig({ | ||
module, | ||
configure: (contextConfigurator) => { | ||
contextConfigurator.processConfig = (config) => { | ||
return { | ||
...config, | ||
...options, | ||
}; | ||
}; | ||
}, | ||
}); | ||
}; | ||
@@ -12,0 +26,0 @@ |
@@ -1,2 +0,3 @@ | ||
import { Observable, pairwise, Subscription } from 'rxjs'; | ||
import { lastValueFrom, Observable, Subscription } from 'rxjs'; | ||
import { map, pairwise } from 'rxjs/operators'; | ||
@@ -31,3 +32,3 @@ import { IContextModuleConfig } from './configurator'; | ||
#contextClient: ContextClient; | ||
#contextQuery: Query<ContextItem[], QueryContextParameters>; | ||
#contextQuery: Query<Array<ContextItem>, QueryContextParameters>; | ||
@@ -38,2 +39,5 @@ #event?: ModuleType<EventModule>; | ||
#contextType?: IContextModuleConfig['contextType']; | ||
#contextFilter: IContextModuleConfig['contextFilter']; | ||
public get contextClient() { | ||
@@ -47,2 +51,19 @@ return this.#contextClient; | ||
public queryContext(search: string): Observable<Array<ContextItem>> { | ||
const query$ = this.queryClient | ||
.query({ | ||
search, | ||
filter: { | ||
type: this.#contextType, | ||
}, | ||
}) | ||
.pipe(map((x) => x.value)); | ||
return this.#contextFilter ? query$.pipe(map(this.#contextFilter)) : query$; | ||
} | ||
public queryContextAsync(search: string): Promise<Array<ContextItem>> { | ||
return lastValueFrom(this.queryContext(search)); | ||
} | ||
get currentContext$(): Observable<ContextItem | undefined> { | ||
@@ -83,2 +104,6 @@ return this.#contextClient.currentContext$; | ||
const { config, event, parentContext } = args; | ||
this.#contextType = config.contextType; | ||
this.#contextFilter = config.contextFilter; | ||
this.#contextClient = new ContextClient(config.getContext); | ||
@@ -85,0 +110,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
159246
860