Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime): object check #1684

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions runtimes/nodejs/src/handler/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
FunctionDebugExecutor,
} from '../support/engine'
import pako from 'pako'
import { base64ToUint8Array, uint8ArrayToBase64 } from '../support/utils'
import { base64ToUint8Array, isObject, uint8ArrayToBase64 } from '../support/utils'

export async function handleInvokeFunction(req: IRequest, res: Response) {
const name = req.params?.name
Expand Down Expand Up @@ -90,7 +90,7 @@ async function invokeFunction(

// reject request if interceptor return false
if (
typeof result.data === 'object' &&
isObject(result.data) &&
result.data.__type__ === '__interceptor__' &&
result.data.__res__ == false
) {
Expand Down Expand Up @@ -200,7 +200,7 @@ async function invokeDebug(

// reject request if interceptor return false
if (
typeof result.data === 'object' &&
isObject(result.data) &&
result.data.__type__ === '__interceptor__' &&
result.data.__res__ == false
) {
Expand Down
3 changes: 2 additions & 1 deletion runtimes/nodejs/src/support/engine/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as util from 'util'
import chalk from 'chalk'
import { padStart } from 'lodash'
import Config from '../../config'
import { isObject } from '../utils'

enum LogLevel {
DEBUG = 'DEBUG',
Expand Down Expand Up @@ -31,7 +32,7 @@ export class Console {
let content = params
.map((param) => {
if (typeof param === 'string') return this._colorize(level, param)
if (typeof param === 'object') {
if (isObject(param)) {
return this._colorize(
level,
util.inspect(param, { depth: Config.LOG_DEPTH, colors: true }),
Expand Down
13 changes: 11 additions & 2 deletions runtimes/nodejs/src/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function deepFreeze(object: Object) {
for (const name of propNames) {
const value = object[name]

if (value && typeof value === 'object') {
if (isObject(value)) {
deepFreeze(value)
}
}
Expand Down Expand Up @@ -114,4 +114,13 @@ export function uint8ArrayToBase64(buffer: Uint8Array) {
export function base64ToUint8Array(base64: string) {
const buffer = Buffer.from(base64, 'base64')
return new Uint8Array(buffer)
}
}

/**
* is object.
* @param obj
* @returns
*/
export function isObject(obj: unknown): obj is Object {
return obj !== null && typeof obj === 'object'
}