@sap/cds-dk 9.2.1 → 9.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/bin/bind.js +5 -8
  3. package/bin/up.js +19 -13
  4. package/lib/bind/cf.js +4 -0
  5. package/lib/bind/k8s.js +21 -0
  6. package/lib/bind/plugin.js +9 -0
  7. package/lib/build/buildTaskProviderFactory.js +8 -14
  8. package/lib/build/constants.js +1 -0
  9. package/lib/build/index.js +17 -2
  10. package/lib/build/plugin.js +5 -7
  11. package/lib/build/provider/hana/index.js +4 -4
  12. package/lib/env/schemas/cds-rc.js +2 -2
  13. package/lib/import/odata/metadataconverter/MetadataConverter.js +5 -0
  14. package/lib/init/constants.js +3 -2
  15. package/lib/init/projectReader.js +17 -5
  16. package/lib/init/template/ams/index.js +1 -2
  17. package/lib/init/template/approuter/files/containerize.yaml.hbs +1 -1
  18. package/lib/init/template/approuter/index.js +1 -1
  19. package/lib/init/template/data/as-csv.js +10 -7
  20. package/lib/init/template/data/as-json.js +7 -4
  21. package/lib/init/template/enterprise-messaging/index.js +3 -2
  22. package/lib/init/template/enterprise-messaging-shared/index.js +3 -2
  23. package/lib/init/template/extension/files/.base/index.cds +6 -6
  24. package/lib/init/template/extension/index.js +5 -5
  25. package/lib/init/template/github-actions/files/kyma-info/action.yaml +1 -1
  26. package/lib/init/template/github-actions/files/kyma-setup/action.yaml +1 -9
  27. package/lib/init/template/github-actions/files/workflows/cf.yaml.hbs +25 -12
  28. package/lib/init/template/github-actions/files/workflows/kyma.yaml.hbs +8 -5
  29. package/lib/init/template/github-actions/files/workflows/release.yaml.hbs +30 -0
  30. package/lib/init/template/github-actions/files/workflows/test.yaml.hbs +6 -3
  31. package/lib/init/template/github-actions/index.js +28 -14
  32. package/lib/init/template/hana/index.js +2 -1
  33. package/lib/init/template/html5-repo/files/mta.yaml.hbs +5 -1
  34. package/lib/init/template/html5-repo/files/package.json.hbs +1 -1
  35. package/lib/init/template/html5-repo/index.js +27 -19
  36. package/lib/init/template/ias/files/mta.yaml.hbs +5 -4
  37. package/lib/init/template/ias/files/values.yaml.hbs +41 -40
  38. package/lib/init/template/mta/files/mta.yaml.hbs +1 -1
  39. package/lib/init/template/mta/files/package.json +1 -1
  40. package/lib/init/template/multitenancy/files/mta.yaml.hbs +1 -1
  41. package/lib/init/template/multitenancy/files/values.yaml.hbs +1 -1
  42. package/lib/init/template/nodejs/files/.vscode/extensions.json +0 -1
  43. package/lib/init/template/nodejs/files/package.json.hbs +3 -9
  44. package/lib/init/template/portal/files/mta.yaml.hbs +5 -1
  45. package/lib/init/template/portal/index.js +0 -1
  46. package/lib/init/template/sample/files/app/_i18n/i18n.properties +15 -0
  47. package/lib/init/template/sample/files/app/_i18n/i18n_de.properties +15 -0
  48. package/lib/init/template/sample/files/app/admin-books/fiori-service.cds +14 -15
  49. package/lib/init/template/sample/files/app/browse/fiori-service.cds +44 -44
  50. package/lib/init/template/sample/files/app/common.cds +99 -84
  51. package/lib/init/template/sample/files/db/schema.cds +22 -17
  52. package/lib/init/template/sample/files/package.json.hbs +1 -3
  53. package/lib/init/template/sample/files/srv/admin-service.cds +4 -3
  54. package/lib/init/template/sample/files/srv/cat-service.cds +28 -11
  55. package/lib/init/template/tiny-sample/files/nodejs/db/schema.cds +3 -3
  56. package/lib/init/template/typescript/files/package.json +1 -1
  57. package/lib/init/template/ui5/index.js +22 -0
  58. package/lib/init/template/xsuaa/files/mta.yaml.hbs +2 -1
  59. package/lib/init/template/xsuaa/index.js +7 -5
  60. package/lib/lint/eslintHelp.json +5 -3
  61. package/npm-shrinkwrap.json +15 -15
  62. package/package.json +1 -1
  63. package/lib/init/template/github-actions/files/cf-github-deploy/action.yaml +0 -48
  64. package/lib/init/template/sample/files/javascript/admin-service.js.hbs +0 -24
  65. package/lib/init/template/sample/files/javascript/cat-service.js.hbs +0 -43
  66. package/lib/init/template/sample/files/typescript/admin-service.ts.hbs +0 -16
  67. package/lib/init/template/sample/files/typescript/cat-service.ts.hbs +0 -38
