@@ -27,6 +27,7 @@ import {
2727 isCellLink ,
2828 isDoc ,
2929} from "@commontools/runner" ;
30+ import { isObject , isRecord } from "@commontools/utils/types" ;
3031
3132/**
3233 * Traverse a value, _not_ entering cells
@@ -52,8 +53,7 @@ export function traverseValue(
5253 ( ! isOpaqueRef ( value ) &&
5354 ! canBeOpaqueRef ( value ) &&
5455 ! isShadowRef ( value ) &&
55- typeof value === "object" &&
56- value !== null ) ||
56+ isRecord ( value ) ) ||
5757 isRecipe ( value )
5858 ) {
5959 return staticWrap (
@@ -105,7 +105,7 @@ export function getValueAtPath(obj: any, path: PropertyKey[]): any {
105105export function hasValueAtPath ( obj : any , path : PropertyKey [ ] ) : boolean {
106106 let current = obj ;
107107 for ( const key of path ) {
108- if ( ! current || typeof current !== "object" || ! ( key in current ) ) {
108+ if ( ! isRecord ( current ) || ! ( key in current ) ) {
109109 return false ;
110110 }
111111 current = current [ key ] ;
@@ -115,7 +115,7 @@ export function hasValueAtPath(obj: any, path: PropertyKey[]): boolean {
115115
116116export const deepEqual = ( a : any , b : any ) : boolean => {
117117 if ( a === b ) return true ;
118- if ( a && b && typeof a === "object" && typeof b === "object" ) {
118+ if ( isRecord ( a ) && isRecord ( b ) ) {
119119 if ( a . constructor !== b . constructor ) return false ;
120120 const keysA = Object . keys ( a ) ;
121121 const keysB = Object . keys ( b ) ;
@@ -211,7 +211,7 @@ export function toJSONWithAliases(
211211 ) ;
212212 }
213213
214- if ( typeof value === "object" || isRecipe ( value ) ) {
214+ if ( isRecord ( value ) || isRecipe ( value ) ) {
215215 const result : any = { } ;
216216 let hasValue = false ;
217217 for ( const key in value as any ) {
@@ -278,11 +278,11 @@ export function createJsonSchema(
278278 schema . items = { } ;
279279 } else {
280280 const first = value [ 0 ] ;
281- if ( first && typeof first === "object" && ! Array . isArray ( first ) ) {
281+ if ( isObject ( first ) ) {
282282 const properties : { [ key : string ] : any } = { } ;
283283 for ( let i = 0 ; i < value . length ; i ++ ) {
284284 const item = value ?. [ i ] ;
285- if ( typeof item === "object" && item !== null ) {
285+ if ( isRecord ( item ) ) {
286286 Object . keys ( item ) . forEach ( ( key ) => {
287287 if ( ! ( key in properties ) ) {
288288 properties [ key ] = analyzeType (
@@ -426,7 +426,7 @@ function attachCfcToOutputs<T, R>(
426426 const cfcSchema : JSONSchema = { ...outputSchema , ifc } ;
427427 ( outputs as OpaqueRef < T > ) . setSchema ( cfcSchema ) ;
428428 return ;
429- } else if ( typeof outputs === "object" && outputs !== null ) {
429+ } else if ( isRecord ( outputs ) ) {
430430 // Descend into objects and arrays
431431 for ( const [ key , value ] of Object . entries ( outputs ) ) {
432432 attachCfcToOutputs ( value , cfc , lubClassification ) ;
0 commit comments