Skip to content

Commit 9550453

Browse files
committed
chore: review circular dependencies
1 parent 6345c60 commit 9550453

File tree

9 files changed

+96
-113
lines changed

9 files changed

+96
-113
lines changed

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/app-shell-services/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"clean": "npx rimraf dist package",
2121
"prepublishOnly": "npm run build && npx clean-publish"
2222
},
23+
"dependencies": {
24+
"@hitachivantara/app-shell-shared": "^1.6.1"
25+
},
2326
"peerDependencies": {
2427
"react": "^18.2.0"
2528
},

packages/app-shell-services/src/hooks/Hooks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useCallback } from "react";
22

3+
import { ServiceId } from "../types/config";
34
import {
4-
ServiceId,
55
ServiceReference,
66
UseGetServiceReferenceOptions,
77
UseGetServiceReferencesOptions,

packages/app-shell-services/src/hooks/useServiceManager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { useMemo } from "react";
22
import { useHvAppShellConfig } from "@hitachivantara/app-shell-shared";
33

4+
import { ServiceId, ServicesConfig } from "../types/config";
45
import {
56
GetServiceBaseOptions,
67
GetServiceOptions,
78
GetServiceReferenceOptions,
89
GetServiceReferencesOptions,
910
GetServicesOptions,
10-
ServiceId,
1111
ServiceManager,
1212
ServiceReference,
13-
ServicesConfig,
1413
ServicesResult,
1514
} from "../types/service";
1615
import { createServiceReference } from "../utils/serviceReference";

packages/app-shell-services/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export type * from "./types/service";
22
export type * from "./types/async";
3+
export type * from "./types/config";
34
export { SERVICES_ERROR_HANDLING } from "./utils/serviceUtil";
45

56
export {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Re-export the services related App Shell configuration types
2+
// This removes the need to install app-shell-shared and avoids circular dependencies
3+
export type {
4+
HvAppShellServicesConfig as ServicesConfig,
5+
HvAppShellServiceId as ServiceId,
6+
HvAppShellServiceProviderConfig as ServiceProviderConfig,
7+
HvAppShellInstanceServiceProviderConfig as InstanceServiceProviderConfig,
8+
HvAppShellInstanceBundleServiceProviderConfig as InstanceBundleServiceProviderConfig,
9+
HvAppShellFactoryBundleServiceProviderConfig as FactoryBundleServiceProviderConfig,
10+
HvAppShellComponentBundleServiceProviderConfig as ComponentBundleServiceProviderConfig,
11+
HvAppShellServiceProviderConfigBase as ServiceProviderConfigBase,
12+
HvAppShellServiceManagerAttributes as ServiceManagerAttributes,
13+
HvAppShellServiceProviderAttributeName as ServiceProviderAttributeName,
14+
HvAppShellStandardServiceProviderAttributeName as StandardServiceProviderAttributeName,
15+
HvAppShellServiceFactoryConfig as ServiceFactoryConfig,
16+
} from "@hitachivantara/app-shell-shared";

packages/app-shell-services/src/types/service.ts

Lines changed: 5 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { SERVICES_ERROR_HANDLING } from "../utils/serviceUtil";
22
import { UseAsyncResult } from "./async";
3+
import {
4+
ServiceFactoryConfig,
5+
ServiceId,
6+
ServiceManagerAttributes,
7+
} from "./config";
38

49
export type ServiceManager = {
510
/**
@@ -77,18 +82,6 @@ export type ServiceManager = {
7782
): Promise<ServicesResult<TService>>;
7883
};
7984

80-
/**
81-
* Maps a service ID to an array of service provider configurations.
82-
* Used to register multiple providers for a single service.
83-
*/
84-
export type ServicesConfig = Record<ServiceId, ServiceProviderConfig[]>;
85-
86-
/**
87-
* Unique identifier for a service.
88-
* Used to reference and retrieve services.
89-
*/
90-
export type ServiceId = string; // NOSONAR
91-
9285
/**
9386
* Base options for service retrieval operations.
9487
* Used as a foundation for more specific service option types.
@@ -132,18 +125,6 @@ export type GetServiceReferenceOptions = GetServiceBaseOptions; // NOSONAR
132125
*/
133126
export type GetServiceReferencesOptions = GetServiceBaseOptions; // NOSONAR
134127

135-
/**
136-
* Standard attribute names for service providers.
137-
*/
138-
export type StandardServiceProviderAttributeName = "ranking";
139-
140-
/**
141-
* Attribute names for service providers which can be the standard names or custom ones for provider metadata.
142-
*/
143-
export type ServiceProviderAttributeName =
144-
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
145-
StandardServiceProviderAttributeName | string;
146-
147128
/**
148129
* Result of a service retrieval operation.
149130
* Contains the successfully loaded services and all errors that happened.
@@ -153,12 +134,6 @@ export type ServicesResult<TService> = {
153134
errors: Error[];
154135
};
155136

156-
/**
157-
* Configuration object for a service factory.
158-
* Used to provide initialization parameters to service factories.
159-
*/
160-
export type ServiceFactoryConfig = Record<string, unknown>;
161-
162137
/**
163138
* Factory function type for creating a service instance.
164139
* Accepts an optional configuration object.
@@ -167,82 +142,6 @@ export type ServiceFactory<TService> = (
167142
config?: ServiceFactoryConfig,
168143
) => TService;
169144

170-
/**
171-
* Attributes for service manager and providers.
172-
* Used for filtering and selecting service providers.
173-
*/
174-
export type ServiceManagerAttributes = Record<
175-
ServiceProviderAttributeName,
176-
unknown
177-
>;
178-
179-
/**
180-
* Union type for all supported service provider configuration shapes.
181-
* Used to describe a given service implementation provided.
182-
*/
183-
export type ServiceProviderConfig =
184-
| InstanceServiceProviderConfig
185-
| InstanceBundleServiceProviderConfig
186-
| FactoryBundleServiceProviderConfig
187-
| ComponentBundleServiceProviderConfig;
188-
189-
/**
190-
* Common properties for all service provider configurations.
191-
*
192-
* These properties are shared by all service provider configuration shapes.
193-
* A provider config describes how a given service implementation should be resolved by the service manager at runtime (e.g. a direct instance, a bundle exporting an instance or factory, or a React component to be wrapped).
194-
*
195-
* @property {number} [ranking] Optional numeric ranking used to order providers when multiple implement the same service. Higher values have higher precedence. Defaults to 0.
196-
* @property {ServiceManagerAttributes} [attributes] Arbitrary metadata for querying and filtering providers. Either standard attribute names or arbitrary which are also supported.
197-
*
198-
* @see ServiceManagerAttributes
199-
*/
200-
export type ServiceProviderConfigBase = {
201-
ranking?: number;
202-
203-
attributes?: ServiceManagerAttributes;
204-
};
205-
206-
/**
207-
* A provider config describing a concrete service instance.
208-
*
209-
* Precedence: when an `instance` property is present it takes precedence over `bundle` and `factory` providers for the same service id. The instance value is used as-is as the provided service.
210-
*/
211-
export type InstanceServiceProviderConfig = ServiceProviderConfigBase & {
212-
instance: unknown;
213-
};
214-
215-
/**
216-
* A provider config that points to a bundle whose default export is a concrete service instance, dynamically imported by the service loader.
217-
*
218-
* Precedence: this form has precedence over `factory`-based providers when multiple providers are registered for the same service id.
219-
*/
220-
export type InstanceBundleServiceProviderConfig = ServiceProviderConfigBase & {
221-
bundle: string;
222-
};
223-
224-
/**
225-
* A provider config that points to a bundle default exporting a service factory. The factory will be invoked with the provided `config` object to obtain the service instance.
226-
*/
227-
export type FactoryBundleServiceProviderConfig = ServiceProviderConfigBase & {
228-
factory: {
229-
bundle: string;
230-
231-
config?: ServiceFactoryConfig;
232-
};
233-
};
234-
235-
/**
236-
* A provider config that points to a bundle exporting a React component as its default export. The service manager will automatically wrap the component so it can be used as a service; the `props` object will be provided as the component's static props at creation time.
237-
*/
238-
export type ComponentBundleServiceProviderConfig = ServiceProviderConfigBase & {
239-
component: {
240-
bundle: string;
241-
242-
props?: Record<string, unknown>;
243-
};
244-
};
245-
246145
/**
247146
* Loader function type for asynchronously loading a service.
248147
* Returns a promise resolving to the service instance.

packages/app-shell-services/src/utils/serviceReference.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import {
55
FactoryBundleServiceProviderConfig,
66
InstanceBundleServiceProviderConfig,
77
InstanceServiceProviderConfig,
8-
ServiceFactory,
98
ServiceId,
10-
ServiceLoader,
119
ServiceProviderConfig,
1210
ServiceProviderConfigBase,
11+
} from "../types/config";
12+
import {
13+
ServiceFactory,
14+
ServiceLoader,
1315
ServiceReference,
1416
} from "../types/service";
1517

packages/app-shell-shared/src/types/Config.ts

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { ServicesConfig } from "@hitachivantara/app-shell-services";
21
import type { HvContainerProps } from "@hitachivantara/uikit-react-core";
32

43
type ViewHvContainerProps = Omit<HvContainerProps, "children">;
@@ -47,6 +46,67 @@ export type HvAppShellProvidersConfig = {
4746
config?: Record<string, unknown>;
4847
};
4948

49+
// region Services types
50+
export type HvAppShellServicesConfig = Record<
51+
HvAppShellServiceId,
52+
HvAppShellServiceProviderConfig[]
53+
>;
54+
55+
export type HvAppShellServiceId = string; //NOSONAR
56+
57+
export type HvAppShellServiceProviderConfig =
58+
| HvAppShellInstanceServiceProviderConfig
59+
| HvAppShellInstanceBundleServiceProviderConfig
60+
| HvAppShellFactoryBundleServiceProviderConfig
61+
| HvAppShellComponentBundleServiceProviderConfig;
62+
63+
export type HvAppShellServiceProviderConfigBase = {
64+
ranking?: number;
65+
66+
attributes?: HvAppShellServiceManagerAttributes;
67+
};
68+
69+
export type HvAppShellServiceManagerAttributes = Record<
70+
HvAppShellServiceProviderAttributeName,
71+
unknown
72+
>;
73+
74+
export type HvAppShellStandardServiceProviderAttributeName = "ranking";
75+
export type HvAppShellServiceProviderAttributeName =
76+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
77+
HvAppShellStandardServiceProviderAttributeName | string;
78+
79+
export type HvAppShellInstanceServiceProviderConfig =
80+
HvAppShellServiceProviderConfigBase & {
81+
instance: unknown;
82+
};
83+
84+
export type HvAppShellInstanceBundleServiceProviderConfig =
85+
HvAppShellServiceProviderConfigBase & {
86+
bundle: string;
87+
};
88+
89+
export type HvAppShellFactoryBundleServiceProviderConfig =
90+
HvAppShellServiceProviderConfigBase & {
91+
factory: {
92+
bundle: string;
93+
94+
config?: HvAppShellServiceFactoryConfig;
95+
};
96+
};
97+
98+
export type HvAppShellServiceFactoryConfig = Record<string, unknown>;
99+
100+
export type HvAppShellComponentBundleServiceProviderConfig =
101+
HvAppShellServiceProviderConfigBase & {
102+
component: {
103+
bundle: string;
104+
105+
props?: Record<string, unknown>;
106+
};
107+
};
108+
// endregion
109+
50110
export type HvAppShellConfig = {
51111
baseUrl?: string;
52112
name?: string;
@@ -59,7 +119,7 @@ export type HvAppShellConfig = {
59119
theming?: HvAppShellThemingConfig;
60120
header?: HvAppShellHeader;
61121
providers?: HvAppShellProvidersConfig[];
62-
services?: ServicesConfig;
122+
services?: HvAppShellServicesConfig;
63123
};
64124

65125
export type HvAppShellThemingConfig = {

0 commit comments

Comments
 (0)