reduct-js
Version:
ReductStore Client SDK for Javascript/NodeJS/Typescript
85 lines (84 loc) • 2.27 kB
JavaScript
import { BucketSettings } from "./BucketSettings";
export class ServerDefaults {
constructor() {
this.bucket = {};
}
}
export class LicenseInfo {
constructor() {
/// Licensee name
this.licensee = "UNKNOWN";
/// Invoice number
this.invoice = "UNKNOWN";
/// Expiry date as unix timestamp in milliseconds
this.expiryDate = 0;
/// Plan name
this.plan = "UNKNOWN";
/// Number of devices
this.deviceNumber = 0;
/// Disk quota
this.diskQuota = 0;
/// Fingerprint
this.fingerprint = "UNKNOWN";
}
static parse(data) {
return {
licensee: data.licensee,
invoice: data.invoice,
expiryDate: Date.parse(data.expiry_date),
plan: data.plan,
deviceNumber: Number(data.device_number),
diskQuota: Number(data.disk_quota),
fingerprint: data.fingerprint,
};
}
}
/**
* Represents information about storage
*/
export class ServerInfo {
constructor() {
/**
* Version storage server
*/
this.version = "";
/**
* Number of buckets
*/
this.bucketCount = 0n;
/**
* Stored data in bytes
*/
this.usage = 0n;
/**
* Server uptime in seconds
*/
this.uptime = 0n;
/**
* Unix timestamp of the oldest record in microseconds
*/
this.oldestRecord = 0n;
/**
* Unix timestamp of the latest record in microseconds
*/
this.latestRecord = 0n;
/**
* Default settings
*/
this.defaults = { bucket: {} };
}
static parse(data) {
return {
version: data.version,
bucketCount: BigInt(data.bucket_count),
uptime: BigInt(data.uptime),
usage: BigInt(data.usage),
oldestRecord: BigInt(data.oldest_record),
latestRecord: BigInt(data.latest_record),
license: data.license ? LicenseInfo.parse(data.license) : undefined,
defaults: {
bucket: BucketSettings.parse(data.defaults.bucket),
},
};
}
}