Files
languageservices/workflow-parser/src/templates/schema/property-definition.ts
T

34 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-01-09 19:02:19 -05:00
import {MAPPING_PROPERTY_VALUE, TYPE, REQUIRED, DESCRIPTION} from "../template-constants";
import {TemplateToken, StringToken} from "../tokens";
import {TokenType} from "../tokens/types";
export class PropertyDefinition {
2023-01-09 19:02:19 -05:00
public readonly type: string = "";
public readonly required: boolean = false;
public readonly description: string | undefined;
public constructor(token: TemplateToken) {
if (token.templateTokenType === TokenType.String) {
2023-01-09 19:02:19 -05:00
this.type = (token as StringToken).value;
} else {
2023-01-09 19:02:19 -05:00
const mapping = token.assertMapping(MAPPING_PROPERTY_VALUE);
for (const mappingPair of mapping) {
2023-01-09 19:02:19 -05:00
const mappingKey = mappingPair.key.assertString(`${MAPPING_PROPERTY_VALUE} key`);
switch (mappingKey.value) {
case TYPE:
2023-01-09 19:02:19 -05:00
this.type = mappingPair.value.assertString(`${MAPPING_PROPERTY_VALUE} ${TYPE}`).value;
break;
case REQUIRED:
2023-01-09 19:02:19 -05:00
this.required = mappingPair.value.assertBoolean(`${MAPPING_PROPERTY_VALUE} ${REQUIRED}`).value;
break;
case DESCRIPTION:
2023-01-09 19:02:19 -05:00
this.description = mappingPair.value.assertString(`${MAPPING_PROPERTY_VALUE} ${DESCRIPTION}`).value;
break;
default:
2023-01-09 19:02:19 -05:00
mappingKey.assertUnexpectedValue(`${MAPPING_PROPERTY_VALUE} key`); // throws
}
}
}
}
}