Skip to content

Commit

Permalink
chore(endpoint): add spacing to debug output (#4108)
Browse files Browse the repository at this point in the history
* chore(endpoint): add spacing to debug output

* fix(logging): check for existence of log method
  • Loading branch information
kuhe authored Oct 27, 2022
1 parent d600213 commit 15ebdda
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions packages/util-endpoints/src/debug/toDebugString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ export function toDebugString(input: FunctionObject): string;
export function toDebugString(input: FunctionReturn): string;
export function toDebugString(input: EndpointObject): string;
export function toDebugString(input: any): string {
if (typeof input !== 'object' || input == null) {
if (typeof input !== "object" || input == null) {
return input;
}

if ('ref' in input) {
return `$${toDebugString(input.ref)}`
if ("ref" in input) {
return `$${toDebugString(input.ref)}`;
}

if ('fn' in input) {
return `${input.fn}(${(input.argv || []).map(toDebugString)})`;
if ("fn" in input) {
return `${input.fn}(${(input.argv || []).map(toDebugString).join(", ")})`;
}

return JSON.stringify(input, null, 2);
}
}
4 changes: 2 additions & 2 deletions packages/util-endpoints/src/resolveEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const resolveEndpoint = (ruleSetObject: RuleSetObject, options: EndpointR
const { endpointParams, logger } = options;
const { parameters, rules } = ruleSetObject;

options.logger?.debug(debugId, `Initial EndpointParams: ${toDebugString(endpointParams)}`);
options.logger?.debug?.(debugId, `Initial EndpointParams: ${toDebugString(endpointParams)}`);

// @ts-ignore Type 'undefined' is not assignable to type 'string | boolean' (2322)
const paramsWithDefault: [string, string | boolean][] = Object.entries(parameters)
Expand Down Expand Up @@ -48,7 +48,7 @@ export const resolveEndpoint = (ruleSetObject: RuleSetObject, options: EndpointR
}
}

options.logger?.debug(debugId, `Resolved endpoint: ${toDebugString(endpoint)}`);
options.logger?.debug?.(debugId, `Resolved endpoint: ${toDebugString(endpoint)}`);

return endpoint;
};
2 changes: 1 addition & 1 deletion packages/util-endpoints/src/utils/evaluateCondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const evaluateCondition = ({ assign, ...fnArgs }: ConditionObject, option
}
const value = callFunction(fnArgs, options);

options.logger?.debug(debugId, `evaluateCondition: ${toDebugString(fnArgs)} = ${toDebugString(value)}`);
options.logger?.debug?.(debugId, `evaluateCondition: ${toDebugString(fnArgs)} = ${toDebugString(value)}`);

return {
result: value === "" ? true : !!value,
Expand Down
2 changes: 1 addition & 1 deletion packages/util-endpoints/src/utils/evaluateConditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const evaluateConditions = (conditions: ConditionObject[] = [], options:

if (toAssign) {
conditionsReferenceRecord[toAssign.name] = toAssign.value;
options.logger?.debug(debugId, `assign: ${toAssign.name} := ${toDebugString(toAssign.value)}`);
options.logger?.debug?.(debugId, `assign: ${toAssign.name} := ${toDebugString(toAssign.value)}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/util-endpoints/src/utils/evaluateEndpointRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const evaluateEndpointRule = (

const { url, properties, headers } = endpoint;

options.logger?.debug(debugId, `Resolving endpoint from template: ${toDebugString(endpoint)}`);
options.logger?.debug?.(debugId, `Resolving endpoint from template: ${toDebugString(endpoint)}`);

return {
...(headers != undefined && {
Expand Down

0 comments on commit 15ebdda

Please sign in to comment.