@openmrs/esm-config 3.2.1-pre.986 → 3.3.1-pre.1173
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/.turbo/turbo-build.log +10 -0
- package/dist/openmrs-esm-module-config.js +1 -1
- package/dist/openmrs-esm-module-config.js.map +1 -1
- package/jest.config.js +3 -0
- package/package.json +4 -4
- package/src/module-config/module-config.test.ts +131 -73
- package/src/module-config/module-config.ts +115 -41
- package/src/module-config/state.ts +59 -22
- package/src/navigation/interpolate-string.ts +2 -2
- package/src/navigation/navigate.ts +1 -1
- package/src/public.ts +12 -0
- package/src/types.ts +1 -0
- package/src/validators/type-validators.ts +1 -1
- package/src/validators/validator.ts +1 -0
- package/src/validators/validators.ts +1 -0
- package/webpack.config.js +1 -1
- package/.babelrc +0 -8
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @module @category Config */
|
|
1
2
|
import { createGlobalStore, getGlobalStore } from "@openmrs/esm-state";
|
|
2
3
|
import {
|
|
3
4
|
Config,
|
|
@@ -109,7 +110,7 @@ export interface ConfigExtensionStoreElement {
|
|
|
109
110
|
|
|
110
111
|
/** @internal */
|
|
111
112
|
export const configExtensionStore = createGlobalStore<ConfigExtensionStore>(
|
|
112
|
-
"config-
|
|
113
|
+
"config-store-of-extension-state",
|
|
113
114
|
{ mountedExtensions: [] }
|
|
114
115
|
);
|
|
115
116
|
|
|
@@ -141,42 +142,78 @@ export function getConfigStore(moduleName: string) {
|
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
/**
|
|
144
|
-
* Configuration for
|
|
145
|
+
* Configuration for all the specific extension slots
|
|
145
146
|
* @internal
|
|
146
147
|
*/
|
|
147
|
-
export interface
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
export interface ExtensionSlotsConfigStore {
|
|
149
|
+
slots: {
|
|
150
|
+
[slotName: string]: {
|
|
151
|
+
config: ExtensionSlotConfigObject;
|
|
152
|
+
loaded: boolean;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
150
155
|
}
|
|
151
156
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
157
|
+
/** @internal */
|
|
158
|
+
export function getExtensionSlotsConfigStore() {
|
|
159
|
+
return getGlobalStore<ExtensionSlotsConfigStore>(`config-extension-slots`, {
|
|
160
|
+
slots: {},
|
|
161
|
+
});
|
|
157
162
|
}
|
|
158
163
|
|
|
159
164
|
/** @internal */
|
|
160
|
-
export function
|
|
161
|
-
return
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
export function getExtensionSlotConfig(slotName: string) {
|
|
166
|
+
return getExtensionSlotConfigFromStore(
|
|
167
|
+
getExtensionSlotsConfigStore().getState(),
|
|
168
|
+
slotName
|
|
164
169
|
);
|
|
165
170
|
}
|
|
166
171
|
|
|
172
|
+
/** @internal */
|
|
173
|
+
export function getExtensionSlotConfigFromStore(
|
|
174
|
+
state: ExtensionSlotsConfigStore,
|
|
175
|
+
slotName: string
|
|
176
|
+
) {
|
|
177
|
+
const slotConfig = state.slots[slotName];
|
|
178
|
+
return slotConfig ?? { loaded: false, config: {} };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** @internal */
|
|
182
|
+
export interface ExtensionsConfigStore {
|
|
183
|
+
configs: {
|
|
184
|
+
[slotName: string]: {
|
|
185
|
+
[extensionId: string]: ConfigStore;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
167
190
|
/**
|
|
168
|
-
*
|
|
191
|
+
* One store for all the extensions
|
|
169
192
|
* @internal
|
|
170
193
|
*/
|
|
171
|
-
export function
|
|
172
|
-
|
|
173
|
-
|
|
194
|
+
export function getExtensionsConfigStore() {
|
|
195
|
+
return getGlobalStore<ExtensionsConfigStore>(`config-extensions`, {
|
|
196
|
+
configs: {},
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** @internal */
|
|
201
|
+
export function getExtensionConfig(slotName: string, extensionId: string) {
|
|
202
|
+
return getExtensionConfigFromStore(
|
|
203
|
+
getExtensionsConfigStore().getState(),
|
|
204
|
+
slotName,
|
|
205
|
+
extensionId
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** @internal */
|
|
210
|
+
export function getExtensionConfigFromStore(
|
|
211
|
+
state: ExtensionsConfigStore,
|
|
212
|
+
slotName: string,
|
|
174
213
|
extensionId: string
|
|
175
214
|
) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
initializeConfigStore()
|
|
179
|
-
);
|
|
215
|
+
const extensionConfig = state.configs[slotName]?.[extensionId];
|
|
216
|
+
return extensionConfig ?? { loaded: false, config: null };
|
|
180
217
|
}
|
|
181
218
|
|
|
182
219
|
/**
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** @module @category Navigation */
|
|
2
|
+
|
|
1
3
|
function trimTrailingSlash(str: string) {
|
|
2
4
|
return str.replace(/\/$/, "");
|
|
3
5
|
}
|
|
@@ -9,7 +11,6 @@ function trimTrailingSlash(str: string) {
|
|
|
9
11
|
* parameters in configurable URLs.
|
|
10
12
|
*
|
|
11
13
|
* @param template A string to interpolate
|
|
12
|
-
* @category Navigation
|
|
13
14
|
*/
|
|
14
15
|
export function interpolateUrl(template: string): string {
|
|
15
16
|
const openmrsSpaBase = trimTrailingSlash(window.getOpenmrsSpaBase());
|
|
@@ -36,7 +37,6 @@ export function interpolateUrl(template: string): string {
|
|
|
36
37
|
*
|
|
37
38
|
* @param template With optional params wrapped in `${ }`
|
|
38
39
|
* @param params Values to interpolate into the string template
|
|
39
|
-
* @category Navigation
|
|
40
40
|
*/
|
|
41
41
|
export function interpolateString(template: string, params: object): string {
|
|
42
42
|
const names = Object.keys(params);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @module @category Navigation */
|
|
1
2
|
import { navigateToUrl } from "single-spa";
|
|
2
3
|
import { interpolateUrl } from "./interpolate-string";
|
|
3
4
|
import type {} from "@openmrs/esm-globals";
|
|
@@ -24,7 +25,6 @@ export interface NavigateOptions {
|
|
|
24
25
|
* @param to The target path or URL. Supports templating with 'openmrsBase' and 'openmrsSpaBase'.
|
|
25
26
|
* For example, `${openmrsSpaBase}/home` will resolve to `/openmrs/spa/home`
|
|
26
27
|
* for implementations using the standard OpenMRS and SPA base paths.
|
|
27
|
-
* @category Navigation
|
|
28
28
|
*/
|
|
29
29
|
export function navigate({ to }: NavigateOptions): void {
|
|
30
30
|
const openmrsSpaBase = trimTrailingSlash(window.getOpenmrsSpaBase());
|
package/src/public.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./navigation/interpolate-string";
|
|
3
|
+
export * from "./navigation/navigate";
|
|
4
|
+
export * from "./validators/validator";
|
|
5
|
+
export * from "./validators/validators";
|
|
6
|
+
export {
|
|
7
|
+
defineConfigSchema,
|
|
8
|
+
defineExtensionConfigSchema,
|
|
9
|
+
provide,
|
|
10
|
+
getConfig,
|
|
11
|
+
} from "./module-config/module-config";
|
|
12
|
+
export { getConfigStore, ConfigStore } from "./module-config/state";
|
package/src/types.ts
CHANGED
|
@@ -27,7 +27,7 @@ export const isObject = validator(
|
|
|
27
27
|
|
|
28
28
|
export const isUuid = validator(
|
|
29
29
|
(val) =>
|
|
30
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-
|
|
30
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
|
31
31
|
val
|
|
32
32
|
) || /^[0-9a-f]{36}$/i.test(val),
|
|
33
33
|
"must be a valid UUID or a 36-character hexadecimal string"
|
package/webpack.config.js
CHANGED