@serialized/serialized-client
Advanced tools
Comparing version 7.1.0 to 7.2.0
@@ -17,2 +17,5 @@ import { BaseClient, DomainEvent } from './'; | ||
} | ||
export interface SaveBulkPayload { | ||
batches: EventBatch[]; | ||
} | ||
export interface BulkSaveRequest { | ||
@@ -77,5 +80,4 @@ tenantId?: string; | ||
update(request: UpdateAggregateRequest, commandHandler: (s: any) => DomainEvent<any>[]): Promise<number>; | ||
saveBulk(request: BulkSaveRequest): Promise<number>; | ||
bulkSave(request: BulkSaveRequest): Promise<number>; | ||
bulkUpdate(request: BulkUpdateRequest, commandHandler: (s: any) => DomainEvent<any>[]): Promise<number>; | ||
bulkSave(batches: EventBatch[], tenantId?: string): Promise<number>; | ||
create(request: CreateAggregateRequest, commandHandler: (s: any) => DomainEvent<any>[]): Promise<number>; | ||
@@ -82,0 +84,0 @@ exists(request: CheckAggregateExistsRequest): Promise<boolean>; |
@@ -129,11 +129,21 @@ "use strict"; | ||
}; | ||
AggregatesClient.prototype.saveBulk = function (request) { | ||
AggregatesClient.prototype.bulkSave = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var batches, tenantId; | ||
var error_3; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
batches = request.batches, tenantId = request.tenantId; | ||
return [4 /*yield*/, this.saveBulkInternal(batches, tenantId)]; | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.aggregateClientConfig.retryStrategy.executeWithRetries(function () { return _this.saveBulkInternal(request.batches, request.tenantId); })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_3 = _a.sent(); | ||
if ((0, error_1.isSerializedApiError)(error_3)) { | ||
if (error_3.statusCode === 409) { | ||
throw new error_1.Conflict(this.aggregateType); | ||
} | ||
} | ||
throw error_3; | ||
case 3: return [2 /*return*/]; | ||
} | ||
@@ -145,3 +155,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var error_3; | ||
var error_4; | ||
var _this = this; | ||
@@ -168,3 +178,3 @@ return __generator(this, function (_a) { | ||
eventsToSave = commandHandler(response.aggregate); | ||
batches.push({ events: eventsToSave, expectedVersion: currentVersion }); | ||
batches.push({ aggregateId: aggregateId, events: eventsToSave, expectedVersion: currentVersion }); | ||
_b.label = 3; | ||
@@ -181,25 +191,2 @@ case 3: | ||
case 2: | ||
error_3 = _a.sent(); | ||
if ((0, error_1.isSerializedApiError)(error_3)) { | ||
if (error_3.statusCode === 409) { | ||
throw new error_1.Conflict(this.aggregateType); | ||
} | ||
} | ||
throw error_3; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
AggregatesClient.prototype.bulkSave = function (batches, tenantId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var error_4; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.aggregateClientConfig.retryStrategy.executeWithRetries(function () { return _this.saveBulkInternal(batches, tenantId); })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_4 = _a.sent(); | ||
@@ -354,3 +341,3 @@ if ((0, error_1.isSerializedApiError)(error_4)) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config, url, eventCounts; | ||
var config, url, data, eventCounts; | ||
return __generator(this, function (_a) { | ||
@@ -364,3 +351,4 @@ switch (_a.label) { | ||
url = "".concat(AggregatesClient.aggregateTypeBulkEventsUrlPath(this.aggregateType)); | ||
return [4 /*yield*/, this.axiosClient.post(url, { batches: batches }, config)]; | ||
data = { batches: batches }; | ||
return [4 /*yield*/, this.axiosClient.post(url, data, config)]; | ||
case 1: | ||
@@ -367,0 +355,0 @@ _a.sent(); |
@@ -49,2 +49,5 @@ "use strict"; | ||
} | ||
else if (error.response.status === 422) { | ||
return Promise.reject(new error_1.InvalidPayloadError(error)); | ||
} | ||
else if (error.response.status === 429) { | ||
@@ -57,3 +60,3 @@ return Promise.reject(new error_1.RateLimitExceeded()); | ||
else { | ||
return Promise.reject(new error_1.SerializedApiError(error.response.status)); | ||
return Promise.reject(new error_1.SerializedApiError(error.response.status, error.response.data)); | ||
} | ||
@@ -60,0 +63,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { AxiosError } from "axios"; | ||
/** | ||
@@ -37,2 +38,14 @@ * Type guard to check if the thrown error is a SerializedError | ||
/** | ||
* Thrown if the client sent a request with an invalid payload. | ||
*/ | ||
export declare class InvalidPayloadError extends SerializedApiError { | ||
cause: AxiosError; | ||
readonly errors: string[]; | ||
constructor(cause: AxiosError); | ||
} | ||
/** | ||
* Type guard to check if the thrown error is an InvalidPayloadError | ||
*/ | ||
export declare const isInvalidPayload: (error: any) => error is InvalidPayloadError; | ||
/** | ||
* Type guard to check if the thrown error is a ProjectionNotFound | ||
@@ -39,0 +52,0 @@ */ |
@@ -18,3 +18,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ServiceUnavailable = exports.isServiceUnavailable = exports.RateLimitExceeded = exports.isRateLimitExceeded = exports.UnauthorizedError = exports.isUnauthorizedError = exports.Conflict = exports.isConflict = exports.ConfigurationError = exports.isConfigurationError = exports.StateLoadingError = exports.isStateLoadingError = exports.AggregateNotFound = exports.isAggregateNotFound = exports.ProjectionNotFound = exports.isProjectionNotFound = exports.ProjectionDefinitionNotFound = exports.isProjectionDefinitionNotFound = exports.UnexpectedClientError = exports.isUnexpectedClientError = exports.SerializedApiError = exports.isSerializedApiError = exports.SerializedError = exports.isSerializedError = void 0; | ||
exports.ServiceUnavailable = exports.isServiceUnavailable = exports.RateLimitExceeded = exports.isRateLimitExceeded = exports.UnauthorizedError = exports.isUnauthorizedError = exports.Conflict = exports.isConflict = exports.ConfigurationError = exports.isConfigurationError = exports.StateLoadingError = exports.isStateLoadingError = exports.AggregateNotFound = exports.isAggregateNotFound = exports.ProjectionNotFound = exports.isProjectionNotFound = exports.ProjectionDefinitionNotFound = exports.isProjectionDefinitionNotFound = exports.isInvalidPayload = exports.InvalidPayloadError = exports.UnexpectedClientError = exports.isUnexpectedClientError = exports.SerializedApiError = exports.isSerializedApiError = exports.SerializedError = exports.isSerializedError = void 0; | ||
/** | ||
@@ -84,2 +84,24 @@ * Type guard to check if the thrown error is a SerializedError | ||
/** | ||
* Thrown if the client sent a request with an invalid payload. | ||
*/ | ||
var InvalidPayloadError = /** @class */ (function (_super) { | ||
__extends(InvalidPayloadError, _super); | ||
function InvalidPayloadError(cause) { | ||
var _this = _super.call(this, 422, cause.response.data) || this; | ||
_this.cause = cause; | ||
_this.errors = cause.response.data.errors; | ||
_this.name = 'InvalidPayloadError'; | ||
return _this; | ||
} | ||
return InvalidPayloadError; | ||
}(SerializedApiError)); | ||
exports.InvalidPayloadError = InvalidPayloadError; | ||
/** | ||
* Type guard to check if the thrown error is an InvalidPayloadError | ||
*/ | ||
var isInvalidPayload = function (error) { | ||
return error.name === 'InvalidPayloadError'; | ||
}; | ||
exports.isInvalidPayload = isInvalidPayload; | ||
/** | ||
* Type guard to check if the thrown error is a ProjectionNotFound | ||
@@ -86,0 +108,0 @@ */ |
@@ -6,3 +6,3 @@ { | ||
"author": "Serialized", | ||
"version": "7.1.0", | ||
"version": "7.2.0", | ||
"main": "dist/index.js", | ||
@@ -9,0 +9,0 @@ "types": "dist/index.d.ts", |
120630
2576