Resource type

Purpose of this type is to describe logical resource or object in simmilar way as class works in OOP.

Description

@doctype: meta/resource

Resource type describes logical object such as article, user or customer which is also actionable.

Resource is described by:

  • Descriptive properties (title, description, icon)
  • Navigation properties
  • Object properties
  • Object actions (methods)

Example of property definition

{
    "@doctype": "meta/resource",
    "$customer": {
        "@type": "meta/data",
        "uri": "./customer.json"
    },
    "$isNew": {
        "@type": "meta/javascript",
        "args": [ "$customer" ],
        "value": "return ($customer.active > $now ? true : false);"
    },
    "$now": {
        "@type": "meta/javascript",
        "args": [],
        "uri": "./now.js"
    },
    "$value": {
        "@type": "meta/data",
        "value": 123
    }
}

Data binding

Resource type describes object behaviour but data are seperated into another layer and are binded as specified.

When resource is loaded then data model is created.

Data binding is based on definition of model properties.

Each model property is defined as document property of object type which is prefixed with $ dollar sign.

Model property can be one of following:

  • Datasource
  • JavaScript function (with limited scope)
  • Inline defined value

Datasource and JavaScript propreties can be external and referenced by URI.

Model definition

Property Type * # Description
@type String Yes No Type of model property, one of: meta/data, meta/datasource, meta/javascript
uri String / URI Yes if external No URI of model resource
value JSON any Yes if not external No Model property value
args Array of String Yes if JavaScript type No Model properties as input arguments

When both uri and value is specified then value is used. You should never specify both properties together.

JavaScript functions

  • JavaScript code is loaded as anonymous function body
  • Function return value is binded as model property
  • Function can accept another model properties as input arguments
  • Function output cannot be also it's input (eg. recursive functions are not allowed)
  • When any of input model properties has changed then function is re-run and it's output is re-binded
  • Functions has no access to standard DOM or browser objects, just vanilla JS

$this property
Property $this is reserved and is used to access current model scope.

Example

{
    "@doctype": "meta/resource",
    "$c": {
        "@type": "meta/data",
        "uri": "./42.json"
    },
    "label: "{{$c.first_name}} {{$c.last_name}}",
    "aliases": [ "Customer", "{{$c.address}}" ],
    "icon": "/assets/customer.svg",
    "schema": "entity.person.customer",
    "readonly": "$c.locked"
}

Descriptive properties

Property Type * # Description
label String Yes Yes Label of resource
alises Array of String No Yes Alternative resource labels, eg. different forms of words - helpful for voice control
icon String / URI No No URI to resource icon, all image formats are supported but SVG is recommended
image String / URI No No URI to resource header image, all image formats are supported. Bitmap formats recommended.
schema String No No MetaWEB schema identifier from Schema vocabulary
readonly Boolean / Model prop. as String No No If resource is read-only and thus all controls must be disabled.

Example

{
    "@doctype": "meta/resource",
    ...
    "parent": "../index.meta",
    "previous": "./41.meta",
    "next": "./43.meta",
    "sitemap": "/sitemap.meta",
    "manifest": "/manifest.meta"
}

Navigation properties

Property Type * # Description
parent String / URI No Yes URI to parent resource
previous String / URI No Yes URI to previous resource on same navigation level
next String / URI No Yes URI to next resource on same navigation level
sitemap String / URI No Yes URI to MetaWEB sitemap file
manifest String / URI No Yes URI to MetaWEB application manifest file

Example

{
    "@doctype": "meta/resource",
    "$c": {
        "@type": "meta/data",
        "uri": "./42.json"
    },
    "label: "{{$c.first_name}} {{$c.last_name}}",
    "properties": [
        {
            "@type": "meta/properties/text",
            "label": "First name",
            "required": true,
            "model": "$c.first_name"
        }
    ]
}

Resource properties

Resource properties describes object and are specified as properties property of document.

See Properties page for specification of object property types.

Property Type * # Description
properties Array of Object Yes No Properties definition

Example

{
    "@doctype": "meta/resource",
    "$c": {
        "@type": "meta/data",
        "uri": "./42.json"
    },
    "label: "{{$c.first_name}} {{$c.last_name}}",
    "aliases": [ "Customer" ],
    "icon": "/assets/customer.svg",
    "schema": "entity.person.customer",
    "readonly": "$c.editable",
    "parent": "../index.meta",
    "previous": "./41.meta",
    "next": "./43.meta",
    "sitemap": "/sitemap.meta",
    "manifest": "/manifest.meta",
    "properties": [
        {
            "@type": "meta/properties/text",
            "label": "First name",
            "required": true,
            "model": "$c.first_name"
        },
        {
            "@type": "meta/properties/text",
            "label": "last name",
            "required": true,
            "model": "$c.last_name"
        }
    ],
    "actions": [
        {
            "method": "PUT",
            "uri": "./42.json",
            "model": "$c",
            "label": "Update",
            "icon": "/assets/save.svg",
            "schema": "@update"
        },
        {
            "method": "navigate",
            "uri": "../related",
            "model": {
                "customer": "$c.id"
            },
            "label": "Related entires",
            "icon": "/assets/link.svg",
            "schema": "@related"
        }
    ]
}

