From 0e43c92c982b332fe53369700e04d0e32a7190f1 Mon Sep 17 00:00:00 2001 From: Kestutis Gudynas <44440041+kemi04@users.noreply.github.com> Date: Thu, 17 Sep 2020 10:45:44 +0100 Subject: [PATCH] v2.x tutorials updated Signed-off-by: Kestutis Gudynas <44440041+kemi04@users.noreply.github.com> --- .../tutorials/annotated-contract-metadata.md | 64 ++++++++++++++++++- docs/_jsdoc/tutorials/tutorials.json | 13 ++-- docs/_jsdoc/tutorials/using-iterators.md | 2 +- 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/docs/_jsdoc/tutorials/annotated-contract-metadata.md b/docs/_jsdoc/tutorials/annotated-contract-metadata.md index d137a922..c1f2e235 100644 --- a/docs/_jsdoc/tutorials/annotated-contract-metadata.md +++ b/docs/_jsdoc/tutorials/annotated-contract-metadata.md @@ -255,4 +255,66 @@ This example is defining the concept of a person; who has a name, address and an } } } -``` \ No newline at end of file +``` +## String and Number validation + +Strict semantic checking can be performed on strings and numbers. As an example consider this extract of metadata describing the parameters of a function +``` + "parameters": [ + { + "name": "pupilName", + "description": "", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "formId", + "description": "", + "required": true, + "schema": { + "type": "string", + "pattern": "^[a-zA-Z0-9]+$" + } + }, + { + "name": "description", + "description": "", + "required": true, + "schema": { + "type": "string", + "maxLength": 100 + } + }, + { + "name": "lifetime", + "description": "days this is valid for (30 if not given)", + "required": false, + "schema": { + "type": "integer", + "minimum": 1, + "maximum": 30 + } + }, + { + "name": "startDate", + "description": "Start date yyyy-mm-dd, today if not specified", + "required": false, + "schema": { + "type": "string", + "format": "date" + } + } + ] +``` + +**Note: The `required` tag at present is not enforced by the node chaincode.** + +- __Pupilname__ this is a string, but has no restrictions placed up on it. +- __formId__ a string, but has to matched the regular expression. In this case it has to be exactly composed of lower or upcase letters and numbers +- __description__ a string, with the restriction that it can't be more than 100 characters in length +- __lifetime__ an integer with minimum value of 1 and maxiomum of 30 +- __startDate__ an string but has to contain a date (As defined by full-date - [RFC3339](http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14)). + +The alternative to `format:date` is `format:dateTime` ... the string here has to confirmed to date-time defined in [RFC3339](http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14) \ No newline at end of file diff --git a/docs/_jsdoc/tutorials/tutorials.json b/docs/_jsdoc/tutorials/tutorials.json index 4093e480..a4e43c6f 100644 --- a/docs/_jsdoc/tutorials/tutorials.json +++ b/docs/_jsdoc/tutorials/tutorials.json @@ -5,9 +5,6 @@ "using-contractinterface":{ "title":"Using the Contract Interface" }, - "using-iterators":{ - "title":"Working with apis that return iterators" - }, "annotated-contract-metadata":{ "title":"Walkthrough of annotated metadata.json" }, @@ -16,6 +13,12 @@ }, "using-typescript-decorators":{ "title":"Using TypeScript Decorators" - } + }, + "data-types-and-contracts":{ + "title":"Details of type handling" + }, + "using-iterators": { + "title":"Working with apis that return iterators" + } -} +} \ No newline at end of file diff --git a/docs/_jsdoc/tutorials/using-iterators.md b/docs/_jsdoc/tutorials/using-iterators.md index 066a457b..d739f39b 100644 --- a/docs/_jsdoc/tutorials/using-iterators.md +++ b/docs/_jsdoc/tutorials/using-iterators.md @@ -25,7 +25,7 @@ These apis are a request to return a set of data for which you need to iterate o These iterators were essentially asynchronous iterators (the next and close methods returned promises) but you couldn't use standard iterator capabilities such as for/of constructs in node because node could not work with the concept of asynchronous iterators. -From fabric v2.x onwards, node chaincode will be using node 10 and this has added support for asynchronous iterators. Also in fabric v2.x onwards, fabric-shim has added support to enable it's asynchronous iterators so that `for/of` can now be used, but note that they don't have full support, so should not be used in generator functions. +From fabric v2.x onwards, node chaincode will be using node 12 and this has added support for asynchronous iterators. Also in fabric v2.x onwards, fabric-shim has added support to enable it's asynchronous iterators so that `for/of` can now be used, but note that they don't have full support, so should not be used in generator functions. As a comparison, let's present first how you would use iterators in previous releases and then show the new way.