As described in the data contract explanation, data contracts must include one or more developer-defined documents.
The most basic example below (tab 1) demonstrates a data contract containing a single document type (note
) which has a single string property (message
).
The second tab shows the same data contract with an index defined on the $ownerId
field. This would allow querying for documents owned by a specific identity using a where clause.
The third tab shows a data contract requiring the optional $createdAt
and $updatedAt
base
fields. Using these fields enables
retrieving timestamps that indicate when a document was created or modified.
The fourth tab shows a data contract using a byte array. This allows a contract to store binary data.
The fifth tab shows a data contract configured to store contract history. This allows all contract revisions to be retrieved in the future as needed.
🚧
Since Platform v0.1.0, each document property must assign
position
value to support backwards compatibility for contract updates.Since Platform v0.1.0, an index can only use the ascending order (
asc
). Future updates will remove this restriction.
JSON
// 1. Minimal contract { "note": { "type": "object", "properties": { "message": { "type": "string", "position": 0 } }, "additionalProperties": false } }
JSON
`// 2. Indexed { "note": { "type": "object", "indices": [ { "name": "ownerId", "properties": [{ "$ownerId": "asc" }], "unique": false } ], "properties": { "message": { "type": "string", "position": 0 } }, "additionalProperties": false } }
/* An identity's documents are accessible via a query including a where clause like: { where: [['$ownerId', '==', 'an identity id']], } */`
JSON