Resource actions

Every resource can specify actions which can be invoked on that resource and are specified as actions property of document.

Property Type * # Description
actions Array of Object No No Actions definition

Action definition

Property Type * # Description
method String Yes No HTTP method + specials
uri String / URI Yes Yes URI which will be called when action will be invoked
model String Object No No
label String Yes Yes Label of action
aliases Array of String No Yes Alternative action labels
icon String / URI No No URI to resource icon, all image formats are supported but SVG is recommended
schema String No No MetaWEB schema identifier from Schema vocabulary
context String No No Where to display action, one of main, options.
style String No No How to display action result, one of default, dialog.

To submit no data specify model as empty object, eg.: {}.

Except navigate method all actions should be processed without redirecting client to target URI.

Supported methods

Method Data format Description
GET Query string Makes GET HTTP request and submits data as query string
POST JSON body Makes POST HTTP request and submits data as JSON encoded body
PUT JSON body Makes PUT HTTP request and submits data as JSON encoded body
DELETE JSON body Makes DELETE HTTP request and submits data as JSON encoded body
navigate Query string Redirects client to target URI with data encoded as query string

Response
Response should be compatible with Response type. Otherwise response content should be displayed as text.

customers/template.meta

{
    "@doctype": "meta/resource",
    "label: "{{$c.first_name}} {{$c.last_name}}",
    "readonly": "$c.editable",
    "previous": "../{{$c.prev_id}}.json",
    "next": "../{{$c.next_id}}.json",
    "properties": [
        {
            "@type": "meta/properties/text",
            "label": "First name",
            "required": true,
            "model": "$c.first_name"
        },
        {
            "@type": "meta/properties/text",
            "label": "last name",
            "required": true,
            "model": "$c.last_name"
        }
    ],
    "actions": [
        {
            "method": "PUT",
            "uri": "./{{$c.id}}.json",
            "model": "$c",
            "label": "Update",
            "icon": "/assets/save.svg",
            "schema": "@update"
        }
    ]
}

customers/42.meta

{
    "@doctype": "meta/resource",
    "template": "./template.meta",
    "$c": {
        "@type": "meta/data",
        "uri": "./42.json"
    }
}

Final document

{
    "@doctype": "meta/resource",
    "label: "{{$c.first_name}} {{$c.last_name}}",
    "readonly": "$c.editable",
    "previous": "../{{$c.prev_id}}.json",
    "next": "../{{$c.next_id}}.json",
    "properties": [
        {
            "@type": "meta/properties/text",
            "label": "First name",
            "required": true,
            "model": "$c.first_name"
        },
        {
            "@type": "meta/properties/text",
            "label": "last name",
            "required": true,
            "model": "$c.last_name"
        }
    ],
    "actions": [
        {
            "method": "PUT",
            "uri": "./{{$c.id}}.json",
            "model": "$c",
            "label": "Update",
            "icon": "/assets/save.svg",
            "schema": "@update"
        }
    ],
    "$c": {
        "@type": "meta/data",
        "uri": "./42.json"
    }
}

Templates

Returning full MetaWEB file for every record in collection is wasting of bandwith and resources.

MetaWEB resource type provides possibility to define template file which can be loaded once, cached and reused in another simplified MetaWEB files.

Template can be specified as URI to another MetaWEB file of same type. When specified client must load template document at first and then override properties specified in current document.

See example for better understanding.

Properties summary

Property Type * # Description
@doctype String Yes No Document type
label String Yes Yes Label of resource
alises Array of String No Yes Alternative resource labels, eg. different forms of words - helpful for voice control
icon String / URI No No URI to resource icon, all image formats are supported but SVG is recommended
schema String No No MetaWEB schema identifier from Schema vocabulary
readonly Boolean / Model prop. as String No No If resource is read-only and thus all controls must be disabled.
parent String / URI No Yes URI to parent resource
previous String / URI No Yes URI to previous resource on same navigation level
next String / URI No Yes URI to next resource on same navigation level
sitemap String / URI No Yes URI to MetaWEB sitemap file
manifest String / URI No Yes URI to MetaWEB application manifest file
properties Array of Object Yes No Properties definition
actions Array of Object No No Actions definition
template String / URI No No Template URI
$* Object No No Model property