@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
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import { IBookmarkModuleConfigurator } from './configurator';
|
|
1
|
+
import type { IModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
2
|
+
import { BookmarkModuleConfigurator } from './BookmarkConfigurator';
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Enables the Bookmark module
|
|
5
|
+
*
|
|
6
|
+
* @param configurator - The configuration object for the modules.
|
|
7
|
+
* @param callback - An optional callback function that receives the `BookmarkModuleConfigurator` instance, allowing for further configuration.
|
|
7
8
|
*/
|
|
8
|
-
export declare const enableBookmark: (configurator: IModulesConfigurator<any
|
|
9
|
+
export declare const enableBookmark: (configurator: IModulesConfigurator<any>, callback?: (builder: BookmarkModuleConfigurator) => void | Promise<void>) => void;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { BookmarkModuleConfigurator
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { BookmarkModuleConfigurator } from './BookmarkConfigurator';
|
|
2
|
+
export type { IBookmarkClient, BookmarkNew, BookmarkUpdate, BookmarksFilter, } from './BookmarkClient.interface';
|
|
3
|
+
export { default, BookmarkModule, module as bookmarkModule, moduleKey as bookmarkModuleKey, } from './bookmark-module';
|
|
4
|
+
export { BookmarkProvider, type BookmarkPayloadGenerator, type BookmarkCreateArgs, type BookmarkUpdateOptions, } from './BookmarkProvider';
|
|
4
5
|
export { enableBookmark } from './enable-bookmark';
|
|
5
6
|
export * from './types';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,65 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
payload: TData;
|
|
31
|
-
sourceSystem?: Partial<SourceSystem>;
|
|
32
|
-
};
|
|
33
|
-
export interface SourceSystem {
|
|
34
|
-
identifier: string;
|
|
35
|
-
name: string;
|
|
36
|
-
subSystem: string;
|
|
37
|
-
}
|
|
38
|
-
interface CreatedBy {
|
|
39
|
-
azureUniqueId: string;
|
|
40
|
-
mail: string;
|
|
41
|
-
name: string;
|
|
42
|
-
phoneNumber: string;
|
|
43
|
-
jobTitle: string;
|
|
44
|
-
accountType: number;
|
|
45
|
-
accountClassification: number;
|
|
46
|
-
}
|
|
47
|
-
interface Context {
|
|
48
|
-
id: string;
|
|
49
|
-
name: string;
|
|
50
|
-
type: string;
|
|
51
|
-
}
|
|
52
|
-
export type GetBookmarkParameters = {
|
|
53
|
-
id: string;
|
|
54
|
-
};
|
|
55
|
-
export type GetAllBookmarksParameters = {
|
|
56
|
-
isValid: boolean;
|
|
57
|
-
};
|
|
58
|
-
export interface BookmarkQueryClient {
|
|
59
|
-
getAllBookmarks: QueryFn<Array<Bookmark<unknown>>, GetAllBookmarksParameters> | QueryCtorOptions<Array<Bookmark<unknown>>, GetAllBookmarksParameters>;
|
|
60
|
-
getBookmarkById: QueryFn<Bookmark<unknown>, GetBookmarkParameters> | QueryCtorOptions<Bookmark<unknown>, GetBookmarkParameters>;
|
|
61
|
-
}
|
|
62
|
-
export type UpdateBookmarkOptions = {
|
|
63
|
-
updatePayload: boolean;
|
|
64
|
-
};
|
|
65
|
-
export {};
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { bookmarkSchema, bookmarkSourceSystemSchema, bookmarksSchema, bookmarkWithDataSchema } from './bookmark.schemas';
|
|
3
|
+
import { bookmarkConfigSchema } from './bookmark-config.schema';
|
|
4
|
+
/**
|
|
5
|
+
* Represents the source system for a bookmark.
|
|
6
|
+
*/
|
|
7
|
+
export type SourceSystem = z.infer<typeof bookmarkSourceSystemSchema>;
|
|
8
|
+
/**
|
|
9
|
+
* Represents the data associated with a bookmark.
|
|
10
|
+
* This is a generic type that can hold any arbitrary data as a key-value map.
|
|
11
|
+
*/
|
|
12
|
+
export type BookmarkData = Record<string, any> | string;
|
|
13
|
+
/**
|
|
14
|
+
* Represents a collection of bookmarks.
|
|
15
|
+
*/
|
|
16
|
+
export type Bookmarks = z.infer<typeof bookmarksSchema>;
|
|
17
|
+
/**
|
|
18
|
+
* Represents a bookmark without any associated data.
|
|
19
|
+
*/
|
|
20
|
+
export type BookmarkWithoutData = z.infer<typeof bookmarkSchema>;
|
|
21
|
+
/**
|
|
22
|
+
* Represents a bookmark with associated data.
|
|
23
|
+
* @template T - The type of the bookmark data.
|
|
24
|
+
*/
|
|
25
|
+
export type Bookmark<T extends BookmarkData = any> = z.infer<ReturnType<typeof bookmarkWithDataSchema<T>>>;
|
|
26
|
+
/**
|
|
27
|
+
* Represents the configuration options for a bookmark module.
|
|
28
|
+
*/
|
|
29
|
+
export type BookmarkModuleConfig = z.infer<typeof bookmarkConfigSchema>;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "
|
|
1
|
+
export declare const version = "2.0.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-bookmark",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -34,18 +34,24 @@
|
|
|
34
34
|
"directory": "packages/modules/context"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"fast-deep-equal": "^3.1.3",
|
|
38
|
+
"immer": "^9.0.16",
|
|
37
39
|
"rxjs": "^7.8.1",
|
|
38
|
-
"
|
|
40
|
+
"uuid": "^9.0.1",
|
|
41
|
+
"@equinor/fusion-log": "^1.1.0",
|
|
39
42
|
"@equinor/fusion-observable": "^8.4.2",
|
|
40
|
-
"@equinor/fusion-query": "^5.1.4"
|
|
43
|
+
"@equinor/fusion-query": "^5.1.4",
|
|
44
|
+
"@equinor/fusion-framework-module": "^4.3.5"
|
|
41
45
|
},
|
|
42
46
|
"devDependencies": {
|
|
47
|
+
"@types/uuid": "^9.0.8",
|
|
43
48
|
"typescript": "^5.5.4",
|
|
44
|
-
"
|
|
49
|
+
"zod": "^3.23.8",
|
|
45
50
|
"@equinor/fusion-framework-module-context": "^5.0.13",
|
|
51
|
+
"@equinor/fusion-framework-module-app": "^6.0.2",
|
|
46
52
|
"@equinor/fusion-framework-module-event": "^4.2.4",
|
|
47
53
|
"@equinor/fusion-framework-module-http": "^6.2.0",
|
|
48
|
-
"@equinor/fusion-framework-module-services": "^
|
|
54
|
+
"@equinor/fusion-framework-module-services": "^5.0.0"
|
|
49
55
|
},
|
|
50
56
|
"scripts": {
|
|
51
57
|
"build": "tsc -b"
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { type ObservableInput } from 'rxjs';
|
|
2
|
+
import type { Bookmark, BookmarkData, BookmarkWithoutData } from './types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Defines the shape of a filter for querying bookmarks.
|
|
6
|
+
* @property {string} [appKey] - The app key to filter bookmarks by.
|
|
7
|
+
* @property {string} [contextId] - The context ID to filter bookmarks by.
|
|
8
|
+
* @property {object} [sourceSystem] - The source system to filter bookmarks by.
|
|
9
|
+
* @property {string} [sourceSystem.identifier] - The identifier of the source system.
|
|
10
|
+
* @property {string} [sourceSystem.name] - The name of the source system.
|
|
11
|
+
* @property {string} [sourceSystem.subSystem] - The sub-system of the source system.
|
|
12
|
+
*/
|
|
13
|
+
export type BookmarksFilter = {
|
|
14
|
+
appKey?: string;
|
|
15
|
+
contextId?: string;
|
|
16
|
+
sourceSystem?: {
|
|
17
|
+
identifier?: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
subSystem?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Defines the shape of an update to an existing bookmark.
|
|
25
|
+
* @template T - The type of the payload data for the bookmark.
|
|
26
|
+
* @property {string} [name] - The updated name of the bookmark.
|
|
27
|
+
* @property {string} [description] - The updated description of the bookmark.
|
|
28
|
+
* @property {boolean} [isShared] - Whether the bookmark is shared or not.
|
|
29
|
+
* @property {T} [payload] - The updated payload data for the bookmark.
|
|
30
|
+
*/
|
|
31
|
+
export type BookmarkUpdate<T extends BookmarkData = BookmarkData> = {
|
|
32
|
+
name?: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
isShared?: boolean;
|
|
35
|
+
payload?: T | null;
|
|
36
|
+
sourceSystem?: {
|
|
37
|
+
identifier: string;
|
|
38
|
+
name?: string | null;
|
|
39
|
+
subSystem?: string | null;
|
|
40
|
+
} | null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Defines the shape of a new bookmark to be created.
|
|
45
|
+
* @template T - The type of the payload data for the bookmark.
|
|
46
|
+
* @property {string} name - The name of the bookmark.
|
|
47
|
+
* @property {string} appKey - The app key associated with the bookmark.
|
|
48
|
+
* @property {string} [description] - The description of the bookmark.
|
|
49
|
+
* @property {boolean} [isShared] - Whether the bookmark is shared or not.
|
|
50
|
+
* @property {string} [contextId] - The context ID associated with the bookmark.
|
|
51
|
+
* @property {object} [sourceSystem] - Information about the source system of the bookmark.
|
|
52
|
+
* @property {string} [sourceSystem.identifier] - The identifier of the source system.
|
|
53
|
+
* @property {string} [sourceSystem.name] - The name of the source system.
|
|
54
|
+
* @property {string} [sourceSystem.subSystem] - The sub-system of the source system.
|
|
55
|
+
* @property {T} [payload] - The payload data for the bookmark.
|
|
56
|
+
*/
|
|
57
|
+
export type BookmarkNew<T extends BookmarkData = BookmarkData> = {
|
|
58
|
+
name: string;
|
|
59
|
+
appKey: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
isShared?: boolean;
|
|
62
|
+
contextId?: string;
|
|
63
|
+
sourceSystem?: {
|
|
64
|
+
identifier: string;
|
|
65
|
+
name?: string;
|
|
66
|
+
subSystem?: string;
|
|
67
|
+
};
|
|
68
|
+
payload?: T;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Defines the interface for a Bookmarks client, which provides methods for managing bookmarks.
|
|
73
|
+
*/
|
|
74
|
+
export interface IBookmarkClient {
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves all bookmarks for the current user.
|
|
77
|
+
* @template TPayload - The type of the payload data for the bookmarks.
|
|
78
|
+
* @param args - Optional arguments to filter or customize the bookmark retrieval.
|
|
79
|
+
* @returns An observable input containing an array of bookmarks.
|
|
80
|
+
*/
|
|
81
|
+
getAllBookmarks: (filter?: BookmarksFilter) => ObservableInput<Array<Bookmark>>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves a single bookmark by id.
|
|
85
|
+
* @template TPayload - The type of the payload data for the bookmark.
|
|
86
|
+
* @param bookmarkId - The id of the bookmark to retrieve.
|
|
87
|
+
* @returns An observable input containing the requested bookmark.
|
|
88
|
+
*/
|
|
89
|
+
getBookmarkById: (bookmarkId: string) => ObservableInput<BookmarkWithoutData>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Retrieves the bookmark data for the specified bookmark ID.
|
|
93
|
+
*
|
|
94
|
+
* @param bookmarkId - The ID of the bookmark to retrieve data for.
|
|
95
|
+
* @returns An observable that emits the bookmark data.
|
|
96
|
+
*/
|
|
97
|
+
getBookmarkData: <T extends BookmarkData>(bookmarkId: string) => ObservableInput<T>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Updates the data associated with a bookmark.
|
|
101
|
+
*
|
|
102
|
+
* @template T - The type of the data to be associated with the bookmark. Can be a record or null.
|
|
103
|
+
* @param bookmarkId - The ID of the bookmark to update.
|
|
104
|
+
* @param data - The new data to be associated with the bookmark.
|
|
105
|
+
* @returns An observable that emits the updated data.
|
|
106
|
+
*/
|
|
107
|
+
setBookmarkData<T extends BookmarkData | null>(bookmarkId: string, data: T): ObservableInput<T>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Adds a bookmark to the current user's favorites.
|
|
111
|
+
* @param bookmarkId - The id of the bookmark to add to favorites.
|
|
112
|
+
* @returns An observable input containing a boolean indicating whether the operation was successful.
|
|
113
|
+
*/
|
|
114
|
+
addBookmarkToFavorites: (bookmarkId: string) => ObservableInput<boolean>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Removes a bookmark from the current user's favorites.
|
|
118
|
+
* @param bookmarkId - The id of the bookmark to remove from favorites.
|
|
119
|
+
* @returns An observable input containing a boolean indicating whether the operation was successful.
|
|
120
|
+
*/
|
|
121
|
+
removeBookmarkFromFavorites: (bookmarkId: string) => ObservableInput<boolean>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Verifies whether a bookmark is a favorite of the current user.
|
|
125
|
+
* @param bookmarkId - The id of the bookmark to verify.
|
|
126
|
+
* @returns An observable input containing a boolean indicating whether the bookmark is a favorite.
|
|
127
|
+
*/
|
|
128
|
+
isBookmarkFavorite: (bookmarkId: string) => ObservableInput<boolean>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Creates a new bookmark.
|
|
132
|
+
* @template TPayload - The type of the payload data for the bookmark.
|
|
133
|
+
* @param bookmark - The bookmark data to create.
|
|
134
|
+
* @returns An observable input containing the created bookmark.
|
|
135
|
+
*/
|
|
136
|
+
createBookmark: <T extends BookmarkData>(
|
|
137
|
+
bookmark: BookmarkNew<T>,
|
|
138
|
+
) => ObservableInput<Bookmark<T>>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Updates an existing bookmark.
|
|
142
|
+
* @template TPayload - The type of the payload data for the bookmark.
|
|
143
|
+
* @param bookmark - The bookmark data to update.
|
|
144
|
+
* @returns An observable input containing the updated bookmark.
|
|
145
|
+
*/
|
|
146
|
+
updateBookmark: <T extends BookmarkData>(
|
|
147
|
+
bookmarkId: string,
|
|
148
|
+
updates: BookmarkUpdate<T>,
|
|
149
|
+
) => ObservableInput<Bookmark<T>>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Deletes a bookmark by id.
|
|
153
|
+
* @param bookmarkId - The id of the bookmark to delete.
|
|
154
|
+
* @returns An observable input containing a boolean indicating whether the operation was successful.
|
|
155
|
+
*/
|
|
156
|
+
deleteBookmark: (bookmarkId: string) => ObservableInput<boolean>;
|
|
157
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { Observable, type ObservableInput } from 'rxjs';
|
|
2
|
+
import { map, shareReplay, tap } from 'rxjs/operators';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Imports the `Query` type from the `@equinor/fusion-query` package.
|
|
6
|
+
* This type is used to cache the results of API requests.
|
|
7
|
+
*/
|
|
8
|
+
import { Query } from '@equinor/fusion-query';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Imports the `BookmarksApiClient` and `ApiBookmarkEntityV1` types from the `@equinor/fusion-framework-module-services/bookmarks` package.
|
|
12
|
+
* These types are used to interact with the Fusion Bookmarks API and represent the API response entities.
|
|
13
|
+
*/
|
|
14
|
+
import type { BookmarksApiClient } from '@equinor/fusion-framework-module-services/bookmarks';
|
|
15
|
+
|
|
16
|
+
import type {
|
|
17
|
+
IBookmarkClient,
|
|
18
|
+
BookmarksFilter,
|
|
19
|
+
BookmarkNew,
|
|
20
|
+
BookmarkUpdate,
|
|
21
|
+
} from './BookmarkClient.interface';
|
|
22
|
+
|
|
23
|
+
import type { Bookmark, BookmarkData, BookmarkWithoutData, Bookmarks } from './types';
|
|
24
|
+
import { bookmarkSchema, bookmarkWithDataSchema, bookmarksSchema } from './bookmark.schemas';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Represents a client for interacting with the Fusion Bookmarks API.
|
|
28
|
+
* This class provides methods for retrieving, creating, updating, and deleting bookmarks, as well as managing favorites.
|
|
29
|
+
*
|
|
30
|
+
* This implementation consumes the `@equinor/fusion-framework-module-services/bookmarks` package.
|
|
31
|
+
* This is the default implementation of the bookmarks API client.
|
|
32
|
+
*
|
|
33
|
+
* This class is intended to be used by the Fusion framework with the Fusion Core Services (Backend)
|
|
34
|
+
*
|
|
35
|
+
* Fetching single and all bookmarks will use Query from '@equinor/fusion-query' to cache the results.
|
|
36
|
+
*
|
|
37
|
+
* @note if you wish to implement your own bookmarks API client, you can do so by implementing the {@link IBookmarkClient} interface.
|
|
38
|
+
*/
|
|
39
|
+
export class BookmarkClient implements IBookmarkClient {
|
|
40
|
+
#api: BookmarksApiClient<'json$'>;
|
|
41
|
+
|
|
42
|
+
#queryBookmark: Query<BookmarkWithoutData, { bookmarkId: string }>;
|
|
43
|
+
#queryBookmarks: Query<Bookmarks, BookmarksFilter | undefined>;
|
|
44
|
+
#queryBookmarkData: Query<BookmarkData | undefined, { bookmarkId: string }>;
|
|
45
|
+
|
|
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: BookmarksApiClient<'json$'>, options?: { expire?: number }) {
|
|
52
|
+
this.#api = api;
|
|
53
|
+
|
|
54
|
+
const { expire = 5 * 60 * 1000 } = options ?? {};
|
|
55
|
+
|
|
56
|
+
// set up the query for fetching a single bookmark
|
|
57
|
+
this.#queryBookmark = new Query({
|
|
58
|
+
client: {
|
|
59
|
+
fn: (args: { bookmarkId: string }) => {
|
|
60
|
+
return this.#api.get('v2', args).pipe(map((res) => bookmarkSchema.parse(res)));
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
key: (args) => args.bookmarkId,
|
|
64
|
+
expire,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// set up the query for fetching all bookmarks
|
|
68
|
+
this.#queryBookmarks = new Query({
|
|
69
|
+
client: {
|
|
70
|
+
fn: (filter?: BookmarksFilter) => {
|
|
71
|
+
return this.#api
|
|
72
|
+
.query('v1', { filter })
|
|
73
|
+
.pipe(map((res) => bookmarksSchema.parse(res)));
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
key: (args) => JSON.stringify(args ?? ''),
|
|
77
|
+
expire,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this.#queryBookmarkData = new Query({
|
|
81
|
+
client: {
|
|
82
|
+
fn: (args: { bookmarkId: string }) => {
|
|
83
|
+
return this.#api.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
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public getAllBookmarks(filter?: BookmarksFilter): ObservableInput<Bookmark[]> {
|
|
97
|
+
return this.#queryBookmarks.query(filter).pipe(map((res) => res.value as Bookmark[]));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public getBookmarkById(bookmarkId: string): ObservableInput<BookmarkWithoutData> {
|
|
101
|
+
return this.#queryBookmark.query({ bookmarkId }).pipe(map((res) => res.value));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public getBookmarkData<T extends BookmarkData>(bookmarkId: string): ObservableInput<T> {
|
|
105
|
+
return this.#queryBookmarkData.query({ bookmarkId }).pipe(map((res): T => res.value as T));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public setBookmarkData<T extends BookmarkData | null>(
|
|
109
|
+
bookmarkId: string,
|
|
110
|
+
data: T,
|
|
111
|
+
): ObservableInput<T> {
|
|
112
|
+
return this.#api.patch('v1', { bookmarkId, updates: { payload: data } }).pipe(
|
|
113
|
+
map((res) => res.payload as T),
|
|
114
|
+
tap((updatedData) => {
|
|
115
|
+
if (updatedData) {
|
|
116
|
+
this.#queryBookmarkData.mutate(
|
|
117
|
+
{ bookmarkId },
|
|
118
|
+
{ value: updatedData, updated: Date.now() },
|
|
119
|
+
{ allowCreation: true },
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public createBookmark<T extends BookmarkData>(
|
|
127
|
+
newBookmark: BookmarkNew<T>,
|
|
128
|
+
): ObservableInput<Bookmark<T>> {
|
|
129
|
+
return this.#api.create('v1', newBookmark).pipe(
|
|
130
|
+
map((response) => bookmarkWithDataSchema<T>().parse(response) as Bookmark<T>),
|
|
131
|
+
/** update the bookmark cache */
|
|
132
|
+
tap((createdBookmark) => {
|
|
133
|
+
const { payload, ...bookmark } = createdBookmark;
|
|
134
|
+
this.#queryBookmark.mutate(
|
|
135
|
+
{ bookmarkId: bookmark.id },
|
|
136
|
+
{ value: bookmark, updated: Date.now() },
|
|
137
|
+
{ allowCreation: true },
|
|
138
|
+
);
|
|
139
|
+
if (payload) {
|
|
140
|
+
this.#queryBookmarkData.mutate(
|
|
141
|
+
{ bookmarkId: bookmark.id },
|
|
142
|
+
{ value: payload, updated: Date.now() },
|
|
143
|
+
{ allowCreation: true },
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
this.#queryBookmarks.invalidate();
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public updateBookmark<T extends BookmarkData>(
|
|
152
|
+
bookmarkId: string,
|
|
153
|
+
updates: BookmarkUpdate<T>,
|
|
154
|
+
): ObservableInput<Bookmark<T>> {
|
|
155
|
+
const update$ = this.#api.patch('v1', { bookmarkId, updates: updates }).pipe(
|
|
156
|
+
map((response) => bookmarkWithDataSchema().parse(response) as Bookmark<T>),
|
|
157
|
+
shareReplay(),
|
|
158
|
+
);
|
|
159
|
+
return new Observable((subscriber) => {
|
|
160
|
+
// update the query cache for the specific bookmark
|
|
161
|
+
subscriber.add(
|
|
162
|
+
update$.subscribe((updatedBookmark) => {
|
|
163
|
+
const { payload, ...bookmark } = updatedBookmark;
|
|
164
|
+
// payload should not be included in the bookmark object
|
|
165
|
+
payload;
|
|
166
|
+
this.#queryBookmark.mutate(
|
|
167
|
+
{ bookmarkId },
|
|
168
|
+
{ value: bookmark, updated: Date.now() },
|
|
169
|
+
{ allowCreation: false },
|
|
170
|
+
);
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
// update the cache for bookmark data
|
|
175
|
+
subscriber.add(
|
|
176
|
+
update$.subscribe((updatedBookmark) => {
|
|
177
|
+
const { payload } = updatedBookmark;
|
|
178
|
+
if (payload) {
|
|
179
|
+
this.#queryBookmarkData.mutate(
|
|
180
|
+
{
|
|
181
|
+
bookmarkId: updatedBookmark.id,
|
|
182
|
+
},
|
|
183
|
+
{ value: payload, updated: Date.now() },
|
|
184
|
+
{ allowCreation: true },
|
|
185
|
+
);
|
|
186
|
+
} else {
|
|
187
|
+
const cacheKey = this.#queryBookmarkData.generateCacheKey({
|
|
188
|
+
bookmarkId: updatedBookmark.id,
|
|
189
|
+
});
|
|
190
|
+
this.#queryBookmarkData.cache.removeItem(cacheKey);
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// invalidate the bookmarks query cache
|
|
196
|
+
subscriber.add(
|
|
197
|
+
update$.subscribe(() => {
|
|
198
|
+
this.#queryBookmarks.invalidate();
|
|
199
|
+
}),
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
// emit the update to the subscriber
|
|
203
|
+
update$.subscribe(subscriber);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public deleteBookmark(bookmarkId: string): ObservableInput<boolean> {
|
|
208
|
+
return this.#api.delete('v1', { bookmarkId });
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
public addBookmarkToFavorites(bookmarkId: string): ObservableInput<boolean> {
|
|
212
|
+
return this.#api
|
|
213
|
+
.addFavourite('v1', { bookmarkId })
|
|
214
|
+
.pipe(tap(() => this.#queryBookmarks.invalidate()));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public removeBookmarkFromFavorites(bookmarkId: string): ObservableInput<boolean> {
|
|
218
|
+
return this.#api
|
|
219
|
+
.removeFavourite('v1', { bookmarkId })
|
|
220
|
+
.pipe(tap(() => this.#queryBookmarks.invalidate()));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public isBookmarkFavorite(bookmarkId: string): ObservableInput<boolean> {
|
|
224
|
+
return this.#api.isFavorite('v1', { bookmarkId });
|
|
225
|
+
}
|
|
226
|
+
}
|