odata-json-schema
Advanced tools
@@ -12,4 +12,10 @@ { | ||
"program": "${workspaceFolder}/__test__/index.js" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Bundle Schemas", | ||
"program": "${workspaceFolder}/bundle.js" | ||
} | ||
] | ||
} |
45
index.js
const fs = require('fs'); | ||
const path = require('path'); | ||
const util = require('util'); | ||
const glob = util.promisify(require('glob')); | ||
const mkdirp = util.promisify(require('mkdirp')); | ||
@@ -16,3 +17,3 @@ const writeFile = util.promisify(fs.writeFile); | ||
} | ||
return !ref.startsWith('Edm'); | ||
return !ref.startsWith('Edm') | ||
}, | ||
@@ -29,4 +30,4 @@ withEnumValue = false, | ||
if (Object.getOwnPropertyNames(schemas[namespace]).length) { | ||
const namespacePath = path.join(dist, parseFullName(namespace)); | ||
await mkdirp(namespacePath); | ||
const namespacePath = path.join(dist, parseFullName(namespace)) | ||
await mkdirp(namespacePath) | ||
for (const name in schemas[namespace]) { | ||
@@ -41,14 +42,14 @@ await writeFile(path.join(namespacePath, `${name}.json`), JSON.stringify(schemas[namespace][name], null, 2)); | ||
function loadRawSchema(name) { | ||
return require(`./dist/${name}`); | ||
return require(`./dist/${name}`) | ||
} | ||
const queue = [startingPoint]; | ||
const visited = new Set(queue); | ||
const navigableSchemas = []; | ||
const queue = [startingPoint] | ||
const visited = new Set(queue) | ||
const navigableSchemas = [] | ||
while (queue.length) { | ||
const first = queue.shift(); | ||
navigableSchemas.push(first); | ||
const first = queue.shift() | ||
navigableSchemas.push(first) | ||
const schema = loadRawSchema(first); | ||
const schema = loadRawSchema(first) | ||
for (let property of schema.$$ODataExtension.NavigationProperty || []) { | ||
@@ -58,6 +59,6 @@ const propertySchema = schema.properties[property]; | ||
propertySchema.items.$ref : | ||
propertySchema.$ref; | ||
propertySchema.$ref | ||
if (typeof refType === 'string' && !visited.has(refType)) { | ||
queue.push(refType); | ||
visited.add(refType); | ||
queue.push(refType) | ||
visited.add(refType) | ||
} | ||
@@ -67,6 +68,20 @@ } | ||
return | ||
return navigableSchemas; | ||
} | ||
async function bundle(root, { | ||
dist = 'schemas.json', | ||
} = {}) { | ||
const files = await glob('**/*.json', { | ||
cwd: root | ||
}) | ||
const bundled = {} | ||
for (const file of files) { | ||
bundled[file.substr(0, file.length - '.json'.length)] = require(`./${root}/${file}`); | ||
} | ||
await writeFile(dist, JSON.stringify(bundled)) | ||
} | ||
module.exports.generateJSONSchema = generateJSONSchema | ||
module.exports.findNavigableSchemas = findNavigableSchemas | ||
module.exports.findNavigableSchemas = findNavigableSchemas | ||
module.exports.bundle = bundle |
{ | ||
"name": "odata-json-schema", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": { |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1043917
60.45%689
0.58%25158
0.11%0
-100%7
40%