Skip to content

feat: support virtual field #158

@coratgerl

Description

@coratgerl

Info: Estimated number of lines 200 - 250 (with tests)

In the file Schema.ts, we have defined all elements of the schema, such as the supported types (Email, Phone, String, Number, Boolean, etc.).

We should add support for virtual fields. This would involve a field in which a function is defined, and this function would be called each time in a hook.

  • The virtual field (the name could be Virtual in the Schema file) should allow defining a function that would be executed ONLY on read operation of an object using a Wabe hook (there are many examples in the src/hooks directory). During read operations, it should compute and return the value of the virtual field. In the callback of the function you should have access to the current object.

It is crucial not to store these fields in the database. Therefore, we should add checks in the database controller to ignore virtual fields during save operations.

The proposed structure is:

{
    name: 'User',
    description: 'User class',
    fields: {
      email: {
        type: 'Email',
        required: true,
      },
      fullName: {
          type: 'Virtual',
          callback: (user) => `${user.firstName} ${user.lastName}`,
      }
    },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions