@blueprint-ts/core 1.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.
Files changed (158) hide show
  1. package/.editorconfig +508 -0
  2. package/.eslintrc.cjs +15 -0
  3. package/.prettierrc.json +8 -0
  4. package/LICENSE +21 -0
  5. package/README.md +1 -0
  6. package/docker-compose.yaml +8 -0
  7. package/docs/.vitepress/config.ts +68 -0
  8. package/docs/.vitepress/theme/Layout.vue +14 -0
  9. package/docs/.vitepress/theme/components/VersionSelector.vue +64 -0
  10. package/docs/.vitepress/theme/index.js +13 -0
  11. package/docs/index.md +70 -0
  12. package/docs/services/laravel/pagination.md +54 -0
  13. package/docs/services/laravel/requests.md +62 -0
  14. package/docs/services/requests/index.md +74 -0
  15. package/docs/vue/forms.md +326 -0
  16. package/docs/vue/requests/route-model-binding.md +66 -0
  17. package/docs/vue/state.md +293 -0
  18. package/env.d.ts +1 -0
  19. package/eslint.config.js +15 -0
  20. package/examples/files/7z2404-x64.exe +0 -0
  21. package/examples/index.html +14 -0
  22. package/examples/js/app.js +8 -0
  23. package/examples/js/router.js +22 -0
  24. package/examples/js/view/App.vue +49 -0
  25. package/examples/js/view/layout/DemoPage.vue +28 -0
  26. package/examples/js/view/pagination/Pagination.vue +28 -0
  27. package/examples/js/view/pagination/components/errorPagination/ErrorPagination.vue +71 -0
  28. package/examples/js/view/pagination/components/errorPagination/GetProductsRequest.ts +54 -0
  29. package/examples/js/view/pagination/components/infiniteScrolling/GetProductsRequest.ts +50 -0
  30. package/examples/js/view/pagination/components/infiniteScrolling/InfiniteScrolling.vue +57 -0
  31. package/examples/js/view/pagination/components/tablePagination/GetProductsRequest.ts +50 -0
  32. package/examples/js/view/pagination/components/tablePagination/TablePagination.vue +63 -0
  33. package/examples/js/view/requests/Requests.vue +34 -0
  34. package/examples/js/view/requests/components/abortableRequest/AbortableRequest.vue +36 -0
  35. package/examples/js/view/requests/components/abortableRequest/GetProductsRequest.ts +25 -0
  36. package/examples/js/view/requests/components/fileDownloadRequest/DownloadFileRequest.ts +15 -0
  37. package/examples/js/view/requests/components/fileDownloadRequest/FileDownloadRequest.vue +44 -0
  38. package/examples/js/view/requests/components/getRequestWithDynamicParams/GetProductsRequest.ts +34 -0
  39. package/examples/js/view/requests/components/getRequestWithDynamicParams/GetRequestWithDynamicParams.vue +59 -0
  40. package/examples/js/view/requests/components/serverErrorRequest/ServerErrorRequest.ts +21 -0
  41. package/examples/js/view/requests/components/serverErrorRequest/ServerErrorRequest.vue +53 -0
  42. package/package.json +81 -0
  43. package/release-tool.json +7 -0
  44. package/src/helpers.ts +78 -0
  45. package/src/service/bulkRequests/BulkRequestEvent.enum.ts +4 -0
  46. package/src/service/bulkRequests/BulkRequestSender.ts +184 -0
  47. package/src/service/bulkRequests/BulkRequestWrapper.ts +49 -0
  48. package/src/service/bulkRequests/index.ts +6 -0
  49. package/src/service/laravel/pagination/contracts/PaginationParamsContract.ts +4 -0
  50. package/src/service/laravel/pagination/contracts/PaginationResponseBodyContract.ts +6 -0
  51. package/src/service/laravel/pagination/dataDrivers/RequestDriver.ts +32 -0
  52. package/src/service/laravel/pagination/index.ts +7 -0
  53. package/src/service/laravel/requests/JsonBaseRequest.ts +35 -0
  54. package/src/service/laravel/requests/PaginationJsonBaseRequest.ts +29 -0
  55. package/src/service/laravel/requests/index.ts +9 -0
  56. package/src/service/laravel/requests/responses/JsonResponse.ts +8 -0
  57. package/src/service/laravel/requests/responses/PaginationResponse.ts +16 -0
  58. package/src/service/pagination/InfiniteScroller.ts +21 -0
  59. package/src/service/pagination/Paginator.ts +149 -0
  60. package/src/service/pagination/contracts/PaginateableRequestContract.ts +13 -0
  61. package/src/service/pagination/contracts/PaginationDataDriverContract.ts +5 -0
  62. package/src/service/pagination/contracts/PaginationResponseContract.ts +7 -0
  63. package/src/service/pagination/contracts/PaginatorLoadDataOptions.ts +4 -0
  64. package/src/service/pagination/contracts/ViewDriverContract.ts +12 -0
  65. package/src/service/pagination/contracts/ViewDriverFactoryContract.ts +5 -0
  66. package/src/service/pagination/dataDrivers/ArrayDriver.ts +28 -0
  67. package/src/service/pagination/dtos/PaginationDataDto.ts +14 -0
  68. package/src/service/pagination/factories/VuePaginationDriverFactory.ts +9 -0
  69. package/src/service/pagination/frontendDrivers/VuePaginationDriver.ts +61 -0
  70. package/src/service/pagination/index.ts +16 -0
  71. package/src/service/persistenceDrivers/LocalStorageDriver.ts +22 -0
  72. package/src/service/persistenceDrivers/NonPersistentDriver.ts +12 -0
  73. package/src/service/persistenceDrivers/SessionStorageDriver.ts +22 -0
  74. package/src/service/persistenceDrivers/index.ts +8 -0
  75. package/src/service/persistenceDrivers/types/PersistenceDriver.ts +5 -0
  76. package/src/service/requests/BaseRequest.ts +197 -0
  77. package/src/service/requests/ErrorHandler.ts +64 -0
  78. package/src/service/requests/RequestEvents.enum.ts +3 -0
  79. package/src/service/requests/RequestMethod.enum.ts +8 -0
  80. package/src/service/requests/bodies/FormDataBody.ts +41 -0
  81. package/src/service/requests/bodies/JsonBody.ts +16 -0
  82. package/src/service/requests/contracts/AbortableRequestContract.ts +3 -0
  83. package/src/service/requests/contracts/BaseRequestContract.ts +36 -0
  84. package/src/service/requests/contracts/BodyContract.ts +7 -0
  85. package/src/service/requests/contracts/BodyFactoryContract.ts +5 -0
  86. package/src/service/requests/contracts/DriverConfigContract.ts +7 -0
  87. package/src/service/requests/contracts/HeadersContract.ts +5 -0
  88. package/src/service/requests/contracts/RequestDriverContract.ts +15 -0
  89. package/src/service/requests/contracts/RequestLoaderContract.ts +5 -0
  90. package/src/service/requests/contracts/RequestLoaderFactoryContract.ts +5 -0
  91. package/src/service/requests/contracts/ResponseContract.ts +7 -0
  92. package/src/service/requests/drivers/contracts/ResponseHandlerContract.ts +10 -0
  93. package/src/service/requests/drivers/fetch/FetchDriver.ts +115 -0
  94. package/src/service/requests/drivers/fetch/FetchResponse.ts +30 -0
  95. package/src/service/requests/exceptions/NoResponseReceivedException.ts +3 -0
  96. package/src/service/requests/exceptions/NotFoundException.ts +3 -0
  97. package/src/service/requests/exceptions/PageExpiredException.ts +3 -0
  98. package/src/service/requests/exceptions/ResponseBodyException.ts +15 -0
  99. package/src/service/requests/exceptions/ResponseException.ts +11 -0
  100. package/src/service/requests/exceptions/ServerErrorException.ts +3 -0
  101. package/src/service/requests/exceptions/UnauthorizedException.ts +3 -0
  102. package/src/service/requests/exceptions/ValidationException.ts +3 -0
  103. package/src/service/requests/exceptions/index.ts +19 -0
  104. package/src/service/requests/factories/FormDataFactory.ts +9 -0
  105. package/src/service/requests/factories/JsonBodyFactory.ts +9 -0
  106. package/src/service/requests/index.ts +50 -0
  107. package/src/service/requests/responses/BaseResponse.ts +41 -0
  108. package/src/service/requests/responses/BlobResponse.ts +19 -0
  109. package/src/service/requests/responses/JsonResponse.ts +15 -0
  110. package/src/service/requests/responses/PlainTextResponse.ts +15 -0
  111. package/src/service/support/DeferredPromise.ts +67 -0
  112. package/src/service/support/index.ts +3 -0
  113. package/src/vue/composables/useConfirmDialog.ts +59 -0
  114. package/src/vue/composables/useGlobalCheckbox.ts +145 -0
  115. package/src/vue/composables/useIsEmpty.ts +34 -0
  116. package/src/vue/composables/useIsOpen.ts +37 -0
  117. package/src/vue/composables/useIsOpenFromVar.ts +61 -0
  118. package/src/vue/composables/useModelWrapper.ts +24 -0
  119. package/src/vue/composables/useOnOpen.ts +34 -0
  120. package/src/vue/contracts/ModelValueOptions.ts +3 -0
  121. package/src/vue/contracts/ModelValueProps.ts +3 -0
  122. package/src/vue/forms/BaseForm.ts +1074 -0
  123. package/src/vue/forms/PropertyAwareArray.ts +78 -0
  124. package/src/vue/forms/index.ts +11 -0
  125. package/src/vue/forms/types/PersistedForm.ts +6 -0
  126. package/src/vue/forms/validation/ValidationMode.enum.ts +14 -0
  127. package/src/vue/forms/validation/index.ts +12 -0
  128. package/src/vue/forms/validation/rules/BaseRule.ts +7 -0
  129. package/src/vue/forms/validation/rules/ConfirmedRule.ts +39 -0
  130. package/src/vue/forms/validation/rules/MinRule.ts +61 -0
  131. package/src/vue/forms/validation/rules/RequiredRule.ts +19 -0
  132. package/src/vue/forms/validation/rules/UrlRule.ts +24 -0
  133. package/src/vue/forms/validation/types/BidirectionalRule.ts +11 -0
  134. package/src/vue/index.ts +14 -0
  135. package/src/vue/requests/factories/VueRequestLoaderFactory.ts +9 -0
  136. package/src/vue/requests/index.ts +5 -0
  137. package/src/vue/requests/loaders/VueRequestBatchLoader.ts +30 -0
  138. package/src/vue/requests/loaders/VueRequestLoader.ts +18 -0
  139. package/src/vue/router/routeModelBinding/RouteModelRequestResolver.ts +11 -0
  140. package/src/vue/router/routeModelBinding/defineRoute.ts +31 -0
  141. package/src/vue/router/routeModelBinding/index.ts +8 -0
  142. package/src/vue/router/routeModelBinding/installRouteInjection.ts +73 -0
  143. package/src/vue/router/routeModelBinding/types.ts +46 -0
  144. package/src/vue/state/State.ts +391 -0
  145. package/src/vue/state/index.ts +3 -0
  146. package/tests/service/helpers/mergeDeep.test.ts +53 -0
  147. package/tests/service/laravel/pagination/dataDrivers/RequestDriver.test.ts +84 -0
  148. package/tests/service/laravel/requests/JsonBaseRequest.test.ts +43 -0
  149. package/tests/service/laravel/requests/PaginationJsonBaseRequest.test.ts +58 -0
  150. package/tests/service/laravel/requests/responses/JsonResponse.test.ts +59 -0
  151. package/tests/service/laravel/requests/responses/PaginationResponse.test.ts +127 -0
  152. package/tests/service/pagination/dtos/PaginationDataDto.test.ts +35 -0
  153. package/tests/service/pagination/factories/VuePaginationDriverFactory.test.ts +32 -0
  154. package/tests/service/pagination/frontendDrivers/VuePaginationDriver.test.ts +66 -0
  155. package/tests/service/requests/ErrorHandler.test.ts +141 -0
  156. package/tsconfig.json +114 -0
  157. package/vite.config.ts +34 -0
  158. package/vitest.config.ts +14 -0
