@blueprint-ts/core 4.1.0-beta.6 → 5.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 (62) hide show
  1. package/dist/bulkRequests/BulkRequestSender.js +81 -102
  2. package/dist/bulkRequests/BulkRequestWrapper.js +16 -26
  3. package/dist/laravel/pagination/dataDrivers/RequestDriver.js +1 -0
  4. package/dist/pagination/BasePaginator.js +4 -4
  5. package/dist/pagination/PageAwarePaginator.js +4 -1
  6. package/dist/pagination/StatePaginator.js +6 -3
  7. package/dist/pagination/dataDrivers/ArrayDriver.js +1 -0
  8. package/dist/pagination/dtos/PaginationDataDto.js +2 -0
  9. package/dist/pagination/dtos/StatePaginationDataDto.js +1 -0
  10. package/dist/pagination/frontendDrivers/VueBaseViewDriver.js +2 -0
  11. package/dist/pagination/frontendDrivers/VuePaginationDriver.js +6 -0
  12. package/dist/persistenceDrivers/LocalStorageDriver.js +1 -0
  13. package/dist/persistenceDrivers/MemoryPersistenceDriver.js +2 -1
  14. package/dist/persistenceDrivers/SessionStorageDriver.js +1 -0
  15. package/dist/requests/BaseRequest.js +93 -100
  16. package/dist/requests/ErrorHandler.js +21 -31
  17. package/dist/requests/RequestErrorRouter.js +12 -25
  18. package/dist/requests/bodies/BinaryBody.js +2 -0
  19. package/dist/requests/bodies/FormDataBody.js +1 -0
  20. package/dist/requests/bodies/JsonBody.js +1 -0
  21. package/dist/requests/drivers/fetch/FetchDriver.js +26 -26
  22. package/dist/requests/drivers/fetch/FetchResponse.js +7 -21
  23. package/dist/requests/drivers/mock/MockRequestDriver.js +190 -169
  24. package/dist/requests/drivers/mock/MockRequestTestHelpers.js +10 -4
  25. package/dist/requests/drivers/mock/MockResponseHandler.js +12 -23
  26. package/dist/requests/drivers/xhr/XMLHttpRequestDriver.js +68 -74
  27. package/dist/requests/drivers/xhr/XMLHttpRequestResponse.js +9 -21
  28. package/dist/requests/exceptions/InvalidJsonException.js +1 -0
  29. package/dist/requests/exceptions/ResponseBodyException.js +1 -0
  30. package/dist/requests/exceptions/ResponseException.js +1 -0
  31. package/dist/requests/exceptions/StaleResponseException.js +1 -0
  32. package/dist/requests/factories/BinaryBodyFactory.js +1 -0
  33. package/dist/requests/responses/BaseResponse.js +9 -21
  34. package/dist/requests/responses/BlobResponse.js +1 -0
  35. package/dist/support/DeferredPromise.js +5 -4
  36. package/dist/vue/composables/useConfirmDialog.js +7 -18
  37. package/dist/vue/composables/useGlobalCheckbox.js +55 -66
  38. package/dist/vue/forms/BaseForm.d.ts +11 -8
  39. package/dist/vue/forms/BaseForm.js +153 -149
  40. package/dist/vue/forms/PropertyAwareArray.js +0 -1
  41. package/dist/vue/forms/PropertyAwareObject.js +4 -2
  42. package/dist/vue/forms/index.d.ts +2 -2
  43. package/dist/vue/forms/persistence/types.d.ts +2 -0
  44. package/dist/vue/forms/validation/rules/BaseRule.js +3 -16
  45. package/dist/vue/forms/validation/rules/ConfirmedRule.js +2 -0
  46. package/dist/vue/forms/validation/rules/EmailRule.js +1 -0
  47. package/dist/vue/forms/validation/rules/JsonRule.js +2 -1
  48. package/dist/vue/forms/validation/rules/MinRule.js +2 -0
  49. package/dist/vue/forms/validation/rules/PrecognitiveRule.js +21 -31
  50. package/dist/vue/forms/validation/rules/RequiredRule.js +1 -0
  51. package/dist/vue/forms/validation/rules/UrlRule.js +2 -1
  52. package/dist/vue/requests/loaders/VueRequestBatchLoader.js +3 -3
  53. package/dist/vue/requests/loaders/VueRequestLoader.js +1 -0
  54. package/dist/vue/router/routeResourceBinding/RouteResourceBoundView.js +8 -18
  55. package/dist/vue/router/routeResourceBinding/RouteResourceRequestResolver.js +4 -14
  56. package/dist/vue/router/routeResourceBinding/defineRoute.js +8 -7
  57. package/dist/vue/router/routeResourceBinding/installRouteInjection.js +12 -21
  58. package/dist/vue/router/routeResourceBinding/useRouteResource.js +5 -17
  59. package/dist/vue/state/State.d.ts +2 -0
  60. package/dist/vue/state/State.js +24 -11
  61. package/dist/vue/state/index.d.ts +2 -1
  62. package/package.json +27 -27
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { BulkRequestEventEnum } from './BulkRequestEvent.enum';
11
2
  export var BulkRequestExecutionMode;
12
3
  (function (BulkRequestExecutionMode) {
@@ -14,12 +5,15 @@ export var BulkRequestExecutionMode;
14
5
  BulkRequestExecutionMode["SEQUENTIAL"] = "sequential";
15
6
  })(BulkRequestExecutionMode || (BulkRequestExecutionMode = {}));
16
7
  export class BulkRequestSender {
8
+ requests;
9
+ executionMode;
10
+ retryCount;
11
+ events = new Map();
12
+ abortController = undefined;
17
13
  constructor(requests = [], executionMode = BulkRequestExecutionMode.PARALLEL, retryCount = 0) {
18
14
  this.requests = requests;
19
15
  this.executionMode = executionMode;
20
16
  this.retryCount = retryCount;
21
- this.events = new Map();
22
- this.abortController = undefined;
23
17
  }
24
18
  setRequests(requests = []) {
25
19
  this.requests = requests;
@@ -52,110 +46,95 @@ export class BulkRequestSender {
52
46
  callbacks.forEach((callback) => callback(req));
53
47
  }
54
48
  get signal() {
55
- var _a;
56
- return (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal;
49
+ return this.abortController?.signal;
57
50
  }
58
51
  abort() {
59
- var _a;
60
- (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.abort();
52
+ this.abortController?.abort();
61
53
  }
62
- send() {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- this.abortController = new AbortController();
65
- try {
66
- if (this.executionMode === BulkRequestExecutionMode.PARALLEL) {
67
- yield this.sendParallel();
68
- }
69
- else {
70
- yield this.sendSequential();
71
- }
54
+ async send() {
55
+ this.abortController = new AbortController();
56
+ try {
57
+ if (this.executionMode === BulkRequestExecutionMode.PARALLEL) {
58
+ await this.sendParallel();
72
59
  }
73
- catch (error) {
74
- // If an abort occurs, the underlying fetch (or request mechanism) should throw an AbortError.
75
- console.error('Bulk operation aborted or encountered an error:', error);
60
+ else {
61
+ await this.sendSequential();
76
62
  }
77
- return {
78
- getSuccessCount: () => this.requests.filter((r) => !r.hasError()).length,
79
- getErrorCount: () => this.requests.filter((r) => r.hasError()).length,
80
- getSuccessfulResponses: () => this.requests
81
- .filter((r) => !r.hasError())
82
- .map((r) => r.getResponse())
83
- .filter((response) => response !== null),
84
- getFailedResponses: () => this.requests.filter((r) => r.hasError()).map((r) => r.getError())
85
- };
86
- });
63
+ }
64
+ catch (error) {
65
+ // If an abort occurs, the underlying fetch (or request mechanism) should throw an AbortError.
66
+ console.error('Bulk operation aborted or encountered an error:', error);
67
+ }
68
+ return {
69
+ getSuccessCount: () => this.requests.filter((r) => !r.hasError()).length,
70
+ getErrorCount: () => this.requests.filter((r) => r.hasError()).length,
71
+ getSuccessfulResponses: () => this.requests
72
+ .filter((r) => !r.hasError())
73
+ .map((r) => r.getResponse())
74
+ .filter((response) => response !== null),
75
+ getFailedResponses: () => this.requests.filter((r) => r.hasError()).map((r) => r.getError())
76
+ };
87
77
  }
88
- sendParallel() {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- // First attempt for all requests
91
- yield Promise.all(this.requests.map((req) => {
92
- var _a;
93
- return req.send((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal).then(() => {
94
- if (!req.hasError()) {
95
- this.emit(BulkRequestEventEnum.REQUEST_SUCCESSFUL, req);
96
- }
97
- });
98
- }));
99
- // Retry logic for failed requests
100
- let retriesLeft = this.retryCount;
101
- while (retriesLeft > 0) {
102
- const failedRequests = this.requests.filter((req) => req.hasError());
103
- if (failedRequests.length === 0) {
104
- break; // No failed requests to retry
105
- }
106
- console.log(`Retrying ${failedRequests.length} failed requests. Attempts left: ${retriesLeft}`);
107
- yield Promise.all(failedRequests.map((req) => {
108
- var _a;
109
- return req.send((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal).then(() => {
110
- if (!req.hasError()) {
111
- // Success after retry
112
- this.emit(BulkRequestEventEnum.REQUEST_SUCCESSFUL, req);
113
- }
114
- });
115
- }));
116
- retriesLeft--;
78
+ async sendParallel() {
79
+ // First attempt for all requests
80
+ await Promise.all(this.requests.map((req) => req.send(this.abortController?.signal).then(() => {
81
+ if (!req.hasError()) {
82
+ this.emit(BulkRequestEventEnum.REQUEST_SUCCESSFUL, req);
117
83
  }
118
- // Emit failed events for any requests that still have errors after all retries
119
- this.requests
120
- .filter((req) => req.hasError())
121
- .forEach((req) => {
122
- this.emit(BulkRequestEventEnum.REQUEST_FAILED, req);
123
- });
124
- });
125
- }
126
- sendSequential() {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- var _a, _b;
129
- // First attempt for all requests
130
- for (const req of this.requests) {
131
- yield req.send((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal);
84
+ })));
85
+ // Retry logic for failed requests
86
+ let retriesLeft = this.retryCount;
87
+ while (retriesLeft > 0) {
88
+ const failedRequests = this.requests.filter((req) => req.hasError());
89
+ if (failedRequests.length === 0) {
90
+ break; // No failed requests to retry
91
+ }
92
+ console.log(`Retrying ${failedRequests.length} failed requests. Attempts left: ${retriesLeft}`);
93
+ await Promise.all(failedRequests.map((req) => req.send(this.abortController?.signal).then(() => {
132
94
  if (!req.hasError()) {
95
+ // Success after retry
133
96
  this.emit(BulkRequestEventEnum.REQUEST_SUCCESSFUL, req);
134
97
  }
98
+ })));
99
+ retriesLeft--;
100
+ }
101
+ // Emit failed events for any requests that still have errors after all retries
102
+ this.requests
103
+ .filter((req) => req.hasError())
104
+ .forEach((req) => {
105
+ this.emit(BulkRequestEventEnum.REQUEST_FAILED, req);
106
+ });
107
+ }
108
+ async sendSequential() {
109
+ // First attempt for all requests
110
+ for (const req of this.requests) {
111
+ await req.send(this.abortController?.signal);
112
+ if (!req.hasError()) {
113
+ this.emit(BulkRequestEventEnum.REQUEST_SUCCESSFUL, req);
135
114
  }
136
- // Retry logic for failed requests
137
- let retriesLeft = this.retryCount;
138
- while (retriesLeft > 0) {
139
- const failedRequests = this.requests.filter((req) => req.hasError());
140
- if (failedRequests.length === 0) {
141
- break; // No failed requests to retry
142
- }
143
- console.log(`Retrying ${failedRequests.length} failed requests sequentially. Attempts left: ${retriesLeft}`);
144
- for (const req of failedRequests) {
145
- yield req.send((_b = this.abortController) === null || _b === void 0 ? void 0 : _b.signal);
146
- if (!req.hasError()) {
147
- // Success after retry
148
- this.emit(BulkRequestEventEnum.REQUEST_SUCCESSFUL, req);
149
- }
115
+ }
116
+ // Retry logic for failed requests
117
+ let retriesLeft = this.retryCount;
118
+ while (retriesLeft > 0) {
119
+ const failedRequests = this.requests.filter((req) => req.hasError());
120
+ if (failedRequests.length === 0) {
121
+ break; // No failed requests to retry
122
+ }
123
+ console.log(`Retrying ${failedRequests.length} failed requests sequentially. Attempts left: ${retriesLeft}`);
124
+ for (const req of failedRequests) {
125
+ await req.send(this.abortController?.signal);
126
+ if (!req.hasError()) {
127
+ // Success after retry
128
+ this.emit(BulkRequestEventEnum.REQUEST_SUCCESSFUL, req);
150
129
  }
151
- retriesLeft--;
152
130
  }
153
- // Emit failed events for any requests that still have errors after all retries
154
- this.requests
155
- .filter((req) => req.hasError())
156
- .forEach((req) => {
157
- this.emit(BulkRequestEventEnum.REQUEST_FAILED, req);
158
- });
131
+ retriesLeft--;
132
+ }
133
+ // Emit failed events for any requests that still have errors after all retries
134
+ this.requests
135
+ .filter((req) => req.hasError())
136
+ .forEach((req) => {
137
+ this.emit(BulkRequestEventEnum.REQUEST_FAILED, req);
159
138
  });
160
139
  }
161
140
  }
@@ -1,33 +1,23 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class BulkRequestWrapper {
2
+ request;
3
+ response = null;
4
+ error = null;
5
+ sent = false;
11
6
  constructor(request) {
12
7
  this.request = request;
13
- this.response = null;
14
- this.error = null;
15
- this.sent = false;
16
- }
17
- send(signal) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- try {
20
- if (signal !== undefined) {
21
- this.request.setAbortSignal(signal);
22
- }
23
- this.response = yield this.request.send();
24
- }
25
- catch (err) {
26
- console.error(err);
27
- this.error = err;
8
+ }
9
+ async send(signal) {
10
+ try {
11
+ if (signal !== undefined) {
12
+ this.request.setAbortSignal(signal);
28
13
  }
29
- this.sent = true;
30
- });
14
+ this.response = await this.request.send();
15
+ }
16
+ catch (err) {
17
+ console.error(err);
18
+ this.error = err;
19
+ }
20
+ this.sent = true;
31
21
  }
32
22
  isLoading() {
33
23
  return this.request.isLoading();
@@ -1,5 +1,6 @@
1
1
  import { PaginationDataDto } from '../../../pagination/dtos/PaginationDataDto';
2
2
  export class RequestDriver {
3
+ request;
3
4
  constructor(request) {
4
5
  this.request = request;
5
6
  }
@@ -1,8 +1,9 @@
1
1
  import { PaginationDataDto } from './dtos/PaginationDataDto';
2
2
  export class BasePaginator {
3
+ dataDriver;
4
+ initialized = false;
3
5
  constructor(dataDriver) {
4
6
  this.dataDriver = dataDriver;
5
- this.initialized = false;
6
7
  }
7
8
  isInitialized() {
8
9
  return this.initialized;
@@ -36,13 +37,12 @@ export class BasePaginator {
36
37
  return updated;
37
38
  }
38
39
  removeRows(predicate, options) {
39
- var _a;
40
40
  const data = this.viewDriver.getData();
41
41
  const next = data.filter((row, index) => !predicate(row, index, data));
42
42
  const removed = data.length - next.length;
43
43
  if (removed > 0) {
44
44
  this.viewDriver.setData(next);
45
- if ((_a = options === null || options === void 0 ? void 0 : options.adjustTotal) !== null && _a !== void 0 ? _a : true) {
45
+ if (options?.adjustTotal ?? true) {
46
46
  this.viewDriver.setTotal(Math.max(0, this.viewDriver.getTotal() - removed));
47
47
  }
48
48
  }
@@ -52,7 +52,7 @@ export class BasePaginator {
52
52
  return this.viewDriver.getTotal();
53
53
  }
54
54
  passDataToViewDriver(dto, options) {
55
- if (options === null || options === void 0 ? void 0 : options.flush) {
55
+ if (options?.flush) {
56
56
  this.flush();
57
57
  }
58
58
  this.viewDriver.setData(dto.getData());
@@ -1,13 +1,16 @@
1
1
  import { BasePaginator } from './BasePaginator';
2
2
  import { StaleResponseException } from '../requests/exceptions/StaleResponseException';
3
3
  export class PageAwarePaginator extends BasePaginator {
4
+ dataDriver;
5
+ static viewDriverFactory;
6
+ viewDriver;
4
7
  static setViewDriverFactory(value) {
5
8
  PageAwarePaginator.viewDriverFactory = value;
6
9
  }
7
10
  constructor(dataDriver, pageNumber = 1, pageSize = 10, options) {
8
11
  super(dataDriver);
9
12
  this.dataDriver = dataDriver;
10
- this.viewDriver = (options === null || options === void 0 ? void 0 : options.viewDriverFactory)
13
+ this.viewDriver = options?.viewDriverFactory
11
14
  ? options.viewDriverFactory.make(pageNumber, pageSize)
12
15
  : PageAwarePaginator.viewDriverFactory.make(pageNumber, pageSize);
13
16
  }
@@ -1,13 +1,16 @@
1
1
  import { BasePaginator } from './BasePaginator';
2
2
  export class StatePaginator extends BasePaginator {
3
+ dataDriver;
4
+ static viewDriverFactory;
5
+ viewDriver;
6
+ currentState = null;
3
7
  static setViewDriverFactory(value) {
4
8
  StatePaginator.viewDriverFactory = value;
5
9
  }
6
10
  constructor(dataDriver, options) {
7
11
  super(dataDriver);
8
12
  this.dataDriver = dataDriver;
9
- this.currentState = null;
10
- this.viewDriver = (options === null || options === void 0 ? void 0 : options.viewDriverFactory)
13
+ this.viewDriver = options?.viewDriverFactory
11
14
  ? options.viewDriverFactory.make()
12
15
  : StatePaginator.viewDriverFactory.make();
13
16
  }
@@ -20,7 +23,7 @@ export class StatePaginator extends BasePaginator {
20
23
  }
21
24
  load(options) {
22
25
  this.currentState = null;
23
- return this.loadData(Object.assign(Object.assign({}, options), { flush: true }));
26
+ return this.loadData({ ...options, flush: true });
24
27
  }
25
28
  loadNext() {
26
29
  return this.loadData();
@@ -1,5 +1,6 @@
1
1
  import { PaginationDataDto } from '../index';
2
2
  export class ArrayDriver {
3
+ data;
3
4
  constructor(data) {
4
5
  this.data = data;
5
6
  }
@@ -1,4 +1,6 @@
1
1
  export class PaginationDataDto {
2
+ data;
3
+ total;
2
4
  constructor(data, total) {
3
5
  this.data = data;
4
6
  this.total = total;
@@ -1,5 +1,6 @@
1
1
  import { PaginationDataDto } from './PaginationDataDto';
2
2
  export class StatePaginationDataDto extends PaginationDataDto {
3
+ state;
3
4
  constructor(data, total, state = null) {
4
5
  super(data, total);
5
6
  this.state = state;
@@ -1,5 +1,7 @@
1
1
  import { ref } from 'vue';
2
2
  export class VueBaseViewDriver {
3
+ dataRef;
4
+ totalRef;
3
5
  constructor() {
4
6
  this.dataRef = ref([]);
5
7
  this.totalRef = ref(0);
@@ -1,5 +1,11 @@
1
1
  import { computed, ref } from 'vue';
2
2
  export class VuePaginationDriver {
3
+ dataRef;
4
+ currentPageRef;
5
+ pageSizeRef;
6
+ totalRef;
7
+ totalPagesComputed;
8
+ pagesComputed;
3
9
  constructor(pageNumber, pageSize) {
4
10
  this.dataRef = ref([]);
5
11
  this.currentPageRef = ref(pageNumber);
@@ -1,4 +1,5 @@
1
1
  export class LocalStorageDriver {
2
+ suffix;
2
3
  constructor(suffix) {
3
4
  this.suffix = suffix;
4
5
  }
@@ -1,4 +1,6 @@
1
1
  export class MemoryPersistenceDriver {
2
+ suffix;
3
+ static store = new Map();
2
4
  constructor(suffix) {
3
5
  this.suffix = suffix;
4
6
  }
@@ -19,4 +21,3 @@ export class MemoryPersistenceDriver {
19
21
  MemoryPersistenceDriver.store.delete(this.storageKey(key));
20
22
  }
21
23
  }
22
- MemoryPersistenceDriver.store = new Map();
@@ -1,4 +1,5 @@
1
1
  export class SessionStorageDriver {
2
+ suffix;
2
3
  constructor(suffix) {
3
4
  this.suffix = suffix;
4
5
  }