import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { ODataApi } from '../../api' ; import { ODataCollection , ODataModel } from '../../models' ; import { ODataCallable } from '../../schema/callable' ; import { PathSegmentNames } from '../../types' ; import { ODataPathSegments } from '../path' ; import { ODataQueryOptions } from '../query' ; import { ODataResource } from '../resource' ; import { ODataEntities , ODataEntity , ODataProperty } from '../responses' ; import { ODataEntitiesOptions , ODataEntityOptions , ODataNoneOptions , ODataOptions , ODataPropertyOptions , } from './options' ; export class ODataActionResource < P , R > extends ODataResource < R > { static factory < P , R > ( api , { path , schema , segments , query , } ) { segments = segments || new ODataPathSegments ( ) ; path = schema !== undefined ? schema . path ( ) : path ; if ( path === undefined ) throw new Error ( `ODataActionResource: path is required` ) ; const segment = segments . add ( PathSegmentNames . action , path ) ; if ( schema !== undefined ) segment . type ( schema . type ( ) ) ; return new ODataActionResource < P , R > ( api , { segments , query , schema , } ) ; } static fromResource < P , R > ( resource , path ) { const baseType = resource . type ( ) ; const actionSchema = resource . api . findCallableForType < R > ( path , baseType ) ; const bindingType = actionSchema ?. binding ( ) ?. type ; const action = ODataActionResource . factory < P , R > ( resource . api , { path , schema : actionSchema , segments : resource . cloneSegments ( ) , } ) ; if ( bindingType !== undefined && bindingType !== baseType ) { let entitySet = resource . api . findEntitySetForType ( bindingType ) ; if ( entitySet !== undefined ) { action . segment ( ( s ) => s . entitySet ( ) . path ( entitySet ! . name ) ) ; } } return action ; } override returnType ( ) { return this . schema instanceof ODataCallable ? this . schema . parser . return ?. type : undefined ; } protected override post ( params , options ? ) { return super . post ( params , options ) ; } param params param options call ( params , options ? ) ; call ( params , options ? ) ; call ( params , options ? ) ; call ( params , options ? ) ; call ( params , options = { } ) { return this . clone < ODataActionResource < P , R > > ( ) . post ( params , options ) ; } param params param options returns callProperty ( params , options = { } ) { return this . call ( params , { responseType : 'property' , ... options } ) . pipe ( map ( ( { property } ) => property ) ) ; } param params param options returns callEntity ( params , options = { } ) { return this . call ( params , { responseType : 'entity' , ... options } ) . pipe ( map ( ( { entity } ) => entity ) ) ; } param params param options returns callModel < M extends ODataModel < R > > ( params , options = { } ) { return this . call ( params , { responseType : 'entity' , ... options } ) . pipe ( map ( ( { entity , annots } ) => entity ? this . asModel < M > ( entity , { annots , reset : true } ) : null ) ) ; } param params param options returns callEntities ( params , options = { } ) { return this . call ( params , { responseType : 'entities' , ... options } ) . pipe ( map ( ( { entities } ) => entities ) ) ; } param params param options returns callCollection < M extends ODataModel < R > , C extends ODataCollection < R , M > > ( params , options = { } ) { return this . call ( params , { responseType : 'entities' , ... options } ) . pipe ( map ( ( { entities , annots } ) => entities ? this . asCollection < M , C > ( entities , { annots , reset : true } ) : null ) ) ; } }