Skip to main content
Skip to main content

IdempotencyKeyService

Constructors

constructor

**new IdempotencyKeyService**(«destructured»)

Parameters

__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
idempotencyKeyRepository_Repository<IdempotencyKey>Required
manager_EntityManagerRequired
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Methods

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

TResultobjectRequired
TErrorobjectRequired

Parameters

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

create

**create**(payload): Promise&#60;[IdempotencyKey](/references/services/classes/IdempotencyKey)&#62;

Creates an idempotency key for a request. If no idempotency key is provided in request, we will create a unique identifier.

Parameters

payload of request to create idempotency key for

Returns

Promise<IdempotencyKey>

PromisePromise<IdempotencyKey>Required
the created idempotency key

initializeRequest

**initializeRequest**(headerKey, reqMethod, reqParams, reqPath): Promise&#60;[IdempotencyKey](/references/services/classes/IdempotencyKey)&#62;

Execute the initial steps in a idempotent request.

Parameters

headerKeystringRequired
potential idempotency key from header
reqMethodstringRequired
method of request
reqParamsRecord<string, unknown>Required
params of request
reqPathstringRequired
path of request

Returns

Promise<IdempotencyKey>

PromisePromise<IdempotencyKey>Required
the existing or created idempotency key

lock

**lock**(idempotencyKey): Promise&#60;[IdempotencyKey](/references/services/classes/IdempotencyKey)&#62;

Locks an idempotency.

Parameters

idempotencyKeystringRequired
key to lock

Returns

Promise<IdempotencyKey>

PromisePromise<IdempotencyKey>Required
result of the update operation

retrieve

**retrieve**(idempotencyKeyOrSelector): Promise&#60;[IdempotencyKey](/references/services/classes/IdempotencyKey)&#62;

Retrieves an idempotency key

Parameters

idempotencyKeyOrSelectorstring | Selector<IdempotencyKey>Required
key or selector to retrieve

Returns

Promise<IdempotencyKey>

PromisePromise<IdempotencyKey>Required
idempotency key

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

errRecord<string, unknown> | { code: string }Required

Returns

boolean

booleanboolean

update

**update**(idempotencyKey, update): Promise&#60;[IdempotencyKey](/references/services/classes/IdempotencyKey)&#62;

Locks an idempotency.

Parameters

idempotencyKeystringRequired
key to update
updateDeepPartial<IdempotencyKey>Required
update object

Returns

Promise<IdempotencyKey>

PromisePromise<IdempotencyKey>Required
result of the update operation

withTransaction

**withTransaction**(transactionManager?): [IdempotencyKeyService](/references/services/classes/IdempotencyKeyService)

Parameters

transactionManagerEntityManager

Returns

IdempotencyKeyService

IdempotencyKeyServiceIdempotencyKeyServiceRequired

workStage

**workStage**(idempotencyKey, callback): Promise&#60;[IdempotencyKey](/references/services/classes/IdempotencyKey)&#62;

Performs an atomic work stage. An atomic work stage contains some related functionality, that needs to be transactionally executed in isolation. An idempotent request will always consist of 2 or more of these phases. The required phases are "started" and "finished".

Parameters

idempotencyKeystringRequired
current idempotency key
callback(transactionManager: EntityManager) => Promise<IdempotencyCallbackResult>Required
functionality to execute within the phase

Returns

Promise<IdempotencyKey>

PromisePromise<IdempotencyKey>Required
new updated idempotency key
Was this section helpful?