Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mediaxml

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mediaxml - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

query/transform/if.js

2

package.json
{
"name": "mediaxml",
"version": "0.3.1",
"version": "0.4.0",
"description": "A general purpose module for working with XML that includes first class support for media manifests like ADI, mRSS, and SCTE-236.",

@@ -5,0 +5,0 @@ "scripts": {

const { normalizeValue } = require('../normalize')
const InvertedPromise = require('inverted-promise')
const { randomBytes } = require('crypto')
const { resolve } = require('../resolve')
const extendMap = require('map-extend')
const bindings = require('./bindings')
const defined = require('defined')
const jsonata = require('jsonata')

@@ -11,2 +11,3 @@ const mutex = require('mutexify')

const path = require('path')
const uri = require('../uri')

@@ -256,2 +257,10 @@ const QUERY_FILE_EXTNAME = '.mxq' // MediaXML Query

evaluate(value) {
// try to evaluate JSONata expression in value statement
value = defined(Expression.from(this, value).evaluate(true), value)
// normalize value before setting
return normalizeValue(value)
}
getValue(key) {

@@ -403,6 +412,6 @@ const assignments = convertMapToObject(this.assignments)

const extname = path.extname(name)
let resolved = resolve(name, { cwd })
let resolved = uri.resolve(name, { cwd })
if (!resolved && !extname) {
resolved = resolve(name + QUERY_FILE_EXTNAME, { cwd })
resolved = uri.resolve(name + QUERY_FILE_EXTNAME, { cwd })
}

@@ -694,2 +703,3 @@

this.push(0, require('./transform/let'))
this.push(0, require('./transform/if'))
this.push(0, require('./transform/import'))

@@ -873,2 +883,6 @@ this.push(0, require('./transform/print'))

values() {
return this.entries.values()
}
/**

@@ -956,5 +970,8 @@ * Queries for binding by name. If binding is a function, a bound

const { imports } = expression
const preprocessed = expression.preprocess()
// compute imports and outputs
expression = Expression.from(context, expression.preprocess(), opts)
if (preprocessed !== queryString) {
// compute imports and outputs
expression = Expression.from(context, preprocessed, opts)
}

@@ -981,3 +998,2 @@ if (imports.waiting || context.output.length) {

const queue = []
let outputs = context.output.splice(0, context.output.length)
let result = null

@@ -989,10 +1005,2 @@

for (const output of outputs) {
try {
await Expression.from(context, `$print(${output})`, opts).evaluate()
} catch (err) {
return reject(err)
}
}
// eslint-disable-next-line

@@ -1043,9 +1051,20 @@ function wait(imports, done) {

const outputs = context.output.splice(0, context.output.length)
for (const output of outputs) {
try {
await Expression.from(context, `$print(${output})`, opts).evaluate()
} catch (err) {
return reject(err)
}
}
if (Array.isArray(result)) {
return resolve(Node.createFragment(null, {
resolve(Node.createFragment(null, {
children: result
}))
} else {
resolve(result || null)
}
return resolve(result || null)
})

@@ -1052,0 +1071,0 @@ } catch (err) {

@@ -0,4 +1,3 @@

const REGEX = /([^|^$|\b]print\s*(.*)(;|\n|\r|$))/g
const REGEX = /([$]?print\s*(.*)(;|\n|\r|$))/g
function transform(queryString, ctx) {

@@ -13,12 +12,4 @@ const result = queryString.replace(REGEX, replace)

function compile(ctx, { statement, input }) {
statement = (statement || '').trim()
// bail on `$print()` calls
if ('$' === statement[0]) {
return statement
}
function compile(ctx, { input }) {
ctx.output.push(input)
return ''

@@ -25,0 +16,0 @@ }

@@ -0,1 +1,2 @@

const { Bindings } = require('../query/index')
const debug = require('debug')('mediaxml')

@@ -14,2 +15,5 @@ const glob = require('glob')

completions.push(...[ ...context.assignments.keys() ].map((key) => `$${key}`))
for (const key in Bindings.builtins) {
completions.push(`$${key}(`)
}

@@ -19,3 +23,3 @@ if (query) {

if (pathToLoad) {
let [, quote, pathspec ] = pathToLoad
let [, , pathspec ] = pathToLoad

@@ -41,32 +45,4 @@ if (pathspec) {

if (query && !/^\$\.$/.test(query)) {
if (/^\$[a-z|A-Z|0-9|_]+$/g.test(end)) {
completions.push(
'$camelcase(',
'$concat(',
'$unique(',
'$float(',
'$int(',
'$now(',
'$import(',
'$slice(',
'$toJSON',
)
} else if (/\.\$?([a-z|A-Z|0-9|_]+)?$/g.test(end)) {
const i = query.lastIndexOf('.')
const prefix = query.slice(0, i)
completions.push(
`${prefix}.$camelcase(`,
`${prefix}.$concat(`,
`${prefix}.$unique(`,
`${prefix}.$float(`,
`${prefix}.$int(`,
`${prefix}.$now(`,
`${prefix}.$slice(`,
`${prefix}.$string(`,
)
}
}
if (/children:?[a-z|A-Z|-]*$/.test(query)) {
const colon = /children\:([a-z|A-Z|-]+)?$/.test(query)
const colon = /children:([a-z|A-Z|-]+)?$/.test(query)

@@ -102,3 +78,3 @@ if (!colon) {

if (!query || ':' === query || /\:?r?o?o?t?/.test(query)) {
if (!query || ':' === query || /:?r?o?o?t?/.test(query)) {
if (!/\.$/.test(end)) {

@@ -128,22 +104,65 @@ completions.unshift(':root')

}
completions.push(
'name',
'text',
'children',
'attributes',
'length'
)
if (/\.$/.test(end)) {
completions.push(
'name',
'text',
'children',
'attributes',
'length'
)
} else {
completions.push(
':is',
':is(array)',
':is(date)',
':is(fragment)',
':is(node)',
':is(number)',
':is(object)',
':is(text)',
':is(string)',
if (/\s$/.test(query) || /(as|is)(\s.*?)$/.test(query)) {
completions.push(...[
'as',
'as array',
'as boolean',
'as float',
'as int',
'as json',
'as number',
'as object',
'as string',
'as false',
'as true',
'as NaN',
'as nan',
'as null',
'as Date',
'as date',
'as Document',
'as document',
'as Fragment',
'as fragment',
'as Node',
'as node',
'as Text',
'as text',
'as any',
'as camelcase',
'as eval',
'as json',
'as keys',
'as pascalcase',
'as query',
'as reversed',
'as snakecase',
'as sorted',
'as tuple',
'as unique',
'is',
'is array',
'is date',
'is fragment',
'is node',
'is number',
'is object',
'is text',
'is string',
].map((s) => query.replace(/\b(as|is)\b.*$/, '') + s))
}
completions.push(
':json',

@@ -159,6 +178,5 @@ ':keys',

)
}
const hits = completions.filter((c) => {
return parts.length && end ? c.startsWith(`:${end}`) : c.startsWith(query)
return c.startsWith(`:${end}`) || c.startsWith(end)
})

@@ -179,5 +197,5 @@

}
module.exports = {
module.exports = {
createCompleter
}

@@ -334,3 +334,3 @@ const { clearScreenDown, cursorTo, moveCursor } = require('readline')

// don't just preview a print all willy nilly
if (/^\s*?print\s*/.test(query.trim())) {
if (/\s*?print\s*/.test(query.trim())) {
return

@@ -340,3 +340,3 @@ }

// don't try to preview imports and lets
if (/^\s*?(import|let)\s*?.*$/.test(query.trim())) {
if (/^\s*?(import|let|if|else)\s*?.*$/.test(query.trim())) {
return

@@ -343,0 +343,0 @@ }

@@ -1,2 +0,2 @@

const { resolve} = require('./resolve')
const { resolve } = require('./uri')
const get = require('get-uri')

@@ -3,0 +3,0 @@ const fs = require('fs')

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc