@sap/cds-dk 7.9.5 → 7.9.6
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.
- package/lib/init/template/data/as-json.js +25 -11
- package/npm-shrinkwrap.json +9 -12
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ const { dirname } = require('node:path')
|
|
|
3
3
|
const cds = require('../../../cds')
|
|
4
4
|
|
|
5
5
|
let counter = Math.round(Math.random() * 10000) // Default random seed // Non-deterministic behaviour
|
|
6
|
-
const MAX_ASSOC_DEPTH =
|
|
6
|
+
const MAX_ASSOC_DEPTH = 5
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Creates JSON test data for the given entities
|
|
@@ -40,25 +40,35 @@ const asJson = module.exports = async (data, csn, numRecords=1, options={}) => {
|
|
|
40
40
|
|
|
41
41
|
for (const name of entityNames) {
|
|
42
42
|
if (!data[name] // removed on purpose because records are created inline through compositions
|
|
43
|
-
|| data[name].length >= numRecords) { // already created by following associations
|
|
43
|
+
|| data[name].length >= numRecords) { // numRecords already created by following associations
|
|
44
44
|
continue
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
let numRecordsToGenerate // numRecords might be reduced if some records were created by following associations
|
|
48
|
+
let records = []
|
|
49
|
+
if (data[name].length > 0) {
|
|
50
|
+
numRecordsToGenerate = numRecords - data[name].length
|
|
51
|
+
records = Array(numRecordsToGenerate).fill({}).map(() => ({}))
|
|
52
|
+
} else {
|
|
53
|
+
numRecordsToGenerate = numRecords
|
|
54
|
+
records = data[name] = Array(numRecordsToGenerate).fill({}).map(() => ({}))
|
|
55
|
+
}
|
|
48
56
|
const entity = defs[name]
|
|
49
57
|
|
|
50
58
|
const idNum = randomNumber()
|
|
51
|
-
for (let i = 0; i <
|
|
59
|
+
for (let i = 0; i < numRecordsToGenerate; i++) {
|
|
52
60
|
fillRecord(records[i], idNum+i, entity, csn, data, null, 0, referenceData)
|
|
53
61
|
}
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
data[name] = data[name].concat(records) // append the new records to the possibly existingand referenced records
|
|
63
|
+
// remove records w/ duplicate keys. This can happen if the key is an enum (and we have less enum values than requested records).
|
|
64
|
+
data[name] = uniqRecords(data[name], entity)
|
|
56
65
|
}
|
|
57
66
|
return data
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
function fillRecord(record, recordID, entity, csn, data, parentEntity, depth, referenceData) {
|
|
61
70
|
Object.defineProperty(record, '$id', {value: recordID, enumerable: false})
|
|
71
|
+
if (data[entity.name]) data[entity.name].push(record) // add id to data, to be referenced by associations to prevent circular dependencies
|
|
62
72
|
|
|
63
73
|
const { elements } = entity
|
|
64
74
|
Object.values(elements).sort(asJson.elementsSorter(csn)).forEach(el => {
|
|
@@ -242,7 +252,7 @@ function dataForField(element, entity, csn, record, data, parentEntity, depth, r
|
|
|
242
252
|
if (element.is2many)
|
|
243
253
|
return
|
|
244
254
|
const target = csn.definitions[element.target]
|
|
245
|
-
if (!target ||
|
|
255
|
+
if (!target || depth > MAX_ASSOC_DEPTH)
|
|
246
256
|
return
|
|
247
257
|
|
|
248
258
|
let targetRecord = randomFromReferenceData(target, csn, referenceData)
|
|
@@ -256,10 +266,14 @@ function dataForField(element, entity, csn, record, data, parentEntity, depth, r
|
|
|
256
266
|
targetRecords = data[target.name] = []
|
|
257
267
|
else if (!targetRecords) // target entity is not in the list of entities to be created
|
|
258
268
|
return
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
|
|
270
|
+
if (targetRecords.length > 0) { // use record generated by following asociation
|
|
271
|
+
targetRecord = targetRecords[0]
|
|
272
|
+
} else {
|
|
273
|
+
targetRecord = fillRecord({}, randomNumber(), target, csn, data, entity, depth+1, referenceData)
|
|
274
|
+
targetRecords.push(targetRecord)
|
|
275
|
+
uniqRecords(targetRecords, target)
|
|
276
|
+
}
|
|
263
277
|
}
|
|
264
278
|
|
|
265
279
|
// TODO: handle foreign keys correctly
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap/cds-dk",
|
|
3
|
-
"version": "7.9.
|
|
3
|
+
"version": "7.9.6",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@sap/cds-dk",
|
|
9
|
-
"version": "7.9.
|
|
9
|
+
"version": "7.9.6",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@sap/cds": "^7",
|
|
@@ -208,10 +208,10 @@
|
|
|
208
208
|
}
|
|
209
209
|
},
|
|
210
210
|
"node_modules/@sap/cds": {
|
|
211
|
-
"version": "7.9.
|
|
211
|
+
"version": "7.9.4",
|
|
212
212
|
"license": "SEE LICENSE IN LICENSE",
|
|
213
213
|
"dependencies": {
|
|
214
|
-
"@cap-js/cds-types": "
|
|
214
|
+
"@cap-js/cds-types": "<=0.2.0",
|
|
215
215
|
"@sap/cds-compiler": "^4",
|
|
216
216
|
"@sap/cds-fiori": "^1",
|
|
217
217
|
"@sap/cds-foss": "^5.0.0"
|
|
@@ -225,7 +225,7 @@
|
|
|
225
225
|
}
|
|
226
226
|
},
|
|
227
227
|
"node_modules/@sap/cds-compiler": {
|
|
228
|
-
"version": "4.9.
|
|
228
|
+
"version": "4.9.6",
|
|
229
229
|
"license": "SEE LICENSE IN LICENSE",
|
|
230
230
|
"dependencies": {
|
|
231
231
|
"antlr4": "4.9.3"
|
|
@@ -2225,12 +2225,9 @@
|
|
|
2225
2225
|
}
|
|
2226
2226
|
},
|
|
2227
2227
|
"node_modules/node-addon-api": {
|
|
2228
|
-
"version": "7.1.
|
|
2228
|
+
"version": "7.1.1",
|
|
2229
2229
|
"license": "MIT",
|
|
2230
|
-
"optional": true
|
|
2231
|
-
"engines": {
|
|
2232
|
-
"node": "^16 || ^18 || >= 20"
|
|
2233
|
-
}
|
|
2230
|
+
"optional": true
|
|
2234
2231
|
},
|
|
2235
2232
|
"node_modules/node-cache": {
|
|
2236
2233
|
"version": "5.1.2",
|
|
@@ -2691,7 +2688,7 @@
|
|
|
2691
2688
|
"license": "ISC"
|
|
2692
2689
|
},
|
|
2693
2690
|
"node_modules/semver": {
|
|
2694
|
-
"version": "7.6.
|
|
2691
|
+
"version": "7.6.3",
|
|
2695
2692
|
"license": "ISC",
|
|
2696
2693
|
"bin": {
|
|
2697
2694
|
"semver": "bin/semver.js"
|
|
@@ -3139,7 +3136,7 @@
|
|
|
3139
3136
|
}
|
|
3140
3137
|
},
|
|
3141
3138
|
"node_modules/uglify-js": {
|
|
3142
|
-
"version": "3.
|
|
3139
|
+
"version": "3.19.0",
|
|
3143
3140
|
"license": "BSD-2-Clause",
|
|
3144
3141
|
"optional": true,
|
|
3145
3142
|
"bin": {
|