@cratis/arc.react 18.0.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/Arc.tsx +44 -0
- package/ArcContext.ts +23 -0
- package/Bindings.ts +15 -0
- package/README.md +65 -0
- package/WellKnownBindings.ts +9 -0
- package/commands/CommandScope.tsx +57 -0
- package/commands/CommandScopeImplementation.ts +68 -0
- package/commands/ICommandScope.ts +31 -0
- package/commands/for_CommandScopeImplementation/FakeCommand.ts +59 -0
- package/commands/for_CommandScopeImplementation/when_executing_with_three_commands_were_two_having_changes.ts +25 -0
- package/commands/for_CommandScopeImplementation/when_none_of_the_added_commands_has_changes.ts +19 -0
- package/commands/for_CommandScopeImplementation/when_one_of_the_added_commands_has_changes.ts +19 -0
- package/commands/for_CommandScopeImplementation/when_property_changes_on_added_command.ts +26 -0
- package/commands/for_CommandScopeImplementation/when_reverting_with_three_commands_were_two_having_changes.ts +25 -0
- package/commands/for_CommandScopeImplementation/when_there_are_no_commands.ts +10 -0
- package/commands/for_useCommand/FakeCommand.ts +31 -0
- package/commands/for_useCommand/when_creating_instance.ts +41 -0
- package/commands/for_useCommand/when_creating_instance_with_initial_values.ts +38 -0
- package/commands/for_useCommand/when_creating_instance_without_optional_context_values.ts +37 -0
- package/commands/index.ts +8 -0
- package/commands/useCommand.ts +70 -0
- package/commands/useCommandScope.ts +9 -0
- package/dialogs/BusyIndicatorDialogRequest.ts +18 -0
- package/dialogs/CloseDialog.ts +9 -0
- package/dialogs/ConfirmationDialogRequest.ts +22 -0
- package/dialogs/DialogButtons.ts +28 -0
- package/dialogs/DialogComponents.tsx +113 -0
- package/dialogs/DialogContext.ts +33 -0
- package/dialogs/DialogProps.ts +14 -0
- package/dialogs/DialogResponse.ts +9 -0
- package/dialogs/DialogResult.ts +32 -0
- package/dialogs/ShowDialog.ts +9 -0
- package/dialogs/index.ts +16 -0
- package/dialogs/useBusyIndicator.ts +41 -0
- package/dialogs/useConfirmationDialog.ts +39 -0
- package/dialogs/useDialog.tsx +55 -0
- package/dist/cjs/Arc.d.ts +12 -0
- package/dist/cjs/Arc.d.ts.map +1 -0
- package/dist/cjs/Arc.js +25 -0
- package/dist/cjs/Arc.js.map +1 -0
- package/dist/cjs/ArcContext.d.ts +12 -0
- package/dist/cjs/ArcContext.d.ts.map +1 -0
- package/dist/cjs/ArcContext.js +16 -0
- package/dist/cjs/ArcContext.js.map +1 -0
- package/dist/cjs/Bindings.d.ts +5 -0
- package/dist/cjs/Bindings.d.ts.map +1 -0
- package/dist/cjs/Bindings.js +15 -0
- package/dist/cjs/Bindings.js.map +1 -0
- package/dist/cjs/WellKnownBindings.d.ts +4 -0
- package/dist/cjs/WellKnownBindings.d.ts.map +1 -0
- package/dist/cjs/WellKnownBindings.js +8 -0
- package/dist/cjs/WellKnownBindings.js.map +1 -0
- package/dist/cjs/commands/CommandScope.d.ts +13 -0
- package/dist/cjs/commands/CommandScope.d.ts.map +1 -0
- package/dist/cjs/commands/CommandScope.js +39 -0
- package/dist/cjs/commands/CommandScope.js.map +1 -0
- package/dist/cjs/commands/CommandScopeImplementation.d.ts +16 -0
- package/dist/cjs/commands/CommandScopeImplementation.d.ts.map +1 -0
- package/dist/cjs/commands/CommandScopeImplementation.js +52 -0
- package/dist/cjs/commands/CommandScopeImplementation.js.map +1 -0
- package/dist/cjs/commands/ICommandScope.d.ts +8 -0
- package/dist/cjs/commands/ICommandScope.d.ts.map +1 -0
- package/dist/cjs/commands/index.d.ts +6 -0
- package/dist/cjs/commands/index.d.ts.map +1 -0
- package/dist/cjs/commands/index.js +15 -0
- package/dist/cjs/commands/index.js.map +1 -0
- package/dist/cjs/commands/useCommand.d.ts +6 -0
- package/dist/cjs/commands/useCommand.d.ts.map +1 -0
- package/dist/cjs/commands/useCommand.js +47 -0
- package/dist/cjs/commands/useCommand.js.map +1 -0
- package/dist/cjs/commands/useCommandScope.d.ts +2 -0
- package/dist/cjs/commands/useCommandScope.d.ts.map +1 -0
- package/dist/cjs/commands/useCommandScope.js +11 -0
- package/dist/cjs/commands/useCommandScope.js.map +1 -0
- package/dist/cjs/dialogs/BusyIndicatorDialogRequest.d.ts +6 -0
- package/dist/cjs/dialogs/BusyIndicatorDialogRequest.d.ts.map +1 -0
- package/dist/cjs/dialogs/BusyIndicatorDialogRequest.js +13 -0
- package/dist/cjs/dialogs/BusyIndicatorDialogRequest.js.map +1 -0
- package/dist/cjs/dialogs/CloseDialog.d.ts +3 -0
- package/dist/cjs/dialogs/CloseDialog.d.ts.map +1 -0
- package/dist/cjs/dialogs/ConfirmationDialogRequest.d.ts +8 -0
- package/dist/cjs/dialogs/ConfirmationDialogRequest.d.ts.map +1 -0
- package/dist/cjs/dialogs/ConfirmationDialogRequest.js +15 -0
- package/dist/cjs/dialogs/ConfirmationDialogRequest.js.map +1 -0
- package/dist/cjs/dialogs/DialogButtons.d.ts +7 -0
- package/dist/cjs/dialogs/DialogButtons.d.ts.map +1 -0
- package/dist/cjs/dialogs/DialogButtons.js +10 -0
- package/dist/cjs/dialogs/DialogButtons.js.map +1 -0
- package/dist/cjs/dialogs/DialogComponents.d.ts +20 -0
- package/dist/cjs/dialogs/DialogComponents.d.ts.map +1 -0
- package/dist/cjs/dialogs/DialogComponents.js +34 -0
- package/dist/cjs/dialogs/DialogComponents.js.map +1 -0
- package/dist/cjs/dialogs/DialogContext.d.ts +10 -0
- package/dist/cjs/dialogs/DialogContext.d.ts.map +1 -0
- package/dist/cjs/dialogs/DialogContext.js +40 -0
- package/dist/cjs/dialogs/DialogContext.js.map +1 -0
- package/dist/cjs/dialogs/DialogProps.d.ts +5 -0
- package/dist/cjs/dialogs/DialogProps.d.ts.map +1 -0
- package/dist/cjs/dialogs/DialogResponse.d.ts +3 -0
- package/dist/cjs/dialogs/DialogResponse.d.ts.map +1 -0
- package/dist/cjs/dialogs/DialogResult.d.ts +8 -0
- package/dist/cjs/dialogs/DialogResult.d.ts.map +1 -0
- package/dist/cjs/dialogs/DialogResult.js +11 -0
- package/dist/cjs/dialogs/DialogResult.js.map +1 -0
- package/dist/cjs/dialogs/ShowDialog.d.ts +3 -0
- package/dist/cjs/dialogs/ShowDialog.d.ts.map +1 -0
- package/dist/cjs/dialogs/index.d.ts +14 -0
- package/dist/cjs/dialogs/index.d.ts.map +1 -0
- package/dist/cjs/dialogs/index.js +33 -0
- package/dist/cjs/dialogs/index.js.map +1 -0
- package/dist/cjs/dialogs/useBusyIndicator.d.ts +5 -0
- package/dist/cjs/dialogs/useBusyIndicator.d.ts.map +1 -0
- package/dist/cjs/dialogs/useBusyIndicator.js +21 -0
- package/dist/cjs/dialogs/useBusyIndicator.js.map +1 -0
- package/dist/cjs/dialogs/useConfirmationDialog.d.ts +5 -0
- package/dist/cjs/dialogs/useConfirmationDialog.d.ts.map +1 -0
- package/dist/cjs/dialogs/useConfirmationDialog.js +20 -0
- package/dist/cjs/dialogs/useConfirmationDialog.js.map +1 -0
- package/dist/cjs/dialogs/useDialog.d.ts +5 -0
- package/dist/cjs/dialogs/useDialog.d.ts.map +1 -0
- package/dist/cjs/dialogs/useDialog.js +34 -0
- package/dist/cjs/dialogs/useDialog.js.map +1 -0
- package/dist/cjs/identity/IdentityProvider.d.ts +10 -0
- package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -0
- package/dist/cjs/identity/IdentityProvider.js +48 -0
- package/dist/cjs/identity/IdentityProvider.js.map +1 -0
- package/dist/cjs/identity/index.d.ts +3 -0
- package/dist/cjs/identity/index.d.ts.map +1 -0
- package/dist/cjs/identity/index.js +11 -0
- package/dist/cjs/identity/index.js.map +1 -0
- package/dist/cjs/identity/useIdentity.d.ts +3 -0
- package/dist/cjs/identity/useIdentity.d.ts.map +1 -0
- package/dist/cjs/identity/useIdentity.js +15 -0
- package/dist/cjs/identity/useIdentity.js.map +1 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/queries/SetPage.d.ts +2 -0
- package/dist/cjs/queries/SetPage.d.ts.map +1 -0
- package/dist/cjs/queries/SetPageSize.d.ts +2 -0
- package/dist/cjs/queries/SetPageSize.d.ts.map +1 -0
- package/dist/cjs/queries/SetSorting.d.ts +3 -0
- package/dist/cjs/queries/SetSorting.d.ts.map +1 -0
- package/dist/cjs/queries/index.d.ts +6 -0
- package/dist/cjs/queries/index.d.ts.map +1 -0
- package/dist/cjs/queries/index.js +12 -0
- package/dist/cjs/queries/index.js.map +1 -0
- package/dist/cjs/queries/useObservableQuery.d.ts +16 -0
- package/dist/cjs/queries/useObservableQuery.d.ts.map +1 -0
- package/dist/cjs/queries/useObservableQuery.js +54 -0
- package/dist/cjs/queries/useObservableQuery.js.map +1 -0
- package/dist/cjs/queries/useQuery.d.ts +19 -0
- package/dist/cjs/queries/useQuery.d.ts.map +1 -0
- package/dist/cjs/queries/useQuery.js +76 -0
- package/dist/cjs/queries/useQuery.js.map +1 -0
- package/dist/esm/Arc.d.ts +12 -0
- package/dist/esm/Arc.d.ts.map +1 -0
- package/dist/esm/Arc.js +23 -0
- package/dist/esm/Arc.js.map +1 -0
- package/dist/esm/ArcContext.d.ts +12 -0
- package/dist/esm/ArcContext.d.ts.map +1 -0
- package/dist/esm/ArcContext.js +14 -0
- package/dist/esm/ArcContext.js.map +1 -0
- package/dist/esm/Bindings.d.ts +5 -0
- package/dist/esm/Bindings.d.ts.map +1 -0
- package/dist/esm/Bindings.js +13 -0
- package/dist/esm/Bindings.js.map +1 -0
- package/dist/esm/WellKnownBindings.d.ts +4 -0
- package/dist/esm/WellKnownBindings.d.ts.map +1 -0
- package/dist/esm/WellKnownBindings.js +6 -0
- package/dist/esm/WellKnownBindings.js.map +1 -0
- package/dist/esm/commands/CommandScope.d.ts +13 -0
- package/dist/esm/commands/CommandScope.d.ts.map +1 -0
- package/dist/esm/commands/CommandScope.js +36 -0
- package/dist/esm/commands/CommandScope.js.map +1 -0
- package/dist/esm/commands/CommandScopeImplementation.d.ts +16 -0
- package/dist/esm/commands/CommandScopeImplementation.d.ts.map +1 -0
- package/dist/esm/commands/CommandScopeImplementation.js +50 -0
- package/dist/esm/commands/CommandScopeImplementation.js.map +1 -0
- package/dist/esm/commands/ICommandScope.d.ts +8 -0
- package/dist/esm/commands/ICommandScope.d.ts.map +1 -0
- package/dist/esm/commands/ICommandScope.js +2 -0
- package/dist/esm/commands/ICommandScope.js.map +1 -0
- package/dist/esm/commands/index.d.ts +6 -0
- package/dist/esm/commands/index.d.ts.map +1 -0
- package/dist/esm/commands/index.js +5 -0
- package/dist/esm/commands/index.js.map +1 -0
- package/dist/esm/commands/useCommand.d.ts +6 -0
- package/dist/esm/commands/useCommand.d.ts.map +1 -0
- package/dist/esm/commands/useCommand.js +45 -0
- package/dist/esm/commands/useCommand.js.map +1 -0
- package/dist/esm/commands/useCommandScope.d.ts +2 -0
- package/dist/esm/commands/useCommandScope.d.ts.map +1 -0
- package/dist/esm/commands/useCommandScope.js +9 -0
- package/dist/esm/commands/useCommandScope.js.map +1 -0
- package/dist/esm/dialogs/BusyIndicatorDialogRequest.d.ts +6 -0
- package/dist/esm/dialogs/BusyIndicatorDialogRequest.d.ts.map +1 -0
- package/dist/esm/dialogs/BusyIndicatorDialogRequest.js +11 -0
- package/dist/esm/dialogs/BusyIndicatorDialogRequest.js.map +1 -0
- package/dist/esm/dialogs/CloseDialog.d.ts +3 -0
- package/dist/esm/dialogs/CloseDialog.d.ts.map +1 -0
- package/dist/esm/dialogs/CloseDialog.js +2 -0
- package/dist/esm/dialogs/CloseDialog.js.map +1 -0
- package/dist/esm/dialogs/ConfirmationDialogRequest.d.ts +8 -0
- package/dist/esm/dialogs/ConfirmationDialogRequest.d.ts.map +1 -0
- package/dist/esm/dialogs/ConfirmationDialogRequest.js +13 -0
- package/dist/esm/dialogs/ConfirmationDialogRequest.js.map +1 -0
- package/dist/esm/dialogs/DialogButtons.d.ts +7 -0
- package/dist/esm/dialogs/DialogButtons.d.ts.map +1 -0
- package/dist/esm/dialogs/DialogButtons.js +10 -0
- package/dist/esm/dialogs/DialogButtons.js.map +1 -0
- package/dist/esm/dialogs/DialogComponents.d.ts +20 -0
- package/dist/esm/dialogs/DialogComponents.d.ts.map +1 -0
- package/dist/esm/dialogs/DialogComponents.js +31 -0
- package/dist/esm/dialogs/DialogComponents.js.map +1 -0
- package/dist/esm/dialogs/DialogContext.d.ts +10 -0
- package/dist/esm/dialogs/DialogContext.d.ts.map +1 -0
- package/dist/esm/dialogs/DialogContext.js +18 -0
- package/dist/esm/dialogs/DialogContext.js.map +1 -0
- package/dist/esm/dialogs/DialogProps.d.ts +5 -0
- package/dist/esm/dialogs/DialogProps.d.ts.map +1 -0
- package/dist/esm/dialogs/DialogProps.js +2 -0
- package/dist/esm/dialogs/DialogProps.js.map +1 -0
- package/dist/esm/dialogs/DialogResponse.d.ts +3 -0
- package/dist/esm/dialogs/DialogResponse.d.ts.map +1 -0
- package/dist/esm/dialogs/DialogResponse.js +2 -0
- package/dist/esm/dialogs/DialogResponse.js.map +1 -0
- package/dist/esm/dialogs/DialogResult.d.ts +8 -0
- package/dist/esm/dialogs/DialogResult.d.ts.map +1 -0
- package/dist/esm/dialogs/DialogResult.js +11 -0
- package/dist/esm/dialogs/DialogResult.js.map +1 -0
- package/dist/esm/dialogs/ShowDialog.d.ts +3 -0
- package/dist/esm/dialogs/ShowDialog.d.ts.map +1 -0
- package/dist/esm/dialogs/ShowDialog.js +2 -0
- package/dist/esm/dialogs/ShowDialog.js.map +1 -0
- package/dist/esm/dialogs/index.d.ts +14 -0
- package/dist/esm/dialogs/index.d.ts.map +1 -0
- package/dist/esm/dialogs/index.js +10 -0
- package/dist/esm/dialogs/index.js.map +1 -0
- package/dist/esm/dialogs/useBusyIndicator.d.ts +5 -0
- package/dist/esm/dialogs/useBusyIndicator.d.ts.map +1 -0
- package/dist/esm/dialogs/useBusyIndicator.js +19 -0
- package/dist/esm/dialogs/useBusyIndicator.js.map +1 -0
- package/dist/esm/dialogs/useConfirmationDialog.d.ts +5 -0
- package/dist/esm/dialogs/useConfirmationDialog.d.ts.map +1 -0
- package/dist/esm/dialogs/useConfirmationDialog.js +18 -0
- package/dist/esm/dialogs/useConfirmationDialog.js.map +1 -0
- package/dist/esm/dialogs/useDialog.d.ts +5 -0
- package/dist/esm/dialogs/useDialog.d.ts.map +1 -0
- package/dist/esm/dialogs/useDialog.js +32 -0
- package/dist/esm/dialogs/useDialog.js.map +1 -0
- package/dist/esm/identity/IdentityProvider.d.ts +10 -0
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -0
- package/dist/esm/identity/IdentityProvider.js +45 -0
- package/dist/esm/identity/IdentityProvider.js.map +1 -0
- package/dist/esm/identity/index.d.ts +3 -0
- package/dist/esm/identity/index.d.ts.map +1 -0
- package/dist/esm/identity/index.js +3 -0
- package/dist/esm/identity/index.js.map +1 -0
- package/dist/esm/identity/useIdentity.d.ts +3 -0
- package/dist/esm/identity/useIdentity.d.ts.map +1 -0
- package/dist/esm/identity/useIdentity.js +13 -0
- package/dist/esm/identity/useIdentity.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/queries/SetPage.d.ts +2 -0
- package/dist/esm/queries/SetPage.d.ts.map +1 -0
- package/dist/esm/queries/SetPage.js +2 -0
- package/dist/esm/queries/SetPage.js.map +1 -0
- package/dist/esm/queries/SetPageSize.d.ts +2 -0
- package/dist/esm/queries/SetPageSize.d.ts.map +1 -0
- package/dist/esm/queries/SetPageSize.js +2 -0
- package/dist/esm/queries/SetPageSize.js.map +1 -0
- package/dist/esm/queries/SetSorting.d.ts +3 -0
- package/dist/esm/queries/SetSorting.d.ts.map +1 -0
- package/dist/esm/queries/SetSorting.js +2 -0
- package/dist/esm/queries/SetSorting.js.map +1 -0
- package/dist/esm/queries/index.d.ts +6 -0
- package/dist/esm/queries/index.d.ts.map +1 -0
- package/dist/esm/queries/index.js +3 -0
- package/dist/esm/queries/index.js.map +1 -0
- package/dist/esm/queries/useObservableQuery.d.ts +16 -0
- package/dist/esm/queries/useObservableQuery.d.ts.map +1 -0
- package/dist/esm/queries/useObservableQuery.js +51 -0
- package/dist/esm/queries/useObservableQuery.js.map +1 -0
- package/dist/esm/queries/useQuery.d.ts +19 -0
- package/dist/esm/queries/useQuery.d.ts.map +1 -0
- package/dist/esm/queries/useQuery.js +73 -0
- package/dist/esm/queries/useQuery.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -0
- package/global.d.ts +11 -0
- package/identity/IdentityProvider.tsx +61 -0
- package/identity/for_IdentityProvider/when_refreshing_identity.ts +59 -0
- package/identity/index.ts +5 -0
- package/identity/useIdentity.ts +19 -0
- package/index.ts +18 -0
- package/package.json +69 -0
- package/queries/SetPage.ts +7 -0
- package/queries/SetPageSize.ts +7 -0
- package/queries/SetSorting.ts +9 -0
- package/queries/for_useQuery/FakeQuery.ts +25 -0
- package/queries/for_useQuery/when_creating_instance.ts +63 -0
- package/queries/for_useQuery/when_creating_instance_with_sorting.ts +55 -0
- package/queries/for_useQuery/when_creating_instance_without_optional_context_values.ts +59 -0
- package/queries/for_useQueryWithPaging/when_creating_instance_with_paging.ts +67 -0
- package/queries/index.ts +8 -0
- package/queries/useObservableQuery.ts +83 -0
- package/queries/useQuery.ts +113 -0
package/Arc.tsx
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { CommandScope } from './commands';
|
|
5
|
+
import { IdentityProvider } from './identity';
|
|
6
|
+
import { Bindings } from './Bindings';
|
|
7
|
+
import { ArcConfiguration, ArcContext } from './ArcContext';
|
|
8
|
+
import { GetHttpHeaders } from '@cratis/arc';
|
|
9
|
+
|
|
10
|
+
export interface ArcProps {
|
|
11
|
+
children?: JSX.Element | JSX.Element[];
|
|
12
|
+
microservice?: string;
|
|
13
|
+
development?: boolean;
|
|
14
|
+
origin?: string;
|
|
15
|
+
basePath?: string;
|
|
16
|
+
apiBasePath?: string;
|
|
17
|
+
httpHeadersCallback?: GetHttpHeaders;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Arc = (props: ArcProps) => {
|
|
21
|
+
const configuration: ArcConfiguration = {
|
|
22
|
+
microservice: props.microservice ?? '',
|
|
23
|
+
development: props.development ?? false,
|
|
24
|
+
origin: props.origin ?? '',
|
|
25
|
+
basePath: props.basePath ?? '',
|
|
26
|
+
apiBasePath: props.apiBasePath ?? '',
|
|
27
|
+
httpHeadersCallback: props.httpHeadersCallback
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
Bindings.initialize(
|
|
31
|
+
configuration.microservice,
|
|
32
|
+
configuration.apiBasePath,
|
|
33
|
+
configuration.origin,
|
|
34
|
+
configuration.httpHeadersCallback);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<ArcContext.Provider value={configuration}>
|
|
38
|
+
<IdentityProvider httpHeadersCallback={props.httpHeadersCallback}>
|
|
39
|
+
<CommandScope>
|
|
40
|
+
{props.children}
|
|
41
|
+
</CommandScope>
|
|
42
|
+
</IdentityProvider>
|
|
43
|
+
</ArcContext.Provider>);
|
|
44
|
+
};
|
package/ArcContext.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { GetHttpHeaders, Globals } from '@cratis/arc';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
export interface ArcConfiguration {
|
|
8
|
+
microservice: string;
|
|
9
|
+
development?: boolean
|
|
10
|
+
origin?: string;
|
|
11
|
+
basePath?: string;
|
|
12
|
+
apiBasePath?: string;
|
|
13
|
+
httpHeadersCallback?: GetHttpHeaders;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const ArcContext = React.createContext<ArcConfiguration>({
|
|
17
|
+
microservice: Globals.microservice,
|
|
18
|
+
development: false,
|
|
19
|
+
origin: '',
|
|
20
|
+
basePath: '',
|
|
21
|
+
apiBasePath: '',
|
|
22
|
+
httpHeadersCallback: () => ({})
|
|
23
|
+
});
|
package/Bindings.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { container } from 'tsyringe';
|
|
5
|
+
import { IQueryProvider, QueryProvider } from '@cratis/arc/queries';
|
|
6
|
+
import { Constructor } from '@cratis/fundamentals';
|
|
7
|
+
import { WellKnownBindings } from './WellKnownBindings';
|
|
8
|
+
import { GetHttpHeaders } from '@cratis/arc';
|
|
9
|
+
|
|
10
|
+
export class Bindings {
|
|
11
|
+
static initialize(microservice: string, apiBasePath?: string, origin?: string, httpHeadersCallback?: GetHttpHeaders): void {
|
|
12
|
+
container.registerSingleton(WellKnownBindings.microservice, microservice);
|
|
13
|
+
container.register(IQueryProvider as Constructor<IQueryProvider>, { useValue: new QueryProvider(microservice, apiBasePath ?? '', origin ?? '', httpHeadersCallback ?? (() => ({}))) });
|
|
14
|
+
}
|
|
15
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Cratis Application Model
|
|
2
|
+
|
|
3
|
+
## Packages / Deployables
|
|
4
|
+
|
|
5
|
+
[](http://nuget.org/packages/Cratis.Arc)
|
|
6
|
+
[](https://www.npmjs.com/package/@cratis/arc)
|
|
7
|
+
|
|
8
|
+
## Builds
|
|
9
|
+
|
|
10
|
+
[](https://github.com/cratis/arc/actions/workflows/dotnet-build.yml)
|
|
11
|
+
[](https://github.com/cratis/arc/actions/workflows/javascript-build.yml)
|
|
12
|
+
[](https://github.com/Cratis/Documentation/actions/workflows/pages.yml)
|
|
13
|
+
|
|
14
|
+
## Description
|
|
15
|
+
|
|
16
|
+
The Cratis Application model represents an opinionated approach to building consistent applications based on the concepts behind CQRS.
|
|
17
|
+
It offers extensions for different frameworks and is built on top of ASP.NET Core. One of the traits of Arc has is the
|
|
18
|
+
bridging between the backend and the frontend. Arc provides a tool, called **ProxyGenerator** that generates TypeScript
|
|
19
|
+
code for recognized artifacts matching the criteria of what is considered a **commmand** or a **query**.
|
|
20
|
+
|
|
21
|
+
## Contributing
|
|
22
|
+
|
|
23
|
+
If you want to jump into building this repository and possibly contributing, please refer to [contributing](./Documentation/contributing/index.md).
|
|
24
|
+
|
|
25
|
+
### Prerequisites
|
|
26
|
+
|
|
27
|
+
The following are prerequisites to work with this repository.
|
|
28
|
+
|
|
29
|
+
* [.NET 8+](https://dotnet.microsoft.com/en-us/).
|
|
30
|
+
* [Node 16+](https://nodejs.org/en)
|
|
31
|
+
* [Yarn](https://yarnpkg.com)
|
|
32
|
+
|
|
33
|
+
### Central Package Management
|
|
34
|
+
|
|
35
|
+
This repository leverages [Central Package Management](https://learn.microsoft.com/en-us/nuget/consume-packages/Central-Package-Management), which
|
|
36
|
+
means that all package versions are managed from a file at the root level called [Directory.Packages.props](./Directory.Packages.props).
|
|
37
|
+
|
|
38
|
+
In addition there are also [Directory.Build.props](https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022#directorybuildprops-and-directorybuildtargets) files for
|
|
39
|
+
setting up common settings that are applied cross cuttingly.
|
|
40
|
+
|
|
41
|
+
### Root package.json
|
|
42
|
+
|
|
43
|
+
The `package.json` found at the root level defines all the workspaces. It is assumed
|
|
44
|
+
|
|
45
|
+
All developer dependencies are defined in the top level `package.json`. The reason for this is to be able to provide global scripts
|
|
46
|
+
for every package to use for easier maintenance.
|
|
47
|
+
|
|
48
|
+
The `package.json` found at the top level contains scripts that can then be used in a child project for this to work properly.
|
|
49
|
+
|
|
50
|
+
In a package, all you need to do is to define the scripts to use the global scripts in the `package.json´ of that project:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"scripts": {
|
|
55
|
+
"prepublish": "yarn g:build",
|
|
56
|
+
"clean": "yarn g:clean",
|
|
57
|
+
"build": "yarn g:build",
|
|
58
|
+
"lint": "yarn g:lint",
|
|
59
|
+
"lint:ci": "yarn g:lint:ci",
|
|
60
|
+
"test": "yarn g:test",
|
|
61
|
+
"ci": "yarn g:ci",
|
|
62
|
+
"up": "yarn g:up"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Well-known IoC binding constants.
|
|
6
|
+
*/
|
|
7
|
+
export const WellKnownBindings = {
|
|
8
|
+
microservice: 'Microservice'
|
|
9
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import React, { useEffect, useState } from 'react';
|
|
5
|
+
import { Command, CommandResult, CommandResults } from '@cratis/arc/commands';
|
|
6
|
+
import { CommandScopeImplementation } from './CommandScopeImplementation';
|
|
7
|
+
import { ICommandScope } from './ICommandScope';
|
|
8
|
+
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
10
|
+
const defaultCommandScopeContext: ICommandScope = {
|
|
11
|
+
addCommand: () => { },
|
|
12
|
+
execute: async () => {
|
|
13
|
+
return new CommandResults(new Map());
|
|
14
|
+
},
|
|
15
|
+
hasChanges: false,
|
|
16
|
+
revertChanges: () => { }
|
|
17
|
+
};
|
|
18
|
+
/* eslint-enable @typescript-eslint/no-empty-function */
|
|
19
|
+
|
|
20
|
+
export const CommandScopeContext = React.createContext<ICommandScope>(defaultCommandScopeContext);
|
|
21
|
+
|
|
22
|
+
export type CommandScopeChanged = (hasChanges: boolean) => void;
|
|
23
|
+
export type CommandScopeExecute = () => Promise<Map<Command, CommandResult>>;
|
|
24
|
+
|
|
25
|
+
export type AddCommand = (command: Command) => void;
|
|
26
|
+
|
|
27
|
+
export interface ICommandScopeProps {
|
|
28
|
+
children?: JSX.Element | JSX.Element[];
|
|
29
|
+
setHasChanges?: CommandScopeChanged;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const CommandScope = (props: ICommandScopeProps) => {
|
|
33
|
+
const [hasChanges, setHasChanges] = useState(false);
|
|
34
|
+
const [commandScope, setCommandScope] = useState<ICommandScope>(defaultCommandScopeContext);
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const commandScopeImplementation = new CommandScopeImplementation((value) => {
|
|
38
|
+
setHasChanges(value);
|
|
39
|
+
});
|
|
40
|
+
setCommandScope(commandScopeImplementation);
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
if (commandScope) {
|
|
44
|
+
commandScope.hasChanges = hasChanges;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<CommandScopeContext.Provider value={{
|
|
49
|
+
addCommand: (command) => commandScope!.addCommand(command),
|
|
50
|
+
execute: () => commandScope.execute(),
|
|
51
|
+
revertChanges: () => commandScope.revertChanges(),
|
|
52
|
+
hasChanges
|
|
53
|
+
}}>
|
|
54
|
+
{props.children}
|
|
55
|
+
</CommandScopeContext.Provider>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { ICommand, CommandResults } from '@cratis/arc/commands';
|
|
6
|
+
import { ICommandScope } from './ICommandScope';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Represents an implementation of {@link ICommandScope}.
|
|
11
|
+
*/
|
|
12
|
+
export class CommandScopeImplementation implements ICommandScope {
|
|
13
|
+
private _commands: ICommand[] = [];
|
|
14
|
+
private _hasChanges = false;
|
|
15
|
+
|
|
16
|
+
constructor(private readonly _setHasChanges: React.Dispatch<React.SetStateAction<boolean>>) {
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @inheritdoc */
|
|
20
|
+
get hasChanges(): boolean {
|
|
21
|
+
return this._hasChanges;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
set hasChanges(value: boolean) {
|
|
25
|
+
this._hasChanges = value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @inheritdoc */
|
|
29
|
+
addCommand(command: ICommand): void {
|
|
30
|
+
if (this._commands.some(_ => _ == command)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this._commands.push(command);
|
|
35
|
+
this.evaluateHasChanges();
|
|
36
|
+
command.onPropertyChanged(this.evaluateHasChanges, this);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @inheritdoc */
|
|
40
|
+
async execute(): Promise<CommandResults> {
|
|
41
|
+
const commandsToCommandResult = new Map();
|
|
42
|
+
|
|
43
|
+
for (const command of this._commands.filter(_ => _.hasChanges === true)) {
|
|
44
|
+
const commandResult = await command.execute();
|
|
45
|
+
commandsToCommandResult.set(command, commandResult);
|
|
46
|
+
}
|
|
47
|
+
this.evaluateHasChanges();
|
|
48
|
+
return new CommandResults(commandsToCommandResult);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @inheritdoc */
|
|
52
|
+
revertChanges() {
|
|
53
|
+
this._commands.forEach(command => command.revertChanges());
|
|
54
|
+
this.evaluateHasChanges();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private evaluateHasChanges() {
|
|
58
|
+
let hasCommandChanges = false;
|
|
59
|
+
this._commands.forEach(command => {
|
|
60
|
+
if (command.hasChanges) {
|
|
61
|
+
hasCommandChanges = true;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
this._hasChanges = hasCommandChanges;
|
|
66
|
+
this._setHasChanges(hasCommandChanges);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { ICommand, CommandResults } from '@cratis/arc/commands';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Defines the system for tracking commands in a scope.
|
|
8
|
+
*/
|
|
9
|
+
export interface ICommandScope {
|
|
10
|
+
/**
|
|
11
|
+
* Gets or sets whether or not there are any changes in the context.
|
|
12
|
+
*/
|
|
13
|
+
hasChanges: boolean;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Add a command for tracking in the scope.
|
|
17
|
+
* @param {ICommand} command Command to add.
|
|
18
|
+
*/
|
|
19
|
+
addCommand(command: ICommand): void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Execute all commands with changes.
|
|
23
|
+
* @returns {Promise<CommandResults>} Command results per command that was executed.
|
|
24
|
+
*/
|
|
25
|
+
execute(): Promise<CommandResults>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Revert any changes for commands in scope.
|
|
29
|
+
*/
|
|
30
|
+
revertChanges(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import sinon from 'sinon';
|
|
5
|
+
import { CommandResult, ICommand, PropertyChanged } from '@cratis/arc/commands';
|
|
6
|
+
import { PropertyDescriptor } from '@cratis/arc/reflection';
|
|
7
|
+
|
|
8
|
+
/* eslint-disable */
|
|
9
|
+
|
|
10
|
+
export class FakeCommand implements ICommand {
|
|
11
|
+
route = '';
|
|
12
|
+
propertyDescriptors: PropertyDescriptor[] = [];
|
|
13
|
+
private _hasChanges: boolean;
|
|
14
|
+
|
|
15
|
+
constructor(hasChanges: boolean) {
|
|
16
|
+
this._hasChanges = hasChanges;
|
|
17
|
+
this.execute = sinon.fake(() => {
|
|
18
|
+
this._hasChanges = false;
|
|
19
|
+
return new Promise<CommandResult>(resolve => {
|
|
20
|
+
resolve(CommandResult.empty);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
this.setInitialValues = sinon.stub();
|
|
24
|
+
this.setInitialValues = sinon.stub();
|
|
25
|
+
this.propertyChanged = sinon.stub();
|
|
26
|
+
this.onPropertyChanged = sinon.stub();
|
|
27
|
+
this.revertChanges = sinon.fake(() => {
|
|
28
|
+
this._hasChanges = false;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get hasChanges() {
|
|
33
|
+
return this._hasChanges;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
revertChanges(): void {
|
|
37
|
+
throw new Error('Method not implemented.');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
execute(): Promise<CommandResult> {
|
|
41
|
+
throw new Error('Method not implemented.');
|
|
42
|
+
}
|
|
43
|
+
setInitialValues(values: {}): void {
|
|
44
|
+
throw new Error('Method not implemented.');
|
|
45
|
+
}
|
|
46
|
+
setInitialValuesFromCurrentValues(): void {
|
|
47
|
+
throw new Error('Method not implemented.');
|
|
48
|
+
}
|
|
49
|
+
propertyChanged(property: string): void {
|
|
50
|
+
throw new Error('Method not implemented.');
|
|
51
|
+
}
|
|
52
|
+
onPropertyChanged(callback: PropertyChanged, thisArg: any): void {
|
|
53
|
+
throw new Error('Method not implemented.');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setMicroservice(microservice: string) {
|
|
57
|
+
throw new Error('Method not implemented.');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { SinonStub } from 'sinon';
|
|
5
|
+
import { CommandScopeImplementation } from '../CommandScopeImplementation';
|
|
6
|
+
import { FakeCommand } from './FakeCommand';
|
|
7
|
+
|
|
8
|
+
describe('when executing with three commands were two having changes', async () => {
|
|
9
|
+
const scope = new CommandScopeImplementation(() => {});
|
|
10
|
+
|
|
11
|
+
const firstCommand = new FakeCommand(true);
|
|
12
|
+
const secondCommand = new FakeCommand(false);
|
|
13
|
+
const thirdCommand = new FakeCommand(true);
|
|
14
|
+
|
|
15
|
+
scope.addCommand(firstCommand);
|
|
16
|
+
scope.addCommand(secondCommand);
|
|
17
|
+
scope.addCommand(thirdCommand);
|
|
18
|
+
|
|
19
|
+
await scope.execute();
|
|
20
|
+
|
|
21
|
+
it('should call execute on first command', () => (firstCommand.execute as SinonStub).called.should.be.true);
|
|
22
|
+
it('should not call execute on second command', () => (secondCommand.execute as SinonStub).called.should.be.false);
|
|
23
|
+
it('should call execute on third command', () => (thirdCommand.execute as SinonStub).called.should.be.true);
|
|
24
|
+
it('should not have any changes', () => scope.hasChanges.should.be.false);
|
|
25
|
+
});
|
package/commands/for_CommandScopeImplementation/when_none_of_the_added_commands_has_changes.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { CommandScopeImplementation } from '../CommandScopeImplementation';
|
|
5
|
+
import { FakeCommand } from './FakeCommand';
|
|
6
|
+
|
|
7
|
+
describe('when none of the added commands has changes', () => {
|
|
8
|
+
const scope = new CommandScopeImplementation(() => {});
|
|
9
|
+
|
|
10
|
+
const firstCommand = new FakeCommand(false);
|
|
11
|
+
const secondCommand = new FakeCommand(false);
|
|
12
|
+
const thirdCommand = new FakeCommand(false);
|
|
13
|
+
|
|
14
|
+
scope.addCommand(firstCommand);
|
|
15
|
+
scope.addCommand(secondCommand);
|
|
16
|
+
scope.addCommand(thirdCommand);
|
|
17
|
+
|
|
18
|
+
it('should not have changes', () => scope.hasChanges.should.be.false);
|
|
19
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { CommandScopeImplementation } from '../CommandScopeImplementation';
|
|
5
|
+
import { FakeCommand } from './FakeCommand';
|
|
6
|
+
|
|
7
|
+
describe('when one of the added commands has changes', () => {
|
|
8
|
+
const scope = new CommandScopeImplementation(() => {});
|
|
9
|
+
|
|
10
|
+
const firstCommand = new FakeCommand(false);
|
|
11
|
+
const secondCommand = new FakeCommand(true);
|
|
12
|
+
const thirdCommand = new FakeCommand(false);
|
|
13
|
+
|
|
14
|
+
scope.addCommand(firstCommand);
|
|
15
|
+
scope.addCommand(secondCommand);
|
|
16
|
+
scope.addCommand(thirdCommand);
|
|
17
|
+
|
|
18
|
+
it('should have changes', () => scope.hasChanges.should.be.true);
|
|
19
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import sinon from 'sinon';
|
|
5
|
+
import { CommandScopeImplementation } from '../CommandScopeImplementation';
|
|
6
|
+
import { PropertyChanged } from '@cratis/arc/commands';
|
|
7
|
+
import { FakeCommand } from './FakeCommand';
|
|
8
|
+
|
|
9
|
+
describe('when property changes on added command', () => {
|
|
10
|
+
const setHasChanges = sinon.stub();
|
|
11
|
+
const scope = new CommandScopeImplementation(setHasChanges);
|
|
12
|
+
let callbackToCall: PropertyChanged;
|
|
13
|
+
let thisArgForCallback: object = {};
|
|
14
|
+
|
|
15
|
+
const command = new FakeCommand(true);
|
|
16
|
+
command.onPropertyChanged = (callback: PropertyChanged, thisArg: object): void => {
|
|
17
|
+
callbackToCall = callback;
|
|
18
|
+
thisArgForCallback = thisArg;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
scope.addCommand(command);
|
|
22
|
+
|
|
23
|
+
callbackToCall!.call(thisArgForCallback, '');
|
|
24
|
+
|
|
25
|
+
it('should call set has changes', () => setHasChanges.called.should.be.true);
|
|
26
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { SinonStub } from 'sinon';
|
|
5
|
+
import { CommandScopeImplementation } from '../CommandScopeImplementation';
|
|
6
|
+
import { FakeCommand } from './FakeCommand';
|
|
7
|
+
|
|
8
|
+
describe('when reverting with three commands were two having changes', () => {
|
|
9
|
+
const scope = new CommandScopeImplementation(() => {});
|
|
10
|
+
|
|
11
|
+
const firstCommand = new FakeCommand(true);
|
|
12
|
+
const secondCommand = new FakeCommand(false);
|
|
13
|
+
const thirdCommand = new FakeCommand(true);
|
|
14
|
+
|
|
15
|
+
scope.addCommand(firstCommand);
|
|
16
|
+
scope.addCommand(secondCommand);
|
|
17
|
+
scope.addCommand(thirdCommand);
|
|
18
|
+
|
|
19
|
+
scope.revertChanges();
|
|
20
|
+
|
|
21
|
+
it('should call revert on first command', () => (firstCommand.revertChanges as SinonStub).called.should.be.true);
|
|
22
|
+
it('should call revert on second command', () => (secondCommand.revertChanges as SinonStub).called.should.be.true);
|
|
23
|
+
it('should call revert on third command', () => (thirdCommand.revertChanges as SinonStub).called.should.be.true);
|
|
24
|
+
it('should not have any changes', () => scope.hasChanges.should.be.false);
|
|
25
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { CommandScopeImplementation } from '../CommandScopeImplementation';
|
|
5
|
+
|
|
6
|
+
describe('when there are no commands', () => {
|
|
7
|
+
const scope = new CommandScopeImplementation(() => {});
|
|
8
|
+
|
|
9
|
+
it('should have no changes', () => scope.hasChanges.should.be.false);
|
|
10
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { Command, CommandValidator } from '@cratis/applications/commands';
|
|
5
|
+
import { PropertyDescriptor } from '@cratis/applications/reflection';
|
|
6
|
+
|
|
7
|
+
export interface FakeCommandContent {
|
|
8
|
+
someProperty?: string;
|
|
9
|
+
anotherProperty?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class FakeCommand extends Command<FakeCommandContent> {
|
|
13
|
+
readonly route = '/api/fake-command';
|
|
14
|
+
readonly validation = {} as CommandValidator;
|
|
15
|
+
readonly propertyDescriptors: PropertyDescriptor[] = [];
|
|
16
|
+
|
|
17
|
+
someProperty?: string;
|
|
18
|
+
anotherProperty?: number;
|
|
19
|
+
|
|
20
|
+
get requestParameters(): string[] {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get properties(): string[] {
|
|
25
|
+
return ['someProperty', 'anotherProperty'];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super(Object, false);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { render } from '@testing-library/react';
|
|
6
|
+
import { useCommand } from '../useCommand';
|
|
7
|
+
import { FakeCommand } from './FakeCommand';
|
|
8
|
+
import { ArcContext, ArcConfiguration } from '../../ArcContext';
|
|
9
|
+
|
|
10
|
+
describe('when creating instance', () => {
|
|
11
|
+
let capturedCommand: FakeCommand | null = null;
|
|
12
|
+
|
|
13
|
+
const TestComponent = () => {
|
|
14
|
+
const [command] = useCommand(FakeCommand);
|
|
15
|
+
capturedCommand = command;
|
|
16
|
+
return React.createElement('div', null, 'Test');
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const config: ArcConfiguration = {
|
|
20
|
+
microservice: 'test-microservice',
|
|
21
|
+
apiBasePath: '/api',
|
|
22
|
+
origin: 'https://example.com',
|
|
23
|
+
httpHeadersCallback: () => ({ 'X-Custom-Header': 'custom-value' })
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
render(
|
|
27
|
+
React.createElement(
|
|
28
|
+
ArcContext.Provider,
|
|
29
|
+
{ value: config },
|
|
30
|
+
React.createElement(TestComponent)
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
it('should set microservice from context', () => capturedCommand!['_microservice'].should.equal('test-microservice'));
|
|
35
|
+
it('should set api base path from context', () => capturedCommand!['_apiBasePath'].should.equal('/api'));
|
|
36
|
+
it('should set origin from context', () => capturedCommand!['_origin'].should.equal('https://example.com'));
|
|
37
|
+
it('should set http headers callback from context', () => {
|
|
38
|
+
const headers = capturedCommand!['_httpHeadersCallback']();
|
|
39
|
+
headers.should.deep.equal({ 'X-Custom-Header': 'custom-value' });
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { render } from '@testing-library/react';
|
|
6
|
+
import { useCommand } from '../useCommand';
|
|
7
|
+
import { FakeCommand, FakeCommandContent } from './FakeCommand';
|
|
8
|
+
import { ArcContext, ArcConfiguration } from '../../ArcContext';
|
|
9
|
+
|
|
10
|
+
describe('when creating instance with initial values', () => {
|
|
11
|
+
let capturedCommand: FakeCommand | null = null;
|
|
12
|
+
|
|
13
|
+
const initialValues: FakeCommandContent = {
|
|
14
|
+
someProperty: 'initial-value',
|
|
15
|
+
anotherProperty: 42
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const TestComponent = () => {
|
|
19
|
+
const [command] = useCommand(FakeCommand, initialValues);
|
|
20
|
+
capturedCommand = command;
|
|
21
|
+
return React.createElement('div', null, 'Test');
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const config: ArcConfiguration = {
|
|
25
|
+
microservice: 'test-microservice'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
render(
|
|
29
|
+
React.createElement(
|
|
30
|
+
ArcContext.Provider,
|
|
31
|
+
{ value: config },
|
|
32
|
+
React.createElement(TestComponent)
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
it('should set someProperty from initial values', () => capturedCommand!.someProperty!.should.equal('initial-value'));
|
|
37
|
+
it('should set anotherProperty from initial values', () => capturedCommand!.anotherProperty!.should.equal(42));
|
|
38
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { render } from '@testing-library/react';
|
|
6
|
+
import { useCommand } from '../useCommand';
|
|
7
|
+
import { FakeCommand } from './FakeCommand';
|
|
8
|
+
import { ArcContext, ArcConfiguration } from '../../ArcContext';
|
|
9
|
+
|
|
10
|
+
describe('when creating instance without optional context values', () => {
|
|
11
|
+
let capturedCommand: FakeCommand | null = null;
|
|
12
|
+
|
|
13
|
+
const TestComponent = () => {
|
|
14
|
+
const [command] = useCommand(FakeCommand);
|
|
15
|
+
capturedCommand = command;
|
|
16
|
+
return React.createElement('div', null, 'Test');
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const config: ArcConfiguration = {
|
|
20
|
+
microservice: 'test-microservice'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
render(
|
|
24
|
+
React.createElement(
|
|
25
|
+
ArcContext.Provider,
|
|
26
|
+
{ value: config },
|
|
27
|
+
React.createElement(TestComponent)
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
it('should set api base path to empty string', () => capturedCommand!['_apiBasePath'].should.equal(''));
|
|
32
|
+
it('should set origin to empty string', () => capturedCommand!['_origin'].should.equal(''));
|
|
33
|
+
it('should set http headers callback to return empty object', () => {
|
|
34
|
+
const headers = capturedCommand!['_httpHeadersCallback']();
|
|
35
|
+
headers.should.deep.equal({});
|
|
36
|
+
});
|
|
37
|
+
});
|