69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import * as plugins from '../plugins.js';
|
|
import type { CloudlyPlatformManager } from './classes.platformmanager.js';
|
|
|
|
@plugins.smartdata.managed()
|
|
export class PlatformBinding extends plugins.smartdata.SmartDataDbDoc<
|
|
PlatformBinding,
|
|
plugins.servezoneInterfaces.platform.IPlatformBinding,
|
|
CloudlyPlatformManager
|
|
> {
|
|
public static async upsertBinding(
|
|
bindingArg: plugins.servezoneInterfaces.platform.IPlatformBinding,
|
|
) {
|
|
const existingBinding =
|
|
bindingArg.id &&
|
|
(await this.getInstance({
|
|
id: bindingArg.id,
|
|
}));
|
|
const binding = existingBinding || new PlatformBinding();
|
|
const timestamp = Date.now();
|
|
|
|
Object.assign(binding, {
|
|
...bindingArg,
|
|
id: bindingArg.id || (await this.getNewId()),
|
|
status: bindingArg.status || 'requested',
|
|
desiredState: bindingArg.desiredState || 'enabled',
|
|
createdAt: bindingArg.createdAt || existingBinding?.createdAt || timestamp,
|
|
updatedAt: timestamp,
|
|
});
|
|
await binding.save();
|
|
return binding;
|
|
}
|
|
|
|
@plugins.smartdata.unI()
|
|
public id!: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public serviceId!: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public capability!: plugins.servezoneInterfaces.platform.TPlatformCapability;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public desiredState!: plugins.servezoneInterfaces.platform.TPlatformDesiredState;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public status!: plugins.servezoneInterfaces.platform.TPlatformBindingStatus;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public providerConfigId?: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public config?: { [key: string]: plugins.servezoneInterfaces.platform.TPlatformConfigValue };
|
|
|
|
@plugins.smartdata.svDb()
|
|
public endpoints?: plugins.servezoneInterfaces.platform.IPlatformServiceEndpoint[];
|
|
|
|
@plugins.smartdata.svDb()
|
|
public credentials?: plugins.servezoneInterfaces.platform.IPlatformCredentialRef[];
|
|
|
|
@plugins.smartdata.svDb()
|
|
public createdAt?: number;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public updatedAt?: number;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public errorText?: string;
|
|
}
|