@blueprint-ts/core 3.0.0 → 4.0.0-beta.2
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/CHANGELOG.md +28 -0
- package/README.md +25 -1
- package/docs/.vitepress/config.ts +80 -23
- package/docs/index.md +6 -63
- package/docs/{services/laravel → laravel}/pagination.md +19 -6
- package/docs/{services/laravel → laravel}/requests.md +2 -2
- package/docs/services/pagination/index.md +46 -0
- package/docs/services/pagination/infinite-scroller.md +19 -0
- package/docs/services/pagination/page-aware.md +46 -0
- package/docs/services/pagination/state-pagination.md +77 -0
- package/docs/services/pagination/updating-rows.md +36 -0
- package/docs/services/persistence/index.md +46 -0
- package/docs/services/requests/abort-requests.md +25 -0
- package/docs/services/requests/bulk-requests.md +70 -0
- package/docs/services/requests/drivers.md +50 -0
- package/docs/services/requests/error-handling.md +137 -0
- package/docs/services/requests/events.md +31 -0
- package/docs/services/requests/getting-started.md +201 -0
- package/docs/services/requests/headers.md +40 -0
- package/docs/services/requests/loading.md +63 -0
- package/docs/services/requests/request-bodies.md +59 -0
- package/docs/services/requests/responses.md +34 -0
- package/docs/services/support/deferred-promise.md +63 -0
- package/docs/services/support/helpers.md +77 -0
- package/docs/services/support/index.md +6 -0
- package/docs/upgrading/v1-to-v2.md +64 -0
- package/docs/upgrading/v2-to-v3.md +52 -0
- package/docs/upgrading/v3-to-v4.md +171 -0
- package/docs/upgrading.md +0 -0
- package/docs/vue/composables/use-confirm-dialog.md +96 -0
- package/docs/vue/composables/use-global-checkbox.md +73 -0
- package/docs/vue/composables/use-is-empty.md +26 -0
- package/docs/vue/composables/use-is-open-from-var.md +32 -0
- package/docs/vue/composables/use-is-open.md +28 -0
- package/docs/vue/composables/use-model-wrapper.md +29 -0
- package/docs/vue/composables/use-on-open.md +26 -0
- package/docs/vue/forms/arrays.md +45 -0
- package/docs/vue/forms/errors.md +52 -0
- package/docs/vue/forms/index.md +99 -0
- package/docs/vue/forms/payloads.md +99 -0
- package/docs/vue/forms/persistence.md +19 -0
- package/docs/vue/forms/state-and-properties.md +26 -0
- package/docs/vue/forms/utilities.md +27 -0
- package/docs/vue/forms/validation.md +189 -0
- package/docs/vue/requests/loading.md +51 -0
- package/docs/vue/{requests → router}/route-resource-binding.md +33 -27
- package/docs/vue/state.md +27 -11
- package/package.json +9 -10
- package/release-tool.json +22 -3
- package/src/{service/bulkRequests → bulkRequests}/BulkRequestSender.ts +29 -17
- package/src/{service/bulkRequests → bulkRequests}/BulkRequestWrapper.ts +5 -5
- package/src/laravel/pagination/dataDrivers/RequestDriver.ts +30 -0
- package/src/laravel/pagination/index.ts +6 -0
- package/src/{service/pagination → pagination}/BasePaginator.ts +35 -0
- package/src/{service/pagination → pagination}/InfiniteScroller.ts +1 -0
- package/src/{service/pagination → pagination}/PageAwarePaginator.ts +19 -21
- package/src/{service/pagination → pagination}/StatePaginator.ts +2 -8
- package/src/{service/pagination → pagination}/index.ts +1 -1
- package/src/{service/requests → requests}/BaseRequest.ts +2 -2
- package/src/requests/ErrorHandler.ts +144 -0
- package/src/requests/RequestErrorRouter.ts +89 -0
- package/src/{service/requests → requests}/bodies/FormDataBody.ts +10 -6
- package/src/requests/exceptions/BadGatewayException.ts +3 -0
- package/src/requests/exceptions/BadRequestException.ts +3 -0
- package/src/requests/exceptions/ConflictException.ts +3 -0
- package/src/requests/exceptions/ForbiddenException.ts +3 -0
- package/src/requests/exceptions/GatewayTimeoutException.ts +3 -0
- package/src/requests/exceptions/GoneException.ts +3 -0
- package/src/requests/exceptions/InvalidJsonException.ts +15 -0
- package/src/requests/exceptions/LockedException.ts +3 -0
- package/src/requests/exceptions/MethodNotAllowedException.ts +3 -0
- package/src/requests/exceptions/NotImplementedException.ts +3 -0
- package/src/requests/exceptions/PayloadTooLargeException.ts +3 -0
- package/src/requests/exceptions/PreconditionFailedException.ts +3 -0
- package/src/requests/exceptions/RequestTimeoutException.ts +3 -0
- package/src/requests/exceptions/ServiceUnavailableException.ts +3 -0
- package/src/requests/exceptions/TooManyRequestsException.ts +3 -0
- package/src/requests/exceptions/UnsupportedMediaTypeException.ts +3 -0
- package/src/requests/exceptions/index.ts +51 -0
- package/src/requests/factories/FormDataFactory.ts +17 -0
- package/src/{service/requests → requests}/index.ts +2 -2
- package/src/{service/support → support}/DeferredPromise.ts +1 -1
- package/src/support/index.ts +4 -0
- package/src/vue/composables/useConfirmDialog.ts +5 -1
- package/src/vue/composables/useModelWrapper.ts +3 -0
- package/src/vue/forms/BaseForm.ts +491 -393
- package/src/vue/forms/PropertyAwareArray.ts +2 -2
- package/src/vue/forms/index.ts +4 -4
- package/src/vue/forms/validation/index.ts +5 -2
- package/src/vue/forms/validation/rules/ConfirmedRule.ts +3 -3
- package/src/vue/forms/validation/rules/EmailRule.ts +23 -0
- package/src/vue/forms/validation/rules/JsonRule.ts +28 -0
- package/src/vue/forms/validation/types/BidirectionalRule.ts +2 -2
- package/src/vue/forms/validation/types/ValidationRules.ts +15 -0
- package/src/vue/index.ts +3 -3
- package/src/vue/requests/factories/VueRequestLoaderFactory.ts +3 -2
- package/src/vue/requests/loaders/VueRequestBatchLoader.ts +6 -1
- package/src/vue/requests/loaders/VueRequestLoader.ts +1 -1
- package/src/vue/router/routeResourceBinding/types.ts +3 -3
- package/src/vue/state/State.ts +38 -50
- package/tests/service/helpers/mergeDeep.test.ts +1 -1
- package/tests/service/laravel/pagination/dataDrivers/RequestDriver.test.ts +3 -3
- package/tests/service/laravel/requests/JsonBaseRequest.test.ts +4 -4
- package/tests/service/laravel/requests/PaginationJsonBaseRequest.test.ts +3 -3
- package/tests/service/laravel/requests/responses/JsonResponse.test.ts +2 -2
- package/tests/service/laravel/requests/responses/PaginationResponse.test.ts +2 -2
- package/tests/service/pagination/dtos/PaginationDataDto.test.ts +1 -1
- package/tests/service/pagination/factories/VuePaginationDriverFactory.test.ts +2 -2
- package/tests/service/pagination/frontendDrivers/VuePaginationDriver.test.ts +1 -1
- package/tests/service/requests/ErrorHandler.test.ts +61 -58
- package/tests/service/requests/FormDataBody.test.ts +1 -1
- package/tests/vue/forms/BaseForm.behavior.test.ts +98 -0
- package/docs/.vitepress/theme/Layout.vue +0 -14
- package/docs/.vitepress/theme/components/VersionSelector.vue +0 -64
- package/docs/.vitepress/theme/index.js +0 -13
- package/docs/services/requests/index.md +0 -74
- package/docs/vue/forms.md +0 -477
- package/examples/files/7z2404-x64.exe +0 -0
- package/examples/index.html +0 -14
- package/examples/js/app.js +0 -8
- package/examples/js/router.js +0 -22
- package/examples/js/view/App.vue +0 -49
- package/examples/js/view/layout/DemoPage.vue +0 -28
- package/examples/js/view/pagination/Pagination.vue +0 -28
- package/examples/js/view/pagination/components/errorPagination/ErrorPagination.vue +0 -71
- package/examples/js/view/pagination/components/errorPagination/GetProductsRequest.ts +0 -54
- package/examples/js/view/pagination/components/infiniteScrolling/GetProductsRequest.ts +0 -50
- package/examples/js/view/pagination/components/infiniteScrolling/InfiniteScrolling.vue +0 -57
- package/examples/js/view/pagination/components/tablePagination/GetProductsRequest.ts +0 -50
- package/examples/js/view/pagination/components/tablePagination/TablePagination.vue +0 -63
- package/examples/js/view/requests/Requests.vue +0 -34
- package/examples/js/view/requests/components/abortableRequest/AbortableRequest.vue +0 -36
- package/examples/js/view/requests/components/abortableRequest/GetProductsRequest.ts +0 -25
- package/examples/js/view/requests/components/fileDownloadRequest/DownloadFileRequest.ts +0 -15
- package/examples/js/view/requests/components/fileDownloadRequest/FileDownloadRequest.vue +0 -44
- package/examples/js/view/requests/components/getRequestWithDynamicParams/GetProductsRequest.ts +0 -34
- package/examples/js/view/requests/components/getRequestWithDynamicParams/GetRequestWithDynamicParams.vue +0 -59
- package/examples/js/view/requests/components/serverErrorRequest/ServerErrorRequest.ts +0 -21
- package/examples/js/view/requests/components/serverErrorRequest/ServerErrorRequest.vue +0 -53
- package/src/service/laravel/pagination/contracts/PaginationParamsContract.ts +0 -4
- package/src/service/laravel/pagination/dataDrivers/RequestDriver.ts +0 -32
- package/src/service/laravel/pagination/index.ts +0 -7
- package/src/service/requests/ErrorHandler.ts +0 -64
- package/src/service/requests/exceptions/index.ts +0 -19
- package/src/service/requests/factories/FormDataFactory.ts +0 -9
- package/src/service/support/index.ts +0 -3
- /package/src/{service/bulkRequests → bulkRequests}/BulkRequestEvent.enum.ts +0 -0
- /package/src/{service/bulkRequests → bulkRequests}/index.ts +0 -0
- /package/src/{service/laravel → laravel}/pagination/contracts/PaginationResponseBodyContract.ts +0 -0
- /package/src/{service/laravel → laravel}/requests/JsonBaseRequest.ts +0 -0
- /package/src/{service/laravel → laravel}/requests/PaginationJsonBaseRequest.ts +0 -0
- /package/src/{service/laravel → laravel}/requests/index.ts +0 -0
- /package/src/{service/laravel → laravel}/requests/responses/JsonResponse.ts +0 -0
- /package/src/{service/laravel → laravel}/requests/responses/PaginationResponse.ts +0 -0
- /package/src/{service/pagination → pagination}/Paginator.ts +0 -0
- /package/src/{service/pagination → pagination}/contracts/BaseViewDriverContract.ts +0 -0
- /package/src/{service/pagination → pagination}/contracts/BaseViewDriverFactoryContract.ts +0 -0
- /package/src/{service/pagination → pagination}/contracts/PaginateableRequestContract.ts +0 -0
- /package/src/{service/pagination → pagination}/contracts/PaginationDataDriverContract.ts +0 -0
- /package/src/{service/pagination → pagination}/contracts/PaginationResponseContract.ts +0 -0
- /package/src/{service/pagination → pagination}/contracts/PaginatorLoadDataOptions.ts +0 -0
- /package/src/{service/pagination → pagination}/contracts/StatePaginationDataDriverContract.ts +0 -0
- /package/src/{service/pagination → pagination}/contracts/ViewDriverContract.ts +0 -0
- /package/src/{service/pagination → pagination}/contracts/ViewDriverFactoryContract.ts +0 -0
- /package/src/{service/pagination → pagination}/dataDrivers/ArrayDriver.ts +0 -0
- /package/src/{service/pagination → pagination}/dtos/PaginationDataDto.ts +0 -0
- /package/src/{service/pagination → pagination}/dtos/StatePaginationDataDto.ts +0 -0
- /package/src/{service/pagination → pagination}/factories/VueBaseViewDriverFactory.ts +0 -0
- /package/src/{service/pagination → pagination}/factories/VuePaginationDriverFactory.ts +0 -0
- /package/src/{service/pagination → pagination}/frontendDrivers/VueBaseViewDriver.ts +0 -0
- /package/src/{service/pagination → pagination}/frontendDrivers/VuePaginationDriver.ts +0 -0
- /package/src/{service/persistenceDrivers → persistenceDrivers}/LocalStorageDriver.ts +0 -0
- /package/src/{service/persistenceDrivers → persistenceDrivers}/NonPersistentDriver.ts +0 -0
- /package/src/{service/persistenceDrivers → persistenceDrivers}/SessionStorageDriver.ts +0 -0
- /package/src/{service/persistenceDrivers → persistenceDrivers}/index.ts +0 -0
- /package/src/{service/persistenceDrivers → persistenceDrivers}/types/PersistenceDriver.ts +0 -0
- /package/src/{service/requests → requests}/RequestEvents.enum.ts +0 -0
- /package/src/{service/requests → requests}/RequestMethod.enum.ts +0 -0
- /package/src/{service/requests → requests}/bodies/JsonBody.ts +0 -0
- /package/src/{service/requests → requests}/contracts/AbortableRequestContract.ts +0 -0
- /package/src/{service/requests → requests}/contracts/BaseRequestContract.ts +0 -0
- /package/src/{service/requests → requests}/contracts/BodyContract.ts +0 -0
- /package/src/{service/requests → requests}/contracts/BodyFactoryContract.ts +0 -0
- /package/src/{service/requests → requests}/contracts/DriverConfigContract.ts +0 -0
- /package/src/{service/requests → requests}/contracts/HeadersContract.ts +0 -0
- /package/src/{service/requests → requests}/contracts/RequestDriverContract.ts +0 -0
- /package/src/{service/requests → requests}/contracts/RequestLoaderContract.ts +0 -0
- /package/src/{service/requests → requests}/contracts/RequestLoaderFactoryContract.ts +0 -0
- /package/src/{service/requests → requests}/contracts/ResponseContract.ts +0 -0
- /package/src/{service/requests → requests}/drivers/contracts/ResponseHandlerContract.ts +0 -0
- /package/src/{service/requests → requests}/drivers/fetch/FetchDriver.ts +0 -0
- /package/src/{service/requests → requests}/drivers/fetch/FetchResponse.ts +0 -0
- /package/src/{service/requests → requests}/exceptions/NoResponseReceivedException.ts +0 -0
- /package/src/{service/requests → requests}/exceptions/NotFoundException.ts +0 -0
- /package/src/{service/requests → requests}/exceptions/PageExpiredException.ts +0 -0
- /package/src/{service/requests → requests}/exceptions/ResponseBodyException.ts +0 -0
- /package/src/{service/requests → requests}/exceptions/ResponseException.ts +0 -0
- /package/src/{service/requests → requests}/exceptions/ServerErrorException.ts +0 -0
- /package/src/{service/requests → requests}/exceptions/UnauthorizedException.ts +0 -0
- /package/src/{service/requests → requests}/exceptions/ValidationException.ts +0 -0
- /package/src/{service/requests → requests}/factories/JsonBodyFactory.ts +0 -0
- /package/src/{service/requests → requests}/responses/BaseResponse.ts +0 -0
- /package/src/{service/requests → requests}/responses/BlobResponse.ts +0 -0
- /package/src/{service/requests → requests}/responses/JsonResponse.ts +0 -0
- /package/src/{service/requests → requests}/responses/PlainTextResponse.ts +0 -0
- /package/src/{helpers.ts → support/helpers.ts} +0 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { PageExpiredException } from './exceptions/PageExpiredException'
|
|
2
|
+
import { NotFoundException } from './exceptions/NotFoundException'
|
|
3
|
+
import { UnauthorizedException } from './exceptions/UnauthorizedException'
|
|
4
|
+
import { ValidationException } from './exceptions/ValidationException'
|
|
5
|
+
import { ResponseException } from './exceptions/ResponseException'
|
|
6
|
+
import { NoResponseReceivedException } from './exceptions/NoResponseReceivedException'
|
|
7
|
+
import { ServerErrorException } from './exceptions/ServerErrorException'
|
|
8
|
+
import { type ResponseHandlerContract } from './drivers/contracts/ResponseHandlerContract'
|
|
9
|
+
import { ForbiddenException } from './exceptions/ForbiddenException'
|
|
10
|
+
import { TooManyRequestsException } from './exceptions/TooManyRequestsException'
|
|
11
|
+
import { LockedException } from './exceptions/LockedException'
|
|
12
|
+
import { NotImplementedException } from './exceptions/NotImplementedException'
|
|
13
|
+
import { ServiceUnavailableException } from './exceptions/ServiceUnavailableException'
|
|
14
|
+
import { MethodNotAllowedException } from './exceptions/MethodNotAllowedException'
|
|
15
|
+
import { RequestTimeoutException } from './exceptions/RequestTimeoutException'
|
|
16
|
+
import { ConflictException } from './exceptions/ConflictException'
|
|
17
|
+
import { GoneException } from './exceptions/GoneException'
|
|
18
|
+
import { PreconditionFailedException } from './exceptions/PreconditionFailedException'
|
|
19
|
+
import { PayloadTooLargeException } from './exceptions/PayloadTooLargeException'
|
|
20
|
+
import { UnsupportedMediaTypeException } from './exceptions/UnsupportedMediaTypeException'
|
|
21
|
+
import { BadGatewayException } from './exceptions/BadGatewayException'
|
|
22
|
+
import { GatewayTimeoutException } from './exceptions/GatewayTimeoutException'
|
|
23
|
+
import { BadRequestException } from './exceptions/BadRequestException'
|
|
24
|
+
import { InvalidJsonException } from './exceptions/InvalidJsonException'
|
|
25
|
+
|
|
26
|
+
export type ErrorHandlerCallback = ((response: ResponseHandlerContract) => boolean | void) | undefined
|
|
27
|
+
|
|
28
|
+
export class ErrorHandler<ResponseErrorBody> {
|
|
29
|
+
protected body: ResponseErrorBody | undefined = undefined
|
|
30
|
+
protected static handler: ErrorHandlerCallback = undefined
|
|
31
|
+
|
|
32
|
+
public constructor(protected response: ResponseHandlerContract) {}
|
|
33
|
+
|
|
34
|
+
public async handle() {
|
|
35
|
+
// Check if there is a global error handler set
|
|
36
|
+
if (ErrorHandler.handler !== undefined) {
|
|
37
|
+
// If handler returns false, we don't process the error further
|
|
38
|
+
if (ErrorHandler.handler(this.response) === false) {
|
|
39
|
+
console.debug('Skipping further error handling due to global handler returning false.')
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
this.body = await this.response.json<ResponseErrorBody>()
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new InvalidJsonException(this.response, error)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (this.body === undefined) {
|
|
51
|
+
throw new NoResponseReceivedException(this.response)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.handleResponseError(this.response, this.body)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public static registerHandler(callback: ErrorHandlerCallback) {
|
|
58
|
+
ErrorHandler.handler = callback
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected handleResponseError(response: ResponseHandlerContract, body: ResponseErrorBody) {
|
|
62
|
+
if (response.getStatusCode() === 400) {
|
|
63
|
+
throw new BadRequestException<ResponseErrorBody>(response, body)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (response.getStatusCode() === 401) {
|
|
67
|
+
throw new UnauthorizedException<ResponseErrorBody>(response, body)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (response.getStatusCode() === 403) {
|
|
71
|
+
throw new ForbiddenException<ResponseErrorBody>(response, body)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (response.getStatusCode() === 404) {
|
|
75
|
+
throw new NotFoundException<ResponseErrorBody>(response, body)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (response.getStatusCode() === 405) {
|
|
79
|
+
throw new MethodNotAllowedException<ResponseErrorBody>(response, body)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (response.getStatusCode() === 408) {
|
|
83
|
+
throw new RequestTimeoutException<ResponseErrorBody>(response, body)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (response.getStatusCode() === 409) {
|
|
87
|
+
throw new ConflictException<ResponseErrorBody>(response, body)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (response.getStatusCode() === 410) {
|
|
91
|
+
throw new GoneException<ResponseErrorBody>(response, body)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (response.getStatusCode() === 412) {
|
|
95
|
+
throw new PreconditionFailedException<ResponseErrorBody>(response, body)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (response.getStatusCode() === 413) {
|
|
99
|
+
throw new PayloadTooLargeException<ResponseErrorBody>(response, body)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (response.getStatusCode() === 415) {
|
|
103
|
+
throw new UnsupportedMediaTypeException<ResponseErrorBody>(response, body)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (response.getStatusCode() === 419) {
|
|
107
|
+
throw new PageExpiredException<ResponseErrorBody>(response, body)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (response.getStatusCode() === 422) {
|
|
111
|
+
throw new ValidationException<ResponseErrorBody>(response, body)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (response.getStatusCode() === 423) {
|
|
115
|
+
throw new LockedException<ResponseErrorBody>(response, body)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (response.getStatusCode() === 429) {
|
|
119
|
+
throw new TooManyRequestsException<ResponseErrorBody>(response, body)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (response.getStatusCode() === 500) {
|
|
123
|
+
throw new ServerErrorException<ResponseErrorBody>(response, body)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (response.getStatusCode() === 501) {
|
|
127
|
+
throw new NotImplementedException<ResponseErrorBody>(response, body)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (response.getStatusCode() === 502) {
|
|
131
|
+
throw new BadGatewayException<ResponseErrorBody>(response, body)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (response.getStatusCode() === 503) {
|
|
135
|
+
throw new ServiceUnavailableException<ResponseErrorBody>(response, body)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (response.getStatusCode() === 504) {
|
|
139
|
+
throw new GatewayTimeoutException<ResponseErrorBody>(response, body)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
throw new ResponseException(response)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BadRequestException } from './exceptions/BadRequestException'
|
|
2
|
+
import { MethodNotAllowedException } from './exceptions/MethodNotAllowedException'
|
|
3
|
+
import { RequestTimeoutException } from './exceptions/RequestTimeoutException'
|
|
4
|
+
import { ConflictException } from './exceptions/ConflictException'
|
|
5
|
+
import { GoneException } from './exceptions/GoneException'
|
|
6
|
+
import { PreconditionFailedException } from './exceptions/PreconditionFailedException'
|
|
7
|
+
import { PayloadTooLargeException } from './exceptions/PayloadTooLargeException'
|
|
8
|
+
import { UnsupportedMediaTypeException } from './exceptions/UnsupportedMediaTypeException'
|
|
9
|
+
import { ForbiddenException } from './exceptions/ForbiddenException'
|
|
10
|
+
import { LockedException } from './exceptions/LockedException'
|
|
11
|
+
import { NoResponseReceivedException } from './exceptions/NoResponseReceivedException'
|
|
12
|
+
import { NotFoundException } from './exceptions/NotFoundException'
|
|
13
|
+
import { NotImplementedException } from './exceptions/NotImplementedException'
|
|
14
|
+
import { BadGatewayException } from './exceptions/BadGatewayException'
|
|
15
|
+
import { PageExpiredException } from './exceptions/PageExpiredException'
|
|
16
|
+
import { ResponseBodyException } from './exceptions/ResponseBodyException'
|
|
17
|
+
import { ResponseException } from './exceptions/ResponseException'
|
|
18
|
+
import { ServerErrorException } from './exceptions/ServerErrorException'
|
|
19
|
+
import { ServiceUnavailableException } from './exceptions/ServiceUnavailableException'
|
|
20
|
+
import { GatewayTimeoutException } from './exceptions/GatewayTimeoutException'
|
|
21
|
+
import { TooManyRequestsException } from './exceptions/TooManyRequestsException'
|
|
22
|
+
import { UnauthorizedException } from './exceptions/UnauthorizedException'
|
|
23
|
+
import { ValidationException } from './exceptions/ValidationException'
|
|
24
|
+
import { InvalidJsonException } from './exceptions/InvalidJsonException'
|
|
25
|
+
|
|
26
|
+
type RequestExceptionConstructor =
|
|
27
|
+
| typeof BadRequestException
|
|
28
|
+
| typeof MethodNotAllowedException
|
|
29
|
+
| typeof RequestTimeoutException
|
|
30
|
+
| typeof ConflictException
|
|
31
|
+
| typeof GoneException
|
|
32
|
+
| typeof PreconditionFailedException
|
|
33
|
+
| typeof PayloadTooLargeException
|
|
34
|
+
| typeof UnsupportedMediaTypeException
|
|
35
|
+
| typeof UnauthorizedException
|
|
36
|
+
| typeof ForbiddenException
|
|
37
|
+
| typeof NotFoundException
|
|
38
|
+
| typeof PageExpiredException
|
|
39
|
+
| typeof ValidationException
|
|
40
|
+
| typeof LockedException
|
|
41
|
+
| typeof TooManyRequestsException
|
|
42
|
+
| typeof ServerErrorException
|
|
43
|
+
| typeof NotImplementedException
|
|
44
|
+
| typeof BadGatewayException
|
|
45
|
+
| typeof ServiceUnavailableException
|
|
46
|
+
| typeof GatewayTimeoutException
|
|
47
|
+
| typeof NoResponseReceivedException
|
|
48
|
+
| typeof InvalidJsonException
|
|
49
|
+
| typeof ResponseBodyException
|
|
50
|
+
| typeof ResponseException
|
|
51
|
+
|
|
52
|
+
type ErrorHandlerCallback<T extends Error> = (error: T) => void | Promise<void>
|
|
53
|
+
|
|
54
|
+
type UnknownErrorHandlerCallback = (error: unknown) => void | Promise<void>
|
|
55
|
+
|
|
56
|
+
export class RequestErrorRouter {
|
|
57
|
+
protected handlers: Array<{ ctor: RequestExceptionConstructor; handler: ErrorHandlerCallback<Error> }> = []
|
|
58
|
+
protected defaultHandler: UnknownErrorHandlerCallback | undefined = undefined
|
|
59
|
+
|
|
60
|
+
public on<C extends RequestExceptionConstructor>(ctor: C, handler: ErrorHandlerCallback<InstanceType<C>>): this {
|
|
61
|
+
this.handlers.push({ ctor, handler: handler as ErrorHandlerCallback<Error> })
|
|
62
|
+
|
|
63
|
+
return this
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public otherwise(handler: UnknownErrorHandlerCallback): this {
|
|
67
|
+
this.defaultHandler = handler
|
|
68
|
+
|
|
69
|
+
return this
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public async handle(error: unknown): Promise<boolean> {
|
|
73
|
+
for (const entry of this.handlers) {
|
|
74
|
+
if (error instanceof entry.ctor) {
|
|
75
|
+
await entry.handler(error)
|
|
76
|
+
|
|
77
|
+
return true
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (this.defaultHandler !== undefined) {
|
|
82
|
+
await this.defaultHandler(error)
|
|
83
|
+
|
|
84
|
+
return true
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return false
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { type BodyContract } from '../contracts/BodyContract'
|
|
2
2
|
import { type HeadersContract } from '../contracts/HeadersContract'
|
|
3
|
-
import { isObject } from '
|
|
3
|
+
import { isObject } from '../../support/helpers'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type FormDataPrimitive = string | number | boolean | null | Date | Blob
|
|
6
|
+
type FormDataValue = FormDataPrimitive | FormDataValue[] | { [key: string]: FormDataValue }
|
|
7
|
+
|
|
8
|
+
export class FormDataBody<RequestBody extends Record<string, FormDataValue | undefined>> implements BodyContract {
|
|
6
9
|
protected data: FormData
|
|
7
10
|
|
|
8
11
|
public constructor(data: RequestBody) {
|
|
@@ -17,12 +20,12 @@ export class FormDataBody<RequestBody> implements BodyContract {
|
|
|
17
20
|
return {}
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
protected toFormData(data:
|
|
23
|
+
protected toFormData(data: Record<string, FormDataValue | undefined>, form: FormData = new FormData(), namespace: string | null = null): FormData {
|
|
21
24
|
for (const property in data) {
|
|
22
25
|
if (Object.prototype.hasOwnProperty.call(data, property)) {
|
|
23
26
|
const formKey = namespace ? namespace + '[' + property + ']' : property
|
|
24
27
|
|
|
25
|
-
const value =
|
|
28
|
+
const value = data[property]
|
|
26
29
|
|
|
27
30
|
// Null is a valid "explicitly empty" value in many APIs.
|
|
28
31
|
// In multipart FormData we encode it as an empty string so the key is still present.
|
|
@@ -45,7 +48,8 @@ export class FormDataBody<RequestBody> implements BodyContract {
|
|
|
45
48
|
// Support arrays via bracket notation: key[0], key[1], ...
|
|
46
49
|
if (Array.isArray(value)) {
|
|
47
50
|
for (let i = 0; i < value.length; i++) {
|
|
48
|
-
|
|
51
|
+
const indexed: Record<string, FormDataValue | undefined> = { [String(i)]: value[i] }
|
|
52
|
+
this.toFormData(indexed, form, formKey)
|
|
49
53
|
}
|
|
50
54
|
continue
|
|
51
55
|
}
|
|
@@ -58,7 +62,7 @@ export class FormDataBody<RequestBody> implements BodyContract {
|
|
|
58
62
|
|
|
59
63
|
// if the property is an object, use recursivity.
|
|
60
64
|
if (isObject(value)) {
|
|
61
|
-
this.toFormData(value as
|
|
65
|
+
this.toFormData(value as Record<string, FormDataValue | undefined>, form, formKey)
|
|
62
66
|
continue
|
|
63
67
|
}
|
|
64
68
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ResponseException } from './ResponseException'
|
|
2
|
+
import { type ResponseHandlerContract } from '../drivers/contracts/ResponseHandlerContract'
|
|
3
|
+
|
|
4
|
+
export class InvalidJsonException extends ResponseException {
|
|
5
|
+
public constructor(
|
|
6
|
+
response: ResponseHandlerContract,
|
|
7
|
+
protected cause: unknown
|
|
8
|
+
) {
|
|
9
|
+
super(response)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public getCause(): unknown {
|
|
13
|
+
return this.cause
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ValidationException } from './ValidationException'
|
|
2
|
+
import { NotFoundException } from './NotFoundException'
|
|
3
|
+
import { NoResponseReceivedException } from './NoResponseReceivedException'
|
|
4
|
+
import { UnauthorizedException } from './UnauthorizedException'
|
|
5
|
+
import { ForbiddenException } from './ForbiddenException'
|
|
6
|
+
import { BadRequestException } from './BadRequestException'
|
|
7
|
+
import { MethodNotAllowedException } from './MethodNotAllowedException'
|
|
8
|
+
import { RequestTimeoutException } from './RequestTimeoutException'
|
|
9
|
+
import { ConflictException } from './ConflictException'
|
|
10
|
+
import { GoneException } from './GoneException'
|
|
11
|
+
import { PreconditionFailedException } from './PreconditionFailedException'
|
|
12
|
+
import { PayloadTooLargeException } from './PayloadTooLargeException'
|
|
13
|
+
import { UnsupportedMediaTypeException } from './UnsupportedMediaTypeException'
|
|
14
|
+
import { PageExpiredException } from './PageExpiredException'
|
|
15
|
+
import { ServerErrorException } from './ServerErrorException'
|
|
16
|
+
import { NotImplementedException } from './NotImplementedException'
|
|
17
|
+
import { BadGatewayException } from './BadGatewayException'
|
|
18
|
+
import { ServiceUnavailableException } from './ServiceUnavailableException'
|
|
19
|
+
import { GatewayTimeoutException } from './GatewayTimeoutException'
|
|
20
|
+
import { TooManyRequestsException } from './TooManyRequestsException'
|
|
21
|
+
import { LockedException } from './LockedException'
|
|
22
|
+
import { InvalidJsonException } from './InvalidJsonException'
|
|
23
|
+
import { ResponseException } from './ResponseException'
|
|
24
|
+
import { ResponseBodyException } from './ResponseBodyException'
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
ValidationException,
|
|
28
|
+
NotFoundException,
|
|
29
|
+
NoResponseReceivedException,
|
|
30
|
+
UnauthorizedException,
|
|
31
|
+
PageExpiredException,
|
|
32
|
+
ServerErrorException,
|
|
33
|
+
NotImplementedException,
|
|
34
|
+
BadGatewayException,
|
|
35
|
+
ServiceUnavailableException,
|
|
36
|
+
GatewayTimeoutException,
|
|
37
|
+
TooManyRequestsException,
|
|
38
|
+
LockedException,
|
|
39
|
+
InvalidJsonException,
|
|
40
|
+
ResponseException,
|
|
41
|
+
ResponseBodyException,
|
|
42
|
+
ForbiddenException,
|
|
43
|
+
BadRequestException,
|
|
44
|
+
MethodNotAllowedException,
|
|
45
|
+
RequestTimeoutException,
|
|
46
|
+
ConflictException,
|
|
47
|
+
GoneException,
|
|
48
|
+
PreconditionFailedException,
|
|
49
|
+
PayloadTooLargeException,
|
|
50
|
+
UnsupportedMediaTypeException
|
|
51
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FormDataBody } from '../bodies/FormDataBody'
|
|
2
|
+
import { type BodyFactoryContract } from '../contracts/BodyFactoryContract'
|
|
3
|
+
import { type BodyContract } from '../contracts/BodyContract'
|
|
4
|
+
|
|
5
|
+
type FormDataPrimitive = string | number | boolean | null | Date | Blob
|
|
6
|
+
|
|
7
|
+
export type FormDataValue = FormDataPrimitive | FormDataValue[] | { [key: string]: FormDataValue }
|
|
8
|
+
|
|
9
|
+
export class FormDataFactory<
|
|
10
|
+
RequestBodyInterface extends {
|
|
11
|
+
[K in keyof RequestBodyInterface]: FormDataValue | undefined
|
|
12
|
+
}
|
|
13
|
+
> implements BodyFactoryContract<RequestBodyInterface> {
|
|
14
|
+
public make(body: RequestBodyInterface): BodyContract {
|
|
15
|
+
return new FormDataBody<RequestBodyInterface>(body)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -5,6 +5,7 @@ import { PlainTextResponse } from './responses/PlainTextResponse'
|
|
|
5
5
|
import { BlobResponse } from './responses/BlobResponse'
|
|
6
6
|
import { BaseRequest } from './BaseRequest'
|
|
7
7
|
import { ErrorHandler } from './ErrorHandler'
|
|
8
|
+
import { RequestErrorRouter } from './RequestErrorRouter'
|
|
8
9
|
import { RequestEvents } from './RequestEvents.enum'
|
|
9
10
|
import { RequestMethodEnum } from './RequestMethod.enum'
|
|
10
11
|
import { JsonBodyFactory } from './factories/JsonBodyFactory'
|
|
@@ -12,7 +13,6 @@ import { FormDataFactory } from './factories/FormDataFactory'
|
|
|
12
13
|
import { type BodyContract } from './contracts/BodyContract'
|
|
13
14
|
import { type RequestLoaderContract } from './contracts/RequestLoaderContract'
|
|
14
15
|
import { type RequestDriverContract } from './contracts/RequestDriverContract'
|
|
15
|
-
import { type PaginationParamsContract } from '../laravel/pagination/contracts/PaginationParamsContract'
|
|
16
16
|
import { type RequestLoaderFactoryContract } from './contracts/RequestLoaderFactoryContract'
|
|
17
17
|
import { type DriverConfigContract } from './contracts/DriverConfigContract'
|
|
18
18
|
import { type BodyFactoryContract } from './contracts/BodyFactoryContract'
|
|
@@ -29,6 +29,7 @@ export {
|
|
|
29
29
|
PlainTextResponse,
|
|
30
30
|
BaseRequest,
|
|
31
31
|
ErrorHandler,
|
|
32
|
+
RequestErrorRouter,
|
|
32
33
|
RequestEvents,
|
|
33
34
|
RequestMethodEnum,
|
|
34
35
|
ResponseException,
|
|
@@ -37,7 +38,6 @@ export {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export type {
|
|
40
|
-
PaginationParamsContract,
|
|
41
41
|
RequestDriverContract,
|
|
42
42
|
RequestLoaderContract,
|
|
43
43
|
BodyContract,
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* https://gist.github.com/GFoley83/5877f6c09fbcfd62569c51dc91444cf0
|
|
23
23
|
*/
|
|
24
24
|
export class DeferredPromise<T> implements Promise<T> {
|
|
25
|
-
readonly [Symbol.toStringTag]
|
|
25
|
+
readonly [Symbol.toStringTag] = 'Promise' as const
|
|
26
26
|
|
|
27
27
|
private _promise: Promise<T>
|
|
28
28
|
private _resolve!: (value: T | PromiseLike<T>) => void
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { getCurrentInstance, h, onUnmounted, render } from 'vue'
|
|
2
2
|
import { type Component } from 'vue'
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export enum ConfirmDialogSeverity {
|
|
5
|
+
INFO = 'info',
|
|
6
|
+
WARNING = 'warning',
|
|
7
|
+
DANGER = 'danger'
|
|
8
|
+
}
|
|
5
9
|
|
|
6
10
|
export interface ConfirmDialogOptions {
|
|
7
11
|
getMessage(): string
|
|
@@ -6,6 +6,9 @@ export interface ModelValueOptions<T> extends ParentModelValueOptions {
|
|
|
6
6
|
callback?: (value: T) => void
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use Vue 3.4+ `defineModel()` instead.
|
|
11
|
+
*/
|
|
9
12
|
export default function <T, EmitType>(props: ModelValueProps, emit: EmitType, options: ModelValueOptions<T> = {}) {
|
|
10
13
|
const { name = 'modelValue', callback = () => {} } = options
|
|
11
14
|
|