Jelajahi Sumber

improve objectid-transformer

Yuki Takei 3 tahun lalu
induk
melakukan
169c9b4221
1 mengubah file dengan 4 tambahan dan 5 penghapusan
  1. 4 5
      packages/app/src/pages/utils/objectid-transformer.ts

+ 4 - 5
packages/app/src/pages/utils/objectid-transformer.ts

@@ -1,4 +1,5 @@
 // !!! Do NOT import 'mongoose' to reduce bundle size !!!
+import { objectIdUtils } from '@growi/core';
 import ObjectId from 'bson-objectid';
 import superjson from 'superjson';
 
@@ -9,11 +10,9 @@ export const registerTransformerForObjectId = (): void => {
         if (v == null) {
           return false;
         }
-        if (typeof v === 'string') {
-          return ObjectId.isValid(v);
-        }
-        if (typeof v.toHexString === 'function') {
-          return ObjectId.isValid(v.toHexString());
+        // Only evaluate types for string and ObjectId
+        if (typeof v === 'string' || typeof v.toHexString === 'function') {
+          return objectIdUtils.isValidObjectId(v);
         }
         return false;
       },