decorators.ts 641 B

1234567891011121314151617181920
  1. import ApiResource from "~/models/ApiResource";
  2. /**
  3. * Decorates an ApiResource's property to signal it as a field that is provided
  4. * as an IRI or an array of IRI by the API
  5. *
  6. * If the property is decorated, the HydraNormalizer will parse the IRI when de-normalizing
  7. * to get the id(s), then re-encode it as IRI(s) when re-normalizing.
  8. */
  9. export function IriEncoded (
  10. apiResource: typeof ApiResource
  11. ): PropertyDecorator {
  12. return (target: Object, propertyKey: string | symbol) => {
  13. //@ts-ignore
  14. const self = target.$self()
  15. //@ts-ignore
  16. self.addIriEncodedField(propertyKey, apiResource)
  17. }
  18. }