@sap/cds 1.15.1 → 1.18.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.
- package/CHANGELOG.md +25 -0
- package/{developer-license-3.1.txt → LICENSE} +37 -35
- package/_hdbext/README.md +373 -0
- package/_hdbext/index.js +4 -0
- package/_hdbext/lib/client-factory.js +62 -0
- package/_hdbext/lib/client-session.js +96 -0
- package/_hdbext/lib/conn-options.js +84 -0
- package/_hdbext/lib/constants.js +79 -0
- package/_hdbext/lib/internal-constants.js +7 -0
- package/_hdbext/lib/middleware.js +46 -0
- package/_hdbext/lib/pool.js +236 -0
- package/_hdbext/lib/safe-sql.js +17 -0
- package/_hdbext/lib/sql-injection-utils.js +149 -0
- package/cds-queries-geo.js +347 -371
- package/cds-queries.js +2692 -2229
- package/cds.js +111 -104
- package/exprs.js +118 -107
- package/manager.js +696 -614
- package/metadata.js +604 -542
- package/npm-shrinkwrap.json +268 -0
- package/package.json +40 -1
- package/transaction.js +45 -51
- package/util/Queue.js +32 -30
- package/utils.js +182 -159
- package/xsjs-cds.js +231 -221
- package/.project +0 -11
- package/SIGNATURE.SMF +0 -1747
- package/TUTORIAL.md +0 -1236
- package/dependencies +0 -56
package/xsjs-cds.js
CHANGED
|
@@ -1,248 +1,258 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/* eslint-disable prefer-rest-params */
|
|
2
|
+
const cds = require('./cds');
|
|
3
|
+
const origExecFct = cds.queries.Query.prototype.$execute;
|
|
3
4
|
|
|
4
5
|
exports.init = function(tx) {
|
|
6
|
+
function resolveEntityReferences(obj) {
|
|
7
|
+
if (typeof obj === 'object' || typeof obj === 'function') {
|
|
8
|
+
if (obj.$_metadata) {
|
|
9
|
+
return obj.$_metadata.entityName;
|
|
10
|
+
}
|
|
11
|
+
const result = {};
|
|
12
|
+
for (const p in obj) {
|
|
13
|
+
result[p] = resolveEntityReferences(obj[p]);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
} else {
|
|
17
|
+
return obj;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
5
20
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
function adaptImport(importSpec) {
|
|
22
|
+
const result = {
|
|
23
|
+
$entity: `${importSpec[0] }::${ importSpec[1]}`,
|
|
24
|
+
$fields: resolveEntityReferences(importSpec[2]),
|
|
25
|
+
$options: importSpec[3],
|
|
26
|
+
};
|
|
27
|
+
if (importSpec[3] && importSpec[3].$entityName) {
|
|
28
|
+
result.$name = importSpec[3].$entityName;
|
|
29
|
+
}
|
|
30
|
+
if (importSpec[3] && importSpec[3].$viaTable) {
|
|
31
|
+
result.$viaEntity = importSpec[3].$viaTable;
|
|
32
|
+
}
|
|
33
|
+
return [result];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function adaptDefine(importSpec) {
|
|
37
|
+
const matches = /"(\w+)"\."([\w.:]+)"/g.exec(importSpec[1]);
|
|
38
|
+
const result = {
|
|
39
|
+
$name: importSpec[0],
|
|
40
|
+
$table: matches[2],
|
|
41
|
+
$schema: matches[1],
|
|
42
|
+
$fields: resolveEntityReferences(importSpec[2]),
|
|
43
|
+
$options: importSpec[3],
|
|
44
|
+
};
|
|
45
|
+
return [result];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const wrapperRepo = {};
|
|
49
|
+
|
|
50
|
+
function makeSkeleton(values, mapping) {
|
|
51
|
+
let res;
|
|
52
|
+
let nextMapping;
|
|
53
|
+
for (const p in mapping) {
|
|
54
|
+
if (p.substring(0, 1) === '$') {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (!res) {
|
|
58
|
+
res = {};
|
|
59
|
+
}
|
|
60
|
+
if (values[p] && (values[p].$__entity || values[p].$_entity)) {
|
|
61
|
+
res[p] = values[p];
|
|
62
|
+
} else if (Object.prototype.toString.call(values[p]) === '[object Array]') {
|
|
63
|
+
nextMapping = mapping[p].$association ?
|
|
64
|
+
mapping[p].$association.$class.$_mapping : mapping[p];
|
|
65
|
+
res[p] = values[p].map(function(e) {
|
|
66
|
+
if (e.$__entity || e.$_entity) {
|
|
67
|
+
return e;
|
|
68
|
+
} else {
|
|
69
|
+
return makeSkeleton(e, nextMapping);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
} else if (Object.prototype.toString.call(values[p]) === '[object Object]') {
|
|
73
|
+
nextMapping = mapping[p].$association ?
|
|
74
|
+
mapping[p].$association.$class.$_mapping : mapping[p];
|
|
75
|
+
res[p] = makeSkeleton(values[p], nextMapping);
|
|
76
|
+
} else if (typeof values[p] !== 'undefined') {
|
|
77
|
+
res[p] = values[p];
|
|
78
|
+
} else if (
|
|
79
|
+
mapping[p].$association &&
|
|
80
|
+
(mapping[p].$viaBacklink || mapping[p].$viaEntity)
|
|
81
|
+
) {
|
|
82
|
+
res[p] = [];
|
|
83
|
+
} else if (mapping[p].$association) {
|
|
84
|
+
res[p] = null;
|
|
85
|
+
} else {
|
|
86
|
+
res[p] = makeSkeleton({}, mapping[p]);
|
|
87
|
+
}
|
|
19
88
|
}
|
|
89
|
+
return res;
|
|
90
|
+
}
|
|
20
91
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (importSpec[3] && importSpec[3].$entityName) {
|
|
28
|
-
result.$name = importSpec[3].$entityName;
|
|
92
|
+
function getWrapper(name, entity) {
|
|
93
|
+
if (!wrapperRepo[name]) {
|
|
94
|
+
const result = function(skeleton) { // constructor
|
|
95
|
+
const e = entity;
|
|
96
|
+
if (!skeleton.$__entity) {
|
|
97
|
+
skeleton = makeSkeleton(skeleton, e.$_mapping);
|
|
29
98
|
}
|
|
30
|
-
|
|
31
|
-
|
|
99
|
+
Object.defineProperty(skeleton, '$save',
|
|
100
|
+
{
|
|
101
|
+
value: function() {
|
|
102
|
+
return tx.$save.sync(entity.$prepare(this));
|
|
103
|
+
},
|
|
104
|
+
enumerable: false,
|
|
105
|
+
configurable: true,
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(skeleton, '$persist',
|
|
108
|
+
{
|
|
109
|
+
value: function() {
|
|
110
|
+
return tx.$save.sync(entity.$prepare(this));
|
|
111
|
+
},
|
|
112
|
+
enumerable: false,
|
|
113
|
+
configurable: true,
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(skeleton, '$discard',
|
|
116
|
+
{
|
|
117
|
+
value: function() {
|
|
118
|
+
return tx.$discard.sync(entity.$prepare(this));
|
|
119
|
+
},
|
|
120
|
+
enumerable: false,
|
|
121
|
+
configurable: true,
|
|
122
|
+
});
|
|
123
|
+
return skeleton;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
for (const p in entity) {
|
|
127
|
+
result[p] = entity[p];
|
|
128
|
+
}
|
|
129
|
+
cds.queries.addExpressionFunctions(entity, result);
|
|
130
|
+
|
|
131
|
+
result.$findAll = function(cond) {
|
|
132
|
+
if (arguments.length === 0) {
|
|
133
|
+
cond = {};
|
|
32
134
|
}
|
|
33
|
-
|
|
34
|
-
|
|
135
|
+
const r = entity.$findAll.sync.call(entity, cond);
|
|
136
|
+
return r;
|
|
137
|
+
};
|
|
35
138
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
139
|
+
result.$saveAll = function(instances) {
|
|
140
|
+
tx.$save(instances.map(function(inst) {
|
|
141
|
+
return entity.$prepare(inst);
|
|
142
|
+
}));
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
result.$discardAll = function(instances) {
|
|
146
|
+
tx.$discard(instances.map(function(inst) {
|
|
147
|
+
return entity.$prepare(inst);
|
|
148
|
+
}));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
result.$persistAll = result.$saveAll;
|
|
47
152
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var res;
|
|
52
|
-
for (var p in mapping) {
|
|
53
|
-
if (p.substring(0, 1) === '$') continue;
|
|
54
|
-
if (!res) res = {};
|
|
55
|
-
if (values[p] && (values[p].$__entity || values[p].$_entity)) {
|
|
56
|
-
res[p] = values[p];
|
|
57
|
-
} else if (Object.prototype.toString.call(values[p]) === "[object Array]") {
|
|
58
|
-
var nextMapping = mapping[p].$association ? mapping[p].$association.$class.$_mapping : mapping[p];
|
|
59
|
-
res[p] = values[p].map(function (e) {
|
|
60
|
-
if (e.$__entity || e.$_entity) {
|
|
61
|
-
return e;
|
|
62
|
-
} else {
|
|
63
|
-
return makeSkeleton(e, nextMapping);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
} else if (Object.prototype.toString.call(values[p]) === "[object Object]") {
|
|
67
|
-
var nextMapping = mapping[p].$association ? mapping[p].$association.$class.$_mapping : mapping[p];
|
|
68
|
-
res[p] = makeSkeleton(values[p], nextMapping);
|
|
69
|
-
} else if (typeof values[p] !== 'undefined') {
|
|
70
|
-
res[p] = values[p];
|
|
71
|
-
} else if (mapping[p].$association && (mapping[p].$viaBacklink || mapping[p].$viaEntity)) {
|
|
72
|
-
res[p] = [];
|
|
73
|
-
} else if (mapping[p].$association) {
|
|
74
|
-
res[p] = null;
|
|
75
|
-
} else {
|
|
76
|
-
res[p] = makeSkeleton({}, mapping[p]);
|
|
77
|
-
}
|
|
153
|
+
result.$find = function(cond) {
|
|
154
|
+
if (arguments.length === 0) {
|
|
155
|
+
cond = {};
|
|
78
156
|
}
|
|
79
|
-
|
|
80
|
-
|
|
157
|
+
const r = entity.$findAll.sync.call(entity, cond)[0];
|
|
158
|
+
return r;
|
|
159
|
+
};
|
|
81
160
|
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
var e = entity;
|
|
86
|
-
if (!skeleton.$__entity) {
|
|
87
|
-
skeleton = makeSkeleton(skeleton, e.$_mapping);
|
|
88
|
-
}
|
|
89
|
-
Object.defineProperty(skeleton, '$save',
|
|
90
|
-
{
|
|
91
|
-
value: function () {
|
|
92
|
-
return tx.$save.sync(entity.$prepare(this));
|
|
93
|
-
},
|
|
94
|
-
enumerable: false,
|
|
95
|
-
configurable: true
|
|
96
|
-
});
|
|
97
|
-
Object.defineProperty(skeleton, '$persist',
|
|
98
|
-
{
|
|
99
|
-
value: function () {
|
|
100
|
-
return tx.$save.sync(entity.$prepare(this));
|
|
101
|
-
},
|
|
102
|
-
enumerable: false,
|
|
103
|
-
configurable: true
|
|
104
|
-
});
|
|
105
|
-
Object.defineProperty(skeleton, '$discard',
|
|
106
|
-
{
|
|
107
|
-
value: function () {
|
|
108
|
-
return tx.$discard.sync(entity.$prepare(this));
|
|
109
|
-
},
|
|
110
|
-
enumerable: false,
|
|
111
|
-
configurable: true
|
|
112
|
-
});
|
|
113
|
-
return skeleton;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
for (var p in entity) {
|
|
117
|
-
result[p] = entity[p];
|
|
118
|
-
}
|
|
119
|
-
cds.queries.addExpressionFunctions(entity, result);
|
|
120
|
-
|
|
121
|
-
result.$findAll = function (cond) {
|
|
122
|
-
if (arguments.length === 0) {
|
|
123
|
-
cond = {};
|
|
124
|
-
}
|
|
125
|
-
var r = entity.$findAll.sync.call(entity, cond);
|
|
126
|
-
return r;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
result.$saveAll = function (instances) {
|
|
130
|
-
tx.$save(instances.map(function (inst) {
|
|
131
|
-
return entity.$prepare(inst);
|
|
132
|
-
}));
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
result.$discardAll = function (instances) {
|
|
136
|
-
tx.$discard(instances.map(function (inst) {
|
|
137
|
-
return entity.$prepare(inst);
|
|
138
|
-
}));
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
result.$persistAll = result.$saveAll;
|
|
142
|
-
|
|
143
|
-
result.$find = function (cond) {
|
|
144
|
-
if (arguments.length === 0) {
|
|
145
|
-
cond = {};
|
|
146
|
-
}
|
|
147
|
-
var r = entity.$findAll.sync.call(entity, cond)[0];
|
|
148
|
-
return r;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
result.$get = function (cond) {
|
|
152
|
-
if (arguments.length === 0) {
|
|
153
|
-
cond = {};
|
|
154
|
-
}
|
|
155
|
-
var r = entity.$get.sync.call(entity, cond);
|
|
156
|
-
return r;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
result.$query = function () {
|
|
160
|
-
var q = entity.$query();
|
|
161
|
-
q.syncExecute = true;
|
|
162
|
-
return q;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
wrapperRepo[name] = result;
|
|
161
|
+
result.$get = function(cond) {
|
|
162
|
+
if (arguments.length === 0) {
|
|
163
|
+
cond = {};
|
|
166
164
|
}
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
const r = entity.$get.sync.call(entity, cond);
|
|
166
|
+
return r;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
result.$query = function() {
|
|
170
|
+
const q = entity.$query();
|
|
171
|
+
q.syncExecute = true;
|
|
172
|
+
return q;
|
|
173
|
+
};
|
|
169
174
|
|
|
170
|
-
|
|
171
|
-
var alias = nodeImport[0].$name;
|
|
172
|
-
var entityName = nodeImport[0].$entity;
|
|
173
|
-
var imp = cds.$importEntities.sync(nodeImport);
|
|
174
|
-
var entity = imp[alias || entityName];
|
|
175
|
-
var name = entity.$_metadata.entityName;
|
|
176
|
-
var wrapped = getWrapper(name, entity);
|
|
177
|
-
return wrapped;
|
|
175
|
+
wrapperRepo[name] = result;
|
|
178
176
|
}
|
|
177
|
+
return wrapperRepo[name];
|
|
178
|
+
}
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
const retrieveEntity = function(nodeImport) {
|
|
181
|
+
const alias = nodeImport[0].$name;
|
|
182
|
+
const entityName = nodeImport[0].$entity;
|
|
183
|
+
const imp = cds.$importEntities.sync(nodeImport);
|
|
184
|
+
const entity = imp[alias || entityName];
|
|
185
|
+
const name = entity.$_metadata.entityName;
|
|
186
|
+
const wrapped = getWrapper(name, entity);
|
|
187
|
+
return wrapped;
|
|
188
|
+
};
|
|
184
189
|
|
|
185
|
-
|
|
190
|
+
exports.importEntity = function() {
|
|
191
|
+
const args = Array.prototype.slice.call(arguments);
|
|
192
|
+
return retrieveEntity.call(this, adaptImport(args));
|
|
193
|
+
};
|
|
186
194
|
|
|
187
|
-
|
|
188
|
-
var args = Array.prototype.slice.call(arguments);
|
|
189
|
-
return retrieveEntity.call(this, adaptDefine(args));
|
|
190
|
-
};
|
|
195
|
+
exports.$importEntity = exports.importEntity;
|
|
191
196
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
197
|
+
exports.defineEntity = function() {
|
|
198
|
+
const args = Array.prototype.slice.call(arguments);
|
|
199
|
+
return retrieveEntity.call(this, adaptDefine(args));
|
|
200
|
+
};
|
|
195
201
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
exports.getEntity = function(name) {
|
|
203
|
+
return getWrapper(name, cds.$getEntitySync(name));
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
cds.queries.Query.prototype.$execute = function() {
|
|
207
|
+
if (!this.syncExecute) {
|
|
208
|
+
return origExecFct.apply(this, arguments);
|
|
209
|
+
} else {
|
|
210
|
+
let args = Array.prototype.slice.call(arguments);
|
|
211
|
+
if (args.length === 0) {
|
|
212
|
+
args = [{}];
|
|
213
|
+
}
|
|
214
|
+
return origExecFct.sync.apply(this, args);
|
|
206
215
|
}
|
|
216
|
+
};
|
|
207
217
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
218
|
+
exports.cdsAsync = cds;
|
|
219
|
+
exports.Manager = {
|
|
220
|
+
clearCache: function() {
|
|
221
|
+
cds._clearCaches();
|
|
222
|
+
},
|
|
223
|
+
resetCaches: function() {
|
|
224
|
+
cds._clearCaches();
|
|
225
|
+
},
|
|
226
|
+
};
|
|
217
227
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
228
|
+
exports.Transaction = {
|
|
229
|
+
$commit: function(callback) {
|
|
230
|
+
tx.$commit(function(err) {
|
|
231
|
+
callback(err);
|
|
232
|
+
});
|
|
233
|
+
},
|
|
224
234
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
235
|
+
$close: function() {
|
|
236
|
+
tx.$close();
|
|
237
|
+
},
|
|
238
|
+
};
|
|
229
239
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
240
|
+
exports.Rename = {
|
|
241
|
+
$lowercase: 'lowercase',
|
|
242
|
+
};
|
|
233
243
|
|
|
234
|
-
|
|
235
|
-
|
|
244
|
+
exports.SqlQuery = cds.queries;
|
|
245
|
+
exports.Query = cds.createQuery;
|
|
236
246
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
return instance;
|
|
247
|
+
cds.extensionPoints.instanceMethods = function(instance) {
|
|
248
|
+
instance.$save = function() {
|
|
249
|
+
tx.$save(instance);
|
|
250
|
+
};
|
|
251
|
+
instance.$persist = instance.$save;
|
|
252
|
+
instance.$discard = function() {
|
|
253
|
+
tx.$discard(instance);
|
|
246
254
|
};
|
|
247
|
-
return
|
|
248
|
-
}
|
|
255
|
+
return instance;
|
|
256
|
+
};
|
|
257
|
+
return exports;
|
|
258
|
+
};
|