| 12345678910111213141516171819202122232425262728293031323334353637 |
- import type ApiResource from '~/models/ApiResource'
- /**
- * Decorates an ApiResource's property to signal it as a field that is provided
- * as an IRI or an array of IRI by the API
- *
- * If the property is decorated, the HydraNormalizer will parse the IRI when de-normalizing
- * to get the id(s), then re-encode it as IRI(s) when re-normalizing.
- */
- export function IriEncoded(apiResource: typeof ApiResource): PropertyDecorator {
- // We have to comply with the PropertyDecorator return type
- // eslint-disable-next-line @typescript-eslint/ban-types
- return (target: object, propertyKey: string | symbol) => {
- // @ts-expect-error The object is an ApiResource
- const self = target.$self()
- self.addIriEncodedField(propertyKey as string, apiResource)
- }
- }
- /**
- * Decorates an ApiResource's property to signal it as a field that is provided
- * as an unique identifier by the API
- *
- * If the property is decorated, the HydraNormalizer will get the item[idField] value to hydrate
- * the id property of the instance
- */
- export function IdField(): PropertyDecorator {
- // We have to comply with the PropertyDecorator return type
- // eslint-disable-next-line @typescript-eslint/ban-types
- return (target: object, propertyKey: string | symbol) => {
- // @ts-expect-error The object is an ApiResource
- const self = target.$self()
- self.setIdField(propertyKey as string)
- }
- }
|