New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-jq

Package Overview
Dependencies
Maintainers
0
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-jq - npm Package Compare versions

Comparing version 5.0.0 to 6.0.0

21

lib/command.d.ts

@@ -1,15 +0,8 @@

import { PartialOptions } from "./options";
export const FILTER_UNDEFINED_ERROR =
'node-jq: invalid filter argument supplied: "undefined"'
export const INPUT_JSON_UNDEFINED_ERROR =
'node-jq: invalid json object argument supplied: "undefined"'
export const INPUT_STRING_ERROR =
'node-jq: invalid json string argument supplied'
interface ICommand {
command: string,
args: string[],
stdin: string
import { type FilterInput, type JsonInput, type OptionsInput } from './options';
interface Command {
command: string;
args: string[];
stdin: string;
}
export function commandFactory(filter: string, json: any, options?: PartialOptions, jqPath?: string): ICommand
export declare const commandFactory: (filter: FilterInput, json: JsonInput, options?: OptionsInput, jqPath?: string) => Command;
export {};

@@ -5,115 +5,97 @@ "use strict";

});
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) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
Object.defineProperty(exports, "commandFactory", {
enumerable: true,
get: function() {
return commandFactory;
}
return obj;
});
const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require("node:path"));
const _options = require("./options");
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
}
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];
}
}
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
}
function _objectSpread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty(target, key, source[key]);
});
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return target;
return newObj;
}
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
};
var validateArguments = function(filter, json, options) {
var context = {
filter: filter,
json: json
};
var validatedOptions = Joi.attempt(options, _options.optionsSchema);
var validatedPreSpawn = Joi.attempt(context, _options.preSpawnSchema.tailor(validatedOptions.input), {
messages: messages,
errors: {
wrap: {
label: ""
const JQ_PATH = process.env.JQ_PATH ?? _nodepath.join(__dirname, '..', 'bin', 'jq');
const validateArguments = (filter, json, options)=>{
const validatedArgs = _options.commandArgsSchema.parse({
filter,
json,
options
});
const flags = (0, _options.buildCommandFlags)(validatedArgs.options);
const commandArgs = [
...flags,
validatedArgs.filter
];
let stdin = '';
switch(validatedArgs.options?.input){
case 'file':
{
const paths = validatedArgs.json;
commandArgs.push(...typeof paths === 'string' ? [
paths
] : paths);
break;
}
}
});
var validatedArgs = (0, _options).parseOptions(validatedOptions, validatedPreSpawn.filter, validatedPreSpawn.json);
var validatedSpawn = Joi.attempt({}, _options.spawnSchema.tailor(validatedOptions.input), {
context: _objectSpread({}, validatedPreSpawn, {
options: validatedOptions
})
});
if (validatedOptions.input === "file") {
return {
args: validatedArgs,
stdin: validatedSpawn.stdin
};
case 'json':
{
stdin = JSON.stringify(validatedArgs.json);
break;
}
case 'string':
{
stdin = validatedArgs.json;
break;
}
}
return {
args: validatedArgs,
stdin: validatedSpawn.stdin
args: commandArgs,
stdin
};
};
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.default.join(jqPath, "./jq") : JQ_PATH;
var result = validateArguments(filter, json, options);
const commandFactory = (filter, json, options, jqPath)=>{
const command = jqPath ? _nodepath.join(jqPath, './jq') : JQ_PATH;
const { args, stdin } = validateArguments(filter, json, options ?? {});
return {
command: command,
args: result.args,
stdin: result.stdin
command,
args,
stdin
};
};
exports.commandFactory = commandFactory;

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

export default function(command: string, args: string[], stdin: string, cwd?: string, detached?: boolean): Promise<string>
declare const exec: (command: string, args: string[], stdin: string, cwd?: string, detached?: boolean) => Promise<string>;
export default exec;

@@ -5,6 +5,11 @@ "use strict";

});
exports.default = void 0;
var _childProcess = _interopRequireDefault(require("child_process"));
var _stripFinalNewline = _interopRequireDefault(require("strip-final-newline"));
function _interopRequireDefault(obj) {
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _child_process = /*#__PURE__*/ _interop_require_default(require("child_process"));
const _stripfinalnewline = /*#__PURE__*/ _interop_require_default(require("strip-final-newline"));
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {

@@ -14,17 +19,17 @@ default: obj

}
var TEN_MEBIBYTE = 1024 * 1024 * 10;
var exec = function(command, args, stdin, cwd, detached) {
return new Promise(function(resolve, reject) {
var stdout = "";
var stderr = "";
var spawnOptions = {
const TEN_MEBIBYTE = 1024 * 1024 * 10;
const exec = (command, args, stdin, cwd, detached)=>{
return new Promise((resolve, reject)=>{
let stdout = '';
let stderr = '';
const spawnOptions = {
maxBuffer: TEN_MEBIBYTE,
cwd: cwd,
detached: detached,
cwd,
detached,
env: {}
};
var process = _childProcess.default.spawn(command, args, spawnOptions);
const process = _child_process.default.spawn(command, args, spawnOptions);
// All of these handlers can close the Promise, so guard against rejecting it twice.
var promiseAlreadyRejected = false;
process.on("close", function(code) {
let promiseAlreadyRejected = false;
process.on('close', (code)=>{
if (!promiseAlreadyRejected) {

@@ -35,3 +40,3 @@ promiseAlreadyRejected = true;

} else {
return resolve((0, _stripFinalNewline).default(stdout));
return resolve((0, _stripfinalnewline.default)(stdout));
}

@@ -41,3 +46,3 @@ }

if (stdin) {
process.stdin.on("error", function(err) {
process.stdin.on('error', (err)=>{
if (!promiseAlreadyRejected) {

@@ -51,7 +56,7 @@ promiseAlreadyRejected = true;

}
process.stdout.setEncoding("utf-8");
process.stdout.on("data", function(data) {
process.stdout.setEncoding('utf-8');
process.stdout.on('data', (data)=>{
stdout += data;
});
process.stderr.on("data", function(data) {
process.stderr.on('data', (data)=>{
stderr += data;

@@ -61,3 +66,2 @@ });

};
var _default = exec;
exports.default = _default;
const _default = exec;

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

import { PartialOptions } from "./options"
export function run(filter: string, json: any, options?: PartialOptions, jqPath?: string, cwd?: string, detached?: boolean): Promise<object | string>
import type { FilterInput, JsonInput, OptionsInput } from './options';
export declare const run: (filter: FilterInput, json: JsonInput, options?: OptionsInput, jqPath?: string, cwd?: string, detached?: boolean) => Promise<object | string>;

@@ -5,6 +5,11 @@ "use strict";

});
exports.run = void 0;
var _exec = _interopRequireDefault(require("./exec"));
var _command = require("./command");
function _interopRequireDefault(obj) {
Object.defineProperty(exports, "run", {
enumerable: true,
get: function() {
return run;
}
});
const _exec = /*#__PURE__*/ _interop_require_default(require("./exec"));
const _command = require("./command");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {

@@ -14,12 +19,11 @@ 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, detached = arguments.length > 5 ? arguments[5] : void 0;
return new Promise(function(resolve, reject) {
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, detached).then(function(stdout) {
if (options.output === "json") {
var result;
const run = (filter, json, options, jqPath, cwd, detached)=>{
return new Promise((resolve, reject)=>{
const { command, args, stdin } = (0, _command.commandFactory)(filter, json, options, jqPath);
(0, _exec.default)(command, args, stdin, cwd, detached).then((stdout)=>{
if (options?.output === 'json') {
let result;
try {
result = JSON.parse(stdout);
} catch (error) {
} catch (_error) {
result = stdout;

@@ -31,5 +35,4 @@ }

}
})["catch"](reject);
}).catch(reject);
});
};
exports.run = run;

@@ -1,18 +0,121 @@

import * as Joi from "joi";
export declare const optionsSchema: Joi.SchemaLike;
export declare const preSpawnSchema: Joi.SchemaLike
export declare const spawnSchema: Joi.SchemaLike
export declare function parseOptions(options: PartialOptions, filter: string, json: any): any
export declare const optionDefaults: IOptions;
interface IOptions {
color: boolean,
input: string,
locations: string[],
output: string,
raw: boolean,
slurp: boolean,
sort: boolean,
args: { [key: string]: object | string }
}
export type PartialOptions = Partial<IOptions>
import * as z from 'zod';
declare const literalSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
type Literal = z.infer<typeof literalSchema>;
export type Json = Literal | {
[key: string]: Json;
} | Json[];
export declare const jsonTypeSchema: z.ZodType<Json>;
export declare const optionsSchema: z.ZodObject<{
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<Json, z.ZodTypeDef, Json>>>;
color: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
input: z.ZodDefault<z.ZodOptional<z.ZodEnum<["file", "json", "string"]>>>;
output: z.ZodDefault<z.ZodOptional<z.ZodEnum<["pretty", "compact", "string", "json"]>>>;
raw: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
slurp: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
sort: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
}, "strip", z.ZodTypeAny, {
sort: boolean;
color: boolean;
input: "string" | "file" | "json";
output: "string" | "json" | "pretty" | "compact";
raw: boolean;
slurp: boolean;
args?: Record<string, Json> | undefined;
}, {
sort?: boolean | undefined;
args?: Record<string, Json> | undefined;
color?: boolean | undefined;
input?: "string" | "file" | "json" | undefined;
output?: "string" | "json" | "pretty" | "compact" | undefined;
raw?: boolean | undefined;
slurp?: boolean | undefined;
}>;
export type OptionsInput = z.input<typeof optionsSchema>;
export type OptionsOutput = z.output<typeof optionsSchema>;
declare const filterSchema: z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodNull, string, null>]>;
export type FilterInput = z.input<typeof filterSchema>;
export type FilterOutput = z.output<typeof filterSchema>;
declare const jsonSchema: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodType<Json, z.ZodTypeDef, Json>]>;
export type JsonInput = z.input<typeof jsonSchema>;
export type JsonOutput = z.output<typeof jsonSchema>;
export declare const commandArgsSchema: z.ZodEffects<z.ZodObject<{
filter: z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodNull, string, null>]>;
json: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodType<Json, z.ZodTypeDef, Json>]>;
options: z.ZodObject<{
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<Json, z.ZodTypeDef, Json>>>;
color: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
input: z.ZodDefault<z.ZodOptional<z.ZodEnum<["file", "json", "string"]>>>;
output: z.ZodDefault<z.ZodOptional<z.ZodEnum<["pretty", "compact", "string", "json"]>>>;
raw: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
slurp: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
sort: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
}, "strip", z.ZodTypeAny, {
sort: boolean;
color: boolean;
input: "string" | "file" | "json";
output: "string" | "json" | "pretty" | "compact";
raw: boolean;
slurp: boolean;
args?: Record<string, Json> | undefined;
}, {
sort?: boolean | undefined;
args?: Record<string, Json> | undefined;
color?: boolean | undefined;
input?: "string" | "file" | "json" | undefined;
output?: "string" | "json" | "pretty" | "compact" | undefined;
raw?: boolean | undefined;
slurp?: boolean | undefined;
}>;
}, "strip", z.ZodTypeAny, {
filter: string;
options: {
sort: boolean;
color: boolean;
input: "string" | "file" | "json";
output: "string" | "json" | "pretty" | "compact";
raw: boolean;
slurp: boolean;
args?: Record<string, Json> | undefined;
};
json: string[] | Json;
}, {
filter: string | null;
options: {
sort?: boolean | undefined;
args?: Record<string, Json> | undefined;
color?: boolean | undefined;
input?: "string" | "file" | "json" | undefined;
output?: "string" | "json" | "pretty" | "compact" | undefined;
raw?: boolean | undefined;
slurp?: boolean | undefined;
};
json: string[] | Json;
}>, {
filter: string;
options: {
sort: boolean;
color: boolean;
input: "string" | "file" | "json";
output: "string" | "json" | "pretty" | "compact";
raw: boolean;
slurp: boolean;
args?: Record<string, Json> | undefined;
};
json: string[] | Json;
}, {
filter: string | null;
options: {
sort?: boolean | undefined;
args?: Record<string, Json> | undefined;
color?: boolean | undefined;
input?: "string" | "file" | "json" | undefined;
output?: "string" | "json" | "pretty" | "compact" | undefined;
raw?: boolean | undefined;
slurp?: boolean | undefined;
};
json: string[] | Json;
}>;
export type CommandArgsInput = z.input<typeof commandArgsSchema>;
export type CommandArgsOutput = z.output<typeof commandArgsSchema>;
export declare const buildCommandFlags: (options: OptionsOutput) => string[];
export {};

@@ -5,176 +5,198 @@ "use strict";

});
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) {
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
buildCommandFlags: function() {
return buildCommandFlags;
},
commandArgsSchema: function() {
return commandArgsSchema;
},
jsonTypeSchema: function() {
return jsonTypeSchema;
},
optionsSchema: function() {
return optionsSchema;
}
});
const _isvalidpath = /*#__PURE__*/ _interop_require_default(require("is-valid-path"));
const _zod = /*#__PURE__*/ _interop_require_wildcard(require("zod"));
const _utils = require("./utils");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && 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];
}
}
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
var _typeof = function(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
function createBooleanSchema(name, value) {
return Joi.string().when("".concat(name), {
is: Joi["boolean"]().required().valid(true),
then: Joi.string()["default"](value)
});
}
var strictBoolean = Joi["boolean"]()["default"](false).strict();
var path = Joi.any().custom(function(value, helpers) {
try {
(0, _utils).validateJSONPath(value);
return value;
} catch (e) {
var errorType = e.message.includes(".json") ? "json" : "path";
return helpers.error("any.invalid", {
type: errorType
});
}
}, "path validation").required().error(function(errors) {
errors.forEach(function(error) {
if (error.value === undefined) {
error.local.type = "path";
}
});
return errors;
const JSON_INVALID_PATH_TYPE_ERROR = 'invalid json argument supplied (expected a string or an array of strings)';
const JSON_INVALID_PATH_ERROR = 'invalid json argument supplied (not a valid path)';
const JSON_NOT_A_JSON_FILE_ERROR = 'invalid json argument supplied (not a .json file)';
const literalSchema = _zod.union([
_zod.string(),
_zod.number(),
_zod.boolean(),
_zod.null()
]);
const jsonTypeSchema = _zod.lazy(()=>_zod.union([
literalSchema,
_zod.array(jsonTypeSchema),
_zod.record(jsonTypeSchema)
]));
const optionsSchema = _zod.object({
args: _zod.record(jsonTypeSchema).optional(),
color: _zod.boolean().optional().default(false),
input: _zod.enum([
'file',
'json',
'string'
]).optional().default('file'),
output: _zod.enum([
'pretty',
'compact',
'string',
'json'
]).optional().default('pretty'),
raw: _zod.boolean().optional().default(false),
slurp: _zod.boolean().optional().default(false),
sort: _zod.boolean().optional().default(false)
});
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"),
raw: strictBoolean,
slurp: strictBoolean,
sort: strictBoolean,
args: Joi.object().unknown()
});
exports.optionsSchema = optionsSchema;
var preSpawnSchema = Joi.object({
filter: Joi.string().allow("", null).required(),
json: Joi.any().alter({
file: function(schema) {
return schema.when("/json", {
is: Joi.array().required(),
then: Joi.array().items(path),
otherwise: path
}).label("path");
},
json: function(schema) {
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");
}
})
});
exports.preSpawnSchema = preSpawnSchema;
var spawnSchema = Joi.object({
args: Joi.object({
color: createBooleanSchema("$options.color", "--color-output"),
input: Joi.any().alter({
file: function(schema) {
return schema.when("$json", {
is: [
Joi.array().items(Joi.string()),
Joi.string()
],
then: Joi.array()["default"](Joi.ref("$json", {
adjust: function(value) {
return [].concat(value);
}
}))
const filterSchema = _zod.union([
_zod.string(),
_zod.null().transform(()=>'null')
]);
const jsonSchema = _zod.union([
_zod.string(),
_zod.array(_zod.string()),
jsonTypeSchema
]);
const commandArgsSchema = _zod.object({
filter: filterSchema,
json: jsonSchema,
options: optionsSchema
}).superRefine((data, ctx)=>{
const json = data.json;
const input = data.options.input;
switch(input){
case 'file':
{
const paths = [];
if (typeof json === 'string') {
paths.push(json);
} else if (Array.isArray(json) && (0, _utils.isStringArray)(json)) {
paths.concat(json);
} else {
ctx.addIssue({
code: _zod.ZodIssueCode.custom,
fatal: true,
message: JSON_INVALID_PATH_TYPE_ERROR
});
return _zod.NEVER;
}
paths.forEach((path)=>{
if (!(0, _isvalidpath.default)(path)) {
ctx.addIssue({
code: _zod.ZodIssueCode.custom,
fatal: true,
message: `${JSON_INVALID_PATH_ERROR}: "${path}"`
});
return;
}
if (!(0, _utils.isJSONPath)(path)) {
ctx.addIssue({
code: _zod.ZodIssueCode.custom,
fatal: true,
message: `${JSON_NOT_A_JSON_FILE_ERROR}: "${path}"`
});
return;
}
});
break;
}
}),
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"),
args: Joi.array().when("$options.args", {
is: Joi.object().required(),
then: Joi.array()["default"](Joi.ref("$options.args", {
adjust: function(value) {
return Object.keys(value).map(function(key) {
switch(_typeof(value[key])){
case "string":
return [
"--arg",
key,
value[key]
];
case "object":
return [
"--argjson",
key,
JSON.stringify(value[key])
];
default:
return [
"--arg",
key,
value[key]
];
}
}).flat();
case 'string':
{
if (typeof json !== 'string') {
ctx.addIssue({
code: _zod.ZodIssueCode.invalid_type,
expected: 'string',
fatal: true,
received: typeof json
});
} else if (json === '') {
ctx.addIssue({
code: _zod.ZodIssueCode.too_small,
fatal: true,
inclusive: true,
minimum: 1,
type: 'string'
});
}
}))
})
})["default"](),
stdin: Joi.string()["default"]("").alter({
json: function(schema) {
return schema["default"](Joi.ref("$json", {
adjust: function(value) {
return JSON.stringify(value);
}
}));
},
string: function(schema) {
return schema["default"](Joi.ref("$json"));
break;
}
}
return _zod.NEVER;
});
const buildCommandFlags = (options)=>{
const flags = [];
options.color && flags.push('--color-output');
options.raw && flags.push('-r');
options.slurp && flags.push('--slurp');
options.sort && flags.push('--sort-keys');
if ([
'compact',
'string'
].includes(options.output)) {
flags.push('--compact-output');
}
Object.entries(options.args ?? {}).forEach(([key, value])=>{
if (typeof value === 'string') {
flags.push('--arg', key, value);
return;
}
})
});
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;
var context = {
filter: filter,
json: json,
options: options
};
var validatedSpawn = Joi.attempt({}, spawnSchema.tailor(options.input), {
context: context
flags.push('--argjson', key, JSON.stringify(value));
});
if (options.input === "file") {
return Object.keys(validatedSpawn.args).filter(function(key) {
return key !== "input";
}).reduce(function(list, key) {
return list.concat(validatedSpawn.args[key]);
}, []).concat(filter, json);
}
return Object.values(validatedSpawn.args).flat().concat(filter);
return flags;
};
exports.parseOptions = parseOptions;
var optionDefaults = Joi.attempt({}, optionsSchema);
exports.optionDefaults = optionDefaults;

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

export const INVALID_PATH_ERROR =
'node-jq: invalid path argument supplied (not a valid path)'
export const INVALID_JSON_PATH_ERROR =
'node-jq: invalid path argument supplied (not a .json file)'
export function isJSONPath(path: any): boolean
export function validateJSONPath(path: any): boolean
export declare const isStringArray: (values: unknown[]) => values is string[];
export declare const isJSONPath: (path: string) => boolean;

@@ -5,26 +5,19 @@ "use strict";

});
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
};
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
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) {
_export(exports, {
isJSONPath: function() {
return isJSONPath;
},
isStringArray: function() {
return isStringArray;
}
});
const isStringArray = (values)=>values.every((value)=>typeof value === 'string');
const isJSONPath = (path)=>{
return /\.json|.jsonl$/.test(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, '"'));
}
return true;
};
exports.validateJSONPath = validateJSONPath;
{
"name": "node-jq",
"version": "5.0.0",
"version": "6.0.0",
"description": "Run jq in node",

@@ -16,7 +16,6 @@ "main": "lib/jq.js",

"install-binary": "node scripts/install-binary.js",
"test": "nyc mocha src/*.test.js -r @swc-node/register",
"test": "nyc mocha src/*.test.ts -r @swc-node/register",
"test:watch": "npm test -- --watch",
"lint": "standard --verbose | snazzy",
"build": "swc ./src --delete-dir-on-start -d lib",
"copy-ts-defintions": "copyfiles src/*.d.ts lib -f",
"lint": "eslint ./src",
"build": "swc ./src --delete-dir-on-start -d lib && tsc",
"preinstall": "npm run install-binary",

@@ -26,3 +25,4 @@ "coverage": "nyc report --reporter=lcov",

"codeclimate": "codeclimate-test-reporter < coverage/lcov.info",
"semantic-release": "semantic-release"
"semantic-release": "semantic-release",
"typecheck": "tsc --noEmit"
},

@@ -49,6 +49,5 @@ "engines": {

"files": [
"src",
"lib",
"scripts",
"docs"
"docs",
"lib"
],

@@ -58,6 +57,6 @@ "dependencies": {

"is-valid-path": "^0.1.1",
"joi": "^17.4.0",
"node-downloader-helper": "^2.1.6",
"strip-final-newline": "^2.0.0",
"tempfile": "^3.0.0"
"tempfile": "^3.0.0",
"zod": "^3.23.8"
},

@@ -71,5 +70,15 @@ "devDependencies": {

"@semantic-release/release-notes-generator": "^11.0.4",
"@swc-node/register": "^1.4.0",
"@swc-node/register": "^1.10.2",
"@swc/cli": "^0.1.57",
"@swc/core": "^1.2.161",
"@tsconfig/node18": "^18.2.4",
"@tsconfig/strictest": "^2.0.5",
"@types/chai": "^4.3.16",
"@types/eslint": "^8.56.10",
"@types/is-valid-path": "^0.1.2",
"@types/mocha": "^10.0.7",
"@types/node": "^18.19.39",
"@types/strip-final-newline": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"chai": "^4.2.0",

@@ -79,15 +88,13 @@ "codeclimate-test-reporter": "^0.5.1",

"copyfiles": "^2.4.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"prettier": "3.3.2",
"semantic-release": "^23.0.0",
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"typescript": "^5.5.3",
"validate-commit-msg": "^2.14.0"
},
"standard": {
"global": [
"describe",
"it"
]
}
}
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