@equinor/fusion-framework-module-context 4.0.10 → 4.0.13

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.
@@ -0,0 +1 @@
1
+ export declare const version = "4.0.13";
package/package.json CHANGED
@@ -1,53 +1,52 @@
1
1
  {
2
- "name": "@equinor/fusion-framework-module-context",
3
- "version": "4.0.10",
4
- "description": "",
5
- "main": "./dist/esm/index.js",
6
- "exports": {
7
- ".": "./dist/esm/index.js",
8
- "./package.json": "./package.json",
9
- "./utils": "./dist/esm/utils/index.js"
10
- },
11
- "types": "index.d.ts",
12
- "typesVersions": {
13
- ">=4.2": {
14
- "*": [
15
- "dist/types/*"
16
- ],
17
- "utils": [
18
- "dist/types/utils/index.d.ts"
19
- ]
20
- }
21
- },
22
- "scripts": {
23
- "build": "tsc -b",
24
- "prepack": "yarn build"
25
- },
26
- "keywords": [],
27
- "author": "",
28
- "license": "ISC",
29
- "publishConfig": {
30
- "access": "public"
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "git+https://github.com/equinor/fusion-framework.git",
35
- "directory": "packages/modules/context"
36
- },
37
- "dependencies": {
38
- "@equinor/fusion-query": "^3.0.2",
39
- "fast-deep-equal": "^3.1.3"
40
- },
41
- "devDependencies": {
42
- "@equinor/fusion-framework-module": "^4.2.1",
43
- "@equinor/fusion-framework-module-event": "^4.0.2",
44
- "@equinor/fusion-framework-module-navigation": "^3.0.1",
45
- "@equinor/fusion-framework-module-services": "^3.1.3",
46
- "rxjs": "^7.5.7",
47
- "typescript": "^5.1.3"
48
- },
49
- "peerDependencies": {
50
- "@equinor/fusion-framework-module": ">=1.2.5",
51
- "rxjs": "^7.5.7"
2
+ "name": "@equinor/fusion-framework-module-context",
3
+ "version": "4.0.13",
4
+ "description": "",
5
+ "main": "./dist/esm/index.js",
6
+ "exports": {
7
+ ".": "./dist/esm/index.js",
8
+ "./package.json": "./package.json",
9
+ "./utils": "./dist/esm/utils/index.js"
10
+ },
11
+ "types": "index.d.ts",
12
+ "typesVersions": {
13
+ ">=4.2": {
14
+ "*": [
15
+ "dist/types/*"
16
+ ],
17
+ "utils": [
18
+ "dist/types/utils/index.d.ts"
19
+ ]
52
20
  }
53
- }
21
+ },
22
+ "keywords": [],
23
+ "author": "",
24
+ "license": "ISC",
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/equinor/fusion-framework.git",
31
+ "directory": "packages/modules/context"
32
+ },
33
+ "dependencies": {
34
+ "fast-deep-equal": "^3.1.3",
35
+ "@equinor/fusion-query": "^3.0.7"
36
+ },
37
+ "devDependencies": {
38
+ "rxjs": "^7.8.1",
39
+ "typescript": "^5.1.3",
40
+ "@equinor/fusion-framework-module": "^4.2.4",
41
+ "@equinor/fusion-framework-module-event": "^4.0.5",
42
+ "@equinor/fusion-framework-module-navigation": "^3.0.5",
43
+ "@equinor/fusion-framework-module-services": "^3.1.5"
44
+ },
45
+ "peerDependencies": {
46
+ "rxjs": "^7.8.1",
47
+ "@equinor/fusion-framework-module": "^4.2.4"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc -b"
51
+ }
52
+ }
@@ -18,7 +18,7 @@ import type {
18
18
  import type { ContextItem, QueryContextParameters, RelatedContextParameters } from './types';
19
19
 
20
20
  export type ContextConfigBuilderCallback = <TDeps extends Array<AnyModule> = []>(
21
- builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>
21
+ builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>,
22
22
  ) => void | Promise<void>;
23
23
 
24
24
  export class ContextConfigBuilder<
@@ -27,15 +27,18 @@ export class ContextConfigBuilder<
27
27
  TInit extends ModuleInitializerArgs<any, any> = ModuleInitializerArgs<
28
28
  ContextModuleConfigurator,
29
29
  TModules
30
- >
30
+ >,
31
31
  > {
32
32
  #init: TInit;
33
- constructor(init: TInit, public config: Partial<ContextModuleConfig> = {}) {
33
+ constructor(
34
+ init: TInit,
35
+ public config: Partial<ContextModuleConfig> = {},
36
+ ) {
34
37
  this.#init = init;
35
38
  }
36
39
 
37
40
  requireInstance<TKey extends string = Extract<keyof Modules, string>>(
38
- module: TKey
41
+ module: TKey,
39
42
  ): Promise<ModuleType<Modules[TKey]>>;
40
43
 
41
44
  requireInstance<T>(module: string): Promise<T>;
@@ -85,7 +88,7 @@ export class ContextConfigBuilder<
85
88
  | QueryFn<ContextItem[], RelatedContextParameters>
86
89
  | QueryCtorOptions<ContextItem[], RelatedContextParameters>;
87
90
  },
88
- expire = 1 * 60 * 1000
91
+ expire = 1 * 60 * 1000,
89
92
  ): void {
90
93
  this.config.client = {
91
94
  get:
@@ -40,10 +40,10 @@ export interface IContextProvider {
40
40
  resolveContext: (current: ContextItem) => Observable<ContextItem>;
41
41
  resolveContextAsync: (current: ContextItem) => Promise<ContextItem>;
42
42
  relatedContexts: (
43
- args: RelatedContextParameters
43
+ args: RelatedContextParameters,
44
44
  ) => Observable<Array<ContextItem<Record<string, unknown>>>>;
45
45
  relatedContextsAsync: (
46
- args: RelatedContextParameters
46
+ args: RelatedContextParameters,
47
47
  ) => Promise<Array<ContextItem<Record<string, unknown>>>>;
48
48
  clearCurrentContext: VoidFunction;
49
49
 
@@ -52,12 +52,12 @@ export interface IContextProvider {
52
52
 
53
53
  setCurrentContext(
54
54
  context: ContextItem<Record<string, unknown>> | null,
55
- opt?: { validate?: boolean; resolve?: boolean }
55
+ opt?: { validate?: boolean; resolve?: boolean },
56
56
  ): Observable<ContextItem<Record<string, unknown>> | null>;
57
57
 
58
58
  setCurrentContextAsync(
59
59
  context: ContextItem<Record<string, unknown>> | null,
60
- opt?: { validate?: boolean; resolve?: boolean }
60
+ opt?: { validate?: boolean; resolve?: boolean },
61
61
  ): Promise<ContextItem<Record<string, unknown>> | null>;
62
62
  }
63
63
 
@@ -97,7 +97,7 @@ export class ContextProvider implements IContextProvider {
97
97
  console.warn(
98
98
  '@deprecated',
99
99
  'ContextProvider.currentContext',
100
- 'use setCurrentContextById|setCurrentContext|clearCurrentContext'
100
+ 'use setCurrentContextById|setCurrentContext|clearCurrentContext',
101
101
  );
102
102
  if (context === undefined) {
103
103
  throw Error('not allowed to set current context as undefined undefined!');
@@ -116,7 +116,7 @@ export class ContextProvider implements IContextProvider {
116
116
  if (args.parentContext) {
117
117
  console.warn(
118
118
  '@deprecated',
119
- 'parentContext as arg is deprecated, use ContextProvider.connectParentContext'
119
+ 'parentContext as arg is deprecated, use ContextProvider.connectParentContext',
120
120
  );
121
121
  }
122
122
 
@@ -150,7 +150,7 @@ export class ContextProvider implements IContextProvider {
150
150
  canBubble: true,
151
151
  detail: { previous, next },
152
152
  });
153
- })
153
+ }),
154
154
  );
155
155
  this.#subscriptions.add(
156
156
  /** observe event from child modules */
@@ -159,7 +159,7 @@ export class ContextProvider implements IContextProvider {
159
159
  if (e.source !== this && e.detail.next !== undefined) {
160
160
  this.setCurrentContext(e.detail.next);
161
161
  }
162
- })
162
+ }),
163
163
  );
