function applySchemaTypeTransforms(self, json) {
  const schema = self.$__schema;
  const paths = Object.keys(schema.paths || {});
  const cur = self._doc;

  if (!cur) {
    return json;
  }

  for (const path of paths) {
    const schematype = schema.paths[path];
    const topLevelTransformFunction = schematype.options.transform ?? schematype.constructor?.defaultOptions?.transform;
    const embeddedSchemaTypeTransformFunction = schematype.$embeddedSchemaType?.options?.transform
      ?? schematype.$embeddedSchemaType?.constructor?.defaultOptions?.transform;
    if (typeof topLevelTransformFunction === 'function') {
      const val = self.$get(path);
      if (val === undefined) {
        continue;
      }
      const transformedValue = topLevelTransformFunction.call(self, val);
      throwErrorIfPromise(path, transformedValue);
      utils.setValue(path, transformedValue, json);
    } else if (typeof embeddedSchemaTypeTransformFunction === 'function') {
      const val = self.$get(path);
      if (val === undefined) {
        continue;
      }
      const vals = [].concat(val);
      for (let i = 0; i < vals.length; ++i) {
        const transformedValue = embeddedSchemaTypeTransformFunction.call(self, vals[i]);
        vals[i] = transformedValue;
        throwErrorIfPromise(path, transformedValue);
      }

      json[path] = vals;
    }
  }

  return json;
}
Applies schema type transforms to `json`.

@param {Document} self
@param {Object} json
@return {Object} `json`
@api private