@puca/puca-core 13.3.2 → 13.4.0
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/dist/core/services/bootstrap-commands.js +65 -0
- package/dist/core/services/bootstrap-commands.js.map +1 -1
- package/dist/core/services/index.d.ts +2 -0
- package/dist/core/services/index.js +3 -1
- package/dist/core/services/index.js.map +1 -1
- package/dist/core/services/table-permission.service.js +47 -4
- package/dist/core/services/table-permission.service.js.map +1 -1
- package/dist/core/services/tag.service.d.ts +56 -0
- package/dist/core/services/tag.service.js +198 -0
- package/dist/core/services/tag.service.js.map +1 -0
- package/dist/helpers/is-primitive-type.d.ts +1 -1
- package/dist/helpers/is-primitive-type.js +1 -1
- package/dist/helpers/is-primitive-type.js.map +1 -1
- package/dist/models/crud-controller-especification-environment.d.ts +7 -0
- package/dist/models/crud-controller-especification-environment.js.map +1 -1
- package/dist/models/crud-controller-especification.d.ts +4 -0
- package/dist/models/crud-controller-especification.js.map +1 -1
- package/dist/models/field-dictionary.d.ts +3 -0
- package/dist/orm/cases/bo/ddl.service.js +1 -0
- package/dist/orm/cases/bo/ddl.service.js.map +1 -1
- package/dist/orm/cases/bo/interfaces.d.ts +3 -0
- package/dist/orm/cases/bo/interfaces.js.map +1 -1
- package/dist/orm/cases/vanilla/interfaces.d.ts +5 -2
- package/dist/orm/cases/vanilla/interfaces.js +3 -0
- package/dist/orm/cases/vanilla/interfaces.js.map +1 -1
- package/dist/orm/cases/vanilla/sql-builder/select.service.js +4 -1
- package/dist/orm/cases/vanilla/sql-builder/select.service.js.map +1 -1
- package/dist/orm/services/sql/sql-layer.service.d.ts +81 -8
- package/dist/orm/services/sql/sql-layer.service.js +521 -224
- package/dist/orm/services/sql/sql-layer.service.js.map +1 -1
- package/dist/orm/services/sql/sql-security-layer.service.js +4 -21
- package/dist/orm/services/sql/sql-security-layer.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/fuql-grammar.js +35 -5
- package/fuql-grammar.ne +28 -2
- package/package.json +1 -1
|
@@ -4,7 +4,6 @@ exports.SqlLayerService = void 0;
|
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
const logger_1 = require("../../../core/services/logger");
|
|
6
6
|
const helpers_1 = require("./helpers");
|
|
7
|
-
;
|
|
8
7
|
const isWhere = (field) => {
|
|
9
8
|
if (typeof field === 'string') {
|
|
10
9
|
return false;
|
|
@@ -28,19 +27,26 @@ const isWhere = (field) => {
|
|
|
28
27
|
return false;
|
|
29
28
|
};
|
|
30
29
|
class UnsafeResolver {
|
|
31
|
-
unsafeResolveStringValue(
|
|
32
|
-
if (!
|
|
33
|
-
return
|
|
30
|
+
unsafeResolveStringValue({ value, alias, parentAlias, path, }) {
|
|
31
|
+
if (!value) {
|
|
32
|
+
return value;
|
|
34
33
|
}
|
|
35
|
-
const r =
|
|
34
|
+
const r = value
|
|
35
|
+
.replace(/\{\{alias\}\}/g, alias)
|
|
36
|
+
.replace(/\{\{parentAlias\}\}/g, `${parentAlias}`);
|
|
36
37
|
return r;
|
|
37
38
|
}
|
|
38
|
-
unsafeResolveValue({ field, alias, path, user }) {
|
|
39
|
+
unsafeResolveValue({ field, alias, parentAlias, path, user, parentTableName, }) {
|
|
39
40
|
if (!field) {
|
|
40
41
|
return field;
|
|
41
42
|
}
|
|
42
43
|
if (typeof field === 'string') {
|
|
43
|
-
return this.unsafeResolveStringValue(
|
|
44
|
+
return this.unsafeResolveStringValue({
|
|
45
|
+
value: field,
|
|
46
|
+
alias,
|
|
47
|
+
parentAlias,
|
|
48
|
+
path,
|
|
49
|
+
});
|
|
44
50
|
}
|
|
45
51
|
if (typeof field === 'number' || typeof field === 'boolean') {
|
|
46
52
|
throw new Error(`invalid typeof ${field} === ${typeof field === 'number'}`);
|
|
@@ -53,13 +59,27 @@ class UnsafeResolver {
|
|
|
53
59
|
if (typeof p === 'string') {
|
|
54
60
|
return p;
|
|
55
61
|
}
|
|
56
|
-
return this.unsafeResolveValue({
|
|
62
|
+
return this.unsafeResolveValue({
|
|
63
|
+
field: p,
|
|
64
|
+
alias,
|
|
65
|
+
parentAlias,
|
|
66
|
+
path,
|
|
67
|
+
user,
|
|
68
|
+
parentTableName,
|
|
69
|
+
});
|
|
57
70
|
});
|
|
58
71
|
const orderBy = (field.over.orderBy || []).map(o => {
|
|
59
72
|
if (typeof o === 'string') {
|
|
60
73
|
return o;
|
|
61
74
|
}
|
|
62
|
-
const result = this.unsafeResolveValue({
|
|
75
|
+
const result = this.unsafeResolveValue({
|
|
76
|
+
field: o,
|
|
77
|
+
alias,
|
|
78
|
+
parentAlias,
|
|
79
|
+
path,
|
|
80
|
+
user,
|
|
81
|
+
parentTableName,
|
|
82
|
+
});
|
|
63
83
|
if (typeof result === 'string') {
|
|
64
84
|
return result;
|
|
65
85
|
}
|
|
@@ -67,7 +87,7 @@ class UnsafeResolver {
|
|
|
67
87
|
});
|
|
68
88
|
return {
|
|
69
89
|
partitionBy,
|
|
70
|
-
orderBy
|
|
90
|
+
orderBy,
|
|
71
91
|
};
|
|
72
92
|
};
|
|
73
93
|
if ('function' in field) {
|
|
@@ -75,47 +95,116 @@ class UnsafeResolver {
|
|
|
75
95
|
function: field.function,
|
|
76
96
|
args: (field.args || []).map(arg => {
|
|
77
97
|
if (isWhere(arg)) {
|
|
78
|
-
return this.unsafeResolveWhere({
|
|
98
|
+
return this.unsafeResolveWhere({
|
|
99
|
+
where: arg,
|
|
100
|
+
alias,
|
|
101
|
+
parentAlias,
|
|
102
|
+
path,
|
|
103
|
+
user,
|
|
104
|
+
parentTableName,
|
|
105
|
+
});
|
|
79
106
|
}
|
|
80
|
-
return this.unsafeResolveValue({
|
|
107
|
+
return this.unsafeResolveValue({
|
|
108
|
+
field: arg,
|
|
109
|
+
alias,
|
|
110
|
+
parentAlias,
|
|
111
|
+
path,
|
|
112
|
+
user,
|
|
113
|
+
parentTableName,
|
|
114
|
+
});
|
|
115
|
+
}),
|
|
116
|
+
alias: this.unsafeResolveStringValue({
|
|
117
|
+
value: field.alias,
|
|
118
|
+
alias,
|
|
119
|
+
parentAlias,
|
|
120
|
+
path,
|
|
81
121
|
}),
|
|
82
|
-
alias: this.unsafeResolveStringValue(field.alias, alias, path),
|
|
83
122
|
cast: field.cast,
|
|
84
|
-
over: resolveOver()
|
|
123
|
+
over: resolveOver(),
|
|
85
124
|
};
|
|
86
125
|
}
|
|
87
126
|
if ('field' in field) {
|
|
88
127
|
return {
|
|
89
|
-
table: this.unsafeResolveStringValue(
|
|
90
|
-
|
|
91
|
-
|
|
128
|
+
table: this.unsafeResolveStringValue({
|
|
129
|
+
value: field.table,
|
|
130
|
+
alias,
|
|
131
|
+
parentAlias,
|
|
132
|
+
path,
|
|
133
|
+
}),
|
|
134
|
+
field: this.unsafeResolveValue({
|
|
135
|
+
field: field.field,
|
|
136
|
+
alias,
|
|
137
|
+
parentAlias,
|
|
138
|
+
path,
|
|
139
|
+
user,
|
|
140
|
+
parentTableName,
|
|
141
|
+
}),
|
|
142
|
+
alias: this.unsafeResolveStringValue({
|
|
143
|
+
value: field.alias,
|
|
144
|
+
alias,
|
|
145
|
+
parentAlias,
|
|
146
|
+
path,
|
|
147
|
+
}),
|
|
92
148
|
cast: field.cast,
|
|
93
|
-
over: resolveOver()
|
|
149
|
+
over: resolveOver(),
|
|
94
150
|
};
|
|
95
151
|
}
|
|
96
152
|
if ('conditions' in field) {
|
|
97
153
|
return {
|
|
98
154
|
conditions: field.conditions.map(c => ({
|
|
99
|
-
when: this.unsafeResolveWhere({
|
|
100
|
-
|
|
155
|
+
when: this.unsafeResolveWhere({
|
|
156
|
+
where: c.when,
|
|
157
|
+
alias,
|
|
158
|
+
parentAlias,
|
|
159
|
+
path,
|
|
160
|
+
user,
|
|
161
|
+
parentTableName,
|
|
162
|
+
}),
|
|
163
|
+
then: this.unsafeResolveValue({
|
|
164
|
+
field: c.then,
|
|
165
|
+
alias,
|
|
166
|
+
parentAlias,
|
|
167
|
+
path,
|
|
168
|
+
user,
|
|
169
|
+
parentTableName,
|
|
170
|
+
}),
|
|
101
171
|
})),
|
|
102
|
-
else: this.unsafeResolveValue({
|
|
172
|
+
else: this.unsafeResolveValue({
|
|
173
|
+
field: field.else,
|
|
174
|
+
alias,
|
|
175
|
+
parentAlias,
|
|
176
|
+
path,
|
|
177
|
+
user,
|
|
178
|
+
parentTableName,
|
|
179
|
+
}),
|
|
103
180
|
alias: field.alias,
|
|
104
181
|
cast: field.cast,
|
|
105
|
-
over: resolveOver()
|
|
182
|
+
over: resolveOver(),
|
|
106
183
|
};
|
|
107
184
|
}
|
|
108
185
|
if ('exists' in field) {
|
|
109
186
|
return {
|
|
110
|
-
exists: this.unsafeResolveSelect(
|
|
187
|
+
exists: this.unsafeResolveSelect({
|
|
188
|
+
select: Object.assign(Object.assign({}, field.exists), { user }),
|
|
189
|
+
alias,
|
|
190
|
+
parentAlias,
|
|
191
|
+
path: `${path}.e`,
|
|
192
|
+
parentTableName,
|
|
193
|
+
}),
|
|
111
194
|
alias: field.alias,
|
|
112
195
|
cast: field.cast,
|
|
113
|
-
over: resolveOver()
|
|
196
|
+
over: resolveOver(),
|
|
114
197
|
};
|
|
115
198
|
}
|
|
116
|
-
return Object.assign(Object.assign({}, this.unsafeResolveSelect(
|
|
199
|
+
return Object.assign(Object.assign({}, this.unsafeResolveSelect({
|
|
200
|
+
select: Object.assign(Object.assign({}, field), { user }),
|
|
201
|
+
alias,
|
|
202
|
+
parentAlias,
|
|
203
|
+
path: `${path}.f`,
|
|
204
|
+
parentTableName,
|
|
205
|
+
})), { alias: field.alias, cast: field.cast, over: resolveOver() });
|
|
117
206
|
}
|
|
118
|
-
unsafeResolveWhere({ where, alias, path, user }) {
|
|
207
|
+
unsafeResolveWhere({ where, alias, parentAlias, path, user, parentTableName, }) {
|
|
119
208
|
if (!where) {
|
|
120
209
|
return null;
|
|
121
210
|
}
|
|
@@ -124,7 +213,9 @@ class UnsafeResolver {
|
|
|
124
213
|
where,
|
|
125
214
|
alias,
|
|
126
215
|
path,
|
|
127
|
-
user
|
|
216
|
+
user,
|
|
217
|
+
parentAlias,
|
|
218
|
+
parentTableName,
|
|
128
219
|
}));
|
|
129
220
|
return { [orOrAnd]: r };
|
|
130
221
|
};
|
|
@@ -136,7 +227,13 @@ class UnsafeResolver {
|
|
|
136
227
|
}
|
|
137
228
|
else if ('exists' in where) {
|
|
138
229
|
return {
|
|
139
|
-
exists: this.unsafeResolveSelect(
|
|
230
|
+
exists: this.unsafeResolveSelect({
|
|
231
|
+
select: Object.assign(Object.assign({}, where.exists), { user }),
|
|
232
|
+
alias,
|
|
233
|
+
parentAlias,
|
|
234
|
+
path,
|
|
235
|
+
parentTableName,
|
|
236
|
+
}),
|
|
140
237
|
};
|
|
141
238
|
}
|
|
142
239
|
else if ('not' in where) {
|
|
@@ -144,28 +241,50 @@ class UnsafeResolver {
|
|
|
144
241
|
not: this.unsafeResolveWhere({
|
|
145
242
|
where: where.not,
|
|
146
243
|
alias,
|
|
244
|
+
parentAlias,
|
|
147
245
|
path,
|
|
148
|
-
user
|
|
149
|
-
|
|
246
|
+
user,
|
|
247
|
+
parentTableName,
|
|
248
|
+
}),
|
|
150
249
|
};
|
|
151
250
|
}
|
|
152
251
|
else {
|
|
153
|
-
return Object.assign(Object.assign({}, where), { v1: this.unsafeResolveValue({
|
|
252
|
+
return Object.assign(Object.assign({}, where), { v1: this.unsafeResolveValue({
|
|
253
|
+
field: where.v1,
|
|
254
|
+
alias,
|
|
255
|
+
parentAlias,
|
|
256
|
+
path,
|
|
257
|
+
user,
|
|
258
|
+
parentTableName,
|
|
259
|
+
}), v2: this.unsafeResolveValue({
|
|
260
|
+
field: where.v2,
|
|
261
|
+
alias,
|
|
262
|
+
parentAlias,
|
|
263
|
+
path,
|
|
264
|
+
user,
|
|
265
|
+
parentTableName,
|
|
266
|
+
}) });
|
|
154
267
|
}
|
|
155
268
|
}
|
|
156
|
-
unsafeResolveSelect(select, alias, path) {
|
|
157
|
-
return Object.assign(Object.assign({}, select), { join: (select.join || [])
|
|
269
|
+
unsafeResolveSelect({ select, alias, parentAlias, path, parentTableName, }) {
|
|
270
|
+
return Object.assign(Object.assign({}, select), { join: (select.join || [])
|
|
271
|
+
.map(join => {
|
|
158
272
|
return Object.assign(Object.assign({}, join), { on: this.unsafeResolveWhere({
|
|
159
273
|
where: join.on,
|
|
160
274
|
alias,
|
|
275
|
+
parentAlias,
|
|
161
276
|
path,
|
|
162
|
-
user: select.user
|
|
277
|
+
user: select.user,
|
|
278
|
+
parentTableName,
|
|
163
279
|
}) });
|
|
164
|
-
})
|
|
280
|
+
})
|
|
281
|
+
.map(j => j), where: this.unsafeResolveWhere({
|
|
165
282
|
where: select.where,
|
|
166
283
|
alias,
|
|
284
|
+
parentAlias,
|
|
167
285
|
path,
|
|
168
|
-
user: select.user
|
|
286
|
+
user: select.user,
|
|
287
|
+
parentTableName,
|
|
169
288
|
}) });
|
|
170
289
|
}
|
|
171
290
|
}
|
|
@@ -178,7 +297,7 @@ class SqlLayerService {
|
|
|
178
297
|
this.unsafeResolver = new UnsafeResolver();
|
|
179
298
|
this.logger = new logger_1.Logger(this.domain, 'SqlServiceLayer');
|
|
180
299
|
}
|
|
181
|
-
addRuleWhere(response, rule) {
|
|
300
|
+
addRuleWhere({ response, rule }) {
|
|
182
301
|
if (rule.where) {
|
|
183
302
|
response.where.and.push(rule.where);
|
|
184
303
|
}
|
|
@@ -193,31 +312,43 @@ class SqlLayerService {
|
|
|
193
312
|
args: Object.assign(Object.assign({}, insert.args), insert.values),
|
|
194
313
|
tables: [],
|
|
195
314
|
where: {
|
|
196
|
-
and: []
|
|
197
|
-
}
|
|
315
|
+
and: [],
|
|
316
|
+
},
|
|
198
317
|
};
|
|
199
318
|
const td = this.getSimpleTableDictionary({
|
|
200
319
|
tableName: insert.tableName,
|
|
201
320
|
statementType: 'insert',
|
|
202
|
-
statement: insert
|
|
321
|
+
statement: insert,
|
|
203
322
|
});
|
|
204
323
|
const mode = 'insert';
|
|
205
324
|
const path = `${this.prefix}.insert`;
|
|
206
|
-
this.addRuleWhere(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
325
|
+
this.addRuleWhere({
|
|
326
|
+
response,
|
|
327
|
+
rule: this.safeResolveWhere({
|
|
328
|
+
where: insert.condition,
|
|
329
|
+
td,
|
|
330
|
+
tableAlias: insert.tableName,
|
|
331
|
+
mode,
|
|
332
|
+
path,
|
|
333
|
+
parentAlias: null,
|
|
334
|
+
parentTableName: null,
|
|
335
|
+
user: insert.user,
|
|
336
|
+
tableName: insert.tableName,
|
|
337
|
+
}),
|
|
338
|
+
});
|
|
339
|
+
this.addRuleWhere({
|
|
340
|
+
response,
|
|
341
|
+
rule: this.tableRules({
|
|
342
|
+
td,
|
|
343
|
+
alias: insert.tableName,
|
|
344
|
+
mode,
|
|
345
|
+
path,
|
|
346
|
+
parentAlias: null,
|
|
347
|
+
parentTableName: null,
|
|
348
|
+
user: insert.user,
|
|
349
|
+
tableName: insert.tableName,
|
|
350
|
+
}),
|
|
351
|
+
});
|
|
221
352
|
const ensureArgs = (insert) => {
|
|
222
353
|
const inserAsStr = JSON.stringify(insert);
|
|
223
354
|
const args = inserAsStr.match(/\$[a-zA-Z0-9_]+/g);
|
|
@@ -236,7 +367,7 @@ class SqlLayerService {
|
|
|
236
367
|
returning: insert.returning,
|
|
237
368
|
args: response.args,
|
|
238
369
|
condition: response.where,
|
|
239
|
-
user: insert.user
|
|
370
|
+
user: insert.user,
|
|
240
371
|
};
|
|
241
372
|
ensureArgs(resultInsert);
|
|
242
373
|
return resultInsert;
|
|
@@ -252,31 +383,43 @@ class SqlLayerService {
|
|
|
252
383
|
args: Object.assign({}, update.args),
|
|
253
384
|
tables: [],
|
|
254
385
|
where: {
|
|
255
|
-
and: []
|
|
256
|
-
}
|
|
386
|
+
and: [],
|
|
387
|
+
},
|
|
257
388
|
};
|
|
258
389
|
const td = this.getSimpleTableDictionary({
|
|
259
390
|
tableName: update.tableName,
|
|
260
391
|
statementType: 'update',
|
|
261
|
-
statement: update
|
|
392
|
+
statement: update,
|
|
262
393
|
});
|
|
263
394
|
const mode = 'update';
|
|
264
395
|
const path = `${this.prefix}.update`;
|
|
265
|
-
this.addRuleWhere(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
396
|
+
this.addRuleWhere({
|
|
397
|
+
response,
|
|
398
|
+
rule: this.safeResolveWhere({
|
|
399
|
+
where: update.where,
|
|
400
|
+
td,
|
|
401
|
+
tableAlias: update.tableName,
|
|
402
|
+
mode,
|
|
403
|
+
path,
|
|
404
|
+
user: update.user,
|
|
405
|
+
parentAlias: null,
|
|
406
|
+
parentTableName: null,
|
|
407
|
+
tableName: update.tableName,
|
|
408
|
+
}),
|
|
409
|
+
});
|
|
410
|
+
this.addRuleWhere({
|
|
411
|
+
response,
|
|
412
|
+
rule: this.tableRules({
|
|
413
|
+
td,
|
|
414
|
+
alias: update.tableName,
|
|
415
|
+
mode,
|
|
416
|
+
path,
|
|
417
|
+
user: update.user,
|
|
418
|
+
parentAlias: null,
|
|
419
|
+
parentTableName: null,
|
|
420
|
+
tableName: update.tableName,
|
|
421
|
+
})
|
|
422
|
+
});
|
|
280
423
|
return {
|
|
281
424
|
puca_pid: update.puca_pid,
|
|
282
425
|
set: update.set,
|
|
@@ -284,7 +427,7 @@ class SqlLayerService {
|
|
|
284
427
|
args: response.args,
|
|
285
428
|
returning: update.returning,
|
|
286
429
|
where: response.where,
|
|
287
|
-
user: update.user
|
|
430
|
+
user: update.user,
|
|
288
431
|
};
|
|
289
432
|
}
|
|
290
433
|
catch (e) {
|
|
@@ -298,31 +441,43 @@ class SqlLayerService {
|
|
|
298
441
|
args: Object.assign({}, d.args),
|
|
299
442
|
tables: [],
|
|
300
443
|
where: {
|
|
301
|
-
and: []
|
|
302
|
-
}
|
|
444
|
+
and: [],
|
|
445
|
+
},
|
|
303
446
|
};
|
|
304
447
|
const td = this.getSimpleTableDictionary({
|
|
305
448
|
tableName: d.tableName,
|
|
306
449
|
statementType: 'delete',
|
|
307
|
-
statement: d
|
|
450
|
+
statement: d,
|
|
308
451
|
});
|
|
309
452
|
const mode = 'delete';
|
|
310
453
|
const path = `${this.prefix}.delete`;
|
|
311
|
-
this.addRuleWhere(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
454
|
+
this.addRuleWhere({
|
|
455
|
+
response,
|
|
456
|
+
rule: this.safeResolveWhere({
|
|
457
|
+
where: d.where,
|
|
458
|
+
td,
|
|
459
|
+
tableAlias: d.tableName,
|
|
460
|
+
mode,
|
|
461
|
+
path,
|
|
462
|
+
user: d.user,
|
|
463
|
+
parentAlias: null,
|
|
464
|
+
parentTableName: null,
|
|
465
|
+
tableName: d.tableName,
|
|
466
|
+
}),
|
|
467
|
+
});
|
|
468
|
+
this.addRuleWhere({
|
|
469
|
+
response,
|
|
470
|
+
rule: this.tableRules({
|
|
471
|
+
td,
|
|
472
|
+
alias: d.tableName,
|
|
473
|
+
mode,
|
|
474
|
+
path,
|
|
475
|
+
user: d.user,
|
|
476
|
+
parentAlias: null,
|
|
477
|
+
parentTableName: null,
|
|
478
|
+
tableName: d.tableName,
|
|
479
|
+
}),
|
|
480
|
+
});
|
|
326
481
|
return {
|
|
327
482
|
puca_pid: d.puca_pid,
|
|
328
483
|
tableName: d.tableName,
|
|
@@ -346,6 +501,8 @@ class SqlLayerService {
|
|
|
346
501
|
select,
|
|
347
502
|
mode: 'select',
|
|
348
503
|
path: `${this.prefix}.select`,
|
|
504
|
+
parentAlias: null,
|
|
505
|
+
parentTableName: null,
|
|
349
506
|
});
|
|
350
507
|
}
|
|
351
508
|
return rules;
|
|
@@ -361,12 +518,12 @@ class SqlLayerService {
|
|
|
361
518
|
throw e;
|
|
362
519
|
}
|
|
363
520
|
}
|
|
364
|
-
safeResolveWhere({ where, td, tableAlias, mode, path, user }) {
|
|
365
|
-
this.checkCircularReference(path);
|
|
521
|
+
safeResolveWhere({ where, td, tableAlias, mode, path, parentAlias, parentTableName, user, tableName, }) {
|
|
522
|
+
this.checkCircularReference({ path });
|
|
366
523
|
const defaultResponse = {
|
|
367
524
|
args: {},
|
|
368
525
|
tables: [],
|
|
369
|
-
where
|
|
526
|
+
where,
|
|
370
527
|
};
|
|
371
528
|
if (!where) {
|
|
372
529
|
return defaultResponse;
|
|
@@ -376,11 +533,13 @@ class SqlLayerService {
|
|
|
376
533
|
select: Object.assign(Object.assign({}, where.exists), { user }),
|
|
377
534
|
mode: 'select',
|
|
378
535
|
path: `${path}.e`,
|
|
536
|
+
parentAlias: tableAlias,
|
|
537
|
+
parentTableName: tableName
|
|
379
538
|
});
|
|
380
539
|
return {
|
|
381
540
|
where: { exists: rules.select },
|
|
382
541
|
tables: rules.tables,
|
|
383
|
-
args: rules.args
|
|
542
|
+
args: rules.args,
|
|
384
543
|
};
|
|
385
544
|
}
|
|
386
545
|
else if ('not' in where) {
|
|
@@ -390,25 +549,32 @@ class SqlLayerService {
|
|
|
390
549
|
tableAlias,
|
|
391
550
|
mode,
|
|
392
551
|
path: `${path}.n`,
|
|
393
|
-
|
|
552
|
+
parentAlias,
|
|
553
|
+
parentTableName,
|
|
554
|
+
user,
|
|
555
|
+
tableName,
|
|
394
556
|
});
|
|
395
557
|
return {
|
|
396
558
|
where: {
|
|
397
559
|
not: rules.where,
|
|
398
560
|
},
|
|
399
561
|
tables: rules.tables,
|
|
400
|
-
args: rules.args
|
|
562
|
+
args: rules.args,
|
|
401
563
|
};
|
|
402
564
|
}
|
|
403
565
|
else if ('or' in where) {
|
|
404
|
-
const or = where.or
|
|
566
|
+
const or = where.or
|
|
567
|
+
.map((w, i) => {
|
|
405
568
|
return this.safeResolveWhere({
|
|
406
569
|
where: w,
|
|
407
570
|
td,
|
|
408
571
|
tableAlias,
|
|
409
572
|
mode,
|
|
410
573
|
path: `${path}.${i}`,
|
|
411
|
-
|
|
574
|
+
parentAlias,
|
|
575
|
+
parentTableName,
|
|
576
|
+
user,
|
|
577
|
+
tableName,
|
|
412
578
|
});
|
|
413
579
|
})
|
|
414
580
|
.filter(w => w.where);
|
|
@@ -418,28 +584,26 @@ class SqlLayerService {
|
|
|
418
584
|
return or.reduce((r, rule) => {
|
|
419
585
|
return {
|
|
420
586
|
where: {
|
|
421
|
-
or: [
|
|
422
|
-
r.where,
|
|
423
|
-
rule.where,
|
|
424
|
-
]
|
|
587
|
+
or: [r.where, rule.where],
|
|
425
588
|
},
|
|
426
|
-
tables: [
|
|
427
|
-
|
|
428
|
-
...rule.tables
|
|
429
|
-
],
|
|
430
|
-
args: Object.assign(Object.assign({}, r.args), rule.args)
|
|
589
|
+
tables: [...r.tables, ...rule.tables],
|
|
590
|
+
args: Object.assign(Object.assign({}, r.args), rule.args),
|
|
431
591
|
};
|
|
432
592
|
});
|
|
433
593
|
}
|
|
434
594
|
else if ('and' in where) {
|
|
435
|
-
const and = where.and
|
|
595
|
+
const and = where.and
|
|
596
|
+
.map((w, i) => {
|
|
436
597
|
return this.safeResolveWhere({
|
|
437
598
|
where: w,
|
|
438
599
|
td,
|
|
439
600
|
tableAlias,
|
|
440
601
|
mode,
|
|
441
602
|
path: `${path}.${i}`,
|
|
442
|
-
|
|
603
|
+
parentAlias,
|
|
604
|
+
parentTableName,
|
|
605
|
+
user,
|
|
606
|
+
tableName,
|
|
443
607
|
});
|
|
444
608
|
})
|
|
445
609
|
.filter(w => w.where);
|
|
@@ -449,16 +613,10 @@ class SqlLayerService {
|
|
|
449
613
|
return and.reduce((r, rule) => {
|
|
450
614
|
return {
|
|
451
615
|
where: {
|
|
452
|
-
and: [
|
|
453
|
-
r.where,
|
|
454
|
-
rule.where
|
|
455
|
-
]
|
|
616
|
+
and: [r.where, rule.where],
|
|
456
617
|
},
|
|
457
|
-
tables: [
|
|
458
|
-
|
|
459
|
-
...rule.tables
|
|
460
|
-
],
|
|
461
|
-
args: Object.assign(Object.assign({}, r.args), rule.args)
|
|
618
|
+
tables: [...r.tables, ...rule.tables],
|
|
619
|
+
args: Object.assign(Object.assign({}, r.args), rule.args),
|
|
462
620
|
};
|
|
463
621
|
});
|
|
464
622
|
}
|
|
@@ -466,12 +624,12 @@ class SqlLayerService {
|
|
|
466
624
|
return defaultResponse;
|
|
467
625
|
}
|
|
468
626
|
}
|
|
469
|
-
checkCircularReference(path) {
|
|
627
|
+
checkCircularReference({ path }) {
|
|
470
628
|
if (path.split('.').length > this.MAX_DEEP) {
|
|
471
629
|
throw new Error('circular reference');
|
|
472
630
|
}
|
|
473
631
|
}
|
|
474
|
-
tableRules({ td, alias: tableAlias, path, user, mode }) {
|
|
632
|
+
tableRules({ td, alias: tableAlias, tableName, path, user, mode, parentAlias, parentTableName, }) {
|
|
475
633
|
if (!td) {
|
|
476
634
|
return { where: null, args: {}, tables: [] };
|
|
477
635
|
}
|
|
@@ -479,7 +637,9 @@ class SqlLayerService {
|
|
|
479
637
|
where: _.get(td.rules, [mode, 'where']),
|
|
480
638
|
alias: tableAlias,
|
|
481
639
|
path,
|
|
482
|
-
|
|
640
|
+
parentAlias,
|
|
641
|
+
user,
|
|
642
|
+
parentTableName,
|
|
483
643
|
});
|
|
484
644
|
if (!where) {
|
|
485
645
|
return { where: null, args: {}, tables: [] };
|
|
@@ -490,36 +650,45 @@ class SqlLayerService {
|
|
|
490
650
|
tableAlias,
|
|
491
651
|
td,
|
|
492
652
|
path: `${path}.tr`,
|
|
493
|
-
|
|
653
|
+
parentAlias,
|
|
654
|
+
parentTableName,
|
|
655
|
+
user,
|
|
656
|
+
tableName,
|
|
657
|
+
});
|
|
658
|
+
const oArgs = _.get(td.rules, [mode, 'args']) || {};
|
|
659
|
+
Object.keys(oArgs).forEach(k => {
|
|
660
|
+
const oValue = oArgs[k];
|
|
661
|
+
if (typeof oValue !== 'string') {
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
const nValue = oValue
|
|
665
|
+
.replace('{{parentTableName}}', parentTableName);
|
|
666
|
+
oArgs[k] = nValue;
|
|
494
667
|
});
|
|
495
|
-
const args = Object.entries(
|
|
496
|
-
.reduce((args, [k, v]) => {
|
|
668
|
+
const args = Object.entries(oArgs).reduce((args, [k, v]) => {
|
|
497
669
|
args[k] = v;
|
|
498
670
|
return args;
|
|
499
671
|
}, rules.args);
|
|
500
672
|
return {
|
|
501
673
|
args,
|
|
502
|
-
tables: [
|
|
503
|
-
|
|
504
|
-
...rules.tables
|
|
505
|
-
],
|
|
506
|
-
where: rules.where
|
|
674
|
+
tables: [td, ...rules.tables],
|
|
675
|
+
where: rules.where,
|
|
507
676
|
};
|
|
508
677
|
}
|
|
509
|
-
safeResolveValue({ field, td, tableAlias, mode, path, user }) {
|
|
510
|
-
this.checkCircularReference(path);
|
|
678
|
+
safeResolveValue({ field, td, tableAlias, mode, path, parentAlias, parentTableName, tableName, user, }) {
|
|
679
|
+
this.checkCircularReference({ path });
|
|
511
680
|
if (!field) {
|
|
512
681
|
return {
|
|
513
682
|
field,
|
|
514
683
|
args: {},
|
|
515
|
-
tables: []
|
|
684
|
+
tables: [],
|
|
516
685
|
};
|
|
517
686
|
}
|
|
518
687
|
if (typeof field === 'string') {
|
|
519
688
|
return {
|
|
520
689
|
field,
|
|
521
690
|
args: {},
|
|
522
|
-
tables: []
|
|
691
|
+
tables: [],
|
|
523
692
|
};
|
|
524
693
|
}
|
|
525
694
|
if (typeof field === 'number' || typeof field === 'boolean') {
|
|
@@ -530,17 +699,37 @@ class SqlLayerService {
|
|
|
530
699
|
return null;
|
|
531
700
|
}
|
|
532
701
|
const partitionBy = (field.over.partitionBy || []).map(p => {
|
|
533
|
-
const result = this.safeResolveValue({
|
|
534
|
-
|
|
535
|
-
|
|
702
|
+
const result = this.safeResolveValue({
|
|
703
|
+
field: p,
|
|
704
|
+
td,
|
|
705
|
+
tableAlias,
|
|
706
|
+
mode,
|
|
707
|
+
path,
|
|
708
|
+
user,
|
|
709
|
+
parentAlias,
|
|
710
|
+
parentTableName,
|
|
711
|
+
tableName,
|
|
712
|
+
});
|
|
713
|
+
tables.push(...result.tables);
|
|
714
|
+
Object.entries(result.args).forEach(([k, v]) => {
|
|
536
715
|
args[k] = v;
|
|
537
716
|
});
|
|
538
717
|
return result.field;
|
|
539
718
|
});
|
|
540
719
|
const orderBy = (field.over.orderBy || []).map(o => {
|
|
541
|
-
const result = this.safeResolveValue({
|
|
542
|
-
|
|
543
|
-
|
|
720
|
+
const result = this.safeResolveValue({
|
|
721
|
+
field: o,
|
|
722
|
+
td,
|
|
723
|
+
tableAlias,
|
|
724
|
+
mode,
|
|
725
|
+
path,
|
|
726
|
+
user,
|
|
727
|
+
parentAlias,
|
|
728
|
+
parentTableName,
|
|
729
|
+
tableName,
|
|
730
|
+
});
|
|
731
|
+
tables.push(...result.tables);
|
|
732
|
+
Object.entries(result.args).forEach(([k, v]) => {
|
|
544
733
|
args[k] = v;
|
|
545
734
|
});
|
|
546
735
|
const field = result.field;
|
|
@@ -551,7 +740,7 @@ class SqlLayerService {
|
|
|
551
740
|
});
|
|
552
741
|
return {
|
|
553
742
|
partitionBy,
|
|
554
|
-
orderBy
|
|
743
|
+
orderBy,
|
|
555
744
|
};
|
|
556
745
|
};
|
|
557
746
|
if ('function' in field) {
|
|
@@ -568,7 +757,10 @@ class SqlLayerService {
|
|
|
568
757
|
tableAlias,
|
|
569
758
|
mode,
|
|
570
759
|
path,
|
|
571
|
-
|
|
760
|
+
parentAlias,
|
|
761
|
+
user,
|
|
762
|
+
parentTableName,
|
|
763
|
+
tableName,
|
|
572
764
|
});
|
|
573
765
|
tables.push(...resolved.tables);
|
|
574
766
|
Object.entries(resolved.args).forEach(([k, v]) => {
|
|
@@ -582,7 +774,10 @@ class SqlLayerService {
|
|
|
582
774
|
tableAlias,
|
|
583
775
|
mode,
|
|
584
776
|
path,
|
|
585
|
-
|
|
777
|
+
parentAlias,
|
|
778
|
+
user,
|
|
779
|
+
parentTableName,
|
|
780
|
+
tableName
|
|
586
781
|
});
|
|
587
782
|
tables.push(...resolved.tables);
|
|
588
783
|
Object.entries(resolved.args).forEach(([k, v]) => {
|
|
@@ -592,10 +787,10 @@ class SqlLayerService {
|
|
|
592
787
|
}),
|
|
593
788
|
cast: field.cast,
|
|
594
789
|
alias: field.alias,
|
|
595
|
-
over: resolveOver(tables, args)
|
|
790
|
+
over: resolveOver(tables, args),
|
|
596
791
|
},
|
|
597
792
|
args,
|
|
598
|
-
tables
|
|
793
|
+
tables,
|
|
599
794
|
};
|
|
600
795
|
}
|
|
601
796
|
if ('field' in field) {
|
|
@@ -606,7 +801,10 @@ class SqlLayerService {
|
|
|
606
801
|
tableAlias,
|
|
607
802
|
mode,
|
|
608
803
|
path,
|
|
609
|
-
|
|
804
|
+
parentAlias,
|
|
805
|
+
user,
|
|
806
|
+
parentTableName,
|
|
807
|
+
tableName,
|
|
610
808
|
});
|
|
611
809
|
const over = resolveOver(resolved.tables, resolved.args);
|
|
612
810
|
return {
|
|
@@ -614,10 +812,10 @@ class SqlLayerService {
|
|
|
614
812
|
alias: field.alias,
|
|
615
813
|
cast: field.cast,
|
|
616
814
|
field: resolved.field,
|
|
617
|
-
over
|
|
815
|
+
over,
|
|
618
816
|
},
|
|
619
817
|
args: resolved.args,
|
|
620
|
-
tables: resolved.tables
|
|
818
|
+
tables: resolved.tables,
|
|
621
819
|
};
|
|
622
820
|
}
|
|
623
821
|
if (field.table && typeof field.table !== 'string') {
|
|
@@ -631,14 +829,31 @@ class SqlLayerService {
|
|
|
631
829
|
const over = resolveOver(tables, args);
|
|
632
830
|
return {
|
|
633
831
|
field: {
|
|
634
|
-
table: this.unsafeResolver.unsafeResolveStringValue(
|
|
635
|
-
|
|
636
|
-
|
|
832
|
+
table: this.unsafeResolver.unsafeResolveStringValue({
|
|
833
|
+
value: field.table,
|
|
834
|
+
alias: tableAlias,
|
|
835
|
+
parentAlias,
|
|
836
|
+
path,
|
|
837
|
+
}),
|
|
838
|
+
field: this.unsafeResolver.unsafeResolveValue({
|
|
839
|
+
field: field.field,
|
|
840
|
+
alias: tableAlias,
|
|
841
|
+
parentAlias,
|
|
842
|
+
path,
|
|
843
|
+
user,
|
|
844
|
+
parentTableName,
|
|
845
|
+
}),
|
|
846
|
+
alias: this.unsafeResolver.unsafeResolveStringValue({
|
|
847
|
+
value: field.alias,
|
|
848
|
+
alias: tableAlias,
|
|
849
|
+
parentAlias,
|
|
850
|
+
path,
|
|
851
|
+
}),
|
|
637
852
|
cast: field.cast,
|
|
638
|
-
over
|
|
853
|
+
over,
|
|
639
854
|
},
|
|
640
855
|
args,
|
|
641
|
-
tables
|
|
856
|
+
tables,
|
|
642
857
|
};
|
|
643
858
|
}
|
|
644
859
|
if ('conditions' in field) {
|
|
@@ -650,7 +865,10 @@ class SqlLayerService {
|
|
|
650
865
|
tableAlias,
|
|
651
866
|
mode,
|
|
652
867
|
path,
|
|
653
|
-
user
|
|
868
|
+
user,
|
|
869
|
+
parentAlias,
|
|
870
|
+
parentTableName,
|
|
871
|
+
tableName,
|
|
654
872
|
});
|
|
655
873
|
tables.push(...e.tables);
|
|
656
874
|
Object.entries(e.args).forEach(([k, v]) => {
|
|
@@ -665,7 +883,10 @@ class SqlLayerService {
|
|
|
665
883
|
tableAlias,
|
|
666
884
|
mode,
|
|
667
885
|
path,
|
|
668
|
-
user
|
|
886
|
+
user,
|
|
887
|
+
parentAlias,
|
|
888
|
+
parentTableName,
|
|
889
|
+
tableName,
|
|
669
890
|
});
|
|
670
891
|
const then = this.safeResolveValue({
|
|
671
892
|
field: c.then,
|
|
@@ -673,7 +894,10 @@ class SqlLayerService {
|
|
|
673
894
|
tableAlias,
|
|
674
895
|
mode,
|
|
675
896
|
path,
|
|
676
|
-
user
|
|
897
|
+
user,
|
|
898
|
+
parentAlias,
|
|
899
|
+
parentTableName,
|
|
900
|
+
tableName,
|
|
677
901
|
});
|
|
678
902
|
tables.push(...when.tables, ...then.tables);
|
|
679
903
|
Object.entries(when.args).forEach(([k, v]) => {
|
|
@@ -684,16 +908,16 @@ class SqlLayerService {
|
|
|
684
908
|
});
|
|
685
909
|
return {
|
|
686
910
|
when: when.where,
|
|
687
|
-
then: then.field
|
|
911
|
+
then: then.field,
|
|
688
912
|
};
|
|
689
913
|
}),
|
|
690
914
|
else: e.field,
|
|
691
915
|
alias: field.alias,
|
|
692
916
|
cast: field.cast,
|
|
693
|
-
over: resolveOver(tables, args)
|
|
917
|
+
over: resolveOver(tables, args),
|
|
694
918
|
},
|
|
695
919
|
args,
|
|
696
|
-
tables
|
|
920
|
+
tables,
|
|
697
921
|
};
|
|
698
922
|
}
|
|
699
923
|
if ('exists' in field) {
|
|
@@ -703,6 +927,8 @@ class SqlLayerService {
|
|
|
703
927
|
select: Object.assign(Object.assign({}, field.exists), { user }),
|
|
704
928
|
mode: 'select',
|
|
705
929
|
path: `${path}.e`,
|
|
930
|
+
parentAlias: tableAlias,
|
|
931
|
+
parentTableName: tableName
|
|
706
932
|
});
|
|
707
933
|
tables.push(...resolved.tables);
|
|
708
934
|
Object.entries(resolved.args).forEach(([k, v]) => {
|
|
@@ -713,101 +939,132 @@ class SqlLayerService {
|
|
|
713
939
|
cast: field.cast,
|
|
714
940
|
exists: resolved.select,
|
|
715
941
|
alias: field.alias,
|
|
716
|
-
over: resolveOver(tables, args)
|
|
942
|
+
over: resolveOver(tables, args),
|
|
717
943
|
},
|
|
718
944
|
args,
|
|
719
|
-
tables
|
|
945
|
+
tables,
|
|
720
946
|
};
|
|
721
947
|
}
|
|
722
948
|
const resolved = this.safeResolveSelect({
|
|
723
949
|
select: Object.assign(Object.assign({}, field), { user }),
|
|
724
950
|
mode: 'select',
|
|
725
951
|
path: `${path}.f`,
|
|
952
|
+
parentAlias: tableAlias,
|
|
953
|
+
parentTableName: tableName
|
|
726
954
|
});
|
|
727
955
|
return {
|
|
728
956
|
field: Object.assign(Object.assign({}, resolved.select), { cast: field.cast, alias: field.alias, over: resolveOver(resolved.tables, resolved.args) }),
|
|
729
957
|
args: resolved.args,
|
|
730
|
-
tables: resolved.tables
|
|
958
|
+
tables: resolved.tables,
|
|
731
959
|
};
|
|
732
960
|
}
|
|
733
|
-
safeResolveSelect({ select, mode, path, }) {
|
|
734
|
-
this.checkCircularReference(path);
|
|
961
|
+
safeResolveSelect({ select, mode, path, parentAlias, parentTableName, }) {
|
|
962
|
+
this.checkCircularReference({ path });
|
|
735
963
|
const tableName = typeof select.from === 'string' ? select.from : select.from.table;
|
|
736
|
-
const tableAlias = (typeof select.from === 'string' ? select.from : select.from.alias) ||
|
|
964
|
+
const tableAlias = (typeof select.from === 'string' ? select.from : select.from.alias) ||
|
|
965
|
+
tableName;
|
|
737
966
|
const td = this.getSimpleTableDictionary({
|
|
738
967
|
tableName,
|
|
739
968
|
statementType: 'select',
|
|
740
|
-
statement: select
|
|
969
|
+
statement: select,
|
|
741
970
|
});
|
|
742
971
|
const response = {
|
|
743
972
|
args: Object.assign({}, select.args),
|
|
744
973
|
tables: [],
|
|
745
974
|
where: {
|
|
746
|
-
and: []
|
|
747
|
-
}
|
|
975
|
+
and: [],
|
|
976
|
+
},
|
|
748
977
|
};
|
|
749
|
-
|
|
978
|
+
const resolvedWhere = this.safeResolveWhere({
|
|
750
979
|
where: select.where,
|
|
751
980
|
td,
|
|
752
981
|
tableAlias,
|
|
753
982
|
mode,
|
|
754
983
|
path,
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
984
|
+
parentAlias,
|
|
985
|
+
user: select.user,
|
|
986
|
+
parentTableName,
|
|
987
|
+
tableName,
|
|
988
|
+
});
|
|
989
|
+
this.addRuleWhere({ response, rule: resolvedWhere });
|
|
990
|
+
const tableRules = this.tableRules({
|
|
758
991
|
td,
|
|
759
992
|
alias: tableAlias,
|
|
760
993
|
mode,
|
|
761
994
|
path,
|
|
762
|
-
|
|
763
|
-
|
|
995
|
+
parentAlias,
|
|
996
|
+
user: select.user,
|
|
997
|
+
parentTableName,
|
|
998
|
+
tableName,
|
|
999
|
+
});
|
|
1000
|
+
this.addRuleWhere({ response, rule: tableRules });
|
|
764
1001
|
const join = (select.join || []).map((join, i) => {
|
|
765
1002
|
const jResponse = {
|
|
766
1003
|
args: {},
|
|
767
1004
|
tables: [],
|
|
768
1005
|
where: {
|
|
769
|
-
and: []
|
|
770
|
-
}
|
|
1006
|
+
and: [],
|
|
1007
|
+
},
|
|
771
1008
|
};
|
|
772
1009
|
const jAlias = join.alias || join.tableName;
|
|
773
1010
|
const td = this.getSimpleTableDictionary({
|
|
774
1011
|
tableName: join.tableName,
|
|
775
1012
|
statementType: 'select',
|
|
776
|
-
statement: select
|
|
1013
|
+
statement: select,
|
|
1014
|
+
});
|
|
1015
|
+
this.addRuleWhere({
|
|
1016
|
+
response: jResponse,
|
|
1017
|
+
rule: this.safeResolveWhere({
|
|
1018
|
+
where: join.on,
|
|
1019
|
+
td,
|
|
1020
|
+
tableAlias: jAlias,
|
|
1021
|
+
mode,
|
|
1022
|
+
path: `${path}.${i}`,
|
|
1023
|
+
user: select.user,
|
|
1024
|
+
parentAlias,
|
|
1025
|
+
parentTableName,
|
|
1026
|
+
tableName,
|
|
1027
|
+
}),
|
|
1028
|
+
});
|
|
1029
|
+
this.addRuleWhere({
|
|
1030
|
+
response: jResponse,
|
|
1031
|
+
rule: this.tableRules({
|
|
1032
|
+
td,
|
|
1033
|
+
alias: jAlias,
|
|
1034
|
+
mode,
|
|
1035
|
+
path: `${path}.${i}`,
|
|
1036
|
+
user: select.user,
|
|
1037
|
+
parentAlias,
|
|
1038
|
+
parentTableName,
|
|
1039
|
+
tableName,
|
|
1040
|
+
}),
|
|
1041
|
+
});
|
|
1042
|
+
this.addRuleWhere({
|
|
1043
|
+
response,
|
|
1044
|
+
rule: { where: null, args: jResponse.args, tables: jResponse.tables },
|
|
777
1045
|
});
|
|
778
|
-
this.addRuleWhere(jResponse, this.safeResolveWhere({
|
|
779
|
-
where: join.on,
|
|
780
|
-
td,
|
|
781
|
-
tableAlias: jAlias,
|
|
782
|
-
mode,
|
|
783
|
-
path: `${path}.${i}`,
|
|
784
|
-
user: select.user
|
|
785
|
-
}));
|
|
786
|
-
this.addRuleWhere(jResponse, this.tableRules({
|
|
787
|
-
td,
|
|
788
|
-
alias: jAlias,
|
|
789
|
-
mode,
|
|
790
|
-
path: `${path}.${i}`,
|
|
791
|
-
user: select.user
|
|
792
|
-
}));
|
|
793
|
-
this.addRuleWhere(response, { where: null, args: jResponse.args, tables: jResponse.tables });
|
|
794
1046
|
return {
|
|
795
1047
|
on: (0, helpers_1.simplifyWhere)(jResponse.where),
|
|
796
1048
|
tableName: join.tableName,
|
|
797
1049
|
alias: jAlias,
|
|
798
|
-
mode: join.mode
|
|
1050
|
+
mode: join.mode,
|
|
799
1051
|
};
|
|
800
1052
|
});
|
|
801
1053
|
const w = (select.with || []).map(w => {
|
|
802
1054
|
const rules = this.safeResolveSelect({
|
|
803
1055
|
mode: 'select',
|
|
804
1056
|
path: `${path}.with`,
|
|
805
|
-
select: Object.assign(Object.assign({}, w.select), { user: select.user })
|
|
1057
|
+
select: Object.assign(Object.assign({}, w.select), { user: select.user }),
|
|
1058
|
+
parentAlias: tableAlias,
|
|
1059
|
+
parentTableName: tableName,
|
|
1060
|
+
});
|
|
1061
|
+
this.addRuleWhere({
|
|
1062
|
+
response,
|
|
1063
|
+
rule: { where: null, args: rules.args, tables: rules.tables },
|
|
806
1064
|
});
|
|
807
|
-
this.addRuleWhere(response, { where: null, args: rules.args, tables: rules.tables });
|
|
808
1065
|
return {
|
|
809
1066
|
select: rules.select,
|
|
810
|
-
alias: w.alias
|
|
1067
|
+
alias: w.alias,
|
|
811
1068
|
};
|
|
812
1069
|
});
|
|
813
1070
|
return {
|
|
@@ -822,11 +1079,17 @@ class SqlLayerService {
|
|
|
822
1079
|
tableAlias,
|
|
823
1080
|
mode,
|
|
824
1081
|
path,
|
|
825
|
-
user: select.user
|
|
1082
|
+
user: select.user,
|
|
1083
|
+
parentAlias,
|
|
1084
|
+
parentTableName,
|
|
1085
|
+
tableName,
|
|
826
1086
|
});
|
|
827
|
-
this.addRuleWhere(
|
|
828
|
-
|
|
829
|
-
|
|
1087
|
+
this.addRuleWhere({
|
|
1088
|
+
response,
|
|
1089
|
+
rule: {
|
|
1090
|
+
args: resolved.args,
|
|
1091
|
+
tables: resolved.tables,
|
|
1092
|
+
},
|
|
830
1093
|
});
|
|
831
1094
|
if (typeof resolved.field === 'string') {
|
|
832
1095
|
return resolved.field;
|
|
@@ -837,18 +1100,28 @@ class SqlLayerService {
|
|
|
837
1100
|
const result = this.safeResolveSelect({
|
|
838
1101
|
mode: 'select',
|
|
839
1102
|
path: `${path}.union`,
|
|
840
|
-
select: u
|
|
1103
|
+
select: u,
|
|
1104
|
+
parentAlias: tableAlias,
|
|
1105
|
+
parentTableName: tableName,
|
|
1106
|
+
});
|
|
1107
|
+
this.addRuleWhere({
|
|
1108
|
+
response,
|
|
1109
|
+
rule: { where: null, args: result.args, tables: result.tables },
|
|
841
1110
|
});
|
|
842
|
-
this.addRuleWhere(response, { where: null, args: result.args, tables: result.tables });
|
|
843
1111
|
return result.select;
|
|
844
1112
|
}),
|
|
845
1113
|
unionAll: (select.unionAll || []).map(u => {
|
|
846
1114
|
const result = this.safeResolveSelect({
|
|
847
1115
|
mode: 'select',
|
|
848
1116
|
path: `${path}.unionAll`,
|
|
849
|
-
select: u
|
|
1117
|
+
select: u,
|
|
1118
|
+
parentAlias: tableAlias,
|
|
1119
|
+
parentTableName: tableName,
|
|
1120
|
+
});
|
|
1121
|
+
this.addRuleWhere({
|
|
1122
|
+
response,
|
|
1123
|
+
rule: { where: null, args: result.args, tables: result.tables },
|
|
850
1124
|
});
|
|
851
|
-
this.addRuleWhere(response, { where: null, args: result.args, tables: result.tables });
|
|
852
1125
|
return result.select;
|
|
853
1126
|
}),
|
|
854
1127
|
orderBy: (select.orderBy || []).map(o => {
|
|
@@ -861,11 +1134,17 @@ class SqlLayerService {
|
|
|
861
1134
|
tableAlias,
|
|
862
1135
|
mode,
|
|
863
1136
|
path,
|
|
864
|
-
|
|
1137
|
+
parentAlias,
|
|
1138
|
+
user: select.user,
|
|
1139
|
+
parentTableName,
|
|
1140
|
+
tableName,
|
|
865
1141
|
});
|
|
866
|
-
this.addRuleWhere(
|
|
867
|
-
|
|
868
|
-
|
|
1142
|
+
this.addRuleWhere({
|
|
1143
|
+
response,
|
|
1144
|
+
rule: {
|
|
1145
|
+
args: resolved.args,
|
|
1146
|
+
tables: resolved.tables,
|
|
1147
|
+
},
|
|
869
1148
|
});
|
|
870
1149
|
if (typeof resolved.field === 'string') {
|
|
871
1150
|
return resolved.field;
|
|
@@ -882,11 +1161,17 @@ class SqlLayerService {
|
|
|
882
1161
|
tableAlias,
|
|
883
1162
|
mode,
|
|
884
1163
|
path,
|
|
885
|
-
|
|
1164
|
+
parentAlias,
|
|
1165
|
+
user: select.user,
|
|
1166
|
+
parentTableName,
|
|
1167
|
+
tableName,
|
|
886
1168
|
});
|
|
887
|
-
this.addRuleWhere(
|
|
888
|
-
|
|
889
|
-
|
|
1169
|
+
this.addRuleWhere({
|
|
1170
|
+
response,
|
|
1171
|
+
rule: {
|
|
1172
|
+
args: resolved.args,
|
|
1173
|
+
tables: resolved.tables,
|
|
1174
|
+
},
|
|
890
1175
|
});
|
|
891
1176
|
if (typeof resolved.field === 'string') {
|
|
892
1177
|
return resolved.field;
|
|
@@ -900,11 +1185,17 @@ class SqlLayerService {
|
|
|
900
1185
|
tableAlias,
|
|
901
1186
|
mode,
|
|
902
1187
|
path,
|
|
903
|
-
|
|
1188
|
+
parentAlias,
|
|
1189
|
+
user: select.user,
|
|
1190
|
+
parentTableName,
|
|
1191
|
+
tableName,
|
|
904
1192
|
});
|
|
905
|
-
this.addRuleWhere(
|
|
906
|
-
|
|
907
|
-
|
|
1193
|
+
this.addRuleWhere({
|
|
1194
|
+
response,
|
|
1195
|
+
rule: {
|
|
1196
|
+
args: resolvedField.args,
|
|
1197
|
+
tables: resolvedField.tables,
|
|
1198
|
+
},
|
|
908
1199
|
});
|
|
909
1200
|
const resolvedValue = this.safeResolveValue({
|
|
910
1201
|
field: q.value,
|
|
@@ -912,11 +1203,17 @@ class SqlLayerService {
|
|
|
912
1203
|
tableAlias,
|
|
913
1204
|
mode,
|
|
914
1205
|
path,
|
|
915
|
-
|
|
1206
|
+
parentAlias,
|
|
1207
|
+
user: select.user,
|
|
1208
|
+
parentTableName,
|
|
1209
|
+
tableName,
|
|
916
1210
|
});
|
|
917
|
-
this.addRuleWhere(
|
|
918
|
-
|
|
919
|
-
|
|
1211
|
+
this.addRuleWhere({
|
|
1212
|
+
response,
|
|
1213
|
+
rule: {
|
|
1214
|
+
args: resolvedValue.args,
|
|
1215
|
+
tables: resolvedValue.tables,
|
|
1216
|
+
},
|
|
920
1217
|
});
|
|
921
1218
|
return {
|
|
922
1219
|
field: resolvedField.field,
|
|
@@ -932,7 +1229,7 @@ class SqlLayerService {
|
|
|
932
1229
|
offset: select.offset,
|
|
933
1230
|
user: select.user,
|
|
934
1231
|
forUpdate: select.forUpdate,
|
|
935
|
-
with: w
|
|
1232
|
+
with: w,
|
|
936
1233
|
},
|
|
937
1234
|
args: response.args,
|
|
938
1235
|
tables: _.uniqBy(response.tables, 'name'),
|