Skip to content

Commit c5280bb

Browse files
committed
Merge pull request #25 from refractproject/zdne/add-variables-examples
Add variables examples
2 parents 7415672 + 70a2b66 commit c5280bb

File tree

1 file changed

+109
-44
lines changed

1 file changed

+109
-44
lines changed

namespaces/mson-namespace.md

Lines changed: 109 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
# MSON Namespace
22

3-
This document extends [Refract][] Specification with new element types necessary to build [MSON][] DOM.
3+
This document extends [Refract][] Specification with new element types necessary to build [MSON][] Refract.
44

55
## Content
66

77
<!-- TOC depth:3 withLinks:1 updateOnSave:0 -->
88
- [MSON Namespace](#mson-namespace)
9-
- [Content](#content)
10-
- [About this Document](#about-this-document)
11-
- [Expanded Element](#expanded-element)
12-
- [Base Element](#base-element)
13-
- [Type comparison](#type-comparison)
14-
- [MSON DOM Elements](#mson-dom-elements)
15-
- [MSON Element (Element)](#mson-element-element)
16-
- [Properties](#properties)
17-
- [Boolean Type (Boolean Element)](#boolean-type-boolean-element)
18-
- [String Type (String Element)](#string-type-string-element)
19-
- [Number Type (Number Element)](#number-type-number-element)
20-
- [Array Type (Array Element)](#array-type-array-element)
21-
- [Object Type (Object Element)](#object-type-object-element)
22-
- [Enum Type (MSON Element)](#enum-type-mson-element)
23-
- [Properties](#properties)
24-
- [Examples](#examples)
25-
- [Examples](#examples)
26-
- [Anonymous Object Type](#anonymous-object-type)
27-
- [Type Attributes](#type-attributes)
28-
- [Default Value](#default-value)
29-
- [One Of](#one-of)
30-
- [Mixin](#mixin)
31-
- [Named Type](#named-type)
32-
9+
- [Content](#content)
10+
- [About this Document](#about-this-document)
11+
- [Expanded Element](#expanded-element)
12+
- [Base Element](#base-element)
13+
- [Type comparison](#type-comparison)
14+
- [MSON Refract Elements](#mson-refract-elements)
15+
- [MSON Element (Element)](#mson-element-element)
16+
- [Properties](#properties)
17+
- [Boolean Type (Boolean Element)](#boolean-type-boolean-element)
18+
- [String Type (String Element)](#string-type-string-element)
19+
- [Number Type (Number Element)](#number-type-number-element)
20+
- [Array Type (Array Element)](#array-type-array-element)
21+
- [Object Type (Object Element)](#object-type-object-element)
22+
- [Enum Type (MSON Element)](#enum-type-mson-element)
23+
- [Properties](#properties)
24+
- [Examples](#examples)
25+
- [Examples](#examples)
26+
- [Anonymous Object Type](#anonymous-object-type)
27+
- [Type Attributes](#type-attributes)
28+
- [Default Value](#default-value)
29+
- [One Of](#one-of)
30+
- [Mixin](#mixin)
31+
- [Named Type](#named-type)
32+
- [Variable Value](#variable-value)
33+
- [Variable Property Name](#variable-property-name)
34+
- [Variable Type Name](#variable-type-name)
3335
<!-- /TOC -->
3436

3537
## About this Document
@@ -46,15 +48,15 @@ MSON is built around the idea of defining recursive data structures. To provide
4648

4749
By default, Refract does not enforce inheritance of data, though element defintions are inherited from the defined element types. To inherit data in Refract, the `extend` element is used to merge one or more elements into a final element. In the MSON namespace, however, when the data is defined, it inherits data from the element definition. MSON itself uses inheritance this way, and the MSON Refract namespace mimics the behavior to provide simplicity and consistency across MSON representations.
4850

49-
Often, before an MSON DOM can be processed, referenced _Named Types_ have to be resolved. Resolving references to _Named Types_ is tedious and error prone. As such an MSON processor can resolve references to produce a complete MSON DOM. That is, a DOM that does not include unresolved references to other data structures. This is referred to as _reference expansion_ or simply _expansion_.
51+
Often, before an MSON Refract can be processed, referenced _Named Types_ have to be resolved. Resolving references to _Named Types_ is tedious and error prone. As such an MSON processor can resolve references to produce a complete MSON Refract. That is, a Refract that does not include unresolved references to other data structures. This is referred to as _reference expansion_ or simply _expansion_.
5052

5153
In other words, an expanded element is one that does not contain any _Identifier_ (defined below) referencing any other elements than those defined in MSON namespaces.
5254

53-
The expanded DOM MUST, however, keep the track of what data structure was expanded and what from where.
55+
The expanded Refract MUST, however, keep the track of what data structure was expanded and what from where.
5456

5557
## Base Element
5658

57-
In MSON, every data structure is a sub-type of another data structure, and, therefore, it is directly or indirectly derived from one of the MSON _Base Types_. This is expressed as an inheritance of elements in MSON DOM. Where the predecessor of an element is referred to as element's _Base Element_.
59+
In MSON, every data structure is a sub-type of another data structure, and, therefore, it is directly or indirectly derived from one of the MSON _Base Types_. This is expressed as an inheritance of elements in MSON Refract. Where the predecessor of an element is referred to as element's _Base Element_.
5860

5961
Note: Not every MSON _Base Type_ is presented in Refract primitive types and vice versa – see the table below.
6062

@@ -70,15 +72,15 @@ Note: Not every MSON _Base Type_ is presented in Refract primitive types and vic
7072
| object | Object Element | object | Object Type |
7173
| null | Null Element | - | - |
7274

73-
# MSON DOM Elements
75+
# MSON Refract Elements
7476

75-
## MSON Element (Element[*T*])
77+
## MSON Element (Element)
7678

7779
Base element for every MSON element.
7880

7981
The MSON Element adds attributes representing MSON _Type Definition_ and _Type Sections_.
8082

81-
Note: In MSON DOM _Nested Member Types_ _Type Section_ is the `content` of the element.
83+
Note: In MSON Refract _Nested Member Types_ _Type Section_ is the `content` of the element.
8284

8385
### Properties
8486

@@ -91,21 +93,23 @@ Note: In MSON DOM _Nested Member Types_ _Type Section_ is the `content` of the e
9193
- sample - The `content` value is a sample value.
9294
- default - The `content` value is a default value.
9395

94-
- `variable` (boolean) - The `content` value is a _Variable Value_
96+
- `variable` (boolean)
97+
98+
The `content` value is either a _Variable Type Name_, or _Variable Property Name_.
9599

96-
The `content` value is either a _Variable Type Name_, _Variable Value_ or _Variable Property Name_.
100+
Note, if the `content` is a _Variable Value_ the `sample` type attribute
101+
should be used instead (see `typeAttributes`).
97102

98-
- `sample` (array[T]) - Alternative sample value for _Member Types_
103+
- `sample` (array) - Alternative sample value for _Member Types_
99104

100105
The type of items in `sample` array attribute MUST match the type of element's `content`.
101106

102-
- `default` (T) - Default value for _Member Types_
107+
- `default` - Default value for _Member Types_
103108

104109
The type of of `default` attribute MUST match the type of element's `content`.
105110

106111
- `validation` - Not used, reserved for a future use
107112

108-
- `content` (T)
109113

110114
## Boolean Type (Boolean Element)
111115

@@ -146,7 +150,7 @@ Enumeration type. Exclusive list of possible elements. The elements in content's
146150
- green
147151
```
148152

149-
#### MSON DOM
153+
#### MSON Refract
150154

151155
```json
152156
{
@@ -182,7 +186,7 @@ Enumeration type. Exclusive list of possible elements. The elements in content's
182186
- id: 42
183187
```
184188

185-
#### MSON DOM
189+
#### MSON Refract
186190

187191
```json
188192
{
@@ -207,7 +211,7 @@ Enumeration type. Exclusive list of possible elements. The elements in content's
207211
- id: 42 (required, fixed)
208212
```
209213

210-
#### MSON DOM
214+
#### MSON Refract
211215

212216
```json
213217
{
@@ -239,7 +243,7 @@ Enumeration type. Exclusive list of possible elements. The elements in content's
239243
- default: 0
240244
```
241245

242-
#### MSON DOM
246+
#### MSON Refract
243247

244248
```json
245249
{
@@ -270,7 +274,7 @@ Enumeration type. Exclusive list of possible elements. The elements in content's
270274
- province
271275
```
272276

273-
#### MSON DOM
277+
#### MSON Refract
274278

275279
```json
276280
{
@@ -322,7 +326,7 @@ Enumeration type. Exclusive list of possible elements. The elements in content's
322326
- Include User
323327
```
324328

325-
#### MSON DOM
329+
#### MSON Refract
326330

327331
Using the `ref` element to reference an the content of an element.
328332

@@ -386,7 +390,7 @@ Description is here! Properties to follow.
386390
- street
387391
```
388392

389-
#### MSON DOM
393+
#### MSON Refract
390394

391395
```json
392396
{
@@ -409,6 +413,8 @@ Description is here! Properties to follow.
409413

410414
### Referencing & Expansion
411415

416+
#### MSON
417+
412418
```markdown
413419
# User (object)
414420
- name
@@ -417,6 +423,8 @@ Description is here! Properties to follow.
417423
- id
418424
```
419425

426+
#### MSON Refract
427+
420428
```json
421429
{
422430
"element": "object",
@@ -451,7 +459,7 @@ Description is here! Properties to follow.
451459
}
452460
```
453461

454-
#### Expanded
462+
#### Expanded MSON Refract
455463

456464
```json
457465
{
@@ -489,6 +497,63 @@ Description is here! Properties to follow.
489497
}
490498
```
491499

500+
### Variable Value
501+
502+
#### MSON
503+
504+
```markdown
505+
- p: *42*
506+
```
507+
508+
#### MSON Refract
509+
510+
```json
511+
["object", {}, {}, [
512+
["string", {"name": "p"}, {"typeAttributes": ["sample"]}, 42]
513+
]]
514+
```
515+
516+
### Variable Property Name
517+
518+
#### MSON
519+
520+
```markdown
521+
- *rel (Relation)*
522+
```
523+
524+
#### MSON Refract
525+
526+
```json
527+
["object", {}, {}, [
528+
["string",
529+
{"name": ["Relation", {}, {"variable": true}, "rel" ] },
530+
{},
531+
null]
532+
]]
533+
```
534+
535+
### Variable Type Name
536+
537+
**Proposal – not yet implemented**
538+
539+
Note this needs an introduction of a new MSON namespace element for any type - `generic`.
540+
541+
#### MSON
542+
543+
```markdown
544+
- p (array[*T*])
545+
```
546+
547+
#### MSON Refract
548+
549+
```json
550+
["object", {}, {}, [
551+
["array", {"name": "p"}, {}, [
552+
["generic", {}, {}, "T"]
553+
]]
554+
]]
555+
```
556+
492557
---
493558

494559
[Refract]: https://github.com/refractproject/refract-spec/blob/master/refract-spec.md

0 commit comments

Comments
 (0)