public makeSelectAndExpandStatement()

in src/parsers/odata-parser.ts [138:180]


    public makeSelectAndExpandStatement(): ISelectAndExpand {
        if (this.query.columns.length > 0) {
            const expandList: string[] = [];
            const selectList: string[] = [];

            this.query.columns.forEach((column) => {
                const odataProperty = this.metadata[column.referenceName];
                if (odataProperty == null) {
                    NotesService.instance.newNote('warning', `Field ${column.referenceName} in the select statement does not have an OData equivalent. Leaving it out of $select.`);
                } else {
                    if (!odataProperty.type.startsWith('Edm')) {
                        // Case: Complex type that has a default property (not expanded in the list of specialProperties).
                        const defaultField = ODataMetadataParser.defaultFields[odataProperty.type];
                        if (defaultField == null) {
                            NotesService.instance.newNote('warning', `The OData datatype of field ${column.referenceName} is not supported. Leaving it out of $select.`);
                        } else {
                            expandList.push(`${odataProperty.name}($select=${defaultField.defaultFieldName})`);
                        }
                    } else if (odataProperty.name.includes('/')) {
                        // Case: Complex type expanded in the list of specialProperties.
                        // Example: Area or Iteration.
                        const stringComponents = odataProperty.name.split('/');
                        expandList.push(`${stringComponents[0]}($select=${stringComponents[1]})`);
                    } else {
                        // Case: Primitive type.
                        selectList.push(odataProperty.name);
                    }
                }
            });

            return {
                select: (selectList.length === 0 ? null : `$select=${selectList.join(', ')}`),
                expand: (expandList.length === 0 ? null : `$expand=${expandList.join(', ')}`),
            };
        } else {
            NotesService.instance.newNote(
                'info',
                `every OData query should have a select statement. Please update your query to explicitly include a select statement.
                Without a select statement, the default and unexpanded will be returned by the query.`
            );
            return null;
        }
    }