@@ -1,20 +1,37 @@
1
- using { sap.capire.bookshop as my } from '../db/schema';
1
+ using {sap.capire.bookshop as my} from '../db/schema';
2
+
2
3
  service CatalogService {
3
4
 
4
5
  /** For displaying lists of Books */
5
- @readonly entity ListOfBooks as projection on Books
6
- excluding { descr };
6
+ @readonly
7
+ entity ListOfBooks as
8
+ projection on Books
9
+ excluding {
10
+ descr
11
+ };
7
12
 
8
13
  /** For display in details pages */
9
- @readonly entity Books as projection on my.Books { *,
10
- author.name as author
11
- } excluding { createdBy, modifiedBy };
14
+ @readonly
15
+ entity Books as
16
+ projection on my.Books {
17
+ *,
18
+ author.name as author
19
+ }
20
+ excluding {
21
+ createdBy,
22
+ modifiedBy
23
+ };
12
24
 
13
25
  @requires: 'authenticated-user'
14
- action submitOrder (
15
- book : Books:ID @mandatory,
16
- quantity: Integer @mandatory
17
- ) returns { stock: Integer };
26
+ action submitOrder(book : Books : ID @mandatory,
27
+ quantity : Integer @mandatory
28
+ ) returns {
29
+ stock : Integer
30
+ };
18
31
 
19
- event OrderedBook : { book: Books:ID; quantity: Integer; buyer: String };
32
+ event OrderedBook : {
33
+ book : Books : ID;
34
+ quantity : Integer;
35
+ buyer : String
36
+ };
20
37
  }
@@ -1,7 +1,7 @@
1
1
  namespace my.bookshop;
2
2
 
