Skip to content

Commit d18721a

Browse files
authored
Use mappings for data model options and attributes (#800)
* Use mappings for data model options and attributes * Specify Options a bit more explicitly
1 parent 380cc47 commit d18721a

File tree

2 files changed

+22
-45
lines changed

2 files changed

+22
-45
lines changed

spec/data-model/README.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,34 +180,31 @@ interface LiteralExpression {
180180
type: "expression";
181181
arg: Literal;
182182
annotation?: FunctionAnnotation | UnsupportedAnnotation;
183-
attributes: Attribute[];
183+
attributes: Attributes;
184184
}
185185

186186
interface VariableExpression {
187187
type: "expression";
188188
arg: VariableRef;
189189
annotation?: FunctionAnnotation | UnsupportedAnnotation;
190-
attributes: Attribute[];
190+
attributes: Attributes;
191191
}
192192

193193
interface FunctionExpression {
194194
type: "expression";
195195
arg?: never;
196196
annotation: FunctionAnnotation;
197-
attributes: Attribute[];
197+
attributes: Attributes;
198198
}
199199

200200
interface UnsupportedExpression {
201201
type: "expression";
202202
arg?: never;
203203
annotation: UnsupportedAnnotation;
204-
attributes: Attribute[];
204+
attributes: Attributes;
205205
}
206206

207-
interface Attribute {
208-
name: string;
209-
value?: Literal | VariableRef;
210-
}
207+
type Attributes = Map<string, Literal | VariableRef | true>;
211208
```
212209

213210
## Expressions
@@ -237,19 +234,17 @@ interface VariableRef {
237234
A `FunctionAnnotation` represents a _function_ _annotation_.
238235
The `name` does not include the `:` starting sigil.
239236

240-
Each _option_ is represented by an `Option`.
237+
`Options` is a key-value mapping containing options,
238+
and is used to represent the _annotation_ and _markup_ _options_.
241239

242240
```ts
243241
interface FunctionAnnotation {
244242
type: "function";
245243
name: string;
246-
options: Option[];
244+
options: Options;
247245
}
248246

249-
interface Option {
250-
name: string;
251-
value: Literal | VariableRef;
252-
}
247+
type Options = Map<string, Literal | VariableRef>;
253248
```
254249

255250
An `UnsupportedAnnotation` represents a
@@ -276,15 +271,15 @@ A `Markup` object has a `kind` of either `"open"`, `"standalone"`, or `"close"`,
276271
each corresponding to _open_, _standalone_, and _close_ _markup_.
277272
The `name` in these does not include the starting sigils `#` and `/`
278273
or the ending sigil `/`.
279-
The optional `options` for markup use the same `Option` as `FunctionAnnotation`.
274+
The `options` for markup use the same key-value mapping as `FunctionAnnotation`.
280275

281276
```ts
282277
interface Markup {
283278
type: "markup";
284279
kind: "open" | "standalone" | "close";
285280
name: string;
286-
options: Option[];
287-
attributes: Attribute[];
281+
options: Options;
282+
attributes: Attributes;
288283
}
289284
```
290285

spec/data-model/message.json

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,18 @@
2121
},
2222
"required": ["type", "name"]
2323
},
24+
"literal-or-variable": {
25+
"oneOf": [{ "$ref": "#/$defs/literal" }, { "$ref": "#/$defs/variable" }]
26+
},
27+
2428
"options": {
25-
"type": "array",
26-
"items": {
27-
"type": "object",
28-
"properties": {
29-
"name": { "type": "string" },
30-
"value": {
31-
"oneOf": [
32-
{ "$ref": "#/$defs/literal" },
33-
{ "$ref": "#/$defs/variable" }
34-
]
35-
}
36-
},
37-
"required": ["name", "value"]
38-
}
29+
"type": "object",
30+
"additionalProperties": { "$ref": "#/$defs/literal-or-variable" }
3931
},
4032
"attributes": {
41-
"type": "array",
42-
"items": {
43-
"type": "object",
44-
"properties": {
45-
"name": { "type": "string" },
46-
"value": {
47-
"oneOf": [
48-
{ "$ref": "#/$defs/literal" },
49-
{ "$ref": "#/$defs/variable" }
50-
]
51-
}
52-
},
53-
"required": ["name"]
33+
"type": "object",
34+
"additionalProperties": {
35+
"oneOf": [{ "$ref": "#/$defs/literal-or-variable" }, { "const": true }]
5436
}
5537
},
5638

@@ -129,7 +111,7 @@
129111
"type": "object",
130112
"properties": {
131113
"type": { "const": "markup" },
132-
"kind": { "oneOf": [ "open", "standalone", "close" ] },
114+
"kind": { "oneOf": ["open", "standalone", "close"] },
133115
"name": { "type": "string" },
134116
"options": { "$ref": "#/$defs/options" },
135117
"attributes": { "$ref": "#/$defs/attributes" }

0 commit comments

Comments
 (0)