rename for consistency

This commit is contained in:
Florian Dold 2020-08-12 16:02:58 +05:30
parent 56f5a1e3ab
commit 8d7b171d02
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
14 changed files with 356 additions and 351 deletions

View File

@ -35,7 +35,7 @@ import {
AmountJson, AmountJson,
Amounts, Amounts,
Codec, Codec,
makeCodecForObject, buildCodecForObject,
codecForString, codecForString,
Duration, Duration,
CoreApiResponse, CoreApiResponse,
@ -627,9 +627,9 @@ export interface WithdrawalOperationInfo {
} }
const codecForWithdrawalOperationInfo = (): Codec<WithdrawalOperationInfo> => const codecForWithdrawalOperationInfo = (): Codec<WithdrawalOperationInfo> =>
makeCodecForObject<WithdrawalOperationInfo>() buildCodecForObject<WithdrawalOperationInfo>()
.property("withdrawal_id", codecForString) .property("withdrawal_id", codecForString())
.property("taler_withdraw_uri", codecForString) .property("taler_withdraw_uri", codecForString())
.build("WithdrawalOperationInfo"); .build("WithdrawalOperationInfo");
export const defaultCoinConfig = [ export const defaultCoinConfig = [

View File

@ -28,19 +28,20 @@ import {
ContractTerms, ContractTerms,
Duration, Duration,
Codec, Codec,
makeCodecForObject, buildCodecForObject,
codecForString, codecForString,
makeCodecOptional, codecOptional,
makeCodecForConstString, codecForConstString,
codecForBoolean, codecForBoolean,
codecForNumber, codecForNumber,
codecForContractTerms, codecForContractTerms,
codecForAny, codecForAny,
makeCodecForUnion, buildCodecForUnion,
AmountString, AmountString,
Timestamp, Timestamp,
CoinPublicKeyString, CoinPublicKeyString,
} from "taler-wallet-core"; } from "taler-wallet-core";
import { codecForAmountString } from "taler-wallet-core/lib/util/amounts";
export interface PostOrderRequest { export interface PostOrderRequest {
// The order must at least contain the minimal // The order must at least contain the minimal
@ -72,43 +73,43 @@ export interface PostOrderResponse {
} }
export const codecForPostOrderResponse = (): Codec<PostOrderResponse> => export const codecForPostOrderResponse = (): Codec<PostOrderResponse> =>
makeCodecForObject<PostOrderResponse>() buildCodecForObject<PostOrderResponse>()
.property("order_id", codecForString) .property("order_id", codecForString())
.property("token", makeCodecOptional(codecForString)) .property("token", codecOptional(codecForString()))
.build("PostOrderResponse"); .build("PostOrderResponse");
export const codecForCheckPaymentPaidResponse = (): Codec< export const codecForCheckPaymentPaidResponse = (): Codec<
CheckPaymentPaidResponse CheckPaymentPaidResponse
> => > =>
makeCodecForObject<CheckPaymentPaidResponse>() buildCodecForObject<CheckPaymentPaidResponse>()
.property("order_status", makeCodecForConstString("paid")) .property("order_status", codecForConstString("paid"))
.property("refunded", codecForBoolean) .property("refunded", codecForBoolean)
.property("wired", codecForBoolean) .property("wired", codecForBoolean)
.property("deposit_total", codecForString) .property("deposit_total", codecForAmountString())
.property("exchange_ec", codecForNumber) .property("exchange_ec", codecForNumber())
.property("exchange_hc", codecForNumber) .property("exchange_hc", codecForNumber())
.property("refund_amount", codecForString) .property("refund_amount", codecForAmountString())
.property("contract_terms", codecForContractTerms()) .property("contract_terms", codecForContractTerms())
// FIXME: specify // FIXME: specify
.property("wire_details", codecForAny) .property("wire_details", codecForAny())
.property("wire_reports", codecForAny) .property("wire_reports", codecForAny())
.property("refund_details", codecForAny) .property("refund_details", codecForAny())
.build("CheckPaymentPaidResponse"); .build("CheckPaymentPaidResponse");
export const codecForCheckPaymentUnpaidResponse = (): Codec< export const codecForCheckPaymentUnpaidResponse = (): Codec<
CheckPaymentUnpaidResponse CheckPaymentUnpaidResponse
> => > =>
makeCodecForObject<CheckPaymentUnpaidResponse>() buildCodecForObject<CheckPaymentUnpaidResponse>()
.property("order_status", makeCodecForConstString("unpaid")) .property("order_status", codecForConstString("unpaid"))
.property("taler_pay_uri", codecForString) .property("taler_pay_uri", codecForString())
.property("order_status_url", codecForString) .property("order_status_url", codecForString())
.property("already_paid_order_id", makeCodecOptional(codecForString)) .property("already_paid_order_id", codecOptional(codecForString()))
.build("CheckPaymentPaidResponse"); .build("CheckPaymentPaidResponse");
export const codecForMerchantOrderPrivateStatusResponse = (): Codec< export const codecForMerchantOrderPrivateStatusResponse = (): Codec<
MerchantOrderPrivateStatusResponse MerchantOrderPrivateStatusResponse
> => > =>
makeCodecForUnion<MerchantOrderPrivateStatusResponse>() buildCodecForUnion<MerchantOrderPrivateStatusResponse>()
.discriminateOn("order_status") .discriminateOn("order_status")
.alternative("paid", codecForCheckPaymentPaidResponse()) .alternative("paid", codecForCheckPaymentPaidResponse())
.alternative("unpaid", codecForCheckPaymentUnpaidResponse()) .alternative("unpaid", codecForCheckPaymentUnpaidResponse())

View File

@ -31,7 +31,7 @@ import {
TalerUriType, TalerUriType,
decodeCrock, decodeCrock,
addPaytoQueryParams, addPaytoQueryParams,
makeCodecForList, codecForList,
codecForString, codecForString,
printTestVectors, printTestVectors,
} from "taler-wallet-core"; } from "taler-wallet-core";
@ -548,7 +548,7 @@ advancedCli
}); });
}); });
const coinPubListCodec = makeCodecForList(codecForString); const coinPubListCodec = codecForList(codecForString());
advancedCli advancedCli
.subcommand("suspendCoins", "suspend-coins", { .subcommand("suspendCoins", "suspend-coins", {

View File

@ -112,7 +112,7 @@ async function createBankWithdrawalUri(
}, },
}, },
); );
const respJson = await readSuccessResponseJsonOrThrow(resp, codecForAny); const respJson = await readSuccessResponseJsonOrThrow(resp, codecForAny());
return respJson; return respJson;
} }
@ -135,7 +135,7 @@ async function confirmBankWithdrawalUri(
}, },
}, },
); );
await readSuccessResponseJsonOrThrow(resp, codecForAny); await readSuccessResponseJsonOrThrow(resp, codecForAny());
return; return;
} }

View File

@ -37,7 +37,6 @@ import {
PaymentShortInfo, PaymentShortInfo,
} from "../types/transactions"; } from "../types/transactions";
import { getFundingPaytoUris } from "./reserves"; import { getFundingPaytoUris } from "./reserves";
import { ResultLevel } from "idb-bridge";
/** /**
* Create an event ID from the type and the primary key for the event. * Create an event ID from the type and the primary key for the event.

View File

@ -23,8 +23,8 @@
*/ */
import { import {
codecForString, codecForString,
makeCodecForObject, buildCodecForObject,
makeCodecForList, codecForList,
Codec, Codec,
} from "../util/codec"; } from "../util/codec";
import { AmountString } from "./talerTypes"; import { AmountString } from "./talerTypes";
@ -51,7 +51,7 @@ export interface ReserveStatus {
} }
export const codecForReserveStatus = (): Codec<ReserveStatus> => export const codecForReserveStatus = (): Codec<ReserveStatus> =>
makeCodecForObject<ReserveStatus>() buildCodecForObject<ReserveStatus>()
.property("balance", codecForString) .property("balance", codecForString())
.property("history", makeCodecForList(codecForReserveTransaction())) .property("history", codecForList(codecForReserveTransaction()))
.build("ReserveStatus"); .build("ReserveStatus");

