oradm-to-gql 35.0.9 → 35.1.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/package.json +5 -5
- package/src/applyModuleSchema.js +1 -4
- package/src/commands/table-map/generateTableMap.js +5 -1
- package/src/commands/table-map/index.js +1 -0
- package/src/data-lib-generator/templates/createEntity.njk +10 -16
- package/src/data-lib-generator/templates/updateEntity.njk +9 -16
- package/src/datamodel-csv-parser/addUserColumn.js +39 -0
- package/src/datamodel-csv-parser/index.js +5 -2
- package/src/knex-tools/createTables.js +2 -9
- package/src/datamodel-csv-parser/defaultBooleans.js +0 -20
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "oradm-to-gql",
|
3
|
-
"version": "35.0
|
3
|
+
"version": "35.1.0",
|
4
4
|
"description": "Oracle Data Modeler CSV Export to Apollo GraphQL Endpoint Generator",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -34,10 +34,10 @@
|
|
34
34
|
"uuid": "^3.3.2"
|
35
35
|
},
|
36
36
|
"peerDependencies": {
|
37
|
-
"graphql": "^
|
37
|
+
"graphql": "^15",
|
38
38
|
"graphql-server-express": "^0.8.5",
|
39
39
|
"graphql-tools": "^1.0.0",
|
40
|
-
"knex": "^0.
|
40
|
+
"knex": "^0.13.0",
|
41
41
|
"tg-knex-query-resolver": "^4.0.0"
|
42
42
|
},
|
43
43
|
"repository": "https://github.com/TeselaGen/oradm-to-gql",
|
@@ -47,12 +47,12 @@
|
|
47
47
|
"clean-deep": "^3.0.5",
|
48
48
|
"express": "^4.15.3",
|
49
49
|
"express-graphql": "^0.6.6",
|
50
|
-
"graphql": "^
|
50
|
+
"graphql": "^15",
|
51
51
|
"graphql-server-express": "^0.8.5",
|
52
52
|
"graphql-tools": "^1.0.0",
|
53
53
|
"jest": "^23.2.0",
|
54
54
|
"knex": "^0.95.11",
|
55
|
-
"pg": "^
|
55
|
+
"pg": "^8.7.1",
|
56
56
|
"require-from-string": "^1.2.1",
|
57
57
|
"tg-client-query-builder": "^2.2.0",
|
58
58
|
"tg-knex-query-resolver": "^4.1.0"
|
package/src/applyModuleSchema.js
CHANGED
@@ -5,10 +5,7 @@ const path = require("path");
|
|
5
5
|
const { applySchema } = require("./knex-tools/");
|
6
6
|
|
7
7
|
async function applyModuleSchema(appConfig, options = {}) {
|
8
|
-
const knexSpecPath = path.join(
|
9
|
-
appConfig.graphql.dataLibPath,
|
10
|
-
"db/knex-spec.json"
|
11
|
-
);
|
8
|
+
const knexSpecPath = path.join(appConfig.graphql.dataLibPath, "db/knex-spec.json");
|
12
9
|
const knexSpec = fse.readJSONSync(knexSpecPath);
|
13
10
|
const db = knex(appConfig.db.app);
|
14
11
|
|
@@ -3,12 +3,16 @@ const path = require("path");
|
|
3
3
|
const fse = require("fs-extra");
|
4
4
|
|
5
5
|
module.exports = function generateTableMap(csvPath, outputDir, opts = {}) {
|
6
|
-
const { extend, timestamps, verbose, maxNameLength } = opts;
|
6
|
+
const { extend, timestamps, verbose, maxNameLength, user } = opts;
|
7
7
|
|
8
8
|
let log = () => {};
|
9
9
|
if (verbose) log = console.log;
|
10
10
|
|
11
11
|
let parseOpts = { log, maxNameLength };
|
12
|
+
|
13
|
+
if (user) {
|
14
|
+
parseOpts.user = { modified: "updatedBy" };
|
15
|
+
}
|
12
16
|
|
13
17
|
if (timestamps) {
|
14
18
|
parseOpts.timestamps = { created: "createdAt", modified: "updatedAt" };
|
@@ -5,6 +5,7 @@ module.exports = {
|
|
5
5
|
options: {
|
6
6
|
"-v, --verbose": "Display verbose output",
|
7
7
|
"-t, --timestamps": "Add timestamp attributes to all models",
|
8
|
+
"-u, --user": "Add updated by attribute to all models",
|
8
9
|
"-x, --extend <extendTableMap>": "Uses the specified module to extend the table map"
|
9
10
|
},
|
10
11
|
action: generateTableMap
|
@@ -32,27 +32,17 @@ async function create{{makePlural(entityName)}}(createRecords, trx, opts){
|
|
32
32
|
let allowQuery = await Promise.resolve(this.entities.{{table.modelName}}.extensions.onCreate.allow.call(this, opts));
|
33
33
|
|
34
34
|
if(!allowQuery) return Promise.resolve([]);
|
35
|
-
|
36
|
-
{% set doneLoop = 'false' %}
|
37
|
-
{% for propName, attrDef in table.attributes %}
|
38
|
-
{% if attrDef.dataType === 'Boolean' and doneLoop !== 'true' %}
|
39
|
-
createRecords.forEach(rec => {
|
40
|
-
{% for propName, attrDef in table.attributes %}
|
41
|
-
{% if attrDef.dataType === 'Boolean' %}
|
42
|
-
if (rec.{{attrDef.name}} === null) {
|
43
|
-
delete rec.{{attrDef.name}}
|
44
|
-
}
|
45
|
-
{% endif %}
|
46
|
-
{% endfor %}
|
47
|
-
})
|
48
|
-
{% set doneLoop = 'true' %}
|
49
|
-
{% endif %}
|
50
|
-
{% endfor %}
|
51
35
|
|
52
36
|
let records = await Promise.resolve(this.entities.{{table.modelName}}.extensions.onCreate.records.call(this, createRecords, opts));
|
53
37
|
|
54
38
|
|
55
39
|
let createdTimestamp = new Date();
|
40
|
+
let modifiedUser = undefined;
|
41
|
+
|
42
|
+
if(this.context.req.user){
|
43
|
+
modifiedUser = await dataAccessLib.entities.user.get(this.context.req.user.id, "username")
|
44
|
+
}
|
45
|
+
|
56
46
|
records.forEach((rec) => {
|
57
47
|
{% for propName, attrDef in table.attributes %}
|
58
48
|
{% if attrDef.isPrimaryKey %}
|
@@ -68,6 +58,10 @@ async function create{{makePlural(entityName)}}(createRecords, trx, opts){
|
|
68
58
|
//set timestamps
|
69
59
|
rec.{{attrDef.name}} = createdTimestamp;
|
70
60
|
{% endif %}
|
61
|
+
{% if attrDef.user == 'modified' %}
|
62
|
+
//set modified user
|
63
|
+
rec.{{attrDef.name}} = modifiedUser;
|
64
|
+
{% endif %}
|
71
65
|
{% endfor %}
|
72
66
|
});
|
73
67
|
|
@@ -22,22 +22,6 @@ async function update{{makePlural(entityName)}}(updateRecords, fkFilter, trx, op
|
|
22
22
|
|
23
23
|
if(!allowQuery) return Promise.resolve([]);
|
24
24
|
|
25
|
-
{% set doneLoop = 'false' %}
|
26
|
-
{% for propName, attrDef in table.attributes %}
|
27
|
-
{% if attrDef.dataType === 'Boolean' and doneLoop !== 'true' %}
|
28
|
-
updateRecords.forEach(rec => {
|
29
|
-
{% for propName, attrDef in table.attributes %}
|
30
|
-
{% if attrDef.dataType === 'Boolean' %}
|
31
|
-
if (rec.{{attrDef.name}} === null) {
|
32
|
-
delete rec.{{attrDef.name}}
|
33
|
-
}
|
34
|
-
{% endif %}
|
35
|
-
{% endfor %}
|
36
|
-
})
|
37
|
-
{% set doneLoop = 'true' %}
|
38
|
-
{% endif %}
|
39
|
-
{% endfor %}
|
40
|
-
|
41
25
|
let records = await Promise.resolve(this.entities.{{table.modelName}}.extensions.onUpdate.records.call(this, updateRecords, opts));
|
42
26
|
|
43
27
|
let qry = this.db;
|
@@ -55,6 +39,12 @@ async function update{{makePlural(entityName)}}(updateRecords, fkFilter, trx, op
|
|
55
39
|
|
56
40
|
let ids = [];
|
57
41
|
let modifiedTimestamp = new Date();
|
42
|
+
let modifiedUser = undefined;
|
43
|
+
|
44
|
+
if(this.context.req.user){
|
45
|
+
modifiedUser = await dataAccessLib.entities.user.get(this.context.req.user.id, "username")
|
46
|
+
}
|
47
|
+
|
58
48
|
return Promise.each(records, async (updateRecord) =>
|
59
49
|
{
|
60
50
|
let recordId = updateRecord.{{table.primaryKeyField}};
|
@@ -118,6 +108,9 @@ async function update{{makePlural(entityName)}}(updateRecords, fkFilter, trx, op
|
|
118
108
|
{% if attrDef.timestamp == 'modified' %}
|
119
109
|
values.{{attrDef.columnName}} = modifiedTimestamp;
|
120
110
|
{% endif %}
|
111
|
+
{% if attrDef.user == 'modified' %}
|
112
|
+
values.{{attrDef.columnName}} = modifiedUser;
|
113
|
+
{% endif %}
|
121
114
|
{% endfor %}
|
122
115
|
|
123
116
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
const { each } = require("lodash");
|
2
|
+
|
3
|
+
module.exports = function addUserColumn(tableMap, user, opts) {
|
4
|
+
opts = opts || {};
|
5
|
+
each(tableMap, (table, tableName) => {
|
6
|
+
if (table.type !== "view") {
|
7
|
+
if (user.modified) {
|
8
|
+
var modifiedColName = user.modified;
|
9
|
+
if (typeof table.attributes[modifiedColName] === "undefined") {
|
10
|
+
table.attributes[modifiedColName] = {
|
11
|
+
name: modifiedColName,
|
12
|
+
dataType: "ORDDOC",
|
13
|
+
isPrimaryKey: false,
|
14
|
+
isForeignKey: false,
|
15
|
+
size: "",
|
16
|
+
precision: "",
|
17
|
+
scale: "",
|
18
|
+
nullable: true,
|
19
|
+
unique: false,
|
20
|
+
columnName: modifiedColName,
|
21
|
+
user: "modified",
|
22
|
+
};
|
23
|
+
} else {
|
24
|
+
if (user.errorOnConflict) {
|
25
|
+
throw new Error(
|
26
|
+
`[DM GEN ERROR] user ${modifiedColName} field already exists on ${tableName}. Unset user.errorOnConflict to warn instead of throwing.`
|
27
|
+
);
|
28
|
+
} else {
|
29
|
+
console.warn(
|
30
|
+
`[DM GEN WARNING] user ${modifiedColName} field already exists on ${tableName}. Set user.errorOnConflict throw an error instead of warning`
|
31
|
+
);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
return tableMap;
|
39
|
+
};
|
@@ -4,10 +4,10 @@ const applyNamingRules = require("./applyNamingRules");
|
|
4
4
|
const populateRelationshipAttributes = require("./populateRelationshipAttributes");
|
5
5
|
const extendTableMap = require("./extendTableMap");
|
6
6
|
const addTimestampColumns = require("./addTimestampColumns");
|
7
|
+
const addUserColumn = require("./addUserColumn")
|
7
8
|
const { addIndexes } = require("./addIndexes");
|
8
9
|
const { processViews } = require("./views");
|
9
10
|
const { mergeCommonTableMap } = require("./mergeCommonTableMap");
|
10
|
-
// const { defaultBooleans } = require("./defaultBooleans");
|
11
11
|
|
12
12
|
module.exports = function parseDatamodelCSV(
|
13
13
|
csvPath,
|
@@ -45,9 +45,12 @@ module.exports = function parseDatamodelCSV(
|
|
45
45
|
if (opts.timestamps) {
|
46
46
|
tableMap = addTimestampColumns(tableMap, opts.timestamps, opts);
|
47
47
|
}
|
48
|
+
// if (opts.user) {
|
49
|
+
// tableMap = addUserColumn(tableMap, opts.user, opts);
|
50
|
+
// }
|
51
|
+
tableMap = addUserColumn(tableMap, { modified: "updatedBy" }, opts);
|
48
52
|
|
49
53
|
tableMap = addIndexes(tableMap, opts);
|
50
|
-
// tableMap = defaultBooleans(tableMap, opts);
|
51
54
|
tableMap = applyNamingRules(tableMap, opts);
|
52
55
|
tableMap = processViews(tableMap, opts);
|
53
56
|
tableMap = populateRelationshipAttributes(tableMap, opts);
|
@@ -45,17 +45,10 @@ function createTables(db, tableSpecs, opts = {}) {
|
|
45
45
|
if (colSpec.unique) {
|
46
46
|
table.unique(colSpec.name);
|
47
47
|
}
|
48
|
-
if (colSpec.
|
49
|
-
colSpec.defaultValue = colSpec.defaultValue || false;
|
50
|
-
}
|
51
|
-
if (colSpec.defaultValue || colSpec.defaultValue === false) {
|
48
|
+
if (colSpec.defaultValue) {
|
52
49
|
let defaultValue = colSpec.defaultValue;
|
53
50
|
if (colSpec.type === "boolean") {
|
54
|
-
if (
|
55
|
-
defaultValue === "false" ||
|
56
|
-
defaultValue === "0" ||
|
57
|
-
defaultValue === false
|
58
|
-
) {
|
51
|
+
if (defaultValue === "false" || defaultValue === "0") {
|
59
52
|
defaultValue = false;
|
60
53
|
} else {
|
61
54
|
defaultValue = true;
|
@@ -1,20 +0,0 @@
|
|
1
|
-
const { each } = require("lodash");
|
2
|
-
|
3
|
-
function defaultBooleans(tableMap) {
|
4
|
-
each(tableMap, (tableDef) => {
|
5
|
-
if (tableDef.type !== "view") {
|
6
|
-
each(tableDef.attributes, (attrDef, attrName) => {
|
7
|
-
if (attrDef.dataType === "Boolean") {
|
8
|
-
attrDef.nullable = false;
|
9
|
-
if (!attrDef.defaultValue) {
|
10
|
-
attrDef.defaultValue = false;
|
11
|
-
}
|
12
|
-
}
|
13
|
-
});
|
14
|
-
}
|
15
|
-
});
|
16
|
-
|
17
|
-
return tableMap;
|
18
|
-
}
|
19
|
-
|
20
|
-
module.exports = { defaultBooleans };
|