Comparing version 2.3.2 to 2.3.3
@@ -0,1 +1,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.commandFactory = exports.INPUT_STRING_ERROR = exports.INPUT_JSON_UNDEFINED_ERROR = exports.FILTER_UNDEFINED_ERROR = void 0; | ||
var Joi = _interopRequireWildcard(require("joi")); | ||
var _path = _interopRequireDefault(require("path")); | ||
var _options = require("./options"); | ||
function _defineProperty(obj, key, value) { | ||
@@ -14,2 +22,28 @@ if (key in obj) { | ||
} | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
function _interopRequireWildcard(obj) { | ||
if (obj && obj.__esModule) { | ||
return obj; | ||
} else { | ||
var newObj = {}; | ||
if (obj != null) { | ||
for(var key in obj){ | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; | ||
if (desc.get || desc.set) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
} | ||
} | ||
newObj.default = obj; | ||
return newObj; | ||
} | ||
} | ||
function _objectSpread(target) { | ||
@@ -30,15 +64,15 @@ for(var i = 1; i < arguments.length; i++){ | ||
} | ||
import * as Joi from 'joi'; | ||
import path from 'path'; | ||
import { parseOptions, optionsSchema, preSpawnSchema, spawnSchema } from './options'; | ||
var JQ_PATH = process.env.JQ_PATH || path.join(__dirname, '..', 'bin', 'jq'); | ||
export var FILTER_UNDEFINED_ERROR = 'node-jq: invalid filter argument supplied: "undefined"'; | ||
export var INPUT_JSON_UNDEFINED_ERROR = 'node-jq: invalid json argument supplied: "undefined"'; | ||
export var INPUT_STRING_ERROR = 'node-jq: invalid json string argument supplied'; | ||
var NODE_JQ_ERROR_TEMPLATE = 'node-jq: invalid {#label} ' + 'argument supplied{if(#label == "path" && #type == "json", " (not a .json file)", "")}' + '{if(#label == "path" && #type == "path", " (not a valid path)", "")}: ' + '"{if(#value != undefined, #value, "undefined")}"'; | ||
var JQ_PATH = process.env.JQ_PATH || _path.default.join(__dirname, "..", "bin", "jq"); | ||
var FILTER_UNDEFINED_ERROR = 'node-jq: invalid filter argument supplied: "undefined"'; | ||
exports.FILTER_UNDEFINED_ERROR = FILTER_UNDEFINED_ERROR; | ||
var INPUT_JSON_UNDEFINED_ERROR = 'node-jq: invalid json argument supplied: "undefined"'; | ||
exports.INPUT_JSON_UNDEFINED_ERROR = INPUT_JSON_UNDEFINED_ERROR; | ||
var INPUT_STRING_ERROR = "node-jq: invalid json string argument supplied"; | ||
exports.INPUT_STRING_ERROR = INPUT_STRING_ERROR; | ||
var NODE_JQ_ERROR_TEMPLATE = "node-jq: invalid {#label} " + 'argument supplied{if(#label == "path" && #type == "json", " (not a .json file)", "")}' + '{if(#label == "path" && #type == "path", " (not a valid path)", "")}: ' + '"{if(#value != undefined, #value, "undefined")}"'; | ||
var messages = { | ||
'any.invalid': NODE_JQ_ERROR_TEMPLATE, | ||
'any.required': NODE_JQ_ERROR_TEMPLATE, | ||
'string.base': NODE_JQ_ERROR_TEMPLATE, | ||
'string.empty': NODE_JQ_ERROR_TEMPLATE | ||
"any.invalid": NODE_JQ_ERROR_TEMPLATE, | ||
"any.required": NODE_JQ_ERROR_TEMPLATE, | ||
"string.base": NODE_JQ_ERROR_TEMPLATE, | ||
"string.empty": NODE_JQ_ERROR_TEMPLATE | ||
}; | ||
@@ -50,13 +84,13 @@ var validateArguments = function(filter, json, options) { | ||
}; | ||
var validatedOptions = Joi.attempt(options, optionsSchema); | ||
var validatedPreSpawn = Joi.attempt(context, preSpawnSchema.tailor(validatedOptions.input), { | ||
var validatedOptions = Joi.attempt(options, _options.optionsSchema); | ||
var validatedPreSpawn = Joi.attempt(context, _options.preSpawnSchema.tailor(validatedOptions.input), { | ||
messages: messages, | ||
errors: { | ||
wrap: { | ||
label: '' | ||
label: "" | ||
} | ||
} | ||
}); | ||
var validatedArgs = parseOptions(validatedOptions, validatedPreSpawn.filter, validatedPreSpawn.json); | ||
var validatedSpawn = Joi.attempt({}, spawnSchema.tailor(validatedOptions.input), { | ||
var validatedArgs = (0, _options).parseOptions(validatedOptions, validatedPreSpawn.filter, validatedPreSpawn.json); | ||
var validatedSpawn = Joi.attempt({}, _options.spawnSchema.tailor(validatedOptions.input), { | ||
context: _objectSpread({}, validatedPreSpawn, { | ||
@@ -66,3 +100,3 @@ options: validatedOptions | ||
}); | ||
if (validatedOptions.input === 'file') { | ||
if (validatedOptions.input === "file") { | ||
return { | ||
@@ -78,5 +112,5 @@ args: validatedArgs, | ||
}; | ||
export var commandFactory = function(filter, json) { | ||
var commandFactory = function(filter, json) { | ||
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, jqPath = arguments.length > 3 ? arguments[3] : void 0; | ||
var command = jqPath ? path.join(jqPath, './jq') : JQ_PATH; | ||
var command = jqPath ? _path.default.join(jqPath, "./jq") : JQ_PATH; | ||
var result = validateArguments(filter, json, options); | ||
@@ -89,1 +123,2 @@ return { | ||
}; | ||
exports.commandFactory = commandFactory; |
@@ -1,8 +0,18 @@ | ||
import childProcess from 'child_process'; | ||
import stripFinalNewline from 'strip-final-newline'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _childProcess = _interopRequireDefault(require("child_process")); | ||
var _stripFinalNewline = _interopRequireDefault(require("strip-final-newline")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
var TEN_MEBIBYTE = 1024 * 1024 * 10; | ||
var exec = function(command, args, stdin, cwd) { | ||
return new Promise(function(resolve, reject) { | ||
var stdout = ''; | ||
var stderr = ''; | ||
var stdout = ""; | ||
var stderr = ""; | ||
var spawnOptions = { | ||
@@ -12,20 +22,20 @@ maxBuffer: TEN_MEBIBYTE, | ||
}; | ||
var process = childProcess.spawn(command, args, spawnOptions); | ||
var process = _childProcess.default.spawn(command, args, spawnOptions); | ||
if (stdin) { | ||
process.stdin.setEncoding('utf-8'); | ||
process.stdin.setEncoding("utf-8"); | ||
process.stdin.write(stdin); | ||
process.stdin.end(); | ||
} | ||
process.stdout.setEncoding('utf-8'); | ||
process.stdout.on('data', function(data) { | ||
process.stdout.setEncoding("utf-8"); | ||
process.stdout.on("data", function(data) { | ||
stdout += data; | ||
}); | ||
process.stderr.on('data', function(data) { | ||
process.stderr.on("data", function(data) { | ||
stderr += data; | ||
}); | ||
process.on('close', function(code) { | ||
process.on("close", function(code) { | ||
if (code !== 0) { | ||
return reject(Error(stderr)); | ||
} else { | ||
return resolve(stripFinalNewline(stdout)); | ||
return resolve((0, _stripFinalNewline).default(stdout)); | ||
} | ||
@@ -35,2 +45,3 @@ }); | ||
}; | ||
export default exec; | ||
var _default = exec; | ||
exports.default = _default; |
@@ -1,9 +0,19 @@ | ||
import exec from './exec'; | ||
import { commandFactory } from './command'; | ||
export var run = function(filter, json) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.run = void 0; | ||
var _exec = _interopRequireDefault(require("./exec")); | ||
var _command = require("./command"); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
var run = function(filter, json) { | ||
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, jqPath = arguments.length > 3 ? arguments[3] : void 0, cwd = arguments.length > 4 ? arguments[4] : void 0; | ||
return new Promise(function(resolve, reject) { | ||
var ref = commandFactory(filter, json, options, jqPath), command = ref.command, args = ref.args, stdin = ref.stdin; | ||
exec(command, args, stdin, cwd).then(function(stdout) { | ||
if (options.output === 'json') { | ||
var ref = (0, _command).commandFactory(filter, json, options, jqPath), command = ref.command, args = ref.args, stdin = ref.stdin; | ||
(0, _exec).default(command, args, stdin, cwd).then(function(stdout) { | ||
if (options.output === "json") { | ||
var result; | ||
@@ -19,4 +29,5 @@ try { | ||
} | ||
}).catch(reject); | ||
})["catch"](reject); | ||
}); | ||
}; | ||
exports.run = run; |
@@ -1,24 +0,50 @@ | ||
import * as Joi from 'joi'; | ||
import { validateJSONPath } from './utils'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.optionDefaults = exports.parseOptions = exports.spawnSchema = exports.preSpawnSchema = exports.optionsSchema = void 0; | ||
var Joi = _interopRequireWildcard(require("joi")); | ||
var _utils = require("./utils"); | ||
function _interopRequireWildcard(obj) { | ||
if (obj && obj.__esModule) { | ||
return obj; | ||
} else { | ||
var newObj = {}; | ||
if (obj != null) { | ||
for(var key in obj){ | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; | ||
if (desc.get || desc.set) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
} | ||
} | ||
newObj.default = obj; | ||
return newObj; | ||
} | ||
} | ||
function createBooleanSchema(name, value) { | ||
return Joi.string().when("".concat(name), { | ||
is: Joi.boolean().required().valid(true), | ||
then: Joi.string().default(value) | ||
is: Joi["boolean"]().required().valid(true), | ||
then: Joi.string()["default"](value) | ||
}); | ||
} | ||
var strictBoolean = Joi.boolean().default(false).strict(); | ||
var strictBoolean = Joi["boolean"]()["default"](false).strict(); | ||
var path = Joi.any().custom(function(value, helpers) { | ||
try { | ||
validateJSONPath(value); | ||
(0, _utils).validateJSONPath(value); | ||
return value; | ||
} catch (e) { | ||
var errorType = e.message.includes('.json') ? 'json' : 'path'; | ||
return helpers.error('any.invalid', { | ||
var errorType = e.message.includes(".json") ? "json" : "path"; | ||
return helpers.error("any.invalid", { | ||
type: errorType | ||
}); | ||
} | ||
}, 'path validation').required().error(function(errors) { | ||
}, "path validation").required().error(function(errors) { | ||
errors.forEach(function(error) { | ||
if (error.value === undefined) { | ||
error.local.type = 'path'; | ||
error.local.type = "path"; | ||
} | ||
@@ -28,7 +54,7 @@ }); | ||
}); | ||
export var optionsSchema = Joi.object({ | ||
var optionsSchema = Joi.object({ | ||
color: strictBoolean, | ||
input: Joi.string().default('file').valid('file', 'json', 'string'), | ||
locations: Joi.array().items(Joi.string()).default([]), | ||
output: Joi.string().default('pretty').valid('string', 'compact', 'pretty', 'json'), | ||
input: Joi.string()["default"]("file").valid("file", "json", "string"), | ||
locations: Joi.array().items(Joi.string())["default"]([]), | ||
output: Joi.string()["default"]("pretty").valid("string", "compact", "pretty", "json"), | ||
raw: strictBoolean, | ||
@@ -38,26 +64,28 @@ slurp: strictBoolean, | ||
}); | ||
export var preSpawnSchema = Joi.object({ | ||
filter: Joi.string().allow('', null).required(), | ||
exports.optionsSchema = optionsSchema; | ||
var preSpawnSchema = Joi.object({ | ||
filter: Joi.string().allow("", null).required(), | ||
json: Joi.any().alter({ | ||
file: function(schema) { | ||
return schema.when('/json', { | ||
return schema.when("/json", { | ||
is: Joi.array().required(), | ||
then: Joi.array().items(path), | ||
otherwise: path | ||
}).label('path'); | ||
}).label("path"); | ||
}, | ||
json: function(schema) { | ||
return Joi.alternatives().try(Joi.array(), Joi.object().allow('', null).required().label('json object')).required(); | ||
return Joi.alternatives()["try"](Joi.array(), Joi.object().allow("", null).required().label("json object")).required(); | ||
}, | ||
string: function(schema) { | ||
return Joi.string().required().label('json string'); | ||
return Joi.string().required().label("json string"); | ||
} | ||
}) | ||
}); | ||
export var spawnSchema = Joi.object({ | ||
exports.preSpawnSchema = preSpawnSchema; | ||
var spawnSchema = Joi.object({ | ||
args: Joi.object({ | ||
color: createBooleanSchema('$options.color', '--color-output'), | ||
color: createBooleanSchema("$options.color", "--color-output"), | ||
input: Joi.any().alter({ | ||
file: function(schema) { | ||
return schema.when('$json', { | ||
return schema.when("$json", { | ||
is: [ | ||
@@ -67,3 +95,3 @@ Joi.array().items(Joi.string()), | ||
], | ||
then: Joi.array().default(Joi.ref('$json', { | ||
then: Joi.array()["default"](Joi.ref("$json", { | ||
adjust: function(value) { | ||
@@ -76,14 +104,14 @@ return [].concat(value); | ||
}), | ||
locations: Joi.ref('$options.locations'), | ||
output: Joi.string().when('$options.output', { | ||
is: Joi.string().required().valid('string', 'compact'), | ||
then: Joi.string().default('--compact-output') | ||
locations: Joi.ref("$options.locations"), | ||
output: Joi.string().when("$options.output", { | ||
is: Joi.string().required().valid("string", "compact"), | ||
then: Joi.string()["default"]("--compact-output") | ||
}), | ||
raw: createBooleanSchema('$options.raw', '-r'), | ||
slurp: createBooleanSchema('$options.slurp', '--slurp'), | ||
sort: createBooleanSchema('$options.sort', '--sort-keys') | ||
}).default(), | ||
stdin: Joi.string().default('').alter({ | ||
raw: createBooleanSchema("$options.raw", "-r"), | ||
slurp: createBooleanSchema("$options.slurp", "--slurp"), | ||
sort: createBooleanSchema("$options.sort", "--sort-keys") | ||
})["default"](), | ||
stdin: Joi.string()["default"]("").alter({ | ||
json: function(schema) { | ||
return schema.default(Joi.ref('$json', { | ||
return schema["default"](Joi.ref("$json", { | ||
adjust: function(value) { | ||
@@ -95,7 +123,8 @@ return JSON.stringify(value); | ||
string: function(schema) { | ||
return schema.default(Joi.ref('$json')); | ||
return schema["default"](Joi.ref("$json")); | ||
} | ||
}) | ||
}); | ||
export var parseOptions = function() { | ||
exports.spawnSchema = spawnSchema; | ||
var parseOptions = function() { | ||
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, filter = arguments.length > 1 ? arguments[1] : void 0, json = arguments.length > 2 ? arguments[2] : void 0; | ||
@@ -110,5 +139,5 @@ var context = { | ||
}); | ||
if (options.input === 'file') { | ||
if (options.input === "file") { | ||
return Object.keys(validatedSpawn.args).filter(function(key) { | ||
return key !== 'input'; | ||
return key !== "input"; | ||
}).reduce(function(list, key) { | ||
@@ -120,2 +149,4 @@ return list.concat(validatedSpawn.args[key]); | ||
}; | ||
export var optionDefaults = Joi.attempt({}, optionsSchema); | ||
exports.parseOptions = parseOptions; | ||
var optionDefaults = Joi.attempt({}, optionsSchema); | ||
exports.optionDefaults = optionDefaults; |
@@ -1,15 +0,29 @@ | ||
import isPathValid from 'is-valid-path'; | ||
export var INVALID_PATH_ERROR = 'node-jq: invalid path argument supplied (not a valid path)'; | ||
export var INVALID_JSON_PATH_ERROR = 'node-jq: invalid path argument supplied (not a .json file)'; | ||
export var isJSONPath = function(path) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.validateJSONPath = exports.isJSONPath = exports.INVALID_JSON_PATH_ERROR = exports.INVALID_PATH_ERROR = void 0; | ||
var _isValidPath = _interopRequireDefault(require("is-valid-path")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
var INVALID_PATH_ERROR = "node-jq: invalid path argument supplied (not a valid path)"; | ||
exports.INVALID_PATH_ERROR = INVALID_PATH_ERROR; | ||
var INVALID_JSON_PATH_ERROR = "node-jq: invalid path argument supplied (not a .json file)"; | ||
exports.INVALID_JSON_PATH_ERROR = INVALID_JSON_PATH_ERROR; | ||
var isJSONPath = function(path) { | ||
return /\.json$/.test(path); | ||
}; | ||
export var validateJSONPath = function(path) { | ||
if (!isPathValid(path)) { | ||
throw new Error("".concat(INVALID_PATH_ERROR, ": \"").concat(path, "\"")); | ||
exports.isJSONPath = isJSONPath; | ||
var validateJSONPath = function(path) { | ||
if (!(0, _isValidPath).default(path)) { | ||
throw new Error("".concat(INVALID_PATH_ERROR, ': "').concat(path, '"')); | ||
} | ||
if (!isJSONPath(path)) { | ||
throw new Error("".concat(INVALID_JSON_PATH_ERROR, ": \"").concat(path === '' ? '' : path, "\"")); | ||
throw new Error("".concat(INVALID_JSON_PATH_ERROR, ': "').concat(path === "" ? "" : path, '"')); | ||
} | ||
return true; | ||
}; | ||
exports.validateJSONPath = validateJSONPath; |
{ | ||
"name": "node-jq", | ||
"version": "2.3.2", | ||
"version": "2.3.3", | ||
"description": "Run jq in node", | ||
@@ -16,3 +16,3 @@ "main": "lib/jq.js", | ||
"lint": "standard --verbose | snazzy", | ||
"build": "swc src --ignore src/__test__,src/*.d.ts --delete-dir-on-start -d lib", | ||
"build": "swc ./src --delete-dir-on-start -d lib", | ||
"copy-ts-defintions": "copyfiles src/*.d.ts lib -f", | ||
@@ -63,4 +63,4 @@ "postinstall": "npm run install-binary", | ||
"@swc-node/register": "^1.4.0", | ||
"@swc/cli": "^0.1.51", | ||
"@swc/core": "^1.2.111", | ||
"@swc/cli": "^0.1.57", | ||
"@swc/core": "^1.2.161", | ||
"chai": "^4.2.0", | ||
@@ -67,0 +67,0 @@ "codeclimate-test-reporter": "^0.5.1", |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
6
628458
37
3433