@cratis/arc 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/GetHttpHeaders.ts +7 -0
- package/Globals.ts +14 -0
- package/ICanBeConfigured.ts +33 -0
- package/README.md +65 -0
- package/UrlHelpers.ts +71 -0
- package/commands/Command.ts +209 -0
- package/commands/CommandResult.ts +203 -0
- package/commands/CommandResults.ts +105 -0
- package/commands/CommandValidator.ts +17 -0
- package/commands/ICommand.ts +82 -0
- package/commands/ICommandResult.ts +60 -0
- package/commands/for_Command/CommandWithRouteParams.ts +34 -0
- package/commands/for_Command/SomeCommand.ts +34 -0
- package/commands/for_Command/given/a_command.ts +18 -0
- package/commands/for_Command/when_clearing_the_command.ts +17 -0
- package/commands/for_Command/when_executing/and_command_route_not_found.ts +26 -0
- package/commands/for_Command/when_executing/and_fetch_throws_exception.ts +24 -0
- package/commands/for_Command/when_executing/with_command_properties.ts +40 -0
- package/commands/for_Command/when_executing/with_custom_http_headers.ts +60 -0
- package/commands/for_Command/when_executing/with_microservice_header.ts +55 -0
- package/commands/for_Command/when_executing/with_origin_and_api_base_path.ts +51 -0
- package/commands/for_Command/when_executing/with_route_parameters.ts +58 -0
- package/commands/for_Command/when_executing/with_successful_response.ts +51 -0
- package/commands/for_Command/when_property_changed_value_that_is_different_from_initial_value.ts +16 -0
- package/commands/for_Command/when_property_changed_value_that_is_same_as_initial_value.ts +16 -0
- package/commands/for_Command/when_property_changes_and_initial_value_is_undefined.ts +12 -0
- package/commands/for_Command/when_property_changes_and_there_is_a_callback.ts +15 -0
- package/commands/for_Command/when_property_has_changed_and_we_revert.ts +15 -0
- package/commands/for_Command/when_setting_initial_values_after_property_changed.ts +17 -0
- package/commands/for_Command/when_validating/and_fetch_throws_exception.ts +24 -0
- package/commands/for_Command/when_validating/and_validation_endpoint_not_found.ts +26 -0
- package/commands/for_Command/when_validating/does_not_update_initial_values.ts +39 -0
- package/commands/for_Command/when_validating/with_successful_response.ts +47 -0
- package/commands/for_Command/when_validating/with_validation_errors.ts +45 -0
- package/commands/for_CommandResult/when_chaining_callbacks/and_result_has_exceptions.ts +54 -0
- package/commands/for_CommandResult/when_chaining_callbacks/and_result_is_invalid.ts +53 -0
- package/commands/for_CommandResult/when_chaining_callbacks/and_result_is_successful.ts +42 -0
- package/commands/for_CommandResult/when_chaining_callbacks/and_result_is_unauthorized.ts +43 -0
- package/commands/index.ts +9 -0
- package/deepEqual.ts +23 -0
- package/dist/cjs/GetHttpHeaders.d.ts +2 -0
- package/dist/cjs/GetHttpHeaders.d.ts.map +1 -0
- package/dist/cjs/Globals.d.ts +7 -0
- package/dist/cjs/Globals.d.ts.map +1 -0
- package/dist/cjs/Globals.js +10 -0
- package/dist/cjs/Globals.js.map +1 -0
- package/dist/cjs/ICanBeConfigured.d.ts +8 -0
- package/dist/cjs/ICanBeConfigured.d.ts.map +1 -0
- package/dist/cjs/UrlHelpers.d.ts +9 -0
- package/dist/cjs/UrlHelpers.d.ts.map +1 -0
- package/dist/cjs/UrlHelpers.js +43 -0
- package/dist/cjs/UrlHelpers.js.map +1 -0
- package/dist/cjs/commands/Command.d.ts +41 -0
- package/dist/cjs/commands/Command.d.ts.map +1 -0
- package/dist/cjs/commands/Command.js +151 -0
- package/dist/cjs/commands/Command.js.map +1 -0
- package/dist/cjs/commands/CommandResult.d.ts +48 -0
- package/dist/cjs/commands/CommandResult.d.ts.map +1 -0
- package/dist/cjs/commands/CommandResult.js +95 -0
- package/dist/cjs/commands/CommandResult.js.map +1 -0
- package/dist/cjs/commands/CommandResults.d.ts +23 -0
- package/dist/cjs/commands/CommandResults.d.ts.map +1 -0
- package/dist/cjs/commands/CommandResults.js +72 -0
- package/dist/cjs/commands/CommandResults.js.map +1 -0
- package/dist/cjs/commands/CommandValidator.d.ts +9 -0
- package/dist/cjs/commands/CommandValidator.d.ts.map +1 -0
- package/dist/cjs/commands/CommandValidator.js +10 -0
- package/dist/cjs/commands/CommandValidator.js.map +1 -0
- package/dist/cjs/commands/ICommand.d.ts +18 -0
- package/dist/cjs/commands/ICommand.d.ts.map +1 -0
- package/dist/cjs/commands/ICommandResult.d.ts +15 -0
- package/dist/cjs/commands/ICommandResult.d.ts.map +1 -0
- package/dist/cjs/commands/index.d.ts +7 -0
- package/dist/cjs/commands/index.d.ts.map +1 -0
- package/dist/cjs/commands/index.js +14 -0
- package/dist/cjs/commands/index.js.map +1 -0
- package/dist/cjs/deepEqual.d.ts +2 -0
- package/dist/cjs/deepEqual.d.ts.map +1 -0
- package/dist/cjs/deepEqual.js +22 -0
- package/dist/cjs/deepEqual.js.map +1 -0
- package/dist/cjs/given.d.ts +5 -0
- package/dist/cjs/given.d.ts.map +1 -0
- package/dist/cjs/identity/IIdentity.d.ts +8 -0
- package/dist/cjs/identity/IIdentity.d.ts.map +1 -0
- package/dist/cjs/identity/IIdentityProvider.d.ts +5 -0
- package/dist/cjs/identity/IIdentityProvider.d.ts.map +1 -0
- package/dist/cjs/identity/IIdentityProvider.js +7 -0
- package/dist/cjs/identity/IIdentityProvider.js.map +1 -0
- package/dist/cjs/identity/IdentityProvider.d.ts +14 -0
- package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -0
- package/dist/cjs/identity/IdentityProvider.js +63 -0
- package/dist/cjs/identity/IdentityProvider.js.map +1 -0
- package/dist/cjs/identity/IdentityProviderResult.d.ts +6 -0
- package/dist/cjs/identity/IdentityProviderResult.d.ts.map +1 -0
- package/dist/cjs/identity/index.d.ts +5 -0
- package/dist/cjs/identity/index.d.ts.map +1 -0
- package/dist/cjs/identity/index.js +10 -0
- package/dist/cjs/identity/index.js.map +1 -0
- package/dist/cjs/index.d.ts +12 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/joinPaths.d.ts +2 -0
- package/dist/cjs/joinPaths.d.ts.map +1 -0
- package/dist/cjs/joinPaths.js +9 -0
- package/dist/cjs/joinPaths.js.map +1 -0
- package/dist/cjs/queries/IObservableQueryConnection.d.ts +6 -0
- package/dist/cjs/queries/IObservableQueryConnection.d.ts.map +1 -0
- package/dist/cjs/queries/IObservableQueryFor.d.ts +13 -0
- package/dist/cjs/queries/IObservableQueryFor.d.ts.map +1 -0
- package/dist/cjs/queries/IQuery.d.ts +10 -0
- package/dist/cjs/queries/IQuery.d.ts.map +1 -0
- package/dist/cjs/queries/IQueryFor.d.ts +12 -0
- package/dist/cjs/queries/IQueryFor.d.ts.map +1 -0
- package/dist/cjs/queries/IQueryProvider.d.ts +6 -0
- package/dist/cjs/queries/IQueryProvider.d.ts.map +1 -0
- package/dist/cjs/queries/IQueryProvider.js +7 -0
- package/dist/cjs/queries/IQueryProvider.js.map +1 -0
- package/dist/cjs/queries/IQueryResult.d.ts +15 -0
- package/dist/cjs/queries/IQueryResult.d.ts.map +1 -0
- package/dist/cjs/queries/NullObservableQueryConnection.d.ts +9 -0
- package/dist/cjs/queries/NullObservableQueryConnection.d.ts.map +1 -0
- package/dist/cjs/queries/NullObservableQueryConnection.js +18 -0
- package/dist/cjs/queries/NullObservableQueryConnection.js.map +1 -0
- package/dist/cjs/queries/ObservableQueryConnection.d.ts +14 -0
- package/dist/cjs/queries/ObservableQueryConnection.d.ts.map +1 -0
- package/dist/cjs/queries/ObservableQueryConnection.js +101 -0
- package/dist/cjs/queries/ObservableQueryConnection.js.map +1 -0
- package/dist/cjs/queries/ObservableQueryFor.d.ts +37 -0
- package/dist/cjs/queries/ObservableQueryFor.d.ts.map +1 -0
- package/dist/cjs/queries/ObservableQueryFor.js +176 -0
- package/dist/cjs/queries/ObservableQueryFor.js.map +1 -0
- package/dist/cjs/queries/ObservableQuerySubscription.d.ts +7 -0
- package/dist/cjs/queries/ObservableQuerySubscription.d.ts.map +1 -0
- package/dist/cjs/queries/ObservableQuerySubscription.js +17 -0
- package/dist/cjs/queries/ObservableQuerySubscription.js.map +1 -0
- package/dist/cjs/queries/Paging.d.ts +8 -0
- package/dist/cjs/queries/Paging.d.ts.map +1 -0
- package/dist/cjs/queries/Paging.js +17 -0
- package/dist/cjs/queries/Paging.js.map +1 -0
- package/dist/cjs/queries/PagingInfo.d.ts +9 -0
- package/dist/cjs/queries/PagingInfo.d.ts.map +1 -0
- package/dist/cjs/queries/PagingInfo.js +18 -0
- package/dist/cjs/queries/PagingInfo.js.map +1 -0
- package/dist/cjs/queries/QueryFor.d.ts +30 -0
- package/dist/cjs/queries/QueryFor.d.ts.map +1 -0
- package/dist/cjs/queries/QueryFor.js +101 -0
- package/dist/cjs/queries/QueryFor.js.map +1 -0
- package/dist/cjs/queries/QueryProvider.d.ts +13 -0
- package/dist/cjs/queries/QueryProvider.d.ts.map +1 -0
- package/dist/cjs/queries/QueryProvider.js +25 -0
- package/dist/cjs/queries/QueryProvider.js.map +1 -0
- package/dist/cjs/queries/QueryResult.d.ts +44 -0
- package/dist/cjs/queries/QueryResult.d.ts.map +1 -0
- package/dist/cjs/queries/QueryResult.js +95 -0
- package/dist/cjs/queries/QueryResult.js.map +1 -0
- package/dist/cjs/queries/QueryResultWithState.d.ts +22 -0
- package/dist/cjs/queries/QueryResultWithState.d.ts.map +1 -0
- package/dist/cjs/queries/QueryResultWithState.js +46 -0
- package/dist/cjs/queries/QueryResultWithState.js.map +1 -0
- package/dist/cjs/queries/SortDirection.d.ts +6 -0
- package/dist/cjs/queries/SortDirection.d.ts.map +1 -0
- package/dist/cjs/queries/SortDirection.js +9 -0
- package/dist/cjs/queries/SortDirection.js.map +1 -0
- package/dist/cjs/queries/Sorting.d.ts +9 -0
- package/dist/cjs/queries/Sorting.d.ts.map +1 -0
- package/dist/cjs/queries/Sorting.js +19 -0
- package/dist/cjs/queries/Sorting.js.map +1 -0
- package/dist/cjs/queries/SortingActions.d.ts +10 -0
- package/dist/cjs/queries/SortingActions.d.ts.map +1 -0
- package/dist/cjs/queries/SortingActions.js +24 -0
- package/dist/cjs/queries/SortingActions.js.map +1 -0
- package/dist/cjs/queries/SortingActionsForObservableQuery.d.ts +10 -0
- package/dist/cjs/queries/SortingActionsForObservableQuery.d.ts.map +1 -0
- package/dist/cjs/queries/SortingActionsForObservableQuery.js +24 -0
- package/dist/cjs/queries/SortingActionsForObservableQuery.js.map +1 -0
- package/dist/cjs/queries/SortingActionsForQuery.d.ts +10 -0
- package/dist/cjs/queries/SortingActionsForQuery.d.ts.map +1 -0
- package/dist/cjs/queries/SortingActionsForQuery.js +24 -0
- package/dist/cjs/queries/SortingActionsForQuery.js.map +1 -0
- package/dist/cjs/queries/ValidateRequestArguments.d.ts +2 -0
- package/dist/cjs/queries/ValidateRequestArguments.d.ts.map +1 -0
- package/dist/cjs/queries/ValidateRequestArguments.js +29 -0
- package/dist/cjs/queries/ValidateRequestArguments.js.map +1 -0
- package/dist/cjs/queries/index.d.ts +19 -0
- package/dist/cjs/queries/index.d.ts.map +1 -0
- package/dist/cjs/queries/index.js +37 -0
- package/dist/cjs/queries/index.js.map +1 -0
- package/dist/cjs/reflection/IHaveParameters.d.ts +5 -0
- package/dist/cjs/reflection/IHaveParameters.d.ts.map +1 -0
- package/dist/cjs/reflection/ParameterDescriptor.d.ts +7 -0
- package/dist/cjs/reflection/ParameterDescriptor.d.ts.map +1 -0
- package/dist/cjs/reflection/ParameterDescriptor.js +13 -0
- package/dist/cjs/reflection/ParameterDescriptor.js.map +1 -0
- package/dist/cjs/reflection/ParametersHelper.d.ts +5 -0
- package/dist/cjs/reflection/ParametersHelper.d.ts.map +1 -0
- package/dist/cjs/reflection/ParametersHelper.js +17 -0
- package/dist/cjs/reflection/ParametersHelper.js.map +1 -0
- package/dist/cjs/reflection/PropertyDescriptor.d.ts +7 -0
- package/dist/cjs/reflection/PropertyDescriptor.d.ts.map +1 -0
- package/dist/cjs/reflection/PropertyDescriptor.js +13 -0
- package/dist/cjs/reflection/PropertyDescriptor.js.map +1 -0
- package/dist/cjs/reflection/index.d.ts +5 -0
- package/dist/cjs/reflection/index.d.ts.map +1 -0
- package/dist/cjs/reflection/index.js +12 -0
- package/dist/cjs/reflection/index.js.map +1 -0
- package/dist/cjs/validation/ValidationResult.d.ts +9 -0
- package/dist/cjs/validation/ValidationResult.d.ts.map +1 -0
- package/dist/cjs/validation/ValidationResult.js +17 -0
- package/dist/cjs/validation/ValidationResult.js.map +1 -0
- package/dist/cjs/validation/ValidationResultSeverity.d.ts +7 -0
- package/dist/cjs/validation/ValidationResultSeverity.d.ts.map +1 -0
- package/dist/cjs/validation/Validator.d.ts +4 -0
- package/dist/cjs/validation/Validator.d.ts.map +1 -0
- package/dist/cjs/validation/Validator.js +10 -0
- package/dist/cjs/validation/Validator.js.map +1 -0
- package/dist/cjs/validation/index.d.ts +3 -0
- package/dist/cjs/validation/index.d.ts.map +1 -0
- package/dist/cjs/validation/index.js +10 -0
- package/dist/cjs/validation/index.js.map +1 -0
- package/dist/esm/GetHttpHeaders.d.ts +2 -0
- package/dist/esm/GetHttpHeaders.d.ts.map +1 -0
- package/dist/esm/GetHttpHeaders.js +2 -0
- package/dist/esm/GetHttpHeaders.js.map +1 -0
- package/dist/esm/Globals.d.ts +7 -0
- package/dist/esm/Globals.d.ts.map +1 -0
- package/dist/esm/Globals.js +8 -0
- package/dist/esm/Globals.js.map +1 -0
- package/dist/esm/ICanBeConfigured.d.ts +8 -0
- package/dist/esm/ICanBeConfigured.d.ts.map +1 -0
- package/dist/esm/ICanBeConfigured.js +2 -0
- package/dist/esm/ICanBeConfigured.js.map +1 -0
- package/dist/esm/UrlHelpers.d.ts +9 -0
- package/dist/esm/UrlHelpers.d.ts.map +1 -0
- package/dist/esm/UrlHelpers.js +41 -0
- package/dist/esm/UrlHelpers.js.map +1 -0
- package/dist/esm/commands/Command.d.ts +41 -0
- package/dist/esm/commands/Command.d.ts.map +1 -0
- package/dist/esm/commands/Command.js +149 -0
- package/dist/esm/commands/Command.js.map +1 -0
- package/dist/esm/commands/CommandResult.d.ts +48 -0
- package/dist/esm/commands/CommandResult.d.ts.map +1 -0
- package/dist/esm/commands/CommandResult.js +93 -0
- package/dist/esm/commands/CommandResult.js.map +1 -0
- package/dist/esm/commands/CommandResults.d.ts +23 -0
- package/dist/esm/commands/CommandResults.d.ts.map +1 -0
- package/dist/esm/commands/CommandResults.js +70 -0
- package/dist/esm/commands/CommandResults.js.map +1 -0
- package/dist/esm/commands/CommandValidator.d.ts +9 -0
- package/dist/esm/commands/CommandValidator.d.ts.map +1 -0
- package/dist/esm/commands/CommandValidator.js +8 -0
- package/dist/esm/commands/CommandValidator.js.map +1 -0
- package/dist/esm/commands/ICommand.d.ts +18 -0
- package/dist/esm/commands/ICommand.d.ts.map +1 -0
- package/dist/esm/commands/ICommand.js +2 -0
- package/dist/esm/commands/ICommand.js.map +1 -0
- package/dist/esm/commands/ICommandResult.d.ts +15 -0
- package/dist/esm/commands/ICommandResult.d.ts.map +1 -0
- package/dist/esm/commands/ICommandResult.js +2 -0
- package/dist/esm/commands/ICommandResult.js.map +1 -0
- package/dist/esm/commands/index.d.ts +7 -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/deepEqual.d.ts +2 -0
- package/dist/esm/deepEqual.d.ts.map +1 -0
- package/dist/esm/deepEqual.js +20 -0
- package/dist/esm/deepEqual.js.map +1 -0
- package/dist/esm/given.d.ts +5 -0
- package/dist/esm/given.d.ts.map +1 -0
- package/dist/esm/given.js +7 -0
- package/dist/esm/given.js.map +1 -0
- package/dist/esm/identity/IIdentity.d.ts +8 -0
- package/dist/esm/identity/IIdentity.d.ts.map +1 -0
- package/dist/esm/identity/IIdentity.js +2 -0
- package/dist/esm/identity/IIdentity.js.map +1 -0
- package/dist/esm/identity/IIdentityProvider.d.ts +5 -0
- package/dist/esm/identity/IIdentityProvider.d.ts.map +1 -0
- package/dist/esm/identity/IIdentityProvider.js +5 -0
- package/dist/esm/identity/IIdentityProvider.js.map +1 -0
- package/dist/esm/identity/IdentityProvider.d.ts +14 -0
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -0
- package/dist/esm/identity/IdentityProvider.js +61 -0
- package/dist/esm/identity/IdentityProvider.js.map +1 -0
- package/dist/esm/identity/IdentityProviderResult.d.ts +6 -0
- package/dist/esm/identity/IdentityProviderResult.d.ts.map +1 -0
- package/dist/esm/identity/IdentityProviderResult.js +2 -0
- package/dist/esm/identity/IdentityProviderResult.js.map +1 -0
- package/dist/esm/identity/index.d.ts +5 -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/index.d.ts +12 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/joinPaths.d.ts +2 -0
- package/dist/esm/joinPaths.d.ts.map +1 -0
- package/dist/esm/joinPaths.js +7 -0
- package/dist/esm/joinPaths.js.map +1 -0
- package/dist/esm/queries/IObservableQueryConnection.d.ts +6 -0
- package/dist/esm/queries/IObservableQueryConnection.d.ts.map +1 -0
- package/dist/esm/queries/IObservableQueryConnection.js +2 -0
- package/dist/esm/queries/IObservableQueryConnection.js.map +1 -0
- package/dist/esm/queries/IObservableQueryFor.d.ts +13 -0
- package/dist/esm/queries/IObservableQueryFor.d.ts.map +1 -0
- package/dist/esm/queries/IObservableQueryFor.js +2 -0
- package/dist/esm/queries/IObservableQueryFor.js.map +1 -0
- package/dist/esm/queries/IQuery.d.ts +10 -0
- package/dist/esm/queries/IQuery.d.ts.map +1 -0
- package/dist/esm/queries/IQuery.js +2 -0
- package/dist/esm/queries/IQuery.js.map +1 -0
- package/dist/esm/queries/IQueryFor.d.ts +12 -0
- package/dist/esm/queries/IQueryFor.d.ts.map +1 -0
- package/dist/esm/queries/IQueryFor.js +2 -0
- package/dist/esm/queries/IQueryFor.js.map +1 -0
- package/dist/esm/queries/IQueryProvider.d.ts +6 -0
- package/dist/esm/queries/IQueryProvider.d.ts.map +1 -0
- package/dist/esm/queries/IQueryProvider.js +5 -0
- package/dist/esm/queries/IQueryProvider.js.map +1 -0
- package/dist/esm/queries/IQueryResult.d.ts +15 -0
- package/dist/esm/queries/IQueryResult.d.ts.map +1 -0
- package/dist/esm/queries/IQueryResult.js +2 -0
- package/dist/esm/queries/IQueryResult.js.map +1 -0
- package/dist/esm/queries/NullObservableQueryConnection.d.ts +9 -0
- package/dist/esm/queries/NullObservableQueryConnection.d.ts.map +1 -0
- package/dist/esm/queries/NullObservableQueryConnection.js +16 -0
- package/dist/esm/queries/NullObservableQueryConnection.js.map +1 -0
- package/dist/esm/queries/ObservableQueryConnection.d.ts +14 -0
- package/dist/esm/queries/ObservableQueryConnection.d.ts.map +1 -0
- package/dist/esm/queries/ObservableQueryConnection.js +99 -0
- package/dist/esm/queries/ObservableQueryConnection.js.map +1 -0
- package/dist/esm/queries/ObservableQueryFor.d.ts +37 -0
- package/dist/esm/queries/ObservableQueryFor.d.ts.map +1 -0
- package/dist/esm/queries/ObservableQueryFor.js +174 -0
- package/dist/esm/queries/ObservableQueryFor.js.map +1 -0
- package/dist/esm/queries/ObservableQuerySubscription.d.ts +7 -0
- package/dist/esm/queries/ObservableQuerySubscription.d.ts.map +1 -0
- package/dist/esm/queries/ObservableQuerySubscription.js +15 -0
- package/dist/esm/queries/ObservableQuerySubscription.js.map +1 -0
- package/dist/esm/queries/Paging.d.ts +8 -0
- package/dist/esm/queries/Paging.d.ts.map +1 -0
- package/dist/esm/queries/Paging.js +15 -0
- package/dist/esm/queries/Paging.js.map +1 -0
- package/dist/esm/queries/PagingInfo.d.ts +9 -0
- package/dist/esm/queries/PagingInfo.d.ts.map +1 -0
- package/dist/esm/queries/PagingInfo.js +16 -0
- package/dist/esm/queries/PagingInfo.js.map +1 -0
- package/dist/esm/queries/QueryFor.d.ts +30 -0
- package/dist/esm/queries/QueryFor.d.ts.map +1 -0
- package/dist/esm/queries/QueryFor.js +99 -0
- package/dist/esm/queries/QueryFor.js.map +1 -0
- package/dist/esm/queries/QueryProvider.d.ts +13 -0
- package/dist/esm/queries/QueryProvider.d.ts.map +1 -0
- package/dist/esm/queries/QueryProvider.js +23 -0
- package/dist/esm/queries/QueryProvider.js.map +1 -0
- package/dist/esm/queries/QueryResult.d.ts +44 -0
- package/dist/esm/queries/QueryResult.d.ts.map +1 -0
- package/dist/esm/queries/QueryResult.js +93 -0
- package/dist/esm/queries/QueryResult.js.map +1 -0
- package/dist/esm/queries/QueryResultWithState.d.ts +22 -0
- package/dist/esm/queries/QueryResultWithState.d.ts.map +1 -0
- package/dist/esm/queries/QueryResultWithState.js +44 -0
- package/dist/esm/queries/QueryResultWithState.js.map +1 -0
- package/dist/esm/queries/SortDirection.d.ts +6 -0
- package/dist/esm/queries/SortDirection.d.ts.map +1 -0
- package/dist/esm/queries/SortDirection.js +9 -0
- package/dist/esm/queries/SortDirection.js.map +1 -0
- package/dist/esm/queries/Sorting.d.ts +9 -0
- package/dist/esm/queries/Sorting.d.ts.map +1 -0
- package/dist/esm/queries/Sorting.js +17 -0
- package/dist/esm/queries/Sorting.js.map +1 -0
- package/dist/esm/queries/SortingActions.d.ts +10 -0
- package/dist/esm/queries/SortingActions.d.ts.map +1 -0
- package/dist/esm/queries/SortingActions.js +22 -0
- package/dist/esm/queries/SortingActions.js.map +1 -0
- package/dist/esm/queries/SortingActionsForObservableQuery.d.ts +10 -0
- package/dist/esm/queries/SortingActionsForObservableQuery.d.ts.map +1 -0
- package/dist/esm/queries/SortingActionsForObservableQuery.js +22 -0
- package/dist/esm/queries/SortingActionsForObservableQuery.js.map +1 -0
- package/dist/esm/queries/SortingActionsForQuery.d.ts +10 -0
- package/dist/esm/queries/SortingActionsForQuery.d.ts.map +1 -0
- package/dist/esm/queries/SortingActionsForQuery.js +22 -0
- package/dist/esm/queries/SortingActionsForQuery.js.map +1 -0
- package/dist/esm/queries/ValidateRequestArguments.d.ts +2 -0
- package/dist/esm/queries/ValidateRequestArguments.d.ts.map +1 -0
- package/dist/esm/queries/ValidateRequestArguments.js +27 -0
- package/dist/esm/queries/ValidateRequestArguments.js.map +1 -0
- package/dist/esm/queries/index.d.ts +19 -0
- package/dist/esm/queries/index.d.ts.map +1 -0
- package/dist/esm/queries/index.js +15 -0
- package/dist/esm/queries/index.js.map +1 -0
- package/dist/esm/reflection/IHaveParameters.d.ts +5 -0
- package/dist/esm/reflection/IHaveParameters.d.ts.map +1 -0
- package/dist/esm/reflection/IHaveParameters.js +2 -0
- package/dist/esm/reflection/IHaveParameters.js.map +1 -0
- package/dist/esm/reflection/ParameterDescriptor.d.ts +7 -0
- package/dist/esm/reflection/ParameterDescriptor.d.ts.map +1 -0
- package/dist/esm/reflection/ParameterDescriptor.js +11 -0
- package/dist/esm/reflection/ParameterDescriptor.js.map +1 -0
- package/dist/esm/reflection/ParametersHelper.d.ts +5 -0
- package/dist/esm/reflection/ParametersHelper.d.ts.map +1 -0
- package/dist/esm/reflection/ParametersHelper.js +15 -0
- package/dist/esm/reflection/ParametersHelper.js.map +1 -0
- package/dist/esm/reflection/PropertyDescriptor.d.ts +7 -0
- package/dist/esm/reflection/PropertyDescriptor.d.ts.map +1 -0
- package/dist/esm/reflection/PropertyDescriptor.js +11 -0
- package/dist/esm/reflection/PropertyDescriptor.js.map +1 -0
- package/dist/esm/reflection/index.d.ts +5 -0
- package/dist/esm/reflection/index.d.ts.map +1 -0
- package/dist/esm/reflection/index.js +4 -0
- package/dist/esm/reflection/index.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -0
- package/dist/esm/validation/ValidationResult.d.ts +9 -0
- package/dist/esm/validation/ValidationResult.d.ts.map +1 -0
- package/dist/esm/validation/ValidationResult.js +15 -0
- package/dist/esm/validation/ValidationResult.js.map +1 -0
- package/dist/esm/validation/ValidationResultSeverity.d.ts +7 -0
- package/dist/esm/validation/ValidationResultSeverity.d.ts.map +1 -0
- package/dist/esm/validation/ValidationResultSeverity.js +8 -0
- package/dist/esm/validation/ValidationResultSeverity.js.map +1 -0
- package/dist/esm/validation/Validator.d.ts +4 -0
- package/dist/esm/validation/Validator.d.ts.map +1 -0
- package/dist/esm/validation/Validator.js +8 -0
- package/dist/esm/validation/Validator.js.map +1 -0
- package/dist/esm/validation/index.d.ts +3 -0
- package/dist/esm/validation/index.d.ts.map +1 -0
- package/dist/esm/validation/index.js +3 -0
- package/dist/esm/validation/index.js.map +1 -0
- package/for_UrlHelpers/when_building_query_params/with_additional_parameters.ts +23 -0
- package/for_UrlHelpers/when_building_query_params/with_empty_parameters.ts +16 -0
- package/for_UrlHelpers/when_building_query_params/with_null_and_undefined_values.ts +22 -0
- package/for_UrlHelpers/when_building_query_params/with_unused_parameters_only.ts +21 -0
- package/for_UrlHelpers/when_creating_url_from/with_base_path_ending_with_slash.ts +32 -0
- package/for_UrlHelpers/when_creating_url_from/with_empty_origin.ts +45 -0
- package/for_UrlHelpers/when_creating_url_from/with_null_or_undefined_origin.ts +53 -0
- package/for_UrlHelpers/when_creating_url_from/with_relative_route.ts +32 -0
- package/for_UrlHelpers/when_creating_url_from/with_valid_parameters.ts +32 -0
- package/for_UrlHelpers/when_creating_url_from/without_document_object.ts +34 -0
- package/for_UrlHelpers/when_replacing_route_parameters/with_all_parameters_used_in_route.ts +21 -0
- package/for_UrlHelpers/when_replacing_route_parameters/with_no_parameters.ts +19 -0
- package/for_UrlHelpers/when_replacing_route_parameters/with_unused_parameters.ts +23 -0
- package/for_UrlHelpers/when_replacing_route_parameters/with_url_encoded_values.ts +20 -0
- package/given.ts +14 -0
- package/identity/IIdentity.ts +33 -0
- package/identity/IIdentityProvider.ts +16 -0
- package/identity/IdentityProvider.ts +85 -0
- package/identity/IdentityProviderResult.ts +8 -0
- package/identity/index.ts +7 -0
- package/index.ts +21 -0
- package/joinPaths.ts +7 -0
- package/package.json +70 -0
- package/queries/IObservableQueryConnection.ts +21 -0
- package/queries/IObservableQueryFor.ts +38 -0
- package/queries/IQuery.ts +31 -0
- package/queries/IQueryFor.ts +36 -0
- package/queries/IQueryProvider.ts +17 -0
- package/queries/IQueryResult.ts +60 -0
- package/queries/NullObservableQueryConnection.ts +29 -0
- package/queries/ObservableQueryConnection.ts +118 -0
- package/queries/ObservableQueryFor.ts +230 -0
- package/queries/ObservableQuerySubscription.ts +27 -0
- package/queries/Paging.ts +38 -0
- package/queries/PagingInfo.ts +43 -0
- package/queries/QueryFor.ts +138 -0
- package/queries/QueryProvider.ts +36 -0
- package/queries/QueryResult.ts +157 -0
- package/queries/QueryResultWithState.ts +95 -0
- package/queries/SortDirection.ts +22 -0
- package/queries/Sorting.ts +30 -0
- package/queries/SortingActions.ts +36 -0
- package/queries/SortingActionsForObservableQuery.ts +36 -0
- package/queries/SortingActionsForQuery.ts +36 -0
- package/queries/ValidateRequestArguments.ts +36 -0
- package/queries/for_ObservableQueryFor/given/TestQueries.ts +58 -0
- package/queries/for_ObservableQueryFor/given/an_observable_query_for.ts +16 -0
- package/queries/for_ObservableQueryFor/when_constructing.ts +32 -0
- package/queries/for_ObservableQueryFor/when_constructing_enumerable.ts +18 -0
- package/queries/for_ObservableQueryFor/when_disposing.ts +28 -0
- package/queries/for_ObservableQueryFor/when_performing/with_enumerable_query.ts +61 -0
- package/queries/for_ObservableQueryFor/when_performing/with_invalid_arguments.ts +22 -0
- package/queries/for_ObservableQueryFor/when_performing/with_paging.ts +55 -0
- package/queries/for_ObservableQueryFor/when_performing/with_parameter_descriptor_values.ts +68 -0
- package/queries/for_ObservableQueryFor/when_performing/with_partial_parameter_descriptor_values.ts +67 -0
- package/queries/for_ObservableQueryFor/when_performing/with_route_parameters_and_unused_parameters.ts +71 -0
- package/queries/for_ObservableQueryFor/when_performing/with_sorting.ts +56 -0
- package/queries/for_ObservableQueryFor/when_performing/with_valid_arguments.ts +79 -0
- package/queries/for_ObservableQueryFor/when_setting_api_base_path.ts +17 -0
- package/queries/for_ObservableQueryFor/when_setting_microservice.ts +17 -0
- package/queries/for_ObservableQueryFor/when_setting_origin.ts +17 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_enumerable_query.ts +34 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_invalid_arguments.ts +40 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_paging.ts +36 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_sorting.ts +37 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_valid_arguments.ts +35 -0
- package/queries/for_QueryFor/given/TestQueries.ts +72 -0
- package/queries/for_QueryFor/given/a_query_for.ts +18 -0
- package/queries/for_QueryFor/when_constructing.ts +31 -0
- package/queries/for_QueryFor/when_constructing_enumerable.ts +17 -0
- package/queries/for_QueryFor/when_performing/with_abort_controller.ts +71 -0
- package/queries/for_QueryFor/when_performing/with_enumerable_query.ts +62 -0
- package/queries/for_QueryFor/when_performing/with_fetch_error.ts +47 -0
- package/queries/for_QueryFor/when_performing/with_invalid_arguments.ts +29 -0
- package/queries/for_QueryFor/when_performing/with_json_parse_error.ts +45 -0
- package/queries/for_QueryFor/when_performing/with_paging.ts +62 -0
- package/queries/for_QueryFor/when_performing/with_parameter_descriptor_values.ts +68 -0
- package/queries/for_QueryFor/when_performing/with_partial_parameter_descriptor_values.ts +67 -0
- package/queries/for_QueryFor/when_performing/with_query_without_required_parameters.ts +58 -0
- package/queries/for_QueryFor/when_performing/with_route_parameters_and_unused_parameters.ts +71 -0
- package/queries/for_QueryFor/when_performing/with_sorting.ts +99 -0
- package/queries/for_QueryFor/when_performing/with_valid_arguments.ts +87 -0
- package/queries/for_QueryFor/when_setting_api_base_path.ts +19 -0
- package/queries/for_QueryFor/when_setting_microservice.ts +19 -0
- package/queries/for_QueryFor/when_setting_origin.ts +19 -0
- package/queries/for_QueryResult/when_asking_has_data/and_it_an_array_with_items.ts +27 -0
- package/queries/for_QueryResult/when_asking_has_data/and_it_is_defined_instance.ts +27 -0
- package/queries/for_QueryResult/when_asking_has_data/and_it_is_empty_array.ts +27 -0
- package/queries/for_QueryResult/when_asking_has_data/and_it_is_undefined.ts +27 -0
- package/queries/index.ts +21 -0
- package/reflection/IHaveParameters.ts +11 -0
- package/reflection/ParameterDescriptor.ts +17 -0
- package/reflection/ParametersHelper.ts +25 -0
- package/reflection/PropertyDescriptor.ts +17 -0
- package/reflection/index.ts +7 -0
- package/validation/ValidationResult.ts +16 -0
- package/validation/ValidationResultSeverity.ts +28 -0
- package/validation/Validator.ts +15 -0
- package/validation/index.ts +5 -0
package/Globals.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export interface IGlobals {
|
|
5
|
+
microservice: string;
|
|
6
|
+
microserviceHttpHeader: string;
|
|
7
|
+
microserviceWSQueryArgument: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Globals: IGlobals = {
|
|
11
|
+
microservice: '',
|
|
12
|
+
microserviceHttpHeader: 'x-cratis-microservice',
|
|
13
|
+
microserviceWSQueryArgument: 'x-cratis-microservice'
|
|
14
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
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 } from 'GetHttpHeaders';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents the concept of something that can be configured.
|
|
8
|
+
*/
|
|
9
|
+
export interface ICanBeConfigured {
|
|
10
|
+
/**
|
|
11
|
+
* Set the microservice to be used for the query. This is passed along to the server to identify the microservice.
|
|
12
|
+
* @param microservice Name of microservice
|
|
13
|
+
*/
|
|
14
|
+
setMicroservice(microservice: string);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Set the base path for the API to use for the query. This is used to prepend to the path to any fetch operation.
|
|
18
|
+
* @param apiBasePath Base path for the API
|
|
19
|
+
*/
|
|
20
|
+
setApiBasePath(apiBasePath: string): void;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Set the origin to be used for the query. This is used to set the origin (scheme + host + port) for API calls.
|
|
24
|
+
* @param origin The origin to use.
|
|
25
|
+
*/
|
|
26
|
+
setOrigin(origin: string): void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Set the callback to call for getting additional Http headers for Web requests.
|
|
30
|
+
* @param callback Callback that gets called.
|
|
31
|
+
*/
|
|
32
|
+
setHttpHeadersCallback(callback: GetHttpHeaders): void;
|
|
33
|
+
}
|
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
|
+
```
|
package/UrlHelpers.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
export class UrlHelpers {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a URL from the given origin, API base path, and route.
|
|
7
|
+
* @param origin The origin of the request. If not provided, it defaults to the current document's origin.
|
|
8
|
+
* @param apiBasePath The base path for the API.
|
|
9
|
+
* @param route The specific route for the request.
|
|
10
|
+
* @returns The constructed URL.
|
|
11
|
+
*/
|
|
12
|
+
static createUrlFrom(origin: string, apiBasePath: string, route: string): URL {
|
|
13
|
+
if ((!origin || origin.length === 0) && typeof document !== 'undefined') {
|
|
14
|
+
origin = document.location?.origin ?? '';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return new URL(route, `${origin}${apiBasePath}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Replaces route parameters in the route template with values from the parameters object.
|
|
22
|
+
* Returns both the updated route and the parameters that were not used in the route.
|
|
23
|
+
* @param route The route template with placeholders like {paramName}.
|
|
24
|
+
* @param parameters The parameters to replace in the route.
|
|
25
|
+
* @returns An object containing the updated route and unused parameters.
|
|
26
|
+
*/
|
|
27
|
+
static replaceRouteParameters<T extends object>(route: string, parameters?: T): { route: string; unusedParameters: Partial<T> } {
|
|
28
|
+
if (!parameters) {
|
|
29
|
+
return { route, unusedParameters: {} };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let result = route;
|
|
33
|
+
const unusedParameters: Partial<T> = { ...parameters };
|
|
34
|
+
|
|
35
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
36
|
+
const pattern = new RegExp(`\\{${key}\\}`, 'gi');
|
|
37
|
+
const newRoute = result.replace(pattern, encodeURIComponent(String(value)));
|
|
38
|
+
|
|
39
|
+
if (newRoute !== result) {
|
|
40
|
+
delete unusedParameters[key as keyof T];
|
|
41
|
+
result = newRoute;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { route: result, unusedParameters };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Builds URLSearchParams from the given parameters and additional query parameters.
|
|
50
|
+
* @param unusedParameters Parameters that were not used in route replacement.
|
|
51
|
+
* @param additionalParams Additional query parameters to include.
|
|
52
|
+
* @returns URLSearchParams containing all parameters.
|
|
53
|
+
*/
|
|
54
|
+
static buildQueryParams(unusedParameters: object, additionalParams?: Record<string, string | number>): URLSearchParams {
|
|
55
|
+
const queryParams = new URLSearchParams();
|
|
56
|
+
|
|
57
|
+
for (const [key, value] of Object.entries(unusedParameters)) {
|
|
58
|
+
if (value !== undefined && value !== null) {
|
|
59
|
+
queryParams.set(key, String(value));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (additionalParams) {
|
|
64
|
+
for (const [key, value] of Object.entries(additionalParams)) {
|
|
65
|
+
queryParams.set(key, String(value));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return queryParams;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
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, PropertyChanged } from './ICommand';
|
|
5
|
+
import { CommandResult } from "./CommandResult";
|
|
6
|
+
import { CommandValidator } from './CommandValidator';
|
|
7
|
+
import { Constructor, JsonSerializer } from '@cratis/fundamentals';
|
|
8
|
+
import { Globals } from '../Globals';
|
|
9
|
+
import { joinPaths } from '../joinPaths';
|
|
10
|
+
import { UrlHelpers } from '../UrlHelpers';
|
|
11
|
+
import { GetHttpHeaders } from '../GetHttpHeaders';
|
|
12
|
+
import { PropertyDescriptor } from '../reflection/PropertyDescriptor';
|
|
13
|
+
|
|
14
|
+
type Callback = {
|
|
15
|
+
callback: WeakRef<PropertyChanged>;
|
|
16
|
+
thisArg: WeakRef<object>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Represents an implementation of {@link ICommand} that works with HTTP fetch.
|
|
21
|
+
*/
|
|
22
|
+
export abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {
|
|
23
|
+
private _microservice: string;
|
|
24
|
+
private _apiBasePath: string;
|
|
25
|
+
private _origin: string;
|
|
26
|
+
private _httpHeadersCallback: GetHttpHeaders;
|
|
27
|
+
abstract readonly route: string;
|
|
28
|
+
abstract readonly validation: CommandValidator;
|
|
29
|
+
abstract readonly propertyDescriptors: PropertyDescriptor[];
|
|
30
|
+
abstract get requestParameters(): string[];
|
|
31
|
+
abstract get properties(): string[];
|
|
32
|
+
|
|
33
|
+
private _initialValues: object = {};
|
|
34
|
+
private _hasChanges = false;
|
|
35
|
+
private _callbacks: Callback[] = [];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Initializes a new instance of the {@link Command<,>} class.
|
|
39
|
+
* @param _responseType Type of response.
|
|
40
|
+
* @param _isResponseTypeEnumerable Whether or not the response type is enumerable.
|
|
41
|
+
*/
|
|
42
|
+
constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {
|
|
43
|
+
this._microservice = Globals.microservice ?? '';
|
|
44
|
+
this._apiBasePath = '';
|
|
45
|
+
this._origin = '';
|
|
46
|
+
this._httpHeadersCallback = () => ({});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @inheritdoc */
|
|
50
|
+
setMicroservice(microservice: string) {
|
|
51
|
+
this._microservice = microservice;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @inheritdoc */
|
|
55
|
+
setApiBasePath(apiBasePath: string): void {
|
|
56
|
+
this._apiBasePath = apiBasePath;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @inheritdoc */
|
|
60
|
+
setOrigin(origin: string): void {
|
|
61
|
+
this._origin = origin;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** @inheritdoc */
|
|
65
|
+
setHttpHeadersCallback(callback: GetHttpHeaders): void {
|
|
66
|
+
this._httpHeadersCallback = callback;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @inheritdoc */
|
|
70
|
+
async execute(): Promise<CommandResult<TCommandResponse>> {
|
|
71
|
+
let actualRoute = this.route;
|
|
72
|
+
|
|
73
|
+
if (this.requestParameters && this.requestParameters.length > 0) {
|
|
74
|
+
const payload = this.buildPayload();
|
|
75
|
+
const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);
|
|
76
|
+
actualRoute = route;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');
|
|
80
|
+
this.setInitialValuesFromCurrentValues();
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @inheritdoc */
|
|
85
|
+
async validate(): Promise<CommandResult<TCommandResponse>> {
|
|
86
|
+
const actualRoute = `${this.route}/validate`;
|
|
87
|
+
return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private buildPayload(): object {
|
|
91
|
+
const payload = {};
|
|
92
|
+
this.properties.forEach(property => {
|
|
93
|
+
payload[property] = this[property];
|
|
94
|
+
});
|
|
95
|
+
return payload;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private buildHeaders(): HeadersInit {
|
|
99
|
+
const customHeaders = this._httpHeadersCallback?.() ?? {};
|
|
100
|
+
const headers = {
|
|
101
|
+
...customHeaders,
|
|
102
|
+
'Accept': 'application/json',
|
|
103
|
+
'Content-Type': 'application/json'
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
if (this._microservice?.length > 0) {
|
|
107
|
+
headers[Globals.microserviceHttpHeader] = this._microservice;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return headers;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private async performRequest(
|
|
114
|
+
route: string,
|
|
115
|
+
notFoundMessage: string,
|
|
116
|
+
errorMessage: string
|
|
117
|
+
): Promise<CommandResult<TCommandResponse>> {
|
|
118
|
+
const payload = this.buildPayload();
|
|
119
|
+
const headers = this.buildHeaders();
|
|
120
|
+
const actualRoute = joinPaths(this._apiBasePath, route);
|
|
121
|
+
const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
const response = await fetch(url, {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
headers,
|
|
127
|
+
body: JsonSerializer.serialize(payload)
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
if (response.status === 404) {
|
|
131
|
+
return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const result = await response.json();
|
|
135
|
+
return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);
|
|
136
|
+
} catch (ex) {
|
|
137
|
+
return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** @inheritdoc */
|
|
142
|
+
clear(): void {
|
|
143
|
+
this.properties.forEach(property => {
|
|
144
|
+
this[property] = undefined;
|
|
145
|
+
});
|
|
146
|
+
this._initialValues = {};
|
|
147
|
+
this._hasChanges = false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @inheritdoc */
|
|
151
|
+
setInitialValues(values: TCommandContent) {
|
|
152
|
+
this.properties.forEach(property => {
|
|
153
|
+
if (Object.prototype.hasOwnProperty.call(values, property)) {
|
|
154
|
+
this._initialValues[property] = values[property];
|
|
155
|
+
this[property] = values[property];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
this.updateHasChanges();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** @inheritdoc */
|
|
162
|
+
setInitialValuesFromCurrentValues() {
|
|
163
|
+
this.properties.forEach(property => {
|
|
164
|
+
if (this[property]) {
|
|
165
|
+
this._initialValues[property] = this[property];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
this.updateHasChanges();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** @inheritdoc */
|
|
172
|
+
revertChanges(): void {
|
|
173
|
+
this.properties.forEach(property => {
|
|
174
|
+
this[property] = this._initialValues[property];
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** @inheritdoc */
|
|
179
|
+
get hasChanges() {
|
|
180
|
+
return this._hasChanges;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** @inheritdoc */
|
|
184
|
+
propertyChanged(property: string) {
|
|
185
|
+
this.updateHasChanges();
|
|
186
|
+
|
|
187
|
+
this._callbacks.forEach(callbackContainer => {
|
|
188
|
+
const callback = callbackContainer.callback.deref();
|
|
189
|
+
const thisArg = callbackContainer.thisArg.deref();
|
|
190
|
+
if (callback && thisArg) {
|
|
191
|
+
callback.call(thisArg, property);
|
|
192
|
+
} else {
|
|
193
|
+
this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** @inheritdoc */
|
|
199
|
+
onPropertyChanged(callback: PropertyChanged, thisArg: object) {
|
|
200
|
+
this._callbacks.push({
|
|
201
|
+
callback: new WeakRef(callback),
|
|
202
|
+
thisArg: new WeakRef(thisArg)
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private updateHasChanges() {
|
|
207
|
+
this._hasChanges = this.properties.some(property => this[property] !== this._initialValues[property]);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
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 { Guid } from '@cratis/fundamentals';
|
|
5
|
+
import { ICommandResult } from './ICommandResult';
|
|
6
|
+
import { ValidationResult } from '../validation/ValidationResult';
|
|
7
|
+
import { Constructor, JsonSerializer } from '@cratis/fundamentals';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Delegate type for the onSuccess callback.
|
|
11
|
+
*/
|
|
12
|
+
type OnSuccess = (<TResponse>(response: TResponse) => void) | (() => void);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Delegate type for the onFailed callback.
|
|
16
|
+
*/
|
|
17
|
+
type OnFailed<TResponse> = ((commandResult: CommandResult<TResponse>) => void) | (() => void);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Delegate type for the onException callback.
|
|
21
|
+
*/
|
|
22
|
+
type OnException = (messages: string[], stackTrace: string) => void;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Delegate type for the onUnauthorized callback.
|
|
26
|
+
*/
|
|
27
|
+
type OnUnauthorized = () => void;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Delegate type for the onValidationFailure callback.
|
|
31
|
+
*/
|
|
32
|
+
type OnValidationFailure = (validationResults: ValidationResult[]) => void;
|
|
33
|
+
|
|
34
|
+
type ServerCommandResult = {
|
|
35
|
+
correlationId: string;
|
|
36
|
+
isSuccess: boolean;
|
|
37
|
+
isAuthorized: boolean;
|
|
38
|
+
isValid: boolean;
|
|
39
|
+
hasExceptions: boolean;
|
|
40
|
+
validationResults: {
|
|
41
|
+
severity: number;
|
|
42
|
+
message: string;
|
|
43
|
+
members: string[];
|
|
44
|
+
state: object;
|
|
45
|
+
}[];
|
|
46
|
+
exceptionMessages: string[];
|
|
47
|
+
exceptionStackTrace: string;
|
|
48
|
+
authorizationFailureReason: string;
|
|
49
|
+
|
|
50
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
51
|
+
response: any;
|
|
52
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Represents the result from executing a {@link ICommand}.
|
|
57
|
+
*/
|
|
58
|
+
export class CommandResult<TResponse = object> implements ICommandResult<TResponse> {
|
|
59
|
+
|
|
60
|
+
static empty: CommandResult = new CommandResult({
|
|
61
|
+
correlationId: Guid.empty.toString(),
|
|
62
|
+
isSuccess: true,
|
|
63
|
+
isAuthorized: true,
|
|
64
|
+
isValid: true,
|
|
65
|
+
hasExceptions: false,
|
|
66
|
+
validationResults: [],
|
|
67
|
+
exceptionMessages: [],
|
|
68
|
+
exceptionStackTrace: '',
|
|
69
|
+
authorizationFailureReason: '',
|
|
70
|
+
response: null
|
|
71
|
+
}, Object, false);
|
|
72
|
+
|
|
73
|
+
static failed = (exceptionMessages: string[]): CommandResult => {
|
|
74
|
+
return new CommandResult({
|
|
75
|
+
correlationId: Guid.empty.toString(),
|
|
76
|
+
isSuccess: false,
|
|
77
|
+
isAuthorized: true,
|
|
78
|
+
isValid: true,
|
|
79
|
+
hasExceptions: true,
|
|
80
|
+
validationResults: [],
|
|
81
|
+
exceptionMessages: exceptionMessages,
|
|
82
|
+
exceptionStackTrace: '',
|
|
83
|
+
authorizationFailureReason: '',
|
|
84
|
+
response: null
|
|
85
|
+
}, Object, false);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** @inheritdoc */
|
|
89
|
+
readonly correlationId: Guid;
|
|
90
|
+
|
|
91
|
+
/** @inheritdoc */
|
|
92
|
+
readonly isSuccess: boolean;
|
|
93
|
+
|
|
94
|
+
/** @inheritdoc */
|
|
95
|
+
readonly isAuthorized: boolean;
|
|
96
|
+
|
|
97
|
+
/** @inheritdoc */
|
|
98
|
+
readonly isValid: boolean;
|
|
99
|
+
|
|
100
|
+
/** @inheritdoc */
|
|
101
|
+
readonly hasExceptions: boolean;
|
|
102
|
+
|
|
103
|
+
/** @inheritdoc */
|
|
104
|
+
readonly validationResults: ValidationResult[];
|
|
105
|
+
|
|
106
|
+
/** @inheritdoc */
|
|
107
|
+
readonly exceptionMessages: string[];
|
|
108
|
+
|
|
109
|
+
/** @inheritdoc */
|
|
110
|
+
readonly exceptionStackTrace: string;
|
|
111
|
+
|
|
112
|
+
/** @inheritdoc */
|
|
113
|
+
readonly authorizationFailureReason: string;
|
|
114
|
+
|
|
115
|
+
/** @inheritdoc */
|
|
116
|
+
readonly response?: TResponse;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Creates an instance of command result.
|
|
120
|
+
* @param {*} result The JSON/any representation of the command result;
|
|
121
|
+
* @param {Constructor} responseInstanceType The {@see Constructor} that represents the type of response, if any. Defaults to {@see Object}.
|
|
122
|
+
* @param {boolean} isResponseTypeEnumerable Whether or not the response type is an enumerable or not.
|
|
123
|
+
*/
|
|
124
|
+
constructor(result: ServerCommandResult, responseInstanceType: Constructor = Object, isResponseTypeEnumerable: boolean) {
|
|
125
|
+
this.correlationId = Guid.parse(result.correlationId);
|
|
126
|
+
this.isSuccess = result.isSuccess;
|
|
127
|
+
this.isAuthorized = result.isAuthorized;
|
|
128
|
+
this.isValid = result.isValid;
|
|
129
|
+
this.hasExceptions = result.hasExceptions;
|
|
130
|
+
this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));
|
|
131
|
+
this.exceptionMessages = result.exceptionMessages;
|
|
132
|
+
this.exceptionStackTrace = result.exceptionStackTrace;
|
|
133
|
+
this.authorizationFailureReason = result.authorizationFailureReason;
|
|
134
|
+
|
|
135
|
+
if (result.response) {
|
|
136
|
+
if (isResponseTypeEnumerable) {
|
|
137
|
+
this.response = JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response) as TResponse;
|
|
138
|
+
} else {
|
|
139
|
+
this.response = JsonSerializer.deserializeFromInstance(responseInstanceType, result.response) as TResponse;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Set up a callback for when the command was successful.
|
|
146
|
+
* @param {OnSuccess} callback The callback to call when the command was successful.
|
|
147
|
+
* @returns {CommandResult} The instance of the command result.
|
|
148
|
+
*/
|
|
149
|
+
onSuccess(callback: OnSuccess): CommandResult<TResponse> {
|
|
150
|
+
if (this.isSuccess) {
|
|
151
|
+
callback(this.response as TResponse);
|
|
152
|
+
}
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Set up a callback for when the command failed.
|
|
158
|
+
* @param {OnFailed} callback The callback to call when the command failed.
|
|
159
|
+
* @returns {CommandResult} The instance of the command result.
|
|
160
|
+
*/
|
|
161
|
+
onFailed(callback: OnFailed<TResponse>): CommandResult<TResponse> {
|
|
162
|
+
if (!this.isSuccess) {
|
|
163
|
+
callback(this);
|
|
164
|
+
}
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Set up a callback for when the command failed with an exception.
|
|
170
|
+
* @param {OnException} callback The callback to call when the command had an exception.
|
|
171
|
+
* @returns {CommandResult} The instance of the command result.
|
|
172
|
+
*/
|
|
173
|
+
onException(callback: OnException): CommandResult<TResponse> {
|
|
174
|
+
if (this.hasExceptions) {
|
|
175
|
+
callback(this.exceptionMessages, this.exceptionStackTrace);
|
|
176
|
+
}
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Set up a callback for when the command was unauthorized.
|
|
182
|
+
* @param {OnUnauthorized} callback The callback to call when the command was unauthorized.
|
|
183
|
+
* @returns {CommandResult} The instance of the command result.
|
|
184
|
+
*/
|
|
185
|
+
onUnauthorized(callback: OnUnauthorized): CommandResult<TResponse> {
|
|
186
|
+
if (!this.isAuthorized) {
|
|
187
|
+
callback();
|
|
188
|
+
}
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Set up a callback for when the command had validation errors.
|
|
194
|
+
* @param {OnSuccess} callback The callback to call when the command was invalid.
|
|
195
|
+
* @returns {CommandResult} The instance of the command result.
|
|
196
|
+
*/
|
|
197
|
+
onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse> {
|
|
198
|
+
if (!this.isValid) {
|
|
199
|
+
callback(this.validationResults);
|
|
200
|
+
}
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
203
|
+
}
|