Skip to content

Commit

Permalink
v2.x tutorials updated
Browse files Browse the repository at this point in the history
Signed-off-by: Kestutis Gudynas <44440041+kemi04@users.noreply.github.com>
  • Loading branch information
kemi04 committed Sep 17, 2020
1 parent 05df03f commit 0e43c92
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 7 deletions.
64 changes: 63 additions & 1 deletion docs/_jsdoc/tutorials/annotated-contract-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,66 @@ This example is defining the concept of a person; who has a name, address and an
}
}
}
```
```
## 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)
13 changes: 8 additions & 5 deletions docs/_jsdoc/tutorials/tutorials.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
}

}
}
2 changes: 1 addition & 1 deletion docs/_jsdoc/tutorials/using-iterators.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 0e43c92

Please sign in to comment.