cds-numberrange-plugin
A CAP plugin that fills an annotated CDS element with the next number from a named range, optionally with prefix, suffix and padding, keeping the counter in a database entity it adds to the model.
The field in question is the one a business user reads as a document number: an integer that counts up, optionally carrying a prefix or a suffix and padded to a fixed width with a character you choose. A range is declared under cds in package.json with a name, a start value and an increment, and the @plugin.numberrange.rangeid annotation on an element names the range it draws from. The counter is a row in plugin.numberrange.Ranges, an entity the plugin adds to your model and exposes as a projection in its own NumberRangePluginService, so the current value is readable from the service. createOnDraft decides whether a draft entity takes its number while it is still a draft or on activation, and the README notes that key fields must be configured in draft mode. Samples cover SQLite in memory, persistent SQLite and SAP HANA; testing with PostgreSQLPostgreSQLA relational database. For CAP it is the production database when the answer is not HANA, reached through an adapter that translates CDS queries into its SQL. is still on the README's list of work to do, and the README asks that fields the plugin fills are never edited by hand.
Facts
Where it sits
Who is behind it
In the atlas: maintains 1, contributes to 1@abdulbasitgmaintainer
Before choosing this
Conditions
LicenceSAP Developer License Agreement 3.2 CAP§ 1, 2, 3A cds-plugin is used with SAP CAP materials, or an artifact is explicitly identified as a CAP plugin or application.
- § 1 License. Productive customer applications are limited to SAP BTP or another SAP-licensed platform, and mass extraction to a non-SAP product is restricted except where solely required for SAP interoperability.
- § 2 Intellectual Property. The agreement retains SAP's rights in the covered materials and limits making APIs, tools or software available to third parties, while preserving ownership of customer applications subject to SAP's underlying rights.
- § 3 Artificial Intelligence Training. The agreement prohibits use of the covered materials and customer applications for training artificial-intelligence models or systems.
What it declares
Every artifact
- Type
- CDS plugin
- Origin
- Independently maintained
- Runtime
- Node.js
As a CDS plugin
- Declared for
- >=8
- Distributed through
- npm
Connections
Defining entities, their relations and the views services consume
Download
Install
npm add cds-numberrange-pluginDerived from the package name. No recipe recorded; the README has the configuration.
Learn more
- A CAP Plugin for Flexible Number Range Management: cds-numberrange-pluginA CAP Plugin for Flexible Number Range Management: cds-numberrange-pluginThe author's own plugin, and the reason given for writing it is about plugins rather than about number ranges: a year of using them convinced them that this was the way to extend CAP without leaving marks on the application. Sequential document numbers are the thing it does; keeping the host project clean is the thing it argues for.abdulbasit, published 2025-06-17abdulbasit, SAP Community
README
quoted from abdulbasitg/cds-numberrange-plugin under MIT, readcds-numberrange-plugin
This is a plugin for CAP framework to let you easily add database ranges into your applications.
Features
You can use this plugin to add auto-incremented fields into your database. There are different options to format the auto-incrementation:
- Basic Configuration allows you configure integer fields starting from specific number and increment by configured number.
- It is also possible to format the generated number with prefix, suffix characters and also pad the generated number with a 0 or any other characters.
Usage
Installing plugin with npm install
npm install cds-numberrange-plugin
In your package.json file, add the following part into the CDS node:
"cds": {
"cds-numberrange-plugin": {
"ranges": [
{
"name": "<RANGE NAME>",
"start": 1,
"increment": 1,
"createOnDraft": true,
"additionalProperties": {
"prefix": "P",
"suffix": "S",
"padCount": 10,
"padValue": "0"
}
}
]
}
}
Then, you can annotate your fields in your database schema with special @plugin.numberrange.rangeid annotation.
annotate <ENTITY> with {
<FIELD> @plugin.numberrange.rangeid: '<RANGE NAME>';
}
This annotation make this field automatically filled with range format configured in your package.json file.
Parameters:
- name: (Required) Range Name created in the database.
- start: (Required) Start index value for the range.
- increment: (Required) Increment value every time new value is created.
- createOnDraft: (Optional) true or false - Whether the next value is retrieved during draft creation or not.
- additionalProperties: (Optional) This part can be used to have additional features to create string based formatted values.
- prefix: You and add prefix characters into the generated range number.
- suffix: You can add suffix characters into the generated range number.
- padCount: You can pad generated range number with a special character.
- padValue: This parameter specifies the character to be used for padding.
Samples
samples/sample-01-sqlite-in-memory
This samples demonstrates the plugin in sqlite-in-memory database with different configuration options.
samples/sample-02-sqlite-persistent
This samples demonstrates the plugin in sqlite persistent database with different configuration options.
samples/sample-03-hana
This samples demonstrates the plugin in SAP HANA database with different configuration options.
samples/sample-04-draft
This sample demonstrates the plugin with draft activated entities. You can configure your ranges to be created either in draft mode or after draft activation. Keep in mind that key fields must be configured in draft mode.
Remarks
- Make sure you don't modify manually the field values that has been configured to use the plugin.
TODO
- Test with PostgreSQL
History
Fixes 1, Other 1
Notes
Fixed
- Add db-level locking for sequence increment operations to prevent race conditions (#15)
Chore
- Added GitHub spec-kit specifications (#14)
Features 5
Notes
Added
- Initial release of cds-numberrange-plugin
- Database-agnostic number range management for CAP framework
- Support for SQLite and SAP HANA databases
- Configurable prefix, suffix, padding, and increment options
- Draft and active creation modes
Others providing
Compare all 6 on the Data modelling page →- com.sap.cds:cds-services-bomcom.sap.cds:cds-services-bomThe Maven bill of materials for CAP Java, pinning every com.sap.cds module in a release, from the API and core runtime to the Spring Boot starters and the CQN engine, to the same version.sap official, capMaven bill of materials pinning CAP Java module versions
- @sap/cds-common-content@sap/cds-common-contentISO-standard content for CAP's common definitions — countries, languages, currencies and timezones — so a project does not seed those tables itself.sap official, capISO content for CAP's countries, languages, currencies and timezones
- @sap/cds-compiler@sap/cds-compilerCompiles CDS models to CSN, EDMX and database schemas.sap official, capCompiler from CDS models to CSN, EDMX and database schemas
- @sap/cds@sap/cdsThe CAP Node.js runtime, which compiles the CDS model, serves the services declared in it, answers generic requests before any handler runs, and loads every cds-plugin.sap official, capCAP Node.js runtime
- cap-user-infocap-user-infoResolves the createdBy and modifiedBy of a managed entity to a stored user record of email, given name and family name, and renders the two fields as links with a quickview.independent, capUser details and quickview links for createdBy and modifiedBy
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
History in the atlas
- First seen.
For your agent
- Ref
artifact:abdulbasitg-cds-numberrange-plugin- JSON
- /artifacts/abdulbasitg-cds-numberrange-plugin.json
- MCP
- Connecting an agent