View File

@ -23,9 +23,9 @@
*/ */
import { import {
codecForString, codecForString,
makeCodecForObject, buildCodecForObject,
makeCodecForConstString, codecForConstString,
makeCodecForUnion, buildCodecForUnion,
Codec, Codec,
} from "../util/codec"; } from "../util/codec";
import { import {
@ -182,54 +182,54 @@ export type ReserveTransaction =
export const codecForReserveWithdrawTransaction = (): Codec< export const codecForReserveWithdrawTransaction = (): Codec<
ReserveWithdrawTransaction ReserveWithdrawTransaction
> => > =>
makeCodecForObject<ReserveWithdrawTransaction>() buildCodecForObject<ReserveWithdrawTransaction>()
.property("amount", codecForString) .property("amount", codecForString())
.property("h_coin_envelope", codecForString) .property("h_coin_envelope", codecForString())
.property("h_denom_pub", codecForString) .property("h_denom_pub", codecForString())
.property("reserve_sig", codecForString) .property("reserve_sig", codecForString())
.property("type", makeCodecForConstString(ReserveTransactionType.Withdraw)) .property("type", codecForConstString(ReserveTransactionType.Withdraw))
.property("withdraw_fee", codecForString) .property("withdraw_fee", codecForString())
.build("ReserveWithdrawTransaction"); .build("ReserveWithdrawTransaction");
export const codecForReserveCreditTransaction = (): Codec< export const codecForReserveCreditTransaction = (): Codec<
ReserveCreditTransaction ReserveCreditTransaction
> => > =>
makeCodecForObject<ReserveCreditTransaction>() buildCodecForObject<ReserveCreditTransaction>()
.property("amount", codecForString) .property("amount", codecForString())
.property("sender_account_url", codecForString) .property("sender_account_url", codecForString())
.property("timestamp", codecForTimestamp) .property("timestamp", codecForTimestamp)
.property("wire_reference", codecForString) .property("wire_reference", codecForString())
.property("type", makeCodecForConstString(ReserveTransactionType.Credit)) .property("type", codecForConstString(ReserveTransactionType.Credit))
.build("ReserveCreditTransaction"); .build("ReserveCreditTransaction");
export const codecForReserveClosingTransaction = (): Codec< export const codecForReserveClosingTransaction = (): Codec<
ReserveClosingTransaction ReserveClosingTransaction
> => > =>
makeCodecForObject<ReserveClosingTransaction>() buildCodecForObject<ReserveClosingTransaction>()
.property("amount", codecForString) .property("amount", codecForString())
.property("closing_fee", codecForString) .property("closing_fee", codecForString())
.property("exchange_pub", codecForString) .property("exchange_pub", codecForString())
.property("exchange_sig", codecForString) .property("exchange_sig", codecForString())
.property("h_wire", codecForString) .property("h_wire", codecForString())
.property("timestamp", codecForTimestamp) .property("timestamp", codecForTimestamp)
.property("type", makeCodecForConstString(ReserveTransactionType.Closing)) .property("type", codecForConstString(ReserveTransactionType.Closing))
.property("wtid", codecForString) .property("wtid", codecForString())
.build("ReserveClosingTransaction"); .build("ReserveClosingTransaction");
export const codecForReserveRecoupTransaction = (): Codec< export const codecForReserveRecoupTransaction = (): Codec<
ReserveRecoupTransaction ReserveRecoupTransaction
> => > =>
makeCodecForObject<ReserveRecoupTransaction>() buildCodecForObject<ReserveRecoupTransaction>()
.property("amount", codecForString) .property("amount", codecForString())
.property("coin_pub", codecForString) .property("coin_pub", codecForString())
.property("exchange_pub", codecForString) .property("exchange_pub", codecForString())
.property("exchange_sig", codecForString) .property("exchange_sig", codecForString())
.property("timestamp", codecForTimestamp) .property("timestamp", codecForTimestamp)
.property("type", makeCodecForConstString(ReserveTransactionType.Recoup)) .property("type", codecForConstString(ReserveTransactionType.Recoup))
.build("ReserveRecoupTransaction"); .build("ReserveRecoupTransaction");
export const codecForReserveTransaction = (): Codec<ReserveTransaction> => export const codecForReserveTransaction = (): Codec<ReserveTransaction> =>
makeCodecForUnion<ReserveTransaction>() buildCodecForUnion<ReserveTransaction>()
.discriminateOn("type") .discriminateOn("type")
.alternative( .alternative(
ReserveTransactionType.Withdraw, ReserveTransactionType.Withdraw,

View File

@ -28,18 +28,18 @@
*/ */
import { import {
makeCodecForObject, buildCodecForObject,
codecForString, codecForString,
makeCodecForList, codecForList,
makeCodecOptional, codecOptional,
codecForAny, codecForAny,
codecForNumber, codecForNumber,
codecForBoolean, codecForBoolean,
makeCodecForMap, codecForMap,
Codec, Codec,
makeCodecForConstNumber, codecForConstNumber,
makeCodecForUnion, buildCodecForUnion,
makeCodecForConstString, codecForConstString,
} from "../util/codec"; } from "../util/codec";
import { import {
Timestamp, Timestamp,
@ -48,6 +48,7 @@ import {
codecForDuration, codecForDuration,
} from "../util/time"; } from "../util/time";
import { ExchangeListItem } from "./walletTypes"; import { ExchangeListItem } from "./walletTypes";
import { codecForAmountString } from "../util/amounts";
/** /**
* Denomination as found in the /keys response from the exchange. * Denomination as found in the /keys response from the exchange.
@ -951,7 +952,7 @@ export interface BankWithdrawalOperationPostResponse {
export const codecForBankWithdrawalOperationPostResponse = (): Codec< export const codecForBankWithdrawalOperationPostResponse = (): Codec<
BankWithdrawalOperationPostResponse BankWithdrawalOperationPostResponse
> => > =>
makeCodecForObject<BankWithdrawalOperationPostResponse>() buildCodecForObject<BankWithdrawalOperationPostResponse>()
.property("transfer_done", codecForBoolean) .property("transfer_done", codecForBoolean)
.build("BankWithdrawalOperationPostResponse"); .build("BankWithdrawalOperationPostResponse");
@ -962,292 +963,292 @@ export type EddsaPublicKeyString = string;
export type CoinPublicKeyString = string; export type CoinPublicKeyString = string;
export const codecForDenomination = (): Codec<Denomination> => export const codecForDenomination = (): Codec<Denomination> =>
makeCodecForObject<Denomination>() buildCodecForObject<Denomination>()
.property("value", codecForString) .property("value", codecForString())
.property("denom_pub", codecForString) .property("denom_pub", codecForString())
.property("fee_withdraw", codecForString) .property("fee_withdraw", codecForString())
.property("fee_deposit", codecForString) .property("fee_deposit", codecForString())
.property("fee_refresh", codecForString) .property("fee_refresh", codecForString())
.property("fee_refund", codecForString) .property("fee_refund", codecForString())
.property("stamp_start", codecForTimestamp) .property("stamp_start", codecForTimestamp)
.property("stamp_expire_withdraw", codecForTimestamp) .property("stamp_expire_withdraw", codecForTimestamp)
.property("stamp_expire_legal", codecForTimestamp) .property("stamp_expire_legal", codecForTimestamp)
.property("stamp_expire_deposit", codecForTimestamp) .property("stamp_expire_deposit", codecForTimestamp)
.property("master_sig", codecForString) .property("master_sig", codecForString())
.build("Denomination"); .build("Denomination");
export const codecForAuditorDenomSig = (): Codec<AuditorDenomSig> => export const codecForAuditorDenomSig = (): Codec<AuditorDenomSig> =>
makeCodecForObject<AuditorDenomSig>() buildCodecForObject<AuditorDenomSig>()
.property("denom_pub_h", codecForString) .property("denom_pub_h", codecForString())
.property("auditor_sig", codecForString) .property("auditor_sig", codecForString())
.build("AuditorDenomSig"); .build("AuditorDenomSig");
export const codecForAuditor = (): Codec<Auditor> => export const codecForAuditor = (): Codec<Auditor> =>
makeCodecForObject<Auditor>() buildCodecForObject<Auditor>()
.property("auditor_pub", codecForString) .property("auditor_pub", codecForString())
.property("auditor_url", codecForString) .property("auditor_url", codecForString())
.property("denomination_keys", makeCodecForList(codecForAuditorDenomSig())) .property("denomination_keys", codecForList(codecForAuditorDenomSig()))
.build("Auditor"); .build("Auditor");
export const codecForExchangeHandle = (): Codec<ExchangeHandle> => export const codecForExchangeHandle = (): Codec<ExchangeHandle> =>
makeCodecForObject<ExchangeHandle>() buildCodecForObject<ExchangeHandle>()
.property("master_pub", codecForString) .property("master_pub", codecForString())
.property("url", codecForString) .property("url", codecForString())
.build("ExchangeHandle"); .build("ExchangeHandle");
export const codecForAuditorHandle = (): Codec<AuditorHandle> => export const codecForAuditorHandle = (): Codec<AuditorHandle> =>
makeCodecForObject<AuditorHandle>() buildCodecForObject<AuditorHandle>()
.property("name", codecForString) .property("name", codecForString())
.property("master_pub", codecForString) .property("master_pub", codecForString())
.property("url", codecForString) .property("url", codecForString())
.build("AuditorHandle"); .build("AuditorHandle");
export const codecForMerchantInfo = (): Codec<MerchantInfo> => export const codecForMerchantInfo = (): Codec<MerchantInfo> =>
makeCodecForObject<MerchantInfo>() buildCodecForObject<MerchantInfo>()
.property("name", codecForString) .property("name", codecForString())
.property("address", makeCodecOptional(codecForString)) .property("address", codecOptional(codecForString()))
.property("jurisdiction", makeCodecOptional(codecForString)) .property("jurisdiction", codecOptional(codecForString()))
.build("MerchantInfo"); .build("MerchantInfo");
export const codecForTax = (): Codec<Tax> => export const codecForTax = (): Codec<Tax> =>
makeCodecForObject<Tax>() buildCodecForObject<Tax>()
.property("name", codecForString) .property("name", codecForString())
.property("tax", codecForString) .property("tax", codecForString())
.build("Tax"); .build("Tax");
export const codecForI18n = (): Codec<{ [lang_tag: string]: string }> => export const codecForI18n = (): Codec<{ [lang_tag: string]: string }> =>
makeCodecForMap(codecForString); codecForMap(codecForString());
export const codecForProduct = (): Codec<Product> => export const codecForProduct = (): Codec<Product> =>
makeCodecForObject<Product>() buildCodecForObject<Product>()
.property("product_id", makeCodecOptional(codecForString)) .property("product_id", codecOptional(codecForString()))
.property("description", codecForString) .property("description", codecForString())
.property("description_i18n", makeCodecOptional(codecForI18n())) .property("description_i18n", codecOptional(codecForI18n()))
.property("quantity", makeCodecOptional(codecForNumber)) .property("quantity", codecOptional(codecForNumber()))
.property("unit", makeCodecOptional(codecForString)) .property("unit", codecOptional(codecForString()))
.property("price", makeCodecOptional(codecForString)) .property("price", codecOptional(codecForString()))
.property("delivery_date", makeCodecOptional(codecForTimestamp)) .property("delivery_date", codecOptional(codecForTimestamp))
.property("delivery_location", makeCodecOptional(codecForString)) .property("delivery_location", codecOptional(codecForString()))
.build("Tax"); .build("Tax");
export const codecForContractTerms = (): Codec<ContractTerms> => export const codecForContractTerms = (): Codec<ContractTerms> =>
makeCodecForObject<ContractTerms>() buildCodecForObject<ContractTerms>()
.property("order_id", codecForString) .property("order_id", codecForString())
.property("fulfillment_url", codecForString) .property("fulfillment_url", codecForString())
.property("merchant_base_url", codecForString) .property("merchant_base_url", codecForString())
.property("h_wire", codecForString) .property("h_wire", codecForString())
.property("auto_refund", makeCodecOptional(codecForDuration)) .property("auto_refund", codecOptional(codecForDuration))
.property("wire_method", codecForString) .property("wire_method", codecForString())
.property("summary", codecForString) .property("summary", codecForString())
.property("summary_i18n", makeCodecOptional(codecForI18n())) .property("summary_i18n", codecOptional(codecForI18n()))
.property("nonce", codecForString) .property("nonce", codecForString())
.property("amount", codecForString) .property("amount", codecForString())
.property("auditors", makeCodecForList(codecForAuditorHandle())) .property("auditors", codecForList(codecForAuditorHandle()))
.property("pay_deadline", codecForTimestamp) .property("pay_deadline", codecForTimestamp)
.property("refund_deadline", codecForTimestamp) .property("refund_deadline", codecForTimestamp)
.property("wire_transfer_deadline", codecForTimestamp) .property("wire_transfer_deadline", codecForTimestamp)
.property("timestamp", codecForTimestamp) .property("timestamp", codecForTimestamp)
.property("locations", codecForAny) .property("locations", codecForAny())
.property("max_fee", codecForString) .property("max_fee", codecForString())
.property("max_wire_fee", makeCodecOptional(codecForString)) .property("max_wire_fee", codecOptional(codecForString()))
.property("merchant", codecForMerchantInfo()) .property("merchant", codecForMerchantInfo())
.property("merchant_pub", codecForString) .property("merchant_pub", codecForString())
.property("exchanges", makeCodecForList(codecForExchangeHandle())) .property("exchanges", codecForList(codecForExchangeHandle()))
.property( .property(
"products", "products",
makeCodecOptional(makeCodecForList(codecForProduct())), codecOptional(codecForList(codecForProduct())),
) )
.property("extra", codecForAny) .property("extra", codecForAny())
.build("ContractTerms"); .build("ContractTerms");
export const codecForMerchantRefundPermission = (): Codec< export const codecForMerchantRefundPermission = (): Codec<
MerchantAbortPayRefundDetails MerchantAbortPayRefundDetails
> => > =>
makeCodecForObject<MerchantAbortPayRefundDetails>() buildCodecForObject<MerchantAbortPayRefundDetails>()
.property("refund_amount", codecForString) .property("refund_amount", codecForAmountString())
.property("refund_fee", codecForString) .property("refund_fee", codecForAmountString())
.property("coin_pub", codecForString) .property("coin_pub", codecForString())
.property("rtransaction_id", codecForNumber) .property("rtransaction_id", codecForNumber())
.property("exchange_http_status", codecForNumber) .property("exchange_http_status", codecForNumber())
.property("exchange_code", makeCodecOptional(codecForNumber)) .property("exchange_code", codecOptional(codecForNumber()))
.property("exchange_reply", makeCodecOptional(codecForAny)) .property("exchange_reply", codecOptional(codecForAny()))
.property("exchange_sig", makeCodecOptional(codecForString)) .property("exchange_sig", codecOptional(codecForString()))
.property("exchange_pub", makeCodecOptional(codecForString)) .property("exchange_pub", codecOptional(codecForString()))
.build("MerchantRefundPermission"); .build("MerchantRefundPermission");
export const codecForMerchantRefundResponse = (): Codec< export const codecForMerchantRefundResponse = (): Codec<
MerchantRefundResponse MerchantRefundResponse
> => > =>
makeCodecForObject<MerchantRefundResponse>() buildCodecForObject<MerchantRefundResponse>()
.property("merchant_pub", codecForString) .property("merchant_pub", codecForString())
.property("h_contract_terms", codecForString) .property("h_contract_terms", codecForString())
.property("refunds", makeCodecForList(codecForMerchantRefundPermission())) .property("refunds", codecForList(codecForMerchantRefundPermission()))
.build("MerchantRefundResponse"); .build("MerchantRefundResponse");
export const codecForReserveSigSingleton = (): Codec<ReserveSigSingleton> => export const codecForReserveSigSingleton = (): Codec<ReserveSigSingleton> =>
makeCodecForObject<ReserveSigSingleton>() buildCodecForObject<ReserveSigSingleton>()
.property("reserve_sig", codecForString) .property("reserve_sig", codecForString())
.build("ReserveSigSingleton"); .build("ReserveSigSingleton");
export const codecForTipResponse = (): Codec<TipResponse> => export const codecForTipResponse = (): Codec<TipResponse> =>
makeCodecForObject<TipResponse>() buildCodecForObject<TipResponse>()
.property("reserve_pub", codecForString) .property("reserve_pub", codecForString())
.property("reserve_sigs", makeCodecForList(codecForReserveSigSingleton())) .property("reserve_sigs", codecForList(codecForReserveSigSingleton()))
.build("TipResponse"); .build("TipResponse");
export const codecForRecoup = (): Codec<Recoup> => export const codecForRecoup = (): Codec<Recoup> =>
makeCodecForObject<Recoup>() buildCodecForObject<Recoup>()
.property("h_denom_pub", codecForString) .property("h_denom_pub", codecForString())
.build("Recoup"); .build("Recoup");
export const codecForExchangeSigningKey = (): Codec<ExchangeSignKeyJson> => export const codecForExchangeSigningKey = (): Codec<ExchangeSignKeyJson> =>
makeCodecForObject<ExchangeSignKeyJson>() buildCodecForObject<ExchangeSignKeyJson>()
.property("key", codecForString) .property("key", codecForString())
.property("master_sig", codecForString) .property("master_sig", codecForString())
.property("stamp_end", codecForTimestamp) .property("stamp_end", codecForTimestamp)
.property("stamp_start", codecForTimestamp) .property("stamp_start", codecForTimestamp)
.property("stamp_expire", codecForTimestamp) .property("stamp_expire", codecForTimestamp)
.build("ExchangeSignKeyJson"); .build("ExchangeSignKeyJson");
export const codecForExchangeKeysJson = (): Codec<ExchangeKeysJson> => export const codecForExchangeKeysJson = (): Codec<ExchangeKeysJson> =>
makeCodecForObject<ExchangeKeysJson>() buildCodecForObject<ExchangeKeysJson>()
.property("denoms", makeCodecForList(codecForDenomination())) .property("denoms", codecForList(codecForDenomination()))
.property("master_public_key", codecForString) .property("master_public_key", codecForString())
.property("auditors", makeCodecForList(codecForAuditor())) .property("auditors", codecForList(codecForAuditor()))
.property("list_issue_date", codecForTimestamp) .property("list_issue_date", codecForTimestamp)
.property("recoup", makeCodecOptional(makeCodecForList(codecForRecoup()))) .property("recoup", codecOptional(codecForList(codecForRecoup())))
.property("signkeys", makeCodecForList(codecForExchangeSigningKey())) .property("signkeys", codecForList(codecForExchangeSigningKey()))
.property("version", codecForString) .property("version", codecForString())
.build("KeysJson"); .build("KeysJson");
export const codecForWireFeesJson = (): Codec<WireFeesJson> => export const codecForWireFeesJson = (): Codec<WireFeesJson> =>
makeCodecForObject<WireFeesJson>() buildCodecForObject<WireFeesJson>()
.property("wire_fee", codecForString) .property("wire_fee", codecForString())
.property("closing_fee", codecForString) .property("closing_fee", codecForString())
.property("sig", codecForString) .property("sig", codecForString())
.property("start_date", codecForTimestamp) .property("start_date", codecForTimestamp)
.property("end_date", codecForTimestamp) .property("end_date", codecForTimestamp)
.build("WireFeesJson"); .build("WireFeesJson");
export const codecForAccountInfo = (): Codec<AccountInfo> => export const codecForAccountInfo = (): Codec<AccountInfo> =>
makeCodecForObject<AccountInfo>() buildCodecForObject<AccountInfo>()
.property("payto_uri", codecForString) .property("payto_uri", codecForString())
.property("master_sig", codecForString) .property("master_sig", codecForString())
.build("AccountInfo"); .build("AccountInfo");
export const codecForExchangeWireJson = (): Codec<ExchangeWireJson> => export const codecForExchangeWireJson = (): Codec<ExchangeWireJson> =>
makeCodecForObject<ExchangeWireJson>() buildCodecForObject<ExchangeWireJson>()
.property("accounts", makeCodecForList(codecForAccountInfo())) .property("accounts", codecForList(codecForAccountInfo()))
.property("fees", makeCodecForMap(makeCodecForList(codecForWireFeesJson()))) .property("fees", codecForMap(codecForList(codecForWireFeesJson())))
.build("ExchangeWireJson"); .build("ExchangeWireJson");
export const codecForProposal = (): Codec<Proposal> => export const codecForProposal = (): Codec<Proposal> =>
makeCodecForObject<Proposal>() buildCodecForObject<Proposal>()
.property("contract_terms", codecForAny) .property("contract_terms", codecForAny())
.property("sig", codecForString) .property("sig", codecForString())
.build("Proposal"); .build("Proposal");
export const codecForCheckPaymentResponse = (): Codec<CheckPaymentResponse> => export const codecForCheckPaymentResponse = (): Codec<CheckPaymentResponse> =>
makeCodecForObject<CheckPaymentResponse>() buildCodecForObject<CheckPaymentResponse>()
.property("order_status", codecForString) .property("order_status", codecForString())
.property("refunded", makeCodecOptional(codecForBoolean)) .property("refunded", codecOptional(codecForBoolean))
.property("refunded_amount", makeCodecOptional(codecForString)) .property("refunded_amount", codecOptional(codecForString()))
.property("contract_terms", makeCodecOptional(codecForAny)) .property("contract_terms", codecOptional(codecForAny()))
.property("taler_pay_uri", makeCodecOptional(codecForString)) .property("taler_pay_uri", codecOptional(codecForString()))
.property("contract_url", makeCodecOptional(codecForString)) .property("contract_url", codecOptional(codecForString()))
.build("CheckPaymentResponse"); .build("CheckPaymentResponse");
export const codecForWithdrawOperationStatusResponse = (): Codec< export const codecForWithdrawOperationStatusResponse = (): Codec<
WithdrawOperationStatusResponse WithdrawOperationStatusResponse
> => > =>
makeCodecForObject<WithdrawOperationStatusResponse>() buildCodecForObject<WithdrawOperationStatusResponse>()
.property("selection_done", codecForBoolean) .property("selection_done", codecForBoolean)
.property("transfer_done", codecForBoolean) .property("transfer_done", codecForBoolean)
.property("amount", codecForString) .property("amount", codecForString())
.property("sender_wire", makeCodecOptional(codecForString)) .property("sender_wire", codecOptional(codecForString()))
.property("suggested_exchange", makeCodecOptional(codecForString)) .property("suggested_exchange", codecOptional(codecForString()))
.property("confirm_transfer_url", makeCodecOptional(codecForString)) .property("confirm_transfer_url", codecOptional(codecForString()))
.property("wire_types", makeCodecForList(codecForString)) .property("wire_types", codecForList(codecForString()))
.build("WithdrawOperationStatusResponse"); .build("WithdrawOperationStatusResponse");
export const codecForTipPickupGetResponse = (): Codec<TipPickupGetResponse> => export const codecForTipPickupGetResponse = (): Codec<TipPickupGetResponse> =>
makeCodecForObject<TipPickupGetResponse>() buildCodecForObject<TipPickupGetResponse>()
.property("extra", codecForAny) .property("extra", codecForAny())
.property("amount", codecForString) .property("amount", codecForString())
.property("amount_left", codecForString) .property("amount_left", codecForString())
.property("exchange_url", codecForString) .property("exchange_url", codecForString())
.property("stamp_expire", codecForTimestamp) .property("stamp_expire", codecForTimestamp)
.property("stamp_created", codecForTimestamp) .property("stamp_created", codecForTimestamp)
.build("TipPickupGetResponse"); .build("TipPickupGetResponse");
export const codecForRecoupConfirmation = (): Codec<RecoupConfirmation> => export const codecForRecoupConfirmation = (): Codec<RecoupConfirmation> =>
makeCodecForObject<RecoupConfirmation>() buildCodecForObject<RecoupConfirmation>()
.property("reserve_pub", makeCodecOptional(codecForString)) .property("reserve_pub", codecOptional(codecForString()))
.property("old_coin_pub", makeCodecOptional(codecForString)) .property("old_coin_pub", codecOptional(codecForString()))
.build("RecoupConfirmation"); .build("RecoupConfirmation");
export const codecForWithdrawResponse = (): Codec<WithdrawResponse> => export const codecForWithdrawResponse = (): Codec<WithdrawResponse> =>
makeCodecForObject<WithdrawResponse>() buildCodecForObject<WithdrawResponse>()
.property("ev_sig", codecForString) .property("ev_sig", codecForString())
.build("WithdrawResponse"); .build("WithdrawResponse");
export const codecForMerchantPayResponse = (): Codec<MerchantPayResponse> => export const codecForMerchantPayResponse = (): Codec<MerchantPayResponse> =>
makeCodecForObject<MerchantPayResponse>() buildCodecForObject<MerchantPayResponse>()
.property("sig", codecForString) .property("sig", codecForString())
.build("MerchantPayResponse"); .build("MerchantPayResponse");
export const codecForExchangeMeltResponse = (): Codec<ExchangeMeltResponse> => export const codecForExchangeMeltResponse = (): Codec<ExchangeMeltResponse> =>
makeCodecForObject<ExchangeMeltResponse>() buildCodecForObject<ExchangeMeltResponse>()
.property("exchange_pub", codecForString) .property("exchange_pub", codecForString())
.property("exchange_sig", codecForString) .property("exchange_sig", codecForString())
.property("noreveal_index", codecForNumber) .property("noreveal_index", codecForNumber())
.property("refresh_base_url", makeCodecOptional(codecForString)) .property("refresh_base_url", codecOptional(codecForString()))
.build("ExchangeMeltResponse"); .build("ExchangeMeltResponse");
export const codecForExchangeRevealItem = (): Codec<ExchangeRevealItem> => export const codecForExchangeRevealItem = (): Codec<ExchangeRevealItem> =>
makeCodecForObject<ExchangeRevealItem>() buildCodecForObject<ExchangeRevealItem>()
.property("ev_sig", codecForString) .property("ev_sig", codecForString())
.build("ExchangeRevealItem"); .build("ExchangeRevealItem");
export const codecForExchangeRevealResponse = (): Codec< export const codecForExchangeRevealResponse = (): Codec<
ExchangeRevealResponse ExchangeRevealResponse
> => > =>
makeCodecForObject<ExchangeRevealResponse>() buildCodecForObject<ExchangeRevealResponse>()
.property("ev_sigs", makeCodecForList(codecForExchangeRevealItem())) .property("ev_sigs", codecForList(codecForExchangeRevealItem()))
.build("ExchangeRevealResponse"); .build("ExchangeRevealResponse");
export const codecForMerchantCoinRefundSuccessStatus = (): Codec< export const codecForMerchantCoinRefundSuccessStatus = (): Codec<
MerchantCoinRefundSuccessStatus MerchantCoinRefundSuccessStatus
> => > =>
makeCodecForObject<MerchantCoinRefundSuccessStatus>() buildCodecForObject<MerchantCoinRefundSuccessStatus>()
.property("type", makeCodecForConstString("success")) .property("type", codecForConstString("success"))
.property("coin_pub", codecForString) .property("coin_pub", codecForString())
.property("exchange_status", makeCodecForConstNumber(200)) .property("exchange_status", codecForConstNumber(200))
.property("exchange_sig", codecForString) .property("exchange_sig", codecForString())
.property("rtransaction_id", codecForNumber) .property("rtransaction_id", codecForNumber())
.property("refund_amount", codecForString) .property("refund_amount", codecForString())
.property("exchange_pub", codecForString) .property("exchange_pub", codecForString())
.property("execution_time", codecForTimestamp) .property("execution_time", codecForTimestamp)
.build("MerchantCoinRefundSuccessStatus"); .build("MerchantCoinRefundSuccessStatus");
export const codecForMerchantCoinRefundFailureStatus = (): Codec< export const codecForMerchantCoinRefundFailureStatus = (): Codec<
MerchantCoinRefundFailureStatus MerchantCoinRefundFailureStatus
> => > =>
makeCodecForObject<MerchantCoinRefundFailureStatus>() buildCodecForObject<MerchantCoinRefundFailureStatus>()
.property("type", makeCodecForConstString("failure")) .property("type", codecForConstString("failure"))
.property("coin_pub", codecForString) .property("coin_pub", codecForString())
.property("exchange_status", makeCodecForConstNumber(200)) .property("exchange_status", codecForConstNumber(200))
.property("rtransaction_id", codecForNumber) .property("rtransaction_id", codecForNumber())
.property("refund_amount", codecForString) .property("refund_amount", codecForString())
.property("exchange_code", makeCodecOptional(codecForNumber)) .property("exchange_code", codecOptional(codecForNumber()))
.property("exchange_reply", makeCodecOptional(codecForAny)) .property("exchange_reply", codecOptional(codecForAny()))
.property("execution_time", codecForTimestamp) .property("execution_time", codecForTimestamp)
.build("MerchantCoinRefundSuccessStatus"); .build("MerchantCoinRefundSuccessStatus");
export const codecForMerchantCoinRefundStatus = (): Codec< export const codecForMerchantCoinRefundStatus = (): Codec<
MerchantCoinRefundStatus MerchantCoinRefundStatus
> => > =>
makeCodecForUnion<MerchantCoinRefundStatus>() buildCodecForUnion<MerchantCoinRefundStatus>()
.discriminateOn("type") .discriminateOn("type")
.alternative("success", codecForMerchantCoinRefundSuccessStatus()) .alternative("success", codecForMerchantCoinRefundSuccessStatus())
.alternative("failure", codecForMerchantCoinRefundFailureStatus()) .alternative("failure", codecForMerchantCoinRefundFailureStatus())
@ -1256,17 +1257,17 @@ export const codecForMerchantCoinRefundStatus = (): Codec<
export const codecForMerchantOrderStatusPaid = (): Codec< export const codecForMerchantOrderStatusPaid = (): Codec<
MerchantOrderStatusPaid MerchantOrderStatusPaid
> => > =>
makeCodecForObject<MerchantOrderStatusPaid>() buildCodecForObject<MerchantOrderStatusPaid>()
.property("merchant_pub", codecForString) .property("merchant_pub", codecForString())
.property("refund_amount", codecForString) .property("refund_amount", codecForString())
.property("refunded", codecForBoolean) .property("refunded", codecForBoolean)
.property("refunds", makeCodecForList(codecForMerchantCoinRefundStatus())) .property("refunds", codecForList(codecForMerchantCoinRefundStatus()))
.build("MerchantOrderStatusPaid"); .build("MerchantOrderStatusPaid");
export const codecForMerchantOrderStatusUnpaid = (): Codec< export const codecForMerchantOrderStatusUnpaid = (): Codec<
MerchantOrderStatusUnpaid MerchantOrderStatusUnpaid
> => > =>
makeCodecForObject<MerchantOrderStatusUnpaid>() buildCodecForObject<MerchantOrderStatusUnpaid>()
.property("taler_pay_uri", codecForString) .property("taler_pay_uri", codecForString())
.property("already_paid_order_id", makeCodecOptional(codecForString)) .property("already_paid_order_id", codecOptional(codecForString()))
.build("MerchantOrderStatusUnpaid"); .build("MerchantOrderStatusUnpaid");

View File

@ -28,8 +28,8 @@ import { Timestamp } from "../util/time";
import { AmountString, Product } from "./talerTypes"; import { AmountString, Product } from "./talerTypes";
import { import {
Codec, Codec,
makeCodecForObject, buildCodecForObject,
makeCodecOptional, codecOptional,
codecForString, codecForString,
} from "../util/codec"; } from "../util/codec";
@ -305,7 +305,7 @@ interface TransactionRefresh extends TransactionCommon {
} }
export const codecForTransactionsRequest = (): Codec<TransactionsRequest> => export const codecForTransactionsRequest = (): Codec<TransactionsRequest> =>
makeCodecForObject<TransactionsRequest>() buildCodecForObject<TransactionsRequest>()
.property("currency", makeCodecOptional(codecForString)) .property("currency", codecOptional(codecForString()))
.property("search", makeCodecOptional(codecForString)) .property("search", codecOptional(codecForString()))
.build("TransactionsRequest"); .build("TransactionsRequest");

View File

@ -40,13 +40,13 @@ import {
} from "./dbTypes"; } from "./dbTypes";
import { Timestamp } from "../util/time"; import { Timestamp } from "../util/time";
import { import {
makeCodecForObject, buildCodecForObject,
codecForString, codecForString,
makeCodecOptional, codecOptional,
Codec, Codec,
makeCodecForList, codecForList,
codecForBoolean, codecForBoolean,
makeCodecForConstString, codecForConstString,
codecForAny, codecForAny,
} from "../util/codec"; } from "../util/codec";
import { AmountString, codecForContractTerms } from "./talerTypes"; import { AmountString, codecForContractTerms } from "./talerTypes";
@ -174,17 +174,17 @@ export interface BalancesResponse {
} }
export const codecForBalance = (): Codec<Balance> => export const codecForBalance = (): Codec<Balance> =>
makeCodecForObject<Balance>() buildCodecForObject<Balance>()
.property("available", codecForString) .property("available", codecForString())
.property("hasPendingTransactions", codecForBoolean) .property("hasPendingTransactions", codecForBoolean)
.property("pendingIncoming", codecForString) .property("pendingIncoming", codecForString())
.property("pendingOutgoing", codecForString) .property("pendingOutgoing", codecForString())
.property("requiresUserInput", codecForBoolean) .property("requiresUserInput", codecForBoolean)
.build("Balance"); .build("Balance");
export const codecForBalancesResponse = (): Codec<BalancesResponse> => export const codecForBalancesResponse = (): Codec<BalancesResponse> =>
makeCodecForObject<BalancesResponse>() buildCodecForObject<BalancesResponse>()
.property("balances", makeCodecForList(codecForBalance())) .property("balances", codecForList(codecForBalance()))
.build("BalancesResponse"); .build("BalancesResponse");
/** /**
@ -270,12 +270,12 @@ export interface CreateReserveRequest {
} }
export const codecForCreateReserveRequest = (): Codec<CreateReserveRequest> => export const codecForCreateReserveRequest = (): Codec<CreateReserveRequest> =>
makeCodecForObject<CreateReserveRequest>() buildCodecForObject<CreateReserveRequest>()
.property("amount", codecForAmountJson()) .property("amount", codecForAmountJson())
.property("exchange", codecForString) .property("exchange", codecForString())
.property("exchangePaytoUri", codecForString) .property("exchangePaytoUri", codecForString())
.property("senderWire", makeCodecOptional(codecForString)) .property("senderWire", codecOptional(codecForString()))
.property("bankWithdrawStatusUrl", makeCodecOptional(codecForString)) .property("bankWithdrawStatusUrl", codecOptional(codecForString()))
.build("CreateReserveRequest"); .build("CreateReserveRequest");
/** /**
@ -290,8 +290,8 @@ export interface ConfirmReserveRequest {
} }
export const codecForConfirmReserveRequest = (): Codec<ConfirmReserveRequest> => export const codecForConfirmReserveRequest = (): Codec<ConfirmReserveRequest> =>
makeCodecForObject<ConfirmReserveRequest>() buildCodecForObject<ConfirmReserveRequest>()
.property("reservePub", codecForString) .property("reservePub", codecForString())
.build("ConfirmReserveRequest"); .build("ConfirmReserveRequest");
/** /**
@ -360,43 +360,43 @@ export const enum PreparePayResultType {
export const codecForPreparePayResultPaymentPossible = (): Codec< export const codecForPreparePayResultPaymentPossible = (): Codec<
PreparePayResultPaymentPossible PreparePayResultPaymentPossible
> => > =>
makeCodecForObject<PreparePayResultPaymentPossible>() buildCodecForObject<PreparePayResultPaymentPossible>()
.property("amountEffective", codecForAmountString()) .property("amountEffective", codecForAmountString())
.property("amountRaw", codecForAmountString()) .property("amountRaw", codecForAmountString())
.property("contractTerms", codecForAny) .property("contractTerms", codecForAny())
.property("proposalId", codecForString) .property("proposalId", codecForString())
.property( .property(
"status", "status",
makeCodecForConstString(PreparePayResultType.PaymentPossible), codecForConstString(PreparePayResultType.PaymentPossible),
) )
.build("PreparePayResultPaymentPossible"); .build("PreparePayResultPaymentPossible");
export const codecForPreparePayResultInsufficientBalance = (): Codec< export const codecForPreparePayResultInsufficientBalance = (): Codec<
PreparePayResultInsufficientBalance PreparePayResultInsufficientBalance
> => > =>
makeCodecForObject<PreparePayResultInsufficientBalance>() buildCodecForObject<PreparePayResultInsufficientBalance>()
.property("amountRaw", codecForAmountString()) .property("amountRaw", codecForAmountString())
.property("contractTerms", codecForAny) .property("contractTerms", codecForAny())
.property("proposalId", codecForString) .property("proposalId", codecForString())
.property( .property(
"status", "status",
makeCodecForConstString(PreparePayResultType.InsufficientBalance), codecForConstString(PreparePayResultType.InsufficientBalance),
) )
.build("PreparePayResultInsufficientBalance"); .build("PreparePayResultInsufficientBalance");
export const codecForPreparePayResultAlreadyConfirmed = (): Codec< export const codecForPreparePayResultAlreadyConfirmed = (): Codec<
PreparePayResultAlreadyConfirmed PreparePayResultAlreadyConfirmed
> => > =>
makeCodecForObject<PreparePayResultAlreadyConfirmed>() buildCodecForObject<PreparePayResultAlreadyConfirmed>()
.property( .property(
"status", "status",
makeCodecForConstString(PreparePayResultType.AlreadyConfirmed), codecForConstString(PreparePayResultType.AlreadyConfirmed),
) )
.property("amountEffective", codecForAmountString()) .property("amountEffective", codecForAmountString())
.property("amountRaw", codecForAmountString()) .property("amountRaw", codecForAmountString())
.property("nextUrl", codecForString) .property("nextUrl", codecForString())
.property("paid", codecForBoolean) .property("paid", codecForBoolean)
.property("contractTerms", codecForAny) .property("contractTerms", codecForAny())
.build("PreparePayResultAlreadyConfirmed"); .build("PreparePayResultAlreadyConfirmed");
export type PreparePayResult = export type PreparePayResult =

View File

@ -22,7 +22,7 @@
* Imports. * Imports.
*/ */
import { import {
makeCodecForObject, buildCodecForObject,
codecForString, codecForString,
codecForNumber, codecForNumber,
Codec, Codec,
@ -68,13 +68,13 @@ export interface AmountJson {
} }
export const codecForAmountJson = (): Codec<AmountJson> => export const codecForAmountJson = (): Codec<AmountJson> =>
makeCodecForObject<AmountJson>() buildCodecForObject<AmountJson>()
.property("currency", codecForString) .property("currency", codecForString())
.property("value", codecForNumber) .property("value", codecForNumber())
.property("fraction", codecForNumber) .property("fraction", codecForNumber())
.build("AmountJson"); .build("AmountJson");
export const codecForAmountString = (): Codec<AmountString> => codecForString; export const codecForAmountString = (): Codec<AmountString> => codecForString();
/** /**
* Result of a possibly overflowing operation. * Result of a possibly overflowing operation.

View File

@ -21,10 +21,10 @@
import test from "ava"; import test from "ava";
import { import {
Codec, Codec,
makeCodecForObject, buildCodecForObject,
makeCodecForConstString, codecForConstString,
codecForString, codecForString,
makeCodecForUnion, buildCodecForUnion,
} from "./codec"; } from "./codec";
interface MyObj { interface MyObj {
@ -44,8 +44,8 @@ interface AltTwo {
type MyUnion = AltOne | AltTwo; type MyUnion = AltOne | AltTwo;
test("basic codec", (t) => { test("basic codec", (t) => {
const myObjCodec = makeCodecForObject<MyObj>() const myObjCodec = buildCodecForObject<MyObj>()
.property("foo", codecForString) .property("foo", codecForString())
.build("MyObj"); .build("MyObj");
const res = myObjCodec.decode({ foo: "hello" }); const res = myObjCodec.decode({ foo: "hello" });
t.assert(res.foo === "hello"); t.assert(res.foo === "hello");
@ -56,15 +56,15 @@ test("basic codec", (t) => {
}); });
test("union", (t) => { test("union", (t) => {
const altOneCodec: Codec<AltOne> = makeCodecForObject<AltOne>() const altOneCodec: Codec<AltOne> = buildCodecForObject<AltOne>()
.property("type", makeCodecForConstString("one")) .property("type", codecForConstString("one"))
.property("foo", codecForString) .property("foo", codecForString())
.build("AltOne"); .build("AltOne");
const altTwoCodec: Codec<AltTwo> = makeCodecForObject<AltTwo>() const altTwoCodec: Codec<AltTwo> = buildCodecForObject<AltTwo>()
.property("type", makeCodecForConstString("two")) .property("type", codecForConstString("two"))
.property("bar", codecForString) .property("bar", codecForString())
.build("AltTwo"); .build("AltTwo");
const myUnionCodec: Codec<MyUnion> = makeCodecForUnion<MyUnion>() const myUnionCodec: Codec<MyUnion> = buildCodecForUnion<MyUnion>()
.discriminateOn("type") .discriminateOn("type")
.alternative("one", altOneCodec) .alternative("one", altOneCodec)
.alternative("two", altTwoCodec) .alternative("two", altTwoCodec)

View File

@ -221,18 +221,18 @@ export class UnionCodecPreBuilder<T> {
/** /**
* Return a builder for a codec that decodes an object with properties. * Return a builder for a codec that decodes an object with properties.
*/ */
export function makeCodecForObject<T>(): ObjectCodecBuilder<T, {}> { export function buildCodecForObject<T>(): ObjectCodecBuilder<T, {}> {
return new ObjectCodecBuilder<T, {}>(); return new ObjectCodecBuilder<T, {}>();
} }
export function makeCodecForUnion<T>(): UnionCodecPreBuilder<T> { export function buildCodecForUnion<T>(): UnionCodecPreBuilder<T> {
return new UnionCodecPreBuilder<T>(); return new UnionCodecPreBuilder<T>();
} }
/** /**
* Return a codec for a mapping from a string to values described by the inner codec. * Return a codec for a mapping from a string to values described by the inner codec.
*/ */
export function makeCodecForMap<T>( export function codecForMap<T>(
innerCodec: Codec<T>, innerCodec: Codec<T>,
): Codec<{ [x: string]: T }> { ): Codec<{ [x: string]: T }> {
if (!innerCodec) { if (!innerCodec) {
@ -255,7 +255,7 @@ export function makeCodecForMap<T>(
/** /**
* Return a codec for a list, containing values described by the inner codec. * Return a codec for a list, containing values described by the inner codec.
*/ */
export function makeCodecForList<T>(innerCodec: Codec<T>): Codec<T[]> { export function codecForList<T>(innerCodec: Codec<T>): Codec<T[]> {
if (!innerCodec) { if (!innerCodec) {
throw Error("inner codec must be defined"); throw Error("inner codec must be defined");
} }
@ -276,7 +276,8 @@ export function makeCodecForList<T>(innerCodec: Codec<T>): Codec<T[]> {
/** /**
* Return a codec for a value that must be a number. * Return a codec for a value that must be a number.
*/ */
export const codecForNumber: Codec<number> = { export function codecForNumber(): Codec<number> {
return {
decode(x: any, c?: Context): number { decode(x: any, c?: Context): number {
if (typeof x === "number") { if (typeof x === "number") {
return x; return x;
@ -285,7 +286,8 @@ export const codecForNumber: Codec<number> = {
`expected number at ${renderContext(c)} but got ${typeof x}`, `expected number at ${renderContext(c)} but got ${typeof x}`,
); );
}, },
}; };
}
/** /**
* Return a codec for a value that must be a number. * Return a codec for a value that must be a number.
@ -304,7 +306,8 @@ export const codecForBoolean: Codec<boolean> = {
/** /**
* Return a codec for a value that must be a string. * Return a codec for a value that must be a string.
*/ */
export const codecForString: Codec<string> = { export function codecForString(): Codec<string> {
return {
decode(x: any, c?: Context): string { decode(x: any, c?: Context): string {
if (typeof x === "string") { if (typeof x === "string") {
return x; return x;
@ -313,21 +316,24 @@ export const codecForString: Codec<string> = {
`expected string at ${renderContext(c)} but got ${typeof x}`, `expected string at ${renderContext(c)} but got ${typeof x}`,
); );
}, },
}; };
}
/** /**
* Codec that allows any value. * Codec that allows any value.
*/ */
export const codecForAny: Codec<any> = { export function codecForAny(): Codec<any> {
return {
decode(x: any, c?: Context): any { decode(x: any, c?: Context): any {
return x; return x;
}, },
}; };
}
/** /**
* Return a codec for a value that must be a string. * Return a codec for a value that must be a string.
*/ */
export function makeCodecForConstString<V extends string>(s: V): Codec<V> { export function codecForConstString<V extends string>(s: V): Codec<V> {
return { return {
decode(x: any, c?: Context): V { decode(x: any, c?: Context): V {
if (x === s) { if (x === s) {
@ -345,7 +351,7 @@ export function makeCodecForConstString<V extends string>(s: V): Codec<V> {
/** /**
* Return a codec for a boolean true constant. * Return a codec for a boolean true constant.
*/ */
export function makeCodecForConstTrue(): Codec<true> { export function codecForConstTrue(): Codec<true> {
return { return {
decode(x: any, c?: Context): true { decode(x: any, c?: Context): true {
if (x === true) { if (x === true) {
@ -361,7 +367,7 @@ export function makeCodecForConstTrue(): Codec<true> {
/** /**
* Return a codec for a boolean true constant. * Return a codec for a boolean true constant.
*/ */
export function makeCodecForConstFalse(): Codec<false> { export function codecForConstFalse(): Codec<false> {
return { return {
decode(x: any, c?: Context): false { decode(x: any, c?: Context): false {
if (x === false) { if (x === false) {
@ -377,7 +383,7 @@ export function makeCodecForConstFalse(): Codec<false> {
/** /**
* Return a codec for a value that must be a constant number. * Return a codec for a value that must be a constant number.
*/ */
export function makeCodecForConstNumber<V extends number>(n: V): Codec<V> { export function codecForConstNumber<V extends number>(n: V): Codec<V> {
return { return {
decode(x: any, c?: Context): V { decode(x: any, c?: Context): V {
if (x === n) { if (x === n) {
@ -392,9 +398,7 @@ export function makeCodecForConstNumber<V extends number>(n: V): Codec<V> {
}; };
} }
export function makeCodecOptional<V>( export function codecOptional<V>(innerCodec: Codec<V>): Codec<V | undefined> {
innerCodec: Codec<V>,
): Codec<V | undefined> {
return { return {
decode(x: any, c?: Context): V | undefined { decode(x: any, c?: Context): V | undefined {
if (x === undefined || x === null) { if (x === undefined || x === null) {

View File

@ -23,10 +23,10 @@ import {
import { TalerErrorCode } from "./TalerErrorCode"; import { TalerErrorCode } from "./TalerErrorCode";
import { codecForTransactionsRequest } from "./types/transactions"; import { codecForTransactionsRequest } from "./types/transactions";
import { import {
makeCodecForObject, buildCodecForObject,
codecForString, codecForString,
Codec, Codec,
makeCodecOptional, codecOptional,
} from "./util/codec"; } from "./util/codec";
import { Amounts } from "./util/amounts"; import { Amounts } from "./util/amounts";
import { OperationErrorDetails } from "./types/walletTypes"; import { OperationErrorDetails } from "./types/walletTypes";
@ -36,8 +36,8 @@ export interface AddExchangeRequest {
} }
export const codecForAddExchangeRequest = (): Codec<AddExchangeRequest> => export const codecForAddExchangeRequest = (): Codec<AddExchangeRequest> =>
makeCodecForObject<AddExchangeRequest>() buildCodecForObject<AddExchangeRequest>()
.property("exchangeBaseUrl", codecForString) .property("exchangeBaseUrl", codecForString())
.build("AddExchangeRequest"); .build("AddExchangeRequest");
export interface GetExchangeTosRequest { export interface GetExchangeTosRequest {
@ -45,8 +45,8 @@ export interface GetExchangeTosRequest {
} }
export const codecForGetExchangeTosRequest = (): Codec<GetExchangeTosRequest> => export const codecForGetExchangeTosRequest = (): Codec<GetExchangeTosRequest> =>
makeCodecForObject<GetExchangeTosRequest>() buildCodecForObject<GetExchangeTosRequest>()
.property("exchangeBaseUrl", codecForString) .property("exchangeBaseUrl", codecForString())
.build("GetExchangeTosRequest"); .build("GetExchangeTosRequest");
export interface AcceptManualWithdrawalRequest { export interface AcceptManualWithdrawalRequest {
@ -57,9 +57,9 @@ export interface AcceptManualWithdrawalRequest {
export const codecForAcceptManualWithdrawalRequet = (): Codec< export const codecForAcceptManualWithdrawalRequet = (): Codec<
AcceptManualWithdrawalRequest AcceptManualWithdrawalRequest
> => > =>
makeCodecForObject<AcceptManualWithdrawalRequest>() buildCodecForObject<AcceptManualWithdrawalRequest>()
.property("exchangeBaseUrl", codecForString) .property("exchangeBaseUrl", codecForString())
.property("amount", codecForString) .property("amount", codecForString())
.build("AcceptManualWithdrawalRequest"); .build("AcceptManualWithdrawalRequest");
export interface GetWithdrawalDetailsForAmountRequest { export interface GetWithdrawalDetailsForAmountRequest {
@ -75,17 +75,17 @@ export interface AcceptBankIntegratedWithdrawalRequest {
export const codecForAcceptBankIntegratedWithdrawalRequest = (): Codec< export const codecForAcceptBankIntegratedWithdrawalRequest = (): Codec<
AcceptBankIntegratedWithdrawalRequest AcceptBankIntegratedWithdrawalRequest
> => > =>
makeCodecForObject<AcceptBankIntegratedWithdrawalRequest>() buildCodecForObject<AcceptBankIntegratedWithdrawalRequest>()
.property("exchangeBaseUrl", codecForString) .property("exchangeBaseUrl", codecForString())
.property("talerWithdrawUri", codecForString) .property("talerWithdrawUri", codecForString())
.build("AcceptBankIntegratedWithdrawalRequest"); .build("AcceptBankIntegratedWithdrawalRequest");
export const codecForGetWithdrawalDetailsForAmountRequest = (): Codec< export const codecForGetWithdrawalDetailsForAmountRequest = (): Codec<
GetWithdrawalDetailsForAmountRequest GetWithdrawalDetailsForAmountRequest
> => > =>
makeCodecForObject<GetWithdrawalDetailsForAmountRequest>() buildCodecForObject<GetWithdrawalDetailsForAmountRequest>()
.property("exchangeBaseUrl", codecForString) .property("exchangeBaseUrl", codecForString())
.property("amount", codecForString) .property("amount", codecForString())
.build("GetWithdrawalDetailsForAmountRequest"); .build("GetWithdrawalDetailsForAmountRequest");
export interface AcceptExchangeTosRequest { export interface AcceptExchangeTosRequest {
@ -94,9 +94,9 @@ export interface AcceptExchangeTosRequest {
} }
export const codecForAcceptExchangeTosRequest = (): Codec<AcceptExchangeTosRequest> => export const codecForAcceptExchangeTosRequest = (): Codec<AcceptExchangeTosRequest> =>
makeCodecForObject<AcceptExchangeTosRequest>() buildCodecForObject<AcceptExchangeTosRequest>()
.property("exchangeBaseUrl", codecForString) .property("exchangeBaseUrl", codecForString())
.property("etag", codecForString) .property("etag", codecForString())
.build("AcceptExchangeTosRequest"); .build("AcceptExchangeTosRequest");
export interface ApplyRefundRequest { export interface ApplyRefundRequest {
@ -104,8 +104,8 @@ export interface ApplyRefundRequest {
} }
export const codecForApplyRefundRequest = (): Codec<ApplyRefundRequest> => export const codecForApplyRefundRequest = (): Codec<ApplyRefundRequest> =>
makeCodecForObject<ApplyRefundRequest>() buildCodecForObject<ApplyRefundRequest>()
.property("talerRefundUri", codecForString) .property("talerRefundUri", codecForString())
.build("ApplyRefundRequest"); .build("ApplyRefundRequest");
export interface GetWithdrawalDetailsForUriRequest { export interface GetWithdrawalDetailsForUriRequest {
@ -115,8 +115,8 @@ export interface GetWithdrawalDetailsForUriRequest {
export const codecForGetWithdrawalDetailsForUri = (): Codec< export const codecForGetWithdrawalDetailsForUri = (): Codec<
GetWithdrawalDetailsForUriRequest GetWithdrawalDetailsForUriRequest
> => > =>
makeCodecForObject<GetWithdrawalDetailsForUriRequest>() buildCodecForObject<GetWithdrawalDetailsForUriRequest>()
.property("talerWithdrawUri", codecForString) .property("talerWithdrawUri", codecForString())
.build("GetWithdrawalDetailsForUriRequest"); .build("GetWithdrawalDetailsForUriRequest");
export interface AbortProposalRequest { export interface AbortProposalRequest {
@ -124,8 +124,8 @@ export interface AbortProposalRequest {
} }
export const codecForAbortProposalRequest = (): Codec<AbortProposalRequest> => export const codecForAbortProposalRequest = (): Codec<AbortProposalRequest> =>
makeCodecForObject<AbortProposalRequest>() buildCodecForObject<AbortProposalRequest>()
.property("proposalId", codecForString) .property("proposalId", codecForString())
.build("AbortProposalRequest"); .build("AbortProposalRequest");
export interface PreparePayRequest { export interface PreparePayRequest {
@ -133,8 +133,8 @@ export interface PreparePayRequest {
} }
const codecForPreparePayRequest = (): Codec<PreparePayRequest> => const codecForPreparePayRequest = (): Codec<PreparePayRequest> =>
makeCodecForObject<PreparePayRequest>() buildCodecForObject<PreparePayRequest>()
.property("talerPayUri", codecForString) .property("talerPayUri", codecForString())
.build("PreparePay"); .build("PreparePay");
export interface ConfirmPayRequest { export interface ConfirmPayRequest {
@ -143,9 +143,9 @@ export interface ConfirmPayRequest {
} }
export const codecForConfirmPayRequest = (): Codec<ConfirmPayRequest> => export const codecForConfirmPayRequest = (): Codec<ConfirmPayRequest> =>
makeCodecForObject<ConfirmPayRequest>() buildCodecForObject<ConfirmPayRequest>()
.property("proposalId", codecForString) .property("proposalId", codecForString())
.property("sessionId", makeCodecOptional(codecForString)) .property("sessionId", codecOptional(codecForString()))
.build("ConfirmPay"); .build("ConfirmPay");
/** /**