@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
|
@@ -0,0 +1,230 @@
|
|
|
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 { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';
|
|
5
|
+
import { ObservableQueryConnection } from './ObservableQueryConnection';
|
|
6
|
+
import { ObservableQuerySubscription } from './ObservableQuerySubscription';
|
|
7
|
+
import { ValidateRequestArguments } from './ValidateRequestArguments';
|
|
8
|
+
import { IObservableQueryConnection } from './IObservableQueryConnection';
|
|
9
|
+
import { NullObservableQueryConnection } from './NullObservableQueryConnection';
|
|
10
|
+
import { Constructor } from '@cratis/fundamentals';
|
|
11
|
+
import { JsonSerializer } from '@cratis/fundamentals';
|
|
12
|
+
import { QueryResult } from './QueryResult';
|
|
13
|
+
import { Sorting } from './Sorting';
|
|
14
|
+
import { Paging } from './Paging';
|
|
15
|
+
import { SortDirection } from './SortDirection';
|
|
16
|
+
import { Globals } from '../Globals';
|
|
17
|
+
import { joinPaths } from '../joinPaths';
|
|
18
|
+
import { UrlHelpers } from '../UrlHelpers';
|
|
19
|
+
import { GetHttpHeaders } from '../GetHttpHeaders';
|
|
20
|
+
import { ParameterDescriptor } from '../reflection/ParameterDescriptor';
|
|
21
|
+
import { ParametersHelper } from '../reflection/ParametersHelper';
|
|
22
|
+
|
|
23
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Represents an implementation of {@link IQueryFor}.
|
|
27
|
+
* @template TDataType Type of data returned by the query.
|
|
28
|
+
*/
|
|
29
|
+
export abstract class ObservableQueryFor<TDataType, TParameters = object> implements IObservableQueryFor<TDataType, TParameters> {
|
|
30
|
+
private _microservice: string;
|
|
31
|
+
private _apiBasePath: string;
|
|
32
|
+
private _origin: string;
|
|
33
|
+
private _connection?: IObservableQueryConnection<TDataType>;
|
|
34
|
+
private _httpHeadersCallback: GetHttpHeaders;
|
|
35
|
+
|
|
36
|
+
abstract readonly route: string;
|
|
37
|
+
abstract readonly defaultValue: TDataType;
|
|
38
|
+
abstract readonly parameterDescriptors: ParameterDescriptor[];
|
|
39
|
+
abstract get requiredRequestParameters(): string[];
|
|
40
|
+
sorting: Sorting;
|
|
41
|
+
paging: Paging;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Initializes a new instance of the {@link ObservableQueryFor<,>}} class.
|
|
45
|
+
* @param modelType Type of model, if an enumerable, this is the instance type.
|
|
46
|
+
* @param enumerable Whether or not it is an enumerable.
|
|
47
|
+
*/
|
|
48
|
+
constructor(readonly modelType: Constructor, readonly enumerable: boolean) {
|
|
49
|
+
this.sorting = Sorting.none;
|
|
50
|
+
this.paging = Paging.noPaging;
|
|
51
|
+
this._microservice = Globals.microservice ?? '';
|
|
52
|
+
this._apiBasePath = '';
|
|
53
|
+
this._origin = '';
|
|
54
|
+
this._httpHeadersCallback = () => ({});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Disposes the query.
|
|
59
|
+
*/
|
|
60
|
+
dispose() {
|
|
61
|
+
this._connection?.disconnect();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** @inheritdoc */
|
|
65
|
+
setMicroservice(microservice: string) {
|
|
66
|
+
this._microservice = microservice;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @inheritdoc */
|
|
70
|
+
setApiBasePath(apiBasePath: string): void {
|
|
71
|
+
this._apiBasePath = apiBasePath;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** @inheritdoc */
|
|
75
|
+
setOrigin(origin: string): void {
|
|
76
|
+
this._origin = origin;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** @inheritdoc */
|
|
80
|
+
setHttpHeadersCallback(callback: GetHttpHeaders): void {
|
|
81
|
+
this._httpHeadersCallback = callback;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @inheritdoc */
|
|
85
|
+
subscribe(callback: OnNextResult<QueryResult<TDataType>>, args?: TParameters): ObservableQuerySubscription<TDataType> {
|
|
86
|
+
const connectionQueryArguments: any = this.buildQueryArguments();
|
|
87
|
+
|
|
88
|
+
if (this._connection) {
|
|
89
|
+
this._connection.disconnect();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!this.validateArguments(args)) {
|
|
93
|
+
this._connection = new NullObservableQueryConnection(this.defaultValue);
|
|
94
|
+
} else {
|
|
95
|
+
const actualRoute = this.buildRoute(args);
|
|
96
|
+
const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);
|
|
97
|
+
this._connection = new ObservableQueryConnection<TDataType>(url, this._microservice);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const subscriber = new ObservableQuerySubscription(this._connection);
|
|
101
|
+
this._connection.connect(data => {
|
|
102
|
+
const result: any = data;
|
|
103
|
+
try {
|
|
104
|
+
this.deserializeResult(result);
|
|
105
|
+
callback(result);
|
|
106
|
+
} catch (ex) {
|
|
107
|
+
console.log(ex);
|
|
108
|
+
}
|
|
109
|
+
}, connectionQueryArguments);
|
|
110
|
+
return subscriber;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** @inheritdoc */
|
|
114
|
+
async perform(args?: TParameters): Promise<QueryResult<TDataType>> {
|
|
115
|
+
const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;
|
|
116
|
+
|
|
117
|
+
if (!this.validateArguments(args)) {
|
|
118
|
+
return new Promise<QueryResult<TDataType>>((resolve) => {
|
|
119
|
+
resolve(noSuccess);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const { route, unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);
|
|
124
|
+
let actualRoute = joinPaths(this._apiBasePath, route);
|
|
125
|
+
|
|
126
|
+
const additionalParams: Record<string, string | number> = {};
|
|
127
|
+
if (this.paging.hasPaging) {
|
|
128
|
+
additionalParams.page = this.paging.page;
|
|
129
|
+
additionalParams.pageSize = this.paging.pageSize;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (this.sorting.hasSorting) {
|
|
133
|
+
additionalParams.sortBy = this.sorting.field;
|
|
134
|
+
additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Collect parameter values from parameterDescriptors that are set
|
|
138
|
+
const parameterValues = ParametersHelper.collectParameterValues(this);
|
|
139
|
+
|
|
140
|
+
const queryParams = UrlHelpers.buildQueryParams({ ...unusedParameters, ...parameterValues }, additionalParams);
|
|
141
|
+
const queryString = queryParams.toString();
|
|
142
|
+
if (queryString) {
|
|
143
|
+
actualRoute += (actualRoute.includes('?') ? '&' : '?') + queryString;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);
|
|
147
|
+
|
|
148
|
+
const headers = {
|
|
149
|
+
...(this._httpHeadersCallback?.() || {}),
|
|
150
|
+
'Accept': 'application/json',
|
|
151
|
+
'Content-Type': 'application/json'
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
if (this._microservice?.length > 0) {
|
|
155
|
+
headers[Globals.microserviceHttpHeader] = this._microservice;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const response = await fetch(url, {
|
|
159
|
+
method: 'GET',
|
|
160
|
+
headers
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
const result = await response.json();
|
|
165
|
+
return new QueryResult(result, this.modelType, this.enumerable);
|
|
166
|
+
} catch {
|
|
167
|
+
return noSuccess;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private validateArguments(args?: TParameters): boolean {
|
|
172
|
+
return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args as object);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private buildRoute(args?: TParameters): string {
|
|
176
|
+
const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);
|
|
177
|
+
const actualRoute = joinPaths(this._apiBasePath, route);
|
|
178
|
+
return actualRoute;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private buildQueryArguments(): any {
|
|
182
|
+
const queryArguments: any = {};
|
|
183
|
+
|
|
184
|
+
if (this.paging && this.paging.pageSize > 0) {
|
|
185
|
+
queryArguments.pageSize = this.paging.pageSize;
|
|
186
|
+
queryArguments.page = this.paging.page;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (this.sorting.hasSorting) {
|
|
190
|
+
queryArguments.sortBy = this.sorting.field;
|
|
191
|
+
queryArguments.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return queryArguments;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private addPagingAndSortingToRoute(route: string): string {
|
|
198
|
+
const additionalParams: Record<string, string | number> = {};
|
|
199
|
+
|
|
200
|
+
if (this.paging.hasPaging) {
|
|
201
|
+
additionalParams.page = this.paging.page;
|
|
202
|
+
additionalParams.pageSize = this.paging.pageSize;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (this.sorting.hasSorting) {
|
|
206
|
+
additionalParams.sortBy = this.sorting.field;
|
|
207
|
+
additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const queryParams = UrlHelpers.buildQueryParams({}, additionalParams);
|
|
211
|
+
const queryString = queryParams.toString();
|
|
212
|
+
if (queryString) {
|
|
213
|
+
route += '?' + queryString;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return route;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private deserializeResult(result: any): void {
|
|
220
|
+
if (this.enumerable) {
|
|
221
|
+
if (Array.isArray(result.data)) {
|
|
222
|
+
result.data = JsonSerializer.deserializeArrayFromInstance(this.modelType, result.data);
|
|
223
|
+
} else {
|
|
224
|
+
result.data = [];
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { IObservableQueryConnection } from './IObservableQueryConnection';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a subscription for an observable query.
|
|
8
|
+
*/
|
|
9
|
+
export class ObservableQuerySubscription<TDataType> {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Initializes a new instance of the {@link ObservableQuerySubscription} class.
|
|
13
|
+
* @param {ObservableQueryConnection<TDataType> _connection The connection to use.
|
|
14
|
+
*/
|
|
15
|
+
constructor(private _connection: IObservableQueryConnection<TDataType>) {
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Unsubscribe subscription.
|
|
20
|
+
*/
|
|
21
|
+
unsubscribe() {
|
|
22
|
+
if (this._connection) {
|
|
23
|
+
this._connection.disconnect();
|
|
24
|
+
this._connection = undefined!;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -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
|
+
/**
|
|
5
|
+
* Represents the paging information for a query.
|
|
6
|
+
*/
|
|
7
|
+
export class Paging {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* No paging.
|
|
11
|
+
*/
|
|
12
|
+
static noPaging: Paging = new Paging(0, 0);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initializes a new instance of {@link Paging}.
|
|
16
|
+
*/
|
|
17
|
+
constructor(page?: number, pageSize?: number) {
|
|
18
|
+
this.page = page ?? 0;
|
|
19
|
+
this.pageSize = pageSize ?? 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Page of paging
|
|
24
|
+
*/
|
|
25
|
+
page: number;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Page size of paging
|
|
29
|
+
*/
|
|
30
|
+
pageSize: number;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Gets whether or not there is paging.
|
|
34
|
+
*/
|
|
35
|
+
get hasPaging(): boolean {
|
|
36
|
+
return this.page > 0 || this.pageSize > 0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
* Represents the paging information for a query.
|
|
6
|
+
*/
|
|
7
|
+
export class PagingInfo {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* No paging paging info.
|
|
11
|
+
*/
|
|
12
|
+
static readonly noPaging = new PagingInfo();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initializes a new instance of the {@link PagingInfo} class.
|
|
16
|
+
*/
|
|
17
|
+
constructor() {
|
|
18
|
+
this.page = 0;
|
|
19
|
+
this.size = 0;
|
|
20
|
+
this.totalItems = 0;
|
|
21
|
+
this.totalPages = 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Current page.
|
|
26
|
+
*/
|
|
27
|
+
page: number;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Page size.
|
|
31
|
+
*/
|
|
32
|
+
size: number;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Total number items.
|
|
36
|
+
*/
|
|
37
|
+
totalItems: number;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Total number of pages.
|
|
41
|
+
*/
|
|
42
|
+
totalPages: number;
|
|
43
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
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 { IQueryFor } from './IQueryFor';
|
|
5
|
+
import { QueryResult } from "./QueryResult";
|
|
6
|
+
import { ValidateRequestArguments } from './ValidateRequestArguments';
|
|
7
|
+
import { Constructor } from '@cratis/fundamentals';
|
|
8
|
+
import { Paging } from './Paging';
|
|
9
|
+
import { Globals } from '../Globals';
|
|
10
|
+
import { Sorting } from './Sorting';
|
|
11
|
+
import { SortDirection } from './SortDirection';
|
|
12
|
+
import { joinPaths } from '../joinPaths';
|
|
13
|
+
import { UrlHelpers } from '../UrlHelpers';
|
|
14
|
+
import { GetHttpHeaders } from '../GetHttpHeaders';
|
|
15
|
+
import { ParameterDescriptor } from '../reflection/ParameterDescriptor';
|
|
16
|
+
import { ParametersHelper } from '../reflection/ParametersHelper';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Represents an implementation of {@link IQueryFor}.
|
|
20
|
+
* @template TDataType Type of data returned by the query.
|
|
21
|
+
*/
|
|
22
|
+
export abstract class QueryFor<TDataType, TParameters = object> implements IQueryFor<TDataType, TParameters> {
|
|
23
|
+
private _microservice: string;
|
|
24
|
+
private _apiBasePath: string;
|
|
25
|
+
private _origin: string;
|
|
26
|
+
private _httpHeadersCallback: GetHttpHeaders;
|
|
27
|
+
abstract readonly route: string;
|
|
28
|
+
abstract readonly parameterDescriptors: ParameterDescriptor[];
|
|
29
|
+
abstract get requiredRequestParameters(): string[];
|
|
30
|
+
abstract defaultValue: TDataType;
|
|
31
|
+
abortController?: AbortController;
|
|
32
|
+
sorting: Sorting;
|
|
33
|
+
paging: Paging;
|
|
34
|
+
parameters: TParameters | undefined;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Initializes a new instance of the {@link ObservableQueryFor<,>}} class.
|
|
38
|
+
* @param modelType Type of model, if an enumerable, this is the instance type.
|
|
39
|
+
* @param enumerable Whether or not it is an enumerable.
|
|
40
|
+
*/
|
|
41
|
+
constructor(readonly modelType: Constructor, readonly enumerable: boolean) {
|
|
42
|
+
this.sorting = Sorting.none;
|
|
43
|
+
this.paging = Paging.noPaging;
|
|
44
|
+
this._microservice = Globals.microservice ?? '';
|
|
45
|
+
this._apiBasePath = '';
|
|
46
|
+
this._origin = '';
|
|
47
|
+
this._httpHeadersCallback = () => ({});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @inheritdoc */
|
|
51
|
+
setMicroservice(microservice: string) {
|
|
52
|
+
this._microservice = microservice;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @inheritdoc */
|
|
56
|
+
setApiBasePath(apiBasePath: string): void {
|
|
57
|
+
this._apiBasePath = apiBasePath;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** @inheritdoc */
|
|
61
|
+
setOrigin(origin: string): void {
|
|
62
|
+
this._origin = origin;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @inheritdoc */
|
|
66
|
+
setHttpHeadersCallback(callback: GetHttpHeaders): void {
|
|
67
|
+
this._httpHeadersCallback = callback;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @inheritdoc */
|
|
71
|
+
async perform(args?: TParameters): Promise<QueryResult<TDataType>> {
|
|
72
|
+
const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;
|
|
73
|
+
|
|
74
|
+
args = args || this.parameters;
|
|
75
|
+
|
|
76
|
+
if (!ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args as object)) {
|
|
77
|
+
return new Promise<QueryResult<TDataType>>((resolve) => {
|
|
78
|
+
resolve(noSuccess);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (this.abortController) {
|
|
83
|
+
this.abortController.abort();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.abortController = new AbortController();
|
|
87
|
+
|
|
88
|
+
const { route, unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);
|
|
89
|
+
let actualRoute = joinPaths(this._apiBasePath, route);
|
|
90
|
+
|
|
91
|
+
const additionalParams: Record<string, string | number> = {};
|
|
92
|
+
if (this.paging.hasPaging) {
|
|
93
|
+
additionalParams.page = this.paging.page;
|
|
94
|
+
additionalParams.pageSize = this.paging.pageSize;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (this.sorting.hasSorting) {
|
|
98
|
+
additionalParams.sortBy = this.sorting.field;
|
|
99
|
+
additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Collect parameter values from parameterDescriptors that are set
|
|
103
|
+
const parameterValues = ParametersHelper.collectParameterValues(this);
|
|
104
|
+
|
|
105
|
+
const queryParams = UrlHelpers.buildQueryParams({ ...unusedParameters, ...parameterValues }, additionalParams);
|
|
106
|
+
const queryString = queryParams.toString();
|
|
107
|
+
if (queryString) {
|
|
108
|
+
actualRoute += (actualRoute.includes('?') ? '&' : '?') + queryString;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);
|
|
112
|
+
|
|
113
|
+
const headers = {
|
|
114
|
+
... this._httpHeadersCallback?.(), ...
|
|
115
|
+
{
|
|
116
|
+
'Accept': 'application/json',
|
|
117
|
+
'Content-Type': 'application/json'
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
if (this._microservice?.length > 0) {
|
|
122
|
+
headers[Globals.microserviceHttpHeader] = this._microservice;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const response = await fetch(url, {
|
|
126
|
+
method: 'GET',
|
|
127
|
+
headers,
|
|
128
|
+
signal: this.abortController.signal
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
const result = await response.json();
|
|
133
|
+
return new QueryResult(result, this.modelType, this.enumerable);
|
|
134
|
+
} catch {
|
|
135
|
+
return noSuccess;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { Constructor } from '@cratis/fundamentals';
|
|
5
|
+
import { IQueryProvider } from './IQueryProvider';
|
|
6
|
+
import { IQuery } from './IQuery';
|
|
7
|
+
import { GetHttpHeaders } from '../GetHttpHeaders';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Represents an implementation of {@link IQueryProvider}
|
|
11
|
+
*/
|
|
12
|
+
export class QueryProvider implements IQueryProvider {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initializes a new instance of {@link QueryProvider}
|
|
16
|
+
* @param _microservice Name of the microservice to provide queries for.
|
|
17
|
+
* @param _apiBasePath Base path for the API to use for the query.
|
|
18
|
+
* @param _origin Origin to use for the query.
|
|
19
|
+
* @param _httpHeadersCallback Callback to get HTTP headers for the query.
|
|
20
|
+
*/
|
|
21
|
+
constructor(
|
|
22
|
+
private readonly _microservice: string,
|
|
23
|
+
private readonly _apiBasePath: string,
|
|
24
|
+
private readonly _origin: string,
|
|
25
|
+
private readonly _httpHeadersCallback: GetHttpHeaders) { }
|
|
26
|
+
|
|
27
|
+
/** @inheritdoc */
|
|
28
|
+
get<T extends IQuery>(queryType: Constructor<T>): T {
|
|
29
|
+
const query = new queryType();
|
|
30
|
+
query.setMicroservice(this._microservice);
|
|
31
|
+
query.setApiBasePath(this._apiBasePath);
|
|
32
|
+
query.setOrigin(this._origin);
|
|
33
|
+
query.setHttpHeadersCallback(this._httpHeadersCallback);
|
|
34
|
+
return query;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
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 { Constructor, JsonSerializer } from '@cratis/fundamentals';
|
|
5
|
+
import { ValidationResult } from '../validation/ValidationResult';
|
|
6
|
+
import { IQueryResult } from './IQueryResult';
|
|
7
|
+
import { PagingInfo } from './PagingInfo';
|
|
8
|
+
|
|
9
|
+
type ServerQueryResult = {
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
|
+
data: any;
|
|
12
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
13
|
+
isSuccess: boolean;
|
|
14
|
+
isAuthorized: boolean;
|
|
15
|
+
isValid: boolean;
|
|
16
|
+
hasExceptions: boolean;
|
|
17
|
+
validationResults: ServerValidationResult[];
|
|
18
|
+
exceptionMessages: string[];
|
|
19
|
+
exceptionStackTrace: string;
|
|
20
|
+
paging: ServerPagingInfo;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type ServerValidationResult = {
|
|
24
|
+
severity: number;
|
|
25
|
+
message: string;
|
|
26
|
+
members: string[];
|
|
27
|
+
state: object;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type ServerPagingInfo = {
|
|
31
|
+
page: number;
|
|
32
|
+
size: number;
|
|
33
|
+
totalItems: number;
|
|
34
|
+
totalPages: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Represents the result from executing a {@link IQueryFor}.
|
|
39
|
+
* @template TDataType The data type.
|
|
40
|
+
*/
|
|
41
|
+
export class QueryResult<TDataType = object> implements IQueryResult<TDataType> {
|
|
42
|
+
|
|
43
|
+
static empty<TDataType>(defaultValue: TDataType): QueryResult<TDataType> {
|
|
44
|
+
return new QueryResult({
|
|
45
|
+
data: defaultValue as object,
|
|
46
|
+
isSuccess: true,
|
|
47
|
+
isAuthorized: true,
|
|
48
|
+
isValid: true,
|
|
49
|
+
hasExceptions: false,
|
|
50
|
+
validationResults: [],
|
|
51
|
+
exceptionMessages: [],
|
|
52
|
+
exceptionStackTrace: '',
|
|
53
|
+
paging: {
|
|
54
|
+
totalItems: 0,
|
|
55
|
+
totalPages: 0,
|
|
56
|
+
page: 0,
|
|
57
|
+
size: 0
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}, Object, false);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static noSuccess: QueryResult = new QueryResult({
|
|
64
|
+
data: {},
|
|
65
|
+
isSuccess: false,
|
|
66
|
+
isAuthorized: true,
|
|
67
|
+
isValid: true,
|
|
68
|
+
hasExceptions: false,
|
|
69
|
+
validationResults: [],
|
|
70
|
+
exceptionMessages: [],
|
|
71
|
+
exceptionStackTrace: '',
|
|
72
|
+
paging: {
|
|
73
|
+
totalItems: 0,
|
|
74
|
+
totalPages: 0,
|
|
75
|
+
page: 0,
|
|
76
|
+
size: 0
|
|
77
|
+
}
|
|
78
|
+
}, Object, false);
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Creates an instance of query result.
|
|
82
|
+
* @param {*} result The raw result from the backend.
|
|
83
|
+
* @param {Constructor} instanceType The type of instance to deserialize.
|
|
84
|
+
* @param {boolean} enumerable Whether or not the result is supposed be an enumerable or not.
|
|
85
|
+
*/
|
|
86
|
+
constructor(result: ServerQueryResult, instanceType: Constructor, enumerable: boolean) {
|
|
87
|
+
this.isSuccess = result.isSuccess;
|
|
88
|
+
this.isAuthorized = result.isAuthorized;
|
|
89
|
+
this.isValid = result.isValid;
|
|
90
|
+
this.hasExceptions = result.hasExceptions;
|
|
91
|
+
this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));
|
|
92
|
+
this.exceptionMessages = result.exceptionMessages;
|
|
93
|
+
this.exceptionStackTrace = result.exceptionStackTrace;
|
|
94
|
+
this.paging = new PagingInfo();
|
|
95
|
+
this.paging.page = result.paging.page;
|
|
96
|
+
this.paging.size = result.paging.size;
|
|
97
|
+
this.paging.totalItems = result.paging.totalItems;
|
|
98
|
+
this.paging.totalPages = result.paging.totalPages;
|
|
99
|
+
|
|
100
|
+
if (result.data) {
|
|
101
|
+
let data: object = result.data;
|
|
102
|
+
if (enumerable) {
|
|
103
|
+
if (Array.isArray(result.data)) {
|
|
104
|
+
data = JsonSerializer.deserializeArrayFromInstance(instanceType, data);
|
|
105
|
+
} else {
|
|
106
|
+
data = [];
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
data = JsonSerializer.deserializeFromInstance(instanceType, data);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
this.data = data as TDataType;
|
|
113
|
+
} else {
|
|
114
|
+
this.data = null as TDataType;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** @inheritdoc */
|
|
119
|
+
readonly data: TDataType;
|
|
120
|
+
|
|
121
|
+
/** @inheritdoc */
|
|
122
|
+
readonly paging: PagingInfo;
|
|
123
|
+
|
|
124
|
+
/** @inheritdoc */
|
|
125
|
+
readonly isSuccess: boolean;
|
|
126
|
+
|
|
127
|
+
/** @inheritdoc */
|
|
128
|
+
readonly isAuthorized: boolean;
|
|
129
|
+
|
|
130
|
+
/** @inheritdoc */
|
|
131
|
+
readonly isValid: boolean;
|
|
132
|
+
|
|
133
|
+
/** @inheritdoc */
|
|
134
|
+
readonly hasExceptions: boolean;
|
|
135
|
+
|
|
136
|
+
/** @inheritdoc */
|
|
137
|
+
readonly validationResults: ValidationResult[];
|
|
138
|
+
|
|
139
|
+
/** @inheritdoc */
|
|
140
|
+
readonly exceptionMessages: string[];
|
|
141
|
+
|
|
142
|
+
/** @inheritdoc */
|
|
143
|
+
readonly exceptionStackTrace: string;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Gets whether or not the query has data.
|
|
147
|
+
*/
|
|
148
|
+
get hasData(): boolean {
|
|
149
|
+
if (this.data) {
|
|
150
|
+
if (Array.isArray(this.data)) {
|
|
151
|
+
return this.data.length > 0;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|