aboutsummaryrefslogtreecommitdiff
path: root/src/checkable.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-01-17 03:49:54 +0100
committerFlorian Dold <florian.dold@gmail.com>2018-01-17 03:49:54 +0100
commitc62ba4986fbfcb8637a3befadf3d3eddbd5348ca (patch)
treee88b71758cff696df0c8f2bb163a7c7c3957f871 /src/checkable.ts
parent894a09a51c1111257be56809f1d3daf0146f8509 (diff)
downloadwallet-core-c62ba4986fbfcb8637a3befadf3d3eddbd5348ca.tar.xz
implement new mobile-compatible payment logic
Diffstat (limited to 'src/checkable.ts')
-rw-r--r--src/checkable.ts25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/checkable.ts b/src/checkable.ts
index 124eb6587..159e5a85e 100644
--- a/src/checkable.ts
+++ b/src/checkable.ts
@@ -15,8 +15,6 @@
*/
-"use strict";
-
/**
* Decorators for validating JSON objects and converting them to a typed
* object.
@@ -55,6 +53,7 @@ export namespace Checkable {
propertyKey: any;
checker: any;
type?: any;
+ typeThunk?: () => any;
elementChecker?: any;
elementProp?: any;
keyProp?: any;
@@ -167,11 +166,18 @@ export namespace Checkable {
function checkValue(target: any, prop: Prop, path: Path): any {
- const type = prop.type;
- const typeName = type.name || "??";
- if (!type) {
- throw Error(`assertion failed (prop is ${JSON.stringify(prop)})`);
+ let type;
+ if (prop.type) {
+ type = prop.type;
+ } else if (prop.typeThunk) {
+ type = prop.typeThunk();
+ if (!type) {
+ throw Error(`assertion failed: typeThunk returned null (prop is ${JSON.stringify(prop)})`);
+ }
+ } else {
+ throw Error(`assertion failed: type/typeThunk missing (prop is ${JSON.stringify(prop)})`);
}
+ const typeName = type.name || "??";
const v = target;
if (!v || typeof v !== "object") {
throw new SchemaError(
@@ -236,16 +242,13 @@ export namespace Checkable {
/**
* Target property must be a Checkable object of the given type.
*/
- export function Value(type: any) {
- if (!type) {
- throw Error("Type does not exist yet (wrong order of definitions?)");
- }
+ export function Value(typeThunk: () => any) {
function deco(target: object, propertyKey: string | symbol): void {
const chk = getCheckableInfo(target);
chk.props.push({
checker: checkValue,
propertyKey,
- type,
+ typeThunk,
});
}