UNPKG

@squarecloud/api

Version:
185 lines (183 loc) 4.98 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); // src/lib/routes.ts var Route = (route) => route; var Routes = { user: () => { return Route("users/me"); }, service: { status: () => { return Route("service/status"); } }, apps: { upload: () => { return Route("apps"); }, statusAll: () => { return Route("apps/status"); }, info: (appId) => { return Route(`apps/${appId}`); }, status: (appId) => { return Route(`apps/${appId}/status`); }, logs: (appId) => { return Route(`apps/${appId}/logs`); }, delete: (appId) => { return Route(`apps/${appId}`); }, commit: (appId) => { return Route(`apps/${appId}/commit`); }, snapshots: (appId) => { return Route(`apps/${appId}/snapshots`); }, generateSnapshot: (appId) => { return Route(`apps/${appId}/snapshots`); }, start: (appId) => { return Route(`apps/${appId}/start`); }, restart: (appId) => { return Route(`apps/${appId}/restart`); }, stop: (appId) => { return Route(`apps/${appId}/stop`); }, files: { read: (appId) => { return Route(`apps/${appId}/files/content`); }, list: (appId) => { return Route(`apps/${appId}/files`); }, upsert: (appId) => { return Route(`apps/${appId}/files`); }, move: (appId) => { return Route(`apps/${appId}/files`); }, delete: (appId) => { return Route(`apps/${appId}/files`); } }, deployments: { list: (appId) => { return Route(`apps/${appId}/deployments`); }, current: (appId) => { return Route( `apps/${appId}/deployments/current` ); }, webhook: (appId) => { return Route( `apps/${appId}/deploy/webhook` ); } }, network: { dns: (appId) => { return Route(`apps/${appId}/network/dns`); }, custom: (appId) => { return Route(`apps/${appId}/network/custom`); }, analytics: (appId) => { return Route( `apps/${appId}/network/analytics` ); } } } }; // src/structures/status.ts var SimpleApplicationStatus = class { /** * Represents an application status fetched from status all endpoint * * @constructor * @param client - The client for this status * @param data - The data from this status */ constructor(client, data) { this.client = client; /** The application's ID this status came from */ __publicField(this, "applicationId"); /** Usage statuses for this application */ __publicField(this, "usage"); /** Whether the application is running or not */ __publicField(this, "running"); const { id, running } = data; this.applicationId = id; this.running = running; if (running) { const { cpu, ram } = data; this.usage = { cpu, ram }; } } /** * Fetches the full application status */ async fetch() { const data = await this.client.api.request( Routes.apps.status(this.applicationId) ); return new ApplicationStatus( this.client, data.response, this.applicationId ); } }; var ApplicationStatus = class { /** * Represents an application status * * @constructor * @param client - The client for this status * @param data - The data from this status * @param applicationId - The application ID this status came from */ constructor(client, data, applicationId) { this.client = client; /** The application's ID this status came from */ __publicField(this, "applicationId"); /** Usage statuses for this application */ __publicField(this, "usage"); /** Whether the application is running or not */ __publicField(this, "running"); /** * The status of the application * * - 'exited' (stopped) * - 'created' (being created) * - 'running' * - 'starting' * - 'restarting' * - 'deleting' */ __publicField(this, "status"); /** For how long the app is running in millisseconds */ __publicField(this, "uptimeTimestamp"); /** For how long the app is running */ __publicField(this, "uptime"); const { cpu, ram, network, storage, running, status, uptime } = data; this.applicationId = applicationId; this.usage = { cpu, ram, network, storage }; this.running = running; this.status = status; this.uptime = uptime ? new Date(uptime) : void 0; this.uptimeTimestamp = uptime ?? void 0; } }; export { ApplicationStatus, SimpleApplicationStatus }; //# sourceMappingURL=status.js.map