3
3
  entity Books {
4
- key ID : Integer;
5
- title : String;
6
- stock : Integer;
4
+ key ID : Integer;
5
+ title : String;
6
+ stock : Integer;
7
7
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "devDependencies": {
3
- "@cap-js/cds-types": "^0.13.0",
3
+ "@cap-js/cds-types": "^0.14.0",
4
4
  "@types/node": "^22.0.0",
5
5
  "tsx": "^4",
6
6
  "typescript": "^5"
@@ -0,0 +1,22 @@
1
+ const cds = require('../../../cds'), { exists, fs, path } = cds.utils
2
+ const { readProject } = require('../../projectReader')
3
+ const { merge } = require('../../merge')
4
+
5
+ module.exports = class extends require('../../plugin') {
6
+
7
+ static hasInProduction() {
8
+ const startPage = path.join(cds.root, cds.env.folders.app, 'index.html')
9
+ const packageJson = path.join(cds.root, 'package.json')
10
+ return exists(startPage) && fs.readFileSync(startPage).includes('https://sapui5') ||
11
+ exists(packageJson) && fs.readFileSync(packageJson).includes('"sapux":')
12
+ }
13
+
14
+ static help() {
15
+ return 'SAP UI5 integration'
16
+ }
17
+
18
+ async run() {
19
+ const project = readProject()
20
+ await merge({ sapux: project.apps.map(({ app }) => project.appPath + app) }).into('package.json')
21
+ }
22
+ }
@@ -24,11 +24,12 @@ resources:
24
24
  config:
25
25
  xsappname: {{appName}}-${org}-${space}
26
26
  tenant-mode: {{#hasMultitenancy}}shared{{/hasMultitenancy}}{{^hasMultitenancy}}dedicated{{/hasMultitenancy}}
27
- {{#hasRoles}}
27
+ {{#hasRoles}}{{^hasCustomRoleCollections}}
28
28
  role-collections:
29
29
  {{#roles}}
30
30
  - name: '{{name}} ({{appName}} ${org}-${space})'
31
31
  description: 'generated'
32
32
  role-template-references: ['$XSAPPNAME.{{name}}']
33
33
  {{/roles}}
34
+ {{/hasCustomRoleCollections}}
34
35
  {{/hasRoles}}
@@ -67,11 +67,13 @@ module.exports = class XsuaaTemplate extends require('../../plugin') {
67
67
  project.hasRoles = xsSecurity['role-templates'].length > 0
68
68
  project.roles = xsSecurity['role-templates'].map(role => role)
69
69
 
70
- for (const role of xsSecurity['role-templates']) {
71
- additions.push({
72
- in: [xsuaa, 'parameters.role-collections'],
73
- where: { 'role-template-references': ['XSAPPNAME'+role.name] }
74
- })
70
+ if (!project.hasCustomRoleCollections) {
71
+ for (const role of xsSecurity['role-templates']) {
72
+ additions.push({
73
+ in: [xsuaa, 'parameters.role-collections'],
74
+ where: { 'role-template-references': ['XSAPPNAME'+role.name] }
75
+ })
76
+ }
75
77
  }
76
78
 
77
79
  await merge(__dirname, 'files/mta.yaml.hbs').into('mta.yaml', { project, additions, overwrites, relationships })
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "9.32.0",
3
- "help": "\n# SYNOPSIS\n\n *cds lint* [options] file.js [file.js] [dir]\n\n Runs environment checks and/or checks the specified models\n based on the ESLint framework\n\n# OPTIONS\n \n Basic configuration:\n --no-config-lookup Disable look up for eslint.config.js\n -c, --config path::String Use this configuration instead of eslint.config.js, eslint.config.mjs, or eslint.config.cjs\n --inspect-config Open the config inspector with the current configuration\n --ext [String] Specify additional file extensions to lint\n --global [String] Define global variables\n --parser String Specify the parser to be used\n --parser-options Object Specify parser options\n \n Specify Rules and Plugins:\n --plugin [String] Specify plugins\n --rule Object Specify rules\n \n Fix Problems:\n --fix Automatically fix problems\n --fix-dry-run Automatically fix problems without saving the changes to the file system\n --fix-type Array Specify the types of fixes to apply (directive, problem, suggestion, layout)\n \n Ignore Files:\n --no-ignore Disable use of ignore files and patterns\n --ignore-pattern [String] Patterns of files to ignore\n \n Use stdin:\n --stdin Lint code provided on <STDIN> - default: false\n --stdin-filename String Specify filename to process STDIN as\n \n Handle Warnings:\n --quiet Report errors only - default: false\n --max-warnings Int Number of warnings to trigger nonzero exit code - default: -1\n \n Output:\n -o, --output-file path::String Specify file to write report to\n -f, --format String Use a specific output format - default: stylish\n --color, --no-color Force enabling/disabling of color\n \n Inline configuration comments:\n --no-inline-config Prevent comments from changing config or rules\n --report-unused-disable-directives Adds reported errors for unused eslint-disable and eslint-enable directives\n --report-unused-disable-directives-severity String Chooses severity level for reporting unused eslint-disable and eslint-enable directives - either: off, warn, error, 0, 1, or 2\n --report-unused-inline-configs String Adds reported errors for unused eslint inline config comments - either: off, warn, error, 0, 1, or 2\n \n Caching:\n --cache Only check changed files - default: false\n --cache-file path::String Path to the cache file. Deprecated: use --cache-location - default: .eslintcache\n --cache-location path::String Path to the cache file or directory\n --cache-strategy String Strategy to use for detecting changed files in the cache - either: metadata or content - default: metadata\n \n Suppressing Violations:\n --suppress-all Suppress all violations - default: false\n --suppress-rule [String] Suppress specific rules\n --suppressions-location path::String Specify the location of the suppressions file\n --prune-suppressions Prune unused suppressions - default: false\n --pass-on-unpruned-suppressions Ignore unused suppressions - default: false\n \n Miscellaneous:\n --init Run config initialization wizard - default: false\n --env-info Output execution environment information - default: false\n --no-error-on-unmatched-pattern Prevent errors when pattern is unmatched\n --exit-on-fatal-error Exit with exit code 2 in case of fatal error - default: false\n --no-warn-ignored Suppress warnings when the file list includes ignored files\n --pass-on-no-patterns Exit with exit code 0 in case no file patterns are passed\n --debug Output debugging information\n -h, --help Show help\n -v, --version Output the version number\n --print-config path::String Print the configuration for the given file\n --stats Add statistics to the lint report - default: false\n --flag [String] Enable a feature flag\n --mcp Start the ESLint MCP server\n \n",
2
+ "version": "9.35.0",
3
+ "help": "\n# SYNOPSIS\n\n *cds lint* [options] file.js [file.js] [dir]\n\n Runs environment checks and/or checks the specified models\n based on the ESLint framework\n\n# OPTIONS\n \n Basic configuration:\n --no-config-lookup Disable look up for eslint.config.js\n -c, --config path::String Use this configuration instead of eslint.config.js, eslint.config.mjs, or eslint.config.cjs\n --inspect-config Open the config inspector with the current configuration\n --ext [String] Specify additional file extensions to lint\n --global [String] Define global variables\n --parser String Specify the parser to be used\n --parser-options Object Specify parser options\n \n Specify Rules and Plugins:\n --plugin [String] Specify plugins\n --rule Object Specify rules\n \n Fix Problems:\n --fix Automatically fix problems\n --fix-dry-run Automatically fix problems without saving the changes to the file system\n --fix-type Array Specify the types of fixes to apply (directive, problem, suggestion, layout)\n \n Ignore Files:\n --no-ignore Disable use of ignore files and patterns\n --ignore-pattern [String] Patterns of files to ignore\n \n Use stdin:\n --stdin Lint code provided on <STDIN> - default: false\n --stdin-filename String Specify filename to process STDIN as\n \n Handle Warnings:\n --quiet Report errors only - default: false\n --max-warnings Int Number of warnings to trigger nonzero exit code - default: -1\n \n Output:\n -o, --output-file path::String Specify file to write report to\n -f, --format String Use a specific output format - default: stylish\n --color, --no-color Force enabling/disabling of color\n \n Inline configuration comments:\n --no-inline-config Prevent comments from changing config or rules\n --report-unused-disable-directives Adds reported errors for unused eslint-disable and eslint-enable directives\n --report-unused-disable-directives-severity String Chooses severity level for reporting unused eslint-disable and eslint-enable directives - either: off, warn, error, 0, 1, or 2\n --report-unused-inline-configs String Adds reported errors for unused eslint inline config comments - either: off, warn, error, 0, 1, or 2\n \n Caching:\n --cache Only check changed files - default: false\n --cache-file path::String Path to the cache file. Deprecated: use --cache-location - default: .eslintcache\n --cache-location path::String Path to the cache file or directory\n --cache-strategy String Strategy to use for detecting changed files in the cache - either: metadata or content - default: metadata\n \n Suppressing Violations:\n --suppress-all Suppress all violations - default: false\n --suppress-rule [String] Suppress specific rules\n --suppressions-location path::String Specify the location of the suppressions file\n --prune-suppressions Prune unused suppressions - default: false\n --pass-on-unpruned-suppressions Ignore unused suppressions - default: false\n \n Miscellaneous:\n --init Run config initialization wizard - default: false\n --env-info Output execution environment information - default: false\n --no-error-on-unmatched-pattern Prevent errors when pattern is unmatched\n --exit-on-fatal-error Exit with exit code 2 in case of fatal error - default: false\n --no-warn-ignored Suppress warnings when the file list includes ignored files\n --pass-on-no-patterns Exit with exit code 0 in case no file patterns are passed\n --debug Output debugging information\n -h, --help Show help\n -v, --version Output the version number\n --print-config path::String Print the configuration for the given file\n --stats Add statistics to the lint report - default: false\n --flag [String] Enable a feature flag\n --mcp Start the ESLint MCP server\n --concurrency Int|String Number of linting threads, auto to choose automatically, off for no multithreading - default: off\n \n",
4
4
  "options": [
5
5
  "--config",
6
6
  "--output-file",
@@ -24,7 +24,8 @@
24
24
  "--suppress-rule",
25
25
  "--suppressions-location",
26
26
  "--print-config",
27
- "--flag"
27
+ "--flag",
28
+ "--concurrency"
28
29
  ],
29
30
  "shortcuts": [
30
31
  "-c",
@@ -50,6 +51,7 @@
50
51
  null,
51
52
  null,
52
53
  null,
54
+ null,
53
55
  "-v",
54
56
  "-h"
55
57
  ],
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@sap/cds-dk",
3
- "version": "9.2.1",
3
+ "version": "9.3.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@sap/cds-dk",
9
- "version": "9.2.1",
9
+ "version": "9.3.1",
10
10
  "license": "SEE LICENSE IN LICENSE",
11
11
  "dependencies": {
12
12
  "@cap-js/asyncapi": "^1.0.0",
@@ -42,8 +42,8 @@
42
42
  }
43
43
  },
44
44
  "node_modules/@cap-js/db-service": {
45
- "version": "2.3.0",
46
- "integrity": "sha512-KkYrnI05bx0PvwP5jxEUos8UQ+XYPucUMQt3i0muQXWJw3rEkWvEArvOwCYjTNnjzHqtVQfpPXsy1+ehkHUrWg==",
45
+ "version": "2.4.0",
46
+ "integrity": "sha512-tWZUkgAPgZQIVu3xownD9cA9joXPI84KDstx3ZezOxXJuRsapgM2QEs0TXwQK5XLG43FUAsGO7wVJPoZ29ZH2Q==",
47
47
  "devOptional": true,
48
48
  "license": "Apache-2.0",
49
49
  "dependencies": {
@@ -78,8 +78,8 @@
78
78
  }
79
79
  },
80
80
  "node_modules/@eslint/js": {
81
- "version": "9.33.0",
82
- "integrity": "sha512-5K1/mKhWaMfreBGJTwval43JJmkip0RmM+3+IuqupeSKNC/Th2Kc7ucaq5ovTSra/OOKB9c58CGSz3QMVbWt0A==",
81
+ "version": "9.35.0",
82
+ "integrity": "sha512-30iXE9whjlILfWobBkNerJo+TXYsgVM5ERQwMcMKCHckHflCmf7wXDAHlARoWnh0s1U72WqlbeyE7iAcCzuCPw==",
83
83
  "license": "MIT",
84
84
  "peer": true,
85
85
  "engines": {
@@ -90,11 +90,11 @@
90
90
  }
91
91
  },
92
92
  "node_modules/@sap/cds": {
93
- "version": "9.2.1",
94
- "integrity": "sha512-0zjjZGlBvcJMyVj48hTs6Q22/w9hNnJR6O88rGoEj4R87uaP4uM5gFLf3PDnPDUwkAeveVHgJRnWPqDGqIMgvA==",
93
+ "version": "9.3.1",
94
+ "integrity": "sha512-xA9EN29X8HKaz83Aod1e3Bs6LRvqcCVoaTvCtyOup5rMYDQumcoZ7UOKH6NIUTeO0zOtafUiMHucMG+dBnq5XQ==",
95
95
  "license": "SEE LICENSE IN LICENSE",
96
96
  "dependencies": {
97
- "@sap/cds-compiler": "^6",
97
+ "@sap/cds-compiler": "^6.1",
98
98
  "@sap/cds-fiori": "^2",
99
99
  "js-yaml": "^4.1.0"
100
100
  },
@@ -120,8 +120,8 @@
120
120
  }
121
121
  },
122
122
  "node_modules/@sap/cds-compiler": {
123
- "version": "6.2.2",
124
- "integrity": "sha512-LqRNfBsWnEJpXVJ6/v52VqAdelWoETLbECMPcy7BfoHE63DGBpKA/ZIgoH11t7vUm7GYQDcSfR7ryy02Q/fP7A==",
123
+ "version": "6.3.0",
124
+ "integrity": "sha512-4HhZuiKa8SztqtjfM9Iey7yb2U6xQGzUbjib3JXcSSP6AJ6Bz0gViliTwf8dASPTLRtv7HU82277m4uqxU2qjw==",
125
125
  "license": "SEE LICENSE IN LICENSE",
126
126
  "bin": {
127
127
  "cdsc": "bin/cdsc.js",
@@ -142,8 +142,8 @@
142
142
  }
143
143
  },
144
144
  "node_modules/@sap/cds-mtxs": {
145
- "version": "3.2.0",
146
- "integrity": "sha512-8X+fK0rsnOaKZpettVAXuzCJT9MRebpuzN1JjNEWPiYVafvIjXIQc2diYgq8rtzhfdFWk6QNlZUjMM7jLgNfsw==",
145
+ "version": "3.3.1",
146
+ "integrity": "sha512-66yWxkVlqu5FsOHxDF8w2JJSlcbgtT2PTegBSECEq9+fjMOaqlxnBHpXXTODCUgK762Ad3kyCUZqW///gmpuMA==",
147
147
  "license": "SEE LICENSE IN LICENSE",
148
148
  "dependencies": {
149
149
  "@sap/hdi-deploy": "^5"
@@ -1213,8 +1213,8 @@
1213
1213
  "license": "MIT"
1214
1214
  },
1215
1215
  "node_modules/node-abi": {
1216
- "version": "3.75.0",
1217
- "integrity": "sha512-OhYaY5sDsIka7H7AtijtI9jwGYLyl29eQn/W623DiN/MIv5sUqc4g7BIDThX+gb7di9f6xK02nkp8sdfFWZLTg==",
1216
+ "version": "3.77.0",
1217
+ "integrity": "sha512-DSmt0OEcLoK4i3NuscSbGjOf3bqiDEutejqENSplMSFA/gmB8mkED9G4pKWnPl7MDU4rSHebKPHeitpDfyH0cQ==",
1218
1218
  "license": "MIT",
1219
1219
  "optional": true,
1220
1220
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds-dk",
3
- "version": "9.2.1",
3
+ "version": "9.3.1",
4
4
  "description": "Command line client and development toolkit for the SAP Cloud Application Programming Model",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "keywords": [
@@ -1,48 +0,0 @@
1
- name: GitHub Deployment for Cloud Foundry
2
- description: "Creates a GitHub deployment for your Cloud Foundry app"
3
-
4
- inputs:
5
- app-name:
6
- description: "Base name of the deployed CAP app"
7
- required: true
8
-
9
- runs:
10
- using: "composite"
11
- steps:
12
- - name: Get deployed server URL
13
- id: get-url
14
- shell: bash
15
- run: |
16
- raw=$(cf app "${{ inputs.app-name }}" | awk '/routes:/ {print $2}')
17
- raw=$(echo "$raw" | sed -E 's#^https?://##')
18
- echo "url=https://$raw" >> "$GITHUB_OUTPUT"
19
-
20
- - name: Create GitHub Deployment
21
- uses: actions/github-script@v7
22
- env:
23
- URL: ${{ steps.get-url.outputs.url }}
24
- with:
25
- script: |
26
- const { owner, repo } = context.repo
27
- const ref = context.ref
28
- const url = process.env.URL
29
-
30
- const deployment = await github.rest.repos.createDeployment({
31
- owner,
32
- repo,
33
- ref,
34
- required_contexts: [],
35
- environment: 'Production',
36
- auto_merge: false,
37
- description: 'Deployed to Cloud Foundry',
38
- })
39
-
40
- await github.rest.repos.createDeploymentStatus({
41
- owner,
42
- repo,
43
- deployment_id: deployment.data.id,
44
- state: 'success',
45
- environment_url: url,
46
- log_url: `https://github.com/${owner}/${repo}/actions/runs/${context.runId}`,
47
- description: 'CAP app is live',
48
- })
@@ -1,24 +0,0 @@
1
- {{#isESM}}
2
- import cds from '@sap/cds'
3
-
4
- export class AdminService extends cds.ApplicationService { init() {
5
- {{/isESM}}
6
- {{^isESM}}
7
- const cds = require('@sap/cds')
8
-
9
- module.exports = class AdminService extends cds.ApplicationService { init() {
10
- {{/isESM}}
11
-
12
- const { Books } = this.entities
13
-
14
- /**
15
- * Generate IDs for new Books drafts
16
- */
17
- this.before ('NEW', Books.drafts, async (req) => {
18
- if (req.data.ID) return
19
- const { ID:id1 } = await SELECT.one.from(Books).columns('max(ID) as ID')
20
- const { ID:id2 } = await SELECT.one.from(Books.drafts).columns('max(ID) as ID')
21
- req.data.ID = Math.max(id1||0, id2||0) + 1
22
- })
23
- return super.init()
24
- }}
@@ -1,43 +0,0 @@
1
- {{#isESM}}
2
- import cds from '@sap/cds'
3
-
4
- export class CatalogService extends cds.ApplicationService { init() {
5
- {{/isESM}}
6
- {{^isESM}}
7
- const cds = require('@sap/cds')
8
-
9
- module.exports = class CatalogService extends cds.ApplicationService { init() {
10
- {{/isESM}}
11
-
12
- const { Books } = cds.entities('sap.capire.bookshop')
13
- const { ListOfBooks } = this.entities
14
-
15
- // Add some discount for overstocked books
16
- this.after('each', ListOfBooks, book => {
17
- if (book.stock > 111) book.title += ` -- 11% discount!`
18
- })
19
-
20
- // Reduce stock of ordered books if available stock suffices
21
- this.on('submitOrder', async req => {
22
- let { book:id, quantity } = req.data
23
- let book = await SELECT.one.from (Books, id, b => b.stock)
24
-
25
- // Validate input data
26
- if (!book) return req.error (404, `Book #${id} doesn't exist`)
27
- if (quantity < 1) return req.error (400, `quantity has to be 1 or more`)
28
- if (!book.stock || quantity > book.stock) return req.error (409, `${quantity} exceeds stock for book #${id}`)
29
-
30
- // Reduce stock in database and return updated stock value
31
- await UPDATE (Books, id) .with ({ stock: book.stock -= quantity })
32
- return book
33
- })
34
-
35
- // Emit event when an order has been submitted
36
- this.after('submitOrder', async (_,req) => {
37
- let { book, quantity } = req.data
38
- await this.emit('OrderedBook', { book, quantity, buyer: req.user.id })
39
- })
40
-
41
- // Delegate requests to the underlying generic service
42
- return super.init()
43
- }}
@@ -1,16 +0,0 @@
1
- import cds from '@sap/cds'
2
-
3
- import { Books } from '#cds-models/AdminService'
4
-
5
- export class AdminService extends cds.ApplicationService { async init() {
6
-
7
- /**
8
- * Generate primary keys for target entity in request
9
- */
10
- this.before ('NEW', Books.drafts, async req => {
11
- if (req.data.ID) return
12
- const { ID } = await SELECT.one.from(Books).columns('max(ID) as ID') ?? { ID: 0 }
13
- req.data.ID = ID! - ID! % 100 + 100 + 1
14
- })
15
- return super.init()
16
- }}
@@ -1,38 +0,0 @@
1
- import cds from '@sap/cds'
2
-
3
- import { Books } from '#cds-models/sap/capire/bookshop'
4
- import { submitOrder, OrderedBook, ListOfBooks } from '#cds-models/CatalogService'
5
-
6
- export class CatalogService extends cds.ApplicationService { async init() {
7
-
8
- // Add some discount for overstocked books
9
- this.after('each', ListOfBooks, book => {
10
- if (book?.stock === undefined || book.stock === null) return
11
- if (book?.stock > 111) book.title += ` -- 11% discount!`
12
- })
13
-
14
- // Reduce stock of ordered books if available stock suffices
15
- this.on(submitOrder, async req => {
16
- let { book:id, quantity } = req.data
17
- if(!id) return req.error (400, `Book ID missing`) // FIXED
18
- let book = await SELECT.from (Books, id, b => b.stock)
19
-
20
- // Validate input data
21
- if (!book) return req.error (404, `Book #${id} doesn't exist`)
22
- if (!quantity || quantity < 1) return req.error (400, `quantity has to be 1 or more`)
23
- if (quantity > book.stock!) return req.error (409, `${quantity} exceeds stock for book #${id}`)
24
-
25
- // Reduce stock in database and return updated stock value
26
- await UPDATE (Books, id) .with ({ stock: book.stock! -= quantity })
27
- return book
28
- })
29
-
30
- // Emit event when an order has been submitted
31
- this.after(submitOrder, async (_,req) => {
32
- let { book, quantity } = req.data
33
- await this.emit(OrderedBook, { book, quantity, buyer: req.user.id })
34
- })
35
-
36
- // Delegate requests to the underlying generic service
37
- return super.init()
38
- }}