gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-wallet-webex] branch master updated: simplify Checka


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] branch master updated: simplify Checkable.Class annotation and allow extra fields in /keys response
Date: Sat, 27 May 2017 15:05:55 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-webex.

The following commit(s) were added to refs/heads/master by this push:
     new 41f152b8 simplify Checkable.Class annotation and allow extra fields in 
/keys response
41f152b8 is described below

commit 41f152b80ac10de22f330ec240196db484a8a479
Author: Florian Dold <address@hidden>
AuthorDate: Sat May 27 15:05:41 2017 +0200

    simplify Checkable.Class annotation and allow extra fields in /keys response
---
 src/checkable.ts | 70 +++++++++++++++++---------------------------------------
 src/types.ts     | 12 +++++-----
 src/wallet.ts    | 14 ++++++------
 3 files changed, 34 insertions(+), 62 deletions(-)

diff --git a/src/checkable.ts b/src/checkable.ts
index 6bfaea01..24eebc71 100644
--- a/src/checkable.ts
+++ b/src/checkable.ts
@@ -206,55 +206,27 @@ export namespace Checkable {
    * This annotation adds the implementation of the `checked`
    * static method.
    */
-  export function Class(target: any) {
-    target.checked = (v: any) => {
-      return checkValue(v, {
-        propertyKey: "(root)",
-        type: target,
-        checker: checkValue
-      }, ["(root)"]);
-    };
-    return target;
-  }
-
-  /**
-   * A checker for a class (see [[Class]) that allows
-   * extra properties to exist on the JSON object being validated.
-   */
-  export function ClassWithExtra(target: any) {
-    target.checked = (v: any) => {
-      return checkValue(v, {
-        propertyKey: "(root)",
-        type: target,
-        extraAllowed: true,
-        checker: checkValue
-      }, ["(root)"]);
-    };
-    return target;
-  }
-
-
-  /**
-   * A validator for a class that can have an additional validate
-   * method.  The validate method is a member method of type `() => void`
-   * that throws an exception on invalidation errors.
-   */
-  export function ClassWithValidator(target: any) {
-    target.checked = (v: any) => {
-      let cv = checkValue(v, {
-        propertyKey: "(root)",
-        type: target,
-        checker: checkValue
-      }, ["(root)"]);
-      let instance = new target();
-      if (typeof instance.validate !== "function") {
-        throw Error("invalid Checkable annotion: validate method required");
-      }
-      // May throw exception
-      instance.validate.call(cv);
-      return cv;
-    };
-    return target;
+  export function Class(opts: {extra?: boolean, validate?: boolean} = {}) {
+    return (target: any) => {
+      target.checked = (v: any) => {
+        let cv = checkValue(v, {
+          propertyKey: "(root)",
+          type: target,
+          extraAllowed: !!opts.extra,
+          checker: checkValue
+        }, ["(root)"]);
+        if (opts.validate) {
+          let instance = new target();
+          if (typeof instance.validate !== "function") {
+            throw Error("invalid Checkable annotion: validate method 
required");
+          }
+          // May throw exception
+          instance.validate.call(cv);
+        }
+        return cv;
+      };
+      return target;
+    }
   }
 
 
diff --git a/src/types.ts b/src/types.ts
index 9b8facf7..26280874 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -28,7 +28,7 @@
  */
 import { Checkable } from "./checkable";
 
address@hidden
address@hidden()
 export class AmountJson {
   @Checkable.Number
   value: number;
@@ -106,7 +106,7 @@ export interface CurrencyRecord {
 }
 
 
address@hidden
address@hidden()
 export class CreateReserveResponse {
   /**
    * Exchange URL where the bank should create the reserve.
@@ -187,7 +187,7 @@ export class DenominationRecord {
 /**
  * Denomination as found in the /keys response from the exchange.
  */
address@hidden
address@hidden()
 export class Denomination {
   @Checkable.Value(AmountJson)
   value: AmountJson;
@@ -304,7 +304,7 @@ export interface PaybackRequest {
   coin_sig: string;
 }
 
address@hidden
address@hidden()
 export class PaybackConfirmation {
   /**
    * public key of the reserve that will receive the payback.
@@ -477,7 +477,7 @@ export interface CoinRecord {
 }
 
 
address@hidden
address@hidden()
 export class ExchangeHandle {
   @Checkable.String
   master_pub: string;
@@ -524,7 +524,7 @@ interface Merchant {
   instance?: string;
 }
 
address@hidden
address@hidden({validate: true})
 export class Contract {
 
   validate() {
diff --git a/src/wallet.ts b/src/wallet.ts
index f2c38078..f48fcc76 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -89,7 +89,7 @@ export interface CoinWithDenom {
  * Element of the payback list that the
  * exchange gives us in /keys.
  */
address@hidden
address@hidden()
 export class Payback {
   @Checkable.String
   h_denom_pub: string;
@@ -99,7 +99,7 @@ export class Payback {
 /**
  * Structure that the exchange gives us in /keys.
  */
address@hidden
address@hidden({extra: true})
 export class KeysJson {
   @Checkable.List(Checkable.Value(Denomination))
   denoms: Denomination[];
@@ -129,7 +129,7 @@ export class KeysJson {
 }
 
 
address@hidden
address@hidden()
 class WireFeesJson {
   @Checkable.Value(AmountJson)
   wire_fee: AmountJson;
@@ -150,7 +150,7 @@ class WireFeesJson {
 }
 
 
address@hidden
address@hidden({extra: true})
 class WireDetailJson {
   @Checkable.String
   type: string;
@@ -162,7 +162,7 @@ class WireDetailJson {
 }
 
 
address@hidden
address@hidden()
 export class CreateReserveRequest {
   /**
    * The initial amount for the reserve.
@@ -180,7 +180,7 @@ export class CreateReserveRequest {
 }
 
 
address@hidden
address@hidden()
 export class ConfirmReserveRequest {
   /**
    * Public key of then reserve that should be marked
@@ -193,7 +193,7 @@ export class ConfirmReserveRequest {
 }
 
 
address@hidden
address@hidden()
 export class OfferRecord {
   @Checkable.Value(Contract)
   contract: Contract;

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]