@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.
@@ -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-extensions",
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 a specific extension slot
145
+ * Configuration for all the specific extension slots
145
146
  * @internal
146
147
  */
147
- export interface ExtensionSlotConfigStore {
148
- config: ExtensionSlotConfigObject;
149
- loaded: boolean;
148
+ export interface ExtensionSlotsConfigStore {
149
+ slots: {
150
+ [slotName: string]: {
151
+ config: ExtensionSlotConfigObject;
152
+ loaded: boolean;
153
+ };
154
+ };
150
155
  }
151
156
 
152
- function initializeExtensionSlotConfigStore() {
153
- return {
154
- config: {},
155
- loaded: false,
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 getExtensionSlotConfigStore(slotName: string) {
161
- return getGlobalStore<ExtensionSlotConfigStore>(
162
- `config-extension-slots-${slotName}`,
163
- initializeExtensionSlotConfigStore()
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
- * A store for each mounted extension's config
191
+ * One store for all the extensions
169
192
  * @internal
170
193
  */
171
- export function getExtensionConfigStore(
172
- extensionSlotModuleName: string,
173
- attachedExtensionSlotName: string,
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
- return getGlobalStore<ConfigStore>(
177
- `config-extension-${extensionSlotModuleName}-${attachedExtensionSlotName}-${extensionId}`,
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
@@ -7,6 +7,7 @@ export enum Type {
7
7
  String = "String",
8
8
  UUID = "UUID",
9
9
  PersonAttributeTypeUuid = "PersonAttributeTypeUuid",
10
+ PatientIdentifierTypeUuid = "PatientIdentifierTypeUuid",
10
11
  }
11
12
 
12
13
  // Full-powered typing for Config and Schema trees depends on being able to
@@ -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-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
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"
@@ -1,3 +1,4 @@
1
+ /** @module @category Config Validation */
1
2
  import { Validator, ValidatorFunction } from "../types";
2
3
 
3
4
  export function validator(
@@ -1,3 +1,4 @@
1
+ /** @module @category Config Validation */
1
2
  import { validator } from "./validator";
2
3
 
3
4
  /**
package/webpack.config.js CHANGED
@@ -18,7 +18,7 @@ module.exports = (env) => ({
18
18
  {
19
19
  test: /\.m?(js|ts|tsx)$/,
20
20
  exclude: /(node_modules|bower_components)/,
21
- use: "babel-loader",
21
+ use: "swc-loader",
22
22
  },
23
23
  ],
24
24
  },
package/.babelrc DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "presets": [
3
- "@babel/preset-env",
4
- "@babel/preset-typescript",
5
- "@babel/preset-react"
6
- ],
7
- "plugins": ["babel-plugin-ramda"]
8
- }