@openmrs/esm-config 6.3.1-pre.3106 → 6.3.1-pre.3124

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,3 @@
1
- [0] Successfully compiled: 8 files with swc (233.45ms)
1
+ [0] Successfully compiled: 8 files with swc (210.06ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
@@ -254,7 +254,9 @@ export function provide(config, sourceName = 'provided') {
254
254
  'Translation overrides'
255
255
  ], state.config);
256
256
  resolve(config);
257
- unsubscribe && unsubscribe();
257
+ if (unsubscribe) {
258
+ unsubscribe();
259
+ }
258
260
  }
259
261
  }
260
262
  update(store.getState());
@@ -269,7 +271,9 @@ export function provide(config, sourceName = 'provided') {
269
271
  if (state.translationOverridesLoaded && state.config) {
270
272
  const translationOverrides = state.config['Translation overrides'] ?? {};
271
273
  resolve(translationOverrides);
272
- unsubscribe && unsubscribe();
274
+ if (unsubscribe) {
275
+ unsubscribe();
276
+ }
273
277
  }
274
278
  }
275
279
  update(configStore.getState());
@@ -283,7 +287,9 @@ export function provide(config, sourceName = 'provided') {
283
287
  if (state.loaded && state.config) {
284
288
  const translationOverrides = state.config['Translation overrides'] ?? {};
285
289
  resolve(translationOverrides);
286
- unsubscribe && unsubscribe();
290
+ if (unsubscribe) {
291
+ unsubscribe();
292
+ }
287
293
  }
288
294
  }
289
295
  update(configStore.getState());
