@equinor/fusion-framework-module-bookmark 1.2.13 → 2.0.0
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 +37 -0
- package/README.md +242 -9
- package/dist/esm/BookmarkClient.interface.js +2 -0
- package/dist/esm/BookmarkClient.interface.js.map +1 -0
- package/dist/esm/BookmarkClient.js +174 -0
- package/dist/esm/BookmarkClient.js.map +1 -0
- package/dist/esm/BookmarkConfigurator.js +348 -0
- package/dist/esm/BookmarkConfigurator.js.map +1 -0
- package/dist/esm/BookmarkProvider.actions.js +60 -0
- package/dist/esm/BookmarkProvider.actions.js.map +1 -0
- package/dist/esm/BookmarkProvider.error.js +14 -0
- package/dist/esm/BookmarkProvider.error.js.map +1 -0
- package/dist/esm/BookmarkProvider.events.js +2 -0
- package/dist/esm/BookmarkProvider.events.js.map +1 -0
- package/dist/esm/BookmarkProvider.flows.js +219 -0
- package/dist/esm/BookmarkProvider.flows.js.map +1 -0
- package/dist/esm/BookmarkProvider.js +937 -0
- package/dist/esm/BookmarkProvider.js.map +1 -0
- package/dist/esm/BookmarkProvider.reducer.js +125 -0
- package/dist/esm/BookmarkProvider.reducer.js.map +1 -0
- package/dist/esm/BookmarkProvider.selectors.js +43 -0
- package/dist/esm/BookmarkProvider.selectors.js.map +1 -0
- package/dist/esm/BookmarkProvider.store.js +19 -0
- package/dist/esm/BookmarkProvider.store.js.map +1 -0
- package/dist/esm/bookmark-config.schema.js +30 -0
- package/dist/esm/bookmark-config.schema.js.map +1 -0
- package/dist/esm/bookmark-module.js +53 -0
- package/dist/esm/bookmark-module.js.map +1 -0
- package/dist/esm/bookmark.schemas.js +38 -0
- package/dist/esm/bookmark.schemas.js.map +1 -0
- package/dist/esm/enable-bookmark.js +20 -7
- package/dist/esm/enable-bookmark.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/BookmarkClient.d.ts +42 -0
- package/dist/types/BookmarkClient.interface.d.ts +139 -0
- package/dist/types/BookmarkConfigurator.d.ts +100 -0
- package/dist/types/BookmarkProvider.actions.d.ts +525 -0
- package/dist/types/BookmarkProvider.d.ts +462 -0
- package/dist/types/BookmarkProvider.error.d.ts +9 -0
- package/dist/types/BookmarkProvider.events.d.ts +78 -0
- package/dist/types/BookmarkProvider.flows.d.ts +79 -0
- package/dist/types/BookmarkProvider.reducer.d.ts +302 -0
- package/dist/types/BookmarkProvider.selectors.d.ts +34 -0
- package/dist/types/BookmarkProvider.store.d.ts +30 -0
- package/dist/types/bookmark-config.schema.d.ts +118 -0
- package/dist/types/{module.d.ts → bookmark-module.d.ts} +3 -3
- package/dist/types/bookmark.schemas.d.ts +760 -0
- package/dist/types/enable-bookmark.d.ts +7 -6
- package/dist/types/index.d.ts +4 -3
- package/dist/types/types.d.ts +29 -65
- package/dist/types/version.d.ts +1 -1
- package/package.json +11 -5
- package/src/BookmarkClient.interface.ts +157 -0
- package/src/BookmarkClient.ts +226 -0
- package/src/BookmarkConfigurator.ts +374 -0
- package/src/BookmarkProvider.actions.ts +131 -0
- package/src/BookmarkProvider.error.ts +21 -0
- package/src/BookmarkProvider.events.ts +89 -0
- package/src/BookmarkProvider.flows.ts +426 -0
- package/src/BookmarkProvider.reducer.ts +141 -0
- package/src/BookmarkProvider.selectors.ts +55 -0
- package/src/BookmarkProvider.store.ts +52 -0
- package/src/BookmarkProvider.ts +1308 -0
- package/src/bookmark-config.schema.ts +41 -0
- package/src/bookmark-module.ts +70 -0
- package/src/bookmark.schemas.ts +50 -0
- package/src/enable-bookmark.ts +13 -20
- package/src/index.ts +15 -7
- package/src/types.ts +46 -73
- package/src/version.ts +1 -1
- package/dist/esm/bookmark-config-builder.js +0 -131
- package/dist/esm/bookmark-config-builder.js.map +0 -1
- package/dist/esm/bookmark-provider.js +0 -155
- package/dist/esm/bookmark-provider.js.map +0 -1
- package/dist/esm/client/bookmarkActions.js +0 -10
- package/dist/esm/client/bookmarkActions.js.map +0 -1
- package/dist/esm/client/bookmarkClient.js +0 -259
- package/dist/esm/client/bookmarkClient.js.map +0 -1
- package/dist/esm/client/bookmarkFlows.js +0 -31
- package/dist/esm/client/bookmarkFlows.js.map +0 -1
- package/dist/esm/client/bookmarkReducer.js +0 -29
- package/dist/esm/client/bookmarkReducer.js.map +0 -1
- package/dist/esm/configurator.js +0 -155
- package/dist/esm/configurator.js.map +0 -1
- package/dist/esm/module.js +0 -27
- package/dist/esm/module.js.map +0 -1
- package/dist/esm/utils/handle-url.js +0 -11
- package/dist/esm/utils/handle-url.js.map +0 -1
- package/dist/esm/utils/index.js +0 -2
- package/dist/esm/utils/index.js.map +0 -1
- package/dist/types/bookmark-config-builder.d.ts +0 -85
- package/dist/types/bookmark-provider.d.ts +0 -169
- package/dist/types/client/bookmarkActions.d.ts +0 -27
- package/dist/types/client/bookmarkClient.d.ts +0 -53
- package/dist/types/client/bookmarkFlows.d.ts +0 -22
- package/dist/types/client/bookmarkReducer.d.ts +0 -5
- package/dist/types/configurator.d.ts +0 -75
- package/dist/types/utils/handle-url.d.ts +0 -2
- package/dist/types/utils/index.d.ts +0 -1
- package/src/bookmark-config-builder.ts +0 -177
- package/src/bookmark-provider.ts +0 -344
- package/src/client/bookmarkActions.ts +0 -44
- package/src/client/bookmarkClient.ts +0 -327
- package/src/client/bookmarkFlows.ts +0 -67
- package/src/client/bookmarkReducer.ts +0 -35
- package/src/configurator.ts +0 -235
- package/src/module.ts +0 -40
- package/src/utils/handle-url.ts +0 -13
- package/src/utils/index.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#2410](https://github.com/equinor/fusion-framework/pull/2410) [`9d1cb90`](https://github.com/equinor/fusion-framework/commit/9d1cb9003fa10e7ccaa95c20ef86f0a618034641) Thanks [@odinr](https://github.com/odinr)! - rewrite bookmark module
|
|
8
|
+
|
|
9
|
+
Needed rewrite of the bookmark module to better represent the api, and provide a more robust interface for working with bookmarks. Instead of fixing the current implementation, it was decided to rework the entire module to save time and confusion in the future.
|
|
10
|
+
|
|
11
|
+
The v1 implementation had strong coupling with the portal code and was not a good representation of the api. The new implementation is more robust and independent of source systems. The new implementation uses zod schemas to validate requests and responses.
|
|
12
|
+
|
|
13
|
+
The new implementation is not backwards compatible with the v1 implementation, so all ancestor modules should be updated to reflect the changes in this module.
|
|
14
|
+
|
|
15
|
+
The new implementation has better state management and error handling, and should be easier to work with than the v1 implementation.
|
|
16
|
+
|
|
17
|
+
**Highlights:**
|
|
18
|
+
|
|
19
|
+
- has validation of configuration of the module.
|
|
20
|
+
- uses the `BaseConfigBuilder` pattern for configuration.
|
|
21
|
+
- has validation of requests and responses using zod schemas.
|
|
22
|
+
- has better error handling and state management.
|
|
23
|
+
- has better separation of concerns.
|
|
24
|
+
- has better documentation.
|
|
25
|
+
- has better state management.
|
|
26
|
+
- has better flow control.
|
|
27
|
+
- has better logging.
|
|
28
|
+
|
|
29
|
+
**Migration:**
|
|
30
|
+
|
|
31
|
+
- update config for enabling the module
|
|
32
|
+
- check all direct access to provider interface if they are still valid
|
|
33
|
+
|
|
34
|
+
**Breaking changes:**
|
|
35
|
+
|
|
36
|
+
- The provider interface has changed
|
|
37
|
+
- The client interface has changed
|
|
38
|
+
- The configuration interface has changed
|
|
39
|
+
|
|
3
40
|
## 1.2.13
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,11 +1,244 @@
|
|
|
1
1
|
# Bookmark Module
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
3
|
+
The Bookmark module provides a way to manage bookmarks in the application. It allows users to create, update, and remove bookmarks, as well as manage the current bookmark and the list of bookmarks.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Create, update, and delete bookmarks**
|
|
8
|
+
- **Manage current bookmark**
|
|
9
|
+
- **Add and remove bookmarks from favorites**
|
|
10
|
+
- **Event listeners for bookmark-related events**
|
|
11
|
+
|
|
12
|
+
## Setup
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm install @equinor/fusion-framework-module-bookmark
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { enableBookmarkModule } from ' @equinor/fusion-framework-module-bookmark'
|
|
20
|
+
const configure = (configurator) => {
|
|
21
|
+
// simplest setup
|
|
22
|
+
enableBookmarkModule(configurator);
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
```ts
|
|
28
|
+
/** example of configuration */
|
|
29
|
+
enableBookmarkModule(configurator, async(builder) => {
|
|
30
|
+
/** Set source system of bookmark, note used for queries and creation */
|
|
31
|
+
builder.setSourceSystem({
|
|
32
|
+
id: 'source-system-id',
|
|
33
|
+
name: 'Source System Name',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** apply filters for current application */
|
|
37
|
+
builder.setFilter('application', true);
|
|
38
|
+
|
|
39
|
+
/** apply filters for current context */
|
|
40
|
+
builder.setFilter('context', true);
|
|
41
|
+
|
|
42
|
+
/** === Advance Configuration === */
|
|
43
|
+
|
|
44
|
+
/** override default implementations */
|
|
45
|
+
builder.setClient(/** custom client implementation */)
|
|
46
|
+
builder.setParent(/** custom parent implementation */)
|
|
47
|
+
|
|
48
|
+
/** override default resolvers */
|
|
49
|
+
builder.setContextResolver(/** custom context resolver implementation */)
|
|
50
|
+
builder.setApplicationResolver(/** custom application resolver implementation */)
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
> [!NOTE]
|
|
56
|
+
> When not providing configuration, the configurator will use the parent (ref initiator, example portal framework) configuration, then fallback to default configuration.
|
|
57
|
+
> - `SourceSystem`
|
|
58
|
+
> - `Filter`
|
|
59
|
+
> - `ContextResolver`
|
|
60
|
+
> - `ApplicationResolver`
|
|
61
|
+
>
|
|
62
|
+
|
|
63
|
+
## BookmarkProvider
|
|
64
|
+
|
|
65
|
+
The `BookmarkProvider` class is responsible for managing bookmarks in the application. It provides methods for creating, updating, and removing bookmarks, as well as managing the current bookmark and the list of bookmarks.
|
|
66
|
+
|
|
67
|
+
### Usage
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
#### Creating a Bookmark
|
|
71
|
+
|
|
72
|
+
To create a new bookmark, use the `createBookmark` method:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const newBookmark = {
|
|
76
|
+
name: 'My Bookmark',
|
|
77
|
+
payload: { /* Your bookmark data */ },
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
bookmarkProvider.createBookmark(newBookmark).subscribe({
|
|
81
|
+
next: (bookmark) => {
|
|
82
|
+
console.log('Bookmark created:', bookmark);
|
|
83
|
+
},
|
|
84
|
+
error: (err) => {
|
|
85
|
+
console.error('Failed to create bookmark:', err);
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
#### Updating a Bookmark
|
|
92
|
+
|
|
93
|
+
To update an existing bookmark, use the `updateBookmark` method:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
const bookmarkId = 'bookmark-id';
|
|
97
|
+
const bookmarkUpdates = {
|
|
98
|
+
name: 'Updated Bookmark Name',
|
|
99
|
+
payload: { /* Updated bookmark data */ },
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
bookmarkProvider.updateBookmark(bookmarkId, bookmarkUpdates).subscribe({
|
|
103
|
+
next: (updatedBookmark) => {
|
|
104
|
+
console.log('Bookmark updated:', updatedBookmark);
|
|
105
|
+
},
|
|
106
|
+
error: (err) => {
|
|
107
|
+
console.error('Failed to update bookmark:', err);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Using payload generator
|
|
113
|
+
|
|
114
|
+
Callback function which triggers on creation or update of bookmark. It is used to modify the payload of the bookmark.
|
|
115
|
+
|
|
116
|
+
- payload: The payload of the bookmark, which can be modified of other payload generators.
|
|
117
|
+
- initial: The initial payload of the bookmark, which is the payload of the bookmark before any payload generators have been applied.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const bookmarkPayloadGenerator = (payload, initial) => {
|
|
121
|
+
payload.counter = payload.counter ?? 0 + initial.counter;
|
|
122
|
+
};
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### Removing a Bookmark
|
|
126
|
+
|
|
127
|
+
To remove a bookmark, use the `removeBookmark` method:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
const bookmarkId = 'bookmark-id';
|
|
131
|
+
|
|
132
|
+
bookmarkProvider.removeBookmark(bookmarkId).subscribe({
|
|
133
|
+
next: (result) => {
|
|
134
|
+
console.log('Bookmark removed:', result);
|
|
135
|
+
},
|
|
136
|
+
error: (err) => {
|
|
137
|
+
console.error('Failed to remove bookmark:', err);
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
#### Managing Favorites
|
|
144
|
+
|
|
145
|
+
To add a bookmark to favorites, use the `addBookmarkToFavorites` method:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
const bookmarkId = 'bookmark-id';
|
|
149
|
+
|
|
150
|
+
bookmarkProvider.addBookmarkToFavorites(bookmarkId).subscribe({
|
|
151
|
+
next: (bookmark) => {
|
|
152
|
+
console.log('Bookmark added to favorites:', bookmark);
|
|
153
|
+
},
|
|
154
|
+
error: (err) => {
|
|
155
|
+
console.error('Failed to add bookmark to favorites:', err);
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
To remove a bookmark from favorites, use the `removeBookmarkFromFavorites` method:
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
const bookmarkId = 'bookmark-id';
|
|
164
|
+
bookmarkProvider.removeBookmarkFromFavorites(bookmarkId).subscribe({
|
|
165
|
+
next: (bookmark) => {
|
|
166
|
+
console.log('Bookmark removed from favorites:', bookmark);
|
|
167
|
+
},
|
|
168
|
+
error: (err) => {
|
|
169
|
+
console.error('Failed to remove bookmark from favorites:', err);
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
To check if a bookmark is in favorites, use the `isBookmarkInFavorites` method:
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
const bookmarkId = 'bookmark-id';
|
|
179
|
+
|
|
180
|
+
bookmarkProvider.isBookmarkInFavorites(bookmarkId).subscribe({
|
|
181
|
+
next: (isFavorite) => {
|
|
182
|
+
console.log('Is bookmark in favorites:', isFavorite);
|
|
183
|
+
},
|
|
184
|
+
error: (err) => {
|
|
185
|
+
console.error('Failed to check if bookmark is in favorites:', err);
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
#### Event Listeners
|
|
192
|
+
|
|
193
|
+
You can register event listeners for various bookmark-related events:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
const removeListener = bookmarkProvider.on('onCurrentBookmarkChanged', (event) => {
|
|
197
|
+
console.log('Current bookmark changed:', event.detail);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// To remove the event listener
|
|
201
|
+
removeListener();
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Client
|
|
205
|
+
|
|
206
|
+
The `BookmarkClient` class is responsible for fetching bookmarks from the source system. It provides methods for fetching bookmarks by ID, fetching bookmarks by query, and fetching the current bookmark. This is the default implementation of the client and created if not overridden in the configuration.
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
/** Example usage with BookmarkClient as stand alone */
|
|
210
|
+
import { BookmarkClient } from '@equinor/fusion-bookmark';
|
|
211
|
+
import { BookmarksApiClient } from '@equinor/fusion-framework-module-services/bookmarks';
|
|
212
|
+
import { HttpClient } from '@equinor/fusion-framework-module-http/client';
|
|
213
|
+
|
|
214
|
+
const httpClient = new HttpClient('https://my-fusion-backend-url.com');
|
|
215
|
+
const apiClient = new BookmarksApiClient(httpClient, 'json$');
|
|
216
|
+
const client = new BookmarkClient(apiClient);
|
|
217
|
+
|
|
218
|
+
client.getAllBookmarks().subscribe(bookmarks => {
|
|
219
|
+
// do something with bookmarks
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
client.getBookmarkById('bookmark-id').subscribe(bookmark => {
|
|
223
|
+
// do something with bookmark
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Custom Client
|
|
228
|
+
|
|
229
|
+
By implementing the `IBookmarkClient` interface, you can create a custom client implementation.
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { IBookmarkClient } from '@equinor/fusion-bookmark';
|
|
233
|
+
|
|
234
|
+
export class CustomBookmarkClient implements IBookmarkClient {
|
|
235
|
+
// Implement the interface methods
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const configure = (configurator) => {
|
|
239
|
+
enableBookmarkModule(configurator, async(builder) => {
|
|
240
|
+
builder.setClient(new CustomBookmarkClient());
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
```
|
|
244
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BookmarkClient.interface.js","sourceRoot":"","sources":["../../src/BookmarkClient.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
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");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
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");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
var _BookmarkClient_api, _BookmarkClient_queryBookmark, _BookmarkClient_queryBookmarks, _BookmarkClient_queryBookmarkData;
|
|
24
|
+
import { Observable } from 'rxjs';
|
|
25
|
+
import { map, shareReplay, tap } from 'rxjs/operators';
|
|
26
|
+
/**
|
|
27
|
+
* Imports the `Query` type from the `@equinor/fusion-query` package.
|
|
28
|
+
* This type is used to cache the results of API requests.
|
|
29
|
+
*/
|
|
30
|
+
import { Query } from '@equinor/fusion-query';
|
|
31
|
+
import { bookmarkSchema, bookmarkWithDataSchema, bookmarksSchema } from './bookmark.schemas';
|
|
32
|
+
/**
|
|
33
|
+
* Represents a client for interacting with the Fusion Bookmarks API.
|
|
34
|
+
* This class provides methods for retrieving, creating, updating, and deleting bookmarks, as well as managing favorites.
|
|
35
|
+
*
|
|
36
|
+
* This implementation consumes the `@equinor/fusion-framework-module-services/bookmarks` package.
|
|
37
|
+
* This is the default implementation of the bookmarks API client.
|
|
38
|
+
*
|
|
39
|
+
* This class is intended to be used by the Fusion framework with the Fusion Core Services (Backend)
|
|
40
|
+
*
|
|
41
|
+
* Fetching single and all bookmarks will use Query from '@equinor/fusion-query' to cache the results.
|
|
42
|
+
*
|
|
43
|
+
* @note if you wish to implement your own bookmarks API client, you can do so by implementing the {@link IBookmarkClient} interface.
|
|
44
|
+
*/
|
|
45
|
+
export class BookmarkClient {
|
|
46
|
+
/**
|
|
47
|
+
* Constructs a new `BookmarkClient` instance with the provided `BookmarksApiClient`.
|
|
48
|
+
*
|
|
49
|
+
* @param api - The `BookmarksApiClient` instance to use for making API requests.
|
|
50
|
+
*/
|
|
51
|
+
constructor(api, options) {
|
|
52
|
+
_BookmarkClient_api.set(this, void 0);
|
|
53
|
+
_BookmarkClient_queryBookmark.set(this, void 0);
|
|
54
|
+
_BookmarkClient_queryBookmarks.set(this, void 0);
|
|
55
|
+
_BookmarkClient_queryBookmarkData.set(this, void 0);
|
|
56
|
+
__classPrivateFieldSet(this, _BookmarkClient_api, api, "f");
|
|
57
|
+
const { expire = 5 * 60 * 1000 } = options !== null && options !== void 0 ? options : {};
|
|
58
|
+
// set up the query for fetching a single bookmark
|
|
59
|
+
__classPrivateFieldSet(this, _BookmarkClient_queryBookmark, new Query({
|
|
60
|
+
client: {
|
|
61
|
+
fn: (args) => {
|
|
62
|
+
return __classPrivateFieldGet(this, _BookmarkClient_api, "f").get('v2', args).pipe(map((res) => bookmarkSchema.parse(res)));
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
key: (args) => args.bookmarkId,
|
|
66
|
+
expire,
|
|
67
|
+
}), "f");
|
|
68
|
+
// set up the query for fetching all bookmarks
|
|
69
|
+
__classPrivateFieldSet(this, _BookmarkClient_queryBookmarks, new Query({
|
|
70
|
+
client: {
|
|
71
|
+
fn: (filter) => {
|
|
72
|
+
return __classPrivateFieldGet(this, _BookmarkClient_api, "f")
|
|
73
|
+
.query('v1', { filter })
|
|
74
|
+
.pipe(map((res) => bookmarksSchema.parse(res)));
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
key: (args) => JSON.stringify(args !== null && args !== void 0 ? args : ''),
|
|
78
|
+
expire,
|
|
79
|
+
}), "f");
|
|
80
|
+
__classPrivateFieldSet(this, _BookmarkClient_queryBookmarkData, new Query({
|
|
81
|
+
client: {
|
|
82
|
+
fn: (args) => {
|
|
83
|
+
return __classPrivateFieldGet(this, _BookmarkClient_api, "f").getPayload('v1', args).pipe(map((res) => res.payload));
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
key: (args) => args.bookmarkId,
|
|
87
|
+
expire,
|
|
88
|
+
cache: {
|
|
89
|
+
trimming: {
|
|
90
|
+
size: 3,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
}), "f");
|
|
94
|
+
}
|
|
95
|
+
getAllBookmarks(filter) {
|
|
96
|
+
return __classPrivateFieldGet(this, _BookmarkClient_queryBookmarks, "f").query(filter).pipe(map((res) => res.value));
|
|
97
|
+
}
|
|
98
|
+
getBookmarkById(bookmarkId) {
|
|
99
|
+
return __classPrivateFieldGet(this, _BookmarkClient_queryBookmark, "f").query({ bookmarkId }).pipe(map((res) => res.value));
|
|
100
|
+
}
|
|
101
|
+
getBookmarkData(bookmarkId) {
|
|
102
|
+
return __classPrivateFieldGet(this, _BookmarkClient_queryBookmarkData, "f").query({ bookmarkId }).pipe(map((res) => res.value));
|
|
103
|
+
}
|
|
104
|
+
setBookmarkData(bookmarkId, data) {
|
|
105
|
+
return __classPrivateFieldGet(this, _BookmarkClient_api, "f").patch('v1', { bookmarkId, updates: { payload: data } }).pipe(map((res) => res.payload), tap((updatedData) => {
|
|
106
|
+
if (updatedData) {
|
|
107
|
+
__classPrivateFieldGet(this, _BookmarkClient_queryBookmarkData, "f").mutate({ bookmarkId }, { value: updatedData, updated: Date.now() }, { allowCreation: true });
|
|
108
|
+
}
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
createBookmark(newBookmark) {
|
|
112
|
+
return __classPrivateFieldGet(this, _BookmarkClient_api, "f").create('v1', newBookmark).pipe(map((response) => bookmarkWithDataSchema().parse(response)),
|
|
113
|
+
/** update the bookmark cache */
|
|
114
|
+
tap((createdBookmark) => {
|
|
115
|
+
const { payload } = createdBookmark, bookmark = __rest(createdBookmark, ["payload"]);
|
|
116
|
+
__classPrivateFieldGet(this, _BookmarkClient_queryBookmark, "f").mutate({ bookmarkId: bookmark.id }, { value: bookmark, updated: Date.now() }, { allowCreation: true });
|
|
117
|
+
if (payload) {
|
|
118
|
+
__classPrivateFieldGet(this, _BookmarkClient_queryBookmarkData, "f").mutate({ bookmarkId: bookmark.id }, { value: payload, updated: Date.now() }, { allowCreation: true });
|
|
119
|
+
}
|
|
120
|
+
__classPrivateFieldGet(this, _BookmarkClient_queryBookmarks, "f").invalidate();
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
updateBookmark(bookmarkId, updates) {
|
|
124
|
+
const update$ = __classPrivateFieldGet(this, _BookmarkClient_api, "f").patch('v1', { bookmarkId, updates: updates }).pipe(map((response) => bookmarkWithDataSchema().parse(response)), shareReplay());
|
|
125
|
+
return new Observable((subscriber) => {
|
|
126
|
+
// update the query cache for the specific bookmark
|
|
127
|
+
subscriber.add(update$.subscribe((updatedBookmark) => {
|
|
128
|
+
const { payload } = updatedBookmark, bookmark = __rest(updatedBookmark, ["payload"]);
|
|
129
|
+
// payload should not be included in the bookmark object
|
|
130
|
+
payload;
|
|
131
|
+
__classPrivateFieldGet(this, _BookmarkClient_queryBookmark, "f").mutate({ bookmarkId }, { value: bookmark, updated: Date.now() }, { allowCreation: false });
|
|
132
|
+
}));
|
|
133
|
+
// update the cache for bookmark data
|
|
134
|
+
subscriber.add(update$.subscribe((updatedBookmark) => {
|
|
135
|
+
const { payload } = updatedBookmark;
|
|
136
|
+
if (payload) {
|
|
137
|
+
__classPrivateFieldGet(this, _BookmarkClient_queryBookmarkData, "f").mutate({
|
|
138
|
+
bookmarkId: updatedBookmark.id,
|
|
139
|
+
}, { value: payload, updated: Date.now() }, { allowCreation: true });
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
const cacheKey = __classPrivateFieldGet(this, _BookmarkClient_queryBookmarkData, "f").generateCacheKey({
|
|
143
|
+
bookmarkId: updatedBookmark.id,
|
|
144
|
+
});
|
|
145
|
+
__classPrivateFieldGet(this, _BookmarkClient_queryBookmarkData, "f").cache.removeItem(cacheKey);
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
148
|
+
// invalidate the bookmarks query cache
|
|
149
|
+
subscriber.add(update$.subscribe(() => {
|
|
150
|
+
__classPrivateFieldGet(this, _BookmarkClient_queryBookmarks, "f").invalidate();
|
|
151
|
+
}));
|
|
152
|
+
// emit the update to the subscriber
|
|
153
|
+
update$.subscribe(subscriber);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
deleteBookmark(bookmarkId) {
|
|
157
|
+
return __classPrivateFieldGet(this, _BookmarkClient_api, "f").delete('v1', { bookmarkId });
|
|
158
|
+
}
|
|
159
|
+
addBookmarkToFavorites(bookmarkId) {
|
|
160
|
+
return __classPrivateFieldGet(this, _BookmarkClient_api, "f")
|
|
161
|
+
.addFavourite('v1', { bookmarkId })
|
|
162
|
+
.pipe(tap(() => __classPrivateFieldGet(this, _BookmarkClient_queryBookmarks, "f").invalidate()));
|
|
163
|
+
}
|
|
164
|
+
removeBookmarkFromFavorites(bookmarkId) {
|
|
165
|
+
return __classPrivateFieldGet(this, _BookmarkClient_api, "f")
|
|
166
|
+
.removeFavourite('v1', { bookmarkId })
|
|
167
|
+
.pipe(tap(() => __classPrivateFieldGet(this, _BookmarkClient_queryBookmarks, "f").invalidate()));
|
|
168
|
+
}
|
|
169
|
+
isBookmarkFavorite(bookmarkId) {
|
|
170
|
+
return __classPrivateFieldGet(this, _BookmarkClient_api, "f").isFavorite('v1', { bookmarkId });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
_BookmarkClient_api = new WeakMap(), _BookmarkClient_queryBookmark = new WeakMap(), _BookmarkClient_queryBookmarks = new WeakMap(), _BookmarkClient_queryBookmarkData = new WeakMap();
|
|
174
|
+
//# sourceMappingURL=BookmarkClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BookmarkClient.js","sourceRoot":"","sources":["../../src/BookmarkClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAwB,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAEvD;;;GAGG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAgB9C,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE7F;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,cAAc;IAOvB;;;;OAIG;IACH,YAAY,GAAgC,EAAE,OAA6B;QAX3E,sCAAkC;QAElC,gDAAmE;QACnE,iDAA+D;QAC/D,oDAA4E;QAQxE,uBAAA,IAAI,uBAAQ,GAAG,MAAA,CAAC;QAEhB,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;QAEjD,kDAAkD;QAClD,uBAAA,IAAI,iCAAkB,IAAI,KAAK,CAAC;YA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