rollthecloudinc / quell

Climate aware CMS breaking web apps free from carbon emissions.
https://demo.carbonfreed.app/pages/create-panel-page
GNU General Public License v3.0
14 stars 1 forks source link

Nesting Crud Adaptors #107

Open windbeneathyourwings opened 2 years ago

windbeneathyourwings commented 2 years ago

The Druid crud extension for NgRx metadata currently accepts the below format.

export const entityMetadata: CrudEntityMetadataMap = {
  PanelPageForm: {
    crud: {
      idb_keyval: {
        params: {
          prefix: 'panelpageform__'
        }
      }
    }
  }
};

The entity will be stored in idb using natural form.

However, some entities will need to be stored differently from their entity form. For example, submissions from a panel page using a form will be stored using a much more readable conversion of the panel page form.

The panel page form will break down into an object literal using panel and form field names to derive a much simpler, easier to read object.

This presents a new challenge. Before saving the entity it needs to undergo a transformation process.

After evaluating several options the below approach has determined to be the most appropriate. Not only does the following approach make it possible to achieve the above goal but it also opens the door to many other possibilities.

Druid crud adaptor will support nesting adaptors.

export const entityMetadata: CrudEntityMetadataMap = {
  PanelPageForm: {
    crud: {
      serialize: {
        params: {
          name: 'form'
        },
        plugins: {
          idb_keyval: {
            params: {
              prefix: "panelpageform__'"
            }
          }
        }
      }
    }
  }
};

The intention defined above is to use the output value of the serialize crud adaptor as input to the nested idb_keyval crud adaptor.

The only issue with this is that serialization will be different between read and writes. For a read operation there would need to be an inverse serialization process that takes effect. This is where plugins might need to be associated with a specific operation.

export const entityMetadata: CrudEntityMetadataMap = {
  PanelPageForm: {
    crud: {
      serialize: {
        ops: ['add', 'upsert', 'update'],
        params: {
          name: 'form'
        },
        plugins: {
          idb_keyval: {
            params: {
              prefix: "panelpageform__'"
            }
          }
        }
      }
    }
  }
};

If operations need to share crud adaptors but require slightly different configuration they can have a generic key name with the object defining the plugin instead of the key being the plugin name.

export const entityMetadata: CrudEntityMetadataMap = {
  PanelPageForm: {
    crud: {
      serialize1: {
        plugin: 'serialize',
        ops: ['add', 'upsert', 'update'],
        params: {
          name: 'form'
        },
        plugins: {
          idb_keyval: {
            params: {
              prefix: "panelpageform__'"
            }
          }
        }
      }
    }
  }
};
windbeneathyourwings commented 2 years ago

The crud data service has been enhanced with nested plugin capabilities. The PanelPageForm entity metadata configuration inside pages module uses this new feature to serialize the form and save too idb. The pipeline still needs some error handling. Also need to implement operational filters (ops).