@mcma/core 0.14.4 → 0.14.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,12 +4,13 @@ exports.JobAssignment = void 0;
4
4
  const job_base_1 = require("./job-base");
5
5
  const mcma_tracker_1 = require("./mcma-tracker");
6
6
  const notification_endpoint_1 = require("./notification-endpoint");
7
+ const utils_1 = require("../utils");
7
8
  class JobAssignment extends job_base_1.JobBase {
8
9
  constructor(properties) {
9
10
  super("JobAssignment", properties);
10
- this.checkProperty("jobId", "url");
11
- this.checkProperty("tracker", "object", false);
12
- this.checkProperty("notificationEndpoint", "object", false);
11
+ utils_1.Utils.checkProperty(this, "jobId", "url");
12
+ utils_1.Utils.checkProperty(this, "tracker", "object", false);
13
+ utils_1.Utils.checkProperty(this, "notificationEndpoint", "object", false);
13
14
  if (typeof this.notificationEndpoint === "object") {
14
15
  this.notificationEndpoint = new notification_endpoint_1.NotificationEndpoint(this.notificationEndpoint);
15
16
  }
@@ -4,13 +4,14 @@ exports.JobBase = void 0;
4
4
  const job_parameter_bag_1 = require("./job-parameter-bag");
5
5
  const mcma_resource_1 = require("./mcma-resource");
6
6
  const problem_detail_1 = require("./problem-detail");
7
+ const utils_1 = require("../utils");
7
8
  class JobBase extends mcma_resource_1.McmaResource {
8
9
  constructor(type, properties) {
9
10
  super(type, properties);
10
- this.checkProperty("status", "string", false);
11
- this.checkProperty("error", "object", false);
12
- this.checkProperty("jobOutput", "object", false);
13
- this.checkProperty("progress", "number", false);
11
+ utils_1.Utils.checkProperty(this, "status", "string", false);
12
+ utils_1.Utils.checkProperty(this, "error", "object", false);
13
+ utils_1.Utils.checkProperty(this, "jobOutput", "object", false);
14
+ utils_1.Utils.checkProperty(this, "progress", "number", false);
14
15
  if (typeof this.error === "object") {
15
16
  this.error = new problem_detail_1.ProblemDetail(this.error);
16
17
  }
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JobExecution = void 0;
4
4
  const job_base_1 = require("./job-base");
5
+ const utils_1 = require("../utils");
5
6
  class JobExecution extends job_base_1.JobBase {
6
7
  constructor(properties) {
7
8
  super("JobExecution", properties);
8
- this.checkProperty("jobAssignmentId", "url", false);
9
- this.checkProperty("actualDuration", "number", false);
10
- this.actualStartDate = this.ensureValidDateOrUndefined(this.actualStartDate);
11
- this.actualEndDate = this.ensureValidDateOrUndefined(this.actualEndDate);
9
+ utils_1.Utils.checkProperty(this, "jobAssignmentId", "url", false);
10
+ utils_1.Utils.checkProperty(this, "actualDuration", "number", false);
11
+ this.actualStartDate = utils_1.Utils.ensureValidDateOrUndefined(this.actualStartDate);
12
+ this.actualEndDate = utils_1.Utils.ensureValidDateOrUndefined(this.actualEndDate);
12
13
  }
13
14
  }
14
15
  exports.JobExecution = JobExecution;
@@ -7,6 +7,4 @@ export declare class JobParameterBag extends McmaObject implements JobParameterB
7
7
  constructor(properties?: {
8
8
  [key: string]: any;
9
9
  });
10
- get<T>(key: string): T;
11
- set<T>(key: string, value: T): this;
12
10
  }
@@ -6,12 +6,5 @@ class JobParameterBag extends mcma_object_1.McmaObject {
6
6
  constructor(properties) {
7
7
  super("JobParameterBag", properties);
8
8
  }
9
- get(key) {
10
- return this[key];
11
- }
12
- set(key, value) {
13
- this[key] = value;
14
- return this;
15
- }
16
9
  }
17
10
  exports.JobParameterBag = JobParameterBag;
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JobParameter = void 0;
4
4
  const mcma_object_1 = require("./mcma-object");
5
+ const utils_1 = require("../utils");
5
6
  class JobParameter extends mcma_object_1.McmaObject {
6
7
  constructor(properties) {
7
8
  super("JobParameter", properties);
8
- this.checkProperty("parameterName", "string");
9
- this.checkProperty("parameterType", "string");
9
+ utils_1.Utils.checkProperty(this, "parameterName", "string");
10
+ utils_1.Utils.checkProperty(this, "parameterType", "string");
10
11
  }
11
12
  }
12
13
  exports.JobParameter = JobParameter;
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JobProfile = void 0;
4
4
  const mcma_resource_1 = require("./mcma-resource");
5
5
  const job_parameter_1 = require("./job-parameter");
6
+ const utils_1 = require("../utils");
6
7
  class JobProfile extends mcma_resource_1.McmaResource {
7
8
  constructor(properties) {
8
9
  super("JobProfile", properties);
9
- this.checkProperty("name", "string", true);
10
- this.checkProperty("inputParameters", "Array", false);
11
- this.checkProperty("outputParameters", "Array", false);
12
- this.checkProperty("optionalInputParameters", "Array", false);
10
+ utils_1.Utils.checkProperty(this, "name", "string", true);
11
+ utils_1.Utils.checkProperty(this, "inputParameters", "Array", false);
12
+ utils_1.Utils.checkProperty(this, "outputParameters", "Array", false);
13
+ utils_1.Utils.checkProperty(this, "optionalInputParameters", "Array", false);
13
14
  if (Array.isArray(this.inputParameters)) {
14
15
  this.inputParameters = this.inputParameters.map(ip => new job_parameter_1.JobParameter(ip));
15
16
  }
@@ -5,17 +5,18 @@ const job_base_1 = require("../job-base");
5
5
  const job_parameter_bag_1 = require("../job-parameter-bag");
6
6
  const mcma_tracker_1 = require("../mcma-tracker");
7
7
  const notification_endpoint_1 = require("../notification-endpoint");
8
+ const utils_1 = require("../../utils");
8
9
  class Job extends job_base_1.JobBase {
9
10
  constructor(type, properties) {
10
11
  super(type, properties);
11
- this.checkProperty("parentId", "string", false);
12
- this.checkProperty("jobProfileId", "url", true);
13
- this.checkProperty("jobInput", "object", false);
14
- this.checkProperty("timeout", "number", false);
15
- this.checkProperty("tracker", "object", false);
16
- this.checkProperty("notificationEndpoint", "object", false);
12
+ utils_1.Utils.checkProperty(this, "parentId", "string", false);
13
+ utils_1.Utils.checkProperty(this, "jobProfileId", "url", true);
14
+ utils_1.Utils.checkProperty(this, "jobInput", "object", false);
15
+ utils_1.Utils.checkProperty(this, "timeout", "number", false);
16
+ utils_1.Utils.checkProperty(this, "tracker", "object", false);
17
+ utils_1.Utils.checkProperty(this, "notificationEndpoint", "object", false);
17
18
  this.jobInput = new job_parameter_bag_1.JobParameterBag(properties.jobInput);
18
- this.deadline = this.ensureValidDateOrUndefined(this.deadline);
19
+ this.deadline = utils_1.Utils.ensureValidDateOrUndefined(this.deadline);
19
20
  if (typeof this.notificationEndpoint === "object") {
20
21
  this.notificationEndpoint = new notification_endpoint_1.NotificationEndpoint(this.notificationEndpoint);
21
22
  }
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Locator = void 0;
4
4
  const mcma_object_1 = require("./mcma-object");
5
+ const utils_1 = require("../utils");
5
6
  class Locator extends mcma_object_1.McmaObject {
6
7
  constructor(type, properties) {
7
8
  super(type, properties);
8
- this.checkProperty("url", "string", true);
9
+ utils_1.Utils.checkProperty(this, "url", "string", true);
9
10
  }
10
11
  }
11
12
  exports.Locator = Locator;
@@ -4,6 +4,4 @@ export interface McmaObjectProperties {
4
4
  export declare class McmaObject implements McmaObjectProperties {
5
5
  ["@type"]: string;
6
6
  constructor(type: string, properties?: McmaObjectProperties);
7
- protected checkProperty(propertyName: string, expectedType: string, required?: boolean): void;
8
- protected ensureValidDateOrUndefined(maybeDate: any): Date;
9
7
  }
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.McmaObject = void 0;
4
- const mcma_exception_1 = require("../mcma-exception");
5
- const utils_1 = require("../utils");
6
4
  class McmaObject {
7
5
  constructor(type, properties) {
8
6
  if (properties) {
@@ -10,45 +8,5 @@ class McmaObject {
10
8
  }
11
9
  this["@type"] = type;
12
10
  }
13
- checkProperty(propertyName, expectedType, required) {
14
- const propertyValue = this[propertyName];
15
- const propertyType = typeof propertyValue;
16
- if (propertyValue === undefined || propertyValue === null) {
17
- if (required) {
18
- throw new mcma_exception_1.McmaException("Resource of type '" + this["@type"] + "' requires property '" + propertyName + "' to be defined", null, this);
19
- }
20
- return;
21
- }
22
- if (expectedType === "url") {
23
- if (propertyType !== "string" || !utils_1.Utils.isValidUrl(propertyValue)) {
24
- throw new mcma_exception_1.McmaException("Resource of type '" + this["@type"] + "' requires property '" + propertyName + "' to have a valid URL", null, this);
25
- }
26
- }
27
- else if (expectedType === "Array") {
28
- if (!Array.isArray(propertyValue)) {
29
- throw new mcma_exception_1.McmaException("Resource of type '" + this["@type"] + "' requires property '" + propertyName + "' to have type Array", null, this);
30
- }
31
- }
32
- else if (expectedType === "object") {
33
- if (propertyType !== "object" || Array.isArray(propertyValue)) {
34
- throw new mcma_exception_1.McmaException("Resource of type '" + this["@type"] + "' requires property '" + propertyName + "' to have type object", null, this);
35
- }
36
- }
37
- else {
38
- if (expectedType !== propertyType) {
39
- throw new mcma_exception_1.McmaException("Resource of type '" + this["@type"] + "' requires property '" + propertyName + "' to have type " + expectedType, null, this);
40
- }
41
- }
42
- }
43
- ensureValidDateOrUndefined(maybeDate) {
44
- if (maybeDate === undefined || maybeDate === null) {
45
- return undefined;
46
- }
47
- const date = new Date(maybeDate);
48
- if (isNaN(date.getTime())) {
49
- return undefined;
50
- }
51
- return date;
52
- }
53
11
  }
54
12
  exports.McmaObject = McmaObject;
@@ -17,6 +17,4 @@ export declare abstract class McmaResource extends McmaObject implements McmaRes
17
17
  [key: string]: any;
18
18
  };
19
19
  protected constructor(type: string, properties: McmaResourceProperties);
20
- onCreate: (id: string) => void;
21
- onUpsert: (id: string) => void;
22
20
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.McmaResource = exports.onResourceUpsert = exports.onResourceCreate = void 0;
4
4
  const mcma_object_1 = require("./mcma-object");
5
+ const utils_1 = require("../utils");
5
6
  function onResourceCreate(resource, id) {
6
7
  resource.id = id;
7
8
  resource.dateModified = resource.dateCreated = new Date();
@@ -18,10 +19,8 @@ exports.onResourceUpsert = onResourceUpsert;
18
19
  class McmaResource extends mcma_object_1.McmaObject {
19
20
  constructor(type, properties) {
20
21
  super(type, properties);
21
- this.onCreate = (id) => onResourceCreate(this, id);
22
- this.onUpsert = (id) => onResourceUpsert(this, id);
23
- this.dateCreated = this.ensureValidDateOrUndefined(this.dateCreated);
24
- this.dateModified = this.ensureValidDateOrUndefined(this.dateModified);
22
+ this.dateCreated = utils_1.Utils.ensureValidDateOrUndefined(this.dateCreated);
23
+ this.dateModified = utils_1.Utils.ensureValidDateOrUndefined(this.dateModified);
25
24
  }
26
25
  }
27
26
  exports.McmaResource = McmaResource;
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.McmaTracker = void 0;
4
4
  const mcma_object_1 = require("./mcma-object");
5
+ const utils_1 = require("../utils");
5
6
  class McmaTracker extends mcma_object_1.McmaObject {
6
7
  constructor(properties) {
7
8
  super("McmaTracker", properties);
8
- this.checkProperty("id", "string", true);
9
- this.checkProperty("label", "string", true);
10
- this.checkProperty("custom", "object", false);
9
+ utils_1.Utils.checkProperty(this, "id", "string", true);
10
+ utils_1.Utils.checkProperty(this, "label", "string", true);
11
+ utils_1.Utils.checkProperty(this, "custom", "object", false);
11
12
  }
12
13
  }
13
14
  exports.McmaTracker = McmaTracker;
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NotificationEndpoint = void 0;
4
4
  const mcma_object_1 = require("./mcma-object");
5
+ const utils_1 = require("../utils");
5
6
  class NotificationEndpoint extends mcma_object_1.McmaObject {
6
7
  constructor(properties) {
7
8
  super("NotificationEndpoint", properties);
8
- this.checkProperty("httpEndpoint", "url", true);
9
+ utils_1.Utils.checkProperty(this, "httpEndpoint", "url", true);
9
10
  }
10
11
  }
11
12
  exports.NotificationEndpoint = NotificationEndpoint;
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Notification = void 0;
4
4
  const mcma_object_1 = require("./mcma-object");
5
+ const utils_1 = require("../utils");
5
6
  class Notification extends mcma_object_1.McmaObject {
6
7
  constructor(properties) {
7
8
  super("Notification", properties);
8
- this.checkProperty("source", "string", false);
9
- this.checkProperty("content", "object", true);
9
+ utils_1.Utils.checkProperty(this, "source", "string", false);
10
+ utils_1.Utils.checkProperty(this, "content", "object", true);
10
11
  }
11
12
  }
12
13
  exports.Notification = Notification;
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProblemDetail = void 0;
4
4
  const mcma_object_1 = require("./mcma-object");
5
+ const utils_1 = require("../utils");
5
6
  class ProblemDetail extends mcma_object_1.McmaObject {
6
7
  constructor(properties) {
7
8
  super("ProblemDetail", properties);
8
- this.checkProperty("type", "string", true);
9
- this.checkProperty("title", "string", true);
10
- this.checkProperty("detail", "string", false);
11
- this.checkProperty("instance", "string", false);
9
+ utils_1.Utils.checkProperty(this, "type", "string", true);
10
+ utils_1.Utils.checkProperty(this, "title", "string", true);
11
+ utils_1.Utils.checkProperty(this, "detail", "string", false);
12
+ utils_1.Utils.checkProperty(this, "instance", "string", false);
12
13
  }
13
14
  }
14
15
  exports.ProblemDetail = ProblemDetail;
@@ -3,12 +3,10 @@ export interface ResourceEndpointProperties extends McmaObjectProperties {
3
3
  resourceType: string;
4
4
  httpEndpoint: string;
5
5
  authType?: string;
6
- authContext?: any;
7
6
  }
8
7
  export declare class ResourceEndpoint extends McmaObject implements ResourceEndpointProperties {
9
8
  resourceType: string;
10
9
  httpEndpoint: string;
11
10
  authType?: string;
12
- authContext?: any;
13
11
  constructor(properties: ResourceEndpointProperties);
14
12
  }
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResourceEndpoint = void 0;
4
4
  const mcma_object_1 = require("./mcma-object");
5
+ const utils_1 = require("../utils");
5
6
  class ResourceEndpoint extends mcma_object_1.McmaObject {
6
7
  constructor(properties) {
7
8
  super("ResourceEndpoint", properties);
8
- this.checkProperty("resourceType", "string", true);
9
- this.checkProperty("httpEndpoint", "url", true);
10
- this.checkProperty("authType", "string", false);
9
+ utils_1.Utils.checkProperty(this, "resourceType", "string", true);
10
+ utils_1.Utils.checkProperty(this, "httpEndpoint", "url", true);
11
+ utils_1.Utils.checkProperty(this, "authType", "string", false);
11
12
  }
12
13
  }
13
14
  exports.ResourceEndpoint = ResourceEndpoint;
@@ -4,7 +4,6 @@ export interface ServiceProperties extends McmaResourceProperties {
4
4
  name: string;
5
5
  resources: ResourceEndpointProperties[];
6
6
  authType?: string;
7
- authContext?: any;
8
7
  jobType?: string;
9
8
  jobProfileIds?: string[];
10
9
  }
@@ -12,7 +11,6 @@ export declare class Service extends McmaResource implements ServiceProperties {
12
11
  name: string;
13
12
  resources: ResourceEndpoint[];
14
13
  authType?: string;
15
- authContext?: any;
16
14
  jobType?: string;
17
15
  jobProfileIds?: string[];
18
16
  constructor(properties: ServiceProperties);
@@ -3,27 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Service = void 0;
4
4
  const mcma_resource_1 = require("./mcma-resource");
5
5
  const resource_endpoint_1 = require("./resource-endpoint");
6
+ const utils_1 = require("../utils");
6
7
  class Service extends mcma_resource_1.McmaResource {
7
8
  constructor(properties) {
8
9
  super("Service", properties);
9
- this.checkProperty("name", "string", true);
10
- this.checkProperty("resources", "Array", true);
11
- this.checkProperty("authType", "string", false);
12
- this.checkProperty("jobType", "string", false);
13
- this.checkProperty("jobProfileIds", "Array", false);
14
- if (properties.authContext) {
15
- if (typeof properties.authContext === "string") {
16
- try {
17
- this.authContext = JSON.parse(properties.authContext);
18
- }
19
- catch {
20
- this.authContext = properties.authContext;
21
- }
22
- }
23
- else {
24
- this.authContext = properties.authContext;
25
- }
26
- }
10
+ utils_1.Utils.checkProperty(this, "name", "string", true);
11
+ utils_1.Utils.checkProperty(this, "resources", "Array", true);
12
+ utils_1.Utils.checkProperty(this, "authType", "string", false);
13
+ utils_1.Utils.checkProperty(this, "jobType", "string", false);
14
+ utils_1.Utils.checkProperty(this, "jobProfileIds", "Array", false);
27
15
  for (let i = 0; i < this.resources.length; i++) {
28
16
  this.resources[i] = new resource_endpoint_1.ResourceEndpoint(this.resources[i]);
29
17
  }
@@ -5,6 +5,8 @@ declare function fromBase64(base64Text: string): string;
5
5
  declare function sleep(timeout: number): Promise<void>;
6
6
  declare function isValidDateString(value: any): boolean;
7
7
  declare function reviver(this: any, key: string, value: any): any;
8
+ declare function ensureValidDateOrUndefined(maybeDate: any): Date | undefined;
9
+ declare function checkProperty(object: any, propertyName: string, expectedType: string, required?: boolean): void;
8
10
  export declare const Utils: {
9
11
  isValidUrl: typeof isValidUrl;
10
12
  getTypeName: typeof getTypeName;
@@ -13,5 +15,7 @@ export declare const Utils: {
13
15
  sleep: typeof sleep;
14
16
  isValidDateString: typeof isValidDateString;
15
17
  reviver: typeof reviver;
18
+ ensureValidDateOrUndefined: typeof ensureValidDateOrUndefined;
19
+ checkProperty: typeof checkProperty;
16
20
  };
17
21
  export {};
package/dist/lib/utils.js CHANGED
@@ -60,6 +60,46 @@ function reviver(key, value) {
60
60
  }
61
61
  return value;
62
62
  }
63
+ function ensureValidDateOrUndefined(maybeDate) {
64
+ if (maybeDate === undefined || maybeDate === null) {
65
+ return undefined;
66
+ }
67
+ const date = new Date(maybeDate);
68
+ if (isNaN(date.getTime())) {
69
+ return undefined;
70
+ }
71
+ return date;
72
+ }
73
+ function checkProperty(object, propertyName, expectedType, required) {
74
+ const propertyValue = object[propertyName];
75
+ const propertyType = typeof propertyValue;
76
+ if (propertyValue === undefined || propertyValue === null) {
77
+ if (required) {
78
+ throw new mcma_exception_1.McmaException("Resource of type '" + object["@type"] + "' requires property '" + propertyName + "' to be defined", null, object);
79
+ }
80
+ return;
81
+ }
82
+ if (expectedType === "url") {
83
+ if (propertyType !== "string" || !exports.Utils.isValidUrl(propertyValue)) {
84
+ throw new mcma_exception_1.McmaException("Resource of type '" + object["@type"] + "' requires property '" + propertyName + "' to have a valid URL", null, object);
85
+ }
86
+ }
87
+ else if (expectedType === "Array") {
88
+ if (!Array.isArray(propertyValue)) {
89
+ throw new mcma_exception_1.McmaException("Resource of type '" + object["@type"] + "' requires property '" + propertyName + "' to have type Array", null, object);
90
+ }
91
+ }
92
+ else if (expectedType === "object") {
93
+ if (propertyType !== "object" || Array.isArray(propertyValue)) {
94
+ throw new mcma_exception_1.McmaException("Resource of type '" + object["@type"] + "' requires property '" + propertyName + "' to have type object", null, object);
95
+ }
96
+ }
97
+ else {
98
+ if (expectedType !== propertyType) {
99
+ throw new mcma_exception_1.McmaException("Resource of type '" + object["@type"] + "' requires property '" + propertyName + "' to have type " + expectedType, null, object);
100
+ }
101
+ }
102
+ }
63
103
  exports.Utils = {
64
104
  isValidUrl,
65
105
  getTypeName,
@@ -68,4 +108,6 @@ exports.Utils = {
68
108
  sleep,
69
109
  isValidDateString,
70
110
  reviver,
111
+ ensureValidDateOrUndefined,
112
+ checkProperty,
71
113
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcma/core",
3
- "version": "0.14.4",
3
+ "version": "0.14.7",
4
4
  "description": "Node module with type definitions and helper utils for the EBU MCMA framework",
5
5
  "engines": {
6
6
  "node": "^14.17.0"