@equinor/fusion-framework-module-bookmark 2.2.1 → 3.0.1

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.
@@ -8,6 +8,7 @@ import type { IBookmarkProvider } from './BookmarkProvider.interface';
8
8
  import type { IBookmarkClient } from './BookmarkClient.interface';
9
9
 
10
10
  import { bookmarkSourceSystemSchema } from './bookmark.schemas';
11
+ import type { BookmarkModuleConfig } from './types';
11
12
 
12
13
  export const bookmarkConfigSchema = z.object({
13
14
  log: z.custom<ILogger>().optional(),
@@ -20,12 +21,8 @@ export const bookmarkConfigSchema = z.object({
20
21
  client: z.custom<IBookmarkClient>().describe('API client for interacting with bookmarks'),
21
22
  resolve: z
22
23
  .object({
23
- context: z.function().returns(z.promise(z.object({ id: z.string() }).optional())),
24
- application: z
25
- .function()
26
- .returns(
27
- z.promise(z.object({ appKey: z.string(), name: z.string().optional() }).optional()),
28
- ),
24
+ context: z.function(),
25
+ application: z.function(),
29
26
  })
30
27
  .describe('Functions for resolving context and application'),
31
28
  filters: z
@@ -37,3 +34,7 @@ export const bookmarkConfigSchema = z.object({
37
34
  .optional()
38
35
  .default({ context: false, application: false }),
39
36
  });
37
+
38
+ export const parseBookmarkConfig = (config: unknown): BookmarkModuleConfig => {
39
+ return bookmarkConfigSchema.parse(config) as BookmarkModuleConfig;
40
+ };
@@ -1,5 +1,5 @@
1
1
  import * as z from 'zod';
2
- import type { BookmarkData } from './types';
2
+ import type { Bookmark, BookmarkData } from './types';
3
3
 
4
4
  export const bookmarkUserSchema = z.object({
5
5
  id: z.string(),
@@ -42,8 +42,12 @@ export const bookmarkWithDataSchema = <
42
42
  T extends BookmarkData = BookmarkData,
43
43
  S extends z.ZodSchema<T> = z.ZodSchema<T>,
44
44
  >(
45
- schema: S = z.record(z.unknown()).or(z.string()).optional() as unknown as S,
45
+ schema: S = z.record(z.string(), z.unknown()).or(z.string()).optional() as unknown as S,
46
46
  ) =>
47
47
  bookmarkSchema.extend({
48
48
  payload: schema,
49
49
  });
50
+
51
+ export const parseBookmark = <T extends BookmarkData>(value: unknown): Bookmark<T> => {
52
+ return bookmarkWithDataSchema().parse(value) as Bookmark<T>;
53
+ };
package/src/types.ts CHANGED
@@ -1,57 +1,121 @@
1
- import type z from 'zod';
2
-
3
- import type {
4
- bookmarkContextSchema,
5
- bookmarkSchema,
6
- bookmarkSourceSystemSchema,
7
- bookmarksSchema,
8
- bookmarkUserSchema,
9
- } from './bookmark.schemas';
10
-
11
- import type { bookmarkConfigSchema } from './bookmark-config.schema';
1
+ import type { ILogger, LogLevel } from '@equinor/fusion-log';
2
+ import type { IEventModuleProvider } from '@equinor/fusion-framework-module-event';
3
+ import type { IBookmarkProvider } from './BookmarkProvider.interface';
4
+ import type { IBookmarkClient } from './BookmarkClient.interface';
12
5
 
13
6
  /**
14
7
  * Represents the source system for a bookmark.
15
8
  */
16
- export type SourceSystem = z.infer<typeof bookmarkSourceSystemSchema>;
9
+ export interface SourceSystem {
10
+ /** Unique identifier for the source system */
11
+ identifier: string;
12
+ /** Human-readable name of the source system */
13
+ name?: string | null;
14
+ /** Sub-system identifier */
15
+ subSystem?: string | null;
16
+ }
17
17
 
18
18
  /**
19
19
  * Represents the data associated with a bookmark.
20
20
  * This is a generic type that can hold any arbitrary data as a key-value map.
21
21
  */
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- export type BookmarkData = Record<string, any> | string;
22
+ export type BookmarkData = Record<string, unknown> | string;
24
23
 
25
24
  /**
26
- * Represents a collection of bookmarks.
25
+ * Represents a user associated with a bookmark.
26
+ */
27
+ export interface BookmarkUser {
28
+ /** Unique identifier for the user */
29
+ id: string;
30
+ /** Display name of the user */
31
+ name: string;
32
+ /** Email address of the user */
33
+ mail?: string;
34
+ }
35
+
36
+ /**
37
+ * Represents the context associated with a bookmark.
27
38
  */
28
- export type Bookmarks = z.infer<typeof bookmarksSchema>;
39
+ export interface BookmarkContext {
40
+ /** Unique identifier for the context */
41
+ id: string;
42
+ /** Human-readable name of the context */
43
+ name?: string;
44
+ /** Type of the context */
45
+ type?: string;
46
+ }
29
47
 
30
48
  /**
31
49
  * Represents a bookmark without any associated data.
32
50
  */
33
- export type BookmarkWithoutData = z.infer<typeof bookmarkSchema>;
51
+ export interface BookmarkWithoutData {
52
+ /** Unique identifier for the bookmark */
53
+ id: string;
54
+ /** Name of the bookmark */
55
+ name: string;
56
+ /** Application key this bookmark belongs to */
57
+ appKey: string;
58
+ /** Optional description of the bookmark */
59
+ description?: string;
60
+ /** Whether the bookmark is shared */
61
+ isShared?: boolean;
62
+ /** When the bookmark was created */
63
+ created: Date;
64
+ /** User who created the bookmark */
65
+ createdBy: BookmarkUser;
66
+ /** When the bookmark was last updated */
67
+ updated?: Date;
68
+ /** User who last updated the bookmark */
69
+ updatedBy?: BookmarkUser;
70
+ /** Context associated with the bookmark */
71
+ context?: BookmarkContext;
72
+ /** Source system information */
73
+ sourceSystem?: SourceSystem | null;
74
+ }
34
75
 
35
76
  /**
36
77
  * Represents a bookmark with associated data.
37
78
  * @template T - The type of the bookmark data.
38
79
  */
39
80
  // biome-ignore lint/suspicious/noExplicitAny: must be any to support all bookmark data types
40
- export type Bookmark<T extends BookmarkData = any> = BookmarkWithoutData & {
81
+ export interface Bookmark<T extends BookmarkData = any> extends BookmarkWithoutData {
82
+ /** Optional payload data associated with the bookmark */
41
83
  payload?: T;
42
- };
84
+ }
43
85
 
44
86
  /**
45
- * Represents the configuration options for a bookmark module.
46
- */
47
- export type BookmarkModuleConfig = z.infer<typeof bookmarkConfigSchema>;
48
-
49
- /**
50
- * Represents a user associated with a bookmark.
87
+ * Represents a collection of bookmarks.
51
88
  */
52
- export type BookmarkUser = z.infer<typeof bookmarkUserSchema>;
89
+ export type Bookmarks = BookmarkWithoutData[];
53
90
 
54
91
  /**
55
- * Represents the context associated with a bookmark.
92
+ * Represents the configuration options for a bookmark module.
56
93
  */
57
- export type bookmarkContext = z.infer<typeof bookmarkContextSchema>;
94
+ export interface BookmarkModuleConfig {
95
+ /** Optional logger instance */
96
+ log?: ILogger;
97
+ /** Optional log level */
98
+ logLevel?: LogLevel;
99
+ /** Optional event provider for handling events */
100
+ eventProvider?: IEventModuleProvider;
101
+ /** The source system for the bookmarks */
102
+ sourceSystem?: SourceSystem;
103
+ /** Parent Bookmark provider */
104
+ parent?: IBookmarkProvider | null;
105
+ /** API client for interacting with bookmarks */
106
+ client: IBookmarkClient;
107
+ /** Functions for resolving context and application */
108
+ resolve: {
109
+ /** Function to resolve the current context */
110
+ context: () => Promise<{ id: string } | undefined>;
111
+ /** Function to resolve the current application */
112
+ application: () => Promise<{ appKey: string; name?: string } | undefined>;
113
+ };
114
+ /** Flags for enabling resolving when fetching bookmarks */
115
+ filters?: {
116
+ /** Whether to filter by context */
117
+ context?: boolean;
118
+ /** Whether to filter by application */
119
+ application?: boolean;
120
+ };
121
+ }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '2.2.1';
2
+ export const version = '3.0.1';