@citrineos/data
Version:
The OCPP data module which includes all persistence layer implementation.
242 lines • 8.19 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { DEFAULT_TENANT_ID, OCPP2_0_1, OCPP2_0_1_Namespace } from '@citrineos/base';
import { BeforeCreate, BeforeUpdate, BelongsTo, Column, DataType, ForeignKey, HasMany, Index, Model, Table, } from 'sequelize-typescript';
import { CryptoUtils } from '../../../../util/CryptoUtils.js';
import { Boot } from '../Boot.js';
import { ChargingStation } from '../Location/index.js';
import { Tenant } from '../Tenant.js';
import { Component } from './Component.js';
import { EvseType } from './EvseType.js';
import { Variable } from './Variable.js';
import { VariableStatus } from './VariableStatus.js';
let VariableAttribute = class VariableAttribute extends Model {
static MODEL_NAME = OCPP2_0_1_Namespace.VariableAttributeType;
static setDefaultTenant(instance) {
if (instance.tenantId == null) {
instance.tenantId = DEFAULT_TENANT_ID;
}
}
constructor(...args) {
super(...args);
if (this.tenantId == null) {
this.tenantId = DEFAULT_TENANT_ID;
}
}
};
__decorate([
Index,
Column({
type: DataType.STRING,
unique: 'stationId_type_variableId_componentId',
allowNull: false,
}),
ForeignKey(() => ChargingStation),
__metadata("design:type", String)
], VariableAttribute.prototype, "stationId", void 0);
__decorate([
BelongsTo(() => ChargingStation),
__metadata("design:type", ChargingStation)
], VariableAttribute.prototype, "chargingStation", void 0);
__decorate([
Column({
type: DataType.STRING,
defaultValue: OCPP2_0_1.AttributeEnumType.Actual,
unique: 'stationId_type_variableId_componentId',
}),
__metadata("design:type", Object)
], VariableAttribute.prototype, "type", void 0);
__decorate([
Column({
type: DataType.STRING,
defaultValue: OCPP2_0_1.DataEnumType.string,
}),
__metadata("design:type", String)
], VariableAttribute.prototype, "dataType", void 0);
__decorate([
Column({
// TODO: Make this configurable? also used in VariableStatus model
type: DataType.STRING(4000),
set(valueString) {
if (valueString) {
const valueType = this.dataType;
switch (valueType) {
case OCPP2_0_1.DataEnumType.passwordString:
valueString = CryptoUtils.getPasswordHash(valueString);
break;
default:
// Do nothing
break;
}
}
this.setDataValue('value', valueString);
},
}),
__metadata("design:type", Object)
], VariableAttribute.prototype, "value", void 0);
__decorate([
Column({
type: DataType.STRING,
defaultValue: OCPP2_0_1.MutabilityEnumType.ReadWrite,
}),
__metadata("design:type", Object)
], VariableAttribute.prototype, "mutability", void 0);
__decorate([
Column({
type: DataType.BOOLEAN,
defaultValue: false,
}),
__metadata("design:type", Object)
], VariableAttribute.prototype, "persistent", void 0);
__decorate([
Column({
type: DataType.BOOLEAN,
defaultValue: false,
}),
__metadata("design:type", Object)
], VariableAttribute.prototype, "constant", void 0);
__decorate([
Column({
type: DataType.DATE,
get() {
return this.getDataValue('generatedAt').toISOString();
},
}),
__metadata("design:type", String)
], VariableAttribute.prototype, "generatedAt", void 0);
__decorate([
BelongsTo(() => Variable),
__metadata("design:type", Object)
], VariableAttribute.prototype, "variable", void 0);
__decorate([
ForeignKey(() => Variable),
Column({
type: DataType.INTEGER,
unique: 'stationId_type_variableId_componentId',
}),
__metadata("design:type", Object)
], VariableAttribute.prototype, "variableId", void 0);
__decorate([
BelongsTo(() => Component),
__metadata("design:type", Object)
], VariableAttribute.prototype, "component", void 0);
__decorate([
ForeignKey(() => Component),
Column({
type: DataType.INTEGER,
unique: 'stationId_type_variableId_componentId',
}),
__metadata("design:type", Object)
], VariableAttribute.prototype, "componentId", void 0);
__decorate([
BelongsTo(() => EvseType),
__metadata("design:type", EvseType)
], VariableAttribute.prototype, "evse", void 0);
__decorate([
ForeignKey(() => EvseType),
Column(DataType.INTEGER),
__metadata("design:type", Object)
], VariableAttribute.prototype, "evseDatabaseId", void 0);
__decorate([
HasMany(() => VariableStatus),
__metadata("design:type", Array)
], VariableAttribute.prototype, "statuses", void 0);
__decorate([
BelongsTo(() => Boot),
__metadata("design:type", Object)
], VariableAttribute.prototype, "bootConfig", void 0);
__decorate([
ForeignKey(() => Boot),
__metadata("design:type", Object)
], VariableAttribute.prototype, "bootConfigId", void 0);
__decorate([
ForeignKey(() => Tenant),
Column({
type: DataType.INTEGER,
allowNull: false,
onUpdate: 'CASCADE',
onDelete: 'RESTRICT',
}),
__metadata("design:type", Number)
], VariableAttribute.prototype, "tenantId", void 0);
__decorate([
BelongsTo(() => Tenant),
__metadata("design:type", Object)
], VariableAttribute.prototype, "tenant", void 0);
__decorate([
BeforeUpdate,
BeforeCreate,
__metadata("design:type", Function),
__metadata("design:paramtypes", [VariableAttribute]),
__metadata("design:returntype", void 0)
], VariableAttribute, "setDefaultTenant", null);
VariableAttribute = __decorate([
Table({
indexes: [
{
unique: true,
fields: ['stationId'],
where: {
type: null,
variableId: null,
componentId: null,
},
},
{
unique: true,
fields: ['stationId', 'type'],
where: {
variableId: null,
componentId: null,
},
},
{
unique: true,
fields: ['stationId', 'variableId'],
where: {
type: null,
componentId: null,
},
},
{
unique: true,
fields: ['stationId', 'componentId'],
where: {
type: null,
variableId: null,
},
},
{
unique: true,
fields: ['stationId', 'type', 'variableId'],
where: {
componentId: null,
},
},
{
unique: true,
fields: ['stationId', 'type', 'componentId'],
where: {
variableId: null,
},
},
{
unique: true,
fields: ['stationId', 'variableId', 'componentId'],
where: {
type: null,
},
},
],
}),
__metadata("design:paramtypes", [Object])
], VariableAttribute);
export { VariableAttribute };
//# sourceMappingURL=VariableAttribute.js.map