import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { ODataApi } from '../../api' ; import { ODataModel } from '../../models' ; import { ODataStructuredType } from '../../schema' ; import { PathSegmentNames , QueryOptionNames } from '../../types' ; import { ODataPathSegments } from '../path' ; import { ODataQueryOptions } from '../query' ; import { ODataResource } from '../resource' ; import { ODataEntity } from '../responses' ; import { ODataActionResource } from './action' ; import { ODataFunctionResource } from './function' ; import { ODataNavigationPropertyResource } from './navigation-property' ; import { ODataOptions } from './options' ; import { ODataPropertyResource } from './property' ; export class ODataSingletonResource < T > extends ODataResource < T > { static factory < S > ( api , { path , schema , query , } ) { const segments = new ODataPathSegments ( ) ; const segment = segments . add ( PathSegmentNames . singleton , path ) ; if ( schema !== undefined ) segment . type ( schema . type ( ) ) ; return new ODataSingletonResource < S > ( api , { segments , query , schema } ) ; } key ( value ) { const singleton = this . clone < ODataSingletonResource < T > > ( ) ; var key = this . resolveKey ( value ) ; if ( key !== undefined ) singleton . segment ( ( s ) => s . singleton ( ) . key ( key ) ) ; return singleton ; } keys ( values ) { const singleton = this . clone < ODataSingletonResource < T > > ( ) ; const types = this . pathSegments . types ( { key : true } ) ; const keys = values . map ( ( value , index ) => ODataResource . resolveKey ( value , this . api . findStructuredTypeForType < T > ( types [ index ] ) ) ) ; singleton . segment ( ( s ) => s . keys ( keys ) ) ; return singleton ; } navigationProperty < N > ( path ) { return ODataNavigationPropertyResource . fromResource < N > ( this , path ) ; } property < P > ( path ) { return ODataPropertyResource . fromResource < P > ( this , path ) ; } action < P , R > ( path ) { return ODataActionResource . fromResource < P , R > ( this , path ) ; } function < P , R > ( path ) { return ODataFunctionResource . fromResource < P , R > ( this , path ) ; } protected override post ( attrs , options = { } ) { return super . post ( attrs , { responseType : 'entity' , ... options } ) ; } protected override put ( attrs , options = { } ) { return super . put ( attrs , { responseType : 'entity' , ... options } ) ; } protected override patch ( attrs , options = { } ) { return super . patch ( attrs , { responseType : 'entity' , ... options } ) ; } protected override delete ( options = { } ) { return super . delete ( { responseType : 'entity' , ... options } ) ; } protected override get ( options = { } ) { return super . get ( { responseType : 'entity' , ... options } ) ; } param attrs param options returns create ( attrs , options ? ) { return this . post ( attrs , options ) ; } param attrs param options returns update ( attrs , options ? ) { return this . put ( attrs , options ) ; } param attrs param options returns modify ( attrs , options ? ) { return this . patch ( attrs , options ) ; } param options returns destroy ( options ? ) { return this . delete ( options ) ; } param options param etag returns fetch ( options ? ) { return this . get ( options ) ; } param options param etag returns fetchEntity ( options ? ) { return this . fetch ( options ) . pipe ( map ( ( { entity } ) => entity ) ) ; } param options param etag returns fetchModel < M extends ODataModel < T > > ( options ? ) { return this . fetch ( options ) . pipe ( map ( ( { entity , annots } ) => entity ? this . asModel < M > ( entity , { annots , reset : true } ) : null ) ) ; } }