|
@@ -54,6 +54,10 @@ class Dish {
|
|
case "bignumber":
|
|
case "bignumber":
|
|
case "big number":
|
|
case "big number":
|
|
return Dish.BIG_NUMBER;
|
|
return Dish.BIG_NUMBER;
|
|
|
|
+ case "json":
|
|
|
|
+ return Dish.JSON;
|
|
|
|
+ case "file":
|
|
|
|
+ return Dish.FILE;
|
|
case "list<file>":
|
|
case "list<file>":
|
|
return Dish.LIST_FILE;
|
|
return Dish.LIST_FILE;
|
|
default:
|
|
default:
|
|
@@ -82,6 +86,10 @@ class Dish {
|
|
return "ArrayBuffer";
|
|
return "ArrayBuffer";
|
|
case Dish.BIG_NUMBER:
|
|
case Dish.BIG_NUMBER:
|
|
return "BigNumber";
|
|
return "BigNumber";
|
|
|
|
+ case Dish.JSON:
|
|
|
|
+ return "JSON";
|
|
|
|
+ case Dish.FILE:
|
|
|
|
+ return "File";
|
|
case Dish.LIST_FILE:
|
|
case Dish.LIST_FILE:
|
|
return "List<File>";
|
|
return "List<File>";
|
|
default:
|
|
default:
|
|
@@ -160,6 +168,13 @@ class Dish {
|
|
case Dish.BIG_NUMBER:
|
|
case Dish.BIG_NUMBER:
|
|
this.value = this.value instanceof BigNumber ? Utils.strToByteArray(this.value.toFixed()) : [];
|
|
this.value = this.value instanceof BigNumber ? Utils.strToByteArray(this.value.toFixed()) : [];
|
|
break;
|
|
break;
|
|
|
|
+ case Dish.JSON:
|
|
|
|
+ this.value = this.value ? Utils.strToByteArray(JSON.stringify(this.value)) : [];
|
|
|
|
+ break;
|
|
|
|
+ case Dish.FILE:
|
|
|
|
+ this.value = await Utils.readFile(this.value);
|
|
|
|
+ this.value = Array.prototype.slice.call(this.value);
|
|
|
|
+ break;
|
|
case Dish.LIST_FILE:
|
|
case Dish.LIST_FILE:
|
|
this.value = await Promise.all(this.value.map(async f => Utils.readFile(f)));
|
|
this.value = await Promise.all(this.value.map(async f => Utils.readFile(f)));
|
|
this.value = this.value.map(b => Array.prototype.slice.call(b));
|
|
this.value = this.value.map(b => Array.prototype.slice.call(b));
|
|
@@ -194,8 +209,15 @@ class Dish {
|
|
}
|
|
}
|
|
this.type = Dish.BIG_NUMBER;
|
|
this.type = Dish.BIG_NUMBER;
|
|
break;
|
|
break;
|
|
- case Dish.LIST_FILE:
|
|
|
|
|
|
+ case Dish.JSON:
|
|
|
|
+ this.value = JSON.parse(byteArrayToStr(this.value));
|
|
|
|
+ this.type = Dish.JSON;
|
|
|
|
+ break;
|
|
|
|
+ case Dish.FILE:
|
|
this.value = new File(this.value, "unknown");
|
|
this.value = new File(this.value, "unknown");
|
|
|
|
+ break;
|
|
|
|
+ case Dish.LIST_FILE:
|
|
|
|
+ this.value = [new File(this.value, "unknown")];
|
|
this.type = Dish.LIST_FILE;
|
|
this.type = Dish.LIST_FILE;
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
@@ -235,6 +257,11 @@ class Dish {
|
|
return this.value instanceof ArrayBuffer;
|
|
return this.value instanceof ArrayBuffer;
|
|
case Dish.BIG_NUMBER:
|
|
case Dish.BIG_NUMBER:
|
|
return this.value instanceof BigNumber;
|
|
return this.value instanceof BigNumber;
|
|
|
|
+ case Dish.JSON:
|
|
|
|
+ // All values can be serialised in some manner, so we return true in all cases
|
|
|
|
+ return true;
|
|
|
|
+ case Dish.FILE:
|
|
|
|
+ return this.value instanceof File;
|
|
case Dish.LIST_FILE:
|
|
case Dish.LIST_FILE:
|
|
return this.value instanceof Array &&
|
|
return this.value instanceof Array &&
|
|
this.value.reduce((acc, curr) => acc && curr instanceof File, true);
|
|
this.value.reduce((acc, curr) => acc && curr instanceof File, true);
|
|
@@ -262,6 +289,10 @@ class Dish {
|
|
return this.value.toString().length;
|
|
return this.value.toString().length;
|
|
case Dish.ARRAY_BUFFER:
|
|
case Dish.ARRAY_BUFFER:
|
|
return this.value.byteLength;
|
|
return this.value.byteLength;
|
|
|
|
+ case Dish.JSON:
|
|
|
|
+ return JSON.stringify(this.value).length;
|
|
|
|
+ case Dish.FILE:
|
|
|
|
+ return this.value.size;
|
|
case Dish.LIST_FILE:
|
|
case Dish.LIST_FILE:
|
|
return this.value.reduce((acc, curr) => acc + curr.size, 0);
|
|
return this.value.reduce((acc, curr) => acc + curr.size, 0);
|
|
default:
|
|
default:
|
|
@@ -308,12 +339,24 @@ Dish.ARRAY_BUFFER = 4;
|
|
* @enum
|
|
* @enum
|
|
*/
|
|
*/
|
|
Dish.BIG_NUMBER = 5;
|
|
Dish.BIG_NUMBER = 5;
|
|
|
|
+/**
|
|
|
|
+ * Dish data type enum for JSON.
|
|
|
|
+ * @readonly
|
|
|
|
+ * @enum
|
|
|
|
+ */
|
|
|
|
+Dish.JSON = 6;
|
|
/**
|
|
/**
|
|
* Dish data type enum for lists of files.
|
|
* Dish data type enum for lists of files.
|
|
* @readonly
|
|
* @readonly
|
|
* @enum
|
|
* @enum
|
|
*/
|
|
*/
|
|
-Dish.LIST_FILE = 6;
|
|
|
|
|
|
+Dish.FILE = 7;
|
|
|
|
+/**
|
|
|
|
+* Dish data type enum for lists of files.
|
|
|
|
+* @readonly
|
|
|
|
+* @enum
|
|
|
|
+*/
|
|
|
|
+Dish.LIST_FILE = 8;
|
|
|
|
|
|
|
|
|
|
export default Dish;
|
|
export default Dish;
|