@withonevision/omnihive-core
Advanced tools
Comparing version 6.2.36 to 6.2.37
@@ -1,7 +0,7 @@ | ||
import { AppSettings } from "../models/AppSettings"; | ||
import { ServerConfig } from "../models/ServerConfig"; | ||
import { IHiveWorker } from "./IHiveWorker"; | ||
export interface IConfigWorker extends IHiveWorker { | ||
get: () => Promise<AppSettings>; | ||
set: (settings: AppSettings) => Promise<boolean>; | ||
get: () => Promise<ServerConfig>; | ||
set: (serverConfig: ServerConfig) => Promise<boolean>; | ||
} | ||
//# sourceMappingURL=IConfigWorker.d.ts.map |
@@ -1,14 +0,15 @@ | ||
import { HiveWorker } from "../models/HiveWorker"; | ||
import { EnvironmentVariable } from "../models/EnvironmentVariable"; | ||
import { RegisteredHiveWorker } from "../models/RegisteredHiveWorker"; | ||
import { AppSettings } from "../models/AppSettings"; | ||
export interface IHiveWorker { | ||
appSettings: AppSettings; | ||
environmentVariables: EnvironmentVariable[]; | ||
metadata: any; | ||
name: string; | ||
registeredWorkers: RegisteredHiveWorker[]; | ||
checkObjectStructure: <T extends object>(type: { | ||
new (): T; | ||
}, model: any | null) => T; | ||
config: HiveWorker; | ||
checkMetadata: (metadata: any) => void; | ||
getWorker: <T extends IHiveWorker | undefined>(type: string, name?: string) => T | undefined; | ||
init: (hiveWorker: HiveWorker) => Promise<void>; | ||
registeredWorkers: RegisteredHiveWorker[]; | ||
init: (name: string, metadata?: any) => Promise<void>; | ||
} | ||
//# sourceMappingURL=IHiveWorker.d.ts.map |
@@ -0,12 +1,15 @@ | ||
/// <reference types="src/types/globals.omnihive" /> | ||
import { EnvironmentVariable } from "./EnvironmentVariable"; | ||
import { RegisteredHiveWorker } from "./RegisteredHiveWorker"; | ||
import { IHiveWorker } from "../interfaces/IHiveWorker"; | ||
import { HiveWorker } from "./HiveWorker"; | ||
import { AppSettings } from "./AppSettings"; | ||
import { WorkerGetterBase } from "./WorkerGetterBase"; | ||
export declare abstract class HiveWorkerBase extends WorkerGetterBase implements IHiveWorker { | ||
constructor(); | ||
config: HiveWorker; | ||
appSettings: AppSettings; | ||
init(config: HiveWorker): Promise<void>; | ||
export declare abstract class HiveWorkerBase implements IHiveWorker { | ||
environmentVariables: EnvironmentVariable[]; | ||
metadata: any; | ||
name: string; | ||
registeredWorkers: RegisteredHiveWorker[]; | ||
init(name: string, metadata?: any): Promise<void>; | ||
checkObjectStructure: <T extends object>(type: new () => T, model: any | null) => T; | ||
checkMetadata: (metadata: any) => void; | ||
getWorker<T extends IHiveWorker | undefined>(type: string, name?: string): T | undefined; | ||
} | ||
//# sourceMappingURL=HiveWorkerBase.d.ts.map |
@@ -14,7 +14,8 @@ "use strict"; | ||
const ObjectHelper_1 = require("../helpers/ObjectHelper"); | ||
const WorkerGetterBase_1 = require("./WorkerGetterBase"); | ||
const IsHelper_1 = require("../helpers/IsHelper"); | ||
class HiveWorkerBase extends WorkerGetterBase_1.WorkerGetterBase { | ||
const EnvironmentVariableType_1 = require("../enums/EnvironmentVariableType"); | ||
class HiveWorkerBase { | ||
constructor() { | ||
super(); | ||
this.environmentVariables = []; | ||
this.registeredWorkers = []; | ||
this.checkObjectStructure = (type, model) => { | ||
@@ -25,3 +26,3 @@ const objectData = ObjectHelper_1.ObjectHelper.createStrict(type, model); | ||
if (IsHelper_1.IsHelper.isNullOrUndefined(objectAny[key])) { | ||
throw new Error(`Object key ${key} is null or undefined on hive worker ${this.config.name}`); | ||
throw new Error(`Object key ${key} is null or undefined on hive worker ${this.name}`); | ||
} | ||
@@ -31,13 +32,52 @@ }); | ||
}; | ||
this.checkMetadata = (metadata) => { | ||
Object.keys(metadata).forEach((metaKey) => { | ||
if (metadata[metaKey].toString().startsWith("${") && | ||
metadata[metaKey].toString().endsWith("}")) { | ||
let metaValue = metadata[metaKey]; | ||
metaValue = metaValue.substr(2, metaValue.length - 3); | ||
const environmentVariable = this.environmentVariables.find((variable) => variable.key === metaValue); | ||
if (IsHelper_1.IsHelper.isNullOrUndefined(environmentVariable)) { | ||
throw new Error(`Metadata key ${metaKey} invalid or not set for worker ${this.name}`); | ||
} | ||
switch (environmentVariable.type) { | ||
case EnvironmentVariableType_1.EnvironmentVariableType.Boolean: | ||
this.metadata[metaKey] = environmentVariable.value === "true"; | ||
break; | ||
case EnvironmentVariableType_1.EnvironmentVariableType.Number: | ||
this.metadata[metaKey] = Number(environmentVariable.value); | ||
break; | ||
default: | ||
this.metadata[metaKey] = String(environmentVariable.value); | ||
break; | ||
} | ||
} | ||
}); | ||
}; | ||
} | ||
init(config) { | ||
init(name, metadata) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (IsHelper_1.IsHelper.isNullOrUndefined(config) || IsHelper_1.IsHelper.isEmptyObject(config)) { | ||
throw new Error("Configuration not specified"); | ||
this.name = name; | ||
this.metadata = metadata; | ||
if (!IsHelper_1.IsHelper.isNullOrUndefined(metadata)) { | ||
this.checkMetadata(metadata); | ||
} | ||
this.config = config; | ||
}); | ||
} | ||
getWorker(type, name) { | ||
if (!IsHelper_1.IsHelper.isNullOrUndefined(name)) { | ||
const namedWorker = this.registeredWorkers.find((value) => value.name === name && value.type === type); | ||
if (!IsHelper_1.IsHelper.isNullOrUndefined(namedWorker)) { | ||
return namedWorker.instance; | ||
} | ||
return undefined; | ||
} | ||
const anyWorkers = this.registeredWorkers.filter((value) => value.type === type); | ||
if (!IsHelper_1.IsHelper.isNullOrUndefined(anyWorkers) && !IsHelper_1.IsHelper.isEmptyArray(anyWorkers)) { | ||
return anyWorkers[0].instance; | ||
} | ||
return undefined; | ||
} | ||
} | ||
exports.HiveWorkerBase = HiveWorkerBase; | ||
//# sourceMappingURL=HiveWorkerBase.js.map |
@@ -0,7 +1,10 @@ | ||
import { HiveWorkerType } from "../enums/HiveWorkerType"; | ||
import { RegisteredHiveWorkerSection } from "../enums/RegisteredHiveWorkerSection"; | ||
import { HiveWorker } from "./HiveWorker"; | ||
export declare class RegisteredHiveWorker extends HiveWorker { | ||
export declare class RegisteredHiveWorker { | ||
instance: any; | ||
name: string; | ||
type: HiveWorkerType | string; | ||
metadata: any; | ||
section: RegisteredHiveWorkerSection; | ||
} | ||
//# sourceMappingURL=RegisteredHiveWorker.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RegisteredHiveWorker = void 0; | ||
const HiveWorkerType_1 = require("../enums/HiveWorkerType"); | ||
const RegisteredHiveWorkerSection_1 = require("../enums/RegisteredHiveWorkerSection"); | ||
const HiveWorker_1 = require("./HiveWorker"); | ||
class RegisteredHiveWorker extends HiveWorker_1.HiveWorker { | ||
class RegisteredHiveWorker { | ||
constructor() { | ||
super(...arguments); | ||
this.name = ""; | ||
this.type = HiveWorkerType_1.HiveWorkerType.User; | ||
this.section = RegisteredHiveWorkerSection_1.RegisteredHiveWorkerSection.User; | ||
@@ -10,0 +11,0 @@ } |
{ | ||
"name": "@withonevision/omnihive-core", | ||
"version": "6.2.36", | ||
"version": "6.2.37", | ||
"description": "OmniHive Core", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
0
104901
241
1296