-move declaration

This commit is contained in:
Florian Dold 2022-09-16 17:21:54 +02:00
parent d6c545a0ba
commit 16e7814445
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
11 changed files with 61 additions and 72 deletions

View File

@ -45,7 +45,7 @@ import {
Location, Location,
WireInfo, WireInfo,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { RetryInfo } from "./util/retries.js"; import { RetryInfo, RetryTags } from "./util/retries.js";
import { Event, IDBDatabase } from "@gnu-taler/idb-bridge"; import { Event, IDBDatabase } from "@gnu-taler/idb-bridge";
import { DenomInfo } from "./internal-wallet-state.js"; import { DenomInfo } from "./internal-wallet-state.js";
@ -1719,6 +1719,8 @@ export interface OperationRetryRecord {
/** /**
* Unique identifier for the operation. Typically of * Unique identifier for the operation. Typically of
* the format `${opType}-${opUniqueKey}` * the format `${opType}-${opUniqueKey}`
*
* @see {@link RetryTags}
*/ */
id: string; id: string;
@ -1727,48 +1729,6 @@ export interface OperationRetryRecord {
retryInfo: RetryInfo; retryInfo: RetryInfo;
} }
export enum OperationAttemptResultType {
Finished = "finished",
Pending = "pending",
Error = "error",
Longpoll = "longpoll",
}
// FIXME: not part of DB!
export type OperationAttemptResult<TSuccess = unknown, TPending = unknown> =
| OperationAttemptFinishedResult<TSuccess>
| OperationAttemptErrorResult
| OperationAttemptLongpollResult
| OperationAttemptPendingResult<TPending>;
export namespace OperationAttemptResult {
export function finishedEmpty(): OperationAttemptResult<unknown, unknown> {
return {
type: OperationAttemptResultType.Finished,
result: undefined,
};
}
}
export interface OperationAttemptFinishedResult<T> {
type: OperationAttemptResultType.Finished;
result: T;
}
export interface OperationAttemptPendingResult<T> {
type: OperationAttemptResultType.Pending;
result: T;
}
export interface OperationAttemptErrorResult {
type: OperationAttemptResultType.Error;
errorDetail: TalerErrorDetail;
}
export interface OperationAttemptLongpollResult {
type: OperationAttemptResultType.Longpoll;
}
/** /**
* Availability of coins of a given denomination (and age restriction!). * Availability of coins of a given denomination (and age restriction!).
* *

View File

@ -74,10 +74,7 @@ import {
BackupProviderStateTag, BackupProviderStateTag,
BackupProviderTerms, BackupProviderTerms,
ConfigRecord, ConfigRecord,
OperationAttemptResult,
OperationAttemptResultType,
WalletBackupConfState, WalletBackupConfState,
WalletStoresV1,
WALLET_BACKUP_STATE_KEY, WALLET_BACKUP_STATE_KEY,
} from "../../db.js"; } from "../../db.js";
import { InternalWalletState } from "../../internal-wallet-state.js"; import { InternalWalletState } from "../../internal-wallet-state.js";
@ -89,9 +86,7 @@ import {
checkDbInvariant, checkDbInvariant,
checkLogicInvariant, checkLogicInvariant,
} from "../../util/invariants.js"; } from "../../util/invariants.js";
import { GetReadWriteAccess } from "../../util/query.js"; import { OperationAttemptResult, OperationAttemptResultType, RetryTags, scheduleRetryInTx } from "../../util/retries.js";
import { RetryInfo, RetryTags, scheduleRetryInTx } from "../../util/retries.js";
import { guardOperationException } from "../common.js";
import { import {
checkPaymentByProposalId, checkPaymentByProposalId,
confirmPay, confirmPay,

View File

@ -47,11 +47,11 @@ import {
import { import {
DenominationRecord, DenominationRecord,
DepositGroupRecord, DepositGroupRecord,
OperationAttemptResult,
OperationStatus, OperationStatus,
} from "../db.js"; } from "../db.js";
import { InternalWalletState } from "../internal-wallet-state.js"; import { InternalWalletState } from "../internal-wallet-state.js";
import { readSuccessResponseJsonOrThrow } from "../util/http.js"; import { readSuccessResponseJsonOrThrow } from "../util/http.js";
import { OperationAttemptResult } from "../util/retries.js";
import { spendCoins } from "../wallet.js"; import { spendCoins } from "../wallet.js";
import { getExchangeDetails } from "./exchanges.js"; import { getExchangeDetails } from "./exchanges.js";
import { import {

View File

@ -68,8 +68,6 @@ import {
CoinRecord, CoinRecord,
CoinStatus, CoinStatus,
DenominationRecord, DenominationRecord,
OperationAttemptResult,
OperationAttemptResultType,
ProposalRecord, ProposalRecord,
ProposalStatus, ProposalStatus,
PurchaseRecord, PurchaseRecord,
@ -99,7 +97,7 @@ import {
throwUnexpectedRequestError, throwUnexpectedRequestError,
} from "../util/http.js"; } from "../util/http.js";
import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js"; import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js";
import { RetryInfo, RetryTags, scheduleRetry } from "../util/retries.js"; import { OperationAttemptResult, OperationAttemptResultType, RetryInfo, RetryTags, scheduleRetry } from "../util/retries.js";
import { spendCoins } from "../wallet.js"; import { spendCoins } from "../wallet.js";
import { getExchangeDetails } from "./exchanges.js"; import { getExchangeDetails } from "./exchanges.js";
import { getTotalRefreshCost } from "./refresh.js"; import { getTotalRefreshCost } from "./refresh.js";

View File

@ -42,8 +42,6 @@ import {
CoinRecord, CoinRecord,
CoinSourceType, CoinSourceType,
CoinStatus, CoinStatus,
OperationAttemptResult,
OperationAttemptResultType,
RecoupGroupRecord, RecoupGroupRecord,
RefreshCoinSource, RefreshCoinSource,
ReserveRecordStatus, ReserveRecordStatus,
@ -54,7 +52,7 @@ import {
import { InternalWalletState } from "../internal-wallet-state.js"; import { InternalWalletState } from "../internal-wallet-state.js";
import { readSuccessResponseJsonOrThrow } from "../util/http.js"; import { readSuccessResponseJsonOrThrow } from "../util/http.js";
import { GetReadWriteAccess } from "../util/query.js"; import { GetReadWriteAccess } from "../util/query.js";
import { RetryInfo, runOperationHandlerForResult } from "../util/retries.js"; import { OperationAttemptResult, RetryInfo, runOperationHandlerForResult } from "../util/retries.js";
import { guardOperationException } from "./common.js"; import { guardOperationException } from "./common.js";
import { createRefreshGroup, processRefreshGroup } from "./refresh.js"; import { createRefreshGroup, processRefreshGroup } from "./refresh.js";
import { internalCreateWithdrawalGroup } from "./withdraw.js"; import { internalCreateWithdrawalGroup } from "./withdraw.js";

View File

@ -57,8 +57,6 @@ import {
CoinSourceType, CoinSourceType,
CoinStatus, CoinStatus,
DenominationRecord, DenominationRecord,
OperationAttemptResult,
OperationAttemptResultType,
OperationStatus, OperationStatus,
RefreshCoinStatus, RefreshCoinStatus,
RefreshGroupRecord, RefreshGroupRecord,
@ -76,7 +74,7 @@ import {
} from "../util/http.js"; } from "../util/http.js";
import { checkDbInvariant } from "../util/invariants.js"; import { checkDbInvariant } from "../util/invariants.js";
import { GetReadWriteAccess } from "../util/query.js"; import { GetReadWriteAccess } from "../util/query.js";
import { RetryInfo, runOperationHandlerForResult } from "../util/retries.js"; import { OperationAttemptResult, OperationAttemptResultType, RetryInfo, runOperationHandlerForResult } from "../util/retries.js";
import { makeCoinAvailable, Wallet } from "../wallet.js"; import { makeCoinAvailable, Wallet } from "../wallet.js";
import { guardOperationException } from "./common.js"; import { guardOperationException } from "./common.js";
import { updateExchangeFromUrl } from "./exchanges.js"; import { updateExchangeFromUrl } from "./exchanges.js";

View File

@ -44,7 +44,6 @@ import {
PrepareRefundResult, PrepareRefundResult,
RefreshReason, RefreshReason,
TalerErrorCode, TalerErrorCode,
TalerErrorDetail,
TalerProtocolTimestamp, TalerProtocolTimestamp,
TransactionType, TransactionType,
URL, URL,
@ -53,7 +52,6 @@ import {
AbortStatus, AbortStatus,
CoinStatus, CoinStatus,
DenominationRecord, DenominationRecord,
OperationAttemptResult,
PurchaseRecord, PurchaseRecord,
RefundReason, RefundReason,
RefundState, RefundState,
@ -63,6 +61,7 @@ import { InternalWalletState } from "../internal-wallet-state.js";
import { readSuccessResponseJsonOrThrow } from "../util/http.js"; import { readSuccessResponseJsonOrThrow } from "../util/http.js";
import { checkDbInvariant } from "../util/invariants.js"; import { checkDbInvariant } from "../util/invariants.js";
import { GetReadWriteAccess } from "../util/query.js"; import { GetReadWriteAccess } from "../util/query.js";
import { OperationAttemptResult } from "../util/retries.js";
import { createRefreshGroup, getTotalRefreshCost } from "./refresh.js"; import { createRefreshGroup, getTotalRefreshCost } from "./refresh.js";
import { makeEventId } from "./transactions.js"; import { makeEventId } from "./transactions.js";

View File

@ -43,8 +43,6 @@ import {
CoinSourceType, CoinSourceType,
CoinStatus, CoinStatus,
DenominationRecord, DenominationRecord,
OperationAttemptResult,
OperationAttemptResultType,
TipRecord, TipRecord,
} from "../db.js"; } from "../db.js";
import { makeErrorDetail } from "../errors.js"; import { makeErrorDetail } from "../errors.js";
@ -54,6 +52,7 @@ import {
readSuccessResponseJsonOrThrow, readSuccessResponseJsonOrThrow,
} from "../util/http.js"; } from "../util/http.js";
import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js"; import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js";
import { OperationAttemptResult, OperationAttemptResultType } from "../util/retries.js";
import { makeCoinAvailable } from "../wallet.js"; import { makeCoinAvailable } from "../wallet.js";
import { updateExchangeFromUrl } from "./exchanges.js"; import { updateExchangeFromUrl } from "./exchanges.js";
import { makeEventId } from "./transactions.js"; import { makeEventId } from "./transactions.js";

View File

@ -69,8 +69,6 @@ import {
DenomSelectionState, DenomSelectionState,
ExchangeDetailsRecord, ExchangeDetailsRecord,
ExchangeRecord, ExchangeRecord,
OperationAttemptResult,
OperationAttemptResultType,
OperationStatus, OperationStatus,
PlanchetRecord, PlanchetRecord,
ReserveRecordStatus, ReserveRecordStatus,
@ -95,6 +93,7 @@ import {
} from "../util/http.js"; } from "../util/http.js";
import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js"; import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js";
import { DbAccess, GetReadOnlyAccess } from "../util/query.js"; import { DbAccess, GetReadOnlyAccess } from "../util/query.js";
import { OperationAttemptResult, OperationAttemptResultType } from "../util/retries.js";
import { import {
WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
WALLET_EXCHANGE_PROTOCOL_VERSION, WALLET_EXCHANGE_PROTOCOL_VERSION,

View File

@ -30,8 +30,6 @@ import {
BackupProviderRecord, BackupProviderRecord,
DepositGroupRecord, DepositGroupRecord,
ExchangeRecord, ExchangeRecord,
OperationAttemptResult,
OperationAttemptResultType,
ProposalRecord, ProposalRecord,
PurchaseRecord, PurchaseRecord,
RecoupGroupRecord, RecoupGroupRecord,
@ -45,6 +43,48 @@ import { InternalWalletState } from "../internal-wallet-state.js";
import { PendingTaskType } from "../pending-types.js"; import { PendingTaskType } from "../pending-types.js";
import { GetReadWriteAccess } from "./query.js"; import { GetReadWriteAccess } from "./query.js";
export enum OperationAttemptResultType {
Finished = "finished",
Pending = "pending",
Error = "error",
Longpoll = "longpoll",
}
// FIXME: not part of DB!
export type OperationAttemptResult<TSuccess = unknown, TPending = unknown> =
| OperationAttemptFinishedResult<TSuccess>
| OperationAttemptErrorResult
| OperationAttemptLongpollResult
| OperationAttemptPendingResult<TPending>;
export namespace OperationAttemptResult {
export function finishedEmpty(): OperationAttemptResult<unknown, unknown> {
return {
type: OperationAttemptResultType.Finished,
result: undefined,
};
}
}
export interface OperationAttemptFinishedResult<T> {
type: OperationAttemptResultType.Finished;
result: T;
}
export interface OperationAttemptPendingResult<T> {
type: OperationAttemptResultType.Pending;
result: T;
}
export interface OperationAttemptErrorResult {
type: OperationAttemptResultType.Error;
errorDetail: TalerErrorDetail;
}
export interface OperationAttemptLongpollResult {
type: OperationAttemptResultType.Longpoll;
}
export interface RetryInfo { export interface RetryInfo {
firstTry: AbsoluteTime; firstTry: AbsoluteTime;
nextRetry: AbsoluteTime; nextRetry: AbsoluteTime;

View File

@ -106,8 +106,6 @@ import {
DenominationRecord, DenominationRecord,
exportDb, exportDb,
importDb, importDb,
OperationAttemptResult,
OperationAttemptResultType,
WalletStoresV1, WalletStoresV1,
} from "./db.js"; } from "./db.js";
import { import {
@ -228,7 +226,12 @@ import {
openPromise, openPromise,
} from "./util/promiseUtils.js"; } from "./util/promiseUtils.js";
import { DbAccess, GetReadWriteAccess } from "./util/query.js"; import { DbAccess, GetReadWriteAccess } from "./util/query.js";
import { RetryInfo, runOperationHandlerForResult } from "./util/retries.js"; import {
OperationAttemptResult,
OperationAttemptResultType,
RetryInfo,
runOperationHandlerForResult,
} from "./util/retries.js";
import { TimerAPI, TimerGroup } from "./util/timer.js"; import { TimerAPI, TimerGroup } from "./util/timer.js";
import { import {
WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
@ -284,7 +287,7 @@ async function callOperationHandler(
ws: InternalWalletState, ws: InternalWalletState,
pending: PendingTaskInfo, pending: PendingTaskInfo,
forceNow = false, forceNow = false,
): Promise<OperationAttemptResult<unknown, unknown>> { ): Promise<OperationAttemptResult> {
switch (pending.type) { switch (pending.type) {
case PendingTaskType.ExchangeUpdate: case PendingTaskType.ExchangeUpdate:
return await updateExchangeFromUrlHandler(ws, pending.exchangeBaseUrl, { return await updateExchangeFromUrlHandler(ws, pending.exchangeBaseUrl, {
@ -1099,7 +1102,7 @@ async function dispatchRequestInternal(
} }
case "getTransactionById": { case "getTransactionById": {
const req = codecForTransactionByIdRequest().decode(payload); const req = codecForTransactionByIdRequest().decode(payload);
return await getTransactionById(ws, req) return await getTransactionById(ws, req);
} }
case "addExchange": { case "addExchange": {
const req = codecForAddExchangeRequest().decode(payload); const req = codecForAddExchangeRequest().decode(payload);