Skip to content

Switch from compiling Notification Types to Event Types#125

Draft
eric-pSAP wants to merge 5 commits into
mainfrom
eventTypes
Draft

Switch from compiling Notification Types to Event Types#125
eric-pSAP wants to merge 5 commits into
mainfrom
eventTypes

Conversation

@eric-pSAP
Copy link
Copy Markdown
Contributor

Plug-in currently builds and compiles from a user-written json file. This is slow and inefficient. Types also (automatically) will come from event types from cds files where events are annotated with @notification (json file remains backwards compatible).

@hyperspace-insights
Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Switch Notification Type Derivation from JSON to CDS Event Annotations

New Features

✨ Notification types can now be automatically derived from CDS event definitions annotated with @notification, eliminating the need to maintain a separate JSON types file. The JSON file remains supported for backwards compatibility and is merged with types extracted from the model.

A new cds.on("loaded", ...) hook injects a recipients element into annotated events that don't already define one. The build plugin now compiles notification types directly from the CDS model (supplemented by an optional JSON file) instead of simply copying a static JSON file.

Changes

  • cds-plugin.js: Added a loaded event hook to auto-inject recipients into @notification-annotated events. Updated the served handler to load notification types from both the CDS model (notificationTypesFromModel) and the optional JSON types file, merging them together. Removed semicolons for consistent code style.
  • lib/build.js: Refactored the build plugin to derive notification types from the CDS model using notificationTypesFromModel and merge with any configured JSON file, then write the result as notification-types.json. Simplified hasTask() to check only for a notifications config entry. Removed unused copy/exists imports.
  • lib/compile.js (new): Introduced notificationTypesFromModel(model) which iterates CDS definitions, finds @notification-annotated events, and maps their annotations (templates, delivery channels, semantic objects, etc.) to the notification type JSON structure.
  • tests/bookshop/srv/notifications.cds (new): Added a sample CDS file defining a BookOrdered event with full @notification annotations for use in integration tests.
  • tests/bookshop/srv/notification-types.json: Slimmed down to only contain the BookReturned type (JSON-only fallback), as BookOrdered is now sourced from the CDS model.
  • tests/integration/bookshop.test.js: Added a new test asserting that CDS-derived and JSON-derived notification types are merged correctly at startup. Replaced semicolons with no-semicolon style.
  • tests/unit/lib/compile.test.js (new): Comprehensive unit tests for notificationTypesFromModel, covering edge cases like missing annotations, namespace stripping, delivery channel handling, and mixed models.
  • tests/unit/lib/plugin.test.js (new): Unit tests for the loaded hook's recipients injection logic.
  • tests/unit/lib/notificationTypes.test.js, tests/unit/lib/utils.test.js, tests/unit/lib/notifications.test.js, tests/unit/srv/notifyToRest.test.js, tests/unit/lib/content-deployment.test.js: Replaced it(...) with test(...) and removed semicolons for consistent style.

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.20.43

  • Correlation ID: 01b9afab-28a3-4551-8db9-7abecd2e74cc
  • LLM: anthropic--claude-4.6-sonnet
  • Output Template: Default Template
  • Summary Prompt: Default Prompt
  • Event Trigger: pull_request.opened
  • File Content Strategy: Full file content

Copy link
Copy Markdown
Contributor

@hyperspace-insights hyperspace-insights Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces a useful feature — deriving notification types from CDS model annotations rather than requiring a hand-authored JSON file. However, there are several substantive issues: a redundant cds.load during startup that should use the already-available cds.model, a potential TypeError in resolveEnum when the channel value is not a string, a silent data loss when the struct form of @notification is used instead of flat annotation keys, and unit tests that bypass cds.reflect() and therefore do not accurately validate the production code path. Please address these before merging.

PR Bot Information

Version: 1.20.43

  • File Content Strategy: Full file content
  • Event Trigger: pull_request.opened
  • Correlation ID: 01b9afab-28a3-4551-8db9-7abecd2e74cc
  • LLM: anthropic--claude-4.6-sonnet

Comment thread lib/compile.js Outdated
Comment thread lib/compile.js
Comment thread cds-plugin.js
Comment thread lib/build.js
Comment thread tests/unit/lib/compile.test.js
This was referenced May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant