@openmrs/esm-framework 4.3.2-pre.680 → 4.4.0

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/docs/API.md CHANGED
@@ -515,7 +515,7 @@ ___
515
515
 
516
516
  #### Index signature
517
517
 
518
- ▪ [key: `string`]: `BoundAction`
518
+ ▪ [key: `string`]: (...`args`: `any`[]) => `void`
519
519
 
520
520
  #### Defined in
521
521
 
@@ -906,11 +906,11 @@ ___
906
906
 
907
907
  ### getSessionStore
908
908
 
909
- ▸ **getSessionStore**(): `Store`<[`SessionStore`](API.md#sessionstore)\>
909
+ ▸ **getSessionStore**(): `StoreApi`<[`SessionStore`](API.md#sessionstore)\>
910
910
 
911
911
  #### Returns
912
912
 
913
- `Store`<[`SessionStore`](API.md#sessionstore)\>
913
+ `StoreApi`<[`SessionStore`](API.md#sessionstore)\>
914
914
 
915
915
  #### Defined in
916
916
 
@@ -2256,19 +2256,18 @@ ___
2256
2256
 
2257
2257
  ### getExtensionStore
2258
2258
 
2259
- ▸ **getExtensionStore**(): `Store`<[`ExtensionStore`](interfaces/ExtensionStore.md)\>
2259
+ ▸ **getExtensionStore**(): `StoreApi`<[`ExtensionStore`](interfaces/ExtensionStore.md)\>
2260
2260
 
2261
- This returns a [store](https://github.com/developit/unistore#store)
2262
- that modules can use to get information about the state of the
2263
- extension system.
2261
+ This returns a store that modules can use to get information about the
2262
+ state of the extension system.
2264
2263
 
2265
2264
  #### Returns
2266
2265
 
2267
- `Store`<[`ExtensionStore`](interfaces/ExtensionStore.md)\>
2266
+ `StoreApi`<[`ExtensionStore`](interfaces/ExtensionStore.md)\>
2268
2267
 
2269
2268
  #### Defined in
2270
2269
 
2271
- [packages/framework/esm-extensions/src/store.ts:130](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/store.ts#L130)
2270
+ [packages/framework/esm-extensions/src/store.ts:129](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/store.ts#L129)
2272
2271
 
2273
2272
  ___
2274
2273
 
@@ -2941,13 +2940,13 @@ ___
2941
2940
 
2942
2941
  ### getOfflinePatientDataStore
2943
2942
 
2944
- ▸ **getOfflinePatientDataStore**(): `Store`<[`OfflinePatientDataSyncStore`](interfaces/OfflinePatientDataSyncStore.md)\>
2943
+ ▸ **getOfflinePatientDataStore**(): `StoreApi`<[`OfflinePatientDataSyncStore`](interfaces/OfflinePatientDataSyncStore.md)\>
2945
2944
 
2946
2945
  **`deprecated`** Will be removed once all modules have been migrated to the new dynamic offline data API.
2947
2946
 
2948
2947
  #### Returns
2949
2948
 
2950
- `Store`<[`OfflinePatientDataSyncStore`](interfaces/OfflinePatientDataSyncStore.md)\>
2949
+ `StoreApi`<[`OfflinePatientDataSyncStore`](interfaces/OfflinePatientDataSyncStore.md)\>
2951
2950
 
2952
2951
  #### Defined in
2953
2952
 
@@ -3478,26 +3477,26 @@ ___
3478
3477
 
3479
3478
  ### createGlobalStore
3480
3479
 
3481
- ▸ **createGlobalStore**<`TState`\>(`name`, `initialState`): `Store`<`TState`\>
3480
+ ▸ **createGlobalStore**<`T`\>(`name`, `initialState`): `StoreApi`<`T`\>
3482
3481
 
3483
- Creates a Unistore [store](https://github.com/developit/unistore#store).
3482
+ Creates a Zustand store.
3484
3483
 
3485
3484
  #### Type parameters
3486
3485
 
3487
3486
  | Name |
3488
3487
  | :------ |
3489
- | `TState` |
3488
+ | `T` |
3490
3489
 
3491
3490
  #### Parameters
3492
3491
 
3493
3492
  | Name | Type | Description |
3494
3493
  | :------ | :------ | :------ |
3495
3494
  | `name` | `string` | A name by which the store can be looked up later. Must be unique across the entire application. |
3496
- | `initialState` | `TState` | An object which will be the initial state of the store. |
3495
+ | `initialState` | `T` | An object which will be the initial state of the store. |
3497
3496
 
3498
3497
  #### Returns
3499
3498
 
3500
- `Store`<`TState`\>
3499
+ `StoreApi`<`T`\>
3501
3500
 
3502
3501
  The newly created store.
3503
3502
 
@@ -3523,7 +3522,7 @@ Avoid this; generally prefer to have clients use `useStore(yourStore)`
3523
3522
 
3524
3523
  | Name | Type |
3525
3524
  | :------ | :------ |
3526
- | `store` | `Store`<`T`\> |
3525
+ | `store` | `StoreApi`<`T`\> |
3527
3526
 
3528
3527
  #### Returns
3529
3528
 
@@ -3561,17 +3560,17 @@ Avoid this; generally prefer to have clients use `useStore(yourStore)`
3561
3560
 
3562
3561
  #### Defined in
3563
3562
 
3564
- [packages/framework/esm-react-utils/src/createUseStore.ts:23](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/createUseStore.ts#L23)
3563
+ [packages/framework/esm-react-utils/src/createUseStore.ts:33](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/createUseStore.ts#L33)
3565
3564
 
3566
3565
  ___
3567
3566
 
3568
3567
  ### getAppState
3569
3568
 
3570
- ▸ **getAppState**(): `Store`<[`AppState`](interfaces/AppState.md)\>
3569
+ ▸ **getAppState**(): `StoreApi`<[`AppState`](interfaces/AppState.md)\>
3571
3570
 
3572
3571
  #### Returns
3573
3572
 
3574
- `Store`<[`AppState`](interfaces/AppState.md)\>
3573
+ `StoreApi`<[`AppState`](interfaces/AppState.md)\>
3575
3574
 
3576
3575
  The [store](https://github.com/developit/unistore#store) named `app`.
3577
3576
 
@@ -3583,27 +3582,27 @@ ___
3583
3582
 
3584
3583
  ### getGlobalStore
3585
3584
 
3586
- ▸ **getGlobalStore**<`TState`\>(`name`, `fallbackState?`): `Store`<`TState`\>
3585
+ ▸ **getGlobalStore**<`T`\>(`name`, `fallbackState?`): `StoreApi`<`T`\>
3587
3586
 
3588
- Returns the existing [store](https://github.com/developit/unistore#store) named `name`,
3587
+ Returns the existing store named `name`,
3589
3588
  or creates a new store named `name` if none exists.
3590
3589
 
3591
3590
  #### Type parameters
3592
3591
 
3593
- | Name | Type |
3594
- | :------ | :------ |
3595
- | `TState` | `any` |
3592
+ | Name |
3593
+ | :------ |
3594
+ | `T` |
3596
3595
 
3597
3596
  #### Parameters
3598
3597
 
3599
3598
  | Name | Type | Description |
3600
3599
  | :------ | :------ | :------ |
3601
3600
  | `name` | `string` | The name of the store to look up. |
3602
- | `fallbackState?` | `TState` | The initial value of the new store if no store named `name` exists. |
3601
+ | `fallbackState?` | `T` | The initial value of the new store if no store named `name` exists. |
3603
3602
 
3604
3603
  #### Returns
3605
3604
 
3606
- `Store`<`TState`\>
3605
+ `StoreApi`<`T`\>
3607
3606
 
3608
3607
  The found or newly created store.
3609
3608
 
@@ -3615,7 +3614,7 @@ ___
3615
3614
 
3616
3615
  ### subscribeTo
3617
3616
 
3618
- ▸ **subscribeTo**<`T`, `U`\>(`store`, `select`, `handle`): `Unsubscribe`
3617
+ ▸ **subscribeTo**<`T`, `U`\>(`store`, `select`, `handle`): () => `void`
3619
3618
 
3620
3619
  #### Type parameters
3621
3620
 
@@ -3628,13 +3627,19 @@ ___
3628
3627
 
3629
3628
  | Name | Type |
3630
3629
  | :------ | :------ |
3631
- | `store` | `Store`<`T`\> |
3630
+ | `store` | `StoreApi`<`T`\> |
3632
3631
  | `select` | (`state`: `T`) => `U` |
3633
3632
  | `handle` | (`subState`: `U`) => `void` |
3634
3633
 
3635
3634
  #### Returns
3636
3635
 
3637
- `Unsubscribe`
3636
+ `fn`
3637
+
3638
+ ▸ (): `void`
3639
+
3640
+ ##### Returns
3641
+
3642
+ `void`
3638
3643
 
3639
3644
  #### Defined in
3640
3645
 
@@ -3657,7 +3662,7 @@ ___
3657
3662
 
3658
3663
  | Name | Type |
3659
3664
  | :------ | :------ |
3660
- | `store` | `Store`<`T`\> |
3665
+ | `store` | `StoreApi`<`T`\> |
3661
3666
 
3662
3667
  #### Returns
3663
3668
 
@@ -3665,7 +3670,7 @@ ___
3665
3670
 
3666
3671
  #### Defined in
3667
3672
 
3668
- [packages/framework/esm-react-utils/src/useStore.ts:23](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useStore.ts#L23)
3673
+ [packages/framework/esm-react-utils/src/useStore.ts:33](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useStore.ts#L33)
3669
3674
 
3670
3675
  ▸ **useStore**<`T`, `U`\>(`store`, `select`): `U`
3671
3676
 
@@ -3680,7 +3685,7 @@ ___
3680
3685
 
3681
3686
  | Name | Type |
3682
3687
  | :------ | :------ |
3683
- | `store` | `Store`<`T`\> |
3688
+ | `store` | `StoreApi`<`T`\> |
3684
3689
  | `select` | (`state`: `T`) => `U` |
3685
3690
 
3686
3691
  #### Returns
@@ -3689,7 +3694,7 @@ ___
3689
3694
 
3690
3695
  #### Defined in
3691
3696
 
3692
- [packages/framework/esm-react-utils/src/useStore.ts:24](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useStore.ts#L24)
3697
+ [packages/framework/esm-react-utils/src/useStore.ts:34](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useStore.ts#L34)
3693
3698
 
3694
3699
  ▸ **useStore**<`T`, `U`\>(`store`, `select`, `actions`): `T` & [`BoundActions`](API.md#boundactions)
3695
3700
 
@@ -3704,7 +3709,7 @@ ___
3704
3709
 
3705
3710
  | Name | Type |
3706
3711
  | :------ | :------ |
3707
- | `store` | `Store`<`T`\> |
3712
+ | `store` | `StoreApi`<`T`\> |
3708
3713
  | `select` | `undefined` |
3709
3714
  | `actions` | [`Actions`](API.md#actions) |
3710
3715
 
@@ -3714,7 +3719,7 @@ ___
3714
3719
 
3715
3720
  #### Defined in
3716
3721
 
3717
- [packages/framework/esm-react-utils/src/useStore.ts:25](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useStore.ts#L25)
3722
+ [packages/framework/esm-react-utils/src/useStore.ts:35](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useStore.ts#L35)
3718
3723
 
3719
3724
  ▸ **useStore**<`T`, `U`\>(`store`, `select`, `actions`): `U` & [`BoundActions`](API.md#boundactions)
3720
3725
 
@@ -3729,7 +3734,7 @@ ___
3729
3734
 
3730
3735
  | Name | Type |
3731
3736
  | :------ | :------ |
3732
- | `store` | `Store`<`T`\> |
3737
+ | `store` | `StoreApi`<`T`\> |
3733
3738
  | `select` | (`state`: `T`) => `U` |
3734
3739
  | `actions` | [`Actions`](API.md#actions) |
3735
3740
 
@@ -3739,7 +3744,7 @@ ___
3739
3744
 
3740
3745
  #### Defined in
3741
3746
 
3742
- [packages/framework/esm-react-utils/src/useStore.ts:30](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useStore.ts#L30)
3747
+ [packages/framework/esm-react-utils/src/useStore.ts:40](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useStore.ts#L40)
3743
3748
 
3744
3749
  ___
3745
3750
 
@@ -3757,7 +3762,7 @@ ___
3757
3762
 
3758
3763
  | Name | Type |
3759
3764
  | :------ | :------ |
3760
- | `store` | `Store`<`T`\> |
3765
+ | `store` | `StoreApi`<`T`\> |
3761
3766
  | `actions` | [`Actions`](API.md#actions) |
3762
3767
 
3763
3768
  #### Returns
@@ -3766,7 +3771,7 @@ ___
3766
3771
 
3767
3772
  #### Defined in
3768
3773
 
3769
- [packages/framework/esm-react-utils/src/useStore.ts:52](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useStore.ts#L52)
3774
+ [packages/framework/esm-react-utils/src/useStore.ts:61](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useStore.ts#L61)
3770
3775
 
3771
3776
  ___
3772
3777
 
package/mock.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import type {} from "@openmrs/esm-globals";
3
- import createStore, { Store } from "unistore";
3
+ import { createStore, StoreApi } from "zustand";
4
4
  import { never, of } from "rxjs";
5
5
  import { interpolateUrl } from "@openmrs/esm-config";
6
6
  import { SessionStore } from "@openmrs/esm-api";
@@ -73,18 +73,20 @@ export const fhirBaseUrl = "/ws/fhir2/R4";
73
73
 
74
74
  /* esm-state */
75
75
  interface StoreEntity {
76
- value: Store<any>;
76
+ value: StoreApi<any>;
77
77
  active: boolean;
78
78
  }
79
79
 
80
- export type MockedStore<T> = Store<T> & { resetMock: () => void };
80
+ export type MockedStore<T> = StoreApi<T> & {
81
+ resetMock: () => void;
82
+ };
81
83
 
82
84
  export const mockStores = availableStores;
83
85
 
84
- export function createGlobalStore<TState>(
86
+ export function createGlobalStore<T>(
85
87
  name: string,
86
- initialState: TState
87
- ): Store<TState> {
88
+ initialState: T
89
+ ): StoreApi<T> {
88
90
  const available = availableStores[name];
89
91
 
90
92
  if (available) {
@@ -99,7 +101,7 @@ export function createGlobalStore<TState>(
99
101
  available.active = true;
100
102
  return available.value;
101
103
  } else {
102
- const store = createStore(initialState);
104
+ const store = createStore<T>()(() => initialState);
103
105
  initialStates[name] = initialState;
104
106
 
105
107
  availableStores[name] = {
@@ -111,14 +113,14 @@ export function createGlobalStore<TState>(
111
113
  }
112
114
  }
113
115
 
114
- export function getGlobalStore<TState = any>(
116
+ export function getGlobalStore<T>(
115
117
  name: string,
116
- fallbackState?: TState
117
- ): Store<TState> {
118
+ fallbackState?: T
119
+ ): StoreApi<T> {
118
120
  const available = availableStores[name];
119
121
 
120
122
  if (!available) {
121
- const store = createStore(fallbackState);
123
+ const store = createStore<T>()(() => fallbackState ?? ({} as unknown as T));
122
124
  initialStates[name] = fallbackState;
123
125
  availableStores[name] = {
124
126
  value: store,
@@ -130,13 +132,11 @@ export function getGlobalStore<TState = any>(
130
132
  return instrumentedStore(name, available.value);
131
133
  }
132
134
 
133
- function instrumentedStore<T>(name: string, store: Store<T>) {
135
+ function instrumentedStore<T>(name: string, store: StoreApi<T>) {
134
136
  return {
135
- action: jest.spyOn(store, "action"),
136
137
  getState: jest.spyOn(store, "getState"),
137
138
  setState: jest.spyOn(store, "setState"),
138
139
  subscribe: jest.spyOn(store, "subscribe"),
139
- unsubscribe: jest.spyOn(store, "unsubscribe"),
140
140
  resetMock: () => store.setState(initialStates[name]),
141
141
  } as any as MockedStore<T>;
142
142
  }
@@ -261,20 +261,16 @@ export const UserHasAccess = jest.fn().mockImplementation((props: any) => {
261
261
  return props.children;
262
262
  });
263
263
 
264
- export const createUseStore = (store: Store<any>) => (actions) => {
265
- const state = store.getState();
266
- return { ...state, ...actions };
267
- };
268
-
269
- export const useExtensionInternalStore = createUseStore(
264
+ export const useExtensionInternalStore = createGlobalStore(
265
+ "extensionInternal",
270
266
  getExtensionInternalStore()
271
267
  );
272
268
 
273
- export const useExtensionStore = createUseStore(getExtensionStore());
269
+ export const useExtensionStore = getExtensionStore();
274
270
 
275
271
  const defaultSelect = (x) => x;
276
272
  export const useStore = (
277
- store: Store<any>,
273
+ store: StoreApi<any>,
278
274
  select = defaultSelect,
279
275
  actions = {}
280
276
  ) => {
@@ -282,10 +278,12 @@ export const useStore = (
282
278
  return { ...state, ...actions };
283
279
  };
284
280
 
285
- export const useStoreWithActions = (store: Store<any>, actions) => {
286
- const state = store.getState();
287
- return { ...state, ...actions };
288
- };
281
+ export function useStoreWithActions<T>(
282
+ store: StoreApi<T>,
283
+ actions: Function | { [key: string]: Function }
284
+ ): T & { [key: string]: (...args: any[]) => void } {
285
+ return useStore(store, defaultSelect, actions);
286
+ }
289
287
 
290
288
  export const usePagination = jest.fn().mockImplementation(() => ({
291
289
  currentPage: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-framework",
3
- "version": "4.3.2-pre.680",
3
+ "version": "4.4.0",
4
4
  "license": "MPL-2.0",
5
5
  "browser": "dist/openmrs-esm-framework.js",
6
6
  "main": "src/index.ts",
@@ -35,17 +35,17 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@openmrs/esm-api": "^4.3.2-pre.680",
39
- "@openmrs/esm-breadcrumbs": "^4.3.2-pre.680",
40
- "@openmrs/esm-config": "^4.3.2-pre.680",
41
- "@openmrs/esm-error-handling": "^4.3.2-pre.680",
42
- "@openmrs/esm-extensions": "^4.3.2-pre.680",
43
- "@openmrs/esm-globals": "^4.3.2-pre.680",
44
- "@openmrs/esm-offline": "^4.3.2-pre.680",
45
- "@openmrs/esm-react-utils": "^4.3.2-pre.680",
46
- "@openmrs/esm-state": "^4.3.2-pre.680",
47
- "@openmrs/esm-styleguide": "^4.3.2-pre.680",
48
- "@openmrs/esm-utils": "^4.3.2-pre.680",
38
+ "@openmrs/esm-api": "^4.4.0",
39
+ "@openmrs/esm-breadcrumbs": "^4.4.0",
40
+ "@openmrs/esm-config": "^4.4.0",
41
+ "@openmrs/esm-error-handling": "^4.4.0",
42
+ "@openmrs/esm-extensions": "^4.4.0",
43
+ "@openmrs/esm-globals": "^4.4.0",
44
+ "@openmrs/esm-offline": "^4.4.0",
45
+ "@openmrs/esm-react-utils": "^4.4.0",
46
+ "@openmrs/esm-state": "^4.4.0",
47
+ "@openmrs/esm-styleguide": "^4.4.0",
48
+ "@openmrs/esm-utils": "^4.4.0",
49
49
  "dayjs": "^1.10.7"
50
50
  },
51
51
  "devDependencies": {
@@ -53,5 +53,5 @@
53
53
  "jest-cli": "28.1.0",
54
54
  "jest-environment-jsdom": "28.1.0"
55
55
  },
56
- "gitHead": "924a6261edaf89142bee78049ff388ef36b097ff"
56
+ "gitHead": "fdaefeded76bee4ec6503ca6590737e89ebe4b26"
57
57
  }