164
164
  }
165
165
 
@@ -167,15 +167,15 @@ export class ContextProvider implements IContextProvider {
167
167
  this.#contextQueue
168
168
  .pipe(
169
169
  switchMap((next) => next),
170
- tap((x) => console.debug('ContextProvider::#contextQueue', x))
170
+ tap((x) => console.debug('ContextProvider::#contextQueue', x)),
171
171
  )
172
- .subscribe((context) => this.#contextClient.setCurrentContext(context ?? null))
172
+ .subscribe((context) => this.#contextClient.setCurrentContext(context ?? null)),
173
173
  );
174
174
  }
175
175
 
176
176
  public connectParentContext(
177
177
  provider: IContextProvider,
178
- opt?: { skipFirst: boolean }
178
+ opt?: { skipFirst: boolean },
179
179
  ): Subscription {
180
180
  const parentContext$ = provider.currentContext$.pipe(
181
181
  // do not set context if parent has not initialized
@@ -185,7 +185,7 @@ export class ContextProvider implements IContextProvider {
185
185
  console.debug(
186
186
  'ContextProvider::connectParentContext',
187
187
  'skipping first item',
188
- next
188
+ next,
189
189
  );
190
190
  return false;
191
191
  }
@@ -199,7 +199,7 @@ export class ContextProvider implements IContextProvider {
199
199
  source: this,
200
200
  detail: next,
201
201
  cancelable: true,
202
- }
202
+ },
203
203
  );
204
204
  return { next, canceled: onParentContextChanged?.canceled };
205
205
  }
@@ -215,16 +215,16 @@ export class ContextProvider implements IContextProvider {
215
215
  console.warn(
216
216
  'ContextProvider::onParentContextChanged',
217
217
  'setCurrentContext',
218
- err
218
+ err,
219
219
  );
220
220
  return EMPTY;
221
- })
221
+ }),
222
222
  );
223
223
  }),
224
224
  catchError((err) => {
225
225
  console.warn('ContextProvider::onParentContextChanged', 'unhandled exception', err);
226
226
  return EMPTY;
227
- })
227
+ }),
228
228
  );
229
229
 
230
230
  const subscription = parentContext$.subscribe();
@@ -239,7 +239,7 @@ export class ContextProvider implements IContextProvider {
239
239
  .resolveContext(id)
240
240
  .pipe(
241
241
  filter((item): item is ContextItem => !!item),
242
- switchMap((item) => this.setCurrentContext(item))
242
+ switchMap((item) => this.setCurrentContext(item)),
243
243
  )
244
244
  .subscribe(subscriber);
245
245
  } catch (err) {
@@ -265,7 +265,7 @@ export class ContextProvider implements IContextProvider {
265
265
  */
266
266
  public setCurrentContext<T extends ContextItem<Record<string, unknown>> | null>(
267
267
  context: T,
268
- opt?: { validate?: boolean; resolve?: boolean }
268
+ opt?: { validate?: boolean; resolve?: boolean },
269
269
  ): Observable<T> {
270
270
  /** signal for aborting the queue entry */
271
271
  const abort$ = new Subject();
@@ -286,7 +286,7 @@ export class ContextProvider implements IContextProvider {
286
286
  subject$.error(err);
287
287
  /** skip setting any context */
288
288
  return EMPTY;
289
- })
289
+ }),
290
290
  );
