-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
933a8df
commit 8c5d513
Showing
6 changed files
with
109 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
const convertElement = require("./convertElement.js"); | ||
const convertCollection = require("./convertCollection.js"); | ||
|
||
module.exports = function convert(data) { | ||
if (Array.isArray(data)) { | ||
var arraySchemas = []; | ||
data.forEach(function (element) { | ||
arraySchemas.push(convertElement(element)); | ||
data.forEach(function (Collection) { | ||
arraySchemas.push(convertCollection(Collection)); | ||
}) | ||
return arraySchemas; | ||
} | ||
if (typeof (data) === "object") { | ||
return convertElement(data); | ||
return convertCollection(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const convertType = require('./convertType.js'); | ||
|
||
module.exports = function convertElement(obj) { | ||
var collection = {}; | ||
if (obj["fields"]) { | ||
obj["fields"].forEach(function (field) { | ||
if (field["name"] == "_id") return; | ||
collection[field["name"]] = { | ||
"type": convertType(field["type"]), | ||
"required": Boolean(field["required"]), | ||
"unique": Boolean(field["unique"]), | ||
"default" : field["defaultValue"], | ||
} | ||
}) | ||
} | ||
return { [obj["name"]]: collection }; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
module.exports = function convertType(type) { | ||
const arrayRegex = /Array<(.+)>/; | ||
const enumRegex = /Enum{(.+)}/; | ||
if (type.match(arrayRegex)) { | ||
return [[convertType(type.match(arrayRegex)[1])[0]], null]; | ||
module.exports = function convertType(type){ | ||
if (type.match(/\[(.+)\]/)){ | ||
return [convertType(type.match(/\[(.+)\]/)[1])]; | ||
} | ||
if (type.match(enumRegex)) { | ||
return ["String", type.match(enumRegex)[1].split(",")]; | ||
switch (type) { | ||
case "String": | ||
return "String"; | ||
case "Integer": | ||
return "Number"; | ||
case "Date": | ||
return "Date"; | ||
case "Boolean": | ||
return "Boolean"; | ||
case "ObjectId": | ||
return "ObjectId"; | ||
case "Array": | ||
return []; | ||
case "[]": | ||
return []; | ||
case "Object": | ||
return "Object"; | ||
case "Double": | ||
return "Double"; | ||
case "Mixed": | ||
return "Mixed"; | ||
default: | ||
return type; | ||
} | ||
if (type === "Integer") { | ||
return ["Number", null]; | ||
} | ||
|
||
if (type === "Array") { | ||
return [[], null]; | ||
} | ||
|
||
return [type, null]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters