From 5108a5f75ad429b5c5de74c266b2d75c2cd724e6 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Wed, 22 May 2024 16:22:24 +0300 Subject: [PATCH 1/2] Use mappings for data model options and attributes --- spec/data-model/README.md | 28 +++++++++++--------------- spec/data-model/message.json | 38 ++++++++++-------------------------- 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/spec/data-model/README.md b/spec/data-model/README.md index 250ec9613f..a1647b2c37 100644 --- a/spec/data-model/README.md +++ b/spec/data-model/README.md @@ -180,34 +180,31 @@ interface LiteralExpression { type: "expression"; arg: Literal; annotation?: FunctionAnnotation | UnsupportedAnnotation; - attributes: Attribute[]; + attributes: Attributes; } interface VariableExpression { type: "expression"; arg: VariableRef; annotation?: FunctionAnnotation | UnsupportedAnnotation; - attributes: Attribute[]; + attributes: Attributes; } interface FunctionExpression { type: "expression"; arg?: never; annotation: FunctionAnnotation; - attributes: Attribute[]; + attributes: Attributes; } interface UnsupportedExpression { type: "expression"; arg?: never; annotation: UnsupportedAnnotation; - attributes: Attribute[]; + attributes: Attributes; } -interface Attribute { - name: string; - value?: Literal | VariableRef; -} +type Attributes = Map; ``` ## Expressions @@ -237,19 +234,16 @@ interface VariableRef { A `FunctionAnnotation` represents a _function_ _annotation_. The `name` does not include the `:` starting sigil. -Each _option_ is represented by an `Option`. +Each _option_ is represented by an `Options` key-value mapping. ```ts interface FunctionAnnotation { type: "function"; name: string; - options: Option[]; + options: Options; } -interface Option { - name: string; - value: Literal | VariableRef; -} +type Options = Map; ``` An `UnsupportedAnnotation` represents a @@ -276,15 +270,15 @@ A `Markup` object has a `kind` of either `"open"`, `"standalone"`, or `"close"`, each corresponding to _open_, _standalone_, and _close_ _markup_. The `name` in these does not include the starting sigils `#` and `/` or the ending sigil `/`. -The optional `options` for markup use the same `Option` as `FunctionAnnotation`. +The optional `options` for markup use the same key-value mapping as `FunctionAnnotation`. ```ts interface Markup { type: "markup"; kind: "open" | "standalone" | "close"; name: string; - options: Option[]; - attributes: Attribute[]; + options: Options; + attributes: Attributes; } ``` diff --git a/spec/data-model/message.json b/spec/data-model/message.json index 86b7ea7b10..77fc3a4f4d 100644 --- a/spec/data-model/message.json +++ b/spec/data-model/message.json @@ -21,36 +21,18 @@ }, "required": ["type", "name"] }, + "literal-or-variable": { + "oneOf": [{ "$ref": "#/$defs/literal" }, { "$ref": "#/$defs/variable" }] + }, + "options": { - "type": "array", - "items": { - "type": "object", - "properties": { - "name": { "type": "string" }, - "value": { - "oneOf": [ - { "$ref": "#/$defs/literal" }, - { "$ref": "#/$defs/variable" } - ] - } - }, - "required": ["name", "value"] - } + "type": "object", + "additionalProperties": { "$ref": "#/$defs/literal-or-variable" } }, "attributes": { - "type": "array", - "items": { - "type": "object", - "properties": { - "name": { "type": "string" }, - "value": { - "oneOf": [ - { "$ref": "#/$defs/literal" }, - { "$ref": "#/$defs/variable" } - ] - } - }, - "required": ["name"] + "type": "object", + "additionalProperties": { + "oneOf": [{ "$ref": "#/$defs/literal-or-variable" }, { "const": true }] } }, @@ -129,7 +111,7 @@ "type": "object", "properties": { "type": { "const": "markup" }, - "kind": { "oneOf": [ "open", "standalone", "close" ] }, + "kind": { "oneOf": ["open", "standalone", "close"] }, "name": { "type": "string" }, "options": { "$ref": "#/$defs/options" }, "attributes": { "$ref": "#/$defs/attributes" } From 686cd8509dee1bbccba702a677ace8a313bdfee0 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Wed, 22 May 2024 17:42:55 +0300 Subject: [PATCH 2/2] Specify Options a bit more explicitly --- spec/data-model/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/data-model/README.md b/spec/data-model/README.md index a1647b2c37..131f2f1f2e 100644 --- a/spec/data-model/README.md +++ b/spec/data-model/README.md @@ -234,7 +234,8 @@ interface VariableRef { A `FunctionAnnotation` represents a _function_ _annotation_. The `name` does not include the `:` starting sigil. -Each _option_ is represented by an `Options` key-value mapping. +`Options` is a key-value mapping containing options, +and is used to represent the _annotation_ and _markup_ _options_. ```ts interface FunctionAnnotation { @@ -270,7 +271,7 @@ A `Markup` object has a `kind` of either `"open"`, `"standalone"`, or `"close"`, each corresponding to _open_, _standalone_, and _close_ _markup_. The `name` in these does not include the starting sigils `#` and `/` or the ending sigil `/`. -The optional `options` for markup use the same key-value mapping as `FunctionAnnotation`. +The `options` for markup use the same key-value mapping as `FunctionAnnotation`. ```ts interface Markup {