Skip to content

Add transform option to Ad4mModel properties#580

Merged
lucksus merged 2 commits intoad4m-model-renamingfrom
feature/model-property-transform
Mar 24, 2025
Merged

Add transform option to Ad4mModel properties#580
lucksus merged 2 commits intoad4m-model-renamingfrom
feature/model-property-transform

Conversation

@lucksus
Copy link
Copy Markdown
Member

@lucksus lucksus commented Mar 21, 2025

Add transform option to property decorators

This PR adds a new transform option to property decorators in Ad4mModel, allowing property values to be transformed after they are retrieved from the perspective. This feature is particularly useful for converting raw data into more usable formats or applying custom transformations to property values.

Features

  • Added transform option to PropertyOptions interface
  • Transform functions are applied after value resolution in assignValuesToInstance
  • Works with all property decorators (@Property, @Optional, @ReadOnly)
  • Fully documented with examples
  • Includes comprehensive test coverage

Example Usage

class ImagePost extends Ad4mModel {
  @Property({
    through: "image://data",
    resolveLanguage: "literal",
    transform: (data) => data ? data:image/png;base64,${data.data_base64} : undefined,
  })
  image: string = "";
}

@lucksus lucksus changed the base branch from dev to ad4m-model-renaming March 21, 2025 15:21
@lucksus lucksus merged commit 2fc6fdd into ad4m-model-renaming Mar 24, 2025
2 checks passed
@lucksus lucksus deleted the feature/model-property-transform branch August 22, 2025 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant