@equinor/fusion-framework-module-bookmark 2.1.4 → 2.1.6
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 +19 -0
- package/dist/esm/BookmarkClient.js +46 -66
- package/dist/esm/BookmarkClient.js.map +1 -1
- package/dist/esm/BookmarkConfigurator.js +96 -142
- package/dist/esm/BookmarkConfigurator.js.map +1 -1
- package/dist/esm/BookmarkProvider.actions.js +7 -7
- package/dist/esm/BookmarkProvider.actions.js.map +1 -1
- package/dist/esm/BookmarkProvider.error.js +1 -0
- package/dist/esm/BookmarkProvider.error.js.map +1 -1
- package/dist/esm/BookmarkProvider.js +160 -230
- package/dist/esm/BookmarkProvider.js.map +1 -1
- package/dist/esm/BookmarkProvider.reducer.js +6 -20
- package/dist/esm/BookmarkProvider.reducer.js.map +1 -1
- package/dist/esm/bookmark-module.js +8 -19
- package/dist/esm/bookmark-module.js.map +1 -1
- package/dist/esm/enable-bookmark.js +2 -11
- package/dist/esm/enable-bookmark.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/BookmarkProvider.d.ts +5 -5
- package/dist/types/bookmark.schemas.d.ts +11 -11
- package/dist/types/version.d.ts +1 -1
- package/package.json +11 -18
- package/src/version.ts +1 -1
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
16
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
17
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
18
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
19
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
20
|
-
};
|
|
21
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
22
|
-
var t = {};
|
|
23
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
24
|
-
t[p] = s[p];
|
|
25
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
26
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
27
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
28
|
-
t[p[i]] = s[p[i]];
|
|
29
|
-
}
|
|
30
|
-
return t;
|
|
31
|
-
};
|
|
32
|
-
var _BookmarkProvider_config, _BookmarkProvider_store, _BookmarkProvider_payloadGenerators, _BookmarkProvider_subscriptions;
|
|
33
1
|
import { Observable, Subscription, forkJoin, from, lastValueFrom, of } from 'rxjs';
|
|
34
2
|
import { filter, switchMap, tap, map, mergeScan, timeout, raceWith, first, catchError, } from 'rxjs/operators';
|
|
35
3
|
import { produce, castDraft } from 'immer';
|
|
@@ -53,6 +21,14 @@ const defaultTimeout = 2 * 60 * 1000; // 2 minutes
|
|
|
53
21
|
* The `BookmarkProvider` also supports event listeners for various bookmark-related events, such as when the current bookmark changes or when a bookmark is created, updated, or removed.
|
|
54
22
|
*/
|
|
55
23
|
export class BookmarkProvider {
|
|
24
|
+
/** provided configuration for the bookmark provider */
|
|
25
|
+
#config;
|
|
26
|
+
/** state machine of the bookmark provider */
|
|
27
|
+
#store;
|
|
28
|
+
/** collection of callback for creating bookmark payload */
|
|
29
|
+
#payloadGenerators = [];
|
|
30
|
+
/** collection of subscriptions for bookmark events */
|
|
31
|
+
#subscriptions = new Subscription();
|
|
56
32
|
/**
|
|
57
33
|
* @deprecated
|
|
58
34
|
* this will be removed as soon as applications have been migrated to use the bookmark provider
|
|
@@ -114,104 +90,104 @@ export class BookmarkProvider {
|
|
|
114
90
|
}
|
|
115
91
|
get filters() {
|
|
116
92
|
// TODO - freeze the config object?
|
|
117
|
-
return
|
|
93
|
+
return this.#config.filters;
|
|
118
94
|
}
|
|
119
95
|
/**
|
|
120
96
|
* Gets the `IBookmarkClient` instance used by this `BookmarkProvider`.
|
|
121
97
|
*/
|
|
122
98
|
get client() {
|
|
123
|
-
return
|
|
99
|
+
return this.#config.client;
|
|
124
100
|
}
|
|
125
101
|
/**
|
|
126
102
|
* Gets the currently active bookmark (if any).
|
|
127
103
|
*/
|
|
128
104
|
get currentBookmark$() {
|
|
129
|
-
return
|
|
105
|
+
return this.#store.select(activeBookmarkSelector, deepEqual);
|
|
130
106
|
}
|
|
131
107
|
/**
|
|
132
108
|
* Gets an observable that emits the current list of bookmarks.
|
|
133
109
|
*/
|
|
134
110
|
get bookmarks$() {
|
|
135
111
|
this.getAllBookmarksAsync();
|
|
136
|
-
return
|
|
112
|
+
return this.#store.select(bookmarksSelector, deepEqual);
|
|
137
113
|
}
|
|
138
114
|
/**
|
|
139
115
|
* Gets the current list of bookmarks.
|
|
140
116
|
*/
|
|
141
117
|
get bookmarks() {
|
|
142
|
-
return bookmarksSelector(
|
|
118
|
+
return bookmarksSelector(this.#store.value);
|
|
143
119
|
}
|
|
144
120
|
/**
|
|
145
121
|
* Gets the currently active bookmark.
|
|
146
122
|
*/
|
|
147
123
|
get currentBookmark() {
|
|
148
|
-
const bookmark = activeBookmarkSelector(
|
|
124
|
+
const bookmark = activeBookmarkSelector(this.#store.value);
|
|
149
125
|
return bookmark;
|
|
150
126
|
}
|
|
151
127
|
/**
|
|
152
128
|
* Represents an observable stream of the bookmark status.
|
|
153
129
|
*/
|
|
154
130
|
get status$() {
|
|
155
|
-
return
|
|
131
|
+
return this.#store.select((x) => x.status);
|
|
156
132
|
}
|
|
157
133
|
/**
|
|
158
134
|
* Gets an observable that emits the current list of bookmark errors.
|
|
159
135
|
*/
|
|
160
136
|
get errors$() {
|
|
161
137
|
// TODO - add deep diff
|
|
162
|
-
return
|
|
138
|
+
return this.#store.select(errorsSelector, deepEqual);
|
|
163
139
|
}
|
|
164
140
|
/**
|
|
165
141
|
* Determines whether there are any bookmark creators configured.
|
|
166
142
|
* `true` if there are any bookmark creators configured, `false` otherwise.
|
|
167
143
|
*/
|
|
168
144
|
get canCreateBookmarks() {
|
|
169
|
-
return
|
|
145
|
+
return this.#payloadGenerators.length > 0;
|
|
170
146
|
}
|
|
171
147
|
/**
|
|
172
148
|
* Gets the source system value from the configuration.
|
|
173
149
|
*/
|
|
174
150
|
get sourceSystem() {
|
|
175
|
-
return
|
|
151
|
+
return this.#config.sourceSystem;
|
|
176
152
|
}
|
|
177
153
|
/**
|
|
178
154
|
* Gets the resolved application from the bookmark module configuration.
|
|
179
155
|
*/
|
|
180
156
|
get resolvedApplication() {
|
|
181
|
-
return
|
|
157
|
+
return this.#config.resolve.application;
|
|
182
158
|
}
|
|
183
159
|
/**
|
|
184
160
|
* Gets the resolved context from the bookmark module configuration.
|
|
185
161
|
*/
|
|
186
162
|
get resolvedContext() {
|
|
187
|
-
return
|
|
163
|
+
return this.#config.resolve.context;
|
|
188
164
|
}
|
|
189
165
|
get _apiClient() {
|
|
190
|
-
return
|
|
166
|
+
return this.#config.client;
|
|
191
167
|
}
|
|
192
168
|
/**
|
|
193
169
|
* configured logger instance.
|
|
194
170
|
*/
|
|
195
171
|
get _log() {
|
|
196
|
-
return
|
|
172
|
+
return this.#config.log;
|
|
197
173
|
}
|
|
198
174
|
/**
|
|
199
175
|
* configured resolvers
|
|
200
176
|
*/
|
|
201
177
|
get _resolve() {
|
|
202
|
-
return
|
|
178
|
+
return this.#config.resolve;
|
|
203
179
|
}
|
|
204
180
|
/**
|
|
205
181
|
* configured event provider.
|
|
206
182
|
*/
|
|
207
183
|
get _event() {
|
|
208
|
-
return
|
|
184
|
+
return this.#config.eventProvider;
|
|
209
185
|
}
|
|
210
186
|
/**
|
|
211
187
|
* configured parent bookmark provider
|
|
212
188
|
*/
|
|
213
189
|
get _parent() {
|
|
214
|
-
return
|
|
190
|
+
return this.#config.parent;
|
|
215
191
|
}
|
|
216
192
|
/**
|
|
217
193
|
* Constructs a new `BookmarkProvider` instance.
|
|
@@ -219,34 +195,24 @@ export class BookmarkProvider {
|
|
|
219
195
|
* @param config - The configuration for the bookmark module, including the client, initial state, and optional parent provider.
|
|
220
196
|
*/
|
|
221
197
|
constructor(config) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
_BookmarkProvider_config.set(this, void 0);
|
|
225
|
-
/** state machine of the bookmark provider */
|
|
226
|
-
_BookmarkProvider_store.set(this, void 0);
|
|
227
|
-
/** collection of callback for creating bookmark payload */
|
|
228
|
-
_BookmarkProvider_payloadGenerators.set(this, []);
|
|
229
|
-
/** collection of subscriptions for bookmark events */
|
|
230
|
-
_BookmarkProvider_subscriptions.set(this, new Subscription());
|
|
231
|
-
__classPrivateFieldSet(this, _BookmarkProvider_config, config, "f");
|
|
232
|
-
__classPrivateFieldSet(this, _BookmarkProvider_store, createBookmarkStore({
|
|
198
|
+
this.#config = config;
|
|
199
|
+
this.#store = createBookmarkStore({
|
|
233
200
|
client: config.client,
|
|
234
|
-
initial: { currentBookmark:
|
|
235
|
-
})
|
|
201
|
+
initial: { currentBookmark: this._parent?.currentBookmark ?? null },
|
|
202
|
+
});
|
|
236
203
|
// add teardown logic for disposing the store
|
|
237
|
-
|
|
204
|
+
this.#subscriptions.add(() => this.#store.complete());
|
|
238
205
|
// subscribe to the store actions and log them
|
|
239
|
-
|
|
240
|
-
var _a, _b;
|
|
206
|
+
this.#subscriptions.add(this.#store.action$.subscribe((action) => {
|
|
241
207
|
if (isFailureAction(action)) {
|
|
242
|
-
|
|
208
|
+
this._log?.error(`Action: ${action.type}`, action);
|
|
243
209
|
}
|
|
244
210
|
else {
|
|
245
|
-
|
|
211
|
+
this._log?.debug(`Action: ${action.type}`, action);
|
|
246
212
|
}
|
|
247
213
|
}));
|
|
248
214
|
// subscribe to the current bookmark changes and dispatch events
|
|
249
|
-
|
|
215
|
+
this.#subscriptions.add(this.#store.select(activeBookmarkSelector).subscribe((bookmark) => {
|
|
250
216
|
// do not emit before the first value
|
|
251
217
|
if (bookmark !== undefined) {
|
|
252
218
|
this._dispatchEvent('onCurrentBookmarkChanged', { detail: bookmark });
|
|
@@ -262,21 +228,21 @@ export class BookmarkProvider {
|
|
|
262
228
|
return;
|
|
263
229
|
// only update the current bookmark if the event source is not this provider
|
|
264
230
|
if (source !== this && detail !== this.currentBookmark) {
|
|
265
|
-
|
|
231
|
+
this.#store.next(bookmarkActions.setCurrentBookmark(detail));
|
|
266
232
|
}
|
|
267
233
|
});
|
|
268
234
|
}
|
|
269
235
|
if (this._parent) {
|
|
270
236
|
// if a parent bookmark provider is configured, subscribe to its current bookmark changes
|
|
271
237
|
try {
|
|
272
|
-
|
|
238
|
+
this.#subscriptions.add(this._parent.currentBookmark$
|
|
273
239
|
.pipe(filter((x) => x !== undefined), filter((x) => x !== this.currentBookmark))
|
|
274
240
|
.subscribe((bookmark) => {
|
|
275
|
-
|
|
241
|
+
this.#store.next(bookmarkActions.setCurrentBookmark(bookmark));
|
|
276
242
|
}));
|
|
277
243
|
}
|
|
278
244
|
catch (e) {
|
|
279
|
-
|
|
245
|
+
this._log?.error('Failed to subscribe to parent bookmark provider', e);
|
|
280
246
|
}
|
|
281
247
|
}
|
|
282
248
|
}
|
|
@@ -289,12 +255,11 @@ export class BookmarkProvider {
|
|
|
289
255
|
* @returns A function that can be called to remove the event listener.
|
|
290
256
|
*/
|
|
291
257
|
on(eventName, callback) {
|
|
292
|
-
var _a, _b;
|
|
293
258
|
if (!this._event) {
|
|
294
|
-
|
|
259
|
+
this._log?.warn('Failed to register event listener, event provider not configured');
|
|
295
260
|
return () => { };
|
|
296
261
|
}
|
|
297
|
-
return
|
|
262
|
+
return this._event?.addEventListener(eventName, (event) => {
|
|
298
263
|
if (event.source === this) {
|
|
299
264
|
callback(event);
|
|
300
265
|
}
|
|
@@ -308,19 +273,17 @@ export class BookmarkProvider {
|
|
|
308
273
|
* @returns A function that can be called to remove the added payload generator.
|
|
309
274
|
*/
|
|
310
275
|
addPayloadGenerator(fn) {
|
|
311
|
-
|
|
312
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.debug(`adding bookmark payload generator: ${fn.name}`);
|
|
276
|
+
this._log?.debug(`adding bookmark payload generator: ${fn.name}`);
|
|
313
277
|
// register the payload generator function
|
|
314
|
-
|
|
278
|
+
this.#payloadGenerators.push(fn);
|
|
315
279
|
// dispatch event to notify listeners of the added payload generator
|
|
316
280
|
this._dispatchEvent('onBookmarkPayloadCreatorAdded', {
|
|
317
281
|
detail: fn,
|
|
318
282
|
});
|
|
319
283
|
// return a function to remove the added payload generator
|
|
320
284
|
return () => {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
__classPrivateFieldSet(this, _BookmarkProvider_payloadGenerators, __classPrivateFieldGet(this, _BookmarkProvider_payloadGenerators, "f").filter((g) => g !== fn), "f");
|
|
285
|
+
this._log?.debug(`removing bookmark payload generator: ${fn.name}`);
|
|
286
|
+
this.#payloadGenerators = this.#payloadGenerators.filter((g) => g !== fn);
|
|
324
287
|
};
|
|
325
288
|
}
|
|
326
289
|
/**
|
|
@@ -331,12 +294,11 @@ export class BookmarkProvider {
|
|
|
331
294
|
* @template T - The type of the generated payload.
|
|
332
295
|
*/
|
|
333
296
|
generatePayload(initial) {
|
|
334
|
-
|
|
335
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.debug(`generating payload`, initial);
|
|
297
|
+
this._log?.debug(`generating payload`, initial);
|
|
336
298
|
/**
|
|
337
299
|
* Observable that emits the generated payload.
|
|
338
300
|
*/
|
|
339
|
-
const result$ = from(
|
|
301
|
+
const result$ = from(this.#payloadGenerators).pipe(mergeScan((acc, generator) => this._producePayload(acc, generator), initial ?? {}, 1), tap((payload) => this._log?.debug(`generated payload`, { initial, payload })));
|
|
340
302
|
return result$;
|
|
341
303
|
}
|
|
342
304
|
/**
|
|
@@ -355,26 +317,25 @@ export class BookmarkProvider {
|
|
|
355
317
|
*/
|
|
356
318
|
_producePayload(value, generator, initial) {
|
|
357
319
|
// produce payload from generator
|
|
358
|
-
return produce(value, (draft) =>
|
|
359
|
-
var _a, _b, _c;
|
|
320
|
+
return produce(value, async (draft) => {
|
|
360
321
|
try {
|
|
361
|
-
const result =
|
|
322
|
+
const result = await Promise.resolve(generator(draft, initial));
|
|
362
323
|
// cast the result to a draft object
|
|
363
324
|
if (result) {
|
|
364
|
-
|
|
325
|
+
this._log?.warn(`bookmark data generator ${generator.name} returned a value, but it should not do this, since the data is an immer draft object`);
|
|
365
326
|
// Dirty fix since some developers are returning the reference object, which will freeze the object
|
|
366
327
|
return castDraft(JSON.parse(JSON.stringify(result)));
|
|
367
328
|
}
|
|
368
329
|
// clear the bookmark data if the generator returns null
|
|
369
330
|
if (result === null) {
|
|
370
|
-
|
|
331
|
+
this._log?.info(`bookmark data generator ${generator.name} wish to clear the bookmark data`);
|
|
371
332
|
return undefined;
|
|
372
333
|
}
|
|
373
334
|
}
|
|
374
335
|
catch (error) {
|
|
375
|
-
|
|
336
|
+
this._log?.error(`Failed to produce payload using generator ${generator.name}`, error);
|
|
376
337
|
}
|
|
377
|
-
})
|
|
338
|
+
});
|
|
378
339
|
}
|
|
379
340
|
/**
|
|
380
341
|
* Retrieves a bookmark with the specified bookmarkId and returns an observable that emits the combined result of fetching the bookmark and bookmark data.
|
|
@@ -384,21 +345,18 @@ export class BookmarkProvider {
|
|
|
384
345
|
* @returns An observable that emits the combined result of fetching the bookmark and bookmark data.
|
|
385
346
|
*/
|
|
386
347
|
getBookmark(bookmarkId, options) {
|
|
387
|
-
|
|
388
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.debug(`fetching bookmark: ${bookmarkId}`, options);
|
|
348
|
+
this._log?.debug(`fetching bookmark: ${bookmarkId}`, options);
|
|
389
349
|
// fetch the bookmark and bookmark data
|
|
390
350
|
return forkJoin({
|
|
391
351
|
bookmark: this._getBookmarkInfo(bookmarkId),
|
|
392
|
-
payload:
|
|
352
|
+
payload: options?.excludePayload ? of({}) : this._getBookmarkData(bookmarkId),
|
|
393
353
|
}).pipe(catchError((error) => {
|
|
394
|
-
|
|
395
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.error(`Failed to fetch bookmark: ${bookmarkId}`, error);
|
|
354
|
+
this._log?.error(`Failed to fetch bookmark: ${bookmarkId}`, error);
|
|
396
355
|
throw error;
|
|
397
356
|
}),
|
|
398
357
|
// combine the bookmark and payload into a single object
|
|
399
358
|
map(({ bookmark, payload }) => Object.assign({}, bookmark, { payload })), tap((bookmark) => {
|
|
400
|
-
|
|
401
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.debug(`Bookmark fetched: ${bookmark.id}`, bookmark);
|
|
359
|
+
this._log?.debug(`Bookmark fetched: ${bookmark.id}`, bookmark);
|
|
402
360
|
}));
|
|
403
361
|
}
|
|
404
362
|
/**
|
|
@@ -419,31 +377,28 @@ export class BookmarkProvider {
|
|
|
419
377
|
*/
|
|
420
378
|
getAllBookmarks() {
|
|
421
379
|
return new Observable((observer) => {
|
|
422
|
-
|
|
423
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.debug(`fetching all bookmarks`);
|
|
380
|
+
this._log?.debug(`fetching all bookmarks`);
|
|
424
381
|
// generate the filter parameters
|
|
425
382
|
const filter$ = forkJoin({
|
|
426
383
|
sourceSystem: of(this.sourceSystem),
|
|
427
|
-
appKey:
|
|
428
|
-
? from(this._resolve.application()).pipe(map((x) => x
|
|
384
|
+
appKey: this.#config.filters?.application
|
|
385
|
+
? from(this._resolve.application()).pipe(map((x) => x?.appKey))
|
|
429
386
|
: of(undefined),
|
|
430
|
-
contextId:
|
|
431
|
-
? from(this._resolve.context()).pipe(map((x) => x
|
|
387
|
+
contextId: this.#config.filters?.context
|
|
388
|
+
? from(this._resolve.context()).pipe(map((x) => x?.id))
|
|
432
389
|
: of(undefined),
|
|
433
390
|
}).pipe(catchError((err) => {
|
|
434
|
-
var _a;
|
|
435
391
|
const error = new BookmarkProviderError('Could not fetch bookmarks, failed to resolve filter parameters', err);
|
|
436
|
-
|
|
392
|
+
this._log?.error(error.message, error);
|
|
437
393
|
throw error;
|
|
438
394
|
}));
|
|
439
395
|
// execute the fetch bookmarks action when the filter parameters are resolved
|
|
440
396
|
observer.add(filter$.subscribe((filter) => {
|
|
441
|
-
|
|
397
|
+
this.#store.next(bookmarkActions.fetchBookmarks(filter));
|
|
442
398
|
}));
|
|
443
399
|
// monitor the failure case when fetching bookmarks
|
|
444
|
-
const failure$ =
|
|
445
|
-
|
|
446
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.error('Failed to fetch bookmarks', action.payload);
|
|
400
|
+
const failure$ = this.#store.action$.pipe(filter(bookmarkActions.fetchBookmarks.failure.match), map((action) => {
|
|
401
|
+
this._log?.error('Failed to fetch bookmarks', action.payload);
|
|
447
402
|
throw new BookmarkProviderError('Failed to fetch bookmarks', action.payload);
|
|
448
403
|
}), timeout({
|
|
449
404
|
each: defaultTimeout,
|
|
@@ -452,9 +407,8 @@ export class BookmarkProvider {
|
|
|
452
407
|
},
|
|
453
408
|
}));
|
|
454
409
|
// monitor the success case when fetching bookmarks
|
|
455
|
-
const request$ =
|
|
456
|
-
|
|
457
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.debug(`fetched all bookmarks`, bookmarks);
|
|
410
|
+
const request$ = this.#store.action$.pipe(filter(bookmarkActions.fetchBookmarks.success.match), map((a) => a.payload), tap((bookmarks) => {
|
|
411
|
+
this._log?.debug(`fetched all bookmarks`, bookmarks);
|
|
458
412
|
}), raceWith(failure$), first());
|
|
459
413
|
request$.subscribe(observer);
|
|
460
414
|
});
|
|
@@ -464,10 +418,8 @@ export class BookmarkProvider {
|
|
|
464
418
|
*
|
|
465
419
|
* @returns A Promise that resolves to the Bookmarks object containing all bookmarks.
|
|
466
420
|
*/
|
|
467
|
-
getAllBookmarksAsync() {
|
|
468
|
-
return
|
|
469
|
-
return lastValueFrom(this.getAllBookmarks());
|
|
470
|
-
});
|
|
421
|
+
async getAllBookmarksAsync() {
|
|
422
|
+
return lastValueFrom(this.getAllBookmarks());
|
|
471
423
|
}
|
|
472
424
|
/**
|
|
473
425
|
* Sets the current bookmark to the specified bookmark or ID.
|
|
@@ -481,34 +433,31 @@ export class BookmarkProvider {
|
|
|
481
433
|
* @template T - The type of the bookmark data.
|
|
482
434
|
*/
|
|
483
435
|
setCurrentBookmark(bookmark_or_id) {
|
|
484
|
-
var _a;
|
|
485
436
|
// check if the bookmark is already the current bookmark
|
|
486
437
|
if (bookmark_or_id == this.currentBookmark)
|
|
487
438
|
return of(bookmark_or_id);
|
|
488
|
-
|
|
439
|
+
this._log?.debug(`setting current bookmark`, bookmark_or_id);
|
|
489
440
|
// resolve the next bookmark
|
|
490
441
|
const next$ = typeof bookmark_or_id === 'string'
|
|
491
442
|
? this.getBookmark(bookmark_or_id)
|
|
492
|
-
: of(bookmark_or_id
|
|
493
|
-
return next$.pipe(switchMap((next) =>
|
|
494
|
-
var _a, _b, _c;
|
|
443
|
+
: of(bookmark_or_id ?? null);
|
|
444
|
+
return next$.pipe(switchMap(async (next) => {
|
|
495
445
|
const current = this.currentBookmark;
|
|
496
|
-
const { type, canceled } =
|
|
446
|
+
const { type, canceled } = await this._dispatchEvent('onCurrentBookmarkChange', {
|
|
497
447
|
detail: { current, next },
|
|
498
448
|
});
|
|
499
449
|
if (canceled) {
|
|
500
|
-
const error = new BookmarkProviderError(`event: ${type} was canceled by listener for change to ${
|
|
501
|
-
|
|
450
|
+
const error = new BookmarkProviderError(`event: ${type} was canceled by listener for change to ${next?.id ?? 'none'}, from ${current?.id ?? 'none'}`);
|
|
451
|
+
this._log?.info(error.message);
|
|
502
452
|
throw error;
|
|
503
453
|
}
|
|
504
454
|
return next;
|
|
505
|
-
})
|
|
455
|
+
}), tap((next) => {
|
|
506
456
|
// set the current bookmark in the store
|
|
507
|
-
|
|
457
|
+
this.#store.next(bookmarkActions.setCurrentBookmark(next));
|
|
508
458
|
}), catchError((err) => {
|
|
509
|
-
var _a;
|
|
510
459
|
const error = new BookmarkProviderError('Could not set current bookmark, resolve of bookmark failed', err);
|
|
511
|
-
|
|
460
|
+
this._log?.error(error.message, error);
|
|
512
461
|
throw error;
|
|
513
462
|
}));
|
|
514
463
|
}
|
|
@@ -533,61 +482,60 @@ export class BookmarkProvider {
|
|
|
533
482
|
*/
|
|
534
483
|
createBookmark(newBookmarkData) {
|
|
535
484
|
return new Observable((subscriber) => {
|
|
536
|
-
var _a;
|
|
537
485
|
const { ref, action$ } = this._useScopedActions();
|
|
538
|
-
|
|
486
|
+
this._log?.debug(`creating new bookmark, ref: ${ref}`, newBookmarkData);
|
|
539
487
|
// resolve the bookmark
|
|
540
488
|
const bookmark$ = forkJoin({
|
|
541
489
|
appKey: newBookmarkData.appKey
|
|
542
490
|
? of(newBookmarkData.appKey)
|
|
543
491
|
: from(this._resolve.application()).pipe(map((app) => {
|
|
544
|
-
if (!
|
|
492
|
+
if (!app?.appKey) {
|
|
545
493
|
throw new BookmarkProviderError('Failed to resolve application key');
|
|
546
494
|
}
|
|
547
495
|
return app.appKey;
|
|
548
496
|
})),
|
|
549
|
-
contextId: this._resolve.context().then((context) => context
|
|
497
|
+
contextId: this._resolve.context().then((context) => context?.id),
|
|
550
498
|
payload: this.generatePayload(newBookmarkData.payload),
|
|
551
499
|
sourceSystem: of(this.sourceSystem),
|
|
552
500
|
}).pipe(catchError((err) => {
|
|
553
|
-
var _a;
|
|
554
501
|
const error = new BookmarkProviderError('Could not create new bookmark, failed to resolve bookmark data', err);
|
|
555
|
-
|
|
502
|
+
this._log?.error(error.message, error);
|
|
556
503
|
throw error;
|
|
557
504
|
}),
|
|
558
505
|
// merge the resolved data with the new bookmark data
|
|
559
|
-
map((resolvedData) => (
|
|
506
|
+
map((resolvedData) => ({
|
|
507
|
+
...newBookmarkData,
|
|
508
|
+
...resolvedData,
|
|
509
|
+
})));
|
|
560
510
|
// notify listeners that a bookmark is about to be created
|
|
561
|
-
const dispatch$ = bookmark$.pipe(switchMap((bookmark) =>
|
|
562
|
-
var _a;
|
|
511
|
+
const dispatch$ = bookmark$.pipe(switchMap(async (bookmark) => {
|
|
563
512
|
// notify listeners that a bookmark is about to be created
|
|
564
|
-
const { canceled, type } =
|
|
513
|
+
const { canceled, type } = await this._dispatchEvent('onBookmarkCreate', {
|
|
565
514
|
detail: bookmark,
|
|
566
515
|
cancelable: true,
|
|
567
516
|
});
|
|
568
517
|
// throw an error if the event is canceled
|
|
569
518
|
if (canceled) {
|
|
570
519
|
const error = new BookmarkProviderError(`event: ${type} was canceled by listener for creating bookmark: ${ref}`);
|
|
571
|
-
|
|
520
|
+
this._log?.info(error.message);
|
|
572
521
|
throw error;
|
|
573
522
|
}
|
|
574
523
|
return bookmark;
|
|
575
|
-
}))
|
|
524
|
+
}));
|
|
576
525
|
// execute the create bookmark action when the bookmark is resolved and not canceled
|
|
577
526
|
subscriber.add(dispatch$.subscribe({
|
|
578
527
|
error: (error) => subscriber.error(error),
|
|
579
528
|
next: (newBookmark) => {
|
|
580
529
|
// request the store to create the bookmark
|
|
581
|
-
|
|
530
|
+
this.#store.next(bookmarkActions.createBookmark(newBookmark, { ref }));
|
|
582
531
|
},
|
|
583
532
|
}));
|
|
584
533
|
// monitor the failure case when creating a bookmark
|
|
585
534
|
const failure$ = action$.pipe(filter(bookmarkActions.createBookmark.failure.match), map(({ payload: cause }) => {
|
|
586
|
-
var _a;
|
|
587
535
|
const error = new BookmarkProviderError(`Failed to create bookmark: ${ref}`, {
|
|
588
536
|
cause,
|
|
589
537
|
});
|
|
590
|
-
|
|
538
|
+
this._log?.warn(error.message);
|
|
591
539
|
throw error;
|
|
592
540
|
}), timeout({
|
|
593
541
|
each: defaultTimeout,
|
|
@@ -597,8 +545,7 @@ export class BookmarkProvider {
|
|
|
597
545
|
}));
|
|
598
546
|
// monitor the success case when creating a bookmark
|
|
599
547
|
const request$ = action$.pipe(filter(bookmarkActions.createBookmark.success.match), map(({ payload }) => payload), tap((bookmark) => {
|
|
600
|
-
|
|
601
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.info(`Bookmark created: ${bookmark.id}, ref: ${ref}`);
|
|
548
|
+
this._log?.info(`Bookmark created: ${bookmark.id}, ref: ${ref}`);
|
|
602
549
|
this._dispatchEvent('onBookmarkCreated', { detail: bookmark });
|
|
603
550
|
}), raceWith(failure$), first());
|
|
604
551
|
// emit the created bookmark
|
|
@@ -624,54 +571,54 @@ export class BookmarkProvider {
|
|
|
624
571
|
* @returns {Promise<Bookmark<T>>} - A promise that resolves to the updated bookmark.
|
|
625
572
|
*/
|
|
626
573
|
updateBookmark(bookmarkId, bookmarkUpdates, options) {
|
|
627
|
-
if (!bookmarkUpdates &&
|
|
574
|
+
if (!bookmarkUpdates && options?.excludePayloadGeneration) {
|
|
628
575
|
throw new BookmarkProviderError('Cannot update bookmark without updates and excludePayloadGeneration option');
|
|
629
576
|
}
|
|
630
577
|
return new Observable((subscriber) => {
|
|
631
|
-
var _a;
|
|
632
578
|
const { ref, action$ } = this._useScopedActions();
|
|
633
|
-
|
|
579
|
+
this._log?.debug(`Updating bookmark: ${bookmarkId}, ref: ${ref}`);
|
|
634
580
|
/**
|
|
635
581
|
* Generate updates with payload
|
|
636
582
|
* @remarks
|
|
637
583
|
* If `excludePayloadGeneration` is `true`, it emits the `bookmarkUpdates` directly.
|
|
638
584
|
* If `excludePayloadGeneration` is `false`, it generates the payload using the `generatePayload` method and emits the updated `bookmarkUpdates` with the generated payload.
|
|
639
585
|
*/
|
|
640
|
-
const updates$ =
|
|
586
|
+
const updates$ = options?.excludePayloadGeneration
|
|
641
587
|
? of(bookmarkUpdates)
|
|
642
|
-
: this.generatePayload(bookmarkUpdates
|
|
588
|
+
: this.generatePayload(bookmarkUpdates?.payload).pipe(map((payload) => ({
|
|
589
|
+
...bookmarkUpdates,
|
|
590
|
+
payload,
|
|
591
|
+
})));
|
|
643
592
|
// notify listeners that a bookmark is about to be updated
|
|
644
|
-
const dispatch$ = updates$.pipe(switchMap((updates) =>
|
|
645
|
-
|
|
646
|
-
const { canceled, type } = yield this._dispatchEvent('onBookmarkUpdate', {
|
|
593
|
+
const dispatch$ = updates$.pipe(switchMap(async (updates) => {
|
|
594
|
+
const { canceled, type } = await this._dispatchEvent('onBookmarkUpdate', {
|
|
647
595
|
detail: {
|
|
648
|
-
current: bookmarkSelector(
|
|
596
|
+
current: bookmarkSelector(this.#store.value, bookmarkId),
|
|
649
597
|
updates,
|
|
650
598
|
},
|
|
651
599
|
cancelable: true,
|
|
652
600
|
});
|
|
653
601
|
if (canceled) {
|
|
654
602
|
const error = new BookmarkProviderError(`event: ${type} was canceled by listener for updating bookmark: ${bookmarkId}, ref: ${ref}`);
|
|
655
|
-
|
|
603
|
+
this._log?.warn(error.message, updates);
|
|
656
604
|
throw error;
|
|
657
605
|
}
|
|
658
606
|
return updates;
|
|
659
|
-
}))
|
|
607
|
+
}));
|
|
660
608
|
// execute the update bookmark action when the updates are resolved and not canceled
|
|
661
609
|
subscriber.add(dispatch$.subscribe({
|
|
662
610
|
error: (error) => subscriber.error(error),
|
|
663
611
|
next: (updates) => {
|
|
664
612
|
// trigger the store to update the bookmark
|
|
665
|
-
|
|
613
|
+
this.#store.next(bookmarkActions.updateBookmark({ bookmarkId, updates }, { ref }));
|
|
666
614
|
},
|
|
667
615
|
}));
|
|
668
616
|
// monitor the failure case when updating a bookmark
|
|
669
617
|
const failure$ = action$.pipe(filter(bookmarkActions.updateBookmark.failure.match), map(({ payload: cause }) => {
|
|
670
|
-
var _a;
|
|
671
618
|
const error = new BookmarkProviderError(`Failed to update bookmark: ${bookmarkId}`, {
|
|
672
619
|
cause,
|
|
673
620
|
});
|
|
674
|
-
|
|
621
|
+
this._log?.info(error.message);
|
|
675
622
|
throw error;
|
|
676
623
|
}), timeout({
|
|
677
624
|
each: defaultTimeout,
|
|
@@ -682,9 +629,11 @@ export class BookmarkProvider {
|
|
|
682
629
|
// monitor the success case when updating a bookmark
|
|
683
630
|
const request$ = action$.pipe(filter(bookmarkActions.updateBookmark.success.match), map(
|
|
684
631
|
// TODO: add payload if current bookmark is the same as the updated bookmark
|
|
685
|
-
({ payload }) => (
|
|
686
|
-
|
|
687
|
-
|
|
632
|
+
({ payload }) => ({
|
|
633
|
+
...bookmarkSelector(this.#store.value, payload.id),
|
|
634
|
+
payload: payload.payload,
|
|
635
|
+
})), tap((bookmark) => {
|
|
636
|
+
this._log?.info(`Bookmark updated: ${bookmark.id}, ref: ${ref}`);
|
|
688
637
|
this._dispatchEvent('onBookmarkUpdated', { detail: bookmark });
|
|
689
638
|
}), raceWith(failure$), first());
|
|
690
639
|
// emit the updated bookmark
|
|
@@ -703,7 +652,7 @@ export class BookmarkProvider {
|
|
|
703
652
|
if (typeof id_or_bookmark === 'object') {
|
|
704
653
|
// @deprecated
|
|
705
654
|
console.warn('updateBookmarkAsync(bookmark, updates, options) is deprecated, use updateBookmarkAsync(id, updates, options) instead');
|
|
706
|
-
const
|
|
655
|
+
const { id, ...updates } = id_or_bookmark;
|
|
707
656
|
return lastValueFrom(this.updateBookmark(id, updates, {
|
|
708
657
|
excludePayloadGeneration: !updates_or_options.updatePayload,
|
|
709
658
|
}).pipe(
|
|
@@ -721,11 +670,10 @@ export class BookmarkProvider {
|
|
|
721
670
|
*/
|
|
722
671
|
deleteBookmark(bookmarkId) {
|
|
723
672
|
return new Observable((subscriber) => {
|
|
724
|
-
var _a, _b;
|
|
725
673
|
const { ref, action$ } = this._useScopedActions();
|
|
726
|
-
|
|
674
|
+
this._log?.debug(`Removing bookmark: ${bookmarkId}, ref: ${ref}`);
|
|
727
675
|
// bookmark to delete
|
|
728
|
-
const bookmark =
|
|
676
|
+
const bookmark = bookmarkSelector(this.#store.value, bookmarkId) ?? {
|
|
729
677
|
id: bookmarkId,
|
|
730
678
|
};
|
|
731
679
|
// observable that dispatches the 'onBookmarkDelete' event and maps the result
|
|
@@ -733,10 +681,9 @@ export class BookmarkProvider {
|
|
|
733
681
|
detail: bookmark,
|
|
734
682
|
cancelable: true,
|
|
735
683
|
})).pipe(map(({ canceled, type, detail }) => {
|
|
736
|
-
var _a;
|
|
737
684
|
if (canceled) {
|
|
738
685
|
const error = new BookmarkProviderError(`event: ${type} was canceled by listener for removing bookmark: ${bookmarkId}, ref: ${ref}`);
|
|
739
|
-
|
|
686
|
+
this._log?.warn(error.message);
|
|
740
687
|
throw error;
|
|
741
688
|
}
|
|
742
689
|
return detail;
|
|
@@ -746,16 +693,15 @@ export class BookmarkProvider {
|
|
|
746
693
|
error: (error) => subscriber.error(error),
|
|
747
694
|
next: (bookmark) => {
|
|
748
695
|
// request the store to delete the bookmark
|
|
749
|
-
|
|
696
|
+
this.#store.next(bookmarkActions.deleteBookmark(bookmark.id, { ref }));
|
|
750
697
|
},
|
|
751
698
|
}));
|
|
752
699
|
// monitor the failure case when deleting a bookmark
|
|
753
700
|
const failure$ = action$.pipe(filter(bookmarkActions.deleteBookmark.failure.match), map(({ payload: cause }) => {
|
|
754
|
-
var _a;
|
|
755
701
|
const error = new BookmarkProviderError(`Failed to update bookmark: ${bookmarkId}`, {
|
|
756
702
|
cause,
|
|
757
703
|
});
|
|
758
|
-
|
|
704
|
+
this._log?.warn(error.message);
|
|
759
705
|
throw error;
|
|
760
706
|
}), timeout({
|
|
761
707
|
each: defaultTimeout,
|
|
@@ -765,8 +711,7 @@ export class BookmarkProvider {
|
|
|
765
711
|
}));
|
|
766
712
|
// monitor the success case when deleting a bookmark
|
|
767
713
|
const request$ = action$.pipe(filter(bookmarkActions.deleteBookmark.success.match), map(() => undefined), tap(() => {
|
|
768
|
-
|
|
769
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.info(`Removed bookmark: ${bookmark.id}, ref: ${ref}`);
|
|
714
|
+
this._log?.info(`Removed bookmark: ${bookmark.id}, ref: ${ref}`);
|
|
770
715
|
this._dispatchEvent('onBookmarkDeleted', { detail: bookmark });
|
|
771
716
|
}), raceWith(failure$), first());
|
|
772
717
|
// emit the deleted bookmark
|
|
@@ -779,10 +724,8 @@ export class BookmarkProvider {
|
|
|
779
724
|
* @param bookmarkId - The ID of the bookmark to delete.
|
|
780
725
|
* @returns A Promise that resolves when the bookmark is deleted.
|
|
781
726
|
*/
|
|
782
|
-
deleteBookmarkAsync(bookmarkId) {
|
|
783
|
-
return
|
|
784
|
-
return lastValueFrom(this.deleteBookmark(bookmarkId));
|
|
785
|
-
});
|
|
727
|
+
async deleteBookmarkAsync(bookmarkId) {
|
|
728
|
+
return lastValueFrom(this.deleteBookmark(bookmarkId));
|
|
786
729
|
}
|
|
787
730
|
/**
|
|
788
731
|
* Adds a bookmark to the favorites.
|
|
@@ -796,18 +739,16 @@ export class BookmarkProvider {
|
|
|
796
739
|
* Emits a `Bookmark` object or `undefined` if the operation fails to resolve added bookmark.
|
|
797
740
|
*/
|
|
798
741
|
const result$ = new Observable((subscriber) => {
|
|
799
|
-
var _a;
|
|
800
742
|
const { ref, action$ } = this._useScopedActions();
|
|
801
|
-
|
|
743
|
+
this._log?.debug(`Adding bookmark: ${bookmarkId} to favourites, ref: ${ref}`);
|
|
802
744
|
// observable that dispatches the 'onBookmarkFavouriteAdd' event and maps the result
|
|
803
745
|
const dispatch$ = from(this._dispatchEvent('onBookmarkFavouriteAdd', {
|
|
804
746
|
detail: { id: bookmarkId },
|
|
805
747
|
cancelable: true,
|
|
806
748
|
})).pipe(map(({ canceled, type }) => {
|
|
807
|
-
var _a;
|
|
808
749
|
if (canceled) {
|
|
809
750
|
const error = new BookmarkProviderError(`event: ${type} was canceled by listener for adding favourite bookmark: ${bookmarkId}, ref: ${ref}`);
|
|
810
|
-
|
|
751
|
+
this._log?.info(error.message);
|
|
811
752
|
throw error;
|
|
812
753
|
}
|
|
813
754
|
}));
|
|
@@ -815,14 +756,13 @@ export class BookmarkProvider {
|
|
|
815
756
|
subscriber.add(dispatch$.subscribe({
|
|
816
757
|
error: (error) => subscriber.error(error),
|
|
817
758
|
next: () => {
|
|
818
|
-
|
|
759
|
+
this.#store.next(bookmarkActions.addBookmarkAsFavourite(bookmarkId, { ref }));
|
|
819
760
|
},
|
|
820
761
|
}));
|
|
821
762
|
// monitor the failure case when adding a bookmark as a favorite
|
|
822
763
|
const failure$ = action$.pipe(filter(bookmarkActions.addBookmarkAsFavourite.failure.match), map(({ payload: cause }) => {
|
|
823
|
-
var _a;
|
|
824
764
|
const error = new BookmarkProviderError(`Failed to add bookmark to favorites: ${bookmarkId}`, { cause });
|
|
825
|
-
|
|
765
|
+
this._log?.warn(error.message);
|
|
826
766
|
throw error;
|
|
827
767
|
}), timeout({
|
|
828
768
|
each: defaultTimeout,
|
|
@@ -832,8 +772,7 @@ export class BookmarkProvider {
|
|
|
832
772
|
}));
|
|
833
773
|
// monitor the success case when adding a bookmark as a favorite
|
|
834
774
|
const request$ = action$.pipe(filter(bookmarkActions.addBookmarkAsFavourite.success.match), switchMap(({ payload }) => this.getBookmark(payload, { excludePayload: true })), tap((bookmark) => {
|
|
835
|
-
|
|
836
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.info(`Added bookmark: ${bookmarkId} to favourites, ref: ${ref}`);
|
|
775
|
+
this._log?.info(`Added bookmark: ${bookmarkId} to favourites, ref: ${ref}`);
|
|
837
776
|
this._dispatchEvent('onBookmarkFavouriteAdded', { detail: bookmark });
|
|
838
777
|
}), raceWith(failure$), first());
|
|
839
778
|
// emit the added bookmark
|
|
@@ -862,20 +801,18 @@ export class BookmarkProvider {
|
|
|
862
801
|
* Represents an observable that emits void values when a bookmark's favorite is removed.
|
|
863
802
|
*/
|
|
864
803
|
const result$ = new Observable((subscriber) => {
|
|
865
|
-
var _a, _b;
|
|
866
804
|
const { ref, action$ } = this._useScopedActions();
|
|
867
|
-
|
|
805
|
+
this._log?.debug(`Removing bookmark: ${bookmarkId} from favourites, ref: ${ref}`);
|
|
868
806
|
// get the bookmark to remove as a favorite
|
|
869
|
-
const bookmark =
|
|
807
|
+
const bookmark = bookmarkSelector(this.#store.value, bookmarkId) ?? { id: bookmarkId };
|
|
870
808
|
// observable that dispatches the 'onBookmarkFavouriteRemove' event and maps the result
|
|
871
809
|
const dispatch$ = from(this._dispatchEvent('onBookmarkFavouriteRemove', {
|
|
872
810
|
detail: bookmark,
|
|
873
811
|
cancelable: true,
|
|
874
812
|
})).pipe(map(({ canceled, type, detail }) => {
|
|
875
|
-
var _a;
|
|
876
813
|
if (canceled) {
|
|
877
814
|
const error = new BookmarkProviderError(`event: ${type} was canceled by listener for removing favourite bookmark: ${bookmarkId}, ref: ${ref}`);
|
|
878
|
-
|
|
815
|
+
this._log?.warn(error.message);
|
|
879
816
|
throw error;
|
|
880
817
|
}
|
|
881
818
|
return detail;
|
|
@@ -885,16 +822,15 @@ export class BookmarkProvider {
|
|
|
885
822
|
error: (error) => subscriber.error(error),
|
|
886
823
|
next: (detail) => {
|
|
887
824
|
// request the store to remove the bookmark as a favorite
|
|
888
|
-
|
|
825
|
+
this.#store.next(bookmarkActions.removeBookmarkAsFavourite(detail.id, { ref }));
|
|
889
826
|
},
|
|
890
827
|
}));
|
|
891
828
|
// monitor the failure case when removing a bookmark as a favorite
|
|
892
829
|
const failure$ = action$.pipe(filter(bookmarkActions.removeBookmarkAsFavourite.failure.match), map(({ payload: cause }) => {
|
|
893
|
-
var _a;
|
|
894
830
|
const error = new BookmarkProviderError(`Failed to remove bookmark: ${bookmarkId} from favourites`, {
|
|
895
831
|
cause,
|
|
896
832
|
});
|
|
897
|
-
|
|
833
|
+
this._log?.warn(error.message);
|
|
898
834
|
throw error;
|
|
899
835
|
}), timeout({
|
|
900
836
|
each: defaultTimeout,
|
|
@@ -904,8 +840,7 @@ export class BookmarkProvider {
|
|
|
904
840
|
}));
|
|
905
841
|
// monitor the success case when removing a bookmark as a favorite
|
|
906
842
|
const request$ = action$.pipe(filter(bookmarkActions.removeBookmarkAsFavourite.success.match), tap(() => {
|
|
907
|
-
|
|
908
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.info(`Removed bookmark: ${bookmarkId} from favourites, ref: ${ref}`);
|
|
843
|
+
this._log?.info(`Removed bookmark: ${bookmarkId} from favourites, ref: ${ref}`);
|
|
909
844
|
this._dispatchEvent('onBookmarkFavouriteRemoved', { detail: bookmark });
|
|
910
845
|
}), map(() => { }), raceWith(failure$), first());
|
|
911
846
|
// emit the removed bookmark
|
|
@@ -928,17 +863,14 @@ export class BookmarkProvider {
|
|
|
928
863
|
* @returns A promise that resolves to a boolean indicating whether the bookmark is in the favorites.
|
|
929
864
|
*/
|
|
930
865
|
isBookmarkInFavorites(bookmarkId) {
|
|
931
|
-
|
|
932
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.debug(`Checking if bookmark: ${bookmarkId} is in favourites`);
|
|
866
|
+
this._log?.debug(`Checking if bookmark: ${bookmarkId} is in favourites`);
|
|
933
867
|
// Check if the bookmark is a favorite
|
|
934
868
|
return from(this._apiClient.isBookmarkFavorite(bookmarkId)).pipe(catchError((err) => {
|
|
935
|
-
var _a;
|
|
936
869
|
const error = new BookmarkProviderError(`Failed to check if bookmark: ${bookmarkId} is in favourites`, err);
|
|
937
|
-
|
|
870
|
+
this._log?.error(error.message, error);
|
|
938
871
|
throw error;
|
|
939
872
|
}), tap((isFavorite) => {
|
|
940
|
-
|
|
941
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.debug(`Bookmark: ${bookmarkId} is ${isFavorite ? 'in' : 'not in'} favourites`);
|
|
873
|
+
this._log?.debug(`Bookmark: ${bookmarkId} is ${isFavorite ? 'in' : 'not in'} favourites`);
|
|
942
874
|
}));
|
|
943
875
|
}
|
|
944
876
|
/**
|
|
@@ -951,40 +883,38 @@ export class BookmarkProvider {
|
|
|
951
883
|
return lastValueFrom(this.isBookmarkInFavorites(bookmarkId));
|
|
952
884
|
}
|
|
953
885
|
_getBookmarkInfo(bookmarkId, options) {
|
|
954
|
-
var _a;
|
|
955
886
|
// only actions with the specified reference are considered
|
|
956
887
|
const { action$ } = this._useScopedActions(bookmarkId);
|
|
957
888
|
// observable stream that emits the bookmark data when the fetch action is successful
|
|
958
889
|
const success$ = action$.pipe(filter(bookmarkActions.fetchBookmark.success.match), map((action) => action.payload), first());
|
|
959
890
|
// observable stream that emits an error when fetching bookmark data fails
|
|
960
|
-
const failure$ =
|
|
891
|
+
const failure$ = this.#store.action$.pipe(filter(bookmarkActions.fetchBookmark.failure.match), map((action) => {
|
|
961
892
|
throw new BookmarkProviderError(`Failed to fetch bookmark data: ${bookmarkId}`, action.payload);
|
|
962
893
|
}), timeout({
|
|
963
|
-
each:
|
|
894
|
+
each: options?.timeout ?? 2 * 60 * 1000,
|
|
964
895
|
with: () => {
|
|
965
896
|
throw new BookmarkProviderError(`Timeout while fetching bookmark data: ${bookmarkId}`);
|
|
966
897
|
},
|
|
967
898
|
}));
|
|
968
|
-
|
|
899
|
+
this.#store.next(bookmarkActions.fetchBookmark(bookmarkId, { ref: bookmarkId }));
|
|
969
900
|
return success$.pipe(raceWith(failure$));
|
|
970
901
|
}
|
|
971
902
|
_getBookmarkData(bookmarkId, options) {
|
|
972
|
-
var _a;
|
|
973
903
|
// only actions with the specified reference are considered
|
|
974
904
|
const { action$ } = this._useScopedActions(bookmarkId);
|
|
975
905
|
// observable stream that emits the bookmark data when the fetch action is successful
|
|
976
906
|
const success$ = action$.pipe(filter(bookmarkActions.fetchBookmarkData.success.match), map((action) => action.payload.data), first());
|
|
977
907
|
// observable stream that emits an error when fetching bookmark data fails
|
|
978
|
-
const failure$ =
|
|
908
|
+
const failure$ = this.#store.action$.pipe(filter(bookmarkActions.fetchBookmarkData.failure.match), map((action) => {
|
|
979
909
|
throw new BookmarkProviderError(`Failed to fetch bookmark data: ${bookmarkId}`, action.payload);
|
|
980
910
|
}), timeout({
|
|
981
|
-
each:
|
|
911
|
+
each: options?.timeout ?? defaultTimeout,
|
|
982
912
|
with: () => {
|
|
983
913
|
throw new BookmarkProviderError(`Timeout while fetching bookmark data: ${bookmarkId}`);
|
|
984
914
|
},
|
|
985
915
|
}));
|
|
986
916
|
// request the store to fetch the bookmark data
|
|
987
|
-
|
|
917
|
+
this.#store.next(bookmarkActions.fetchBookmarkData(bookmarkId, { ref: bookmarkId }));
|
|
988
918
|
return success$.pipe(raceWith(failure$));
|
|
989
919
|
}
|
|
990
920
|
/**
|
|
@@ -994,41 +924,41 @@ export class BookmarkProvider {
|
|
|
994
924
|
* @param args - The arguments to pass to the event.
|
|
995
925
|
* @returns A promise that resolves with the result of the event dispatch.
|
|
996
926
|
*/
|
|
997
|
-
_dispatchEvent(type, args) {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
(_a = this._log) === null || _a === void 0 ? void 0 : _a.debug(`dispatching event ${type}`, args);
|
|
1004
|
-
const { canceled } = yield this._event.dispatchEvent(event);
|
|
1005
|
-
if (canceled) {
|
|
1006
|
-
(_b = this._log) === null || _b === void 0 ? void 0 : _b.debug(`event ${type} was canceled`, args);
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
return event;
|
|
927
|
+
async _dispatchEvent(type, args) {
|
|
928
|
+
// create a new event instance
|
|
929
|
+
const event = new FrameworkEvent(type, {
|
|
930
|
+
source: this,
|
|
931
|
+
canBubble: true,
|
|
932
|
+
...args,
|
|
1010
933
|
});
|
|
934
|
+
if (this._event) {
|
|
935
|
+
this._log?.debug(`dispatching event ${type}`, args);
|
|
936
|
+
const { canceled } = await this._event.dispatchEvent(event);
|
|
937
|
+
if (canceled) {
|
|
938
|
+
this._log?.debug(`event ${type} was canceled`, args);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
return event;
|
|
1011
942
|
}
|
|
1012
943
|
_useScopedActions(ref) {
|
|
1013
944
|
/**
|
|
1014
945
|
* Generates a unique identifier for the operation
|
|
1015
946
|
*/
|
|
1016
|
-
ref
|
|
947
|
+
ref ??= generateGUID();
|
|
1017
948
|
/**
|
|
1018
949
|
* Observable stream of actions filtered by a specific reference.
|
|
1019
950
|
*/
|
|
1020
|
-
const action$ =
|
|
951
|
+
const action$ = this.#store.action$.pipe(filter((action) => 'meta' in action && action.meta?.ref === ref));
|
|
1021
952
|
return { ref, action$ };
|
|
1022
953
|
}
|
|
1023
954
|
/**
|
|
1024
955
|
* Disposes the BookmarkProvider.
|
|
1025
956
|
*/
|
|
1026
957
|
dispose() {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
__classPrivateFieldGet(this, _BookmarkProvider_subscriptions, "f").unsubscribe();
|
|
958
|
+
this._log?.debug('disposing BookmarkProvider');
|
|
959
|
+
this.#subscriptions.unsubscribe();
|
|
1030
960
|
}
|
|
1031
|
-
[
|
|
961
|
+
[Symbol.dispose]() {
|
|
1032
962
|
this.dispose();
|
|
1033
963
|
}
|
|
1034
964
|
}
|