@mcma/core
Advanced tools
Comparing version 0.6.3 to 0.7.0
@@ -1,6 +0,18 @@ | ||
export abstract class Resource { | ||
constructor(type: string, properties: any); | ||
export abstract class McmaObject { | ||
protected constructor(type: string, properties: object); | ||
["@type"]: string; | ||
} | ||
export class McmaTracker extends McmaObject { | ||
constructor(properties: object) | ||
id: string; | ||
["@type"]: string; | ||
label: string; | ||
} | ||
export abstract class Resource extends McmaObject { | ||
protected constructor(type: string, properties: object); | ||
id: string; | ||
dateCreated?: string; | ||
@@ -46,5 +58,6 @@ dateModified?: string; | ||
authType?: string; | ||
authContext?: string; | ||
} | ||
export class ResourceEndpoint extends Resource implements ResourceEndpointProperties { | ||
export class ResourceEndpoint extends McmaObject implements ResourceEndpointProperties { | ||
constructor(properties: ResourceEndpointProperties); | ||
@@ -55,2 +68,3 @@ | ||
authType?: string; | ||
authContext?: string; | ||
} | ||
@@ -84,4 +98,4 @@ | ||
export class JobParameterBag extends Resource { | ||
constructor(properties: any); | ||
export class JobParameterBag extends McmaObject { | ||
constructor(properties: object); | ||
@@ -121,2 +135,3 @@ [key: string]: any; | ||
export interface JobBaseProperties { | ||
tracker?: McmaTracker; | ||
notificationEndpoint?: NotificationEndpointProperties; | ||
@@ -130,2 +145,4 @@ status?: string; | ||
protected constructor(type: string, properties: JobBaseProperties); | ||
tracker?: McmaTracker; | ||
notificationEndpoint?: NotificationEndpointProperties; | ||
@@ -195,3 +212,3 @@ status?: string; | ||
export class BMContent extends Resource { | ||
constructor(properties: any); | ||
constructor(properties: object); | ||
@@ -202,3 +219,3 @@ [key: string]: any; | ||
export class BMEssence extends Resource { | ||
constructor(properties: any); | ||
constructor(properties: object); | ||
@@ -209,3 +226,3 @@ [key: string]: any; | ||
export class DescriptiveMetadata extends Resource { | ||
constructor(properties: any); | ||
constructor(properties: object); | ||
@@ -216,3 +233,3 @@ [key: string]: any; | ||
export class TechnicalMetadata extends Resource { | ||
constructor(properties: any); | ||
constructor(properties: object); | ||
@@ -238,24 +255,37 @@ [key: string]: any; | ||
debug(msg: string, ...args: any[]): void; | ||
info(msg: string, ...args: any[]): void; | ||
warn(msg: string, ...args: any[]): void; | ||
error(msg: string, ...args: any[]): void; | ||
} | ||
export abstract class Logger implements ILogger { | ||
protected constructor(source: string, tracker: McmaTracker); | ||
abstract debug(msg: string, ...args: any[]): void; | ||
abstract error(msg: string, ...args: any[]): void; | ||
abstract info(msg: string, ...args: any[]): void; | ||
abstract warn(msg: string, ...args: any[]): void; | ||
} | ||
export class ConsoleLogger extends Logger { | ||
constructor(source: string, tracker: McmaTracker); | ||
debug(msg: string, ...args: any[]): void; | ||
error(msg: string, ...args: any[]): void; | ||
info(msg: string, ...args: any[]): void; | ||
warn(msg: string, ...args: any[]): void; | ||
} | ||
exception(error: Error): void; | ||
export interface LoggerProvider { | ||
get(tracker: McmaTracker): ILogger | ||
} | ||
export class Logger { | ||
static global: ILogger; | ||
export class ConsoleLoggerProvider implements LoggerProvider { | ||
constructor(source: string); | ||
static debug(msg: string, ...args: any[]): void; | ||
static info(msg: string, ...args: any[]): void; | ||
static warn(msg: string, ...args: any[]): void; | ||
static error(msg: string, ...args: any[]): void; | ||
static exception(error: Error): void; | ||
get(tracker: McmaTracker): ILogger; | ||
} | ||
export abstract class ContextVariableProvider { | ||
constructor(contextVariables: { [key: string]: string }); | ||
protected constructor(contextVariables: { [key: string]: string }); | ||
@@ -262,0 +292,0 @@ getAllContextVariables(): { [key: string]: string }; |
47
index.js
//"use strict"; | ||
const Core = require("./lib/mcma-core"); | ||
const { | ||
onResourceCreate, onResourceUpsert, McmaObject, McmaTracker, Resource, Service, ResourceEndpoint, BMContent, | ||
BMEssence, DescriptiveMetadata, TechnicalMetadata, JobProfile, Locator, JobStatus, JobBase, JobProcess, | ||
JobAssignment, Job, JobParameter, JobParameterBag, AIJob, AmeJob, CaptureJob, QAJob, TransferJob, TransformJob, | ||
WorkflowJob, Notification, NotificationEndpoint, Exception, | ||
} = require("./lib/mcma-core"); | ||
const { ContextVariableProvider, EnvironmentVariableProvider } = require("./lib/context-variable-provider"); | ||
const { Logger } = require("./lib/logger"); | ||
const { Logger, ConsoleLogger, ConsoleLoggerProvider } = require("./lib/logger"); | ||
const Utils = require("./lib/utils"); | ||
module.exports = Object.assign(Core, { | ||
module.exports = { | ||
onResourceCreate, | ||
onResourceUpsert, | ||
McmaObject, | ||
McmaTracker, | ||
Resource, | ||
Service, | ||
ResourceEndpoint, | ||
BMContent, | ||
BMEssence, | ||
DescriptiveMetadata, | ||
TechnicalMetadata, | ||
JobProfile, | ||
Locator, | ||
JobStatus, | ||
JobBase, | ||
JobProcess, | ||
JobAssignment, | ||
Job, | ||
JobParameter, | ||
JobParameterBag, | ||
AIJob, | ||
AmeJob, | ||
CaptureJob, | ||
QAJob, | ||
TransferJob, | ||
TransformJob, | ||
WorkflowJob, | ||
Notification, | ||
NotificationEndpoint, | ||
Exception, | ||
Logger, | ||
ConsoleLogger, | ||
ConsoleLoggerProvider, | ||
ContextVariableProvider, | ||
EnvironmentVariableProvider, | ||
Utils | ||
}); | ||
Utils, | ||
}; |
@@ -1,35 +0,58 @@ | ||
class ConsoleLogger { | ||
const util = require("util"); | ||
class Logger { | ||
constructor(source, tracker) { | ||
this.source = source; | ||
this.tracker = tracker; | ||
} | ||
buildLogEvent(level, message, ...args) { | ||
const logEvent = { | ||
trackerId: this.tracker && this.tracker.id || "", | ||
trackerLabel: this.tracker && this.tracker.label || "", | ||
source: this.source || "", | ||
timestamp: Date.now(), | ||
level: level, | ||
message: util.format(message, ...args), | ||
}; | ||
return JSON.stringify(logEvent, null, 2); | ||
} | ||
} | ||
class ConsoleLogger extends Logger { | ||
constructor(source, tracker) { | ||
super(source, tracker); | ||
} | ||
debug(msg, ...args) { | ||
console.log(msg, ...args); | ||
console.log(this.buildLogEvent("DEBUG", msg, ...args)); | ||
} | ||
info(msg, ...args) { | ||
console.log(msg, ...args); | ||
console.log(this.buildLogEvent("INFO", msg, ...args)); | ||
} | ||
warn(msg, ...args) { | ||
console.warn(msg, ...args); | ||
console.warn(this.buildLogEvent("WARN", msg, ...args)); | ||
} | ||
error(msg, ...args) { | ||
console.error(msg, ...args); | ||
console.error(this.buildLogEvent("ERROR", msg, ...args)); | ||
} | ||
} | ||
exception(error) { | ||
console.log(error); | ||
class ConsoleLoggerProvider { | ||
constructor(source) { | ||
this.source = source; | ||
} | ||
} | ||
function Logger() { | ||
getLogger(tracker) { | ||
return ConsoleLogger(this.source, tracker); | ||
} | ||
} | ||
Logger.global = new ConsoleLogger(); | ||
Logger.debug = (msg, ...args) => Logger.global.debug(msg, ...args); | ||
Logger.info = (msg, ...args) => Logger.global.info(msg, ...args); | ||
Logger.warn = (msg, ...args) => Logger.global.warn(msg, ...args); | ||
Logger.error = (msg, ...args) => Logger.global.error(msg, ...args); | ||
Logger.exception = (error) => Logger.global.exception(error); | ||
module.exports = { | ||
Logger | ||
Logger, | ||
ConsoleLogger, | ||
ConsoleLoggerProvider, | ||
}; |
@@ -59,3 +59,3 @@ //"use strict"; | ||
class Resource { | ||
class McmaObject { | ||
constructor(type, properties) { | ||
@@ -72,6 +72,21 @@ this["@type"] = type; | ||
this.checkProperty = (propertyName, expectedType, required) => checkProperty(this, propertyName, expectedType, required); | ||
} | ||
} | ||
class McmaTracker extends McmaObject { | ||
constructor(properties) { | ||
super("McmaTracker", properties); | ||
this.checkProperty("id", "string", true); | ||
this.checkProperty("label", "string", true); | ||
} | ||
} | ||
class Resource extends McmaObject { | ||
constructor(type, properties) { | ||
super(type, properties); | ||
this.onCreate = (id) => onResourceCreate(this, id); | ||
this.onUpsert = (id) => onResourceUpsert(this, id); | ||
this.checkProperty = (propertyName, expectedType, required) => checkProperty(this, propertyName, expectedType, required); | ||
} | ||
@@ -84,7 +99,7 @@ } | ||
checkProperty(this, "name", "string", true); | ||
checkProperty(this, "resources", "Array", true); | ||
checkProperty(this, "authType", "string", false); | ||
checkProperty(this, "jobType", "string", false); | ||
checkProperty(this, "jobProfiles", "Array", false); | ||
this.checkProperty("name", "string", true); | ||
this.checkProperty("resources", "Array", true); | ||
this.checkProperty("authType", "string", false); | ||
this.checkProperty("jobType", "string", false); | ||
this.checkProperty("jobProfiles", "Array", false); | ||
@@ -105,9 +120,9 @@ for (let i = 0; i < this.resources.length; i++) { | ||
class ResourceEndpoint extends Resource { | ||
class ResourceEndpoint extends McmaObject { | ||
constructor(properties) { | ||
super("ResourceEndpoint", properties); | ||
checkProperty(this, "resourceType", "string", true); | ||
checkProperty(this, "httpEndpoint", "url", true); | ||
checkProperty(this, "authType", "string", false); | ||
this.checkProperty("resourceType", "string", true); | ||
this.checkProperty("httpEndpoint", "url", true); | ||
this.checkProperty("authType", "string", false); | ||
} | ||
@@ -120,5 +135,5 @@ } | ||
checkProperty(this, "inputParameters", "Array", false); | ||
checkProperty(this, "outputParameters", "Array", false); | ||
checkProperty(this, "optionalInputParameters", "Array", false); | ||
this.checkProperty("inputParameters", "Array", false); | ||
this.checkProperty("outputParameters", "Array", false); | ||
this.checkProperty("optionalInputParameters", "Array", false); | ||
} | ||
@@ -131,8 +146,8 @@ } | ||
checkProperty(this, "parameterName", "string", true); | ||
checkProperty(this, "parameterType", "string", false); | ||
this.checkProperty("parameterName", "string", true); | ||
this.checkProperty("parameterType", "string", false); | ||
} | ||
} | ||
class JobParameterBag extends Resource { | ||
class JobParameterBag extends McmaObject { | ||
constructor(properties) { | ||
@@ -157,7 +172,10 @@ super("JobParameterBag", properties); | ||
checkProperty(this, "notificationEndpoint", "resource", false); | ||
checkProperty(this, "status", "string", false); | ||
checkProperty(this, "statusMessage", "string", false); | ||
checkProperty(this, "jobOutput", "resource", false); | ||
this.checkProperty("tracker", "object", false); | ||
this.checkProperty("notificationEndpoint", "resource", false); | ||
this.checkProperty("status", "string", false); | ||
this.checkProperty("statusMessage", "string", false); | ||
this.checkProperty("jobOutput", "resource", false); | ||
this.tracker = new McmaTracker(this.tracker); | ||
if (typeof this.notificationEndpoint === "object") { | ||
@@ -173,4 +191,5 @@ this.notificationEndpoint = new NotificationEndpoint(this.notificationEndpoint); | ||
checkProperty(this, "jobProfile", "resource", true); | ||
checkProperty(this, "jobInput", "resource", true); | ||
this.checkProperty("jobProfile", "resource", true); | ||
this.checkProperty("jobInput", "resource", true); | ||
this.checkProperty("tracker", "object", false); | ||
@@ -232,3 +251,3 @@ if (typeof this.jobProfile === "object") { | ||
checkProperty(this, "job", "resource"); | ||
this.checkProperty("job", "resource"); | ||
} | ||
@@ -241,3 +260,3 @@ } | ||
checkProperty(this, "job", "resource"); | ||
this.checkProperty("job", "resource"); | ||
} | ||
@@ -250,4 +269,4 @@ } | ||
checkProperty(this, "source", "string", false); | ||
checkProperty(this, "content", "resource", true); | ||
this.checkProperty("source", "string", false); | ||
this.checkProperty("content", "resource", true); | ||
} | ||
@@ -260,3 +279,3 @@ } | ||
checkProperty(this, "httpEndpoint", "url", true); | ||
this.checkProperty("httpEndpoint", "url", true); | ||
} | ||
@@ -339,2 +358,4 @@ } | ||
onResourceUpsert, | ||
McmaObject, | ||
McmaTracker, | ||
Resource, | ||
@@ -365,3 +386,3 @@ Service, | ||
NotificationEndpoint, | ||
Exception | ||
Exception, | ||
}; |
{ | ||
"name": "@mcma/core", | ||
"version": "0.6.3", | ||
"version": "0.7.0", | ||
"description": "Node module with type definitions and helper utils for the EBU MCMA framework", | ||
@@ -5,0 +5,0 @@ "engines": { |
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
23715
700
9