Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@sap-ux/cds-annotation-parser
Advanced tools
Readme
Npm
npm install --save @sap-ux/cds-annotation-parser
Yarn
yarn add @sap-ux/cds-annotation-parser
Pnpm
pnpm add @sap-ux/cds-annotation-parser
Examples of how to use CDS annotation parsing and abstract syntax tree (AST) node search functions.
import { parse, findAnnotationNode, getAstNodes, getNode } from '@sap-ux/cds-annotation-parser';
const ast = parse(`
UI.LineItem #table1 : [
{
$type: 'UI.DataField',
value: some.path,
Label: 'Sample column'
}
]';
`);
if (ast !== undefined) {
// Expected pathToLabel: "/value/items/0/properties/2/value"
const pathToLabel = findAnnotationNode(ast, {
position: { line: 5, character: 15 },
includeDelimiterCharacters: true
});
// An array of nodes matching each segment of the path.
const nodes = getAstNodes(ast, pathToLabel);
const serializedNodes = nodes.map((n) =>
Array.isArray(n) ? '<array of child elements>' : typeof n === 'object' ? `Node of type '${n.type}'` : n
);
/* Expected serializedNodes:
[
"Node of type 'collection'",
"<array of child elements>",
"Node of type 'record'",
"<array of child elements>",
"Node of type 'record-property'",
"Node of type 'string'",
]
*/
const termNode = getNode(ast, '/term');
if (termNode.type === 'path') {
// expected termName: "UI.LineItem"
const termName = termNode.value;
}
const qualifierNode = getNode(ast, '/qualifier');
if (qualifierNode.type === 'qualifier') {
// expected qualifier: "table1"
const qualifier = qualifierNode.value;
}
const propertyValueNode = getNode(ast, '/value/items/0/properties/1/value');
if (propertyValueNode.type === 'path') {
// expected value: "some.path"
const value = propertyValueNode.value;
}
}
OData annotations CAP CDS
FAQs
Annotation Parser for CDS
The npm package @sap-ux/cds-annotation-parser receives a total of 1 weekly downloads. As such, @sap-ux/cds-annotation-parser popularity was classified as not popular.
We found that @sap-ux/cds-annotation-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.