Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add date time descriptors for date formats #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions reverse_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module.exports = {
const { includeSystemCollection } = connectionInfo;

client.info().then(info => {
const majorVersion = getMajorVersion(info);
const majorVersion = +info.version.number.split('.').shift();

return getIndexes(client, includeSystemCollection)
.then(indexes => {
Expand Down Expand Up @@ -169,8 +169,6 @@ module.exports = {
logger.log('info', getSamplingInfo(recordSamplingSettings, fieldInference), 'Reverse-Engineering sampling params', data.hiddenKeys);
logger.log('info', { Indices: indices }, 'Selected collection list', data.hiddenKeys);

let majorVersion;

async.waterfall([
(getDbInfo) => {
this.connect(data, logger, getDbInfo);
Expand All @@ -184,7 +182,6 @@ module.exports = {
port: +socket.port,
version: getVersion(info.version.number, versions)
};
majorVersion = getMajorVersion(info);

logger.log('info', { modelInfo }, 'Model info');

Expand All @@ -193,7 +190,7 @@ module.exports = {
},

(client, modelInfo, getData) => {
const indexTypes = getTypesByVersion(majorVersion, types, indices);
const indexTypes = getTypesByVersion(modelInfo.version, types, indices);

getSchemaMapping(indexTypes, client).then((jsonSchemas) => {
getData(null, client, modelInfo, jsonSchemas);
Expand All @@ -208,7 +205,7 @@ module.exports = {
},

(client, modelInfo, jsonSchemas, next) => {
const indexTypes = getTypesByVersion(majorVersion, types, indices);
const indexTypes = getTypesByVersion(modelInfo.version, types, indices);

async.map(indices, (indexName, nextIndex) => {
let bucketInfo = Object.assign(getBucketData(jsonSchemas[indexName] || {}), defaultBucketInfo);
Expand All @@ -225,6 +222,7 @@ module.exports = {
nextIndex(null, [{}]);
}
} else {
const majorVersion = +modelInfo.version.split('.').shift();
const schemaData = {
indexName, recordSamplingSettings, containerLevelKeys, bucketInfo, jsonSchemas, fieldInference, client
};
Expand Down Expand Up @@ -273,10 +271,6 @@ module.exports = {
}
};

const getMajorVersion = (info) => {
return +(((info || {}).version || {}).number || '5').split('.').shift();
};

const shouldPackageBeAdded = (docPackage, includeEmptyCollection) => {
if (includeEmptyCollection) {
return true;
Expand Down Expand Up @@ -386,7 +380,9 @@ const getIndexTypeData = (typeName, {
});
});

const getTypesByVersion = (majorVersion, types, indexes) => {
const getTypesByVersion = (version, types, indexes) => {
const majorVersion = +version.split('.').shift();

if (majorVersion < 7) {
return types;
}
Expand Down
45 changes: 43 additions & 2 deletions types/date.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,46 @@
"default": "",
"format": "",
"sample": ""
}
}
},
"descriptor": [{
"schema": {
"format": "date"
},
"format": "YYYY-MM-DD"
}, {
"schema": {
"format": "time_no_millis"
},
"format": "hh:mm:ss"
}, {
"schema": {
"format": "time"
},
"format": "hh:mm:ss.nnn"
}, {
"schema": {
"format": "HH:mm:ss.SSSSSS"
},
"format": "hh:mm:ss.nnnnnn"
}, {
"schema": {
"format": "date_hour_minute_second"
},
"format": "YYYY-MM-DD hh:mm:ss"
}, {
"schema": {
"format": "date_hour_minute_second_millis"
},
"format": "YYYY-MM-DD hh:mm:ss.nnn"
}, {
"schema": {
"format": "date_time"
},
"format": "YYYY-MM-DD hh:mm:ss.nnnZ"
}, {
"schema": {
"format": "strict_date_optional_time_nanos"
},
"format": "YYYY-MM-DD hh:mm:ss.nnnnnnZ"
}]
}