@sap/cds-dk 6.0.3 → 6.1.2

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 (105) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/bin/add.js +29 -16
  3. package/bin/compile/index.js +7 -2
  4. package/bin/fix-redirects.js +4 -2
  5. package/bin/init.js +5 -0
  6. package/bin/login.js +20 -4
  7. package/bin/pull.js +58 -0
  8. package/bin/push.js +52 -0
  9. package/bin/subscribe.js +45 -0
  10. package/lib/bind/bindingUtil.js +1 -2
  11. package/lib/bind/cfKeyProvider.js +3 -3
  12. package/lib/cds.js +2 -3
  13. package/lib/client/activate.js +17 -16
  14. package/lib/client/auth_manager.js +10 -5
  15. package/lib/client/base_command.js +4 -6
  16. package/lib/client/extend.js +3 -2
  17. package/lib/client/helper/cf_helper.js +1 -0
  18. package/lib/client/helper/errors.js +11 -0
  19. package/lib/client/helper/logging.js +3 -10
  20. package/lib/client/helper/url_helper.js +7 -3
  21. package/lib/client/index.js +1 -1
  22. package/lib/client/params.js +9 -6
  23. package/lib/client/pull.js +48 -0
  24. package/lib/client/push.js +45 -0
  25. package/lib/client/settings_manager.js +81 -27
  26. package/lib/compile/openapi/csdl2openapi.js +135 -163
  27. package/lib/compile/openapi/index.js +0 -1
  28. package/lib/import/common.js +9 -1
  29. package/lib/import/odata/metadataconverter/MetadataConverter.js +17 -4
  30. package/lib/import/odata/v2parser.js +50 -26
  31. package/lib/import/odata/v4parser.js +110 -29
  32. package/lib/import/openapi/importOpenAPI.js +3 -3
  33. package/lib/init/constants.js +9 -3
  34. package/lib/init/template/_merging/registry-mta.js +284 -0
  35. package/lib/init/template/approuter/files/xs-app.json.hbs +7 -7
  36. package/lib/init/template/approuter/index.js +22 -32
  37. package/lib/init/template/auditlog/index.js +7 -9
  38. package/lib/init/template/data/index.js +2 -4
  39. package/lib/init/template/extensibility/files/cds.package.json +7 -0
  40. package/lib/init/template/extensibility/files/cds.package.json.hbs +9 -0
  41. package/lib/init/template/extensibility/files/xs-security.json.hbs +26 -0
  42. package/lib/init/template/extensibility/index.js +48 -0
  43. package/lib/init/template/hana/files/java/cdsrc.json.hbs +1 -1
  44. package/lib/init/template/hana/files/java/profile.cdsrc.json.hbs +2 -2
  45. package/lib/init/template/hana/files/mta.yaml.hbs +10 -0
  46. package/lib/init/template/hana/files/nodejs/cds.package.json.hbs +1 -1
  47. package/lib/init/template/hana/files/nodejs/cds.profile.package.json.hbs +2 -2
  48. package/lib/init/template/hana/index.js +76 -63
  49. package/lib/init/template/kibana-logging/index.js +31 -37
  50. package/lib/init/template/lint/files/.eslint/rules/no-entity-moo.js +14 -14
  51. package/lib/init/template/mta/files/mta.yaml.hbs +1 -1
  52. package/lib/init/template/mta/index.js +13 -7
  53. package/lib/init/template/mtx/index.js +2 -142
  54. package/lib/init/template/multitenancy/files/cds.package.json +7 -0
  55. package/lib/init/template/multitenancy/files/cds.package.json.hbs +9 -0
  56. package/lib/init/template/{mtx → multitenancy}/files/dependencies.package.json +1 -1
  57. package/lib/init/template/multitenancy/files/java/.cdsrc.json +19 -0
  58. package/lib/init/template/multitenancy/files/java/package.json +31 -0
  59. package/lib/init/template/{mtx → multitenancy}/files/mta.yaml.hbs +13 -6
  60. package/lib/init/template/multitenancy/files/xs-security.json.hbs +18 -0
  61. package/lib/init/template/multitenancy/index.js +109 -0
  62. package/lib/init/template/nodejs/files/package.json.hbs +3 -0
  63. package/lib/init/template/templateBase.js +2 -1
  64. package/lib/init/template/toggles/files/cds.package.json +7 -0
  65. package/lib/init/template/toggles/files/cds.package.json.hbs +9 -0
  66. package/lib/init/template/toggles/index.js +24 -0
  67. package/lib/init/template/xsuaa/files/mta.yaml.hbs +10 -0
  68. package/lib/init/template/xsuaa/index.js +44 -33
  69. package/lib/init/util/projectReader.js +12 -7
  70. package/lib/init/util/templateUtil.js +113 -111
  71. package/lib/k8s/ChartAdder.js +13 -3
  72. package/lib/k8s/ChartBuilder.js +6 -0
  73. package/lib/k8s/buildModel.js +1 -3
  74. package/lib/k8s/connectivity/index.js +5 -5
  75. package/lib/k8s/deployment/index.js +2 -4
  76. package/lib/k8s/deployment/subchart/Chart.yaml +1 -1
  77. package/lib/k8s/deployment/subchart/templates/_helpers.tpl +22 -11
  78. package/lib/k8s/deployment/subchart/templates/deployment.yaml +12 -5
  79. package/lib/k8s/deployment/subchart/templates/network-policy.yaml +3 -1
  80. package/lib/k8s/deployment/subchart/templates/pod-disruption-budget.yaml +1 -1
  81. package/lib/k8s/deployment/subchart/values.md +812 -0
  82. package/lib/k8s/deployment/subchart/values.schema.json +125 -30
  83. package/lib/k8s/deployment/subchart/values.yaml +7 -3
  84. package/lib/k8s/hana-deployer/index.js +10 -0
  85. package/lib/k8s/hana-deployer/templates/hana-deployer-job.yaml +8 -0
  86. package/lib/k8s/html5-apps-deployer/index.js +10 -0
  87. package/lib/k8s/html5-apps-deployer/templates/html5-apps-deployer-job.yaml +8 -0
  88. package/lib/k8s/index.js +2 -2
  89. package/lib/k8s/resources/helm/chart/schemas/values.root.schema.json +11 -0
  90. package/lib/k8s/resources/helm/chart/schemas/values.schema.json +479 -0
  91. package/lib/k8s/resources/helm/chart/templates/_deployment_helpers.tpl +1 -159
  92. package/lib/k8s/resources/helm/chart/templates/_helpers.tpl +0 -33
  93. package/lib/k8s/resources/helm/chart/templates/_sapcp_helpers.tpl +1 -1
  94. package/lib/lint/Linter.js +155 -158
  95. package/lib/lint/io.js +12 -5
  96. package/npm-shrinkwrap.json +1052 -135
  97. package/package.json +5 -4
  98. package/lib/init/template/_merging/existences.js +0 -297
  99. package/lib/init/template/mtx/files/cds.package.json +0 -12
  100. package/lib/init/template/mtx/files/cds.package.json.hbs +0 -14
  101. package/lib/init/template/mtx/files/java/.cdsrc.json +0 -17
  102. package/lib/init/template/mtx/files/java/package.json +0 -43
  103. package/lib/init/template/mtx/files/java/server.js +0 -30
  104. package/lib/init/template/mtx/files/xs-security.json.hbs +0 -48
  105. package/lib/lint/.eslintrc.js +0 -3