291
291
 
292
292
  /** add task to internal queue */
@@ -294,13 +294,13 @@ export class ContextProvider implements IContextProvider {
294
294
 
295
295
  return subject$.pipe(
296
296
  /** if caller subscribes, unsubscribe should abort queue entry */
297
- finalize(() => abort$.next(true))
297
+ finalize(() => abort$.next(true)),
298
298
  );
299
299
  }
300
300
 
301
301
  protected _setCurrentContext<T extends ContextItem<Record<string, unknown>> | null>(
302
302
  context: T,
303
- opt?: { validate?: boolean; resolve?: boolean }
303
+ opt?: { validate?: boolean; resolve?: boolean },
304
304
  ): Observable<T> {
305
305
  return new Observable((subscriber) => {
306
306
  if (context === this.currentContext) {
@@ -327,7 +327,7 @@ export class ContextProvider implements IContextProvider {
327
327
  source: this,
328
328
  cancelable: true,
329
329
  detail: { context },
330
- }
330
+ },
331
331
  );
332
332
  if (event?.canceled) {
333
333
  throw Error('resolving of context was canceled');
@@ -340,8 +340,8 @@ export class ContextProvider implements IContextProvider {
340
340
  map((resolved) => ({
341
341
  context,
342
342
  resolved,
343
- }))
344
- )
343
+ })),
344
+ ),
345
345
  ),
346
346
  /** notify event observers that context was resolved */
347
347
  switchMap(async ({ context, resolved }) => {
@@ -351,7 +351,7 @@ export class ContextProvider implements IContextProvider {
351
351
  source: this,
352
352
  cancelable: true,
353
353
  detail: { context, resolved },
354
- }
354
+ },
355
355
  );
356
356
  if (event?.canceled) {
357
357
  throw Error('resolving of context was canceled');
@@ -360,8 +360,8 @@ export class ContextProvider implements IContextProvider {
360
360
  }),
361
361
  /** recursive set current context without validation and resolve */
362
362
  switchMap((resolved) =>
363
- this._setCurrentContext(resolved as unknown as T)
364
- )
363
+ this._setCurrentContext(resolved as unknown as T),
364
+ ),
365
365
  )
366
366
  .subscribe(subscriber);
367
367
  }
@@ -382,7 +382,7 @@ export class ContextProvider implements IContextProvider {
382
382
  }
383
383
 
384
384
  return context;
385
- })
385
+ }),
386
386
  )
387
387
  .subscribe((context) => {
388
388
  subscriber.next(context);
@@ -393,7 +393,7 @@ export class ContextProvider implements IContextProvider {
393
393
 
394
394
  public async setCurrentContextAsync<T extends ContextItem<Record<string, unknown>> | null>(
395
395
  context: T,
396
- opt?: { validate?: boolean; resolve?: boolean }
396
+ opt?: { validate?: boolean; resolve?: boolean },
397
397
  ): Promise<T> {
398
398
  return lastValueFrom(this.setCurrentContext(context, opt));
399
399
  }
@@ -404,7 +404,7 @@ export class ContextProvider implements IContextProvider {
404
404
  // TODO
405
405
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
406
406
  /* @ts-ignore */
407
- this.#contextParameterFn({ search, type: this.#contextType })
407
+ this.#contextParameterFn({ search, type: this.#contextType }),
408
408
  )
409
409
  .pipe(map((x) => x.value));
410
410
 
@@ -421,7 +421,7 @@ export class ContextProvider implements IContextProvider {
421
421
  }
422
422
 
423
423
  public resolveContext(
424
- item: ContextItem<Record<string, unknown>>
424
+ item: ContextItem<Record<string, unknown>>,
425
425
  ): Observable<ContextItem<Record<string, unknown>>> {
426
426
  return this.relatedContexts({ item, filter: { type: this.#contextType } }).pipe(
427
427
  map((x) => x.filter((item) => this.validateContext(item))),
@@ -434,28 +434,28 @@ export class ContextProvider implements IContextProvider {
434
434
  console.warn(
435
435
  'ContextProvider::relatedContext',
436
436
  'multiple items found 🤣',
437
- values
437
+ values,
438
438
  );
439
439
  }
440
440
  return value;
441
- })
441
+ }),
442
442
  );
443
443
  }
444
444
 
445
445
  public resolveContextAsync(
446
- item: ContextItem<Record<string, unknown>>
446
+ item: ContextItem<Record<string, unknown>>,
447
447
  ): Promise<ContextItem<Record<string, unknown>>> {
448
448
  return lastValueFrom(this.resolveContext(item));
449
449
  }
450
450
 
451
451
  public relatedContexts(
452
- args: RelatedContextParameters
452
+ args: RelatedContextParameters,
453
453
  ): Observable<Array<ContextItem<Record<string, unknown>>>> {
454
454
  if (!this.#contextRelated) {
455
455
  return throwError(() =>
456
456
  Error(
457
- 'ContextProvider::relatedContexts - no client defined for resolving related context'
458
- )
457
+ 'ContextProvider::relatedContexts - no client defined for resolving related context',
458
+ ),
459
459
  );
460
460
  }
461
461
  return this.#contextRelated.query(args).pipe(
@@ -465,12 +465,12 @@ export class ContextProvider implements IContextProvider {
465
465
  throw err.cause;
466
466
  }
467
467
  throw err;
468
- })
468
+ }),
469
469
  );
470
470
  }
471
471
 
472
472
  public relatedContextsAsync(
473
- args: RelatedContextParameters
473
+ args: RelatedContextParameters,
474
474
  ): Promise<Array<ContextItem<Record<string, unknown>>>> {
475
475
  return lastValueFrom(this.relatedContexts(args));
476
476
  }
@@ -54,7 +54,7 @@ export class ContextClient extends Observable<ContextItem | null> {
54
54
  throw err.cause;
55
55
  }
56
56
  throw err;
57
- })
57
+ }),
58
58
  );
59
59
  }
60
60
 
@@ -50,12 +50,12 @@ export interface ContextModuleConfig {
50
50
 
51
51
  resolveContext?: (
52
52
  this: IContextProvider,
53
- item: ContextItem | null
53
+ item: ContextItem | null,
54
54
  ) => ReturnType<IContextProvider['resolveContext']>;
55
55
 
56
56
  validateContext?: (
57
57
  this: IContextProvider,
58
- item: ContextItem | null
58
+ item: ContextItem | null,
59
59
  ) => ReturnType<IContextProvider['validateContext']>;
60
60
 
61
61
  resolveInitialContext?: (args: {
@@ -79,7 +79,7 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator {
79
79
  }
80
80
 
81
81
  protected async _getServiceProvider(
82
- init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>
82
+ init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule]>,
83
83
  ): Promise<IApiProvider> {
84
84
  if (init.hasModule('services')) {
85
85
  return init.requireInstance('services');
@@ -94,14 +94,17 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator {
94
94
  }
95
95
 
96
96
  public async createConfig(
97
- init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule, NavigationModule]>
97
+ init: ModuleInitializerArgs<IContextModuleConfigurator, [ServicesModule, NavigationModule]>,
98
98
  ): Promise<ContextModuleConfig> {
99
- const config = await this.#configBuilders.reduce(async (cur, cb) => {
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- const builder = new ContextConfigBuilder<any, any>(init, await cur);
102
- await Promise.resolve(cb(builder));
103
- return Object.assign(cur, builder.config);
104
- }, Promise.resolve({} as Partial<ContextModuleConfig>));
99
+ const config = await this.#configBuilders.reduce(
100
+ async (cur, cb) => {
101
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
+ const builder = new ContextConfigBuilder<any, any>(init, await cur);
103
+ await Promise.resolve(cb(builder));
104
+ return Object.assign(cur, builder.config);
105
+ },
106
+ Promise.resolve({} as Partial<ContextModuleConfig>),
107
+ );
105
108
 
106
109
  config.resolveInitialContext ??= resolveInitialContext();
107
110
 
@@ -124,7 +127,7 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator {
124
127
  contextClient.query(
125
128
  'v1',
126
129
  { query },
127
- { selector: queryContextSelector }
130
+ { selector: queryContextSelector },
128
131
  ),
129
132
  },
130
133
  // TODO - might cast to checksum
@@ -137,7 +140,7 @@ export class ContextModuleConfigurator implements IContextModuleConfigurator {
137
140
  return contextClient.related(
138
141
  'v1',
139
142
  { id: args.item.id, query: { filter: args.filter } },
140
- { selector: relatedContextSelector }
143
+ { selector: relatedContextSelector },
141
144
  );
142
145
  },
143
146
  },
