UNPKG

typed-ocpp

Version:

A library for type-aware parsing, serialization and validation of OCPP 1.6, OCPP 2.0 and OCPP 2.1 messages

73 lines (72 loc) 5.93 kB
import type { Call } from './call.js'; import type { BaseMessage } from './utils.js'; import type { WithErrorsArr, ValidateFn } from '../common/utils.js'; import { Action, MessageType } from './utils.js'; import * as types from './types.js'; export type UncheckedCallResult<P extends {} = {}> = BaseMessage<MessageType.CALLRESULT, [payload: P]>; export type AuthorizeCallResult = UncheckedCallResult<types.AuthorizeResponse>; export type BootNotificationCallResult = UncheckedCallResult<types.BootNotificationResponse>; export type CancelReservationCallResult = UncheckedCallResult<types.CancelReservationResponse>; export type ChangeAvailabilityCallResult = UncheckedCallResult<types.ChangeAvailabilityResponse>; export type ChangeConfigurationCallResult = UncheckedCallResult<types.ChangeConfigurationResponse>; export type ClearCacheCallResult = UncheckedCallResult<types.ClearCacheResponse>; export type ClearChargingProfileCallResult = UncheckedCallResult<types.ClearChargingProfileResponse>; export type DataTransferCallResult = UncheckedCallResult<types.DataTransferResponse>; export type DiagnosticsStatusNotificationCallResult = UncheckedCallResult<types.DiagnosticsStatusNotificationResponse>; export type FirmwareStatusNotificationCallResult = UncheckedCallResult<types.FirmwareStatusNotificationResponse>; export type GetCompositeScheduleCallResult = UncheckedCallResult<types.GetCompositeScheduleResponse>; export type GetConfigurationCallResult = UncheckedCallResult<types.GetConfigurationResponse>; export type GetDiagnosticsCallResult = UncheckedCallResult<types.GetDiagnosticsResponse>; export type GetLocalListVersionCallResult = UncheckedCallResult<types.GetLocalListVersionResponse>; export type HeartbeatCallResult = UncheckedCallResult<types.HeartbeatResponse>; export type MeterValuesCallResult = UncheckedCallResult<types.MeterValuesResponse>; export type RemoteStartTransactionCallResult = UncheckedCallResult<types.RemoteStartTransactionResponse>; export type RemoteStopTransactionCallResult = UncheckedCallResult<types.RemoteStopTransactionResponse>; export type ReserveNowCallResult = UncheckedCallResult<types.ReserveNowResponse>; export type ResetCallResult = UncheckedCallResult<types.ResetResponse>; export type SendLocalListCallResult = UncheckedCallResult<types.SendLocalListResponse>; export type SetChargingProfileCallResult = UncheckedCallResult<types.SetChargingProfileResponse>; export type StartTransactionCallResult = UncheckedCallResult<types.StartTransactionResponse>; export type StatusNotificationCallResult = UncheckedCallResult<types.StatusNotificationResponse>; export type StopTransactionCallResult = UncheckedCallResult<types.StopTransactionResponse>; export type TriggerMessageCallResult = UncheckedCallResult<types.TriggerMessageResponse>; export type UnlockConnectorCallResult = UncheckedCallResult<types.UnlockConnectorResponse>; export type UpdateFirmwareCallResult = UncheckedCallResult<types.UpdateFirmwareResponse>; export type CallResult = AuthorizeCallResult | BootNotificationCallResult | CancelReservationCallResult | ChangeAvailabilityCallResult | ChangeConfigurationCallResult | ClearCacheCallResult | ClearChargingProfileCallResult | DataTransferCallResult | DiagnosticsStatusNotificationCallResult | FirmwareStatusNotificationCallResult | GetCompositeScheduleCallResult | GetConfigurationCallResult | GetDiagnosticsCallResult | GetLocalListVersionCallResult | HeartbeatCallResult | MeterValuesCallResult | RemoteStartTransactionCallResult | RemoteStopTransactionCallResult | ReserveNowCallResult | ResetCallResult | SendLocalListCallResult | SetChargingProfileCallResult | StartTransactionCallResult | StatusNotificationCallResult | StopTransactionCallResult | TriggerMessageCallResult | UnlockConnectorCallResult | UpdateFirmwareCallResult; export declare const validateCallResult: ValidateFn<any, UncheckedCallResult>; export interface CallResultTypesByAction extends Record<Action, CallResult> { [Action.Authorize]: AuthorizeCallResult; [Action.BootNotification]: BootNotificationCallResult; [Action.CancelReservation]: CancelReservationCallResult; [Action.ChangeAvailability]: ChangeAvailabilityCallResult; [Action.ChangeConfiguration]: ChangeConfigurationCallResult; [Action.ClearCache]: ClearCacheCallResult; [Action.ClearChargingProfile]: ClearChargingProfileCallResult; [Action.DataTransfer]: DataTransferCallResult; [Action.DiagnosticsStatusNotification]: DiagnosticsStatusNotificationCallResult; [Action.FirmwareStatusNotification]: FirmwareStatusNotificationCallResult; [Action.GetCompositeSchedule]: GetCompositeScheduleCallResult; [Action.GetConfiguration]: GetConfigurationCallResult; [Action.GetDiagnostics]: GetDiagnosticsCallResult; [Action.GetLocalListVersion]: GetLocalListVersionCallResult; [Action.Heartbeat]: HeartbeatCallResult; [Action.MeterValues]: MeterValuesCallResult; [Action.RemoteStartTransaction]: RemoteStartTransactionCallResult; [Action.RemoteStopTransaction]: RemoteStopTransactionCallResult; [Action.ReserveNow]: ReserveNowCallResult; [Action.Reset]: ResetCallResult; [Action.SendLocalList]: SendLocalListCallResult; [Action.SetChargingProfile]: SetChargingProfileCallResult; [Action.StartTransaction]: StartTransactionCallResult; [Action.StatusNotification]: StatusNotificationCallResult; [Action.StopTransaction]: StopTransactionCallResult; [Action.TriggerMessage]: TriggerMessageCallResult; [Action.UnlockConnector]: UnlockConnectorCallResult; [Action.UpdateFirmware]: UpdateFirmwareCallResult; } export type CheckedCallResult<C extends Call> = CallResultTypesByAction[C[2]]; export interface CheckCallResultFn extends WithErrorsArr { <C extends Call>(value: CheckedCallResult<Call>, call: C): value is CheckedCallResult<C>; errors: string[]; } export declare const checkCallResult: CheckCallResultFn;