@@ -1,4 +1,4 @@
1
- module.exports = require("@sap/eslint-plugin-cds/lib/api").createRule({
1
+ module.exports = require("@sap/eslint-plugin-cds").createRule({
2
2
  meta: {
3
3
  docs: {
4
4
  description: `Demonstrates how to implement a model validation check.
@@ -11,30 +11,30 @@ module.exports = require("@sap/eslint-plugin-cds/lib/api").createRule({
11
11
  (__)\ )\/\
12
12
  ||----w |
13
13
  || ||`,
14
- version: "1.0.0",
14
+ version: "1.0.0"
15
15
  },
16
- fixable: "code",
16
+ fixable: "code"
17
17
  },
18
18
  create: function (context) {
19
- const m = context.cds.model;
20
- m.forall("entity", (d) => {
21
- const entityName = d.name.split(".").pop();
19
+ return { entity: checkForMoo };
20
+
21
+ function checkForMoo(e) {
22
+ const entityName = e.name.split(".").pop();
22
23
  if (entityName === "Moo") {
23
- const loc = context.cds.getLocation(entityName, d);
24
+ const loc = context.getLocation(entityName, e);
24
25
  const fix = (fixer) => {
25
- const rangeEnd = context.sourcecode.getIndexFromLoc({
26
+ const rangeEnd = context.getSourceCode().getIndexFromLoc({
26
27
  line: loc.end.line,
27
- column: loc.end.column,
28
+ column: loc.end.column
28
29
  });
29
30
  return fixer.insertTextAfterRange([0, rangeEnd], "n");
30
31
  };
31
32
  context.report({
32
33
  message: "Entity 'Moo' not allowed!",
33
- loc,
34
- fix,
35
- file: d.$location.file,
34
+ node: context.getNode(e),
35
+ fix
36
36
  });
37
37
  }
38
- });
39
- },
38
+ }
39
+ }
40
40
  })
@@ -9,7 +9,7 @@ build-parameters:
9
9
  before-all:
10
10
  - builder: custom
11
11
  commands:
12
- - npx -p @sap/cds-dk cds build --production
12
+ - npx -p @sap/cds-dk{{#cap.isJava}}@^6{{/cap.isJava}} cds build --production
13
13
 
14
14
  modules:
15
15
  - name: {{cap.appName}}-srv
@@ -11,6 +11,7 @@ module.exports = class MtaTemplate extends TemplateBase {
11
11
 
12
12
  async run() {
13
13
  const projectDescriptor = await this.projectReader.read();
14
+ const { hasApprouter, hasHana, hasXsuaa, isMultitenant, isExtensible } = projectDescriptor.cap;
14
15
  if (!existsSync(join(this.projectPath, 'mta.yaml'))) {
15
16
  await this.templateUtil.copyFiles('.', this.projectPath, projectDescriptor);
16
17
  }
@@ -18,25 +19,30 @@ module.exports = class MtaTemplate extends TemplateBase {
18
19
  // Re-applying the merging part of `cds add xsuaa`, `cds add hana`, and `cds add mtx`, if necessary.
19
20
  // TODO: Find a generic solution for situation like these. Probably involves some restructuring in the
20
21
  // project reader, so that there's a logical mapping from hasX to XTemplate.
21
- if (projectDescriptor.cap.hasApprouter) {
22
+ if (hasApprouter) {
22
23
  const ApprouterTemplate = require(`../approuter`)
23
24
  const template = new ApprouterTemplate(this.projectPath, this.generator)
24
25
  await template.runDependentMerging()
25
26
  }
26
- if (projectDescriptor.cap.hasHana) {
27
+ if (hasHana) {
27
28
  const HanaTemplate = require(`../hana`)
28
29
  const template = new HanaTemplate(this.projectPath, this.generator)
29
30
  await template.runDependentMerging()
30
31
  }
31
- if (projectDescriptor.cap.hasXsuaa) {
32
+ if (hasXsuaa) {
32
33
  const XsuaaTemplate = require(`../xsuaa`)
33
34
  const template = new XsuaaTemplate(this.projectPath, this.generator)
34
35
  await template.runDependentMerging()
35
36
  }
36
- if (projectDescriptor.cap.isMultitenant) {
37
- const MtxTemplate = require(`../mtx`)
38
- const template = new MtxTemplate(this.projectPath, this.generator)
37
+ if (isMultitenant) {
38
+ const MultitenancyTemplate = require(`../multitenancy`)
39
+ const template = new MultitenancyTemplate(this.projectPath, this.generator)
40
+ await template.runDependentMerging()
41
+ }
42
+ if (isExtensible) {
43
+ const ExtensibilityTemplate = require(`../extensibility`)
44
+ const template = new ExtensibilityTemplate(this.projectPath, this.generator)
39
45
  await template.runDependentMerging()
40
46
  }
41
47
  }
42
- };
48
+ }
@@ -1,14 +1,6 @@
1
- const cds = require('../../../cds'), { fs, path } = cds.utils
2
1
  const TemplateBase = require('../templateBase')
3
2
  const ProjectReader = require('../../util/projectReader')
4
- const { OPTION_HANA, OPTION_XSUAA } = require('../../constants')
5
-
6
- const {
7
- srvNode, srvJava, // Server
8
- mtxSidecar, // Additional Modules
9
- saasRegistry, xsuaa, // BTP Services
10
- providedMtxAPI, srvAPI, providedMtxSidecarAPI, requiredMtxSidecarAPI // APIs
11
- } = require('../_merging/existences');
3
+ const { OPTION_MULTITENANCY, OPTION_TOGGLES, OPTION_EXTENSIBILITY } = require('../../constants')
12
4
 
13
5
  module.exports = class MtxTemplate extends TemplateBase {
14
6
  constructor(projectPath, generator) {
@@ -17,138 +9,6 @@ module.exports = class MtxTemplate extends TemplateBase {
17
9
  }
18
10
 
19
11
  async getDependencies() {
20
- return [OPTION_HANA, OPTION_XSUAA]
21
- }
22
-
23
- async runDependentMerging() {
24
- const projectDescriptor = await this.projectReader.read()
25
-
26
- const mtaYAMLPath = path.join(this.projectPath, 'mta.yaml')
27
-
28
- if (fs.existsSync(mtaYAMLPath)) {
29
- const mergingRules = projectDescriptor.cap.isNodejs ?
30
- {
31
- existences: [srvNode, saasRegistry, providedMtxAPI, xsuaa],
32
- overwrites: [{
33
- in: xsuaa,
34
- keyPath: ["parameters", "config", "tenant-mode"],
35
- replacement: "shared"
36
- }],
37
- relationships: [{
38
- in: srvNode,
39
- inKeyPath: ["requires"],
40
- into: "name",
41
- existences: [saasRegistry],
42
- existenceKeyPath: ["name"],
43
- }],
44
- }
45
- :
46
- {
47
- existences: [srvJava, srvAPI, mtxSidecar, xsuaa, saasRegistry, providedMtxAPI, providedMtxSidecarAPI, requiredMtxSidecarAPI],
48
- overwrites: [{
49
- in: xsuaa,
50
- keyPath: ["parameters", "config", "tenant-mode"],
51
- replacement: "shared"
52
- }],
53
- relationships: [{
54
- in: srvJava,
55
- inKeyPath: ["requires"],
56
- into: "name",
57
- existences: [saasRegistry],
58
- existenceKeyPath: ["name"],
59
- }],
60
- }
61
-
62
- await this.templateUtil.mergeYAML(
63
- mtaYAMLPath,
64
- path.join(__dirname, `files`, `mta.yaml.hbs`),
65
- projectDescriptor,
66
- mergingRules
67
- )
68
- }
69
-
70
- if (projectDescriptor.cap.hasApprouter) {
71
- const ApprouterTemplate = require(`../approuter`)
72
- const template = new ApprouterTemplate(this.projectPath, this.generator)
73
- await template.runDependentMerging()
74
- }
75
- }
76
-
77
- async runXSSecurityMerging() {
78
- const projectDescriptor = await this.projectReader.read()
79
- await this.templateUtil.mergeJSON(
80
- path.join(this.projectPath, 'xs-security.json'),
81
- path.join(__dirname, 'files', 'xs-security.json.hbs'),
82
- projectDescriptor,
83
- {
84
- existences: [{
85
- ref: "scope-subscription",
86
- keyPath: ["scopes"],
87
- constraints: [{
88
- comparisonKeyPath: ["name"],
89
- value: "$XSAPPNAME.mtcallback"
90
- }],
91
- }, {
92
- ref: "scope-update",
93
- keyPath: ["scopes"],
94
- constraints: [{
95
- comparisonKeyPath: ["name"],
96
- value: "$XSAPPNAME.mtdeployment"
97
- }],
98
- }, {
99
- ref: "scope-diagnose",
100
- keyPath: ["scopes"],
101
- constraints: [{
102
- comparisonKeyPath: ["name"],
103
- value: "$XSAPPNAME.MtxDiagnose"
104
- }],
105
- }, {
106
- ref: "scope-extend",
107
- keyPath: ["scopes"],
108
- constraints: [{
109
- comparisonKeyPath: ["name"],
110
- value: "$XSAPPNAME.ExtendCDS"
111
- }],
112
- }, {
113
- ref: "scope-extend-delete",
114
- keyPath: ["scopes"],
115
- constraints: [{
116
- comparisonKeyPath: ["name"],
117
- value: "$XSAPPNAME.ExtendCDSdelete"
118
- }],
119
- }, {
120
- ref: "template-extension-developer",
121
- keyPath: ["role-templates"],
122
- constraints: [{
123
- comparisonKeyPath: ["name"],
124
- value: "ExtensionDeveloper"
125
- }],
126
- }, {
127
- ref: "template-extension-developer-undeploy",
128
- keyPath: ["role-templates"],
129
- constraints: [{
130
- comparisonKeyPath: ["name"],
131
- value: "ExtensionDeveloperUndeploy"
132
- }],
133
- }],
134
- }
135
- )
136
- }
137
-
138
- async run() {
139
- const projectDescriptor = await this.projectReader.read(this.options)
140
- if (projectDescriptor.cap.isNodejs) {
141
- const packageJSONPath = path.join(this.projectPath, 'package.json')
142
- const cdsTemplateFile = projectDescriptor.cap.for ? 'cds.package.json.hbs' : 'cds.package.json'
143
- await this.templateUtil.mergeJSON(packageJSONPath, path.join(__dirname, 'files', cdsTemplateFile), projectDescriptor)
144
- await this.templateUtil.mergeJSON(packageJSONPath, path.join(__dirname, 'files', 'dependencies.package.json'))
145
- await this.templateUtil.sortDependencies(packageJSONPath)
146
- } else {
147
- const cdsrcJSONPath = path.join(this.projectPath, '.cdsrc.json')
148
- await this.templateUtil.mergeJSON(cdsrcJSONPath, path.join(__dirname, 'files', 'java', '.cdsrc.json'))
149
- await fs.copy(path.join(__dirname, 'files', 'java'), path.join(this.projectPath, 'mtx-sidecar'))
150
- }
151
- await this.runXSSecurityMerging()
152
- await this.runDependentMerging()
12
+ return [OPTION_MULTITENANCY, OPTION_TOGGLES, OPTION_EXTENSIBILITY]
153
13
  }
154
14
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "cds": {
3
+ "requires": {
4
+ "multitenancy": true
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "cds": {
3
+ "requires": {
4
+ "[{{cap.for}}]": {
5
+ "multitenancy": true
6
+ }
7
+ }
8
+ }
9
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "dependencies": {
3
- "@sap/cds-mtx": "^2"
3
+ "@sap/cds-mtxs": "^1"
4
4
  }
5
5
  }
@@ -0,0 +1,19 @@
1
+ {
2
+ "build": {
3
+ "target": ".",
4
+ "tasks": [
5
+ {
6
+ "for": "java"
7
+ },
8
+ {
9
+ "for": "mtx-sidecar"
10
+ },
11
+ {
12
+ "for": "hana",
13
+ "options": {
14
+ "deploy-format": "hdbtable"
15
+ }
16
+ }
17
+ ]
18
+ }
19
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "cap-mtx-sidecar",
3
+ "dependencies": {
4
+ "@sap/cds": "^6.0.2",
5
+ "@sap/cds-mtxs": "^1.0.1",
6
+ "@sap/hdi-deploy": "^4.4.1",
7
+ "@sap/xssec": "^3.2.13",
8
+ "express": "^4.18.1",
9
+ "hdb": "^0.19.3",
10
+ "passport": "^0.6.0"
11
+ },
12
+ "scripts": {
13
+ "start": "cds run",
14
+ "build": "npm ci && npx -p @sap/cds-dk@^6 cds build ../.. --for mtx-sidecar --production && cd gen && npm ci"
15
+ },
16
+ "engines": {
17
+ "node": "^16.15.0"
18
+ },
19
+ "cds": {
20
+ "requires": {
21
+ "db": {
22
+ "kind": "sqlite",
23
+ "[production]": {
24
+ "kind": "hana-mt"
25
+ }
26
+ },
27
+ "cds.xt.ModelProviderService": "in-sidecar",
28
+ "cds.xt.SaasProvisioningService": true
29
+ }
30
+ }
31
+ }
@@ -8,6 +8,7 @@ modules:
8
8
  {{#cap.isJava}}
9
9
  - name: mtx-sidecar
10
10
  properties:
11
+ CDS_MULTITENANCY_MTXS_ENABLED: true
11
12
  CDS_MULTITENANCY_SIDECAR_URL: ~{url}
12
13
  {{/cap.isJava}}
13
14
  provides:
@@ -21,17 +22,23 @@ modules:
21
22
  {{#cap.isJava}}
22
23
  - name: {{cap.appName}}-mtx-sidecar
23
24
  type: nodejs
24
- path: mtx-sidecar
25
+ path: mtx/sidecar
26
+ build-parameters:
27
+ builder: custom
28
+ build-result: gen
29
+ commands:
30
+ - npm run build
25
31
  parameters:
26
32
  memory: 256M
27
33
  disk-quota: 512M
28
- requires:
29
- - name: {{cap.appName}}-db
30
- - name: {{cap.appName}}-auth
31
34
  provides:
32
35
  - name: mtx-sidecar
33
36
  properties:
34
37
  url: ${default-url}
38
+ {{#cap.hasXsuaa}}
39
+ requires:
40
+ - name: {{cap.appName}}-auth
41
+ {{/cap.hasXsuaa}}
35
42
  {{/cap.isJava}}
36
43
 
37
44
  resources:
@@ -55,8 +62,8 @@ resources:
55
62
  category: 'Category'
56
63
  appUrls:
57
64
  {{#cap.isNodejs}}
58
- getDependencies: ~{mtx-api/mtx-url}/mtx/v1/provisioning/dependencies
59
- onSubscription: ~{mtx-api/mtx-url}/mtx/v1/provisioning/tenant/{tenantId}
65
+ getDependencies: ~{mtx-api/mtx-url}/-/cds/saas-provisioning/dependencies
66
+ onSubscription: ~{mtx-api/mtx-url}/-/cds/saas-provisioning/tenant/{tenantId}
60
67
  {{/cap.isNodejs}}
61
68
  {{#cap.isJava}}
62
69
  getDependencies: ~{srv-api/srv-url}/mt/v1.0/subscriptions/dependencies
@@ -0,0 +1,18 @@
1
+ {
2
+ "scopes": [
3
+ {
4
+ "name": "$XSAPPNAME.mtcallback",
5
+ "description": "Subscription via SaaS Registry",
6
+ "grant-as-authority-to-apps": [
7
+ "$XSAPPNAME(application,sap-provisioning,tenant-onboarding)"
8
+ ]
9
+ },
10
+ {
11
+ "name": "$XSAPPNAME.cds.Subscriber",
12
+ "description": "Subscribe to applications"
13
+ }
14
+ ],
15
+ "authorities": [
16
+ "$XSAPPNAME.cds.Subscriber"
17
+ ]
18
+ }
@@ -0,0 +1,109 @@
1
+ const cds = require('../../../cds'), { fs, path } = cds.utils
2
+ const TemplateBase = require('../templateBase')
3
+ const ProjectReader = require('../../util/projectReader')
4
+
5
+ const {
6
+ srvNode, srvJava, // Server
7
+ mtxSidecar, // Additional Modules
8
+ saasRegistry, serviceManager, xsuaa, // BTP Services
9
+ providedMtxAPI, srvAPI, providedMtxSidecarAPI, requiredMtxSidecarAPI // APIs
10
+ } = require('../_merging/registry-mta');
11
+
12
+ module.exports = class MultitenancyTemplate extends TemplateBase {
13
+ constructor(projectPath, generator) {
14
+ super(projectPath, generator, __dirname)
15
+ this.projectReader = new ProjectReader(this)
16
+ }
17
+
18
+ async runDependentMerging() {
19
+ const projectDescriptor = await this.projectReader.read()
20
+ const { isNodejs, isJava, hasMtaDeployment, hasApprouter, hasXsuaa, hasHana } = projectDescriptor.cap
21
+
22
+ if (hasMtaDeployment) {
23
+ const modules = isNodejs ? [srvNode] : [srvJava, mtxSidecar]
24
+ const srv = isNodejs ? srvNode : srvJava
25
+ const services = [saasRegistry]
26
+ if (hasXsuaa) services.push(xsuaa)
27
+ const apis = isNodejs ? [providedMtxAPI] : [srvAPI, providedMtxAPI, providedMtxSidecarAPI, requiredMtxSidecarAPI]
28
+ const relationships = [{
29
+ insert: [saasRegistry, 'name'],
30
+ into: [srv, 'requires', 'name']
31
+ }]
32
+
33
+ if (isJava) {
34
+ if (hasXsuaa) {
35
+ relationships.push({
36
+ insert: [xsuaa, 'name'],
37
+ into: [mtxSidecar, 'requires', 'name']
38
+ })
39
+ }
40
+ if (hasHana) {
41
+ relationships.push({
42
+ insert: [serviceManager, 'name'],
43
+ into: [mtxSidecar, 'requires', 'name'],
44
+ })
45
+ }
46
+ }
47
+
48
+ const mergingRules = {
49
+ additions: [...modules, ...services, ...apis],
50
+ overwrites: hasXsuaa ? [{ // TODO: the hasXsuaa should not be necessary
51
+ item: [xsuaa, 'parameters.config.tenant-mode'],
52
+ withValue: 'shared'
53
+ }] : undefined,
54
+ relationships,
55
+ }
56
+ const mtaPath = path.join(this.projectPath, 'mta.yaml')
57
+ const templateMtaPath = path.join(__dirname, `files`, `mta.yaml.hbs`)
58
+ await this.templateUtil.mergeYAML(mtaPath, templateMtaPath, projectDescriptor, mergingRules)
59
+ }
60
+
61
+ if (hasApprouter) {
62
+ const ApprouterTemplate = require(`../approuter`)
63
+ const template = new ApprouterTemplate(this.projectPath, this.generator)
64
+ await template.runDependentMerging()
65
+ }
66
+
67
+ if (hasHana) {
68
+ const HanaTemplate = require(`../hana`)
69
+ const template = new HanaTemplate(this.projectPath, this.generator)
70
+ await template.runDependentMerging()
71
+ }
72
+
73
+ if (hasXsuaa) {
74
+ await this.templateUtil.mergeJSON(
75
+ path.join(this.projectPath, 'xs-security.json'),
76
+ path.join(__dirname, 'files', 'xs-security.json.hbs'),
77
+ projectDescriptor,
78
+ {
79
+ additions: [{
80
+ ref: 'scope-mtcallback',
81
+ in: 'scopes',
82
+ where: [{ property: 'name', isEqualTo: '$XSAPPNAME.mtcallback' }],
83
+ }, {
84
+ ref: 'scope-subscriber',
85
+ in: 'scopes',
86
+ where: [{ property: 'name', isEqualTo: '$XSAPPNAME.cds.Subscriber' }],
87
+ }]
88
+ }
89
+ )
90
+ }
91
+ }
92
+
93
+ async run() {
94
+ const projectDescriptor = await this.projectReader.read(this.options)
95
+ const { for: forProfile, isNodejs, isJava } = projectDescriptor.cap
96
+ if (isNodejs) {
97
+ const packageJSONPath = path.join(this.projectPath, 'package.json')
98
+ const cdsTemplateFile = forProfile ? 'cds.package.json.hbs' : 'cds.package.json'
99
+ await this.templateUtil.mergeJSON(packageJSONPath, path.join(__dirname, 'files', cdsTemplateFile), projectDescriptor)
100
+ await this.templateUtil.mergeJSON(packageJSONPath, path.join(__dirname, 'files', 'dependencies.package.json'))
101
+ await this.templateUtil.sortDependencies(packageJSONPath)
102
+ } else if (isJava) {
103
+ const cdsrcJSONPath = path.join(this.projectPath, '.cdsrc.json')
104
+ await this.templateUtil.mergeJSON(cdsrcJSONPath, path.join(__dirname, 'files', 'java', '.cdsrc.json'))
105
+ await fs.copy(path.join(__dirname, 'files', 'java', 'package.json'), path.join(this.projectPath, 'mtx', 'sidecar', 'package.json'))
106
+ }
107
+ await this.runDependentMerging()
108
+ }
109
+ }
@@ -15,6 +15,9 @@
15
15
  "scripts": {
16
16
  "start": "cds run"
17
17
  },
18
+ "engines": {
19
+ "node": "^16.15"
20
+ },
18
21
  "eslintConfig": {
19
22
  "extends": "eslint:recommended",
20
23
  "env": {
@@ -64,13 +64,14 @@ module.exports = class TemplateBase {
64
64
 
65
65
  /**
66
66
  * @abstract
67
- * Executes the given template's merging steps.
67
+ * Executes the given template's merging steps which are dependent on another template.
68
68
  * The separation from `run()` is necessary to preserve templating associativity,
69
69
  * i.e. the order in which you apply them does not matter.
70
70
  * Ex.: Assume `cds add hana` is called before `cds add mta`. We want `cds add mta`
71
71
  * to create the base mta.yaml template and merge the hana mta.yaml in, but _don't_
72
72
  * want any other steps from the hana template performed (e.g. creating the .hdiconfig).
73
73
  * Separating the two let's us run this _only_ the merging part of the template.
74
+ * In addition, this partial merging avoids cyclic template dependencies.
74
75
  */
75
76
  async runDependentMerging() {
76
77
 
@@ -0,0 +1,7 @@
1
+ {
2
+ "cds": {
3
+ "requires": {
4
+ "toggles": true
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "cds": {
3
+ "requires": {
4
+ "[{{cap.for}}]": {
5
+ "toggles": true
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,24 @@
1
+ const cds = require('../../../cds'), { path } = cds.utils
2
+ const TemplateBase = require('../templateBase')
3
+ const ProjectReader = require('../../util/projectReader')
4
+
5
+ module.exports = class TogglesTemplate extends TemplateBase {
6
+ constructor(projectPath, generator) {
7
+ super(projectPath, generator, __dirname)
8
+ this.projectReader = new ProjectReader(this)
9
+ }
10
+
11
+ async run() {
12
+ const projectDescriptor = await this.projectReader.read(this.options)
13
+ const { for: forProfile, isNodejs, isJava } = projectDescriptor.cap
14
+ if (isNodejs) {
15
+ const packageJSONPath = path.join(this.projectPath, 'package.json')
16
+ const cdsTemplateFile = forProfile ? 'cds.package.json.hbs' : 'cds.package.json'
17
+ await this.templateUtil.mergeJSON(packageJSONPath, path.join(__dirname, 'files', cdsTemplateFile), projectDescriptor)
18
+ await this.templateUtil.sortDependencies(packageJSONPath)
19
+ } else if (isJava) {
20
+ // TODO: implement
21
+ }
22
+ await this.runDependentMerging()
23
+ }
24
+ }
@@ -5,6 +5,16 @@ modules:
5
5
  requires:
6
6
  - name: {{cap.appName}}-auth
7
7
 
8
+ {{#cap.isJava}}
9
+ {{#cap.isMultitenant}}
10
+ - name: {{cap.appName}}-mtx-sidecar
11
+ type: nodejs
12
+ path: mtx/sidecar
13
+ requires:
14
+ - name: {{cap.appName}}-auth
15
+ {{/cap.isMultitenant}}
16
+ {{/cap.isJava}}
17
+
8
18
  resources:
9
19
  - name: {{cap.appName}}-auth
10
20
  type: org.cloudfoundry.managed-service