///
/// Copyright © 2016-2020 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { FunctionArg, FunctionArgType, TbEditorCompletions } from '@shared/models/ace/completion.models';
export const entityIdHref = 'EntityId';
export const entityTypeHref = 'EntityType';
export const pageDataHref = 'PageData';
export const deviceInfoHref = 'DeviceInfo';
export const deviceHref = 'Device';
export const deviceCredentialsHref = 'DeviceCredentials';
export const pageLinkArg: FunctionArg = {
name: 'pageLink',
type: 'PageLink',
description: 'Page link object used to perform paginated request.'
};
export const requestConfigArg: FunctionArg = {
name: 'config',
type: 'RequestConfig',
description: 'HTTP request configuration.',
optional: true
};
export function observableReturnType(objectType: string): FunctionArgType {
return {
type: `Observable<${objectType}>`,
description: `An Observable of ${objectType} object.`
};
}
export function observableVoid(): FunctionArgType {
return {
type: `Observable<void>`,
description: `An Observable.`
};
}
export function observableArrayReturnType(objectType: string): FunctionArgType {
return {
type: `Observable<Array<${objectType}>>`,
description: `An Observable of array of ${objectType} objects.`
};
}
export function observablePageDataReturnType(objectType: string): FunctionArgType {
return {
type: `Observable<${pageDataHref}<${objectType}>>`,
description: `An Observable of page result as a ${pageDataHref} holding array of ${objectType} objects.`
};
}
export const serviceCompletions: TbEditorCompletions = {
deviceService: {
description: 'Device Service API
' +
'See DeviceService for API reference.',
meta: 'service',
type: 'DeviceService',
children: {
getTenantDeviceInfos: {
description: 'Get tenant devices',
meta: 'function',
args: [
pageLinkArg,
{ name: 'type', type: 'string', optional: true, description: 'Device type'},
requestConfigArg
],
return: observablePageDataReturnType(deviceInfoHref)
},
getCustomerDeviceInfos: {
description: 'Get customer devices',
meta: 'function',
args: [
{ name: 'customerId', type: 'string', description: 'Id of the customer'},
pageLinkArg,
{ name: 'type', type: 'string', optional: true, description: 'Device type'},
requestConfigArg
],
return: observablePageDataReturnType(deviceInfoHref)
},
getDevice: {
description: 'Get device by id',
meta: 'function',
args: [
{ name: 'deviceId', type: 'string', description: 'Id of the device'},
requestConfigArg
],
return: observableReturnType(deviceHref)
},
getDevices: {
description: 'Get devices by ids',
meta: 'function',
args: [
{ name: 'deviceIds', type: 'Array', description: 'List of device ids'},
requestConfigArg
],
return: observableArrayReturnType(deviceHref)
},
getDeviceInfo: {
description: 'Get device info by id',
meta: 'function',
args: [
{ name: 'deviceId', type: 'string', description: 'Id of the device'},
requestConfigArg
],
return: observableReturnType(deviceInfoHref)
},
saveDevice: {
description: 'Save device',
meta: 'function',
args: [
{ name: 'device', type: deviceHref, description: 'Device object to save'},
requestConfigArg
],
return: observableReturnType(deviceHref)
},
deleteDevice: {
description: 'Delete device by id',
meta: 'function',
args: [
{ name: 'deviceId', type: 'string', description: 'Id of the device'},
requestConfigArg
],
return: observableVoid()
},
getDeviceTypes: {
description: 'Get all available devices types',
meta: 'function',
args: [
requestConfigArg
],
return: observableArrayReturnType('EntitySubtype')
},
getDeviceCredentials: {
description: 'Get device credentials by device id',
meta: 'function',
args: [
{ name: 'deviceId', type: 'string', description: 'Id of the device'},
{ name: 'sync', type: 'boolean', description: 'Whether to execute HTTP request synchronously (false by default)', optional: true},
requestConfigArg
],
return: observableReturnType(deviceCredentialsHref)
},
saveDeviceCredentials: {
description: 'Save device credentials',
meta: 'function',
args: [
{ name: 'deviceCredentials', type: deviceCredentialsHref, description: 'Device credentials object to save'},
requestConfigArg
],
return: observableReturnType(deviceCredentialsHref)
},
makeDevicePublic: {
description: 'Make device public (available from public dashboard)',
meta: 'function',
args: [
{ name: 'deviceId', type: 'string', description: 'Id of the device'},
requestConfigArg
],
return: observableReturnType(deviceHref)
},
assignDeviceToCustomer: {
description: 'Assign device to specific customer',
meta: 'function',
args: [
{ name: 'customerId', type: 'string', description: 'Id of the customer'},
{ name: 'deviceId', type: 'string', description: 'Id of the device'},
requestConfigArg
],
return: observableReturnType(deviceHref)
},
unassignDeviceFromCustomer: {
description: 'Unassign device from any customer',
meta: 'function',
args: [
{ name: 'deviceId', type: 'string', description: 'Id of the device'},
requestConfigArg
],
return: observableVoid()
},
sendOneWayRpcCommand: {
description: 'Send one way (without response) RPC command to the device.',
meta: 'function',
args: [
{ name: 'deviceId', type: 'string', description: 'Id of the device'},
{ name: 'requestBody', type: 'object', description: 'Request body to be sent to device'},
requestConfigArg
],
return: {
type: `Observable<any>`,
description: `A command execution Observable.`
}
},
sendTwoWayRpcCommand: {
description: 'Sends two way (with response) RPC command to the device.',
meta: 'function',
args: [
{ name: 'deviceId', type: 'string', description: 'Id of the device'},
{ name: 'requestBody', type: 'object', description: 'Request body to be sent to device'},
requestConfigArg
],
return: {
type: `Observable<any>`,
description: `A command execution Observable of response body.`
}
},
findByQuery: {
description: 'Find devices by search query',
meta: 'function',
args: [
{ name: 'query', type: 'DeviceSearchQuery',
description: 'Device search query object'},
requestConfigArg
],
return: observableArrayReturnType(deviceHref)
},
findByName: {
description: 'Find device by name',
meta: 'function',
args: [
{ name: 'deviceName', type: 'string',
description: 'Search device name'},
requestConfigArg
],
return: observableReturnType(deviceHref)
},
claimDevice: {
description: 'Send claim device request',
meta: 'function',
args: [
{ name: 'deviceName', type: 'string',
description: 'Claiming device name'},
requestConfigArg
],
return: observableReturnType('ClaimResult')
},
unclaimDevice: {
description: 'Send un-claim device request',
meta: 'function',
args: [
{ name: 'deviceName', type: 'string',
description: 'Device name to un-claim'},
requestConfigArg
],
return: observableVoid()
}
}
},
assetService: {
description: 'Asset Service API
' +
'See AssetService for API reference.',
meta: 'service',
type: 'AssetService'
},
entityViewService: {
description: 'EntityView Service API
' +
'See EntityViewService for API reference.',
meta: 'service',
type: 'EntityViewService'
},
customerService: {
description: 'Customer Service API
' +
'See CustomerService for API reference.',
meta: 'service',
type: 'CustomerService'
},
dashboardService: {
description: 'Dashboard Service API
' +
'See DashboardService for API reference.',
meta: 'service',
type: 'DashboardService'
},
userService: {
description: 'User Service API
' +
'See UserService for API reference.',
meta: 'service',
type: 'UserService'
},
attributeService: {
description: 'Attribute Service API
' +
'See AttributeService for API reference.',
meta: 'service',
type: 'AttributeService'
},
entityRelationService: {
description: 'Entity Relation Service API
' +
'See EntityRelationService for API reference.',
meta: 'service',
type: 'EntityRelationService'
},
entityService: {
description: 'Entity Service API
' +
'See EntityService for API reference.',
meta: 'service',
type: 'EntityService'
},
dialogs: {
description: 'Dialogs Service API
' +
'See DialogService for API reference.',
meta: 'service',
type: 'DialogService'
},
customDialog: {
description: 'Custom Dialog Service API
' +
'See CustomDialogService for API reference.',
meta: 'service',
type: 'CustomDialogService'
},
date: {
description: 'Date Pipe
Formats a date value according to locale rules.
' +
'See DatePipe for API reference.',
meta: 'service',
type: 'DatePipe'
},
translate: {
description: 'Translate Service API
' +
'See TranslateService for API reference.',
meta: 'service',
type: 'TranslateService'
},
http: {
description: 'HTTP Client Service
' +
'See HttpClient for API reference.',
meta: 'service',
type: 'HttpClient'
}
}