( objs: any[], mustGetObjId: (obj: any) => string, getObjId: GetObjID | null, collector: Collector, containerState: any )
| 936 | return Object.keys(obj).length === 0; |
| 937 | }; |
| 938 | function serializeObjects( |
| 939 | objs: any[], |
| 940 | mustGetObjId: (obj: any) => string, |
| 941 | getObjId: GetObjID | null, |
| 942 | collector: Collector, |
| 943 | containerState: any |
| 944 | ) { |
| 945 | return objs.map((obj) => { |
| 946 | if (obj === null) { |
| 947 | return null; |
| 948 | } |
| 949 | const typeObj = typeof obj; |
| 950 | switch (typeObj) { |
| 951 | case 'undefined': |
| 952 | return UNDEFINED_PREFIX; |
| 953 | case 'number': |
| 954 | if (!Number.isFinite(obj)) { |
| 955 | break; |
| 956 | } |
| 957 | return obj; |
| 958 | case 'string': |
| 959 | if ((obj as string).charCodeAt(0) < 32 /* space */) { |
| 960 | // if strings starts with a special character let the string serializer handle it |
| 961 | // to deal with escape sequences. |
| 962 | break; |
| 963 | } else { |
| 964 | // Fast path of just serializing the string. |
| 965 | return obj; |
| 966 | } |
| 967 | case 'boolean': |
| 968 | return obj; |
| 969 | } |
| 970 | const value = serializeValue(obj, mustGetObjId, collector, containerState); |
| 971 | if (value !== undefined) { |
| 972 | return value; |
| 973 | } |
| 974 | if (typeObj === 'object') { |
| 975 | if (isArray(obj)) { |
| 976 | return obj.map(mustGetObjId); |
| 977 | } |
| 978 | if (isSerializableObject(obj)) { |
| 979 | const output: Record<string, any> = {}; |
| 980 | for (const key in obj) { |
| 981 | if (getObjId) { |
| 982 | const id = getObjId(obj[key]); |
| 983 | if (id !== null) { |
| 984 | output[key] = id; |
| 985 | } |
| 986 | } else { |
| 987 | output[key] = mustGetObjId(obj[key]); |
| 988 | } |
| 989 | } |
| 990 | return output; |
| 991 | } |
| 992 | } |
| 993 | throw qError(QError_verifySerializable, obj); |
| 994 | }); |
| 995 | } |
no test coverage detected
searching dependent graphs…