@@ -0,0 +1,127 @@
1
+ import { describe, test, expect, beforeEach, vi } from 'vitest';
2
+ import { PaginationResponse } from '../../../../../src/service/laravel/requests'
3
+
4
+ describe('PaginationResponse', () => {
5
+ let paginationResponse: PaginationResponse<{ id: number; name: string }>;
6
+
7
+ beforeEach(() => {
8
+ // Erstelle für jeden Test eine neue Instanz
9
+ paginationResponse = new PaginationResponse();
10
+ });
11
+
12
+ test('should correctly return total from the response body meta', async () => {
13
+ const mockBody = {
14
+ data: { id: 1, name: 'Test Data' },
15
+ meta: { total: 42 },
16
+ };
17
+
18
+ // Simuliere den ResponseHandler mit einem Mock
19
+ const mockResponseHandler = {
20
+ async json() {
21
+ return mockBody;
22
+ },
23
+ getRawResponse: vi.fn(),
24
+ getStatusCode: vi.fn(),
25
+ getHeaders: vi.fn(),
26
+ };
27
+
28
+ // Setze die Response und überprüfe getTotal
29
+ await paginationResponse.setResponse(mockResponseHandler as any);
30
+
31
+ const total = paginationResponse.getTotal();
32
+ expect(total).toBe(mockBody.meta.total);
33
+ });
34
+
35
+ test('should correctly return data from the response body data', async () => {
36
+ const mockBody = {
37
+ data: { id: 1, name: 'Test Data' },
38
+ meta: { total: 42 },
39
+ };
40
+
41
+ // Simuliere den ResponseHandler
42
+ const mockResponseHandler = {
43
+ async json() {
44
+ return mockBody;
45
+ },
46
+ getRawResponse: vi.fn(),
47
+ getStatusCode: vi.fn(),
48
+ getHeaders: vi.fn(),
49
+ };
50
+
51
+ // Setze die Response und überprüfe die Methode getData
52
+ await paginationResponse.setResponse(mockResponseHandler as any);
53
+
54
+ const data = paginationResponse.getData();
55
+ expect(data).toEqual(mockBody.data);
56
+ });
57
+
58
+ test('should throw error when body is not set before calling getTotal', () => {
59
+ // Rufe getTotal auf, ohne den Body zu setzen
60
+ expect(() => paginationResponse.getTotal()).toThrowError(
61
+ 'Response body is not set'
62
+ );
63
+ });
64
+
65
+ test('should throw error when body is not set before calling getData', () => {
66
+ // Rufe getData auf, ohne den Body zu setzen
67
+ expect(() => paginationResponse.getData()).toThrowError(
68
+ 'Response body is not set'
69
+ );
70
+ });
71
+
72
+ test('should preserve raw response, headers, and status code', async () => {
73
+ const mockBody = {
74
+ data: { id: 3, name: 'Test Headers' },
75
+ meta: { total: 15 },
76
+ };
77
+
78
+ const mockRawResponse = { ok: true };
79
+ const mockHeaders = { 'content-type': 'application/json' };
80
+ const mockStatusCode = 200;
81
+
82
+ const mockResponseHandler = {
83
+ async json() {
84
+ return mockBody;
85
+ },
86
+ getRawResponse: () => mockRawResponse,
87
+ getStatusCode: () => mockStatusCode,
88
+ getHeaders: () => mockHeaders,
89
+ };
90
+
91
+ // Setze die Response
92
+ await paginationResponse.setResponse(mockResponseHandler as any);
93
+
94
+ // Prüfe getRawResponse, getHeaders und getStatusCode
95
+ expect(paginationResponse.getData()).toEqual(mockBody.data);
96
+ expect(paginationResponse.getTotal()).toBe(mockBody.meta.total);
97
+ expect(paginationResponse.getRawResponse()).toEqual(mockRawResponse);
98
+ expect(paginationResponse.getHeaders()).toEqual(mockHeaders);
99
+ expect(paginationResponse.getStatusCode()).toBe(mockStatusCode);
100
+ });
101
+
102
+ test('should handle responses with no meta data gracefully', async () => {
103
+ const mockBody = {
104
+ data: { id: 1, name: 'Test Data without Meta' },
105
+ meta: null, // Keine meta-Daten
106
+ };
107
+
108
+ const mockResponseHandler = {
109
+ async json() {
110
+ return mockBody;
111
+ },
112
+ getRawResponse: vi.fn(),
113
+ getStatusCode: vi.fn(),
114
+ getHeaders: vi.fn(),
115
+ };
116
+
117
+ // Setze die Response, auch wenn meta null ist
118
+ await paginationResponse.setResponse(mockResponseHandler as any);
119
+
120
+ const data = paginationResponse.getData();
121
+ expect(data).toEqual(mockBody.data);
122
+
123
+ expect(() => paginationResponse.getTotal()).toThrowError(
124
+ "Cannot read properties of null (reading 'total')"
125
+ );
126
+ });
127
+ });
@@ -0,0 +1,35 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { PaginationDataDto } from '../../../../src/service/pagination'
3
+
4
+ describe('PaginationDataDto', () => {
5
+ interface MockResource {
6
+ id: number;
7
+ name: string;
8
+ }
9
+
10
+ it('should correctly store and retrieve data', () => {
11
+ const mockData: MockResource = { id: 1, name: 'Test' };
12
+ const mockTotal = 100;
13
+
14
+ const paginationData = new PaginationDataDto(mockData, mockTotal);
15
+
16
+ // Test getData method
17
+ expect(paginationData.getData()).toEqual(mockData);
18
+
19
+ // Test getTotal method
20
+ expect(paginationData.getTotal()).toBe(mockTotal);
21
+ });
22
+
23
+ it('should handle empty or null data', () => {
24
+ const emptyMockData = null;
25
+ const total = 0;
26
+
27
+ const paginationData = new PaginationDataDto(emptyMockData, total);
28
+
29
+ // Test getData method
30
+ expect(paginationData.getData()).toBeNull();
31
+
32
+ // Test getTotal method
33
+ expect(paginationData.getTotal()).toBe(0);
34
+ });
35
+ });
@@ -0,0 +1,32 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { VuePaginationDriverFactory } from '../../../../src/service/pagination'
3
+ import { VuePaginationDriver } from '../../../../src/service/pagination'
4
+
5
+ describe('VuePaginationDriverFactory', () => {
6
+ it('should create an instance of VuePaginationDriver', () => {
7
+ const factory = new VuePaginationDriverFactory();
8
+
9
+ const pageNumber = 1;
10
+ const pageSize = 10;
11
+
12
+ const driver = factory.make(pageNumber, pageSize);
13
+
14
+ // Test if the returned object is an instance of VuePaginationDriver
15
+ expect(driver).toBeInstanceOf(VuePaginationDriver);
16
+ });
17
+
18
+ it('should correctly pass pageNumber and pageSize to VuePaginationDriver', () => {
19
+ const factory = new VuePaginationDriverFactory();
20
+
21
+ const pageNumber = 3;
22
+ const pageSize = 20;
23
+
24
+ const driver = factory.make(pageNumber, pageSize);
25
+
26
+ // Cast to VuePaginationDriver to access its properties (falls nötig)
27
+ const vueDriver = driver as VuePaginationDriver<unknown[]>;
28
+
29
+ expect(vueDriver.getCurrentPage()).toBe(pageNumber);
30
+ expect(vueDriver.getPageSize()).toBe(pageSize);
31
+ });
32
+ });
@@ -0,0 +1,66 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { VuePaginationDriver } from '../../../../src/service/pagination'
3
+
4
+ describe('VuePaginationDriver', () => {
5
+ it('should initialize with correct default values', () => {
6
+ const pageNumber = 1;
7
+ const pageSize = 10;
8
+ const driver = new VuePaginationDriver(pageNumber, pageSize);
9
+
10
+ expect(driver.getData()).toEqual([]);
11
+ expect(driver.getCurrentPage()).toBe(pageNumber);
12
+ expect(driver.getPageSize()).toBe(pageSize);
13
+ expect(driver.getTotal()).toBe(0);
14
+ expect(driver.getLastPage()).toBe(0);
15
+ expect(driver.getPages()).toEqual([]);
16
+ });
17
+
18
+ it('should set and get data correctly', () => {
19
+ const driver = new VuePaginationDriver(1, 10);
20
+
21
+ const data = [{ id: 1 }, { id: 2 }];
22
+ driver.setData(data);
23
+
24
+ expect(driver.getData()).toEqual(data);
25
+ });
26
+
27
+ it('should set and get total correctly', () => {
28
+ const driver = new VuePaginationDriver(1, 10);
29
+
30
+ driver.setTotal(100);
31
+
32
+ expect(driver.getTotal()).toBe(100);
33
+ expect(driver.getLastPage()).toBe(10); // 100 items, 10 items per page
34
+ expect(driver.getPages()).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
35
+ });
36
+
37
+ it('should update current page correctly', () => {
38
+ const driver = new VuePaginationDriver(1, 10);
39
+
40
+ driver.setPage(5);
41
+ expect(driver.getCurrentPage()).toBe(5);
42
+ });
43
+
44
+ it('should update page size correctly', () => {
45
+ const driver = new VuePaginationDriver(1, 10);
46
+
47
+ driver.setPageSize(20);
48
+ expect(driver.getPageSize()).toBe(20);
49
+
50
+ driver.setTotal(100);
51
+ expect(driver.getLastPage()).toBe(5); // 100 items, 20 items per page
52
+ expect(driver.getPages()).toEqual([1, 2, 3, 4, 5]);
53
+ });
54
+
55
+ it('should compute correct pagination values when data changes', () => {
56
+ const driver = new VuePaginationDriver(1, 10);
57
+
58
+ driver.setTotal(35); // 35 items, 10 items per page
59
+ expect(driver.getLastPage()).toBe(4);
60
+ expect(driver.getPages()).toEqual([1, 2, 3, 4]);
61
+
62
+ driver.setPageSize(7); // Change page size
63
+ expect(driver.getLastPage()).toBe(5); // 35 items, 7 items per page
64
+ expect(driver.getPages()).toEqual([1, 2, 3, 4, 5]);
65
+ });
66
+ });
@@ -0,0 +1,141 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { ErrorHandler } from '../../../src/service/requests'
3
+
4
+ import {
5
+ PageExpiredException,
6
+ NotFoundException,
7
+ UnauthorizedException,
8
+ ValidationException,
9
+ ResponseException,
10
+ NoResponseReceivedException,
11
+ ServerErrorException
12
+ } from '../../../src/service/requests/exceptions';
13
+
14
+ describe('ErrorHandler', () => {
15
+ it('should throw UnauthorizedException for status code 401', () => {
16
+ // Mock-response that mimics a ResponseHandlerContract
17
+ const mockResponse = {
18
+ getStatusCode: vi.fn().mockReturnValue(401),
19
+ };
20
+
21
+ // Mock the ResponseException with the mocked response
22
+ const mockError = {
23
+ getResponse: vi.fn().mockReturnValue(mockResponse),
24
+ };
25
+
26
+ expect(() => new ErrorHandler(mockError as any)).toThrow(UnauthorizedException);
27
+
28
+ // Assert that methods were called
29
+ expect(mockError.getResponse).toHaveBeenCalled();
30
+ expect(mockResponse.getStatusCode).toHaveBeenCalled();
31
+ });
32
+
33
+ it('should throw NotFoundException for status code 404', () => {
34
+ const mockResponse = {
35
+ getStatusCode: vi.fn().mockReturnValue(404),
36
+ };
37
+
38
+ const mockError = {
39
+ getResponse: vi.fn().mockReturnValue(mockResponse),
40
+ };
41
+
42
+ expect(() => new ErrorHandler(mockError as any)).toThrow(NotFoundException);
43
+
44
+ expect(mockError.getResponse).toHaveBeenCalled();
45
+ expect(mockResponse.getStatusCode).toHaveBeenCalled();
46
+ });
47
+
48
+ it('should throw PageExpiredException for status code 419', () => {
49
+ const mockResponse = {
50
+ getStatusCode: vi.fn().mockReturnValue(419),
51
+ };
52
+
53
+ const mockError = {
54
+ getResponse: vi.fn().mockReturnValue(mockResponse),
55
+ };
56
+
57
+ expect(() => new ErrorHandler(mockError as any)).toThrow(PageExpiredException);
58
+
59
+ expect(mockError.getResponse).toHaveBeenCalled();
60
+ expect(mockResponse.getStatusCode).toHaveBeenCalled();
61
+ });
62
+
63
+ it('should throw ValidationException for status code 422', () => {
64
+ const mockResponse = {
65
+ getStatusCode: vi.fn().mockReturnValue(422),
66
+ };
67
+
68
+ const mockError = {
69
+ getResponse: vi.fn().mockReturnValue(mockResponse),
70
+ };
71
+
72
+ expect(() => new ErrorHandler(mockError as any)).toThrow(ValidationException);
73
+
74
+ expect(mockError.getResponse).toHaveBeenCalled();
75
+ expect(mockResponse.getStatusCode).toHaveBeenCalled();
76
+ });
77
+
78
+ it('should throw ServerErrorException for status code 500', () => {
79
+ const mockResponse = {
80
+ getStatusCode: vi.fn().mockReturnValue(500),
81
+ };
82
+
83
+ const mockError = {
84
+ getResponse: vi.fn().mockReturnValue(mockResponse),
85
+ };
86
+
87
+ expect(() => new ErrorHandler(mockError as any)).toThrow(ServerErrorException);
88
+
89
+ expect(mockError.getResponse).toHaveBeenCalled();
90
+ expect(mockResponse.getStatusCode).toHaveBeenCalled();
91
+ });
92
+
93
+ it('should throw NoResponseReceivedException if no status code in response', () => {
94
+ const mockResponse = {
95
+ getStatusCode: vi.fn().mockReturnValue(undefined),
96
+ };
97
+
98
+ const mockError = {
99
+ getResponse: vi.fn().mockReturnValue(mockResponse),
100
+ };
101
+
102
+ expect(() => new ErrorHandler(mockError as any)).toThrow(NoResponseReceivedException);
103
+
104
+ expect(mockError.getResponse).toHaveBeenCalled();
105
+ expect(mockResponse.getStatusCode).toHaveBeenCalled();
106
+ });
107
+
108
+ it('should throw ResponseException for other status codes', () => {
109
+ const mockResponse = {
110
+ getStatusCode: vi.fn().mockReturnValue(499),
111
+ };
112
+
113
+ const mockError = {
114
+ getResponse: vi.fn().mockReturnValue(mockResponse),
115
+ };
116
+
117
+ expect(() => new ErrorHandler(mockError as any)).toThrow(ResponseException);
118
+
119
+ expect(mockError.getResponse).toHaveBeenCalled();
120
+ expect(mockResponse.getStatusCode).toHaveBeenCalled();
121
+ });
122
+
123
+ it('should correctly use global error handler if registered', () => {
124
+ // Set up the global handler
125
+ const handlerMock = vi.fn().mockReturnValue(false);
126
+ ErrorHandler.registerHandler(handlerMock);
127
+
128
+ const mockResponse = {
129
+ getStatusCode: vi.fn().mockReturnValue(500),
130
+ };
131
+
132
+ const mockError = {
133
+ getResponse: vi.fn().mockReturnValue(mockResponse),
134
+ };
135
+
136
+ // Since the handler returns false, the error should not propagate further
137
+ expect(() => new ErrorHandler(mockError as any)).not.toThrow();
138
+
139
+ expect(handlerMock).toHaveBeenCalledWith(mockError);
140
+ });
141
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,114 @@
1
+ {
2
+ "include": ["env.d.ts", "src/**/*.ts"],
3
+ "exclude": ["tests/**/*"],
4
+
5
+ "compilerOptions": {
6
+ /* Visit https://aka.ms/tsconfig to read more about this file */
7
+
8
+ /* Projects */
9
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
10
+ "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
11
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
12
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
13
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
14
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
15
+
16
+ /* Language and Environment */
17
+ "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
18
+ "lib": ["DOM", "ES6"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
19
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
20
+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
21
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
22
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
23
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
24
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
25
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
26
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
27
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
28
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
29
+
30
+ /* Modules */
31
+ // "module": "nodenext", /* Specify what module code is generated. */
32
+ // "rootDir": "./", /* Specify the root folder within your source files. */
33
+ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
34
+ // "baseUrl": "", /* Specify the base directory to resolve non-relative module names. */
35
+ // "paths": {},
36
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
37
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
38
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
39
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
40
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
41
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
42
+ // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
43
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
44
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
45
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
46
+ // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
47
+ // "resolveJsonModule": true, /* Enable importing .json files. */
48
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
49
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
50
+
51
+ /* JavaScript Support */
52
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
53
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
54
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
55
+
56
+ /* Emit */
57
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
58
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
59
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
60
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
61
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
62
+ // "noEmit": true, /* Disable emitting files from a compilation. */
63
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
64
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
65
+ // "removeComments": true, /* Disable emitting comments. */
66
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
67
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
68
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
69
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
70
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
71
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
72
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
73
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
74
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
75
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
76
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
77
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
78
+
79
+ /* Interop Constraints */
80
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
81
+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
82
+ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
83
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
84
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
85
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
86
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
87
+
88
+ /* Type Checking */
89
+ "strict": true, /* Enable all strict type-checking options. */
90
+ "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
91
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
92
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
93
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
94
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
95
+ // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
96
+ "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
97
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
98
+ "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
99
+ "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
100
+ "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
101
+ "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
102
+ "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
103
+ "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
104
+ "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
105
+ "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
106
+ "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
107
+ "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
108
+ "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
109
+
110
+ /* Completeness */
111
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
112
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
113
+ }
114
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { defineConfig } from 'vite'
2
+ import vue from '@vitejs/plugin-vue'
3
+
4
+ // https://vitejs.dev/config/
5
+ export default defineConfig({
6
+ plugins: [
7
+ vue({
8
+ template: {
9
+ transformAssetUrls: {
10
+ // The Vue plugin will re-write asset URLs, when referenced
11
+ // in Single File Components, to point to the Laravel web
12
+ // server. Setting this to `null` allows the Laravel plugin
13
+ // to instead re-write asset URLs to point to the Vite
14
+ // server instead.
15
+ base: null,
16
+
17
+ // The Vue plugin will parse absolute URLs and treat them
18
+ // as absolute paths to files on disk. Setting this to
19
+ // `false` will leave absolute URLs un-touched so they can
20
+ // reference assets in the public directly as expected.
21
+ includeAbsolute: false,
22
+ },
23
+ },
24
+ }),
25
+ ],
26
+ root: 'examples',
27
+ resolve: {
28
+ alias: {
29
+ '@js': '/js',
30
+ '@view': '/js/view',
31
+ '@hank-it/ui': '/../src',
32
+ },
33
+ },
34
+ })
@@ -0,0 +1,14 @@
1
+ import { fileURLToPath } from 'node:url'
2
+ import { mergeConfig, defineConfig, configDefaults } from 'vitest/config'
3
+ import viteConfig from './vite.config'
4
+
5
+ export default mergeConfig(
6
+ viteConfig,
7
+ defineConfig({
8
+ test: {
9
+ environment: 'jsdom',
10
+ exclude: [...configDefaults.exclude, 'e2e/*'],
11
+ root: fileURLToPath(new URL('./', import.meta.url))
12
+ }
13
+ })
14
+ )