forked from jsa2/CloudShellAadApps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschemaForExternalData.js
56 lines (42 loc) · 1.52 KB
/
schemaForExternalData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var pathLoc = 'material'
var fs = require('fs')
var path = require('path')
var {createStorage} = require('./SchemaStorage')
//var chalk = require('chalk')
main()
async function main ( ) {
var files = fs.readdirSync(path.resolve(pathLoc))
var tid = fs.readFileSync('kql/tid.txt').toString()
var fullSchema = `let home="${tid}"; \n //`
for await (file of files) {
var content = require(`./${pathLoc}/${file}`).filter(app => app.appDisplayName !== null)
//console.log( chalk.yellow('\nschema for', file, '\n' ))
var schema = `\nlet ${file.split('.json')[0]} = (externaldata (`
try {delete content[0]['@odata.id']} catch (error) {
console.log('different schema')
}
var k = Object.keys(content[0])
k.forEach((key, index) => {
if (key.match('appDisplayName')) {
console.log()
}
var type = typeof(content[0][key])
/* console.log(content[0][key]) */
if (type == "object") {
schema += `${key}: dynamic`
} else {
schema += `${key}: string`
}
if (index !== (k.length - 1)) {
schema += ", "
}
})
var url = await createStorage(pathLoc,file,`./${pathLoc}/${file}`)
schema += `)[@"${url}"] with (format="multijson"));`
schema += '\n //'
fullSchema+=schema
}
let callIt = fs.readFileSync('kql/call.kql').toString()
var baseq = fs.readFileSync('kql/query.kql').toString()
fs.writeFileSync('kql/runtime.kql',fullSchema+baseq+callIt)
}