Accessing documents retrieved from a server-role scoped UDF

This is the end of a server-role scoped UDF

let boundsensorMappingSet = MimamoriSensorShare
    .byBoundCompanyProperty(managementCompany, Property.byId(payload.propertyId))
    .map(
      share=>{
        let sensorMapping = share!.sensor! {
          sensorId,
          roomTitle
        }

        let notificationSettings = share!.notificationSettings! {
          id,
          enableMotionNotifications,
          sendNotifications,
          notificationAddresses {
            emailId,
            email
          }
        }

        {
          sensorId: sensorMapping!.sensorId!,
          roomTitle: sensorMapping!.roomTitle!,
          sensorShares: [],
          notificationSettings: share!.notificationSettings!
        }
      }
    )

  boundsensorMappingSet.paginate(1000).data

Here is the result:

[
    {
        "sensorId": "sigfox-FAKEID2",
        "roomTitle": "101",
        "sensorShares": [],
        "notificationSettings": {
            "@ref": {
                "id": "380868249832653312",
                "coll": {
                    "@mod": "MimamoriSensorNotificationSettings"
                },
                "exists": false,
                "cause": "permission denied"
            }
        }
    }
]

Why can’t I access notificationSettings and what’s the best way to accomplish passing this document outside of a server-role scoped UDF?

In v10 values are lazy as long as possible, so pure references are materialized at the last moment. The UDF is returning objects with references in them, not of materialized documents.

You can either provide the caller with permission to read the document, or you can make sure to convert all of the documents into objects from the UDF.

It looks like the problem reference is nested in the resulting objects. You should be able to add a projection to those to convert them to an object rather than return a document reference.

        // ...

        {
          sensorId: sensorMapping!.sensorId!,
          roomTitle: sensorMapping!.roomTitle!,
          sensorShares: [],
          notificationSettings: share!.notificationSettings! {
            id,
            /* other fields ... */
          }
        }
      }
    )

  boundsensorMappingSet.paginate(1000).data