import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { ODataApi } from '../../api' ; import { $ID , $REF , ODATA_ID } from '../../constants' ; import { PathSegmentNames , QueryOptionNames } from '../../types' ; import { ODataPathSegments } from '../path' ; import { ODataQueryOptions } from '../query' ; import { ODataResource } from '../resource' ; import { ODataEntities , ODataEntity } from '../responses/types' ; import { ODataEntityResource } from './entity' ; import { ODataEntitiesOptions , ODataEntityOptions , ODataOptions , } from './options' ; export class ODataReferenceResource < T > extends ODataResource < T > { static factory < P > ( api , { segments , query , } ) { segments . add ( PathSegmentNames . reference , $REF ) ; query ?. clear ( ) ; return new ODataReferenceResource < P > ( api , { segments , query } ) ; } protected override post ( target , options ? ) { return super . post ( { [ ODATA_ID ] : target . endpointUrl ( false ) } , options ) ; } protected override put ( target , options ? ) { return super . put ( { [ ODATA_ID ] : target . endpointUrl ( false ) } , options ) ; } protected override delete ( { etag , target , ... options } = { } ) { if ( target ) { options . params = { [ $ID ] : target . endpointUrl ( false ) } ; } return super . delete ( { etag , ... options } ) ; } param target param options returns add ( target , options ? ) { return this . post ( target , options ) ; } param target param options returns remove ( target ? , options ? ) { return this . delete ( { target , ... options } ) ; } param target param options returns set ( target , options ? ) { return this . put ( target , options ) ; } param options returns unset ( options ? ) { return this . delete ( options ) ; } param options return fetch ( options ? ) ; fetch ( options ? ) ; fetch ( options = { } ) { return this . get ( options ) ; } param options returns fetchEntity ( options = { } ) { return this . fetch ( { responseType : 'entity' , ... options } ) . pipe ( map ( ( { entity } ) => entity ) ) ; } param options returns fetchEntities ( options = { } ) { return this . fetch ( { responseType : 'entities' , ... options } ) . pipe ( map ( ( { entities } ) => entities ) ) ; } }