Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
talsabagport committed Jan 22, 2024
1 parent faa13e1 commit 68d9bbf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ docs
.DS_Store
.vscode
load.js
reports/
reports/
.idea
8 changes: 5 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
declare module '@port-labs/jq-node-bindings' {
type ExecOptions = {enableEnv?: boolean, throwOnError?: boolean};
export function exec(json: object, input: string, options?: ExecOptions): object | Array<any> | string | number | boolean | null;
export function renderRecursively(json: object, input: object | Array<any> | string | number | boolean | null, execOptions?: ExecOptions): object | Array<any> | string | number | boolean | null;
type ExecOptions = { enableEnv?: boolean, throwOnError?: boolean };

export function exec(json: object, input: string, options?: ExecOptions): object | Array<any> | string | number | boolean | null;

export function renderRecursively(json: object, input: object | Array<any> | string | number | boolean | null, execOptions?: ExecOptions): object | Array<any> | string | number | boolean | null;
}
2 changes: 1 addition & 1 deletion lib/jq.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const formatFilter = (filter, {enableEnv = false} = {}) => {
// Escape single quotes only if they are opening or closing a string
let formattedFilter = filter.replace(/(^|\s)'(?!\s|")|(?<!\s|")'(\s|$)/g, '$1"$2');
// Conditionally enable access to env
return enableEnv ? formattedFilter: `def env: {}; {} as $ENV | ${formattedFilter}`;
return enableEnv ? formattedFilter : `def env: {}; {} as $ENV | ${formattedFilter}`;
}
const exec = (object, filter, {enableEnv = false, throwOnError = false} = {}) => {
try {
Expand Down
18 changes: 9 additions & 9 deletions lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ const renderRecursively = (inputJson, template, execOptions = {}) => {
}
if (typeof template === 'object' && template !== null) {
return Object.fromEntries(
Object.entries(template).flatMap(([key, value]) => {
const evaluatedKey = renderRecursively(inputJson, key, execOptions);
if (!['undefined', 'string'].includes(typeof evaluatedKey) && evaluatedKey !== null) {
throw new Error(
`Evaluated object key should be undefined, null or string. Original key: ${key}, evaluated to: ${JSON.stringify(evaluatedKey)}`,
);
}
return evaluatedKey ? [[evaluatedKey, renderRecursively(inputJson, value, execOptions)]] : [];
}),
Object.entries(template).flatMap(([key, value]) => {
const evaluatedKey = renderRecursively(inputJson, key, execOptions);
if (!['undefined', 'string'].includes(typeof evaluatedKey) && evaluatedKey !== null) {
throw new Error(
`Evaluated object key should be undefined, null or string. Original key: ${key}, evaluated to: ${JSON.stringify(evaluatedKey)}`,
);
}
return evaluatedKey ? [[evaluatedKey, renderRecursively(inputJson, value, execOptions)]] : [];
}),
);
}

Expand Down

0 comments on commit 68d9bbf

Please sign in to comment.