@equinor/fusion-framework-module-bookmark 4.1.0 → 4.1.2
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/dist/esm/BookmarkProvider.js +10 -5
- package/dist/esm/BookmarkProvider.js.map +1 -1
- package/dist/esm/__tests__/BookmarkProvider.test.js +34 -0
- package/dist/esm/__tests__/BookmarkProvider.test.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/BookmarkProvider.d.ts +5 -2
- package/dist/types/__tests__/BookmarkProvider.test.d.ts +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +13 -10
- package/CHANGELOG.md +0 -821
- package/src/BookmarkClient.interface.ts +0 -157
- package/src/BookmarkClient.ts +0 -290
- package/src/BookmarkFlowError.ts +0 -38
- package/src/BookmarkModuleConfigurator.ts +0 -412
- package/src/BookmarkProvider.events.ts +0 -87
- package/src/BookmarkProvider.interface.ts +0 -180
- package/src/BookmarkProvider.selectors.ts +0 -69
- package/src/BookmarkProvider.ts +0 -1549
- package/src/BookmarkProviderError.ts +0 -19
- package/src/__tests__/mock/bookmark-mock.test.ts +0 -199
- package/src/bookmark-actions.ts +0 -132
- package/src/bookmark-config.schema.ts +0 -55
- package/src/bookmark-flows/bookmark-api-flows.ts +0 -45
- package/src/bookmark-flows/handle-add-bookmark-as-favorite.ts +0 -49
- package/src/bookmark-flows/handle-create-bookmark.ts +0 -47
- package/src/bookmark-flows/handle-delete-bookmark.ts +0 -47
- package/src/bookmark-flows/handle-fetch-all-bookmark.ts +0 -53
- package/src/bookmark-flows/handle-fetch-bookmark-data.ts +0 -58
- package/src/bookmark-flows/handle-fetch-bookmark.ts +0 -64
- package/src/bookmark-flows/handle-remove-bookmark-from-favorites.ts +0 -49
- package/src/bookmark-flows/handle-remove-bookmark.ts +0 -76
- package/src/bookmark-flows/handle-update-bookmark.ts +0 -48
- package/src/bookmark-flows/index.ts +0 -10
- package/src/bookmark-module.ts +0 -98
- package/src/bookmark.schemas.ts +0 -81
- package/src/create-bookmark-reducer.ts +0 -149
- package/src/create-bookmark-store.ts +0 -61
- package/src/enable-bookmark.ts +0 -44
- package/src/index.ts +0 -43
- package/src/mock/BookmarkMockClient.ts +0 -310
- package/src/mock/BookmarkMockConfigurator.ts +0 -159
- package/src/mock/index.ts +0 -25
- package/src/mock/module.ts +0 -64
- package/src/types.ts +0 -121
- package/src/version.ts +0 -2
- package/tsconfig.json +0 -30
- package/vitest.config.ts +0 -11
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import type { ZodError } from 'zod';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
BaseConfigBuilder,
|
|
5
|
-
type ConfigBuilderCallback,
|
|
6
|
-
type ConfigBuilderCallbackArgs,
|
|
7
|
-
type ModulesInstanceType,
|
|
8
|
-
} from '@equinor/fusion-framework-module';
|
|
9
|
-
|
|
10
|
-
import type { IApiProvider, ServicesModule } from '@equinor/fusion-framework-module-services';
|
|
11
|
-
import type { AppModuleProvider } from '@equinor/fusion-framework-module-app';
|
|
12
|
-
import type { ILogger, LogLevel } from '@equinor/fusion-log';
|
|
13
|
-
|
|
14
|
-
import { BookmarkClient } from './BookmarkClient';
|
|
15
|
-
import type { BookmarkModule } from './bookmark-module';
|
|
16
|
-
import { bookmarkConfigSchema, parseBookmarkConfig } from './bookmark-config.schema';
|
|
17
|
-
import type { BookmarkModuleConfig } from './types';
|
|
18
|
-
import type { BookmarkProvider } from './BookmarkProvider';
|
|
19
|
-
|
|
20
|
-
const initialBookmarkConfig = bookmarkConfigSchema
|
|
21
|
-
.pick({
|
|
22
|
-
filters: true,
|
|
23
|
-
sourceSystem: true,
|
|
24
|
-
resolve: true,
|
|
25
|
-
})
|
|
26
|
-
.partial()
|
|
27
|
-
.optional();
|
|
28
|
-
|
|
29
|
-
const parseInitialBookmarkConfigConfig = (initial?: unknown): BookmarkModuleConfig => {
|
|
30
|
-
return initialBookmarkConfig.parse(initial) as BookmarkModuleConfig;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Configurator for the bookmark module.
|
|
35
|
-
*
|
|
36
|
-
* Provides a builder-style API for setting the source system, bookmark client,
|
|
37
|
-
* context/application resolvers, filters, and parent provider before the module
|
|
38
|
-
* is initialised. Extends {@link BaseConfigBuilder} and produces a validated
|
|
39
|
-
* {@link BookmarkModuleConfig} at build time.
|
|
40
|
-
*
|
|
41
|
-
* In most cases you interact with this class through the callback provided to
|
|
42
|
-
* {@link enableBookmark} rather than instantiating it directly.
|
|
43
|
-
*/
|
|
44
|
-
export class BookmarkModuleConfigurator extends BaseConfigBuilder<BookmarkModuleConfig> {
|
|
45
|
-
#log?: ILogger;
|
|
46
|
-
/** Default expiration time, in milliseconds, for bookmarks. */
|
|
47
|
-
defaultExpireTime = 1 * 60 * 1000;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Constructs a new `BookmarkModuleConfigurator`.
|
|
51
|
-
*
|
|
52
|
-
* @param options - Optional configurator options.
|
|
53
|
-
* @param options.log - Logger instance inherited from the parent module, if any.
|
|
54
|
-
* @param options.ref - Reference to sibling module instances available during configuration.
|
|
55
|
-
*/
|
|
56
|
-
constructor(options?: { log?: ILogger; ref?: ModulesInstanceType<[BookmarkModule]> }) {
|
|
57
|
-
super();
|
|
58
|
-
const { log } = options ?? {};
|
|
59
|
-
this.#log = log;
|
|
60
|
-
this._set('log', async () => log);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Sets the log level for the bookmark configurator.
|
|
65
|
-
*
|
|
66
|
-
* @param level - The log level to set. Allowed values are:
|
|
67
|
-
* - 0: No logging
|
|
68
|
-
* - 1: Error messages only
|
|
69
|
-
* - 2: Error and warning messages
|
|
70
|
-
* - 3: Error, warning, and info messages
|
|
71
|
-
* - 4: Error, warning, info, and debug messages
|
|
72
|
-
*/
|
|
73
|
-
public setLogLevel(level: LogLevel) {
|
|
74
|
-
this._set('logLevel', async () => level);
|
|
75
|
-
// propagate the level to the configurator's own logger, if one is set
|
|
76
|
-
if (this.#log) {
|
|
77
|
-
this.#log.level = level;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Sets the client for interacting with bookmark operations.
|
|
83
|
-
* The client argument can be either a client object with predefined methods for bookmark operations or a callback function that creates and returns such a client object.
|
|
84
|
-
* This method enables the configuration of how the bookmark module interacts with the backend or any other service to perform operations such as getting, creating, or updating bookmarks.
|
|
85
|
-
*
|
|
86
|
-
* @param client A client object or a callback function that returns a client object.
|
|
87
|
-
* - If a callback function is provided, it receives an initializer function as its argument,
|
|
88
|
-
* and it should return a Promise that resolves to a client object.
|
|
89
|
-
* - If a client object is provided directly, it is wrapped in a Promise and used as-is.
|
|
90
|
-
*
|
|
91
|
-
* @see {@link BookmarkModuleConfig.client}
|
|
92
|
-
*/
|
|
93
|
-
public setClient(
|
|
94
|
-
client: ConfigBuilderCallback<BookmarkModuleConfig['client']> | BookmarkModuleConfig['client'],
|
|
95
|
-
) {
|
|
96
|
-
// a callback receives the module initializer and resolves the client itself
|
|
97
|
-
if (typeof client === 'function') {
|
|
98
|
-
this._set('client', (init) => client(init));
|
|
99
|
-
} else {
|
|
100
|
-
this._set('client', async () => client);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Sets the parent configuration for the bookmark module.
|
|
106
|
-
* This allows the bookmark module to inherit configuration from a parent module.
|
|
107
|
-
*
|
|
108
|
-
* @param parent - A callback function or a configuration object that provides the parent configuration.
|
|
109
|
-
* - If a callback function is provided, it receives an initializer function as its argument and should return a Promise that resolves to the parent configuration object.
|
|
110
|
-
* - If a configuration object is provided directly, it is wrapped in a Promise and used as-is.
|
|
111
|
-
*/
|
|
112
|
-
public setParent(
|
|
113
|
-
parent: ConfigBuilderCallback<BookmarkModuleConfig['parent']> | BookmarkModuleConfig['parent'],
|
|
114
|
-
) {
|
|
115
|
-
// a callback receives the module initializer and resolves the parent itself
|
|
116
|
-
if (typeof parent === 'function') {
|
|
117
|
-
this._set('parent', (init) => parent(init));
|
|
118
|
-
} else {
|
|
119
|
-
this._set('parent', async () => parent);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Set the source system for the bookmark module.
|
|
125
|
-
* This is used to tag bookmarks with their originating system for filtering or categorization purposes.
|
|
126
|
-
* @param sourceSystem - A callback function that returns the source system or a string value of the source system.
|
|
127
|
-
*
|
|
128
|
-
* Example:
|
|
129
|
-
* ```
|
|
130
|
-
* configurator.setSourceSystem('MyApplication');
|
|
131
|
-
* ```
|
|
132
|
-
* or
|
|
133
|
-
* ```
|
|
134
|
-
* configurator.setSourceSystem((init) => 'MyApplication');
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
public setSourceSystem(
|
|
138
|
-
sourceSystem:
|
|
139
|
-
| ConfigBuilderCallback<BookmarkModuleConfig['sourceSystem']>
|
|
140
|
-
| BookmarkModuleConfig['sourceSystem'],
|
|
141
|
-
) {
|
|
142
|
-
// a callback receives the module initializer and resolves the source system itself
|
|
143
|
-
if (typeof sourceSystem === 'function') {
|
|
144
|
-
this._set('sourceSystem', sourceSystem);
|
|
145
|
-
} else {
|
|
146
|
-
this._set('sourceSystem', async () => sourceSystem);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Set the context ID resolver for the bookmark module.
|
|
152
|
-
* This function is used to resolve the context ID dynamically, allowing for context-aware bookmark operations.
|
|
153
|
-
* @param cb - A callback function that returns the context ID resolver function.
|
|
154
|
-
*
|
|
155
|
-
* Example:
|
|
156
|
-
* ```
|
|
157
|
-
* configurator.setContextIdResolver((init) => () => 'currentContextId');
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
public setContextResolver(cb: ConfigBuilderCallback<BookmarkModuleConfig['resolve']['context']>) {
|
|
161
|
-
this._set('resolve.context', cb);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Set the application key resolver for the bookmark module.
|
|
166
|
-
* This function is used to resolve the application key dynamically, providing a way to associate bookmarks with specific applications.
|
|
167
|
-
* @param cb - A callback function that returns the application key resolver function.
|
|
168
|
-
*
|
|
169
|
-
* Example:
|
|
170
|
-
* ```
|
|
171
|
-
* configurator.setApplicationKeyResolver((init) => () => 'myApplicationKey');
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
public setApplicationResolver(
|
|
175
|
-
cb: ConfigBuilderCallback<BookmarkModuleConfig['resolve']['application']>,
|
|
176
|
-
) {
|
|
177
|
-
this._set('resolve.application', cb);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Sets a filter for the bookmark module.
|
|
182
|
-
* @template TKey - The filter key being set.
|
|
183
|
-
* @param key - The key of the filter to set.
|
|
184
|
-
* @param value - The value to set for the filter.
|
|
185
|
-
*
|
|
186
|
-
* Applied when fetching bookmarks
|
|
187
|
-
* - application: Only return bookmarks for the resolved application.
|
|
188
|
-
* - context: Only return bookmarks for the resolved context.
|
|
189
|
-
*/
|
|
190
|
-
public setFilter<TKey extends keyof BookmarkModuleConfig['filters']>(
|
|
191
|
-
key: TKey,
|
|
192
|
-
value: BookmarkModuleConfig['filters'][TKey],
|
|
193
|
-
) {
|
|
194
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
195
|
-
// @ts-expect-error
|
|
196
|
-
this._set(`filters.${key}`, async () => value);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Will set default configuration:
|
|
201
|
-
* - `client` - a default client is set
|
|
202
|
-
* - `resolveContextId` - a default context resolver is set
|
|
203
|
-
* - `resolveApplicationKey` - a default application key resolver is set
|
|
204
|
-
* - `sourceSystem` - a default source system is set
|
|
205
|
-
* @internal method to create config, will apply defaults if not provided during build of config.
|
|
206
|
-
* @param init - The config builder callback args.
|
|
207
|
-
* @param initial - An optional initial config to merge into the returned config.
|
|
208
|
-
* @returns The config object.
|
|
209
|
-
*/
|
|
210
|
-
protected _createConfig(
|
|
211
|
-
init: ConfigBuilderCallbackArgs,
|
|
212
|
-
initial?: Partial<BookmarkModuleConfig>,
|
|
213
|
-
) {
|
|
214
|
-
// check if parent is provided
|
|
215
|
-
if (!this._has('parent')) {
|
|
216
|
-
this.#log?.debug('No parent provided, using default parent');
|
|
217
|
-
|
|
218
|
-
// Check if parent and parent version compatible
|
|
219
|
-
const parentModules = init.ref as ModulesInstanceType<[BookmarkModule]>;
|
|
220
|
-
// only use the parent module's bookmark provider if it's actually present
|
|
221
|
-
if (parentModules && 'bookmark' in parentModules) {
|
|
222
|
-
const parent = parentModules.bookmark;
|
|
223
|
-
// `parent` is narrowed to `{ version: unknown }` by the `'version' in parent` check below,
|
|
224
|
-
// so it must be cast through `unknown` to access `BookmarkProvider`-specific members.
|
|
225
|
-
const parentProvider = parent as unknown as BookmarkProvider;
|
|
226
|
-
// only inherit from a parent whose version satisfies the minimum supported range
|
|
227
|
-
if ('version' in parent && parentProvider.version.satisfies('>=2.0.0')) {
|
|
228
|
-
this._set('parent', async () => parent);
|
|
229
|
-
} else {
|
|
230
|
-
this.#log?.warn('invalid version of parent BookmarkProvider provided');
|
|
231
|
-
}
|
|
232
|
-
} else {
|
|
233
|
-
this.#log?.info('No parent BookmarkProvider found');
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Ensure a default client is set if none is provided
|
|
238
|
-
if (!this._has('client')) {
|
|
239
|
-
this.#log?.debug('No client provided, using default client');
|
|
240
|
-
this._set('client', this._createDefaultClient.bind(this));
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Ensure a default context resolver is set if none is provided
|
|
244
|
-
if (!this._has('resolve.context')) {
|
|
245
|
-
this.#log?.debug('No context resolver provided, using default context resolver');
|
|
246
|
-
this._set('resolve.context', this._createDefaultContextResolver.bind(this));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Ensure a default application resolver is set if none is provided
|
|
250
|
-
if (!this._has('resolve.application')) {
|
|
251
|
-
this.#log?.debug('No application resolver provided, using default application resolver');
|
|
252
|
-
this._set('resolve.application', this._createDefaultApplicationResolver.bind(this));
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Ensure a default event provider is set if none is provided
|
|
256
|
-
if (!this._has('eventProvider')) {
|
|
257
|
-
this.#log?.debug('No event provider provided, using default event provider');
|
|
258
|
-
this._set('eventProvider', this._resolveEventProvider.bind(this));
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// call super to create config
|
|
262
|
-
return super._createConfig(init, parseInitialBookmarkConfigConfig(initial));
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* @internal Create a default context resolver for the bookmark module.
|
|
267
|
-
* @param init - The configuration initialization object.
|
|
268
|
-
* @returns A function that resolves the current context ID, or undefined if no context module is available.
|
|
269
|
-
*/
|
|
270
|
-
protected async _createDefaultContextResolver(
|
|
271
|
-
init: ConfigBuilderCallbackArgs,
|
|
272
|
-
): Promise<BookmarkModuleConfig['resolve']['context'] | undefined> {
|
|
273
|
-
// Check if context module is available and use context provider if available
|
|
274
|
-
if (init.hasModule('context')) {
|
|
275
|
-
this.#log?.debug('Context module available, awaiting instance');
|
|
276
|
-
const contextProvider = await init.requireInstance('context');
|
|
277
|
-
|
|
278
|
-
this.#log?.debug('Context provider available, creating context resolver');
|
|
279
|
-
return async () => {
|
|
280
|
-
this.#log?.debug('Resolving context for bookmarks');
|
|
281
|
-
const id = contextProvider.currentContext?.id;
|
|
282
|
-
return id ? { id } : undefined;
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* @internal Create a default application resolver for the bookmark module.
|
|
289
|
-
* @param init - The configuration initialization object.
|
|
290
|
-
* @returns A function that resolves the current application key, or undefined if no app module is available.
|
|
291
|
-
*/
|
|
292
|
-
protected async _createDefaultApplicationResolver(
|
|
293
|
-
init: ConfigBuilderCallbackArgs,
|
|
294
|
-
): Promise<BookmarkModuleConfig['resolve']['application'] | undefined> {
|
|
295
|
-
// Check if app module is available and use app provider if available
|
|
296
|
-
if (init.hasModule('app')) {
|
|
297
|
-
this.#log?.debug('App module available, awaiting instance');
|
|
298
|
-
const appProvider = await init.requireInstance('app');
|
|
299
|
-
|
|
300
|
-
this.#log?.debug('App provider available, creating application resolver');
|
|
301
|
-
return async () => {
|
|
302
|
-
const app = appProvider.current;
|
|
303
|
-
// only resolve the application if there is a currently loaded app
|
|
304
|
-
if (app) {
|
|
305
|
-
return {
|
|
306
|
-
appKey: app.appKey,
|
|
307
|
-
name: app.manifest?.name,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
this.#log?.warn('No current application found');
|
|
311
|
-
return undefined;
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* @internal Resolves the {@link AppModuleProvider} for the bookmark module.
|
|
318
|
-
* @param init - The configuration initialization object.
|
|
319
|
-
* @returns A promise that resolves to the app module provider, or undefined if unavailable.
|
|
320
|
-
*/
|
|
321
|
-
protected async _resolveAppProvider(
|
|
322
|
-
init: ConfigBuilderCallbackArgs,
|
|
323
|
-
): Promise<AppModuleProvider | undefined> {
|
|
324
|
-
// Check if app module is available
|
|
325
|
-
if (init.hasModule('app')) {
|
|
326
|
-
this.#log?.debug('App module available, awaiting instance');
|
|
327
|
-
return init.requireInstance('app');
|
|
328
|
-
}
|
|
329
|
-
this.#log?.debug('No app module available, will use ref to app module if available');
|
|
330
|
-
return undefined;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* @internal Create a default event provider for the bookmark module.
|
|
335
|
-
* @param init - The configuration initialization object.
|
|
336
|
-
* @returns A promise that resolves to the default event provider.
|
|
337
|
-
*/
|
|
338
|
-
protected async _resolveEventProvider(
|
|
339
|
-
init: ConfigBuilderCallbackArgs,
|
|
340
|
-
): Promise<BookmarkModuleConfig['eventProvider'] | undefined> {
|
|
341
|
-
// Check if event module is available
|
|
342
|
-
if (init.hasModule('event')) {
|
|
343
|
-
this.#log?.debug('Event module available, awaiting instance');
|
|
344
|
-
return init.requireInstance('event');
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* @internal Create a default client for the bookmark module.
|
|
350
|
-
* @param init - The configuration initialization object.
|
|
351
|
-
* @returns A promise that resolves to the default client.
|
|
352
|
-
*/
|
|
353
|
-
protected async _createDefaultClient(
|
|
354
|
-
init: ConfigBuilderCallbackArgs,
|
|
355
|
-
): Promise<BookmarkModuleConfig['client'] | undefined> {
|
|
356
|
-
try {
|
|
357
|
-
const apiProvider = await this._getServiceProvider(init);
|
|
358
|
-
const api = await apiProvider.createBookmarksClient('json$');
|
|
359
|
-
return new BookmarkClient(api);
|
|
360
|
-
} catch (_err) {
|
|
361
|
-
this.#log?.warn('Failed to create bookmark api client');
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* @internal retrieves the service provider from the configuration initialization object.
|
|
367
|
-
* @param init - The configuration initialization object.
|
|
368
|
-
* @returns A promise that resolves to the service provider.
|
|
369
|
-
* @throws {Error} When no services module or parent service module is available.
|
|
370
|
-
*/
|
|
371
|
-
protected async _getServiceProvider(init: ConfigBuilderCallbackArgs): Promise<IApiProvider> {
|
|
372
|
-
// check if services module is available
|
|
373
|
-
if (init.hasModule('services')) {
|
|
374
|
-
this.#log?.debug('Services module available, awaiting instance');
|
|
375
|
-
return init.requireInstance('services');
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
this.#log?.debug('No services module available, will use ref services module if available');
|
|
379
|
-
|
|
380
|
-
// check if parent has services module
|
|
381
|
-
const parentServiceModule = (init.ref as ModulesInstanceType<[ServicesModule]>)?.services;
|
|
382
|
-
// reuse the parent's service module if one is available
|
|
383
|
-
if (parentServiceModule) {
|
|
384
|
-
return parentServiceModule;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// No service provider available
|
|
388
|
-
this.#log?.error('No service provider available, cannot create bookmarks client');
|
|
389
|
-
throw Error('[BookmarkConfigurator] No service provider configures [ServicesModule] ');
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* @internal Validates and normalizes the resolved config before it's returned from `build`.
|
|
394
|
-
* @param config - The partially-resolved bookmark module config.
|
|
395
|
-
* @param _init - The configuration initialization object (unused).
|
|
396
|
-
* @returns The validated {@link BookmarkModuleConfig}.
|
|
397
|
-
* @throws {ZodError} When the config fails schema validation.
|
|
398
|
-
*/
|
|
399
|
-
protected async _processConfig(
|
|
400
|
-
config: Partial<BookmarkModuleConfig>,
|
|
401
|
-
_init: ConfigBuilderCallbackArgs,
|
|
402
|
-
): Promise<BookmarkModuleConfig> {
|
|
403
|
-
try {
|
|
404
|
-
return parseBookmarkConfig(config);
|
|
405
|
-
} catch (err) {
|
|
406
|
-
this.#log?.error('Failed to parse config', config, (err as ZodError).issues ?? err);
|
|
407
|
-
throw err;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
export default BookmarkModuleConfigurator;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { FrameworkEventInit, IFrameworkEvent } from '@equinor/fusion-framework-module-event';
|
|
2
|
-
import type { Bookmark } from './types';
|
|
3
|
-
import type { BookmarkPayloadGenerator, IBookmarkProvider } from './BookmarkProvider.interface';
|
|
4
|
-
import type { BookmarkNew, BookmarkUpdate } from './BookmarkClient.interface';
|
|
5
|
-
|
|
6
|
-
export interface BookmarkProviderEventMap {
|
|
7
|
-
/**
|
|
8
|
-
* An event that is emitted before current bookmark is changed.
|
|
9
|
-
*/
|
|
10
|
-
onCurrentBookmarkChange: IFrameworkEvent<
|
|
11
|
-
FrameworkEventInit<{ current?: Bookmark | null; next: Bookmark | null }, IBookmarkProvider>
|
|
12
|
-
>;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* An event that is emitted when the current bookmark has changed.
|
|
16
|
-
*/
|
|
17
|
-
onCurrentBookmarkChanged: IFrameworkEvent<
|
|
18
|
-
FrameworkEventInit<Bookmark | null | undefined, IBookmarkProvider>
|
|
19
|
-
>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* An event that is emitted before a bookmark is created.
|
|
23
|
-
*/
|
|
24
|
-
onBookmarkCreate: IFrameworkEvent<FrameworkEventInit<BookmarkNew, IBookmarkProvider>>;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* An event that is emitted when a bookmark has been created.
|
|
28
|
-
*/
|
|
29
|
-
onBookmarkCreated: IFrameworkEvent<FrameworkEventInit<Bookmark, IBookmarkProvider>>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* An event that is emitted before a bookmark is updated.
|
|
33
|
-
*/
|
|
34
|
-
onBookmarkUpdate: IFrameworkEvent<
|
|
35
|
-
FrameworkEventInit<{ current?: Bookmark; updates: BookmarkUpdate }, IBookmarkProvider>
|
|
36
|
-
>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* An event that is emitted before a bookmark is updated.
|
|
40
|
-
*/
|
|
41
|
-
onBookmarkUpdated: IFrameworkEvent<FrameworkEventInit<Bookmark, IBookmarkProvider>>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* An event that is emitted before a bookmark is removed.
|
|
45
|
-
*/
|
|
46
|
-
onBookmarkDelete: IFrameworkEvent<FrameworkEventInit<{ id: string }, IBookmarkProvider>>;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* An event that is emitted before a bookmark is removed.
|
|
50
|
-
*/
|
|
51
|
-
onBookmarkDeleted: IFrameworkEvent<FrameworkEventInit<{ id: string }, IBookmarkProvider>>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* An event that is emitted before a bookmark is added to the user's favorites.
|
|
55
|
-
*/
|
|
56
|
-
onBookmarkFavouriteRemove: IFrameworkEvent<FrameworkEventInit<{ id: string }, IBookmarkProvider>>;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* An event that is emitted when a bookmark is removed from the user's favorites.
|
|
60
|
-
*/
|
|
61
|
-
onBookmarkFavouriteRemoved: IFrameworkEvent<
|
|
62
|
-
FrameworkEventInit<{ id: string }, IBookmarkProvider>
|
|
63
|
-
>;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* An event that is emitted before a bookmark is added to the user's favorites.
|
|
67
|
-
*/
|
|
68
|
-
onBookmarkFavouriteAdd: IFrameworkEvent<FrameworkEventInit<{ id: string }, IBookmarkProvider>>;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* An event that is emitted when a bookmark is added to the user's favorites.
|
|
72
|
-
*/
|
|
73
|
-
onBookmarkFavouriteAdded: IFrameworkEvent<
|
|
74
|
-
FrameworkEventInit<Bookmark | undefined, IBookmarkProvider>
|
|
75
|
-
>;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* An event that is emitted when a new bookmark payload generator is added.
|
|
79
|
-
*/
|
|
80
|
-
onBookmarkPayloadCreatorAdded: IFrameworkEvent<
|
|
81
|
-
FrameworkEventInit<BookmarkPayloadGenerator, IBookmarkProvider>
|
|
82
|
-
>;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
declare module '@equinor/fusion-framework-module-event' {
|
|
86
|
-
interface FrameworkEventMap extends BookmarkProviderEventMap {}
|
|
87
|
-
}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: `BookmarkData = any` generic defaults must remain bivariant — `unknown` breaks assignability of concrete `Bookmark<T>`/`BookmarkPayloadGenerator<TData>` instances to the default-typed generic
|
|
2
|
-
import type { Observable, ObservableInput } from 'rxjs';
|
|
3
|
-
import type { Bookmark, BookmarkData, BookmarkWithoutData } from './types';
|
|
4
|
-
import type { BookmarkNew, BookmarkUpdate } from './BookmarkClient.interface';
|
|
5
|
-
import type { BookmarkProviderEventMap } from './BookmarkProvider.events';
|
|
6
|
-
import type { BookmarkState } from './create-bookmark-store';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Arguments for creating a bookmark via {@link IBookmarkProvider.createBookmark}.
|
|
10
|
-
*
|
|
11
|
-
* Omits fields that the provider resolves automatically (`appKey`, `contextId`, `sourceSystem`),
|
|
12
|
-
* but allows the caller to override `appKey` if needed.
|
|
13
|
-
*
|
|
14
|
-
* @template T - The type of payload data stored in the bookmark.
|
|
15
|
-
*/
|
|
16
|
-
export type BookmarkCreateArgs<T extends BookmarkData = any> = Omit<
|
|
17
|
-
BookmarkNew<T>,
|
|
18
|
-
'appKey' | 'contextId' | 'sourceSystem'
|
|
19
|
-
> &
|
|
20
|
-
Partial<Pick<BookmarkNew<T>, 'appKey'>>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Options that control how {@link IBookmarkProvider.updateBookmark} processes an update.
|
|
24
|
-
*
|
|
25
|
-
* @property excludePayloadGeneration - When `true`, skip running registered payload generators
|
|
26
|
-
* and send the update payload as-is. Useful when the caller has already computed the full payload.
|
|
27
|
-
*/
|
|
28
|
-
export type BookmarkUpdateOptions = {
|
|
29
|
-
excludePayloadGeneration?: boolean;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Callback registered with {@link IBookmarkProvider.addPayloadGenerator} that participates
|
|
34
|
-
* in building or transforming bookmark payload data during create and update operations.
|
|
35
|
-
*
|
|
36
|
-
* The `payload` argument is an Immer draft — mutate it in place rather than returning a new
|
|
37
|
-
* object. If the generator returns a value it will be used, but this is discouraged.
|
|
38
|
-
* Return `null` to signal that the bookmark payload should be cleared.
|
|
39
|
-
*
|
|
40
|
-
* @template TData - Shape of the bookmark payload.
|
|
41
|
-
* @param payload - The accumulated payload draft from previous generators (mutable).
|
|
42
|
-
* @param initial - The original payload before any generators ran (read-only reference).
|
|
43
|
-
* @returns A partial payload, `void` (when mutating the draft), or `null` to clear.
|
|
44
|
-
*/
|
|
45
|
-
export type BookmarkPayloadGenerator<TData extends BookmarkData = any> = (
|
|
46
|
-
payload?: Partial<TData> | null,
|
|
47
|
-
initial?: Partial<TData> | null,
|
|
48
|
-
// biome-ignore lint/suspicious/noConfusingVoidType: `void` here relies on TypeScript's special-cased "void-returning callback accepts any return value" behavior for draft-mutating generators — `undefined` would break assignability of generators that only conditionally return a partial payload
|
|
49
|
-
) => Promise<Partial<TData> | void> | Partial<TData> | void;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Interface representing a Bookmark Provider.
|
|
53
|
-
*/
|
|
54
|
-
export interface IBookmarkProvider {
|
|
55
|
-
readonly currentBookmark: Bookmark | null | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* Observable of the current bookmark.
|
|
58
|
-
*
|
|
59
|
-
* @type {ObservableInput<Bookmark | null | undefined>}
|
|
60
|
-
*/
|
|
61
|
-
readonly currentBookmark$: Observable<Bookmark | null | undefined>;
|
|
62
|
-
|
|
63
|
-
readonly bookmarks$: Observable<BookmarkWithoutData[]>;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Observable status of the bookmark provider.
|
|
67
|
-
*/
|
|
68
|
-
readonly status$: Observable<BookmarkState['status']>;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Indicates whether the user can create bookmarks.
|
|
72
|
-
* If no payload generator is provided, this will always be false.
|
|
73
|
-
*
|
|
74
|
-
* @type {boolean}
|
|
75
|
-
*/
|
|
76
|
-
readonly canCreateBookmarks: boolean;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* fetch a bookmark by its ID.
|
|
80
|
-
*
|
|
81
|
-
* @param {string} bookmarkId - The ID of the bookmark to fetch.
|
|
82
|
-
* @returns {ObservableInput<Bookmark>} An observable input of the bookmark.
|
|
83
|
-
*/
|
|
84
|
-
getBookmark(bookmarkId: string): ObservableInput<Bookmark>;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Fetches all bookmarks.
|
|
88
|
-
*
|
|
89
|
-
* @returns {ObservableInput<Bookmark[]>} An observable input of the bookmarks.
|
|
90
|
-
*/
|
|
91
|
-
getAllBookmarks(): ObservableInput<Bookmark[]>;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Sets the current bookmark.
|
|
95
|
-
*
|
|
96
|
-
* @param {Bookmark | string | null} bookmark_or_id - The bookmark or its ID to set as current.
|
|
97
|
-
* @returns {ObservableInput<Bookmark | null>} An observable input of the current bookmark.
|
|
98
|
-
*/
|
|
99
|
-
setCurrentBookmark(bookmark_or_id: Bookmark | string | null): ObservableInput<Bookmark | null>;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Creates a new bookmark.
|
|
103
|
-
*
|
|
104
|
-
* @param {BookmarkCreateArgs} newBookmarkData - The data for the new bookmark.
|
|
105
|
-
* @returns {ObservableInput<Bookmark>} An observable input of the created bookmark.
|
|
106
|
-
*/
|
|
107
|
-
createBookmark(newBookmarkData: BookmarkCreateArgs): ObservableInput<Bookmark>;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Updates an existing bookmark.
|
|
111
|
-
*
|
|
112
|
-
* @param {string} bookmarkId - The ID of the bookmark to update.
|
|
113
|
-
* @param {BookmarkUpdate} [bookmarkUpdates] - The updates to apply to the bookmark.
|
|
114
|
-
* @param {BookmarkUpdateOptions} [options] - Additional options for the update.
|
|
115
|
-
* @returns {ObservableInput<Bookmark>} An observable input of the updated bookmark.
|
|
116
|
-
*/
|
|
117
|
-
updateBookmark(
|
|
118
|
-
bookmarkId: string,
|
|
119
|
-
bookmarkUpdates?: BookmarkUpdate,
|
|
120
|
-
options?: BookmarkUpdateOptions,
|
|
121
|
-
): ObservableInput<Bookmark>;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Deletes a bookmark.
|
|
125
|
-
*
|
|
126
|
-
* @param {string} bookmarkId - The ID of the bookmark to delete.
|
|
127
|
-
* @returns {ObservableInput<void>} An observable input indicating the deletion.
|
|
128
|
-
*/
|
|
129
|
-
deleteBookmark(bookmarkId: string): ObservableInput<void>;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Adds a bookmark to the favorites.
|
|
133
|
-
*
|
|
134
|
-
* @param {string} bookmarkId - The ID of the bookmark to add to favorites.
|
|
135
|
-
* @returns {ObservableInput<void>} An observable input indicating the addition.
|
|
136
|
-
*/
|
|
137
|
-
addBookmarkToFavorites(bookmarkId: string): ObservableInput<BookmarkWithoutData | undefined>;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Removes a bookmark from the favorites.
|
|
141
|
-
*
|
|
142
|
-
* @param {string} bookmarkId - The ID of the bookmark to remove from favorites.
|
|
143
|
-
* @returns {ObservableInput<void>} An observable input indicating the removal.
|
|
144
|
-
*/
|
|
145
|
-
removeBookmarkAsFavorite(bookmarkId: string): ObservableInput<void>;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Checks if a bookmark is in the favorites.
|
|
149
|
-
*
|
|
150
|
-
* @param bookmarkId
|
|
151
|
-
* @returns {ObservableInput<boolean>} An observable input indicating whether the bookmark is in the favorites.
|
|
152
|
-
*/
|
|
153
|
-
isBookmarkInFavorites(bookmarkId: string): ObservableInput<boolean>;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Registers a payload generator that runs during bookmark create and update operations.
|
|
157
|
-
*
|
|
158
|
-
* Multiple generators can be registered and they execute sequentially, each receiving
|
|
159
|
-
* the accumulated payload from previous generators.
|
|
160
|
-
*
|
|
161
|
-
* @template TData - Shape of the bookmark payload.
|
|
162
|
-
* @param generator - The generator callback to register.
|
|
163
|
-
* @returns A disposal function that unregisters the generator when called.
|
|
164
|
-
*/
|
|
165
|
-
addPayloadGenerator<TData extends BookmarkData>(
|
|
166
|
-
generator: BookmarkPayloadGenerator<TData>,
|
|
167
|
-
): VoidFunction;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Registers an event listener for bookmark provider events.
|
|
171
|
-
*
|
|
172
|
-
* @param {TType} eventName - The name of the event to listen for.
|
|
173
|
-
* @param {(event: BookmarkProviderEventMap[TType]) => void} callback - The callback to invoke when the event is triggered.
|
|
174
|
-
* @returns {VoidFunction} A function to unregister the event listener.
|
|
175
|
-
*/
|
|
176
|
-
on<TType extends keyof BookmarkProviderEventMap>(
|
|
177
|
-
eventName: TType,
|
|
178
|
-
callback: (event: BookmarkProviderEventMap[TType]) => void,
|
|
179
|
-
): VoidFunction;
|
|
180
|
-
}
|