@equinor/fusion-framework-module-context 5.0.7 → 5.0.8

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/esm/ContextConfigBuilder.js +5 -0
  3. package/dist/esm/ContextConfigBuilder.js.map +1 -1
  4. package/dist/esm/ContextProvider.js +124 -23
  5. package/dist/esm/ContextProvider.js.map +1 -1
  6. package/dist/esm/client/ContextClient.js +7 -1
  7. package/dist/esm/client/ContextClient.js.map +1 -1
  8. package/dist/esm/configurator.js +4 -0
  9. package/dist/esm/configurator.js.map +1 -1
  10. package/dist/esm/errors.js +14 -0
  11. package/dist/esm/errors.js.map +1 -1
  12. package/dist/esm/module.js +20 -3
  13. package/dist/esm/module.js.map +1 -1
  14. package/dist/esm/selectors.js +27 -0
  15. package/dist/esm/selectors.js.map +1 -1
  16. package/dist/esm/utils/enable-context.js +7 -1
  17. package/dist/esm/utils/enable-context.js.map +1 -1
  18. package/dist/esm/utils/resolve-context-from-path.js +19 -0
  19. package/dist/esm/utils/resolve-context-from-path.js.map +1 -1
  20. package/dist/esm/utils/resolve-initial-context.js +19 -0
  21. package/dist/esm/utils/resolve-initial-context.js.map +1 -1
  22. package/dist/esm/version.js +2 -1
  23. package/dist/esm/version.js.map +1 -1
  24. package/dist/tsconfig.tsbuildinfo +1 -1
  25. package/dist/types/ContextProvider.d.ts +86 -0
  26. package/dist/types/configurator.d.ts +9 -0
  27. package/dist/types/errors.d.ts +20 -0
  28. package/dist/types/selectors.d.ts +15 -0
  29. package/dist/types/utils/enable-context.d.ts +5 -1
  30. package/dist/types/utils/resolve-context-from-path.d.ts +67 -0
  31. package/dist/types/utils/resolve-initial-context.d.ts +15 -1
  32. package/dist/types/version.d.ts +1 -1
  33. package/package.json +8 -8
  34. package/src/version.ts +1 -1
@@ -5,25 +5,98 @@ import { ContextItem, QueryContextParameters, RelatedContextParameters } from '.
5
5
  import { ModuleType } from '@equinor/fusion-framework-module';
