npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cap-sf-sdk/odata-transformer

v1.0.1

Published

Transforms SAP CAP CQN queries into OData v2 query strings for SuccessFactors.

Readme

@cap-sf-sdk/odata-transformer

Transform SAP CAP CQN queries into OData v2 query strings for SuccessFactors integration.

Part of the CAP SuccessFactors SDK monorepo.

🚀 Installation

# Install this package individually
npm install @cap-sf-sdk/odata-transformer

# Or install the complete SDK
npm install @cap-sf-sdk/core

📖 Overview

The OData Transformer converts SAP CAP CQN (Common Query Notation) objects into OData v2 query strings, making it easy to integrate CAP services with SuccessFactors APIs.

Supported OData Parameters

  • $select (from CQN columns)
  • $filter (from CQN where conditions)
  • $orderby (from CQN orderBy)
  • $top / $skip (from CQN limit)
  • $expand (from CQN columns with expand)
  • SuccessFactors date parameters: fromDate, toDate, asOfDate

🧩 Usage

Basic Usage

import { cqnToOData } from '@cap-sf-sdk/odata-transformer'

// In your CAP service handler
this.on('READ', 'Employees', async (req) => {
  const odataQuery = cqnToOData(req.query, {
    fromDate: '2024-01-01',
    toDate: '2024-12-31',
  })

  console.log(odataQuery)
  // Result: $format=json&$select=externalCode,startDate&$filter=status eq 'A'&fromDate=2024-01-01&toDate=2024-12-31

  // Use with SuccessFactors API
  const response = await fetch(`https://api.successfactors.com/odata/v2/PerPerson?${odataQuery}`)
})

Advanced Examples

// Complex query with joins and filters
const complexQuery = {
  columns: [
    { ref: ['externalCode'] },
    { ref: ['startDate'] },
    { ref: ['companyNav'], expand: ['code', 'name'] },
  ],
  where: [
    'and',
    [{ ref: ['status'] }, '=', { val: 'A' }],
    [{ ref: ['startDate'] }, '>=', { val: '2024-01-01' }],
  ],
  orderBy: [{ ref: ['startDate'], sort: 'desc' }],
  limit: { rows: { val: 100 }, offset: { val: 0 } },
}

const queryString = cqnToOData(complexQuery, { asOfDate: '2024-06-01' })
// Result: $format=json&$select=externalCode,startDate,companyNav($select=code,name)&$filter=status eq 'A' and startDate ge '2024-01-01'&$orderby=startDate desc&$top=100&$skip=0&asOfDate=2024-06-01

📅 SuccessFactors Date Parameters

The transformer supports SuccessFactors-specific date parameters with intelligent logic:

Date Parameter Rules

  • asOfDate is exclusive: If provided, fromDate and toDate are ignored
  • fromDate and toDate can be used individually or together
// asOfDate takes precedence
cqnToOData(
  { columns: [{ ref: ['id'] }] },
  {
    asOfDate: '2024-06-01',
    fromDate: '2024-01-01', // Ignored
    toDate: '2024-12-31', // Ignored
  }
)
// → ...&asOfDate=2024-06-01

// fromDate only
cqnToOData(query, { fromDate: '2024-02-01' })
// → ...&fromDate=2024-02-01

// toDate only
cqnToOData(query, { toDate: '2024-03-01' })
// → ...&toDate=2024-03-01

// Both fromDate and toDate
cqnToOData(query, { fromDate: '2024-01-01', toDate: '2024-12-31' })
// → ...&fromDate=2024-01-01&toDate=2024-12-31

🔧 API Reference

cqnToOData(cqn, options?)

Converts a CAP CQN query to an OData v2 query string.

Parameters:

  • cqn: CqnSelect - The CAP CQN query object
  • options?: ODataOptions - Optional SuccessFactors parameters

Returns: string - The OData query string

Types:

interface ODataOptions {
  fromDate?: string // YYYY-MM-DD format
  toDate?: string // YYYY-MM-DD format
  asOfDate?: string // YYYY-MM-DD format (exclusive)
}

interface CqnSelect {
  columns?: Column[]
  where?: Condition[]
  orderBy?: OrderBy[]
  limit?: { rows?: { val: number }; offset?: { val: number } }
}

🏗️ Project Structure

src/
├── index.ts              # Main entry point & cqnToOData function
├── types.ts              # TypeScript type definitions
├── builders/             # Query string builders
│   └── buildQueryString.ts
├── parsers/              # CQN to OData parsers
│   ├── select.ts         # $select parameter
│   ├── filter.ts         # $filter parameter
│   ├── orderby.ts        # $orderby parameter
│   ├── limit.ts          # $top/$skip parameters
│   └── expand.ts         # $expand parameter
└── utils/                # Utility functions
    └── encode.ts         # URL encoding helpers

🧪 Testing

# Run tests for this package
npm test

# Run tests from package directory
cd packages/odata-transformer
npm test

# Coverage report
npm run test:coverage

📚 Related Packages

🤝 Contributing

See the main repository for contribution guidelines.

📄 License

MIT - see LICENSE for details.

Generated API reference is available locally after running the docs task. It uses TypeDoc to extract JSDoc from the TypeScript source.

Generate docs:

npm run docs

This produces static HTML in the docs/ directory. Open docs/index.html in a browser.