Socket
Socket
Sign inDemoInstall

@medable/mdctl-import-adapter

Package Overview
Dependencies
173
Maintainers
3
Versions
86
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

156

index.js
const { Transform } = require('stream'),
EventEmitter = require('events'),
globby = require('globby'),
mime = require('mime-types'),

@@ -9,6 +10,12 @@ uuid = require('uuid'),

{ ImportSection } = require('@medable/mdctl-core/streams/section'),
{ stringifyContent, parseString } = require('@medable/mdctl-core-utils/values'),
{ parseString } = require('@medable/mdctl-core-utils/values'),
{ md5FileHash } = require('@medable/mdctl-core-utils/crypto'),
{ privatesAccessor } = require('@medable/mdctl-core-utils/privates'),
{ OutputStream } = require('./chunk-stream')
{ Fault } = require('@medable/mdctl-core'),
{ OutputStream } = require('@medable/mdctl-core/streams/chunk-stream'),
KNOWN_FILES = {
data: 'data/**/*.{json,yaml}',
objects: 'env/**/*.{json,yaml}',
manifest: 'manifest.{json,yaml}'
}

@@ -32,5 +39,9 @@ class ImportFileTransformStream extends Transform {

_transform(chunk, enc, callback) {
const { metadata, basePath, file } = privatesAccessor(this),
content = parseString(chunk, metadata.format)
this.push(new ImportSection(content, content.object, file, basePath))
const { metadata, basePath, file } = privatesAccessor(this)
try {
const content = parseString(chunk, metadata.format)
this.push(new ImportSection(content, content.object, file, basePath))
} catch (e) {
console.log(e, chunk.toString())
}
callback()

@@ -51,5 +62,4 @@ }

metadata: {},
blobs: [],
index: 0,
blobIndex: 0
preparedChunks: []
})

@@ -69,11 +79,8 @@

getAssetStream(ef) {
const { metadata } = privatesAccessor(this),
outS = new OutputStream({
ndjson: false,
template: ef
})
outS.write(stringifyContent(ef, metadata.format))
outS.end()
return outS
static getAssetStream(ef) {
const outS = new OutputStream({
ndjson: false,
template: ef
})
return ef.data.pipe(outS)
}

@@ -92,61 +99,69 @@

async loadFileContent(f) {
const section = await this.loadFile(f)
await this.loadFacets(section)
await this.loadScripts(section)
await this.loadTemplates(section)
let results = [],
blobResults = []
results.push(section.content)
get blobs() {
return privatesAccessor(this).blobs
if (section && section.facets && section.facets.length) {
results = _.concat(
results,
section.facets
)
if (section.extraFiles && section.extraFiles.length) {
// const blobs = this.getBlobData(section.extraFiles)
blobResults = _.concat(blobResults, _.map(section.extraFiles, (ef) => {
return ImportFileTreeAdapter.getAssetStream(ef)
}))
}
}
return { results, blobResults }
}
async prepareChunks() {
const { files, preparedChunks } = privatesAccessor(this),
promises = []
if (preparedChunks.length) {
return Promise.resolve(preparedChunks)
}
files.forEach((f) => {
promises.push(this.loadFileContent(f))
})
return Promise.all(promises).then((res) => {
const results = _.flatten(_.map(res, 'results')),
blobs = _.flatten(_.flatten(_.map(res, 'blobResults'))),
data = _.concat(results, blobs)
privatesAccessor(this, 'preparedChunks', data)
return data
})
}
async getChunks() {
const { files, index } = privatesAccessor(this),
result = {
done: false,
value: []
}
let { blobs } = privatesAccessor(this)
if (files.length > index) {
// Increment index processing
const { index } = privatesAccessor(this),
chunks = await this.prepareChunks()
if (chunks.length > index) {
privatesAccessor(this, 'index', index + 1)
const f = files[index],
section = await this.loadFile(f)
await this.loadFacets(section)
await this.loadScripts(section)
await this.loadTemplates(section)
result.value.push(section.content)
if (section && section.facets && section.facets.length) {
result.value = _.concat(
result.value,
section.facets
)
if (section.extraFiles && section.extraFiles.length) {
blobs = _.concat(blobs, section.extraFiles)
}
privatesAccessor(this, 'blobs', blobs)
}
return result
return Promise.resolve({
done: false,
value: chunks[index]
})
}
return {
value: null,
done: true
}
return Promise.resolve({
done: true,
value: null
})
}
walkFiles(dir) {
const files = fs.readdirSync(dir)
files.forEach((f) => {
if (f.indexOf('.') !== 0) {
const pathFile = `${dir}/${f}`
if (fs.statSync(pathFile).isDirectory()) {
this.walkFiles(pathFile)
} else {
const type = mime.lookup(pathFile)
if (type === 'application/json' || ['text/yaml', 'application/yaml'].indexOf(type) > -1) {
privatesAccessor(this, 'files').push(pathFile)
}
}
}
})
const { format } = privatesAccessor(this),
files = globby.sync([KNOWN_FILES.manifest, KNOWN_FILES.objects], { cwd: dir }),
mappedFiles = _.map(files, f => `${dir}/${f}`),
existsManifest = _.find(files, f => f.indexOf(`manifest.${format}`))
if (!existsManifest) {
throw Fault.create({ code: 'KMissingManifest', reason: 'There is no manifest file present on folder' })
}
privatesAccessor(this, 'files', mappedFiles)
}

@@ -209,3 +224,3 @@

streamId: resourceKey,
data: fs.readFileSync(localFile),
data: fs.createReadStream(localFile),
object: 'stream'

@@ -233,6 +248,5 @@ }

if (!_.isObject(n.value)) {
const parent = this.getParentFromPath(chunk, n.path)
if (parent.script.indexOf('/env') === 0) {
const jsFile = `${basePath}${parent.script}`
parent.script = fs.readFileSync(jsFile).toString()
if (n.value.indexOf('/env') === 0) {
const jsFile = `${basePath}${n.value}`
jp.value(content, jp.stringify(n.path), fs.readFileSync(jsFile).toString())
}

@@ -239,0 +253,0 @@ }

{
"name": "@medable/mdctl-import-adapter",
"version": "1.0.0",
"version": "1.0.1",
"description": "Medable Developer Client Tools :: Import Adapter",

@@ -28,5 +28,6 @@ "repository": {

"dependencies": {
"@medable/mdctl-core": "^1.0.0",
"@medable/mdctl-core-utils": "^1.0.0",
"@medable/mdctl-core": "^1.0.1",
"@medable/mdctl-core-utils": "^1.0.1",
"clone": "^2.1.2",
"globby": "^9.1.0",
"jsonpath": "^1.0.0",

@@ -51,3 +52,3 @@ "lodash": "^4.17.11",

},
"gitHead": "5357404ee705e2db77860f94a43352db8c871205"
"gitHead": "3cc9bffc20b1026350a2fd2399f126c53a20cd35"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc