@serialized/serialized-client
Advanced tools
Comparing version 7.4.0 to 8.1.0
@@ -1,82 +0,94 @@ | ||
import { BaseClient, DomainEvent } from './'; | ||
import { BaseClient, StateBuilder } from './'; | ||
import { RetryStrategy } from "./RetryStrategy"; | ||
declare type AggregateId = string; | ||
export interface DeleteToken { | ||
token: string; | ||
consumed: boolean; | ||
} | ||
export interface AggregatesClientConfig { | ||
retryStrategy: RetryStrategy; | ||
} | ||
export interface AggregateRequest { | ||
tenantId?: string; | ||
type AggregateType = string; | ||
type AggregateData = object; | ||
type AggregateId = string; | ||
type TenantId = string; | ||
export type DomainEvent<T extends AggregateType, D extends AggregateData> = { | ||
readonly eventType: T; | ||
readonly data?: D; | ||
readonly eventId?: string; | ||
readonly encryptedData?: string; | ||
}; | ||
export type AggregatesClientConfig<T extends AggregateType> = { | ||
readonly aggregateType: T; | ||
readonly retryStrategy?: RetryStrategy; | ||
}; | ||
export type DeleteToken = { | ||
readonly token: string; | ||
readonly consumed: boolean; | ||
}; | ||
export type AggregateRequest<E> = { | ||
tenantId?: TenantId; | ||
aggregateId: AggregateId; | ||
expectedVersion: number; | ||
events: DomainEvent<any>[]; | ||
} | ||
export interface SaveBulkPayload { | ||
batches: EventBatch[]; | ||
} | ||
export interface BulkSaveRequest { | ||
tenantId?: string; | ||
batches: EventBatch[]; | ||
} | ||
export interface BulkUpdateRequest { | ||
tenantId?: string; | ||
events: E[]; | ||
}; | ||
export type SaveBulkPayload<E> = { | ||
batches: EventBatch<E>[]; | ||
}; | ||
export type BulkSaveRequest<E> = { | ||
tenantId?: TenantId; | ||
batches: EventBatch<E>[]; | ||
}; | ||
export type BulkUpdateRequest = { | ||
tenantId?: TenantId; | ||
aggregateIds: string[]; | ||
} | ||
export interface UpdateAggregateRequest { | ||
}; | ||
export type UpdateAggregateRequest = { | ||
aggregateId: AggregateId; | ||
tenantId?: string; | ||
tenantId?: TenantId; | ||
useOptimisticConcurrency?: boolean; | ||
} | ||
export interface CreateAggregateRequest { | ||
}; | ||
export type CreateAggregateRequest = { | ||
aggregateId: AggregateId; | ||
tenantId?: string; | ||
} | ||
export interface LoadAggregateRequest { | ||
tenantId?: TenantId; | ||
}; | ||
export type LoadAggregateRequest = { | ||
aggregateId: AggregateId; | ||
tenantId?: string; | ||
tenantId?: TenantId; | ||
since?: number; | ||
limit?: number; | ||
} | ||
export interface LoadAggregateResponse { | ||
}; | ||
export type LoadAggregateResponse<E> = { | ||
aggregateId: AggregateId; | ||
aggregateVersion: number; | ||
events: DomainEvent<any>[]; | ||
events: E[]; | ||
hasMore: boolean; | ||
} | ||
export interface CheckAggregateExistsRequest { | ||
}; | ||
export type CheckAggregateExistsRequest = { | ||
aggregateId: AggregateId; | ||
tenantId?: string; | ||
} | ||
export interface DeleteAggregateOptions { | ||
}; | ||
export type DeleteAggregateOptions = { | ||
aggregateId?: AggregateId; | ||
tenantId?: string; | ||
} | ||
export interface ConfirmDeleteAggregateOptions { | ||
}; | ||
export type ConfirmDeleteAggregateOptions = { | ||
token: string; | ||
aggregateId?: AggregateId; | ||
tenantId?: string; | ||
} | ||
export interface AggregateMetadata { | ||
}; | ||
export type AggregateMetadata = { | ||
version: number; | ||
} | ||
export interface EventBatch { | ||
}; | ||
export type EventBatch<E> = { | ||
aggregateId: string; | ||
events: DomainEvent<any>[]; | ||
events: E[]; | ||
expectedVersion?: number; | ||
} | ||
declare class AggregatesClient extends BaseClient { | ||
private aggregateTypeConstructor; | ||
private readonly aggregateType; | ||
private readonly stateLoader; | ||
private readonly aggregateClientConfig; | ||
private static DEFAULT_CONFIG; | ||
constructor(aggregateTypeConstructor: any, serializedConfig: any, aggregateClientConfig?: AggregatesClientConfig); | ||
save(request: AggregateRequest): Promise<number>; | ||
update(request: UpdateAggregateRequest, commandHandler: (s: any) => DomainEvent<any>[]): Promise<number>; | ||
bulkSave(request: BulkSaveRequest): Promise<number>; | ||
bulkUpdate(request: BulkUpdateRequest, commandHandler: (s: any) => DomainEvent<any>[]): Promise<number>; | ||
create(request: CreateAggregateRequest, commandHandler: (s: any) => DomainEvent<any>[]): Promise<number>; | ||
}; | ||
declare class AggregatesClient<A, S, T extends string, E extends { | ||
eventType: string; | ||
}> extends BaseClient { | ||
private aggregateClientConfig; | ||
private stateBuilder; | ||
private aggregateFactory; | ||
private stateLoader; | ||
constructor(serializedConfig: any, aggregateClientConfig: AggregatesClientConfig<T>, stateBuilder: StateBuilder<S, E>, aggregateFactory: (state: S) => A); | ||
get aggregateType(): T; | ||
save(request: AggregateRequest<E>): Promise<number>; | ||
update(request: UpdateAggregateRequest, commandHandler: (aggregate: A) => E[]): Promise<number>; | ||
bulkSave(request: BulkSaveRequest<E>): Promise<number>; | ||
bulkUpdate(request: BulkUpdateRequest, commandHandler: (s: any) => E[]): Promise<number>; | ||
create(request: CreateAggregateRequest, commandHandler: (a: A) => E[]): Promise<number>; | ||
exists(request: CheckAggregateExistsRequest): Promise<boolean>; | ||
@@ -88,8 +100,8 @@ delete(options?: DeleteAggregateOptions): Promise<DeleteToken>; | ||
private saveInternal; | ||
static aggregateEventsUrlPath(aggregateType: string, aggregateId: string): string; | ||
static aggregateUrlPath(aggregateType: string, aggregateId: string): string; | ||
static aggregateTypeUrlPath(aggregateType: string): string; | ||
static aggregateTypeBulkEventsUrlPath(aggregateType: string): string; | ||
get initialState(): any; | ||
get retryStrategy(): RetryStrategy; | ||
get aggregateEventsUrlPath(): (aggregateId: string) => string; | ||
get aggregateUrlPath(): (aggregateId: string) => string; | ||
get aggregateTypeBulkEventsUrlPath(): string; | ||
get aggregateTypeUrlPath(): string; | ||
} | ||
export { AggregatesClient }; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -26,379 +11,222 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AggregatesClient = void 0; | ||
var _1 = require("./"); | ||
var StateLoader_1 = require("./StateLoader"); | ||
var error_1 = require("./error"); | ||
var RetryStrategy_1 = require("./RetryStrategy"); | ||
var AggregatesClient = /** @class */ (function (_super) { | ||
__extends(AggregatesClient, _super); | ||
function AggregatesClient(aggregateTypeConstructor, serializedConfig, aggregateClientConfig) { | ||
var _this = _super.call(this, serializedConfig) || this; | ||
_this.aggregateTypeConstructor = aggregateTypeConstructor; | ||
_this.aggregateClientConfig = aggregateClientConfig !== null && aggregateClientConfig !== void 0 ? aggregateClientConfig : AggregatesClient.DEFAULT_CONFIG; | ||
var aggregateTypeInstance = new aggregateTypeConstructor.prototype.constructor({}); | ||
if (!aggregateTypeInstance.aggregateType) { | ||
throw new Error("No aggregateType configured for ".concat(aggregateTypeConstructor.prototype.constructor.name)); | ||
} | ||
_this.stateLoader = new StateLoader_1.StateLoader(aggregateTypeConstructor); | ||
_this.aggregateType = aggregateTypeInstance.aggregateType; | ||
return _this; | ||
const _1 = require("./"); | ||
const error_1 = require("./error"); | ||
const RetryStrategy_1 = require("./RetryStrategy"); | ||
const StateLoader_1 = require("./StateLoader"); | ||
class AggregatesClient extends _1.BaseClient { | ||
constructor(serializedConfig, aggregateClientConfig, stateBuilder, aggregateFactory) { | ||
super(serializedConfig); | ||
this.aggregateClientConfig = aggregateClientConfig; | ||
this.stateBuilder = stateBuilder; | ||
this.aggregateFactory = aggregateFactory; | ||
this.stateLoader = new StateLoader_1.StateLoader(); | ||
} | ||
AggregatesClient.prototype.save = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var events, aggregateId, expectedVersion, tenantId; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
events = request.events, aggregateId = request.aggregateId, expectedVersion = request.expectedVersion, tenantId = request.tenantId; | ||
return [4 /*yield*/, this.saveInternal({ aggregateId: aggregateId, events: events, expectedVersion: expectedVersion }, tenantId)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
get aggregateType() { | ||
return this.aggregateClientConfig.aggregateType; | ||
} | ||
save(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { events, aggregateId, expectedVersion, tenantId } = request; | ||
return yield this.saveInternal({ aggregateId, events, expectedVersion }, tenantId); | ||
}); | ||
}; | ||
AggregatesClient.prototype.update = function (request, commandHandler) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var tenantId, error_2; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
tenantId = request === null || request === void 0 ? void 0 : request.tenantId; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.aggregateClientConfig.retryStrategy.executeWithRetries(function () { return __awaiter(_this, void 0, void 0, function () { | ||
var response, currentVersion, eventsToSave; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.loadInternal(request)]; | ||
case 1: | ||
response = _a.sent(); | ||
currentVersion = response.metadata.version; | ||
eventsToSave = commandHandler(response.aggregate); | ||
return [4 /*yield*/, this.saveInternal({ | ||
aggregateId: request.aggregateId, | ||
events: eventsToSave, | ||
expectedVersion: (request === null || request === void 0 ? void 0 : request.useOptimisticConcurrency) === false ? undefined : currentVersion | ||
}, tenantId)]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); })]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
case 3: | ||
error_2 = _a.sent(); | ||
if ((0, error_1.isSerializedApiError)(error_2)) { | ||
if (error_2.statusCode === 409) { | ||
throw new error_1.Conflict(this.aggregateType, request.aggregateId); | ||
} | ||
} | ||
throw error_2; | ||
case 4: return [2 /*return*/]; | ||
} | ||
update(request, commandHandler) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const tenantId = request === null || request === void 0 ? void 0 : request.tenantId; | ||
try { | ||
return yield this.retryStrategy.executeWithRetries(() => __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this.loadInternal(request); | ||
const currentVersion = response.metadata.version; | ||
const eventsToSave = commandHandler(response.aggregate); | ||
return yield this.saveInternal({ | ||
aggregateId: request.aggregateId, | ||
events: eventsToSave, | ||
expectedVersion: (request === null || request === void 0 ? void 0 : request.useOptimisticConcurrency) === false ? undefined : currentVersion | ||
}, tenantId); | ||
})); | ||
} | ||
catch (error) { | ||
if ((0, error_1.isSerializedApiError)(error)) { | ||
if (error.statusCode === 409) { | ||
throw new error_1.Conflict(this.aggregateType, request.aggregateId); | ||
} | ||
} | ||
}); | ||
throw error; | ||
} | ||
}); | ||
}; | ||
AggregatesClient.prototype.bulkSave = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var error_3; | ||
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(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*/]; | ||
} | ||
bulkSave(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield this.retryStrategy.executeWithRetries(() => this.saveBulkInternal(request.batches, request.tenantId)); | ||
} | ||
catch (error) { | ||
if ((0, error_1.isSerializedApiError)(error)) { | ||
if (error.statusCode === 409) { | ||
throw new error_1.Conflict(this.aggregateType); | ||
} | ||
} | ||
}); | ||
throw error; | ||
} | ||
}); | ||
}; | ||
AggregatesClient.prototype.bulkUpdate = function (request, commandHandler) { | ||
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 __awaiter(_this, void 0, void 0, function () { | ||
var batches, _i, _a, aggregateId, response, currentVersion, eventsToSave; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
batches = []; | ||
_i = 0, _a = request.aggregateIds; | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 4]; | ||
aggregateId = _a[_i]; | ||
return [4 /*yield*/, this.loadInternal({ aggregateId: aggregateId })]; | ||
case 2: | ||
response = _b.sent(); | ||
currentVersion = response.metadata.version; | ||
eventsToSave = commandHandler(response.aggregate); | ||
batches.push({ aggregateId: aggregateId, events: eventsToSave, expectedVersion: currentVersion }); | ||
_b.label = 3; | ||
case 3: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 4: return [4 /*yield*/, this.saveBulkInternal(batches, request.tenantId)]; | ||
case 5: return [2 /*return*/, _b.sent()]; | ||
} | ||
}); | ||
}); })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_4 = _a.sent(); | ||
if ((0, error_1.isSerializedApiError)(error_4)) { | ||
if (error_4.statusCode === 409) { | ||
throw new error_1.Conflict(this.aggregateType); | ||
} | ||
} | ||
throw error_4; | ||
case 3: return [2 /*return*/]; | ||
} | ||
bulkUpdate(request, commandHandler) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield this.retryStrategy.executeWithRetries(() => __awaiter(this, void 0, void 0, function* () { | ||
let batches = []; | ||
for (const aggregateId of request.aggregateIds) { | ||
const response = yield this.loadInternal({ aggregateId }); | ||
const currentVersion = response.metadata.version; | ||
const eventsToSave = commandHandler(response.aggregate); | ||
batches.push({ aggregateId, events: eventsToSave, expectedVersion: currentVersion }); | ||
} | ||
return yield this.saveBulkInternal(batches, request.tenantId); | ||
})); | ||
} | ||
catch (error) { | ||
if ((0, error_1.isSerializedApiError)(error)) { | ||
if (error.statusCode === 409) { | ||
throw new error_1.Conflict(this.aggregateType); | ||
} | ||
} | ||
}); | ||
throw error; | ||
} | ||
}); | ||
}; | ||
AggregatesClient.prototype.create = function (request, commandHandler) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var aggregate, eventsToSave, tenantId, aggregateId, error_5; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
aggregate = new this.aggregateTypeConstructor.prototype.constructor(this.initialState()); | ||
eventsToSave = commandHandler(aggregate); | ||
tenantId = request === null || request === void 0 ? void 0 : request.tenantId; | ||
aggregateId = request.aggregateId; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.aggregateClientConfig.retryStrategy.executeWithRetries(function () { return _this.saveInternal({ aggregateId: aggregateId, events: eventsToSave, expectedVersion: 0 }, tenantId); })]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
case 3: | ||
error_5 = _a.sent(); | ||
if ((0, error_1.isSerializedApiError)(error_5)) { | ||
if (error_5.statusCode === 409) { | ||
throw new error_1.Conflict(this.aggregateType, aggregateId); | ||
} | ||
} | ||
throw error_5; | ||
case 4: return [2 /*return*/]; | ||
} | ||
create(request, commandHandler) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const state = this.stateBuilder.initialState(); | ||
const aggregate = this.aggregateFactory(state); | ||
const eventsToSave = commandHandler(aggregate); | ||
const tenantId = request === null || request === void 0 ? void 0 : request.tenantId; | ||
const aggregateId = request.aggregateId; | ||
try { | ||
return yield this.retryStrategy.executeWithRetries(() => this.saveInternal({ aggregateId, events: eventsToSave, expectedVersion: 0 }, tenantId)); | ||
} | ||
catch (error) { | ||
if ((0, error_1.isSerializedApiError)(error)) { | ||
if (error.statusCode === 409) { | ||
throw new error_1.Conflict(this.aggregateType, aggregateId); | ||
} | ||
} | ||
}); | ||
throw error; | ||
} | ||
}); | ||
}; | ||
AggregatesClient.prototype.exists = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, error_6; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = AggregatesClient.aggregateUrlPath(this.aggregateType, request.aggregateId); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.axiosClient.head(url, this.axiosConfig(request.tenantId))]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/, true]; | ||
case 3: | ||
error_6 = _a.sent(); | ||
if ((0, error_1.isSerializedApiError)(error_6) && error_6.statusCode === 404) { | ||
return [2 /*return*/, false]; | ||
} | ||
throw error_6; | ||
case 4: return [2 /*return*/]; | ||
} | ||
exists(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = this.aggregateUrlPath(request.aggregateId); | ||
try { | ||
yield this.axiosClient.head(url, this.axiosConfig(request.tenantId)); | ||
return true; | ||
} | ||
catch (error) { | ||
if ((0, error_1.isSerializedApiError)(error) && error.statusCode === 404) { | ||
return false; | ||
} | ||
}); | ||
throw error; | ||
} | ||
}); | ||
}; | ||
AggregatesClient.prototype.delete = function (options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config, url, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
config = options && options.tenantId ? this.axiosConfig(options.tenantId) : this.axiosConfig(); | ||
url = (options === null || options === void 0 ? void 0 : options.aggregateId) ? | ||
"".concat(AggregatesClient.aggregateUrlPath(this.aggregateType, options.aggregateId)) : | ||
"".concat(AggregatesClient.aggregateTypeUrlPath(this.aggregateType)); | ||
return [4 /*yield*/, this.axiosClient.delete(url, config)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, response.data]; | ||
} | ||
}); | ||
} | ||
delete(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = options && options.tenantId ? this.axiosConfig(options.tenantId) : this.axiosConfig(); | ||
const url = (options === null || options === void 0 ? void 0 : options.aggregateId) ? | ||
`${this.aggregateUrlPath(options.aggregateId)}` : | ||
`${this.aggregateTypeUrlPath}`; | ||
const response = yield this.axiosClient.delete(url, config); | ||
return response.data; | ||
}); | ||
}; | ||
AggregatesClient.prototype.loadInternal = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, config, limit, since, queryParams, events, response, axiosResponse, currentState, aggregate, metadata; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "".concat(AggregatesClient.aggregateUrlPath(this.aggregateType, request.aggregateId)); | ||
config = request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
limit = request.limit ? request.limit : 1000; | ||
since = request.since ? request.since : 0; | ||
queryParams = new URLSearchParams(); | ||
queryParams.set('since', String(since)); | ||
queryParams.set('limit', String(limit)); | ||
events = []; | ||
response = null; | ||
_a.label = 1; | ||
case 1: | ||
config.params = queryParams; | ||
return [4 /*yield*/, this.axiosClient.get(url, config)]; | ||
case 2: | ||
axiosResponse = _a.sent(); | ||
response = axiosResponse.data; | ||
response.events.forEach(function (e) { return events.push(e); }); | ||
since += limit; | ||
queryParams.set('since', String(since)); | ||
_a.label = 3; | ||
case 3: | ||
if (response.hasMore) return [3 /*break*/, 1]; | ||
_a.label = 4; | ||
case 4: | ||
currentState = this.stateLoader.loadState(events); | ||
aggregate = new this.aggregateTypeConstructor.prototype.constructor(currentState); | ||
metadata = { version: response.aggregateVersion }; | ||
aggregate._metadata = metadata; | ||
console.log("Loaded aggregate ".concat(this.aggregateType, "@").concat(request.aggregateId, ":").concat(metadata.version)); | ||
return [2 /*return*/, { aggregate: aggregate, metadata: metadata }]; | ||
} | ||
}); | ||
} | ||
loadInternal(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = `${this.aggregateUrlPath(request.aggregateId)}`; | ||
const config = request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
const limit = request.limit ? request.limit : 1000; | ||
let since = request.since ? request.since : 0; | ||
const queryParams = new URLSearchParams(); | ||
queryParams.set('since', String(since)); | ||
queryParams.set('limit', String(limit)); | ||
let response = null; | ||
let currentState = this.stateBuilder.initialState(); | ||
do { | ||
config.params = queryParams; | ||
const axiosResponse = yield this.axiosClient.get(url, config); | ||
response = axiosResponse.data; | ||
currentState = this.stateLoader.loadState(currentState, this.stateBuilder, response.events); | ||
since += limit; | ||
queryParams.set('since', String(since)); | ||
} while (response.hasMore); | ||
const metadata = { version: response.aggregateVersion }; | ||
const aggregate = this.aggregateFactory(currentState); | ||
console.log(`Loaded aggregate ${this.aggregateType}@${request.aggregateId}:${metadata.version}`); | ||
return { aggregate, metadata }; | ||
}); | ||
}; | ||
AggregatesClient.prototype.confirmDelete = function (options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config, url, queryParams; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
config = options && options.tenantId ? this.axiosConfig(options.tenantId) : this.axiosConfig(); | ||
url = options.aggregateId ? | ||
"".concat(AggregatesClient.aggregateUrlPath(this.aggregateType, options.aggregateId)) : | ||
"".concat(AggregatesClient.aggregateTypeUrlPath(this.aggregateType)); | ||
queryParams = new URLSearchParams(); | ||
if (options.token) { | ||
queryParams.set('deleteToken', options.token); | ||
} | ||
config.params = queryParams; | ||
return [4 /*yield*/, this.axiosClient.delete(url, config)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
} | ||
confirmDelete(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = options && options.tenantId ? this.axiosConfig(options.tenantId) : this.axiosConfig(); | ||
const url = options.aggregateId ? | ||
`${this.aggregateUrlPath(options.aggregateId)}` : | ||
`${this.aggregateTypeUrlPath}`; | ||
const queryParams = new URLSearchParams(); | ||
if (options.token) { | ||
queryParams.set('deleteToken', options.token); | ||
} | ||
config.params = queryParams; | ||
yield this.axiosClient.delete(url, config); | ||
}); | ||
}; | ||
AggregatesClient.prototype.saveBulkInternal = function (batches, tenantId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config, url, data, eventCounts; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
config = tenantId ? this.axiosConfig(tenantId) : this.axiosConfig(); | ||
if (batches.length === 0) { | ||
return [2 /*return*/, 0]; | ||
} | ||
url = "".concat(AggregatesClient.aggregateTypeBulkEventsUrlPath(this.aggregateType)); | ||
data = { batches: batches }; | ||
return [4 /*yield*/, this.axiosClient.post(url, data, config)]; | ||
case 1: | ||
_a.sent(); | ||
eventCounts = batches.map(function (b) { return b.events.length; }); | ||
return [2 /*return*/, eventCounts.reduce(function (sum, current) { return (sum + current); }, 0)]; | ||
} | ||
}); | ||
} | ||
saveBulkInternal(batches, tenantId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = tenantId ? this.axiosConfig(tenantId) : this.axiosConfig(); | ||
if (batches.length === 0) { | ||
return 0; | ||
} | ||
const url = `${this.aggregateTypeBulkEventsUrlPath}`; | ||
const data = { batches }; | ||
yield this.axiosClient.post(url, data, config); | ||
const eventCounts = batches.map(b => b.events.length); | ||
return eventCounts.reduce((sum, current) => (sum + current), 0); | ||
}); | ||
}; | ||
AggregatesClient.prototype.saveInternal = function (eventBatch, tenantId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config, events, aggregateId, expectedVersion; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
config = tenantId ? this.axiosConfig(tenantId) : this.axiosConfig(); | ||
events = eventBatch.events, aggregateId = eventBatch.aggregateId, expectedVersion = eventBatch.expectedVersion; | ||
if (events.length === 0) { | ||
return [2 /*return*/, 0]; | ||
} | ||
return [4 /*yield*/, this.axiosClient.post(AggregatesClient.aggregateEventsUrlPath(this.aggregateType, aggregateId), { | ||
events: events, | ||
expectedVersion: expectedVersion | ||
}, config)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, events.length]; | ||
} | ||
}); | ||
} | ||
saveInternal(eventBatch, tenantId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = tenantId ? this.axiosConfig(tenantId) : this.axiosConfig(); | ||
const { events, aggregateId, expectedVersion } = eventBatch; | ||
if (events.length === 0) { | ||
return 0; | ||
} | ||
let url = this.aggregateEventsUrlPath(aggregateId); | ||
yield this.axiosClient.post(url, { | ||
events, | ||
expectedVersion | ||
}, config); | ||
return events.length; | ||
}); | ||
}; | ||
AggregatesClient.aggregateEventsUrlPath = function (aggregateType, aggregateId) { | ||
return "/aggregates/".concat(aggregateType, "/").concat(aggregateId, "/events"); | ||
}; | ||
AggregatesClient.aggregateUrlPath = function (aggregateType, aggregateId) { | ||
return "/aggregates/".concat(aggregateType, "/").concat(aggregateId); | ||
}; | ||
AggregatesClient.aggregateTypeUrlPath = function (aggregateType) { | ||
return "/aggregates/".concat(aggregateType); | ||
}; | ||
AggregatesClient.aggregateTypeBulkEventsUrlPath = function (aggregateType) { | ||
return "/aggregates/".concat(aggregateType, "/events"); | ||
}; | ||
Object.defineProperty(AggregatesClient.prototype, "initialState", { | ||
get: function () { | ||
var aggregateTypeInstance = new this.aggregateTypeConstructor.prototype.constructor({}); | ||
return aggregateTypeInstance.initialState ? aggregateTypeInstance.initialState : {}; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
AggregatesClient.DEFAULT_CONFIG = { | ||
retryStrategy: new RetryStrategy_1.NoRetryStrategy() | ||
}; | ||
return AggregatesClient; | ||
}(_1.BaseClient)); | ||
} | ||
get retryStrategy() { | ||
var _a; | ||
return (_a = this.aggregateClientConfig.retryStrategy) !== null && _a !== void 0 ? _a : new RetryStrategy_1.NoRetryStrategy(); | ||
} | ||
get aggregateEventsUrlPath() { | ||
return (aggregateId) => { | ||
return `${this.aggregateUrlPath(aggregateId)}/events`; | ||
}; | ||
} | ||
get aggregateUrlPath() { | ||
return (aggregateId) => { | ||
return `${this.aggregateTypeUrlPath}/${aggregateId}`; | ||
}; | ||
} | ||
get aggregateTypeBulkEventsUrlPath() { | ||
return `${this.aggregateTypeUrlPath}/events`; | ||
} | ||
get aggregateTypeUrlPath() { | ||
return `/aggregates/${this.aggregateType}`; | ||
} | ||
} | ||
exports.AggregatesClient = AggregatesClient; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseClient = void 0; | ||
var axios_1 = __importDefault(require("axios")); | ||
var error_1 = require("./error"); | ||
var SERIALIZED_ACCESS_KEY_HEADER = 'Serialized-Access-Key'; | ||
var SERIALIZED_SECRET_ACCESS_KEY_HEADER = 'Serialized-Secret-Access-Key'; | ||
var BaseClient = /** @class */ (function () { | ||
function BaseClient(config) { | ||
var axiosClient = axios_1.default.create({ | ||
baseURL: "https://api.serialized.io", | ||
const axios_1 = require("axios"); | ||
const error_1 = require("./error"); | ||
const SERIALIZED_ACCESS_KEY_HEADER = 'Serialized-Access-Key'; | ||
const SERIALIZED_SECRET_ACCESS_KEY_HEADER = 'Serialized-Secret-Access-Key'; | ||
class BaseClient { | ||
constructor(config) { | ||
const axiosClient = axios_1.default.create({ | ||
baseURL: `https://api.serialized.io`, | ||
withCredentials: true, | ||
@@ -34,5 +20,5 @@ maxRedirects: 0, | ||
}); | ||
axiosClient.interceptors.response.use(function (response) { | ||
axiosClient.interceptors.response.use((response) => { | ||
return response; | ||
}, function (error) { | ||
}, error => { | ||
if (error.config && error.config.headers) { | ||
@@ -70,4 +56,4 @@ if (error.config.headers[SERIALIZED_ACCESS_KEY_HEADER]) { | ||
} | ||
BaseClient.prototype.axiosConfig = function (tenantId) { | ||
var additionalHeaders = {}; | ||
axiosConfig(tenantId) { | ||
let additionalHeaders = {}; | ||
if (tenantId) { | ||
@@ -77,7 +63,6 @@ additionalHeaders = { 'Serialized-Tenant-Id': tenantId }; | ||
return { | ||
headers: __assign({}, additionalHeaders) | ||
headers: Object.assign({}, additionalHeaders) | ||
}; | ||
}; | ||
return BaseClient; | ||
}()); | ||
} | ||
} | ||
exports.BaseClient = BaseClient; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -22,3 +7,3 @@ 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; | ||
*/ | ||
var isSerializedError = function (error) { | ||
const isSerializedError = (error) => { | ||
return error.isSerializedError === true; | ||
@@ -30,11 +15,8 @@ }; | ||
*/ | ||
var SerializedError = /** @class */ (function (_super) { | ||
__extends(SerializedError, _super); | ||
function SerializedError(message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.isSerializedError = true; | ||
return _this; | ||
class SerializedError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.isSerializedError = true; | ||
} | ||
return SerializedError; | ||
}(Error)); | ||
} | ||
exports.SerializedError = SerializedError; | ||
@@ -44,3 +26,3 @@ /** | ||
*/ | ||
var isSerializedApiError = function (error) { | ||
const isSerializedApiError = (error) => { | ||
return error.isSerializedApiError === true; | ||
@@ -52,13 +34,10 @@ }; | ||
*/ | ||
var SerializedApiError = /** @class */ (function (_super) { | ||
__extends(SerializedApiError, _super); | ||
function SerializedApiError(statusCode, data) { | ||
var _this = _super.call(this) || this; | ||
_this.statusCode = statusCode; | ||
_this.data = data; | ||
_this.isSerializedApiError = true; | ||
return _this; | ||
class SerializedApiError extends SerializedError { | ||
constructor(statusCode, data) { | ||
super(); | ||
this.statusCode = statusCode; | ||
this.data = data; | ||
this.isSerializedApiError = true; | ||
} | ||
return SerializedApiError; | ||
}(SerializedError)); | ||
} | ||
exports.SerializedApiError = SerializedApiError; | ||
@@ -68,3 +47,3 @@ /** | ||
*/ | ||
var isUnexpectedClientError = function (error) { | ||
const isUnexpectedClientError = (error) => { | ||
return error.name === UnexpectedClientError.name; | ||
@@ -76,12 +55,9 @@ }; | ||
*/ | ||
var UnexpectedClientError = /** @class */ (function (_super) { | ||
__extends(UnexpectedClientError, _super); | ||
function UnexpectedClientError(cause) { | ||
var _this = _super.call(this) || this; | ||
_this.cause = cause; | ||
_this.name = 'UnexpectedClientError'; | ||
return _this; | ||
class UnexpectedClientError extends SerializedError { | ||
constructor(cause) { | ||
super(); | ||
this.cause = cause; | ||
this.name = 'UnexpectedClientError'; | ||
} | ||
return UnexpectedClientError; | ||
}(SerializedError)); | ||
} | ||
exports.UnexpectedClientError = UnexpectedClientError; | ||
@@ -91,13 +67,10 @@ /** | ||
*/ | ||
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; | ||
class InvalidPayloadError extends SerializedApiError { | ||
constructor(cause) { | ||
super(422, cause.response.data); | ||
this.cause = cause; | ||
this.errors = cause.response.data.errors; | ||
this.name = 'InvalidPayloadError'; | ||
} | ||
return InvalidPayloadError; | ||
}(SerializedApiError)); | ||
} | ||
exports.InvalidPayloadError = InvalidPayloadError; | ||
@@ -107,3 +80,3 @@ /** | ||
*/ | ||
var isInvalidPayload = function (error) { | ||
const isInvalidPayload = (error) => { | ||
return error.name === 'InvalidPayloadError'; | ||
@@ -115,3 +88,3 @@ }; | ||
*/ | ||
var isProjectionDefinitionNotFound = function (error) { | ||
const isProjectionDefinitionNotFound = (error) => { | ||
return error.name === 'ProjectionDefinitionNotFound'; | ||
@@ -123,12 +96,9 @@ }; | ||
*/ | ||
var ProjectionDefinitionNotFound = /** @class */ (function (_super) { | ||
__extends(ProjectionDefinitionNotFound, _super); | ||
function ProjectionDefinitionNotFound(projectionName) { | ||
var _this = _super.call(this, 404) || this; | ||
_this.projectionName = projectionName; | ||
_this.name = 'ProjectionDefinitionNotFound'; | ||
return _this; | ||
class ProjectionDefinitionNotFound extends SerializedApiError { | ||
constructor(projectionName) { | ||
super(404); | ||
this.projectionName = projectionName; | ||
this.name = 'ProjectionDefinitionNotFound'; | ||
} | ||
return ProjectionDefinitionNotFound; | ||
}(SerializedApiError)); | ||
} | ||
exports.ProjectionDefinitionNotFound = ProjectionDefinitionNotFound; | ||
@@ -138,3 +108,3 @@ /** | ||
*/ | ||
var isProjectionNotFound = function (error) { | ||
const isProjectionNotFound = (error) => { | ||
return error.name === 'ProjectionNotFound'; | ||
@@ -146,13 +116,10 @@ }; | ||
*/ | ||
var ProjectionNotFound = /** @class */ (function (_super) { | ||
__extends(ProjectionNotFound, _super); | ||
function ProjectionNotFound(projectionName, projectionId) { | ||
var _this = _super.call(this, 404) || this; | ||
_this.projectionName = projectionName; | ||
_this.projectionId = projectionId; | ||
_this.name = 'ProjectionNotFound'; | ||
return _this; | ||
class ProjectionNotFound extends SerializedApiError { | ||
constructor(projectionName, projectionId) { | ||
super(404); | ||
this.projectionName = projectionName; | ||
this.projectionId = projectionId; | ||
this.name = 'ProjectionNotFound'; | ||
} | ||
return ProjectionNotFound; | ||
}(SerializedApiError)); | ||
} | ||
exports.ProjectionNotFound = ProjectionNotFound; | ||
@@ -162,3 +129,3 @@ /** | ||
*/ | ||
var isAggregateNotFound = function (error) { | ||
const isAggregateNotFound = (error) => { | ||
return error.name === AggregateNotFound.name; | ||
@@ -170,13 +137,10 @@ }; | ||
*/ | ||
var AggregateNotFound = /** @class */ (function (_super) { | ||
__extends(AggregateNotFound, _super); | ||
function AggregateNotFound(aggregateType, aggregateId) { | ||
var _this = _super.call(this, 404) || this; | ||
_this.aggregateType = aggregateType; | ||
_this.aggregateId = aggregateId; | ||
_this.name = AggregateNotFound.name; | ||
return _this; | ||
class AggregateNotFound extends SerializedApiError { | ||
constructor(aggregateType, aggregateId) { | ||
super(404); | ||
this.aggregateType = aggregateType; | ||
this.aggregateId = aggregateId; | ||
this.name = AggregateNotFound.name; | ||
} | ||
return AggregateNotFound; | ||
}(SerializedApiError)); | ||
} | ||
exports.AggregateNotFound = AggregateNotFound; | ||
@@ -186,3 +150,3 @@ /** | ||
*/ | ||
var isStateLoadingError = function (error) { | ||
const isStateLoadingError = (error) => { | ||
return error.name === 'StateLoadingError'; | ||
@@ -194,11 +158,8 @@ }; | ||
*/ | ||
var StateLoadingError = /** @class */ (function (_super) { | ||
__extends(StateLoadingError, _super); | ||
function StateLoadingError(message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.name = 'StateLoadingError'; | ||
return _this; | ||
class StateLoadingError extends SerializedError { | ||
constructor(message) { | ||
super(message); | ||
this.name = 'StateLoadingError'; | ||
} | ||
return StateLoadingError; | ||
}(SerializedError)); | ||
} | ||
exports.StateLoadingError = StateLoadingError; | ||
@@ -208,3 +169,3 @@ /** | ||
*/ | ||
var isConfigurationError = function (error) { | ||
const isConfigurationError = (error) => { | ||
return error.name === 'ConfigurationError'; | ||
@@ -216,11 +177,8 @@ }; | ||
*/ | ||
var ConfigurationError = /** @class */ (function (_super) { | ||
__extends(ConfigurationError, _super); | ||
function ConfigurationError(message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.name = 'ConfigurationError'; | ||
return _this; | ||
class ConfigurationError extends SerializedError { | ||
constructor(message) { | ||
super(message); | ||
this.name = 'ConfigurationError'; | ||
} | ||
return ConfigurationError; | ||
}(SerializedError)); | ||
} | ||
exports.ConfigurationError = ConfigurationError; | ||
@@ -230,3 +188,3 @@ /** | ||
*/ | ||
var isConflict = function (error) { | ||
const isConflict = (error) => { | ||
return error.name === 'Conflict'; | ||
@@ -238,13 +196,10 @@ }; | ||
*/ | ||
var Conflict = /** @class */ (function (_super) { | ||
__extends(Conflict, _super); | ||
function Conflict(aggregateType, aggregateId) { | ||
var _this = _super.call(this, 409) || this; | ||
_this.aggregateType = aggregateType; | ||
_this.aggregateId = aggregateId; | ||
_this.name = 'Conflict'; | ||
return _this; | ||
class Conflict extends SerializedApiError { | ||
constructor(aggregateType, aggregateId) { | ||
super(409); | ||
this.aggregateType = aggregateType; | ||
this.aggregateId = aggregateId; | ||
this.name = 'Conflict'; | ||
} | ||
return Conflict; | ||
}(SerializedApiError)); | ||
} | ||
exports.Conflict = Conflict; | ||
@@ -254,3 +209,3 @@ /** | ||
*/ | ||
var isUnauthorizedError = function (error) { | ||
const isUnauthorizedError = (error) => { | ||
return error.name === 'UnauthorizedError'; | ||
@@ -262,12 +217,9 @@ }; | ||
*/ | ||
var UnauthorizedError = /** @class */ (function (_super) { | ||
__extends(UnauthorizedError, _super); | ||
function UnauthorizedError(requestUrl) { | ||
var _this = _super.call(this, 401) || this; | ||
_this.requestUrl = requestUrl; | ||
_this.name = 'UnauthorizedError'; | ||
return _this; | ||
class UnauthorizedError extends SerializedApiError { | ||
constructor(requestUrl) { | ||
super(401); | ||
this.requestUrl = requestUrl; | ||
this.name = 'UnauthorizedError'; | ||
} | ||
return UnauthorizedError; | ||
}(SerializedApiError)); | ||
} | ||
exports.UnauthorizedError = UnauthorizedError; | ||
@@ -277,3 +229,3 @@ /** | ||
*/ | ||
var isRateLimitExceeded = function (error) { | ||
const isRateLimitExceeded = (error) => { | ||
return error.name === 'RateLimitExceeded'; | ||
@@ -285,11 +237,8 @@ }; | ||
*/ | ||
var RateLimitExceeded = /** @class */ (function (_super) { | ||
__extends(RateLimitExceeded, _super); | ||
function RateLimitExceeded() { | ||
var _this = _super.call(this, 429) || this; | ||
_this.name = 'RateLimitExceeded'; | ||
return _this; | ||
class RateLimitExceeded extends SerializedApiError { | ||
constructor() { | ||
super(429); | ||
this.name = 'RateLimitExceeded'; | ||
} | ||
return RateLimitExceeded; | ||
}(SerializedApiError)); | ||
} | ||
exports.RateLimitExceeded = RateLimitExceeded; | ||
@@ -299,3 +248,3 @@ /** | ||
*/ | ||
var isServiceUnavailable = function (error) { | ||
const isServiceUnavailable = (error) => { | ||
return error.name === 'ServiceUnavailable'; | ||
@@ -307,12 +256,9 @@ }; | ||
*/ | ||
var ServiceUnavailable = /** @class */ (function (_super) { | ||
__extends(ServiceUnavailable, _super); | ||
function ServiceUnavailable(requestUrl) { | ||
var _this = _super.call(this, 503) || this; | ||
_this.requestUrl = requestUrl; | ||
_this.name = 'ServiceUnavailable'; | ||
return _this; | ||
class ServiceUnavailable extends SerializedApiError { | ||
constructor(requestUrl) { | ||
super(503); | ||
this.requestUrl = requestUrl; | ||
this.name = 'ServiceUnavailable'; | ||
} | ||
return ServiceUnavailable; | ||
}(SerializedApiError)); | ||
} | ||
exports.ServiceUnavailable = ServiceUnavailable; |
import { BaseClient } from "./"; | ||
export interface FeedEvent { | ||
eventType: string; | ||
eventId: string; | ||
data?: any; | ||
encryptedData?: number; | ||
} | ||
export interface FeedEntry { | ||
sequenceNumber: number; | ||
aggregateId: string; | ||
timestamp: number; | ||
feedName: string; | ||
events: FeedEvent[]; | ||
} | ||
export interface FeedOverview { | ||
aggregateType: string; | ||
aggregateCount: number; | ||
batchCount: number; | ||
eventCount: number; | ||
} | ||
export interface LoadFeedResponse { | ||
entries: FeedEntry[]; | ||
hasMore: boolean; | ||
currentSequenceNumber: number; | ||
} | ||
export interface LoadFeedsOverviewResponse { | ||
feeds: FeedOverview[]; | ||
} | ||
export interface LoadFeedRequest { | ||
feedName: string; | ||
tenantId?: string; | ||
since?: number; | ||
limit?: number; | ||
from?: string; | ||
to?: string; | ||
waitTime?: number; | ||
types?: string[]; | ||
partitionNumber?: number; | ||
partitionCount?: number; | ||
} | ||
export interface LoadAllFeedRequest { | ||
tenantId?: string; | ||
since?: number; | ||
limit?: number; | ||
from?: string; | ||
to?: string; | ||
waitTime?: number; | ||
types?: string[]; | ||
partitionNumber?: number; | ||
partitionCount?: number; | ||
} | ||
export interface GetCurrentSequenceNumberRequest { | ||
feedName: string; | ||
tenantId?: string; | ||
} | ||
export interface GetGlobalSequenceNumberRequest { | ||
tenantId?: string; | ||
} | ||
export type FeedEvent = { | ||
readonly eventType: string; | ||
readonly eventId: string; | ||
readonly data?: any; | ||
readonly encryptedData?: number; | ||
}; | ||
export type FeedEntry = { | ||
readonly sequenceNumber: number; | ||
readonly aggregateId: string; | ||
readonly timestamp: number; | ||
readonly feedName: string; | ||
readonly events: FeedEvent[]; | ||
}; | ||
export type FeedOverview = { | ||
readonly aggregateType: string; | ||
readonly aggregateCount: number; | ||
readonly batchCount: number; | ||
readonly eventCount: number; | ||
}; | ||
export type LoadFeedResponse = { | ||
readonly entries: FeedEntry[]; | ||
readonly hasMore: boolean; | ||
readonly currentSequenceNumber: number; | ||
}; | ||
export type LoadFeedsOverviewResponse = { | ||
readonly feeds: FeedOverview[]; | ||
}; | ||
export type LoadFeedRequest = { | ||
readonly feedName: string; | ||
readonly tenantId?: string; | ||
readonly since?: number; | ||
readonly limit?: number; | ||
readonly from?: string; | ||
readonly to?: string; | ||
readonly waitTime?: number; | ||
readonly types?: string[]; | ||
readonly partitionNumber?: number; | ||
readonly partitionCount?: number; | ||
}; | ||
export type LoadAllFeedRequest = { | ||
readonly tenantId?: string; | ||
readonly since?: number; | ||
readonly limit?: number; | ||
readonly from?: string; | ||
readonly to?: string; | ||
readonly waitTime?: number; | ||
readonly types?: string[]; | ||
readonly partitionNumber?: number; | ||
readonly partitionCount?: number; | ||
}; | ||
export type GetCurrentSequenceNumberRequest = { | ||
readonly feedName: string; | ||
readonly tenantId?: string; | ||
}; | ||
export type GetGlobalSequenceNumberRequest = { | ||
readonly tenantId?: string; | ||
}; | ||
export declare class FeedsClient extends BaseClient { | ||
@@ -60,0 +60,0 @@ loadOverview(): Promise<LoadFeedsOverviewResponse>; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,138 +11,75 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FeedsClient = void 0; | ||
var _1 = require("./"); | ||
var FeedsClient = /** @class */ (function (_super) { | ||
__extends(FeedsClient, _super); | ||
function FeedsClient() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const _1 = require("./"); | ||
class FeedsClient extends _1.BaseClient { | ||
loadOverview() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return (yield this.axiosClient.get(FeedsClient.feedsUrl())).data; | ||
}); | ||
} | ||
FeedsClient.prototype.loadOverview = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.get(FeedsClient.feedsUrl())]; | ||
case 1: return [2 /*return*/, (_a.sent()).data]; | ||
} | ||
}); | ||
loadFeed(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let config = this.axiosConfig(); | ||
const params = new URLSearchParams(); | ||
if (request.tenantId !== undefined) { | ||
config = this.axiosConfig(request.tenantId); | ||
} | ||
if (request.limit !== undefined) { | ||
params.set('limit', String(request.limit)); | ||
} | ||
if (request.since !== undefined) { | ||
params.set('since', String(request.since)); | ||
} | ||
if (request.from !== undefined) { | ||
params.set('from', String(request.from)); | ||
} | ||
if (request.to !== undefined) { | ||
params.set('to', String(request.to)); | ||
} | ||
if (request.waitTime !== undefined) { | ||
params.set('waitTime', String(request.waitTime)); | ||
} | ||
if (request.partitionNumber !== undefined) { | ||
params.set('partitionNumber', String(request.partitionNumber)); | ||
} | ||
if (request.partitionCount !== undefined) { | ||
params.set('partitionCount', String(request.partitionCount)); | ||
} | ||
if (request.types) { | ||
request.types.forEach((type) => { | ||
params.append('filterType', type); | ||
}); | ||
} | ||
config.params = params; | ||
return (yield this.axiosClient.get(FeedsClient.feedUrl(request.feedName), config)).data; | ||
}); | ||
}; | ||
FeedsClient.prototype.loadFeed = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config, params; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
config = this.axiosConfig(); | ||
params = new URLSearchParams(); | ||
if (request.tenantId !== undefined) { | ||
config = this.axiosConfig(request.tenantId); | ||
} | ||
if (request.limit !== undefined) { | ||
params.set('limit', String(request.limit)); | ||
} | ||
if (request.since !== undefined) { | ||
params.set('since', String(request.since)); | ||
} | ||
if (request.from !== undefined) { | ||
params.set('from', String(request.from)); | ||
} | ||
if (request.to !== undefined) { | ||
params.set('to', String(request.to)); | ||
} | ||
if (request.waitTime !== undefined) { | ||
params.set('waitTime', String(request.waitTime)); | ||
} | ||
if (request.partitionNumber !== undefined) { | ||
params.set('partitionNumber', String(request.partitionNumber)); | ||
} | ||
if (request.partitionCount !== undefined) { | ||
params.set('partitionCount', String(request.partitionCount)); | ||
} | ||
if (request.types) { | ||
request.types.forEach(function (type) { | ||
params.append('filterType', type); | ||
}); | ||
} | ||
config.params = params; | ||
return [4 /*yield*/, this.axiosClient.get(FeedsClient.feedUrl(request.feedName), config)]; | ||
case 1: return [2 /*return*/, (_a.sent()).data]; | ||
} | ||
}); | ||
} | ||
loadAllFeed(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.loadFeed(Object.assign({ feedName: '_all' }, { request })); | ||
}); | ||
}; | ||
FeedsClient.prototype.loadAllFeed = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.loadFeed(__assign({ feedName: '_all' }, { request: request }))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
} | ||
getCurrentSequenceNumber(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const headers = (yield this.axiosClient.head(FeedsClient.feedUrl(request.feedName))).headers; | ||
return Number(headers['Serialized-SequenceNumber-Current']); | ||
}); | ||
}; | ||
FeedsClient.prototype.getCurrentSequenceNumber = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var headers; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.head(FeedsClient.feedUrl(request.feedName))]; | ||
case 1: | ||
headers = (_a.sent()).headers; | ||
return [2 /*return*/, Number(headers['Serialized-SequenceNumber-Current'])]; | ||
} | ||
}); | ||
} | ||
getGlobalSequenceNumber(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const headers = (yield this.axiosClient.head(FeedsClient.allFeedUrl())).headers; | ||
return Number(headers['Serialized-SequenceNumber-Current']); | ||
}); | ||
}; | ||
FeedsClient.prototype.getGlobalSequenceNumber = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var headers; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.head(FeedsClient.allFeedUrl())]; | ||
case 1: | ||
headers = (_a.sent()).headers; | ||
return [2 /*return*/, Number(headers['Serialized-SequenceNumber-Current'])]; | ||
} | ||
}); | ||
}); | ||
}; | ||
FeedsClient.feedsUrl = function () { | ||
return "/feeds"; | ||
}; | ||
FeedsClient.allFeedUrl = function () { | ||
return "/feeds/_all"; | ||
}; | ||
FeedsClient.feedUrl = function (feedName) { | ||
return "/feeds/".concat(feedName); | ||
}; | ||
return FeedsClient; | ||
}(_1.BaseClient)); | ||
} | ||
static feedsUrl() { | ||
return `/feeds`; | ||
} | ||
static allFeedUrl() { | ||
return `/feeds/_all`; | ||
} | ||
static feedUrl(feedName) { | ||
return `/feeds/${feedName}`; | ||
} | ||
} | ||
exports.FeedsClient = FeedsClient; |
import { SerializedInstance } from "./Serialized"; | ||
import { SerializedConfig } from "./types"; | ||
export * from "./types"; | ||
export * from "./decorators"; | ||
export * from "./Serialized"; | ||
export * from "./BaseClient"; | ||
export * from "./StateBuilder"; | ||
export * from "./AggregatesClient"; | ||
export * from "./StateLoader"; | ||
export * from "./ProjectionsClient"; | ||
@@ -10,0 +9,0 @@ export * from "./ReactionsClient"; |
@@ -18,9 +18,8 @@ "use strict"; | ||
exports.Serialized = void 0; | ||
var Serialized_1 = require("./Serialized"); | ||
const Serialized_1 = require("./Serialized"); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./decorators"), exports); | ||
__exportStar(require("./Serialized"), exports); | ||
__exportStar(require("./BaseClient"), exports); | ||
__exportStar(require("./StateBuilder"), exports); | ||
__exportStar(require("./AggregatesClient"), exports); | ||
__exportStar(require("./StateLoader"), exports); | ||
__exportStar(require("./ProjectionsClient"), exports); | ||
@@ -30,9 +29,7 @@ __exportStar(require("./ReactionsClient"), exports); | ||
__exportStar(require("./TenantClient"), exports); | ||
var Serialized = /** @class */ (function () { | ||
function Serialized() { | ||
} | ||
Serialized.create = function (config) { | ||
class Serialized { | ||
static create(config) { | ||
if (!config) { | ||
var accessKey = process.env.SERIALIZED_ACCESS_KEY; | ||
var secretAccessKey = process.env.SERIALIZED_SECRET_ACCESS_KEY; | ||
const accessKey = process.env.SERIALIZED_ACCESS_KEY; | ||
const secretAccessKey = process.env.SERIALIZED_SECRET_ACCESS_KEY; | ||
if (!accessKey || !secretAccessKey) { | ||
@@ -42,3 +39,3 @@ console.error('Environment variable SERIALIZED_ACCESS_KEY or SERIALIZED_SECRET_ACCESS_KEY is undefined.'); | ||
} | ||
return Serialized.createInstance({ accessKey: accessKey, secretAccessKey: secretAccessKey }); | ||
return Serialized.createInstance({ accessKey, secretAccessKey }); | ||
} | ||
@@ -48,8 +45,7 @@ else { | ||
} | ||
}; | ||
Serialized.createInstance = function (config) { | ||
} | ||
static createInstance(config) { | ||
return new Serialized_1.SerializedInstance(config); | ||
}; | ||
return Serialized; | ||
}()); | ||
} | ||
} | ||
exports.Serialized = Serialized; |
import { BaseClient } from "./"; | ||
import { UnauthorizedError } from "./error"; | ||
export declare type ProjectionSort = 'projectionId' | 'reference' | 'createdAt' | 'updatedAt' | '-projectionId' | '-reference' | '-createdAt' | '-updatedAt' | '+projectionId' | '+reference' | '+createdAt' | '+updatedAt'; | ||
export interface GetSingleProjectionResponse { | ||
projectionId: string; | ||
createdAt: number; | ||
updatedAt: number; | ||
data: any; | ||
} | ||
export type ProjectionSort = 'projectionId' | 'reference' | 'createdAt' | 'updatedAt' | '-projectionId' | '-reference' | '-createdAt' | '-updatedAt' | '+projectionId' | '+reference' | '+createdAt' | '+updatedAt'; | ||
export declare enum ProjectionType { | ||
@@ -14,84 +8,91 @@ SINGLE = "SINGLE", | ||
} | ||
export interface DeleteProjectionsRequest { | ||
projectionType: ProjectionType; | ||
projectionName: string; | ||
tenantId?: string; | ||
} | ||
export interface GetAggregatedProjectionResponse { | ||
projectionId: string; | ||
createdAt: number; | ||
updatedAt: number; | ||
data: any; | ||
} | ||
export interface GetAggregatedProjectionRequest { | ||
projectionName: string; | ||
} | ||
export interface CustomProjectionHandler { | ||
eventType: string; | ||
functionUri: string; | ||
} | ||
export interface JsonPathFunction { | ||
function: string; | ||
targetSelector?: string; | ||
eventSelector?: string; | ||
targetFilter?: string; | ||
eventFilter?: string; | ||
rawData?: any; | ||
} | ||
export interface JsonPathHandler { | ||
eventType: string; | ||
functions: JsonPathFunction[]; | ||
} | ||
export interface LoadProjectionDefinitionResponse { | ||
projectionName: string; | ||
feedName: string; | ||
description?: string; | ||
handlers: CustomProjectionHandler[] | JsonPathHandler[]; | ||
} | ||
export interface CreateProjectionDefinitionRequest { | ||
projectionName: string; | ||
feedName: string; | ||
description?: string; | ||
handlers: CustomProjectionHandler[] | JsonPathHandler[]; | ||
indexedFields?: string[]; | ||
aggregated?: boolean; | ||
idField?: string; | ||
signingSecret?: string; | ||
} | ||
export interface DeleteProjectionDefinitionRequest { | ||
projectionName: string; | ||
} | ||
export interface GetProjectionDefinitionRequest { | ||
projectionName: string; | ||
} | ||
export interface ListSingleProjectionsResponse { | ||
projections: GetSingleProjectionResponse[]; | ||
hasMore: boolean; | ||
totalCount: number; | ||
} | ||
export interface GetSingleProjectionRequest { | ||
projectionName: string; | ||
projectionId: string; | ||
tenantId?: string; | ||
awaitCreation?: number; | ||
} | ||
export interface ListSingleProjectionRequest { | ||
projectionName: string; | ||
reference?: string; | ||
from?: string; | ||
to?: string; | ||
tenantId?: string; | ||
sort?: ProjectionSort; | ||
skip?: number; | ||
limit?: number; | ||
ids?: string[]; | ||
search?: string; | ||
} | ||
export interface CountSingleProjectionRequest { | ||
projectionName: string; | ||
tenantId?: string; | ||
} | ||
export interface CountSingleProjectionResponse { | ||
count: number; | ||
} | ||
export type GetSingleProjectionResponse = { | ||
readonly projectionId: string; | ||
readonly createdAt: number; | ||
readonly updatedAt: number; | ||
readonly data: any; | ||
}; | ||
export type DeleteProjectionsRequest = { | ||
readonly projectionType: ProjectionType; | ||
readonly projectionName: string; | ||
readonly tenantId?: string; | ||
}; | ||
export type GetAggregatedProjectionResponse = { | ||
readonly projectionId: string; | ||
readonly createdAt: number; | ||
readonly updatedAt: number; | ||
readonly data: any; | ||
}; | ||
export type GetAggregatedProjectionRequest = { | ||
readonly projectionName: string; | ||
}; | ||
export type CustomProjectionHandler = { | ||
readonly eventType: string; | ||
readonly functionUri: string; | ||
}; | ||
export type JsonPathFunction = { | ||
readonly function: string; | ||
readonly targetSelector?: string; | ||
readonly eventSelector?: string; | ||
readonly targetFilter?: string; | ||
readonly eventFilter?: string; | ||
readonly rawData?: any; | ||
}; | ||
export type JsonPathHandler = { | ||
readonly eventType: string; | ||
readonly feedName?: string; | ||
readonly functions: JsonPathFunction[]; | ||
}; | ||
export type LoadProjectionDefinitionResponse = { | ||
readonly projectionName: string; | ||
readonly feedName: string; | ||
readonly description?: string; | ||
readonly handlers: CustomProjectionHandler[] | JsonPathHandler[]; | ||
}; | ||
export type CreateProjectionDefinitionRequest = { | ||
readonly projectionName: string; | ||
readonly feedName?: string; | ||
readonly description?: string; | ||
readonly handlers: CustomProjectionHandler[] | JsonPathHandler[]; | ||
readonly indexedFields?: string[]; | ||
readonly aggregated?: boolean; | ||
readonly idField?: string; | ||
readonly signingSecret?: string; | ||
}; | ||
export type DeleteProjectionDefinitionRequest = { | ||
readonly projectionName: string; | ||
}; | ||
export type GetProjectionDefinitionRequest = { | ||
readonly projectionName: string; | ||
}; | ||
export type ListSingleProjectionsResponse = { | ||
readonly projections: GetSingleProjectionResponse[]; | ||
readonly hasMore: boolean; | ||
readonly totalCount: number; | ||
}; | ||
export type GetSingleProjectionRequest = { | ||
readonly projectionName: string; | ||
readonly projectionId: string; | ||
readonly tenantId?: string; | ||
readonly awaitCreation?: number; | ||
}; | ||
export type ListSingleProjectionRequest = { | ||
readonly projectionName: string; | ||
readonly reference?: string; | ||
readonly from?: string; | ||
readonly to?: string; | ||
readonly tenantId?: string; | ||
readonly sort?: ProjectionSort; | ||
readonly skip?: number; | ||
readonly limit?: number; | ||
readonly ids?: string[]; | ||
readonly search?: string; | ||
}; | ||
export type CountSingleProjectionRequest = { | ||
readonly projectionName: string; | ||
readonly tenantId?: string; | ||
}; | ||
export type CountSingleProjectionResponse = { | ||
readonly count: number; | ||
}; | ||
export declare const isUnauthorizedError: (error: any) => error is UnauthorizedError; | ||
@@ -98,0 +99,0 @@ export declare class ProjectionsClient extends BaseClient { |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -26,33 +11,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ProjectionsClient = exports.isUnauthorizedError = exports.ProjectionType = void 0; | ||
var _1 = require("./"); | ||
var error_1 = require("./error"); | ||
const _1 = require("./"); | ||
const error_1 = require("./error"); | ||
var ProjectionType; | ||
@@ -63,251 +21,158 @@ (function (ProjectionType) { | ||
})(ProjectionType = exports.ProjectionType || (exports.ProjectionType = {})); | ||
var isUnauthorizedError = function (error) { | ||
const isUnauthorizedError = (error) => { | ||
return error.name === 'UnauthorizedError'; | ||
}; | ||
exports.isUnauthorizedError = isUnauthorizedError; | ||
var ProjectionsClient = /** @class */ (function (_super) { | ||
__extends(ProjectionsClient, _super); | ||
function ProjectionsClient() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
class ProjectionsClient extends _1.BaseClient { | ||
createDefinition(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = ProjectionsClient.projectionDefinitionsUrl(); | ||
try { | ||
yield this.axiosClient.post(url, request, this.axiosConfig()); | ||
} | ||
catch (e) { | ||
throw this.handleAxiosError(e, request); | ||
} | ||
}); | ||
} | ||
ProjectionsClient.prototype.createDefinition = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = ProjectionsClient.projectionDefinitionsUrl(); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.axiosClient.post(url, request, this.axiosConfig())]; | ||
case 2: | ||
_a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
throw this.handleAxiosError(e_1, request); | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
createOrUpdateDefinition(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = ProjectionsClient.projectionDefinitionUrl(request.projectionName); | ||
try { | ||
yield this.axiosClient.put(url, request, this.axiosConfig()); | ||
} | ||
catch (e) { | ||
throw this.handleAxiosError(e, request); | ||
} | ||
}); | ||
}; | ||
ProjectionsClient.prototype.createOrUpdateDefinition = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, e_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = ProjectionsClient.projectionDefinitionUrl(request.projectionName); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.axiosClient.put(url, request, this.axiosConfig())]; | ||
case 2: | ||
_a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_2 = _a.sent(); | ||
throw this.handleAxiosError(e_2, request); | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
} | ||
deleteProjectionDefinition(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = ProjectionsClient.projectionDefinitionUrl(request.projectionName); | ||
try { | ||
yield this.axiosClient.delete(url, this.axiosConfig()); | ||
} | ||
catch (e) { | ||
throw this.handleAxiosError(e, request); | ||
} | ||
}); | ||
}; | ||
ProjectionsClient.prototype.deleteProjectionDefinition = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, e_3; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = ProjectionsClient.projectionDefinitionUrl(request.projectionName); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.axiosClient.delete(url, this.axiosConfig())]; | ||
case 2: | ||
_a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_3 = _a.sent(); | ||
throw this.handleAxiosError(e_3, request); | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
} | ||
getProjectionDefinition(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = ProjectionsClient.projectionDefinitionUrl(request.projectionName); | ||
try { | ||
return (yield this.axiosClient.get(url, this.axiosConfig())).data; | ||
} | ||
catch (e) { | ||
throw this.handleAxiosError(e, request); | ||
} | ||
}); | ||
}; | ||
ProjectionsClient.prototype.getProjectionDefinition = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, e_4; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = ProjectionsClient.projectionDefinitionUrl(request.projectionName); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.axiosClient.get(url, this.axiosConfig())]; | ||
case 2: return [2 /*return*/, (_a.sent()).data]; | ||
case 3: | ||
e_4 = _a.sent(); | ||
throw this.handleAxiosError(e_4, request); | ||
case 4: return [2 /*return*/]; | ||
} | ||
getSingleProjection(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = ProjectionsClient.singleProjectionUrl(request.projectionName, request.projectionId); | ||
try { | ||
let config = this.axiosConfig(); | ||
const params = new URLSearchParams(); | ||
if (request.tenantId !== undefined) { | ||
config = this.axiosConfig(request.tenantId); | ||
} | ||
}); | ||
}); | ||
}; | ||
ProjectionsClient.prototype.getSingleProjection = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, config, params, error_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = ProjectionsClient.singleProjectionUrl(request.projectionName, request.projectionId); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
config = this.axiosConfig(); | ||
params = new URLSearchParams(); | ||
if (request.tenantId !== undefined) { | ||
config = this.axiosConfig(request.tenantId); | ||
} | ||
if (request.awaitCreation !== undefined) { | ||
params.set('awaitCreation', String(request.awaitCreation)); | ||
} | ||
config.params = params; | ||
return [4 /*yield*/, this.axiosClient.get(url, config)]; | ||
case 2: return [2 /*return*/, (_a.sent()).data]; | ||
case 3: | ||
error_2 = _a.sent(); | ||
throw this.handleApiError(error_2, request); | ||
case 4: return [2 /*return*/]; | ||
if (request.awaitCreation !== undefined) { | ||
params.set('awaitCreation', String(request.awaitCreation)); | ||
} | ||
}); | ||
config.params = params; | ||
return (yield this.axiosClient.get(url, config)).data; | ||
} | ||
catch (error) { | ||
throw this.handleApiError(error, request); | ||
} | ||
}); | ||
}; | ||
ProjectionsClient.prototype.getAggregatedProjection = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, error_3; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = ProjectionsClient.aggregatedProjectionUrl(request.projectionName); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.axiosClient.get(url, this.axiosConfig())]; | ||
case 2: return [2 /*return*/, (_a.sent()).data]; | ||
case 3: | ||
error_3 = _a.sent(); | ||
throw this.handleApiError(error_3, request); | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
} | ||
getAggregatedProjection(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = ProjectionsClient.aggregatedProjectionUrl(request.projectionName); | ||
try { | ||
return (yield this.axiosClient.get(url, this.axiosConfig())).data; | ||
} | ||
catch (error) { | ||
throw this.handleApiError(error, request); | ||
} | ||
}); | ||
}; | ||
ProjectionsClient.prototype.delete = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, config, error_4; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (request.projectionType == ProjectionType.SINGLE) { | ||
url = ProjectionsClient.singleProjectionsUrl(request.projectionName); | ||
} | ||
else { | ||
url = ProjectionsClient.aggregatedProjectionUrl(request.projectionName); | ||
} | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
config = request && request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
config.params = new URLSearchParams(); | ||
return [4 /*yield*/, this.axiosClient.delete(url, config)]; | ||
case 2: | ||
_a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_4 = _a.sent(); | ||
throw this.handleApiError(error_4, request); | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
} | ||
delete(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let url; | ||
if (request.projectionType == ProjectionType.SINGLE) { | ||
url = ProjectionsClient.singleProjectionsUrl(request.projectionName); | ||
} | ||
else { | ||
url = ProjectionsClient.aggregatedProjectionUrl(request.projectionName); | ||
} | ||
try { | ||
const config = request && request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
config.params = new URLSearchParams(); | ||
yield this.axiosClient.delete(url, config); | ||
} | ||
catch (error) { | ||
throw this.handleApiError(error, request); | ||
} | ||
}); | ||
}; | ||
ProjectionsClient.prototype.listSingleProjections = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, config, params_1, error_5; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = ProjectionsClient.singleProjectionsUrl(request.projectionName); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
config = this.axiosConfig(); | ||
params_1 = new URLSearchParams(); | ||
if (request.tenantId !== undefined) { | ||
config = this.axiosConfig(request.tenantId); | ||
} | ||
if (request.limit !== undefined) { | ||
params_1.set('limit', request.limit.toString()); | ||
} | ||
if (request.reference !== undefined) { | ||
params_1.set('reference', request.reference); | ||
} | ||
if (request.from !== undefined) { | ||
params_1.set('from', request.from); | ||
} | ||
if (request.to !== undefined) { | ||
params_1.set('to', request.to); | ||
} | ||
if (request.skip !== undefined) { | ||
params_1.set('skip', request.skip.toString()); | ||
} | ||
if (request.sort !== undefined) { | ||
params_1.set('sort', request.sort); | ||
} | ||
if (request.ids !== undefined) { | ||
request.ids.forEach(function (id) { | ||
params_1.append('id', id); | ||
}); | ||
} | ||
if (request.search !== undefined) { | ||
params_1.set('search', request.search); | ||
} | ||
config.params = params_1; | ||
return [4 /*yield*/, this.axiosClient.get(url, config)]; | ||
case 2: return [2 /*return*/, (_a.sent()).data]; | ||
case 3: | ||
error_5 = _a.sent(); | ||
throw this.handleApiError(error_5, request); | ||
case 4: return [2 /*return*/]; | ||
} | ||
listSingleProjections(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = ProjectionsClient.singleProjectionsUrl(request.projectionName); | ||
try { | ||
let config = this.axiosConfig(); | ||
const params = new URLSearchParams(); | ||
if (request.tenantId !== undefined) { | ||
config = this.axiosConfig(request.tenantId); | ||
} | ||
}); | ||
}); | ||
}; | ||
ProjectionsClient.prototype.countSingleProjections = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, config, data, error_6; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = ProjectionsClient.singleProjectionsCountUrl(request.projectionName); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
config = request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
return [4 /*yield*/, this.axiosClient.get(url, config)]; | ||
case 2: | ||
data = (_a.sent()).data; | ||
return [2 /*return*/, data.count]; | ||
case 3: | ||
error_6 = _a.sent(); | ||
throw this.handleApiError(error_6, request); | ||
case 4: return [2 /*return*/]; | ||
if (request.limit !== undefined) { | ||
params.set('limit', request.limit.toString()); | ||
} | ||
}); | ||
if (request.reference !== undefined) { | ||
params.set('reference', request.reference); | ||
} | ||
if (request.from !== undefined) { | ||
params.set('from', request.from); | ||
} | ||
if (request.to !== undefined) { | ||
params.set('to', request.to); | ||
} | ||
if (request.skip !== undefined) { | ||
params.set('skip', request.skip.toString()); | ||
} | ||
if (request.sort !== undefined) { | ||
params.set('sort', request.sort); | ||
} | ||
if (request.ids !== undefined) { | ||
request.ids.forEach((id) => { | ||
params.append('id', id); | ||
}); | ||
} | ||
if (request.search !== undefined) { | ||
params.set('search', request.search); | ||
} | ||
config.params = params; | ||
return (yield this.axiosClient.get(url, config)).data; | ||
} | ||
catch (error) { | ||
throw this.handleApiError(error, request); | ||
} | ||
}); | ||
}; | ||
ProjectionsClient.prototype.handleApiError = function (err, request) { | ||
} | ||
countSingleProjections(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = ProjectionsClient.singleProjectionsCountUrl(request.projectionName); | ||
try { | ||
const config = request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
const data = (yield this.axiosClient.get(url, config)).data; | ||
return data.count; | ||
} | ||
catch (error) { | ||
throw this.handleApiError(error, request); | ||
} | ||
}); | ||
} | ||
handleApiError(err, request) { | ||
if ((0, error_1.isSerializedApiError)(err)) { | ||
@@ -319,4 +184,4 @@ if (err.statusCode === 404) { | ||
return err; | ||
}; | ||
ProjectionsClient.prototype.handleAxiosError = function (err, request) { | ||
} | ||
handleAxiosError(err, request) { | ||
if ((0, error_1.isSerializedApiError)(err)) { | ||
@@ -328,23 +193,22 @@ if (err.statusCode === 404) { | ||
return err; | ||
}; | ||
ProjectionsClient.projectionDefinitionsUrl = function () { | ||
return "/projections/definitions"; | ||
}; | ||
ProjectionsClient.projectionDefinitionUrl = function (projectionName) { | ||
return "/projections/definitions/".concat(projectionName); | ||
}; | ||
ProjectionsClient.singleProjectionUrl = function (projectionName, projectionId) { | ||
return "/projections/single/".concat(projectionName, "/").concat(projectionId); | ||
}; | ||
ProjectionsClient.aggregatedProjectionUrl = function (projectionName) { | ||
return "/projections/aggregated/".concat(projectionName); | ||
}; | ||
ProjectionsClient.singleProjectionsUrl = function (projectionName) { | ||
return "/projections/single/".concat(projectionName); | ||
}; | ||
ProjectionsClient.singleProjectionsCountUrl = function (projectionName) { | ||
return "/projections/single/".concat(projectionName, "/_count"); | ||
}; | ||
return ProjectionsClient; | ||
}(_1.BaseClient)); | ||
} | ||
static projectionDefinitionsUrl() { | ||
return `/projections/definitions`; | ||
} | ||
static projectionDefinitionUrl(projectionName) { | ||
return `/projections/definitions/${projectionName}`; | ||
} | ||
static singleProjectionUrl(projectionName, projectionId) { | ||
return `/projections/single/${projectionName}/${projectionId}`; | ||
} | ||
static aggregatedProjectionUrl(projectionName) { | ||
return `/projections/aggregated/${projectionName}`; | ||
} | ||
static singleProjectionsUrl(projectionName) { | ||
return `/projections/single/${projectionName}`; | ||
} | ||
static singleProjectionsCountUrl(projectionName) { | ||
return `/projections/single/${projectionName}/_count`; | ||
} | ||
} | ||
exports.ProjectionsClient = ProjectionsClient; |
import { BaseClient } from "./"; | ||
export interface HttpAction { | ||
actionType: 'HTTP_POST'; | ||
targetUri: string; | ||
signingSecret?: string; | ||
} | ||
export interface IftttAction { | ||
actionType: 'IFTTT_POST'; | ||
targetUri: string; | ||
valueMap?: object; | ||
} | ||
export interface AutomateAction { | ||
actionType: 'AUTOMATE_POST'; | ||
targetUri: string; | ||
valueMap?: object; | ||
} | ||
export interface ZapierAction { | ||
actionType: 'ZAPIER_POST'; | ||
targetUri: string; | ||
valueMap?: object; | ||
} | ||
export interface SlackAction { | ||
actionType: 'SLACK_POST'; | ||
targetUri: string; | ||
body?: object; | ||
} | ||
export declare type Action = HttpAction | SlackAction | IftttAction | AutomateAction | ZapierAction; | ||
export interface Reaction { | ||
reactionId: string; | ||
reactionName: string; | ||
aggregateType: string; | ||
aggregateId: string; | ||
eventId: string; | ||
createdAt: number; | ||
triggerAt: number; | ||
} | ||
export interface ListReactionsResponse { | ||
reactions: Reaction[]; | ||
} | ||
export interface GetReactionDefinitionRequest { | ||
reactionName: string; | ||
} | ||
export interface DeleteReactionDefinitionRequest { | ||
reactionName: string; | ||
} | ||
export interface DeleteReactionRequest { | ||
reactionId: string; | ||
tenantId?: string; | ||
} | ||
export interface ExecuteReactionRequest { | ||
reactionId: string; | ||
tenantId?: string; | ||
} | ||
export interface ListReactionsRequest { | ||
tenantId?: string; | ||
status?: string; | ||
skip?: number; | ||
limit?: number; | ||
aggregateId?: string; | ||
eventId?: string; | ||
from?: number; | ||
to?: number; | ||
} | ||
export interface CreateReactionDefinitionRequest { | ||
reactionName: string; | ||
feedName: string; | ||
description?: string; | ||
reactOnEventType: string; | ||
action: Action; | ||
cancelOnEventTypes?: string[]; | ||
triggerTimeField?: string; | ||
offset?: string; | ||
} | ||
export interface LoadReactionDefinitionResponse { | ||
reactionName: string; | ||
feedName: string; | ||
description?: string; | ||
reactOnEventType: string; | ||
action: Action; | ||
cancelOnEventTypes?: string[]; | ||
triggerTimeField?: string; | ||
offset?: string; | ||
} | ||
export interface LoadReactionDefinitionsResponse { | ||
definitions: string; | ||
} | ||
export type HttpAction = { | ||
readonly actionType: 'HTTP_POST'; | ||
readonly targetUri: string; | ||
readonly signingSecret?: string; | ||
}; | ||
export type IftttAction = { | ||
readonly actionType: 'IFTTT_POST'; | ||
readonly targetUri: string; | ||
readonly valueMap?: object; | ||
}; | ||
export type AutomateAction = { | ||
readonly actionType: 'AUTOMATE_POST'; | ||
readonly targetUri: string; | ||
readonly valueMap?: object; | ||
}; | ||
export type ZapierAction = { | ||
readonly actionType: 'ZAPIER_POST'; | ||
readonly targetUri: string; | ||
readonly valueMap?: object; | ||
}; | ||
export type SlackAction = { | ||
readonly actionType: 'SLACK_POST'; | ||
readonly targetUri: string; | ||
readonly body?: object; | ||
}; | ||
export type Action = HttpAction | SlackAction | IftttAction | AutomateAction | ZapierAction; | ||
export type Reaction = { | ||
readonly reactionId: string; | ||
readonly reactionName: string; | ||
readonly aggregateType: string; | ||
readonly aggregateId: string; | ||
readonly eventId: string; | ||
readonly createdAt: number; | ||
readonly triggerAt: number; | ||
}; | ||
export type ListReactionsResponse = { | ||
readonly reactions: Reaction[]; | ||
}; | ||
export type GetReactionDefinitionRequest = { | ||
readonly reactionName: string; | ||
}; | ||
export type DeleteReactionDefinitionRequest = { | ||
readonly reactionName: string; | ||
}; | ||
export type DeleteReactionRequest = { | ||
readonly reactionId: string; | ||
readonly tenantId?: string; | ||
}; | ||
export type ExecuteReactionRequest = { | ||
readonly reactionId: string; | ||
readonly tenantId?: string; | ||
}; | ||
export type ListReactionsRequest = { | ||
readonly tenantId?: string; | ||
readonly status?: string; | ||
readonly skip?: number; | ||
readonly limit?: number; | ||
readonly aggregateId?: string; | ||
readonly eventId?: string; | ||
readonly from?: number; | ||
readonly to?: number; | ||
}; | ||
export type CreateReactionDefinitionRequest = { | ||
readonly reactionName: string; | ||
readonly feedName: string; | ||
readonly description?: string; | ||
readonly reactOnEventType: string; | ||
readonly action: Action; | ||
readonly cancelOnEventTypes?: string[]; | ||
readonly triggerTimeField?: string; | ||
readonly offset?: string; | ||
}; | ||
export type LoadReactionDefinitionResponse = { | ||
readonly reactionName: string; | ||
readonly feedName: string; | ||
readonly description?: string; | ||
readonly reactOnEventType: string; | ||
readonly action: Action; | ||
readonly cancelOnEventTypes?: string[]; | ||
readonly triggerTimeField?: string; | ||
readonly offset?: string; | ||
}; | ||
export type LoadReactionDefinitionsResponse = { | ||
readonly definitions: string; | ||
}; | ||
export declare class ReactionsClient extends BaseClient { | ||
@@ -88,0 +88,0 @@ createDefinition(request: CreateReactionDefinitionRequest): Promise<void>; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -26,62 +11,17 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ReactionsClient = void 0; | ||
var _1 = require("./"); | ||
var ReactionsClient = /** @class */ (function (_super) { | ||
__extends(ReactionsClient, _super); | ||
function ReactionsClient() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const _1 = require("./"); | ||
class ReactionsClient extends _1.BaseClient { | ||
createDefinition(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.axiosClient.post(ReactionsClient.reactionDefinitionsUrl(), request, this.axiosConfig()); | ||
}); | ||
} | ||
ReactionsClient.prototype.createDefinition = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.post(ReactionsClient.reactionDefinitionsUrl(), request, this.axiosConfig())]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
; | ||
ReactionsClient.prototype.createOrUpdateDefinition = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.put(ReactionsClient.reactionDefinitionUrl(request.reactionName), request, this.axiosConfig())]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
createOrUpdateDefinition(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.axiosClient.put(ReactionsClient.reactionDefinitionUrl(request.reactionName), request, this.axiosConfig()); | ||
}); | ||
}; | ||
} | ||
; | ||
@@ -92,137 +32,87 @@ /** | ||
*/ | ||
ReactionsClient.prototype.createOrUpdateReactionDefinition = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.createOrUpdateDefinition(request)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
createOrUpdateReactionDefinition(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.createOrUpdateDefinition(request); | ||
}); | ||
}; | ||
} | ||
; | ||
ReactionsClient.prototype.listReactionDefinitions = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.get(ReactionsClient.reactionDefinitionsUrl(), this.axiosConfig())]; | ||
case 1: return [2 /*return*/, (_a.sent()).data]; | ||
} | ||
}); | ||
listReactionDefinitions() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return (yield this.axiosClient.get(ReactionsClient.reactionDefinitionsUrl(), this.axiosConfig())).data; | ||
}); | ||
}; | ||
} | ||
; | ||
ReactionsClient.prototype.getReactionDefinition = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.get(ReactionsClient.reactionDefinitionUrl(request.reactionName), this.axiosConfig())]; | ||
case 1: return [2 /*return*/, (_a.sent()).data]; | ||
} | ||
}); | ||
getReactionDefinition(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return (yield this.axiosClient.get(ReactionsClient.reactionDefinitionUrl(request.reactionName), this.axiosConfig())).data; | ||
}); | ||
}; | ||
} | ||
; | ||
ReactionsClient.prototype.deleteDefinition = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.delete(ReactionsClient.reactionDefinitionUrl(request.reactionName), this.axiosConfig())]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
deleteDefinition(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.axiosClient.delete(ReactionsClient.reactionDefinitionUrl(request.reactionName), this.axiosConfig()); | ||
}); | ||
}; | ||
} | ||
; | ||
ReactionsClient.prototype.listReactions = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
config = request && request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
config.params = new URLSearchParams(); | ||
if (request.status !== undefined) { | ||
config.params.set('status', request.status); | ||
} | ||
if (request.skip !== undefined) { | ||
config.params.set('skip', request.skip.toString()); | ||
} | ||
if (request.limit !== undefined) { | ||
config.params.set('limit', request.limit.toString()); | ||
} | ||
if (request.aggregateId !== undefined) { | ||
config.params.set('aggregateId', request.aggregateId); | ||
} | ||
if (request.eventId !== undefined) { | ||
config.params.set('eventId', request.eventId); | ||
} | ||
if (request.from !== undefined) { | ||
config.params.set('from', request.from.toString()); | ||
} | ||
if (request.to !== undefined) { | ||
config.params.set('to', request.to.toString()); | ||
} | ||
return [4 /*yield*/, this.axiosClient.get(ReactionsClient.reactionsUrl(), config)]; | ||
case 1: return [2 /*return*/, (_a.sent()).data]; | ||
} | ||
}); | ||
listReactions(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = request && request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
config.params = new URLSearchParams(); | ||
if (request.status !== undefined) { | ||
config.params.set('status', request.status); | ||
} | ||
if (request.skip !== undefined) { | ||
config.params.set('skip', request.skip.toString()); | ||
} | ||
if (request.limit !== undefined) { | ||
config.params.set('limit', request.limit.toString()); | ||
} | ||
if (request.aggregateId !== undefined) { | ||
config.params.set('aggregateId', request.aggregateId); | ||
} | ||
if (request.eventId !== undefined) { | ||
config.params.set('eventId', request.eventId); | ||
} | ||
if (request.from !== undefined) { | ||
config.params.set('from', request.from.toString()); | ||
} | ||
if (request.to !== undefined) { | ||
config.params.set('to', request.to.toString()); | ||
} | ||
return (yield this.axiosClient.get(ReactionsClient.reactionsUrl(), config)).data; | ||
}); | ||
}; | ||
} | ||
; | ||
ReactionsClient.prototype.deleteReaction = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
config = request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
config.params = new URLSearchParams(); | ||
return [4 /*yield*/, this.axiosClient.delete(ReactionsClient.reactionUrl(request.reactionId), config)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
deleteReaction(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
config.params = new URLSearchParams(); | ||
yield this.axiosClient.delete(ReactionsClient.reactionUrl(request.reactionId), config); | ||
}); | ||
}; | ||
} | ||
; | ||
ReactionsClient.prototype.executeReaction = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
config = request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
config.params = new URLSearchParams(); | ||
return [4 /*yield*/, this.axiosClient.post(ReactionsClient.reactionExecutionUrl(request.reactionId), '', config)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
executeReaction(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = request.tenantId ? this.axiosConfig(request.tenantId) : this.axiosConfig(); | ||
config.params = new URLSearchParams(); | ||
yield this.axiosClient.post(ReactionsClient.reactionExecutionUrl(request.reactionId), '', config); | ||
}); | ||
}; | ||
} | ||
; | ||
ReactionsClient.reactionDefinitionsUrl = function () { | ||
return "/reactions/definitions"; | ||
}; | ||
ReactionsClient.reactionDefinitionUrl = function (reactionName) { | ||
return "/reactions/definitions/".concat(reactionName); | ||
}; | ||
ReactionsClient.reactionsUrl = function () { | ||
return "/reactions"; | ||
}; | ||
ReactionsClient.reactionUrl = function (reactionId) { | ||
return "/reactions/".concat(reactionId); | ||
}; | ||
ReactionsClient.reactionExecutionUrl = function (reactionId) { | ||
return "/reactions/".concat(reactionId, "/execute"); | ||
}; | ||
return ReactionsClient; | ||
}(_1.BaseClient)); | ||
static reactionDefinitionsUrl() { | ||
return `/reactions/definitions`; | ||
} | ||
static reactionDefinitionUrl(reactionName) { | ||
return `/reactions/definitions/${reactionName}`; | ||
} | ||
static reactionsUrl() { | ||
return `/reactions`; | ||
} | ||
static reactionUrl(reactionId) { | ||
return `/reactions/${reactionId}`; | ||
} | ||
static reactionExecutionUrl(reactionId) { | ||
return `/reactions/${reactionId}/execute`; | ||
} | ||
} | ||
exports.ReactionsClient = ReactionsClient; |
@@ -11,50 +11,15 @@ "use strict"; | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LinearRetryStrategy = exports.NoRetryStrategy = void 0; | ||
var error_1 = require("./error"); | ||
const error_1 = require("./error"); | ||
/** | ||
* Performs no retries, but tries invoking the target function once. | ||
*/ | ||
var NoRetryStrategy = /** @class */ (function () { | ||
function NoRetryStrategy() { | ||
class NoRetryStrategy { | ||
executeWithRetries(fn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield fn(); | ||
}); | ||
} | ||
NoRetryStrategy.prototype.executeWithRetries = function (fn) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fn()]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return NoRetryStrategy; | ||
}()); | ||
} | ||
exports.NoRetryStrategy = NoRetryStrategy; | ||
@@ -64,3 +29,3 @@ /** | ||
*/ | ||
var LinearRetryStrategy = /** @class */ (function () { | ||
class LinearRetryStrategy { | ||
/** | ||
@@ -70,50 +35,35 @@ * @param retryCount the maximum number of retries | ||
*/ | ||
function LinearRetryStrategy(retryCount, sleep) { | ||
constructor(retryCount, sleep) { | ||
this.retryCount = retryCount; | ||
this.sleep = sleep; | ||
if (retryCount < 0 || retryCount > LinearRetryStrategy.MAX_RETRY_COUNT) { | ||
throw new error_1.ConfigurationError("retryCount must be between 0 and ".concat(LinearRetryStrategy.MAX_RETRY_COUNT)); | ||
throw new error_1.ConfigurationError(`retryCount must be between 0 and ${LinearRetryStrategy.MAX_RETRY_COUNT}`); | ||
} | ||
if (sleep < 0 || sleep > LinearRetryStrategy.MAX_SLEEP_MS) { | ||
throw new error_1.ConfigurationError("sleep must be between 0 and ".concat(LinearRetryStrategy.MAX_SLEEP_MS)); | ||
throw new error_1.ConfigurationError(`sleep must be between 0 and ${LinearRetryStrategy.MAX_SLEEP_MS}`); | ||
} | ||
} | ||
LinearRetryStrategy.prototype.executeWithRetries = function (fn) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var lastError, i, error_2; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
i = 0; | ||
_a.label = 1; | ||
case 1: | ||
if (!(i <= this.retryCount)) return [3 /*break*/, 9]; | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 4, , 8]); | ||
return [4 /*yield*/, fn()]; | ||
case 3: return [2 /*return*/, _a.sent()]; | ||
case 4: | ||
error_2 = _a.sent(); | ||
if (!((0, error_1.isSerializedApiError)(error_2) && error_2.statusCode === 409)) return [3 /*break*/, 6]; | ||
lastError = error_2; | ||
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, _this.sleep); })]; | ||
case 5: | ||
_a.sent(); | ||
return [3 /*break*/, 7]; | ||
case 6: throw error_2; | ||
case 7: return [3 /*break*/, 8]; | ||
case 8: | ||
i++; | ||
return [3 /*break*/, 1]; | ||
case 9: throw lastError; | ||
executeWithRetries(fn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let lastError; | ||
for (let i = 0; i <= this.retryCount; i++) { | ||
try { | ||
return yield fn(); | ||
} | ||
}); | ||
catch (error) { | ||
if ((0, error_1.isSerializedApiError)(error) && error.statusCode === 409) { | ||
lastError = error; | ||
yield new Promise(resolve => setTimeout(resolve, this.sleep)); | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
} | ||
throw lastError; | ||
}); | ||
}; | ||
LinearRetryStrategy.MAX_RETRY_COUNT = 10; | ||
LinearRetryStrategy.MAX_SLEEP_MS = 10000; | ||
return LinearRetryStrategy; | ||
}()); | ||
} | ||
} | ||
exports.LinearRetryStrategy = LinearRetryStrategy; | ||
LinearRetryStrategy.MAX_RETRY_COUNT = 10; | ||
LinearRetryStrategy.MAX_SLEEP_MS = 10000; |
@@ -1,10 +0,2 @@ | ||
import { AggregatesClient, AggregatesClientConfig, FeedsClient, ProjectionsClient, ReactionsClient, SerializedConfig, TenantClient } from "./"; | ||
export declare class DomainEvent<E> { | ||
readonly eventId: string; | ||
readonly eventType: string; | ||
readonly data: E; | ||
readonly encryptedData?: string; | ||
constructor(eventData: E, encryptedData?: string); | ||
static create<E>(eventData: E, encryptedData?: string): DomainEvent<E>; | ||
} | ||
import { AggregatesClient, AggregatesClientConfig, FeedsClient, ProjectionsClient, ReactionsClient, SerializedConfig, StateBuilder, TenantClient } from "./"; | ||
export declare class SerializedInstance { | ||
@@ -14,3 +6,5 @@ readonly serializedConfig: SerializedConfig; | ||
validateConfiguration(): void; | ||
aggregateClient(aggregateType: any, aggregateClientConfig?: AggregatesClientConfig): AggregatesClient; | ||
aggregateClient<A, S, T extends string, E extends { | ||
eventType: string; | ||
}>(config: AggregatesClientConfig<T>, stateBuilder: StateBuilder<S, E>, aggregateFactory: (state: S) => A): AggregatesClient<A, S, T, E>; | ||
projectionsClient(): ProjectionsClient; | ||
@@ -17,0 +11,0 @@ feedsClient(): FeedsClient; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SerializedInstance = exports.DomainEvent = void 0; | ||
var _1 = require("./"); | ||
var uuid_1 = require("uuid"); | ||
var DomainEvent = /** @class */ (function () { | ||
function DomainEvent(eventData, encryptedData) { | ||
this.eventId = (0, uuid_1.v4)(); | ||
this.eventType = eventData.constructor.name; | ||
this.data = eventData; | ||
this.encryptedData = encryptedData; | ||
} | ||
DomainEvent.create = function (eventData, encryptedData) { | ||
return new DomainEvent(eventData, encryptedData); | ||
}; | ||
return DomainEvent; | ||
}()); | ||
exports.DomainEvent = DomainEvent; | ||
var SerializedInstance = /** @class */ (function () { | ||
function SerializedInstance(serializedConfig) { | ||
exports.SerializedInstance = void 0; | ||
const _1 = require("./"); | ||
class SerializedInstance { | ||
constructor(serializedConfig) { | ||
this.serializedConfig = serializedConfig; | ||
@@ -27,3 +13,3 @@ if (!serializedConfig) { | ||
} | ||
SerializedInstance.prototype.validateConfiguration = function () { | ||
validateConfiguration() { | ||
if (!this.serializedConfig.accessKey) { | ||
@@ -35,20 +21,19 @@ throw "accessKey is missing in client configuration"; | ||
} | ||
}; | ||
SerializedInstance.prototype.aggregateClient = function (aggregateType, aggregateClientConfig) { | ||
return new _1.AggregatesClient(aggregateType, this.serializedConfig, aggregateClientConfig); | ||
}; | ||
SerializedInstance.prototype.projectionsClient = function () { | ||
} | ||
aggregateClient(config, stateBuilder, aggregateFactory) { | ||
return new _1.AggregatesClient(this.serializedConfig, config, stateBuilder, aggregateFactory); | ||
} | ||
projectionsClient() { | ||
return new _1.ProjectionsClient(this.serializedConfig); | ||
}; | ||
SerializedInstance.prototype.feedsClient = function () { | ||
} | ||
feedsClient() { | ||
return new _1.FeedsClient(this.serializedConfig); | ||
}; | ||
SerializedInstance.prototype.reactionsClient = function () { | ||
} | ||
reactionsClient() { | ||
return new _1.ReactionsClient(this.serializedConfig); | ||
}; | ||
SerializedInstance.prototype.tenantClient = function () { | ||
} | ||
tenantClient() { | ||
return new _1.TenantClient(this.serializedConfig); | ||
}; | ||
return SerializedInstance; | ||
}()); | ||
} | ||
} | ||
exports.SerializedInstance = SerializedInstance; |
@@ -1,10 +0,6 @@ | ||
import { DomainEvent } from "./Serialized"; | ||
declare class StateLoader { | ||
private readonly stateType; | ||
private readonly initialStateFunction; | ||
private readonly eventHandlers; | ||
private readonly defaultHandler; | ||
constructor(stateType: any); | ||
loadState(events: DomainEvent<any>[]): any; | ||
import { StateBuilder } from "./StateBuilder"; | ||
export declare class StateLoader<S, E extends { | ||
eventType: string; | ||
}> { | ||
loadState(currentState: S, stateBuilder: StateBuilder<S, E>, events: E[]): S; | ||
} | ||
export { StateLoader }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StateLoader = void 0; | ||
var error_1 = require("./error"); | ||
var StateLoader = /** @class */ (function () { | ||
function StateLoader(stateType) { | ||
this.stateType = stateType; | ||
var constructor = stateType.prototype.constructor; | ||
var instance = new constructor({}); | ||
if (!instance.eventHandlers || instance.eventHandlers.length === 0) { | ||
throw new error_1.ConfigurationError("No event handlers configured for aggregate: ".concat(constructor.name)); | ||
} | ||
if (instance.initialState && typeof instance.initialState !== 'function') { | ||
throw new error_1.ConfigurationError("Initial state of ".concat(constructor.name, " must be a function")); | ||
} | ||
else { | ||
this.initialStateFunction = instance.initialState ? instance.initialState : function () { | ||
}; | ||
} | ||
this.eventHandlers = instance.eventHandlers; | ||
this.defaultHandler = instance.defaultHandler; | ||
} | ||
StateLoader.prototype.loadState = function (events) { | ||
var _this = this; | ||
var currentState = this.initialStateFunction(); | ||
events.forEach(function (e) { | ||
var eventType = e.eventType; | ||
var handler = _this.eventHandlers[e.eventType]; | ||
if (handler) { | ||
currentState = handler.call({}, currentState, e); | ||
} | ||
else if (_this.defaultHandler) { | ||
_this.defaultHandler.call({}, currentState, e); | ||
} | ||
else { | ||
throw new error_1.StateLoadingError("Failed to call handler. No match for event ".concat(eventType)); | ||
} | ||
class StateLoader { | ||
loadState(currentState, stateBuilder, events) { | ||
events.forEach(e => { | ||
let eventType = e.eventType; | ||
currentState = stateBuilder[`apply${eventType}`](currentState, e); | ||
}); | ||
return currentState; | ||
}; | ||
return StateLoader; | ||
}()); | ||
} | ||
} | ||
exports.StateLoader = StateLoader; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -26,83 +11,30 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TenantClient = void 0; | ||
var _1 = require("./"); | ||
var TenantClient = /** @class */ (function (_super) { | ||
__extends(TenantClient, _super); | ||
function TenantClient() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const _1 = require("./"); | ||
class TenantClient extends _1.BaseClient { | ||
addTenant(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.axiosClient.post(TenantClient.tenantRootUrl(), request); | ||
}); | ||
} | ||
TenantClient.prototype.addTenant = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.post(TenantClient.tenantRootUrl(), request)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
updateTenant(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.axiosClient.put(TenantClient.tenantUrl(request.tenantId), request, this.axiosConfig()); | ||
}); | ||
}; | ||
TenantClient.prototype.updateTenant = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.put(TenantClient.tenantUrl(request.tenantId), request, this.axiosConfig())]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
} | ||
; | ||
TenantClient.prototype.deleteTenant = function (request) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosClient.delete(TenantClient.tenantUrl(request.tenantId))]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
deleteTenant(request) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.axiosClient.delete(TenantClient.tenantUrl(request.tenantId)); | ||
}); | ||
}; | ||
} | ||
; | ||
TenantClient.tenantUrl = function (tenantId) { | ||
return "/tenants/".concat(tenantId); | ||
}; | ||
TenantClient.tenantRootUrl = function () { | ||
return "/tenants"; | ||
}; | ||
return TenantClient; | ||
}(_1.BaseClient)); | ||
static tenantUrl(tenantId) { | ||
return `/tenants/${tenantId}`; | ||
} | ||
static tenantRootUrl() { | ||
return `/tenants`; | ||
} | ||
} | ||
exports.TenantClient = TenantClient; |
@@ -6,3 +6,3 @@ { | ||
"author": "Serialized", | ||
"version": "7.4.0", | ||
"version": "8.1.0", | ||
"main": "dist/index.js", | ||
@@ -39,11 +39,12 @@ "types": "dist/index.d.ts", | ||
"@types/jest": "28.1.3", | ||
"@types/node": "18.14.1", | ||
"jest": "28.1.1", | ||
"nock": "13.2.4", | ||
"ts-jest": "28.0.5", | ||
"typescript": "4.7.4" | ||
"typescript": "4.9.5" | ||
}, | ||
"engines": { | ||
"npm": ">=6.0.0", | ||
"node": ">=12.0.0" | ||
"node": ">=16.0.0" | ||
} | ||
} |
142
README.md
@@ -1,11 +0,10 @@ | ||
# Serialized Javascript & Typescript client | ||
# Serialized Typescript client | ||
The official Javascript/Typescript client for [Serialized](https://serialized.io). | ||
The official Typescript client for [Serialized](https://serialized.io). | ||
## ✨ Features | ||
- Client for Event Sourcing & CQRS APIs provided by [Serialized](https://serialized.io) | ||
- Works both for Typescript and Javascript on Node version >= 10. | ||
- Built with Typescript | ||
- Client for Event Sourcing & CQRS APIs provided by [Serialized](https://serialized.io) | ||
- Promise-based API that supports async/await | ||
- Built with Typescript | ||
- Provides an easy way to implement DDD Aggregates using Event Sourcing. | ||
@@ -24,2 +23,3 @@ | ||
Import the library and initialize the client instance: | ||
```typescript | ||
@@ -29,4 +29,4 @@ import {Serialized} from "@serialized/serialized-client" | ||
const serialized = Serialized.create({ | ||
accessKey: "<YOUR_ACCESS_KEY>", | ||
secretAccessKey: "<YOUR_SECRET_ACCESS_KEY>" | ||
accessKey: "<YOUR_ACCESS_KEY>", | ||
secretAccessKey: "<YOUR_SECRET_ACCESS_KEY>" | ||
}); | ||
@@ -38,2 +38,3 @@ ``` | ||
### State | ||
The state type holds the assembled state from the events during the load of the aggregate. | ||
@@ -47,2 +48,3 @@ | ||
STARTED = 'STARTED', | ||
CANCELED = 'CANCELED', | ||
FINISHED = 'FINISHED' | ||
@@ -52,95 +54,110 @@ } | ||
type GameState = { | ||
readonly gameId?: string; | ||
readonly status?: GameStatus; | ||
readonly gameId?: string | ||
readonly status?: GameStatus | ||
} | ||
``` | ||
### Events | ||
Define your domain events as immutable Typescript classes. | ||
Define your domain events as types | ||
```typescript | ||
class GameCreated { | ||
constructor(readonly gameId: string, | ||
readonly creationTime: number) { | ||
}; | ||
} | ||
class GameStarted { | ||
constructor(readonly gameId: string, | ||
readonly startTime: number) { | ||
}; | ||
} | ||
type GameCreated = DomainEvent<'GameCreated', { gameId: string, creationTime: number }> | ||
type GameStarted = DomainEvent<'GameStarted', { gameId: string, startTime: number }> | ||
type GameCanceled = DomainEvent<'GameCanceled', { gameId: string, cancelTime: number }> | ||
type GameFinished = DomainEvent<'GameFinished', { gameId: string, endTime: number }> | ||
type GameEvent = GameCreated | GameStarted | GameCanceled | GameFinished; | ||
``` | ||
Next, we create the state builder, which can handle loading events one-by-one to create the current state. | ||
Next, we create the `StateBuilder` implementation, which can handle loading events one-by-one to create the current | ||
state. Each method should have `apply` as a prefix and the event type as the suffix and return the new state. | ||
The state builder has methods decorated with `@EventHandler` to mark its event handling methods: | ||
```typescript | ||
class GameStateBuilder { | ||
get initialState(): GameState { | ||
return () => ({ | ||
status: GameStatus.UNDEFINED | ||
}) | ||
const stateBuilder: StateBuilder<GameState, GameEvent> = { | ||
initialState: () => { | ||
return {gameId: '', status: GameStatus.UNDEFINED} | ||
}, | ||
applyGameCreated: (state, event) => { | ||
return {...state, gameId: event.data.gameId, status: GameStatus.CREATED} | ||
}, | ||
applyGameStarted: (state, event) => { | ||
return {...state, status: GameStatus.STARTED} | ||
}, | ||
applyGameCanceled: (state, event) => { | ||
return {...state, status: GameStatus.CANCELED} | ||
}, | ||
applyGameFinished: (state, event) => { | ||
return {...state, status: GameStatus.FINISHED} | ||
} | ||
@EventHandler(GameCreated) | ||
handleGameCreated(state: GameState, event: DomainEvent<GameCreated>): GameState { | ||
return {gameId: state.gameId, status: GameStatus.CREATED}; | ||
} | ||
@EventHandler(GameStarted) | ||
handleGameStarted(state: GameState, event: DomainEvent<GameStarted>): GameState { | ||
return {...state, status: GameStatus.STARTED}; | ||
} | ||
} | ||
``` | ||
## Aggregate | ||
## Aggregate | ||
The aggregate contains the domain logic and each method should return `0..n` events that should be stored for a successful operation. | ||
The aggregate contains the domain logic and each method should return `0..n` events that should be stored for a | ||
successful operation. The aggregate takes the state as a constructor argument and should be immutable. | ||
Any unsuccessful operation should throw an error. | ||
Any unsuccessful operation should throw an error. | ||
```typescript | ||
@Aggregate('game', GameStateBuilder) | ||
class Game { | ||
constructor(private readonly state: GameState) { | ||
} | ||
create(gameId: string, creationTime: number) { | ||
return [DomainEvent.create(new GameCreated(gameId, creationTime))]; | ||
create(gameId: string, creationTime: number): GameCreated[] { | ||
const currentStatus = this.state.status; | ||
if (currentStatus == GameStatus.UNDEFINED) { | ||
return [{ | ||
eventType: 'GameCreated', | ||
eventId: uuidv4(), | ||
data: { | ||
gameId, | ||
creationTime | ||
} | ||
}]; | ||
} else if (currentStatus == GameStatus.CREATED) { | ||
return []; | ||
} else { | ||
throw new InvalidGameStatusException(GameStatus.UNDEFINED, currentStatus); | ||
} | ||
} | ||
start(gameId: string, startTime: number) { | ||
if (this.state.status !== GameStatus.CREATED) { | ||
throw new Error('Must create Game before you can start it'); | ||
start(startTime: number): GameStarted[] { | ||
const currentStatus = this.state.status; | ||
if (this.state.status == GameStatus.STARTED) { | ||
return []; | ||
} else if (this.state.status == GameStatus.CREATED) { | ||
return [{ | ||
eventType: 'GameStarted', | ||
eventId: uuidv4(), | ||
data: { | ||
gameId: this.state.gameId, | ||
startTime | ||
} | ||
}]; | ||
} | ||
return [DomainEvent.create(new GameStarted(gameId, startTime))]; | ||
throw new InvalidGameStatusException(GameStatus.CREATED, currentStatus); | ||
} | ||
- | ||
... | ||
} | ||
``` | ||
Test the client by creating a `Game`: | ||
```typescript | ||
const gameClient = serialized.aggregateClient(Game); | ||
const gameId = uuidv4(); | ||
const gameClient = serialized.aggregateClient({aggregateType: 'game'}, stateBuilder, (state: GameState) => new Game(state)); | ||
await gameClient.create(gameId, (game) => (game.create(gameId, Date.now()))); | ||
``` | ||
To perform an `update` operation, which means loading all events, performing business logic and then appending more events | ||
To perform an `update` operation, which means loading all events, performing business logic and then appending more | ||
events | ||
```typescript | ||
await gameClient.update(gameId, (game: Game) => (game.start(gameId, startTime))); | ||
await gameClient.update({aggregateId: gameId}, (game: Game) => game.start(startTime)) | ||
``` | ||
## 📄 Client reference | ||
* [Getting started](https://github.com/serialized-io/client-js/blob/main/docs/getting-started.md) | ||
* [Reference](https://github.com/serialized-io/client-js/blob/main/docs/reference.md) | ||
## 📄 More resources | ||
@@ -154,2 +171,3 @@ | ||
Encountering an issue? Don't feel afraid to add an issue here on Github or to reach out via [Serialized](https://serialized.io). | ||
Encountering an issue? Don't feel afraid to add an issue here on Github or to reach out | ||
via [Serialized](https://serialized.io). |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
168
77141
6
1807
1