6
6
  import { EventModule, FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
7
7
  import Query from '@equinor/fusion-query';
8
+ /**
9
+ * WARNING: this is an initial out cast.
10
+ * api clients will most probably not be exposed in future!
11
+ */
12
+ /**
13
+ * Represents a context provider that manages the current context and provides methods for querying and manipulating context items.
14
+ */
8
15
  export interface IContextProvider {
16
+ /** DANGER */
9
17
  readonly contextClient: ContextClient;
18
+ /** DANGER */
10
19
  readonly queryClient: Query<ContextItem[], QueryContextParameters>;
11
20
  readonly currentContext$: Observable<ContextItem | null | undefined>;
12
21
  currentContext: ContextItem | null | undefined;
22
+ /**
23
+ * Queries the context items based on the provided search string.
24
+ * @param search The search string.
25
+ * @returns An observable that emits an array of context items.
26
+ */
13
27
  queryContext(search: string): Observable<Array<ContextItem>>;
28
+ /**
29
+ * Queries the context items asynchronously based on the provided search string.
30
+ * @param search The search string.
31
+ * @returns A promise that resolves to an array of context items.
32
+ */
14
33
  queryContextAsync(search: string): Promise<Array<ContextItem>>;
34
+ /**
35
+ * Validates the given context item.
36
+ * @param item The context item to validate.
37
+ * @returns A boolean indicating whether the context item is valid or not.
38
+ */
15
39
  validateContext(item: ContextItem<Record<string, unknown>>): boolean;
40
+ /**
41
+ * Resolves the context item as a stream.
42
+ * @param current The current context item.
43
+ * @returns An observable that emits the resolved context item.
44
+ */
16
45
  resolveContext: (current: ContextItem) => Observable<ContextItem>;
46
+ /**
47
+ * Resolves the context item asynchronously.
48
+ * @param current The current context item.
49
+ * @returns A promise that resolves to the resolved context item.
50
+ */
17
51
  resolveContextAsync: (current: ContextItem) => Promise<ContextItem>;
52
+ /**
53
+ * Retrieves the related context items based on the provided parameters.
54
+ * @param args The parameters for retrieving related context items.
55
+ * @returns An observable that emits an array of related context items.
56
+ */
18
57
  relatedContexts: (args: RelatedContextParameters) => Observable<Array<ContextItem<Record<string, unknown>>>>;
58
+ /**
59
+ * Retrieves the related context items asynchronously based on the provided parameters.
60
+ * @param args The parameters for retrieving related context items.
61
+ * @returns A promise that resolves to an array of related context items.
62
+ */
19
63
  relatedContextsAsync: (args: RelatedContextParameters) => Promise<Array<ContextItem<Record<string, unknown>>>>;
64
+ /**
65
+ * Clears the current context.
66
+ */
20
67
  clearCurrentContext: VoidFunction;
68
+ /**
69
+ * Sets the current context item by its ID.
70
+ * @param id The ID of the context item.
71
+ * @returns An observable that emits the current context item.
72
+ */
21
73
  setCurrentContextById(id: string): Observable<ContextItem<Record<string, unknown>>>;
74
+ /**
75
+ * Sets the current context item by its ID asynchronously.
76
+ * @param id The ID of the context item.
77
+ * @returns A promise that resolves to the current context item.
78
+ */
22
79
  setCurrentContextByIdAsync(id: string): Promise<ContextItem<Record<string, unknown>>>;
80
+ /**
81
+ * Sets the current context item.
82
+ * @param context The context item to set as the current context.
83
+ * @param opt Optional settings for the operation.
84
+ * @param opt.validate Specifies whether to validate the context item. Default is `true`.
85
+ * @param opt.resolve Specifies whether to resolve the context item. Default is `true`.
86
+ * @returns An observable that emits the current context item or `null`.
87
+ */
23
88
  setCurrentContext(context: ContextItem<Record<string, unknown>> | null, opt?: {
24
89
  validate?: boolean;
25
90
  resolve?: boolean;
26
91
  }): Observable<ContextItem<Record<string, unknown>> | null>;
92
+ /**
93
+ * Sets the current context item asynchronously.
94
+ * @param context The context item to set as the current context.
95
+ * @param opt Optional settings for the operation.
96
+ * @param opt.validate Specifies whether to validate the context item. Default is `true`.
97
+ * @param opt.resolve Specifies whether to resolve the context item. Default is `true`.
98
+ * @returns A promise that resolves to the current context item or `null`.
99
+ */
27
100
  setCurrentContextAsync(context: ContextItem<Record<string, unknown>> | null, opt?: {
28
101
  validate?: boolean;
29
102
  resolve?: boolean;
@@ -35,10 +108,12 @@ export declare class ContextProvider implements IContextProvider {
35
108
  get queryClient(): Query<ContextItem[], QueryContextParameters>;
36
109
  get currentContext$(): Observable<ContextItem | null | undefined>;
37
110
  get currentContext(): ContextItem | undefined | null;
111
+ /** @deprecated do not use, will be removed */
38
112
  set currentContext(context: ContextItem | null | undefined);
39
113
  constructor(args: {
40
114
  config: ContextModuleConfig;
41
115
  event?: ModuleType<EventModule>;
116
+ /** @deprecated use ContextProvider.connectParentContext */
42
117
  parentContext?: IContextProvider;
43
118
  });
44
119
  connectParentContext(provider: IContextProvider, opt?: {
@@ -46,6 +121,17 @@ export declare class ContextProvider implements IContextProvider {
46
121
  }): Subscription;
47
122
  setCurrentContextById(id: string): Observable<ContextItem<Record<string, unknown>>>;
48
123
  setCurrentContextByIdAsync(id: string): Promise<ContextItem<Record<string, unknown>>>;
124
+ /**
125
+ * Setting context is a complex operation, and might not happen immediately.
126
+ * When setting the context, a task is created and added to the queue.
127
+ * Once the task is completed, the returned observable will emit the value which will be the next state.
128
+ *
129
+ * Even tho this function returns a `Observable`, the task will be queued even tho nobody subscribes.
130
+ *
131
+ * If the observable is subscribe, unsubscribing __WILL__ abort the task and remove it from queue
132
+ *
133
+ * @param context context item which would be queue to set as current
134
+ */
49
135
  setCurrentContext<T extends ContextItem<Record<string, unknown>> | null>(context: T, opt?: {
50
136
  validate?: boolean;
51
137
  resolve?: boolean;
@@ -15,8 +15,17 @@ export interface ContextModuleConfig {
15
15
  };
16
16
  contextType?: string[];
17
17
  contextFilter?: ContextFilterFn;
18
+ /**
19
+ * connect context module to paren context module.
20
+ *
21
+ * _default: `true`_
22
+ */
18
23
  connectParentContext?: boolean;
24
+ /** set initial context from parent, will await resolve */
19
25
  skipInitialContext?: boolean;
26
+ /**
27
+ * Method for generating context query parameters.
28
+ */
20
29
  contextParameterFn?: (args: {
21
30
  search: string;
22
31
  type: ContextModuleConfig['contextType'];
@@ -1,9 +1,29 @@
1
+ /**
2
+ * Represents an error that occurs during a search in the Fusion Context.
3
+ */
1
4
  export declare class FusionContextSearchError extends Error {
2
5
  #private;
6
+ /**
7
+ * The title of the error.
8
+ */
3
9
  get title(): string;
10
+ /**
11
+ * The description of the error, if available.
12
+ */
4
13
  get description(): string | undefined;
14
+ /**
15
+ * Creates a new instance of FusionContextSearchError.
16
+ * @param details - The details of the error.
17
+ * @param options - Optional parameters for the error.
18
+ */
5
19
  constructor(details: {
20
+ /**
21
+ * The title of the error.
22
+ */
6
23
  title: string;
24
+ /**
25
+ * The description of the error, if available.
26
+ */
7
27
  description?: string;
8
28
  }, options?: ErrorOptions);
9
29
  }
@@ -1,4 +1,19 @@
1
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
+ */
2
7
  export declare const getContextSelector: (response: Response) => Promise<ContextItem>;
8
+ /**
9
+ * Parse the response from the QueryContext API into an array of context items.
10
+ * @param response The response object.
11
+ * @returns A promise that resolves to an array of context items.
12
+ */
3
13
  export declare const queryContextSelector: (response: Response) => Promise<ContextItem[]>;
14
+ /**
15
+ * Parse the response from the RelatedContext API into an array of context items.
16
+ * @param response The response object containing the related context items.
17
+ * @returns A promise that resolves to an array of ContextItem objects.
18
+ */
4
19
  export declare const relatedContextSelector: (response: Response) => Promise<ContextItem[]>;
@@ -1,4 +1,8 @@
1
1
  import type { IModulesConfigurator, AnyModule, ModuleInitializerArgs } from '@equinor/fusion-framework-module';
2
2
  import type { IContextModuleConfigurator } from '../configurator';
3
3
  import type { ContextConfigBuilder } from '../ContextConfigBuilder';
4
- export declare const enableContext: (configurator: IModulesConfigurator<any, any>, builder?: (<TDeps extends AnyModule[] = []>(builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>) => void | Promise<void>) | undefined) => void;
4
+ /**
5
+ * Method for enabling the Service module
6
+ * @param configurator - configuration object
7
+ */
8
+ export declare const enableContext: (configurator: IModulesConfigurator<any, any>, builder?: <TDeps extends Array<AnyModule> = []>(builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>) => void | Promise<void>) => void;
@@ -2,14 +2,81 @@ import { 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
+ /**
6
+ * Arguments for resolving a context from a path.
7
+ */
5
8
  export type ContextPathResolveArgs = {
9
+ /**
10
+ * Callback to extract a context id from a path.
11
+ * @param path string - the path to extract the context id from
12
+ * @returns string | undefined - the context id or undefined
13
+ */
6
14
  extract?: (path: string) => string | undefined;
15
+ /**
16
+ * Callback to validate a context id.
17
+ * @param contextId string - the context id to validate
18
+ * @returns boolean - true if the context id is valid
19
+ */
7
20
  validate?: (contextId: string) => boolean;
8
21
  };
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
+ */
9
37
  export declare const extractContextIdFromPath: (path: string, matcher?: RegExp) => string | undefined;
38
+ /**
39
+ * Method will try to resolve a context from a path.
40
+ * The method will return a function that takes a path and returns an observable of the resolved context.
41
+ * The method will use the context module to resolve the context.
42
+ * The method will use the extract and validate methods from the args to extract and validate the context id.
43
+ * If the context id is not valid, the method will throw an error.
44
+ * If the context id is valid, the method will return an observable of the resolved context.
45
+ * If the context id is not found, the method will return an empty observable.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const resolve = resolveContextFromPath(modules.context);
50
+ * resolve(
51
+ * '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?foobar#example'
52
+ * ).subscribe(console.log);
53
+ * ```
54
+ *
55
+ * @param context The context module.
56
+ * @returns A function that takes a path and returns an Observable of the resolved context item.
57
+ */
10
58
  export interface resolveContextFromPath {
11
59
  (context: ModuleType<ContextModule>): (path: string) => Observable<ContextItem>;
12
60
  }
61
+ /**
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const resolve = resolveContextFromPath(
66
+ * modules.context,
67
+ * {
68
+ * extract: (path) => path.find(extractingContextFromPath),
69
+ * validate: (id) => isValidContextId(id)
70
+ * });
71
+ * resolve(
72
+ * '/apps/context/7fd97952-7fe6-409b-a6dc-292dbf0e50d7?foobar#example'
73
+ * ).subscribe(console.log);
74
+ * ```
75
+ *
76
+ * @param context The context module.
77
+ * @param args The arguments for resolving the path.
78
+ * @returns A function that takes a path and returns an Observable of the resolved context item.
79
+ */
13
80
  export interface resolveContextFromPath {
14
81
  (context: ModuleType<ContextModule>, args: ContextPathResolveArgs): (path: string) => Observable<ContextItem>;
15
82
  }
@@ -1,7 +1,21 @@
1
1
  import { type ContextModuleConfig } from '../configurator';
2
2
  import { type ContextPathResolveArgs } from './resolve-context-from-path';
3
+ /**
4
+ * Resolves the initial context from the parent module.
5
+ *
6
+ * @param ref - parent modules.
7
+ * @returns An Observable of the resolved initial context.
8
+ */
3
9
  export declare const resolveContextFromParent: ContextModuleConfig['resolveInitialContext'];
10
+ /**
11
+ * Resolves the initial context for a Fusion Framework context module.
12
+ *
13
+ * will try to resolve the initial context from the path, and if that fails, it will try to resolve the context from the parent.
14
+ *
15
+ * @param options - Optional configuration for resolving the context path.
16
+ * @returns A function that accepts the module's reference and modules, and returns an Observable of the resolved initial context.
17
+ */
4
18
  export declare const resolveInitialContext: (options?: {
5
19
  path?: ContextPathResolveArgs;
6
- }) => Required<ContextModuleConfig>['resolveInitialContext'];
20
+ }) => Required<ContextModuleConfig>["resolveInitialContext"];
7
21
  export default resolveInitialContext;
@@ -1 +1 @@
1
- export declare const version = "5.0.7";
1
+ export declare const version = "5.0.8";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-module-context",
3
- "version": "5.0.7",
3
+ "version": "5.0.8",
4
4
  "description": "",
5
5
  "main": "./dist/esm/index.js",
6
6
  "exports": {
@@ -45,19 +45,19 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "fast-deep-equal": "^3.1.3",
48
- "@equinor/fusion-query": "^5.0.5"
48
+ "@equinor/fusion-query": "^5.1.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "rxjs": "^7.8.1",
52
- "typescript": "^5.4.2",
53
- "@equinor/fusion-framework-module-navigation": "^4.0.2",
54
- "@equinor/fusion-framework-module": "^4.3.1",
55
- "@equinor/fusion-framework-module-event": "^4.1.2",
56
- "@equinor/fusion-framework-module-services": "^4.1.0"
52
+ "typescript": "^5.5.3",
53
+ "@equinor/fusion-framework-module": "^4.3.2",
54
+ "@equinor/fusion-framework-module-navigation": "^4.0.3",
55
+ "@equinor/fusion-framework-module-event": "^4.2.0",
56
+ "@equinor/fusion-framework-module-services": "^4.1.1"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "rxjs": "^7.8.1",
60
- "@equinor/fusion-framework-module": "^4.3.1"
60
+ "@equinor/fusion-framework-module": "^4.3.2"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsc -b"
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '5.0.7';
2
+ export const version = '5.0.8';