@@ -624,6 +630,7 @@ function validateArrayStructure(arraySchema, value, keyPath) {
624
630
  * @returns true if validation passes, false otherwise
625
631
  */ function checkType(keyPath, _type, value) {
626
632
  if (_type) {
633
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
627
634
  const validator = {
628
635
  Array: isArray,
629
636
  Boolean: isBoolean,
@@ -644,7 +651,8 @@ function validateArrayStructure(arraySchema, value, keyPath) {
644
651
  /**
645
652
  * Runs validators, logging errors.
646
653
  * @returns true if all pass, false otherwise.
647
- */ function runValidators(keyPath, validators, value) {
654
+ */ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
655
+ function runValidators(keyPath, validators, value) {
648
656
  let returnValue = true;
649
657
  if (validators) {
650
658
  try {
@@ -1,5 +1,5 @@
1
1
  import { type StoreApi } from 'zustand';
2
- import type { Config, ConfigObject, ConfigSchema, ExtensionSlotConfigObject, ProvidedConfig } from '../types';
2
+ import type { Config, ConfigObject, ConfigSchema, ExtensionSlotConfig, ProvidedConfig } from '../types';
3
3
  /**
4
4
  * Internal store
5
5
  * A store of the inputs and internal state
@@ -70,7 +70,7 @@ export declare function getConfigStore(moduleName: string): StoreApi<ConfigStore
70
70
  export interface ExtensionSlotsConfigStore {
71
71
  slots: {
72
72
  [slotName: string]: {
73
- config: ExtensionSlotConfigObject;
73
+ config: ExtensionSlotConfig;
74
74
  loaded: boolean;
75
75
  };
76
76
  };
@@ -79,12 +79,12 @@ export interface ExtensionSlotsConfigStore {
79
79
  export declare function getExtensionSlotsConfigStore(): StoreApi<ExtensionSlotsConfigStore>;
80
80
  /** @internal */
81
81
  export declare function getExtensionSlotConfig(slotName: string): {
82
- config: ExtensionSlotConfigObject;
82
+ config: ExtensionSlotConfig;
83
83
  loaded: boolean;
84
84
  };
85
85
  /** @internal */
86
86
  export declare function getExtensionSlotConfigFromStore(state: ExtensionSlotsConfigStore, slotName: string): {
87
- config: ExtensionSlotConfigObject;
87
+ config: ExtensionSlotConfig;
88
88
  loaded: boolean;
89
89
  };
90
90
  /** @internal */
@@ -104,6 +104,8 @@ export declare function getExtensionsConfigStore(): StoreApi<ExtensionsConfigSto
104
104
  export declare function getExtensionConfig(slotName: string, extensionId: string): StoreApi<Omit<ConfigStore, 'translationOverridesLoaded'>>;
105
105
  /** @internal */
106
106
  export declare function getExtensionConfigFromStore(state: ExtensionsConfigStore, slotName: string, extensionId: string): ConfigStore;
107
+ /** @internal */
108
+ export declare function getExtensionConfigFromExtensionSlotStore(state: ExtensionSlotConfig, slotName: string, extensionId: string): object | null;
107
109
  /**
108
110
  * A store of the implementer tools output config
109
111
  * @internal
@@ -111,6 +111,10 @@ function initializeConfigStore() {
111
111
  config: null
112
112
  };
113
113
  }
114
+ /** @internal */ export function getExtensionConfigFromExtensionSlotStore(state, slotName, extensionId) {
115
+ const extensionConfig = state.configure?.[extensionId];
116
+ return extensionConfig ?? null;
117
+ }
114
118
  /** @internal */ export const implementerToolsConfigStore = createGlobalStore('config-implementer-tools', {
115
119
  config: {}
116
120
  });
package/dist/types.d.ts CHANGED
@@ -38,22 +38,17 @@ export interface DisplayConditionsConfigObject {
38
38
  }
39
39
  export type ConfigValue = string | number | boolean | void | Array<any> | object;
40
40
  export interface ExtensionSlotConfig {
41
+ /** Additional extension IDs to assign to this slot, in addition to those `attach`ed in code. */
41
42
  add?: Array<string>;
43
+ /** Extension IDs which were `attach`ed to the slot but which should not be assigned. */
42
44
  remove?: Array<string>;
45
+ /** Overrides the default ordering of extensions. */
43
46
  order?: Array<string>;
44
47
  configure?: ExtensionSlotConfigureValueObject;
45
48
  }
46
49
  export interface ExtensionSlotConfigureValueObject {
47
50
  [key: string]: object;
48
51
  }
49
- export interface ExtensionSlotConfigObject {
50
- /** Additional extension IDs to assign to this slot, in addition to those `attach`ed in code. */
51
- add?: Array<string>;
52
- /** Extension IDs which were `attach`ed to the slot but which should not be assigned. */
53
- remove?: Array<string>;
54
- /** Overrides the default ordering of extensions. */
55
- order?: Array<string>;
56
- }
57
52
  export type ProvidedConfig = {
58
53
  source: string;
59
54
  config: Config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-config",
3
- "version": "6.3.1-pre.3106",
3
+ "version": "6.3.1-pre.3124",
4
4
  "license": "MPL-2.0",
5
5
  "description": "A configuration library for the OpenMRS Single-Spa framework.",
6
6
  "type": "module",
@@ -61,9 +61,9 @@
61
61
  "single-spa": "6.x"
62
62
  },
63
63
  "devDependencies": {
64
- "@openmrs/esm-globals": "6.3.1-pre.3106",
65
- "@openmrs/esm-state": "6.3.1-pre.3106",
66
- "@openmrs/esm-utils": "6.3.1-pre.3106",
64
+ "@openmrs/esm-globals": "6.3.1-pre.3124",
65
+ "@openmrs/esm-state": "6.3.1-pre.3124",
66
+ "@openmrs/esm-utils": "6.3.1-pre.3124",
67
67
  "@swc/cli": "^0.7.7",
68
68
  "@swc/core": "^1.11.29",
69
69
  "@types/ramda": "^0.26.44",
@@ -1,6 +1,6 @@
1
1
  /** @module @category Config */
2
2
  import { clone, reduce, mergeDeepRight, equals, omit } from 'ramda';
3
- import type { Config, ConfigObject, ConfigSchema, ExtensionSlotConfig, ExtensionSlotConfigObject } from '../types';
3
+ import type { Config, ConfigObject, ConfigSchema, ExtensionSlotConfig } from '../types';
4
4
  import { Type } from '../types';
5
5
  import { isArray, isBoolean, isUuid, isNumber, isObject, isString } from '../validators/type-validators';
6
6
  import { validator } from '../validators/validator';
@@ -281,7 +281,10 @@ export function getConfig<T = Record<string, any>>(moduleName: string): Promise<
281
281
  if (state.loaded && state.config) {
282
282
  const config = omit(['Display conditions', 'Translation overrides'], state.config);
283
283
  resolve(config as T);
284
- unsubscribe && unsubscribe();
284
+
285
+ if (unsubscribe) {
286
+ unsubscribe();
287
+ }
285
288
  }
286
289
  }
287
290
  update(store.getState());
@@ -302,7 +305,10 @@ export function getTranslationOverrides(
302
305
  if (state.translationOverridesLoaded && state.config) {
303
306
  const translationOverrides = state.config['Translation overrides'] ?? {};
304
307
  resolve(translationOverrides);
305
- unsubscribe && unsubscribe();
308
+
309
+ if (unsubscribe) {
310
+ unsubscribe();
311
+ }
306
312
  }
307
313
  }
308
314
  update(configStore.getState());
@@ -318,7 +324,10 @@ export function getTranslationOverrides(
318
324
  if (state.loaded && state.config) {
319
325
  const translationOverrides = state.config['Translation overrides'] ?? {};
320
326
  resolve(translationOverrides);
321
- unsubscribe && unsubscribe();
327
+
328
+ if (unsubscribe) {
329
+ unsubscribe();
330
+ }
322
331
  }
323
332
  }
324
333
  update(configStore.getState());
@@ -431,7 +440,7 @@ function createValuesAndSourcesTree(config: ConfigObject, source: string) {
431
440
  function getExtensionSlotConfigs(
432
441
  configState: ConfigInternalStore,
433
442
  tempConfigState: TemporaryConfigStore,
434
- ): Record<string, ExtensionSlotConfigObject> {
443
+ ): Record<string, ExtensionSlotConfig> {
435
444
  const allConfigs = mergeConfigs(getProvidedConfigs(configState, tempConfigState));
436
445
  const slotConfigPerModule: Record<string, Record<string, ExtensionSlotConfig>> = Object.keys(allConfigs).reduce(
437
446
  (obj, key) => {
@@ -715,6 +724,7 @@ function runAllValidatorsInConfigTree(schema: ConfigSchema, config: ConfigObject
715
724
  */
716
725
  function checkType(keyPath: string, _type: Type | undefined, value: any) {
717
726
  if (_type) {
727
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
718
728
  const validator: Record<string, Function> = {
719
729
  Array: isArray,
720
730
  Boolean: isBoolean,
@@ -735,6 +745,7 @@ function checkType(keyPath: string, _type: Type | undefined, value: any) {
735
745
  * Runs validators, logging errors.
736
746
  * @returns true if all pass, false otherwise.
737
747
  */
748
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
738
749
  function runValidators(keyPath: string, validators: Array<Function> | undefined, value: any) {
739
750
  let returnValue = true;
740
751
  if (validators) {
@@ -811,7 +822,7 @@ const setDefaults = (schema: ConfigSchema, inputConfig: Config) => {
811
822
  return config;
812
823
  };
813
824
 
814
- function hasObjectSchema(elementsSchema: Object | undefined): elementsSchema is ConfigSchema {
825
+ function hasObjectSchema(elementsSchema: unknown): elementsSchema is ConfigSchema {
815
826
  return (
816
827
  !!elementsSchema && Object.keys(elementsSchema).filter((e) => !['_default', '_validators'].includes(e)).length > 0
817
828
  );
@@ -2,7 +2,7 @@
2
2
  import { createGlobalStore, getGlobalStore } from '@openmrs/esm-state';
3
3
  import { shallowEqual } from '@openmrs/esm-utils';
4
4
  import { type StoreApi } from 'zustand';
5
- import type { Config, ConfigObject, ConfigSchema, ExtensionSlotConfigObject, ProvidedConfig } from '../types';
5
+ import type { Config, ConfigObject, ConfigSchema, ExtensionSlotConfig, ProvidedConfig } from '../types';
6
6
 
7
7
  /**
8
8
  * Internal store
@@ -123,7 +123,7 @@ export function getConfigStore(moduleName: string) {
123
123
  export interface ExtensionSlotsConfigStore {
124
124
  slots: {
125
125
  [slotName: string]: {
126
- config: ExtensionSlotConfigObject;
126
+ config: ExtensionSlotConfig;
127
127
  loaded: boolean;
128
128
  };
129
129
  };
@@ -235,6 +235,16 @@ export function getExtensionConfigFromStore(state: ExtensionsConfigStore, slotNa
235
235
  return extensionConfig ?? { loaded: false, config: null };
236
236
  }
237
237
 
238
+ /** @internal */
239
+ export function getExtensionConfigFromExtensionSlotStore(
240
+ state: ExtensionSlotConfig,
241
+ slotName: string,
242
+ extensionId: string,
243
+ ) {
244
+ const extensionConfig = state.configure?.[extensionId];
245
+ return extensionConfig ?? null;
246
+ }
247
+
238
248
  /**
239
249
  * A store of the implementer tools output config
240
250
  * @internal
package/src/types.ts CHANGED
@@ -46,8 +46,11 @@ export interface DisplayConditionsConfigObject {
46
46
  export type ConfigValue = string | number | boolean | void | Array<any> | object;
47
47
 
48
48
  export interface ExtensionSlotConfig {
49
+ /** Additional extension IDs to assign to this slot, in addition to those `attach`ed in code. */
49
50
  add?: Array<string>;
51
+ /** Extension IDs which were `attach`ed to the slot but which should not be assigned. */
50
52
  remove?: Array<string>;
53
+ /** Overrides the default ordering of extensions. */
51
54
  order?: Array<string>;
52
55
  configure?: ExtensionSlotConfigureValueObject;
53
56
  }
@@ -56,15 +59,6 @@ export interface ExtensionSlotConfigureValueObject {
56
59
  [key: string]: object;
57
60
  }
58
61
 
59
- export interface ExtensionSlotConfigObject {
60
- /** Additional extension IDs to assign to this slot, in addition to those `attach`ed in code. */
61
- add?: Array<string>;
62
- /** Extension IDs which were `attach`ed to the slot but which should not be assigned. */
63
- remove?: Array<string>;
64
- /** Overrides the default ordering of extensions. */
65
- order?: Array<string>;
66
- }
67
-
68
62
  export type ProvidedConfig = {
69
63
  source: string;
70
64
  config: Config;