@equinor/fusion-framework-module-context 8.0.0 → 8.0.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.
- package/CHANGELOG.md +15 -0
- package/dist/esm/ContextConfigBuilder.js +17 -6
- package/dist/esm/ContextConfigBuilder.js.map +1 -1
- package/dist/esm/ContextProvider.js +71 -15
- package/dist/esm/ContextProvider.js.map +1 -1
- package/dist/esm/client/ContextClient.js +13 -3
- package/dist/esm/client/ContextClient.js.map +1 -1
- package/dist/esm/configurator.js +9 -5
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/{errors.js → errors/FusionContextSearchError.js} +3 -1
- package/dist/esm/errors/FusionContextSearchError.js.map +1 -0
- package/dist/esm/errors/index.js +2 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/get-context-selector.js +14 -0
- package/dist/esm/get-context-selector.js.map +1 -0
- package/dist/esm/parse-context-item.js +31 -0
- package/dist/esm/parse-context-item.js.map +1 -0
- package/dist/esm/query-context-selector.js +12 -0
- package/dist/esm/query-context-selector.js.map +1 -0
- package/dist/esm/related-context-selector.js +12 -0
- package/dist/esm/related-context-selector.js.map +1 -0
- package/dist/esm/utils/extract-context-id-from-path.js +25 -0
- package/dist/esm/utils/extract-context-id-from-path.js.map +1 -0
- package/dist/esm/utils/resolve-context-from-path.js +11 -22
- package/dist/esm/utils/resolve-context-from-path.js.map +1 -1
- package/dist/esm/utils/resolve-initial-context.js +2 -0
- package/dist/esm/utils/resolve-initial-context.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ContextConfigBuilder.d.ts +16 -1
- package/dist/types/ContextProvider.d.ts +37 -3
- package/dist/types/client/ContextClient.d.ts +8 -1
- package/dist/types/{errors.d.ts → errors/FusionContextSearchError.d.ts} +2 -0
- package/dist/types/errors/index.d.ts +1 -0
- package/dist/types/get-context-selector.d.ts +9 -0
- package/dist/types/parse-context-item.d.ts +8 -0
- package/dist/types/query-context-selector.d.ts +7 -0
- package/dist/types/related-context-selector.d.ts +7 -0
- package/dist/types/types.d.ts +1 -1
- package/dist/types/utils/extract-context-id-from-path.d.ts +16 -0
- package/dist/types/utils/resolve-context-from-path.d.ts +1 -16
- package/dist/types/utils/resolve-initial-context.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +11 -11
- package/src/ContextConfigBuilder.ts +32 -7
- package/src/ContextProvider.ts +78 -21
- package/src/client/ContextClient.ts +13 -3
- package/src/configurator.ts +15 -6
- package/src/{errors.ts → errors/FusionContextSearchError.ts} +2 -0
- package/src/errors/index.ts +1 -0
- package/src/get-context-selector.ts +18 -0
- package/src/parse-context-item.ts +39 -0
- package/src/query-context-selector.ts +15 -0
- package/src/related-context-selector.ts +15 -0
- package/src/types.ts +1 -1
- package/src/utils/extract-context-id-from-path.ts +30 -0
- package/src/utils/resolve-context-from-path.ts +13 -28
- package/src/utils/resolve-initial-context.ts +2 -0
- package/src/version.ts +1 -1
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/selectors.js +0 -58
- package/dist/esm/selectors.js.map +0 -1
- package/dist/types/selectors.d.ts +0 -19
- package/src/selectors.ts +0 -70
|
@@ -35,7 +35,7 @@ export type ContextConfigBuilderCallback = <TDeps extends Array<AnyModule> = []>
|
|
|
35
35
|
* - The builder pattern allows chaining configuration methods for clarity and convenience.
|
|
36
36
|
* - The `requireInstance` method enables asynchronous retrieval of module instances by name.
|
|
37
37
|
*
|
|
38
|
-
* @todo - this should extend the BaseConfigBuilder
|
|
38
|
+
* @todo(#5120) - this should extend the BaseConfigBuilder
|
|
39
39
|
*
|
|
40
40
|
* @see ContextModuleConfig
|
|
41
41
|
* @see ModuleInitializerArgs
|
|
@@ -43,8 +43,23 @@ export type ContextConfigBuilderCallback = <TDeps extends Array<AnyModule> = []>
|
|
|
43
43
|
export declare class ContextConfigBuilder<TModules extends Array<AnyModule> = [], TInit extends ModuleInitializerArgs<any, any> = ModuleInitializerArgs<ContextModuleConfigurator, TModules>> {
|
|
44
44
|
#private;
|
|
45
45
|
config: Partial<ContextModuleConfig>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new `ContextConfigBuilder`.
|
|
48
|
+
* @param init - Module initializer arguments used to resolve module instances.
|
|
49
|
+
* @param config - The partial context module config to build upon.
|
|
50
|
+
*/
|
|
46
51
|
constructor(init: TInit, config?: Partial<ContextModuleConfig>);
|
|
52
|
+
/**
|
|
53
|
+
* Requires a module instance by its registered key.
|
|
54
|
+
* @param module - The key of the module to resolve.
|
|
55
|
+
* @returns A promise that resolves to the requested module instance.
|
|
56
|
+
*/
|
|
47
57
|
requireInstance<TKey extends string = Extract<keyof Modules, string>>(module: TKey): Promise<ModuleType<Modules[TKey]>>;
|
|
58
|
+
/**
|
|
59
|
+
* Requires a module instance by name.
|
|
60
|
+
* @param module - The name of the module to resolve.
|
|
61
|
+
* @returns A promise that resolves to the requested module instance.
|
|
62
|
+
*/
|
|
48
63
|
requireInstance<T>(module: string): Promise<T>;
|
|
49
64
|
/**
|
|
50
65
|
* Sets the context type for the current configuration.
|
|
@@ -290,12 +290,40 @@ export interface IContextProvider {
|
|
|
290
290
|
*/
|
|
291
291
|
export declare class ContextProvider extends BaseModuleProvider<ContextModuleConfig> implements IContextProvider {
|
|
292
292
|
#private;
|
|
293
|
+
/**
|
|
294
|
+
* The underlying context client used to resolve and hold the current context item.
|
|
295
|
+
* @returns The internal {@link ContextClient} instance.
|
|
296
|
+
*/
|
|
293
297
|
get contextClient(): ContextClient;
|
|
298
|
+
/**
|
|
299
|
+
* The query client used to search for context items.
|
|
300
|
+
* @returns The internal `Query` instance used by {@link queryContext}.
|
|
301
|
+
*/
|
|
294
302
|
get queryClient(): Query<ContextItem[], QueryContextParameters>;
|
|
303
|
+
/**
|
|
304
|
+
* Observable stream emitting the current context item.
|
|
305
|
+
* @returns Observable that emits the current `ContextItem`, `null`, or `undefined`.
|
|
306
|
+
*/
|
|
295
307
|
get currentContext$(): Observable<ContextItem | null | undefined>;
|
|
308
|
+
/**
|
|
309
|
+
* Snapshot of the current context item.
|
|
310
|
+
* @returns The current `ContextItem`, or `null`/`undefined` if not set.
|
|
311
|
+
*/
|
|
296
312
|
get currentContext(): ContextItem | undefined | null;
|
|
297
|
-
/**
|
|
313
|
+
/**
|
|
314
|
+
* Sets the current context item.
|
|
315
|
+
* @deprecated do not use, will be removed
|
|
316
|
+
* @param context - The context item to set as current. Must not be `undefined`.
|
|
317
|
+
* @throws Error if `context` is `undefined`.
|
|
318
|
+
*/
|
|
298
319
|
set currentContext(context: ContextItem | null | undefined);
|
|
320
|
+
/**
|
|
321
|
+
* Creates a new instance of `ContextProvider`.
|
|
322
|
+
* @param args - Constructor arguments.
|
|
323
|
+
* @param args.config - The context module configuration.
|
|
324
|
+
* @param args.event - Optional event module instance for dispatching context change events.
|
|
325
|
+
* @param args.parentContext - Optional parent context provider. Deprecated, use {@link connectParentContext}.
|
|
326
|
+
*/
|
|
299
327
|
constructor(args: {
|
|
300
328
|
config: ContextModuleConfig;
|
|
301
329
|
event?: ModuleType<EventModule>;
|
|
@@ -357,6 +385,11 @@ export declare class ContextProvider extends BaseModuleProvider<ContextModuleCon
|
|
|
357
385
|
* If the observable is subscribe, unsubscribing __WILL__ abort the task and remove it from queue
|
|
358
386
|
*
|
|
359
387
|
* @param context context item which would be queue to set as current
|
|
388
|
+
* @param opt Optional settings.
|
|
389
|
+
* @param opt.validate Whether to validate the context item before setting it.
|
|
390
|
+
* @param opt.resolve Whether to attempt to resolve the context item if validation fails.
|
|
391
|
+
* @template T The type of the context item, which extends `ContextItem<Record<string, unknown>>` or can be `null`.
|
|
392
|
+
* @returns An observable that emits the context item once the queued task completes.
|
|
360
393
|
*/
|
|
361
394
|
setCurrentContext<T extends ContextItem<Record<string, unknown>> | null>(context: T, opt?: {
|
|
362
395
|
validate?: boolean;
|
|
@@ -391,7 +424,7 @@ export declare class ContextProvider extends BaseModuleProvider<ContextModuleCon
|
|
|
391
424
|
* - Emit the context and complete the observable.
|
|
392
425
|
*
|
|
393
426
|
* @protected
|
|
394
|
-
* @
|
|
427
|
+
* @template T - The type of the context item, which extends `ContextItem<Record<string, unknown>>` or can be `null`.
|
|
395
428
|
* @param context - The new context to set.
|
|
396
429
|
* @param opt - Optional settings:
|
|
397
430
|
* - `validate`: Whether to validate the context before setting.
|
|
@@ -412,7 +445,7 @@ export declare class ContextProvider extends BaseModuleProvider<ContextModuleCon
|
|
|
412
445
|
*
|
|
413
446
|
* @see {@link setCurrentContext} for more details.
|
|
414
447
|
*
|
|
415
|
-
* @
|
|
448
|
+
* @template T - The type of the context item, which extends `ContextItem<Record<string, unknown>>` or can be `null`.
|
|
416
449
|
* @param context - The context item to set as the current context, or `null` to clear it.
|
|
417
450
|
* @param opt - Optional settings for context handling.
|
|
418
451
|
* @param opt.validate - If `true`, validates the context before setting it.
|
|
@@ -433,6 +466,7 @@ export declare class ContextProvider extends BaseModuleProvider<ContextModuleCon
|
|
|
433
466
|
*
|
|
434
467
|
* @param search - The search string to filter context items.
|
|
435
468
|
* @returns An Observable that emits an array of `ContextItem` objects matching the search criteria.
|
|
469
|
+
* @throws Re-throws the underlying cause of a `QueryClientError`, otherwise re-throws the original error.
|
|
436
470
|
*/
|
|
437
471
|
queryContext(search: string): Observable<Array<ContextItem>>;
|
|
438
472
|
/**
|
|
@@ -20,7 +20,7 @@ export type GetContextParameters = {
|
|
|
20
20
|
* @template ContextItem The type of the context item managed by the client.
|
|
21
21
|
* @extends Observable<ContextItem | null | undefined>
|
|
22
22
|
*
|
|
23
|
-
* @todo - should this have `undefined` as a valid value?
|
|
23
|
+
* @todo(#5116) - should this have `undefined` as a valid value?
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
@@ -55,6 +55,10 @@ export declare class ContextClient extends Observable<ContextItem | null | undef
|
|
|
55
55
|
get client(): Query<ContextItem, {
|
|
56
56
|
id: string;
|
|
57
57
|
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new `ContextClient`.
|
|
60
|
+
* @param options - Query constructor options used to fetch a `ContextItem` by its ID.
|
|
61
|
+
*/
|
|
58
62
|
constructor(options: QueryCtorOptions<ContextItem, GetContextParameters>);
|
|
59
63
|
/**
|
|
60
64
|
* Sets the current context based on the provided identifier or context item.
|
|
@@ -85,6 +89,9 @@ export declare class ContextClient extends Observable<ContextItem | null | undef
|
|
|
85
89
|
resolveContextAsync(id: string, opt?: {
|
|
86
90
|
awaitResolve: boolean;
|
|
87
91
|
}): Promise<ContextItem>;
|
|
92
|
+
/**
|
|
93
|
+
* Disposes of the client, completing the internal current-context subject.
|
|
94
|
+
*/
|
|
88
95
|
dispose(): void;
|
|
89
96
|
}
|
|
90
97
|
export default ContextClient;
|
|
@@ -16,10 +16,12 @@ export declare class FusionContextSearchError extends Error {
|
|
|
16
16
|
#private;
|
|
17
17
|
/**
|
|
18
18
|
* The title of the error.
|
|
19
|
+
* @returns The error title.
|
|
19
20
|
*/
|
|
20
21
|
get title(): string;
|
|
21
22
|
/**
|
|
22
23
|
* The description of the error, if available.
|
|
24
|
+
* @returns The error description, or `undefined` if none was provided.
|
|
23
25
|
*/
|
|
24
26
|
get description(): string | undefined;
|
|
25
27
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FusionContextSearchError';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ContextItem } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse the response from the GetContext API into a context item.
|
|
4
|
+
* @param response The response object containing the context item.
|
|
5
|
+
* @returns A promise that resolves to the context item.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getContextSelector: (response: Response) => Promise<ContextItem>;
|
|
8
|
+
export { queryContextSelector } from './query-context-selector';
|
|
9
|
+
export { relatedContextSelector } from './related-context-selector';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApiVersion, ApiContextEntity } from '@equinor/fusion-framework-module-services/context';
|
|
2
|
+
import type { ContextItem } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Parses an ApiContextEntity object into a ContextItem object.
|
|
5
|
+
* @param item The ApiContextEntity object to parse.
|
|
6
|
+
* @returns The parsed ContextItem object.
|
|
7
|
+
*/
|
|
8
|
+
export declare const parseContextItem: (item: ApiContextEntity<ApiVersion.v1>) => ContextItem;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ContextItem } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse the response from the QueryContext API into an array of context items.
|
|
4
|
+
* @param response The response object.
|
|
5
|
+
* @returns A promise that resolves to an array of context items.
|
|
6
|
+
*/
|
|
7
|
+
export declare const queryContextSelector: (response: Response) => Promise<ContextItem[]>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ContextItem } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse the response from the RelatedContext API into an array of context items.
|
|
4
|
+
* @param response The response object containing the related context items.
|
|
5
|
+
* @returns A promise that resolves to an array of ContextItem objects.
|
|
6
|
+
*/
|
|
7
|
+
export declare const relatedContextSelector: (response: Response) => Promise<ContextItem[]>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* @property graphic - Optional graphical representation, either as a string or an object containing type and content.
|
|
17
17
|
* @property meta - Optional meta information, either as a string or an object containing type and content.
|
|
18
18
|
*
|
|
19
|
-
* @todo - convert to Zod schema for validation and type safety.
|
|
19
|
+
* @todo(#5122) - convert to Zod schema for validation and type safety.
|
|
20
20
|
*/
|
|
21
21
|
export type ContextItem<TType extends Record<string, unknown> = Record<string, unknown>> = {
|
|
22
22
|
id: string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method will try to extract a context id from a path.
|
|
3
|
+
* The default matcher is a GUID pattern.
|
|
4
|
+
* Will iterate over the path and return the first match.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const path = '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?dsadasdas#example';
|
|
9
|
+
* const contextId = extractContextIdFromPath(path); // '7fd97952-7fe6-409b-a6dc-292dbf0e50d7'
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param path string - the path to extract the context id from
|
|
13
|
+
* @param matcher RegExp - the pattern to match against
|
|
14
|
+
* @returns string | undefined - the context id or undefined
|
|
15
|
+
*/
|
|
16
|
+
export declare const extractContextIdFromPath: (path: string, matcher?: RegExp) => string | undefined;
|
|
@@ -2,6 +2,7 @@ import { type Observable } from 'rxjs';
|
|
|
2
2
|
import type { ModuleType } from '@equinor/fusion-framework-module';
|
|
3
3
|
import type { ContextModule } from '../module';
|
|
4
4
|
import type { ContextItem } from '../types';
|
|
5
|
+
export { extractContextIdFromPath } from './extract-context-id-from-path';
|
|
5
6
|
/**
|
|
6
7
|
* Arguments for resolving a context from a path.
|
|
7
8
|
*/
|
|
@@ -19,22 +20,6 @@ export type ContextPathResolveArgs = {
|
|
|
19
20
|
*/
|
|
20
21
|
validate?: (contextId: string) => boolean;
|
|
21
22
|
};
|
|
22
|
-
/**
|
|
23
|
-
* Method will try to extract a context id from a path.
|
|
24
|
-
* The default matcher is a GUID pattern.
|
|
25
|
-
* Will iterate over the path and return the first match.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* const path = '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?dsadasdas#example';
|
|
30
|
-
* const contextId = extractContextIdFromPath(path); // '7fd97952-7fe6-409b-a6dc-292dbf0e50d7'
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* @param path string - the path to extract the context id from
|
|
34
|
-
* @param matcher RegExp - the pattern to match against
|
|
35
|
-
* @returns string | undefined - the context id or undefined
|
|
36
|
-
*/
|
|
37
|
-
export declare const extractContextIdFromPath: (path: string, matcher?: RegExp) => string | undefined;
|
|
38
23
|
/**
|
|
39
24
|
* Method will try to resolve a context from a path.
|
|
40
25
|
* The method will return a function that takes a path and returns an observable of the resolved context.
|
|
@@ -17,5 +17,5 @@ export declare const resolveContextFromParent: ContextModuleConfig['resolveIniti
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const resolveInitialContext: (options?: {
|
|
19
19
|
path?: ContextPathResolveArgs;
|
|
20
|
-
}) => Required<ContextModuleConfig>[
|
|
20
|
+
}) => Required<ContextModuleConfig>['resolveInitialContext'];
|
|
21
21
|
export default resolveInitialContext;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "8.0.
|
|
1
|
+
export declare const version = "8.0.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-context",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"types": "./dist/types/index.d.ts"
|
|
10
10
|
},
|
|
11
11
|
"./errors.js": {
|
|
12
|
-
"import": "./dist/esm/errors.js",
|
|
13
|
-
"types": "./dist/types/errors.d.ts"
|
|
12
|
+
"import": "./dist/esm/errors/index.js",
|
|
13
|
+
"types": "./dist/types/errors/index.d.ts"
|
|
14
14
|
},
|
|
15
15
|
"./utils": {
|
|
16
16
|
"import": "./dist/esm/utils/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist/types/index.d.ts"
|
|
26
26
|
],
|
|
27
27
|
"errors.js": [
|
|
28
|
-
"dist/types/errors.d.ts"
|
|
28
|
+
"dist/types/errors/index.d.ts"
|
|
29
29
|
],
|
|
30
30
|
"utils": [
|
|
31
31
|
"dist/types/utils/index.d.ts"
|
|
@@ -45,19 +45,19 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"fast-deep-equal": "^3.1.3",
|
|
48
|
-
"@equinor/fusion-query": "^7.0.
|
|
48
|
+
"@equinor/fusion-query": "^7.0.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"rxjs": "^7.8.1",
|
|
52
|
-
"typescript": "^
|
|
53
|
-
"@equinor/fusion-framework-module-
|
|
54
|
-
"@equinor/fusion-framework-module": "^6.
|
|
55
|
-
"@equinor/fusion-framework-module-services": "^8.0.
|
|
56
|
-
"@equinor/fusion-framework-module-
|
|
52
|
+
"typescript": "^7.0.2",
|
|
53
|
+
"@equinor/fusion-framework-module-navigation": "^7.0.5",
|
|
54
|
+
"@equinor/fusion-framework-module": "^6.1.1",
|
|
55
|
+
"@equinor/fusion-framework-module-services": "^8.0.2",
|
|
56
|
+
"@equinor/fusion-framework-module-event": "^6.0.1"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"rxjs": "^7.0.0",
|
|
60
|
-
"@equinor/fusion-framework-module": "^6.
|
|
60
|
+
"@equinor/fusion-framework-module": "^6.1.1"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsc -b"
|
|
@@ -52,19 +52,25 @@ export type ContextConfigBuilderCallback = <TDeps extends Array<AnyModule> = []>
|
|
|
52
52
|
* - The builder pattern allows chaining configuration methods for clarity and convenience.
|
|
53
53
|
* - The `requireInstance` method enables asynchronous retrieval of module instances by name.
|
|
54
54
|
*
|
|
55
|
-
* @todo - this should extend the BaseConfigBuilder
|
|
55
|
+
* @todo(#5120) - this should extend the BaseConfigBuilder
|
|
56
56
|
*
|
|
57
57
|
* @see ContextModuleConfig
|
|
58
58
|
* @see ModuleInitializerArgs
|
|
59
59
|
*/
|
|
60
60
|
export class ContextConfigBuilder<
|
|
61
61
|
TModules extends Array<AnyModule> = [],
|
|
62
|
+
// biome-ignore lint/suspicious/noExplicitAny: `ModuleInitializerArgs<any, any>` widens the constraint to accept initializer args for any configurator/module set \u2014 `unknown` breaks assignability of the concrete default type argument
|
|
62
63
|
TInit extends ModuleInitializerArgs<any, any> = ModuleInitializerArgs<
|
|
63
64
|
ContextModuleConfigurator,
|
|
64
65
|
TModules
|
|
65
66
|
>,
|
|
66
67
|
> {
|
|
67
68
|
#init: TInit;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new `ContextConfigBuilder`.
|
|
71
|
+
* @param init - Module initializer arguments used to resolve module instances.
|
|
72
|
+
* @param config - The partial context module config to build upon.
|
|
73
|
+
*/
|
|
68
74
|
constructor(
|
|
69
75
|
init: TInit,
|
|
70
76
|
public config: Partial<ContextModuleConfig> = {},
|
|
@@ -72,13 +78,31 @@ export class ContextConfigBuilder<
|
|
|
72
78
|
this.#init = init;
|
|
73
79
|
}
|
|
74
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Requires a module instance by its registered key.
|
|
83
|
+
* @param module - The key of the module to resolve.
|
|
84
|
+
* @returns A promise that resolves to the requested module instance.
|
|
85
|
+
*/
|
|
75
86
|
requireInstance<TKey extends string = Extract<keyof Modules, string>>(
|
|
76
87
|
module: TKey,
|
|
77
88
|
): Promise<ModuleType<Modules[TKey]>>;
|
|
78
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Requires a module instance by name.
|
|
92
|
+
* @param module - The name of the module to resolve.
|
|
93
|
+
* @returns A promise that resolves to the requested module instance.
|
|
94
|
+
*/
|
|
79
95
|
requireInstance<T>(module: string): Promise<T>;
|
|
80
96
|
|
|
81
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Requires a module instance by key or name.
|
|
99
|
+
* @param module - The key or name of the module to resolve.
|
|
100
|
+
* @returns A promise that resolves to the requested module instance.
|
|
101
|
+
*/
|
|
102
|
+
requireInstance(
|
|
103
|
+
module: string,
|
|
104
|
+
// biome-ignore lint/suspicious/noExplicitAny: implementation signature must satisfy both overloads above (`Promise<ModuleType<...>>` and `Promise<T>`); `unknown` is not assignable to the generic `Promise<T>` overload
|
|
105
|
+
): Promise<any> {
|
|
82
106
|
return this.#init.requireInstance(module);
|
|
83
107
|
}
|
|
84
108
|
|
|
@@ -192,7 +216,7 @@ export class ContextConfigBuilder<
|
|
|
192
216
|
},
|
|
193
217
|
expire = 1 * 60 * 1000,
|
|
194
218
|
): void {
|
|
195
|
-
|
|
219
|
+
const clientConfig: ContextModuleConfig['client'] = {
|
|
196
220
|
get:
|
|
197
221
|
typeof client.get === 'function'
|
|
198
222
|
? {
|
|
@@ -206,7 +230,7 @@ export class ContextConfigBuilder<
|
|
|
206
230
|
query:
|
|
207
231
|
typeof client.query === 'function'
|
|
208
232
|
? {
|
|
209
|
-
// TODO - might cast to checksum
|
|
233
|
+
// TODO(#5118) - might cast to checksum
|
|
210
234
|
key: (args) => JSON.stringify(args),
|
|
211
235
|
client: {
|
|
212
236
|
fn: client.query,
|
|
@@ -215,12 +239,13 @@ export class ContextConfigBuilder<
|
|
|
215
239
|
}
|
|
216
240
|
: client.query,
|
|
217
241
|
};
|
|
242
|
+
this.config.client = clientConfig;
|
|
243
|
+
// only override the related-context client config if one was provided
|
|
218
244
|
if (client.related) {
|
|
219
|
-
|
|
220
|
-
this.config.client!.related =
|
|
245
|
+
clientConfig.related =
|
|
221
246
|
typeof client.related === 'function'
|
|
222
247
|
? {
|
|
223
|
-
// TODO - might cast to checksum
|
|
248
|
+
// TODO(#5118) - might cast to checksum
|
|
224
249
|
key: (args) => JSON.stringify(args),
|
|
225
250
|
client: {
|
|
226
251
|
fn: client.related,
|