@quandis/qbo4.ui 4.0.1-CI-20240429-215003 → 4.0.1-CI-20240429-225952

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Quandis, Inc.",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "version": "4.0.1-CI-20240429-215003",
6
+ "version": "4.0.1-CI-20240429-225952",
7
7
  "workspaces": [
8
8
  "code"
9
9
  ],
package/readme.md CHANGED
@@ -69,7 +69,6 @@ In this example, the `qms` is cloned in `getApiService`, and the `relativePath`
69
69
  You can write your own `IApiService` class, and register it to qbo's DI container:
70
70
 
71
71
  ```typescript
72
- import { services } from "@quandis/qbo4.logging";
73
72
  import { services, IApiService } from "@quandis/qbo4.ui";
74
73
 
75
74
  @injectable()
@@ -13,6 +13,7 @@ export interface IApiService {
13
13
  * @param payload The payload to send to the API.
14
14
  */
15
15
  fetch(relativePath: string | null, payload: Record<string, string> | null): Promise<any>;
16
+ clone(relativePath: string | null): IApiService;
16
17
  }
17
18
  /**
18
19
  * Define a token for the IApiService interface
@@ -16,6 +16,9 @@ export interface IApiService {
16
16
  * @param payload The payload to send to the API.
17
17
  */
18
18
  fetch(relativePath: string | null, payload: Record<string, string> | null): Promise<any>;
19
+
20
+
21
+ clone(relativePath: string | null): IApiService;
19
22
  }
20
23
 
21
24
  /**
@@ -116,10 +116,5 @@ export function getApiService(url) {
116
116
  const service = services.container.isRegistered(name)
117
117
  ? services.container.resolve(name)
118
118
  : new RestApiService(url);
119
- if (relativePath) {
120
- const clone = structuredClone(service);
121
- clone.relativePath = relativePath;
122
- return clone;
123
- }
124
- return service;
119
+ return (relativePath) ? service.clone(relativePath) : service;
125
120
  }
@@ -125,10 +125,5 @@ export function getApiService(url: string) {
125
125
  ? services.container.resolve<IApiService>(name)
126
126
  : new RestApiService(url);
127
127
 
128
- if (relativePath) {
129
- const clone = structuredClone(service);
130
- clone.relativePath = relativePath;
131
- return clone;
132
- }
133
- return service;
128
+ return (relativePath) ? service.clone(relativePath) : service;
134
129
  }
@@ -6,5 +6,6 @@ export declare class RestApiService implements IApiService {
6
6
  relativePath: string;
7
7
  constructor(apiEndpoint: string, headers?: HeadersInit, method?: string | null);
8
8
  fetch(relativePath: string | null, payload?: Record<string, string> | null): Promise<any>;
9
+ clone(relativePath: string | null): IApiService;
9
10
  }
10
11
  export declare function registerRestApi(name: string, apiEndpoint: string, headers?: HeadersInit, method?: string | null): void;
@@ -24,6 +24,11 @@ export class RestApiService {
24
24
  }
25
25
  return response.json();
26
26
  }
27
+ clone(relativePath) {
28
+ const clone = new RestApiService(this.apiEndpoint, this.headers, this.method);
29
+ clone.relativePath = relativePath ?? '';
30
+ return clone;
31
+ }
27
32
  }
28
33
  // Register a RestApiService with the default name 'default' and the base URL of the current page
29
34
  services.container.registerInstance('default', new RestApiService(document.querySelector('base[href]')?.getAttribute('href') || window.location.origin));
@@ -35,6 +35,12 @@ export class RestApiService implements IApiService {
35
35
 
36
36
  return response.json();
37
37
  }
38
+
39
+ clone(relativePath: string | null): IApiService {
40
+ const clone = new RestApiService(this.apiEndpoint, this.headers, this.method);
41
+ clone.relativePath = relativePath ?? '';
42
+ return clone;
43
+ }
38
44
  }
39
45
 
40
46
  // Register a RestApiService with the default name 'default' and the base URL of the current page