@sap/cds 6.8.4 → 7.0.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 (217) hide show
  1. package/CHANGELOG.md +66 -4
  2. package/README.md +0 -1
  3. package/bin/cds-serve.js +50 -3
  4. package/bin/deploy/to-hana.js +1 -0
  5. package/bin/serve.js +16 -20
  6. package/lib/auth/basic-auth.js +6 -4
  7. package/lib/auth/index.js +4 -3
  8. package/lib/auth/jwt-auth.js +2 -5
  9. package/lib/compile/cds-compile.js +34 -89
  10. package/lib/compile/cdsc.js +11 -0
  11. package/lib/compile/etc/properties.js +2 -2
  12. package/lib/compile/for/lean_drafts.js +36 -69
  13. package/lib/compile/for/nodejs.js +2 -1
  14. package/lib/compile/load.js +3 -3
  15. package/lib/compile/minify.js +2 -0
  16. package/lib/compile/to/csn.js +74 -0
  17. package/{bin/build/provider/hana/2tabledata.js → lib/compile/to/hdbtabledata.js} +4 -6
  18. package/lib/compile/to/json.js +1 -1
  19. package/lib/compile/to/sql.js +8 -6
  20. package/lib/dbs/cds-deploy.js +174 -114
  21. package/lib/env/cds-env.js +64 -79
  22. package/lib/env/cds-requires.js +11 -28
  23. package/lib/env/defaults.js +13 -3
  24. package/lib/env/plugins.js +1 -12
  25. package/lib/env/presets.js +25 -21
  26. package/lib/index.js +121 -147
  27. package/lib/{core/reflect.js → linked/models.js} +2 -2
  28. package/lib/{core/infer.js → linked/queries.js} +2 -0
  29. package/lib/{core/index.js → linked/types.js} +2 -1
  30. package/lib/log/cds-error.js +13 -7
  31. package/lib/log/format/cf.js +1 -1
  32. package/lib/plugins.js +49 -0
  33. package/lib/ql/Query.js +0 -9
  34. package/lib/ql/STREAM.js +0 -1
  35. package/lib/req/context.js +2 -7
  36. package/lib/req/request.js +6 -2
  37. package/lib/req/response.js +23 -10
  38. package/lib/srv/middlewares/ctx-model.js +2 -2
  39. package/lib/srv/middlewares/errors.js +1 -1
  40. package/lib/srv/protocols/_legacy.js +1 -0
  41. package/lib/srv/protocols/graphql.js +7 -16
  42. package/lib/srv/protocols/index.js +59 -45
  43. package/lib/srv/protocols/odata-v2-proxy.js +2 -70
  44. package/lib/srv/protocols/odata-v4.js +9 -4
  45. package/lib/srv/srv-api.js +9 -3
  46. package/lib/srv/srv-dispatch.js +12 -9
  47. package/lib/srv/srv-models.js +4 -21
  48. package/lib/srv/srv-tx.js +15 -12
  49. package/lib/utils/cds-test.js +14 -9
  50. package/lib/utils/cds-utils.js +2 -12
  51. package/lib/utils/check-version.js +17 -0
  52. package/{bin/build → lib/utils}/csv-reader.js +23 -24
  53. package/libx/_runtime/auth/index.js +27 -23
  54. package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +15 -72
  55. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +1 -1
  56. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +0 -2
  57. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +33 -63
  58. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +14 -18
  59. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +15 -5
  60. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +5 -4
  61. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +37 -40
  62. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/updateToCQN.js +7 -1
  63. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/utils.js +101 -38
  64. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/errors/AbstractError.js +5 -1
  65. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriTokenizer.js +5 -8
  66. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/utils/ValueConverter.js +2 -1
  67. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/deserializer/ResourceJsonDeserializer.js +9 -8
  68. package/libx/_runtime/cds-services/adapter/odata-v4/to.js +1 -1
  69. package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +15 -11
  70. package/libx/_runtime/cds-services/adapter/odata-v4/utils/readAfterWrite.js +4 -0
  71. package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +5 -2
  72. package/libx/_runtime/cds-services/adapter/odata-v4/utils/stream.js +1 -123
  73. package/libx/_runtime/cds-services/services/Service.js +79 -107
  74. package/libx/_runtime/cds-services/services/utils/columns.js +23 -19
  75. package/libx/_runtime/cds-services/services/utils/compareJson.js +11 -1
  76. package/libx/_runtime/cds-services/services/utils/differ.js +7 -2
  77. package/libx/_runtime/cds-services/util/assert.js +65 -2
  78. package/libx/_runtime/common/composition/data.js +1 -0
  79. package/libx/_runtime/common/generic/auth/expand.js +1 -1
  80. package/libx/_runtime/common/generic/auth/restrict.js +5 -10
  81. package/libx/_runtime/common/generic/auth/restrictions.js +40 -0
  82. package/libx/_runtime/common/generic/auth/utils.js +1 -2
  83. package/libx/_runtime/common/generic/crud.js +32 -16
  84. package/libx/_runtime/common/generic/etag.js +133 -104
  85. package/libx/_runtime/common/generic/input.js +6 -21
  86. package/libx/_runtime/common/generic/put.js +1 -1
  87. package/libx/_runtime/common/generic/stream.js +52 -0
  88. package/libx/_runtime/common/generic/temporal.js +25 -8
  89. package/libx/_runtime/common/i18n/messages.properties +0 -2
  90. package/libx/_runtime/common/utils/cqn.js +1 -1
  91. package/libx/_runtime/common/utils/cqn2cqn4sql.js +5 -2
  92. package/libx/_runtime/common/utils/csn.js +0 -51
  93. package/libx/_runtime/common/utils/etag.js +30 -0
  94. package/libx/_runtime/common/utils/keys.js +1 -1
  95. package/libx/_runtime/common/utils/normalizeTimestamp.js +25 -0
  96. package/libx/_runtime/common/utils/path.js +1 -1
  97. package/libx/_runtime/common/utils/resolveView.js +2 -1
  98. package/libx/_runtime/common/utils/rewriteAsterisks.js +6 -4
  99. package/libx/_runtime/common/utils/search2cqn4sql.js +12 -16
  100. package/libx/_runtime/common/utils/stream.js +140 -0
  101. package/libx/_runtime/common/utils/streamProp.js +29 -12
  102. package/libx/_runtime/common/utils/templateProcessorPathSerializer.js +0 -2
  103. package/libx/_runtime/db/generic/index.js +0 -2
  104. package/libx/_runtime/db/query/delete.js +2 -2
  105. package/libx/_runtime/db/query/insert.js +2 -2
  106. package/libx/_runtime/db/query/read.js +2 -2
  107. package/libx/_runtime/db/query/run.js +2 -2
  108. package/libx/_runtime/db/query/update.js +2 -2
  109. package/libx/_runtime/db/sql-builder/BaseBuilder.js +0 -6
  110. package/libx/_runtime/db/sql-builder/ExpressionBuilder.js +23 -12
  111. package/libx/_runtime/db/sql-builder/FunctionBuilder.js +18 -6
  112. package/libx/_runtime/db/sql-builder/InsertBuilder.js +1 -0
  113. package/libx/_runtime/db/sql-builder/SelectBuilder.js +3 -7
  114. package/libx/_runtime/db/sql-builder/UpsertBuilder.js +1 -0
  115. package/libx/_runtime/db/utils/normalizeTimeData.js +7 -3
  116. package/libx/_runtime/fiori/draft.js +2 -0
  117. package/libx/_runtime/fiori/generic/activate.js +8 -9
  118. package/libx/_runtime/fiori/generic/before.js +30 -20
  119. package/libx/_runtime/fiori/generic/cancel.js +5 -3
  120. package/libx/_runtime/fiori/generic/delete.js +5 -3
  121. package/libx/_runtime/fiori/generic/edit.js +7 -7
  122. package/libx/_runtime/fiori/generic/index.js +10 -16
  123. package/libx/_runtime/fiori/generic/new.js +5 -3
  124. package/libx/_runtime/fiori/generic/patch.js +11 -8
  125. package/libx/_runtime/fiori/generic/prepare.js +13 -6
  126. package/libx/_runtime/fiori/generic/read.js +12 -6
  127. package/libx/_runtime/fiori/lean-draft.js +207 -152
  128. package/libx/_runtime/fiori/utils/delete.js +10 -5
  129. package/libx/_runtime/fiori/utils/req.js +17 -5
  130. package/libx/_runtime/fiori/utils/stream.js +36 -0
  131. package/libx/_runtime/hana/Service.js +12 -9
  132. package/libx/_runtime/hana/conversion.js +10 -15
  133. package/libx/_runtime/hana/driver.js +2 -0
  134. package/libx/_runtime/hana/execute.js +28 -6
  135. package/libx/_runtime/hana/pool.js +36 -122
  136. package/libx/_runtime/hana/search2cqn4sql.js +34 -36
  137. package/libx/_runtime/messaging/enterprise-messaging-utils/getTenantInfo.js +2 -6
  138. package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +3 -1
  139. package/libx/_runtime/messaging/enterprise-messaging.js +10 -58
  140. package/libx/_runtime/messaging/outbox/utils.js +1 -1
  141. package/libx/_runtime/remote/Service.js +20 -1
  142. package/libx/_runtime/remote/utils/client.js +3 -5
  143. package/libx/_runtime/sqlite/Service.js +4 -6
  144. package/libx/_runtime/sqlite/conversion.js +3 -13
  145. package/libx/_runtime/sqlite/customBuilder/CustomFunctionBuilder.js +9 -6
  146. package/libx/_runtime/sqlite/customBuilder/CustomUpsertBuilder.js +6 -1
  147. package/libx/_runtime/sqlite/execute.js +5 -16
  148. package/libx/odata/afterburner.js +22 -6
  149. package/libx/odata/grammar.pegjs +6 -1
  150. package/libx/odata/parser.js +1 -1
  151. package/libx/rest/RestAdapter.js +16 -9
  152. package/libx/rest/RestRequest.js +1 -1
  153. package/libx/rest/middleware/input.js +2 -1
  154. package/libx/rest/middleware/operation.js +1 -0
  155. package/libx/rest/middleware/parse.js +3 -2
  156. package/libx/rest/middleware/payload.js +9 -8
  157. package/libx/rest/middleware/read.js +1 -0
  158. package/package.json +9 -16
  159. package/server.js +1 -1
  160. package/app/fiori/preview.js +0 -270
  161. package/app/fiori/routes.js +0 -59
  162. package/bin/build/buildTaskEngine.js +0 -360
  163. package/bin/build/buildTaskFactory.js +0 -283
  164. package/bin/build/buildTaskHandler.js +0 -241
  165. package/bin/build/buildTaskProvider.js +0 -22
  166. package/bin/build/buildTaskProviderFactory.js +0 -175
  167. package/bin/build/cds.js +0 -5
  168. package/bin/build/constants.js +0 -66
  169. package/bin/build/index.js +0 -58
  170. package/bin/build/provider/buildTaskHandlerEdmx.js +0 -82
  171. package/bin/build/provider/buildTaskHandlerFeatureToggles.js +0 -131
  172. package/bin/build/provider/buildTaskHandlerInternal.js +0 -254
  173. package/bin/build/provider/buildTaskProviderInternal.js +0 -383
  174. package/bin/build/provider/fiori/index.js +0 -171
  175. package/bin/build/provider/hana/2migration.js +0 -179
  176. package/bin/build/provider/hana/index.js +0 -505
  177. package/bin/build/provider/hana/migrationtable.js +0 -472
  178. package/bin/build/provider/hana/template/.hdiconfig-haas +0 -163
  179. package/bin/build/provider/hana/template/.hdiconfig-hanacloud +0 -137
  180. package/bin/build/provider/hana/template/.hdinamespace +0 -4
  181. package/bin/build/provider/hana/template/package.json +0 -12
  182. package/bin/build/provider/hana/template/undeploy.json +0 -5
  183. package/bin/build/provider/java/index.js +0 -111
  184. package/bin/build/provider/java-cf/index.js +0 -1
  185. package/bin/build/provider/mtx/index.js +0 -268
  186. package/bin/build/provider/mtx/resourcesTarBuilder.js +0 -95
  187. package/bin/build/provider/mtx-extension/index.js +0 -131
  188. package/bin/build/provider/mtx-sidecar/index.js +0 -137
  189. package/bin/build/provider/node-cf/index.js +0 -1
  190. package/bin/build/provider/nodejs/index.js +0 -192
  191. package/bin/build/util.js +0 -299
  192. package/bin/cds.js +0 -125
  193. package/bin/deploy/to-hana/cfUtil.js +0 -355
  194. package/bin/deploy/to-hana/gitUtil.js +0 -57
  195. package/bin/deploy/to-hana/hana.js +0 -306
  196. package/bin/deploy/to-hana/hdiDeployUtil.js +0 -153
  197. package/bin/deploy/to-hana/index.js +0 -16
  198. package/bin/deploy/to-hana/mtaUtil.js +0 -170
  199. package/bin/mtx/in-cds.js +0 -17
  200. package/bin/plugins.js +0 -32
  201. package/bin/run.js +0 -24
  202. package/bin/utils/log.js +0 -24
  203. package/bin/version.js +0 -178
  204. package/libx/_runtime/audit/Service.js +0 -222
  205. package/libx/_runtime/audit/generic/personal/access.js +0 -61
  206. package/libx/_runtime/audit/generic/personal/index.js +0 -56
  207. package/libx/_runtime/audit/generic/personal/modification.js +0 -132
  208. package/libx/_runtime/audit/generic/personal/utils.js +0 -186
  209. package/libx/_runtime/audit/utils/log.js +0 -23
  210. package/libx/_runtime/audit/utils/v2.js +0 -176
  211. package/libx/_runtime/db/data-conversion/timestamp.js +0 -9
  212. package/libx/_runtime/db/generic/integrity.js +0 -455
  213. package/srv/audit-log.cds +0 -87
  214. package/srv/mtx.cds +0 -2
  215. package/srv/mtx.js +0 -8
  216. /package/lib/{core → linked}/classes.js +0 -0
  217. /package/lib/{core → linked}/entities.js +0 -0