package/src/module.ts CHANGED
@@ -8,7 +8,7 @@ import { NavigationModule } from '@equinor/fusion-framework-module-navigation';
8
8
 
9
9
  import { IContextModuleConfigurator, ContextModuleConfigurator } from './configurator';
10
10
  import { IContextProvider, ContextProvider } from './ContextProvider';
11
- import { ContextItem } from 'types';
11
+ import { ContextItem } from './types';
12
12
 
13
13
  export type ContextModuleKey = 'context';
14
14
 
@@ -41,8 +41,8 @@ export const module: ContextModule = {
41
41
  args.modules.context.setCurrentContext(item, {
42
42
  validate: true,
43
43
  resolve: true,
44
- })
45
- )
44
+ }),
45
+ ),
46
46
  )
47
47
  : EMPTY;
48
48
 
@@ -53,17 +53,17 @@ export const module: ContextModule = {
53
53
  console.warn(
54
54
  'ContextModule.postInitialize',
55
55
  'failed to resolve initial context',
56
- err
56
+ err,
57
57
  );
58
58
  return EMPTY;
59
- })
59
+ }),
60
60
  )
61
61
  .subscribe({
62
62
  next: (item) => {
63
63
  console.debug(
64
64
  'ContextModule.postInitialize',
65
65
  `initial context was resolved to [${item ? item.id : 'none'}]`,
66
- item
66
+ item,
67
67
  );
68
68
  },
69
69
  complete: () => {
@@ -72,7 +72,7 @@ export const module: ContextModule = {
72
72
  }
73
73
  subscriber.complete();
74
74
  },
75
- })
75
+ }),
76
76
  );
77
77
  });
78
78
 
@@ -19,8 +19,8 @@ export const enableContext = (
19
19
  builder: ContextConfigBuilder<
20
20
  TDeps,
21
21
  ModuleInitializerArgs<IContextModuleConfigurator, TDeps>
22
- >
23
- ) => void | Promise<void>
22
+ >,
23
+ ) => void | Promise<void>,
24
24
  ): void => {
25
25
  configurator.addConfig({
26
26
  module,
@@ -22,7 +22,7 @@ export const resolveInitialContext =
22
22
  const pathResolver = resolveContextFromPath(context, options?.path);
23
23
  return concat(
24
24
  navigation ? pathResolver(navigation.path.pathname) : EMPTY,
25
- resolveContextFromParent({ ref, modules })
25
+ resolveContextFromParent({ ref, modules }),
26
26
  ).pipe(first());
27
27
  };
28
28
 
package/src/version.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Generated by genversion.
2
+ export const version = '4.0.13';
package/tsconfig.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "outDir": "dist/esm",
5
5
  "rootDir": "src",
6
6
  "declarationDir": "./dist/types",
7
- "baseUrl": "src",
7
+
8
8
  },
9
9
  "references": [
10
10
  {