@@ -1,472 +0,0 @@
1
- const fs = require('fs').promises
2
- const {existsSync} = require('fs')
3
- class MigrationTableParser {
4
- constructor() {
5
- }
6
-
7
- async read(filePath, options = { encoding: 'utf8' }) {
8
- if (existsSync(filePath)) {
9
- return this.parse((await fs.readFile(filePath, options)).replace(/\r\n/g, '\n'))
10
- }
11
- return null
12
- }
13
-
14
- /**
15
- * Parses the given .hdbmigrationtable file content and returns the @see MigrationTableModel representation.
16
- *
17
- * @param {String} content The .hdbmigrationtable file content.
18
- * @returns {MigrationTableModel} The migration table model representation of the given .hdbmigrationtable file content.
19
- */
20
- parse(content) {
21
- const lines = content.split('\n')
22
- this._validate(lines)
23
- const table = this._parseTable(lines)
24
- const migrations = this._parseMigrations(lines, table)
25
- return new MigrationTableModel(table, migrations)
26
- }
27
-
28
- _validate(lines) {
29
- let isTableBegin = false, isTableEnd = false, isMigration = false
30
- let tVersion, mVersion = -1
31
- for (let idx = 0; idx < lines.length; idx++) {
32
- if (MigrationTableParser._isVersionMarker(lines[idx])) {
33
- tVersion = MigrationTableParser._parseVersionNumber(lines[idx])
34
- if (isTableBegin || isTableEnd || isMigration) {
35
- throw new Error(`Invalid format, version defintion must be very first statement`)
36
- }
37
- } else if (/^\s*(ROW(\s*COLUMN)?|COLUMN)\s*TABLE\s/.test(lines[idx])) {
38
- if (tVersion === -1) {
39
- throw new Error(`Invalid format, version entry not complying to format '^== version=d+'`)
40
- }
41
- if (isTableBegin) {
42
- throw new Error(`Invalid format, multiple TABLE definitions found`)
43
- }
44
- if (isMigration) {
45
- throw new Error(`Invalid format, migrations must not be mixed with TABLE definitions`)
46
- }
47
- isTableBegin = true
48
- } else if (MigrationTableParser._isMigrationMarker(lines[idx])) {
49
- const version = MigrationTableParser._parseVersionNumber(lines[idx])
50
- if (version === -1) {
51
- throw new Error(`Invalid format, migration entry not complying to format '^== version=d+'`)
52
- }
53
- if (version > mVersion) {
54
- mVersion = version
55
- }
56
- if (!isMigration) {
57
- if (!isTableBegin) {
58
- throw new Error(`Invalid format, TABLE statement missing`)
59
- }
60
- // back search for end table
61
- for (let tIdx = idx - 1; tIdx > 0; tIdx--) {
62
- if (MigrationTableParser._isDDL(lines[tIdx])
63
- || MigrationTableParser._isComment(lines[tIdx])) {
64
- isTableEnd = true
65
- break
66
- }
67
- }
68
- isMigration = true
69
- }
70
- } else if (isTableBegin && !isMigration && idx + 1 === lines.length) {
71
- isTableEnd = true
72
- }
73
- }
74
- if (!isTableBegin) {
75
- throw new Error(`Invalid format, TABLE statement missing`)
76
- }
77
- if (!isTableEnd) {
78
- throw new Error(`Invalid format, TABLE statement not correctly terminated`)
79
- }
80
- if (!isMigration && tVersion > 1) {
81
- throw new Error(`Invalid format, '== migration=${tVersion}' entry missing`)
82
- }
83
- if (mVersion !== -1 && mVersion !== tVersion) {
84
- throw new Error(`Invalid format, migration version ${mVersion} does not match table version ${tVersion}`)
85
- }
86
- }
87
-
88
- _parseTable(lines) {
89
- const format = { startLine: -1, endLine: -1 }
90
- for (let idx = 0; idx < lines.length; idx++) {
91
- if (format.startLine === -1) {
92
- if (MigrationTableParser._isVersionMarker(lines[idx])) {
93
- format.startLine = idx
94
- }
95
- } else if (format.endLine === -1) {
96
- let tIdx = -1
97
- if (MigrationTableParser._isMigrationMarker(lines[idx])) {
98
- tIdx = idx - 1
99
- } else if (idx + 1 === lines.length) {
100
- tIdx = idx
101
- }
102
- // back search for end of table, comments belong to table
103
- for (; tIdx > format.startLine; tIdx--) {
104
- if (MigrationTableParser._isDDL(lines[tIdx])
105
- || MigrationTableParser._isComment(lines[tIdx])) {
106
- format.endLine = tIdx
107
- break
108
- }
109
- }
110
- } else {
111
- break
112
- }
113
- }
114
- if (format.startLine === -1) {
115
- throw new Error(`Invalid format, '== version=' entry missing`)
116
- }
117
- return new MigrationTable(lines, format)
118
- }
119
-
120
- _parseMigrations(lines, table) {
121
- const migrations = []
122
- let format = { startLine: -1, endLine: -1 }
123
- for (let idx = table.lines.length; idx < lines.length; idx++) {
124
- let nextMigration = false
125
- if (MigrationTableParser._isMigrationMarker(lines[idx])) {
126
- if (format.startLine === -1) {
127
- format.startLine = idx
128
- } else {
129
- nextMigration = true
130
- }
131
- }
132
- if (format.startLine !== -1 && (nextMigration || (idx + 1) === lines.length)) {
133
- // skip empty lines
134
- for (let mIdx = nextMigration ? idx - 1 : idx; mIdx > format.startLine; mIdx--) {
135
- if (!/^\s*$/.test(lines[mIdx])) {
136
- format.endLine = mIdx
137
- break
138
- }
139
- }
140
- migrations.push(new Migration(lines, format))
141
- if (nextMigration) {
142
- format = { startLine: idx, endLine: -1 }
143
- }
144
- }
145
- }
146
- return new Migrations(migrations)
147
- }
148
-
149
- // any lines that do not start with a comment or conflict marker and do not represent version tags
150
- static _isDDL(line) {
151
- return !/^\s*--|^\s*==|^\s*$|^\s*>>>>>/.test(line)
152
- }
153
-
154
- static _isComment(line) {
155
- return /^\s*--/.test(line)
156
- }
157
-
158
- static _isConflictMarker(line) {
159
- return /^\s*>>>>>/.test(line)
160
- }
161
-
162
- static _isVersionMarker(line) {
163
- return /^\s*== version=\d+\s*$/.test(line)
164
- }
165
-
166
- static _isMigrationMarker(line) {
167
- return /^\s*== migration=\d+\s*$/.test(line)
168
- }
169
-
170
- static _parseVersionNumber(line) {
171
- let version = -1;
172
- const match = line.match(/(^\s*== version=|^\s*== migration=)(\d+)\s*$/)
173
- if (match && match.length === 3) {
174
- version = parseInt(match[2])
175
- }
176
- if (version === -1) {
177
- throw new Error(`Invalid format - ${line} is malformed, format '^== version=d+'|'^== migration=d+' expected`)
178
- }
179
- return version
180
- }
181
- }
182
-
183
- /**
184
- * Model representation of an entire .hdbmigrationtable file.
185
- * <p>
186
- * The MigrationTableModel provides access to underlying file contents using a well-defined API.
187
- */
188
- class MigrationTableModel {
189
- constructor(table, migrations) {
190
- this._table = table
191
- this._migrations = migrations
192
- }
193
-
194
- get versionNumber() {
195
- return this._table.versionNumber
196
- }
197
-
198
- get table() {
199
- return this._table
200
- }
201
-
202
- get migrations() {
203
- return this._migrations
204
- }
205
-
206
- toString() {
207
- return `${this._table.toString()}${(this._migrations.entries.length > 0 ? '\n\n' : '') + this._migrations.toString()}`
208
- }
209
- /**
210
- * Incorporates migration versions from base (since the time their histories diverged from the current migration version)
211
- * into the current branch representing the extension.
212
- * <code>extension.merge(base, targetTable)</code>
213
- *
214
- * A---B---E---F extension X---Y extension
215
- * / /
216
- * A---B---C base A---B base
217
- *
218
- * || upgrade extension with base - migration version C is inserted into extension, its version number is updated,
219
- * || its version number is rebased on the version number of the extension
220
- * \/
221
- *
222
- * A---B---E---F---C extension A---B---X---Y extension
223
- * / /
224
- * A---B---C base A---B base
225
- *
226
- * @param {MigrationTableModel} base The new base migration table version from which all missing migration versions
227
- * will be taken and merged into the new migration table result.
228
- * @param {MigrationTable} targetTable The column table representing the merge result. Technically speaking - it is
229
- * retrieved from the migration table file created by cds build based on the final CDS model version.
230
- * @returns {MigrationTableModel} The merge result containg missing migrations from base.
231
- */
232
- merge(base, targetTable, addBaseVersionAnnotation) {
233
- let idxBase = this._findCommonBaseMigrationIdx(base)
234
- const mergeResult = new MigrationTableModel(targetTable, this.migrations.clone())
235
-
236
- // insert all migration versions since the histories diverged
237
- for (let idx = idxBase >= 0 ? idxBase - 1 : base.migrations.entries.length - 1, versionNumber = this.versionNumber + 1; idx >= 0; idx--, versionNumber++) {
238
- const migration = base.migrations.entries[idx].clone();
239
- if (addBaseVersionAnnotation) {
240
- migration._addBaseMigrationVersion(migration.versionNumber)
241
- }
242
- // update migration version number and insert at beginning
243
- migration.versionNumber = mergeResult.table.versionNumber = versionNumber
244
- mergeResult.migrations.entries.splice(0, 0, migration)
245
- }
246
- return mergeResult
247
- }
248
-
249
- clone() {
250
- return new MigrationTableModel(this.table.clone(), this.migrations.clone())
251
- }
252
-
253
- /**
254
- * Returns the index of the common base migration version (since the time their histories diverged)
255
- * or -1 if there is no common base. The index points to the base migration table model.
256
- * @param {MigrationTableModel} base The new base migration table version.
257
- * @returns The index of the common base migration, -1 if there is no common base.
258
- */
259
- _findCommonBaseMigrationIdx(base) {
260
- // get the index based on the annotation '-- migration-base=<version number>'
261
- const extMigration = this.migrations.entries.find(extMigration => extMigration._getBaseMigrationVersion() !== -1)
262
- // get the index based on DDL equality
263
- const idxBase = base.migrations.entries.findIndex(baseMigration => {
264
- return this.migrations.entries.some(extMigration => this._compareMigrations(baseMigration, extMigration))
265
- })
266
- if (!extMigration && idxBase === -1) {
267
- // no common base version - all good
268
- return -1
269
- }
270
- if (extMigration && idxBase !== -1 && extMigration._getBaseMigrationVersion() === base.migrations.entries[idxBase].versionNumber) {
271
- // both indices refer to the same base version - all good
272
- return idxBase
273
- }
274
- // differences encountered, cause might be:
275
- // 1. older versions may not add 'migration-base' annotations
276
- // 2. the same DDL statements might exist in different migrations
277
- if (!extMigration && idxBase !== -1) {
278
- // if migration-base annotations do not exist use equality of DDL statements
279
- // older versions did not add 'migration-base' annotations - most probably all good
280
- return idxBase
281
- }
282
- if (extMigration) {
283
- // favor 'migration-base' annotation over DDL statement equality
284
- const baseVersion = extMigration._getBaseMigrationVersion()
285
- const idxBase = base.migrations.entries.findIndex(baseMigration => baseMigration.versionNumber === baseVersion)
286
- if (idxBase > -1) {
287
- return idxBase
288
- }
289
- }
290
- return idxBase
291
- }
292
-
293
- /**
294
- * Migrations are identical if the corresponding DDL statements are identical,
295
- * ignoring order and ignoring comments.
296
- */
297
- _compareMigrations(m1, m2) {
298
- if (m1.ddl.length !== m2.ddl.length) {
299
- return false
300
- }
301
- const mDdl2 = m2.ddl.map(entry => this._compactLine(entry))
302
- return m1.ddl.some(entry => mDdl2.includes(this._compactLine(entry)))
303
- }
304
-
305
- /**
306
- * Delete comments and return only those lines representing DDL statements.
307
- */
308
- _compactLine(line) {
309
- return line.replace(/ /g, '')
310
- }
311
- }
312
-
313
- /**
314
- * Representation of the table SQL statement within an .hdbmigrationtable file.
315
- */
316
- class MigrationTable {
317
- /**
318
- * Constructor
319
- * @param {*} lines If the format parameter is passed the given lines represent all lines of the migration table file where format defines start and the end line.
320
- * If the format is ommitted the lines parameter only contains the lines of this table definition.
321
- * @param {*} format The format defines the start and end line of the table definition within the given lines.
322
- */
323
- constructor(lines, format) {
324
- lines = Array.isArray(lines) ? lines : lines.split('\n')
325
- if (format) {
326
- if (format.startLine < 0 || format.startLine > format.endLine) {
327
- throw Error("Invalid format of DDL table statement - end line has to be larger that start line")
328
- }
329
- this._lines = lines.slice(format.startLine, format.endLine + 1)
330
- } else {
331
- this._lines = lines
332
- }
333
- this._versionNumber = MigrationTableParser._parseVersionNumber(this._lines[0])
334
- }
335
-
336
- get versionNumber() {
337
- return this._versionNumber
338
- }
339
-
340
- set versionNumber(newVersion) {
341
- if (newVersion < 1) {
342
- throw new Error(`Invalid migration table version number ${newVersion} `)
343
- }
344
- this._lines[0] = this._lines[0].replace(this.versionNumber, newVersion)
345
- this._versionNumber = newVersion
346
- }
347
-
348
- get lines() {
349
- return this._lines
350
- }
351
-
352
- toString() {
353
- return this.lines.join('\n')
354
- }
355
-
356
- clone() {
357
- return new MigrationTable(JSON.parse(JSON.stringify(this.lines)))
358
- }
359
- }
360
-
361
- class Migrations {
362
- constructor(migrations = []) {
363
- this._migrations = migrations.sort((a, b) => b.versionNumber - a.versionNumber)
364
- }
365
- get versionNumber() {
366
- return this._migrations.length > 0 ? this._migrations[0].versionNumber : 1
367
- }
368
- get entries() {
369
- return this._migrations
370
- }
371
- toString() {
372
- return this._migrations.map(migration => migration.toString()).join('\n\n')
373
- }
374
- clone() {
375
- return new Migrations(this._migrations.map(migration => migration.clone()))
376
- }
377
- }
378
- /**
379
- * Representation of a migration version within an .hdbmigrationtable file.
380
- * <p>
381
- * The first line of a migration represents the version definition.
382
- * A migration may contain multiple line comments and any number of DDL statements.
383
- * The latter can be accessed using the changeset method.
384
- */
385
- class Migration {
386
- /**
387
- * Constructor
388
- * @param {*} lines If the format parameter is passed the given lines represent all lines of the migration table file where format defines start and the end line.
389
- * If the format is ommitted the lines parameter only contains the lines of this migration version.
390
- * @param {*} format The format defines the start and end line of the migration version within the given lines.
391
- */
392
- constructor(lines, format) {
393
- if (format) {
394
- if (format.startLine < 0 || format.startLine > format.endLine) {
395
- throw Error("Invalid migration format")
396
- }
397
- this._lines = lines.slice(format.startLine, format.endLine + 1)
398
- } else {
399
- this._lines = lines
400
- }
401
- this._versionNumber = MigrationTableParser._parseVersionNumber(this.lines[0])
402
- }
403
-
404
- /**
405
- * Returns the version number of this migration.
406
- */
407
- get versionNumber() {
408
- return this._versionNumber
409
- }
410
-
411
- set versionNumber(newVersion) {
412
- if (newVersion < 1) {
413
- throw new Error(`Invalid migration table version number ${newVersion} `)
414
- }
415
- this._lines[0] = this._lines[0].replace(this.versionNumber, newVersion)
416
- this._versionNumber = newVersion
417
- }
418
-
419
- /**
420
- * Returns the entire content of this migration including version and any line comments.
421
- */
422
- get lines() {
423
- return this._lines
424
- }
425
-
426
- /**
427
- * Returns the changeset containing the DDL statements of this migration.
428
- */
429
- get changeset() {
430
- return this._lines.filter(line => !MigrationTableParser._isMigrationMarker(line))
431
- }
432
-
433
- /**
434
- * Returns the DDL statements of this changeset. Any lines that do not start with a comment or conflict marker
435
- * and do not represent version tags are treated as valid DDL statements.
436
- */
437
- get ddl() {
438
- return this.changeset.filter(line => MigrationTableParser._isDDL(line))
439
- }
440
-
441
- _addBaseMigrationVersion(versionNumber) {
442
- this._addComment(1, `-- migration-base=${versionNumber}`)
443
- }
444
-
445
- _getBaseMigrationVersion() {
446
- let versionNumber = -1
447
- if (this._lines.length > 1) {
448
- const match = this._lines[1].match(/(^\s*-- migration-base=)(\d+)\s*$/)
449
- if (match && match.length === 3) {
450
- versionNumber = parseInt(match[2])
451
- }
452
- }
453
- return versionNumber
454
- }
455
-
456
- _addComment(start, comment) {
457
- this._lines.splice(start, 0, comment)
458
- }
459
-
460
- /**
461
- * Returns the string representation of this migration.
462
- */
463
- toString() {
464
- return this.lines.join('\n')
465
- }
466
-
467
- clone() {
468
- return new Migration(JSON.parse(JSON.stringify(this.lines)))
469
- }
470
- }
471
-
472
- module.exports = new MigrationTableParser()
@@ -1,163 +0,0 @@
1
- {
2
- "file_suffixes": {
3
- "csv": {
4
- "plugin_name": "com.sap.hana.di.tabledata.source"
5
- },
6
- "hdbafllangprocedure": {
7
- "plugin_name": "com.sap.hana.di.afllangprocedure"
8
- },
9
- "hdbanalyticprivilege": {
10
- "plugin_name": "com.sap.hana.di.analyticprivilege"
11
- },
12
- "hdbcalculationview": {
13
- "plugin_name": "com.sap.hana.di.calculationview"
14
- },
15
- "hdbcds": {
16
- "plugin_name": "com.sap.hana.di.cds"
17
- },
18
- "hdbcollection": {
19
- "plugin_name": "com.sap.hana.di.collection"
20
- },
21
- "hdbconstraint": {
22
- "plugin_name": "com.sap.hana.di.constraint"
23
- },
24
- "hdbdropcreatetable": {
25
- "plugin_name": "com.sap.hana.di.dropcreatetable"
26
- },
27
- "hdbflowgraph": {
28
- "plugin_name": "com.sap.hana.di.flowgraph"
29
- },
30
- "hdbfulltextindex": {
31
- "plugin_name": "com.sap.hana.di.fulltextindex"
32
- },
33
- "hdbfunction": {
34
- "plugin_name": "com.sap.hana.di.function"
35
- },
36
- "hdbgraphworkspace": {
37
- "plugin_name": "com.sap.hana.di.graphworkspace"
38
- },
39
- "hdbhadoopmrjob": {
40
- "plugin_name": "com.sap.hana.di.virtualfunctionpackage.hadoop"
41
- },
42
- "hdbindex": {
43
- "plugin_name": "com.sap.hana.di.index"
44
- },
45
- "hdblibrary": {
46
- "plugin_name": "com.sap.hana.di.library"
47
- },
48
- "hdbmigrationtable": {
49
- "plugin_name": "com.sap.hana.di.table.migration"
50
- },
51
- "hdbprocedure": {
52
- "plugin_name": "com.sap.hana.di.procedure"
53
- },
54
- "hdbprojectionview": {
55
- "plugin_name": "com.sap.hana.di.projectionview"
56
- },
57
- "hdbprojectionviewconfig": {
58
- "plugin_name": "com.sap.hana.di.projectionview.config"
59
- },
60
- "hdbreptask": {
61
- "plugin_name": "com.sap.hana.di.reptask"
62
- },
63
- "hdbresultcache": {
64
- "plugin_name": "com.sap.hana.di.resultcache"
65
- },
66
- "hdbrole": {
67
- "plugin_name": "com.sap.hana.di.role"
68
- },
69
- "hdbroleconfig": {
70
- "plugin_name": "com.sap.hana.di.role.config"
71
- },
72
- "hdbsearchruleset": {
73
- "plugin_name": "com.sap.hana.di.searchruleset"
74
- },
75
- "hdbsequence": {
76
- "plugin_name": "com.sap.hana.di.sequence"
77
- },
78
- "hdbstatistics": {
79
- "plugin_name": "com.sap.hana.di.statistics"
80
- },
81
- "hdbstructuredprivilege": {
82
- "plugin_name": "com.sap.hana.di.structuredprivilege"
83
- },
84
- "hdbsynonym": {
85
- "plugin_name": "com.sap.hana.di.synonym"
86
- },
87
- "hdbsynonymconfig": {
88
- "plugin_name": "com.sap.hana.di.synonym.config"
89
- },
90
- "hdbsystemversioning": {
91
- "plugin_name": "com.sap.hana.di.systemversioning"
92
- },
93
- "hdbtable": {
94
- "plugin_name": "com.sap.hana.di.table"
95
- },
96
- "hdbtabledata": {
97
- "plugin_name": "com.sap.hana.di.tabledata"
98
- },
99
- "hdbtabletype": {
100
- "plugin_name": "com.sap.hana.di.tabletype"
101
- },
102
- "hdbtextconfig": {
103
- "plugin_name": "com.sap.hana.di.textconfig"
104
- },
105
- "hdbtextdict": {
106
- "plugin_name": "com.sap.hana.di.textdictionary"
107
- },
108
- "hdbtextinclude": {
109
- "plugin_name": "com.sap.hana.di.textrule.include"
110
- },
111
- "hdbtextlexicon": {
112
- "plugin_name": "com.sap.hana.di.textrule.lexicon"
113
- },
114
- "hdbtextminingconfig": {
115
- "plugin_name": "com.sap.hana.di.textminingconfig"
116
- },
117
- "hdbtextrule": {
118
- "plugin_name": "com.sap.hana.di.textrule"
119
- },
120
- "hdbtrigger": {
121
- "plugin_name": "com.sap.hana.di.trigger"
122
- },
123
- "hdbview": {
124
- "plugin_name": "com.sap.hana.di.view"
125
- },
126
- "hdbvirtualfunction": {
127
- "plugin_name": "com.sap.hana.di.virtualfunction"
128
- },
129
- "hdbvirtualfunctionconfig": {
130
- "plugin_name": "com.sap.hana.di.virtualfunction.config"
131
- },
132
- "hdbvirtualpackagehadoop": {
133
- "plugin_name": "com.sap.hana.di.virtualpackage.hadoop"
134
- },
135
- "hdbvirtualpackagesparksql": {
136
- "plugin_name": "com.sap.hana.di.virtualpackage.sparksql"
137
- },
138
- "hdbvirtualprocedure": {
139
- "plugin_name": "com.sap.hana.di.virtualprocedure"
140
- },
141
- "hdbvirtualprocedureconfig": {
142
- "plugin_name": "com.sap.hana.di.virtualprocedure.config"
143
- },
144
- "hdbvirtualtable": {
145
- "plugin_name": "com.sap.hana.di.virtualtable"
146
- },
147
- "hdbvirtualtableconfig": {
148
- "plugin_name": "com.sap.hana.di.virtualtable.config"
149
- },
150
- "jar": {
151
- "plugin_name": "com.sap.hana.di.virtualfunctionpackage.hadoop"
152
- },
153
- "properties": {
154
- "plugin_name": "com.sap.hana.di.tabledata.properties"
155
- },
156
- "tags": {
157
- "plugin_name": "com.sap.hana.di.tabledata.properties"
158
- },
159
- "txt": {
160
- "plugin_name": "com.sap.hana.di.copyonly"
161
- }
162
- }
163
- }