@things-factory/integration-base 6.2.158 → 6.2.163

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.
@@ -77,7 +77,8 @@ class ConnectionManager {
77
77
  }
78
78
  static getConnectionInstances(domain) {
79
79
  const connections = ConnectionManager.connections[domain.id];
80
- return Object.assign({}, connections);
80
+ const parentConnections = domain.parentId && ConnectionManager.connections[domain.parentId];
81
+ return Object.assign(Object.assign({}, parentConnections), connections);
81
82
  }
82
83
  static addConnectionInstance(connection, instance) {
83
84
  const { domain, name } = connection;
@@ -1 +1 @@
1
- {"version":3,"file":"connection-manager.js","sourceRoot":"","sources":["../../server/engine/connection-manager.ts"],"names":[],"mappings":";;;;AAAA,8EAAoC;AACpC,qCAA0D;AAE1D,iDAAyF;AAEzF,wCAAyD;AAGzD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,gBAAM,CAAA;AACpD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,6CAA6C,CAAC,CAAA;AAE7E,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAA;AAClE,MAAM,eAAe,GAAG,IAAA,gBAAM,EAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;IAC5C,IAAI,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,SAAS,GAAG,IAAA,yBAAM,GAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAA;IAC3D,OAAO,IAAI,CAAA;AACb,CAAC,CAAC,CAAA;AAEF,MAAa,iBAAiB;IAwB5B,MAAM,CAAC,KAAK,CAAC,KAAK;QAChB,MAAM,WAAW,GAAG,CAClB,MAAM,IAAA,qBAAa,EAAC,oBAAU,CAAC,CAAC,IAAI,CAAC;YACnC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;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AE,KAAK;YACd,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,MAAM;SACd,CAAC;QACF,IAAI,0BAAkB,CAAC;YACrB,KAAK,EAAE,gBAAgB;SACxB,CAAC;KACH;CACF,CAAC,CAAA","sourcesContent":["import moment from 'moment-timezone'\nimport { createLogger, format, transports } from 'winston'\n\nimport { Domain, getRepository, pubsub, PubSubLogTransport } from '@things-factory/shell'\n\nimport { Connection, ConnectionStatus } from '../service'\nimport { Connector } from './types'\n\nconst { combine, timestamp, splat, printf } = format\nconst debug = require('debug')('things-factory:integration-base:connections')\n\nconst SYSTEM_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone\nconst systemTimestamp = format((info, opts) => {\n if (opts.tz) info.timestamp = moment().tz(opts.tz).format()\n return info\n})\n\nexport class ConnectionManager {\n private static connectors: { [propName: string]: Connector } = {}\n private static connections = {}\n private static logFormat = printf(({ level, message, timestamp }) => {\n return `${timestamp} ${level}: ${message}`\n })\n\n public static logger = createLogger({\n format: combine(systemTimestamp({ tz: SYSTEM_TZ }), splat(), ConnectionManager.logFormat),\n transports: [\n new (transports as any).DailyRotateFile({\n filename: `logs/connections-%DATE%.log`,\n datePattern: 'YYYY-MM-DD-HH',\n zippedArchive: false,\n maxSize: '20m',\n maxFiles: '14d',\n level: 'info'\n }),\n new PubSubLogTransport({\n topic: 'connection-log'\n })\n ]\n })\n\n static async ready() {\n const CONNECTIONS = (\n await getRepository(Connection).find({\n where: { active: true },\n relations: ['domain', 'creator', 'updater']\n })\n ).map(connection => {\n var params = {}\n try {\n params = JSON.parse(connection.params || '{}')\n } catch (ex) {\n ConnectionManager.logger.error(`connection '${connection.name}' params should be JSON format`)\n ConnectionManager.logger.error(ex)\n }\n\n return {\n ...connection,\n params\n }\n })\n\n ConnectionManager.logger.info('Initializing ConnectionManager...')\n\n return await Promise.all(\n Object.keys(ConnectionManager.connectors).map(type => {\n var connector = ConnectionManager.connectors[type]\n ConnectionManager.logger.info(`Connector '${type}' started to ready`)\n\n return connector\n .ready(CONNECTIONS.filter(connection => connection.type == type) as any)\n .catch(error => {\n ConnectionManager.logger.error(error.message)\n })\n .then(() => {\n ConnectionManager.logger.info(`All connector for '${type}' ready`)\n })\n })\n ).then(() => {\n ConnectionManager.logger.info('ConnectionManager initialization done:')\n Object.keys(ConnectionManager.connections).forEach(key => {\n var connections = ConnectionManager.connections[key]\n ConnectionManager.logger.info('For domain(%s) : %s', key, JSON.stringify(Object.keys(connections)))\n })\n })\n }\n\n static registerConnector(type: string, connector: Connector) {\n ConnectionManager.connectors[type] = connector\n }\n\n static getConnector(type: string): Connector {\n return ConnectionManager.connectors[type]\n }\n\n static getConnectors(): { [connectorName: string]: Connector } {\n return {\n ...ConnectionManager.connectors\n }\n }\n\n static unregisterConnector(type: string) {\n delete ConnectionManager.connectors[type]\n }\n\n static getConnectionInstance(connection: Connection): any {\n const { domain, name } = connection\n return ConnectionManager.connections[domain.id]?.[name]\n }\n\n static getConnectionInstanceByName(domain: Domain, name: string) {\n const connections = ConnectionManager.connections[domain.id]\n const connection = connections?.[name]\n\n if (!connection) {\n throw `The connection with the given name(${name}) cannot be found`\n }\n\n return connection\n }\n\n static getConnectionInstances(domain: Domain): { [connectionName: string]: any } {\n const connections = ConnectionManager.connections[domain.id]\n\n return {\n ...connections\n }\n }\n\n static addConnectionInstance(connection: Connection, instance: any) {\n const { domain, name } = connection\n\n var connections = ConnectionManager.connections[domain.id]\n if (!connections) {\n connections = ConnectionManager.connections[domain.id] = {}\n }\n\n connections[name] = instance\n\n ConnectionManager.publishState(connection, ConnectionStatus.CONNECTED)\n debug('add-connection', domain.subdomain, name)\n }\n\n static removeConnectionInstance(connection: Connection): any {\n const { domain, name } = connection\n var connections = ConnectionManager.connections[domain.id]\n var instance = connections?.[name]\n\n if (!connections || !instance) {\n debug('remove-connection', `'${name}' connection not found in domain '${domain.subdomain}'`)\n return\n }\n\n delete connections[name]\n\n ConnectionManager.publishState(connection, ConnectionStatus.DISCONNECTED)\n debug('remove-connection', `'${name}' connection is removed from domain '${domain.subdomain}'`)\n\n return instance\n }\n\n static publishState(connection: Connection, state) {\n const { domain, id, name, description, type } = connection\n\n pubsub.publish('connection-state', {\n connectionState: {\n domain,\n id,\n name,\n description,\n type,\n state,\n timestamp: new Date()\n }\n })\n }\n}\n"]}
1
+ {"version":3,"file":"connection-manager.js","sourceRoot":"","sources":["../../server/engine/connection-manager.ts"],"names":[],"mappings":";;;;AAAA,8EAAoC;AACpC,qCAA0D;AAE1D,iDAAyF;AAEzF,wCAAyD;AAGzD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,gBAAM,CAAA;AACpD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,6CAA6C,CAAC,CAAA;AAE7E,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAA;AAClE,MAAM,eAAe,GAAG,IAAA,gBAAM,EAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;IAC5C,IAAI,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,SAAS,GAAG,IAAA,yBAAM,GAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAA;IAC3D,OAAO,IAAI,CAAA;AACb,CAAC,CAAC,CAAA;AAEF,MAAa,iBAAiB;IAwB5B,MAAM,CAAC,KAAK,CAAC,KAAK;QAChB,MAAM,WAAW,GAAG,CAClB,MAAM,IAAA,qBAAa,EAAC,oBAAU,CAAC,CAAC,IAAI,CAAC;YACnC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;YACvB,SAAS,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC;SAC5C,CAAC,CACH,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YACjB,IAAI,MAAM,GAAG,EAAE,CAAA;YACf,IAAI;gBACF,MAAM,GAAG,IAAI,CAAC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;QACF,IAAI,0BAAkB,CAAC;YACrB,KAAK,EAAE,gBAAgB;SACxB,CAAC;KACH;CACF,CAAC,CAAA","sourcesContent":["import moment from 'moment-timezone'\nimport { createLogger, format, transports } from 'winston'\n\nimport { Domain, getRepository, pubsub, PubSubLogTransport } from '@things-factory/shell'\n\nimport { Connection, ConnectionStatus } from '../service'\nimport { Connector } from './types'\n\nconst { combine, timestamp, splat, printf } = format\nconst debug = require('debug')('things-factory:integration-base:connections')\n\nconst SYSTEM_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone\nconst systemTimestamp = format((info, opts) => {\n if (opts.tz) info.timestamp = moment().tz(opts.tz).format()\n return info\n})\n\nexport class ConnectionManager {\n private static connectors: { [propName: string]: Connector } = {}\n private static connections = {}\n private static logFormat = printf(({ level, message, timestamp }) => {\n return `${timestamp} ${level}: ${message}`\n })\n\n public static logger = createLogger({\n format: combine(systemTimestamp({ tz: SYSTEM_TZ }), splat(), ConnectionManager.logFormat),\n transports: [\n new (transports as any).DailyRotateFile({\n filename: `logs/connections-%DATE%.log`,\n datePattern: 'YYYY-MM-DD-HH',\n zippedArchive: false,\n maxSize: '20m',\n maxFiles: '14d',\n level: 'info'\n }),\n new PubSubLogTransport({\n topic: 'connection-log'\n })\n ]\n })\n\n static async ready() {\n const CONNECTIONS = (\n await getRepository(Connection).find({\n where: { active: true },\n relations: ['domain', 'creator', 'updater']\n })\n ).map(connection => {\n var params = {}\n try {\n params = JSON.parse(connection.params || '{}')\n } catch (ex) {\n ConnectionManager.logger.error(`connection '${connection.name}' params should be JSON format`)\n ConnectionManager.logger.error(ex)\n }\n\n return {\n ...connection,\n params\n }\n })\n\n ConnectionManager.logger.info('Initializing ConnectionManager...')\n\n return await Promise.all(\n Object.keys(ConnectionManager.connectors).map(type => {\n var connector = ConnectionManager.connectors[type]\n ConnectionManager.logger.info(`Connector '${type}' started to ready`)\n\n return connector\n .ready(CONNECTIONS.filter(connection => connection.type == type) as any)\n .catch(error => {\n ConnectionManager.logger.error(error.message)\n })\n .then(() => {\n ConnectionManager.logger.info(`All connector for '${type}' ready`)\n })\n })\n ).then(() => {\n ConnectionManager.logger.info('ConnectionManager initialization done:')\n Object.keys(ConnectionManager.connections).forEach(key => {\n var connections = ConnectionManager.connections[key]\n ConnectionManager.logger.info('For domain(%s) : %s', key, JSON.stringify(Object.keys(connections)))\n })\n })\n }\n\n static registerConnector(type: string, connector: Connector) {\n ConnectionManager.connectors[type] = connector\n }\n\n static getConnector(type: string): Connector {\n return ConnectionManager.connectors[type]\n }\n\n static getConnectors(): { [connectorName: string]: Connector } {\n return {\n ...ConnectionManager.connectors\n }\n }\n\n static unregisterConnector(type: string) {\n delete ConnectionManager.connectors[type]\n }\n\n static getConnectionInstance(connection: Connection): any {\n const { domain, name } = connection\n return ConnectionManager.connections[domain.id]?.[name]\n }\n\n static getConnectionInstanceByName(domain: Domain, name: string) {\n const connections = ConnectionManager.connections[domain.id]\n const connection = connections?.[name]\n\n if (!connection) {\n throw `The connection with the given name(${name}) cannot be found`\n }\n\n return connection\n }\n\n static getConnectionInstances(domain: Domain): { [connectionName: string]: any } {\n const connections = ConnectionManager.connections[domain.id]\n const parentConnections = domain.parentId && ConnectionManager.connections[domain.parentId]\n\n return {\n ...parentConnections,\n ...connections\n }\n }\n\n static addConnectionInstance(connection: Connection, instance: any) {\n const { domain, name } = connection\n\n var connections = ConnectionManager.connections[domain.id]\n if (!connections) {\n connections = ConnectionManager.connections[domain.id] = {}\n }\n\n connections[name] = instance\n\n ConnectionManager.publishState(connection, ConnectionStatus.CONNECTED)\n debug('add-connection', domain.subdomain, name)\n }\n\n static removeConnectionInstance(connection: Connection): any {\n const { domain, name } = connection\n var connections = ConnectionManager.connections[domain.id]\n var instance = connections?.[name]\n\n if (!connections || !instance) {\n debug('remove-connection', `'${name}' connection not found in domain '${domain.subdomain}'`)\n return\n }\n\n delete connections[name]\n\n ConnectionManager.publishState(connection, ConnectionStatus.DISCONNECTED)\n debug('remove-connection', `'${name}' connection is removed from domain '${domain.subdomain}'`)\n\n return instance\n }\n\n static publishState(connection: Connection, state) {\n const { domain, id, name, description, type } = connection\n\n pubsub.publish('connection-state', {\n connectionState: {\n domain,\n id,\n name,\n description,\n type,\n state,\n timestamp: new Date()\n }\n })\n }\n}\n"]}
@@ -9,15 +9,19 @@ const shell_1 = require("@things-factory/shell");
9
9
  const engine_1 = require("../../engine");
10
10
  const step_type_1 = require("../step/step-type");
11
11
  let Scenario = class Scenario {
12
- async start(instanceName, variables) {
12
+ async start(options) {
13
13
  try {
14
- await engine_1.ScenarioEngine.load(instanceName || this.name, this, { domain: this.domain, user: this.updater, variables });
14
+ await engine_1.ScenarioEngine.load((options === null || options === void 0 ? void 0 : options.instanceName) || this.name, this, {
15
+ domain: (options === null || options === void 0 ? void 0 : options.domain) || this.domain,
16
+ user: (options === null || options === void 0 ? void 0 : options.user) || this.updater,
17
+ variables: options === null || options === void 0 ? void 0 : options.variables
18
+ });
15
19
  }
16
20
  catch (ex) { }
17
21
  }
18
- async stop(instanceName) {
22
+ async stop(options) {
19
23
  try {
20
- await engine_1.ScenarioEngine.unload(this.domain, instanceName || this.name);
24
+ await engine_1.ScenarioEngine.unload((options === null || options === void 0 ? void 0 : options.domain) || this.domain, (options === null || options === void 0 ? void 0 : options.instanceName) || this.name);
21
25
  }
22
26
  finally {
23
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scenario.js","sourceRoot":"","sources":["../../../server/service/scenario/scenario.ts"],"names":[],"mappings":";;;;AAAA,+CAAoE;AACpE,qCAUgB;AAEhB,yDAAiF;AACjF,iDAA8C;AAE9C,yCAA6C;AAC7C,iDAAwC;AAKjC,IAAM,QAAQ,GAAd,MAAM,QAAQ;IA0EnB,KAAK,CAAC,KAAK,CAAC,YAAY,EAAE,SAAe;QACvC,IAAI;YACF,MAAM,uBAAc,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM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;IAAC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCAChB,gBAAI;yCAAA;AAEd;IAAC,IAAA,oBAAU,EAAC,CAAC,QAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;;2CACnC;AAElB;IAAC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCAChB,gBAAI;yCAAA;AAEd;IAAC,IAAA,oBAAU,EAAC,CAAC,QAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;;2CACnC;AAxEP,QAAQ;IAHpB,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,eAAe,EAAE,CAAC,QAAkB,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAClG,IAAA,yBAAU,GAAE;GACA,QAAQ,CAsFpB;AAtFY,4BAAQ","sourcesContent":["import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'\nimport {\n Column,\n CreateDateColumn,\n Entity,\n Index,\n ManyToOne,\n OneToMany,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\n\nimport { PrivilegeObject, PrivilegeInput, User } from '@things-factory/auth-base'\nimport { Domain } from '@things-factory/shell'\n\nimport { ScenarioEngine } from '../../engine'\nimport { Step } from '../step/step-type'\n\n@Entity()\n@Index('ix_scenario_0', (scenario: Scenario) => [scenario.domain, scenario.name], { unique: true })\n@ObjectType()\nexport class Scenario {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID)\n id?: string\n\n @ManyToOne(type => Domain)\n @Field({ nullable: true })\n domain?: Domain\n\n @RelationId((scenario: Scenario) => scenario.domain)\n domainId?: string\n\n @Column()\n @Field()\n name?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n description?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n type?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'accessible and executable system-wide' })\n public?: boolean\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: '[will be deprecated] automatically be started when this server start' })\n active?: boolean\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n schedule?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n scheduleId?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n timezone?: string\n\n @OneToMany(type => Step, step => step.scenario)\n @Field(type => [Step], { nullable: true })\n steps?: Step[]\n\n @Column({ type: 'simple-json', nullable: true })\n @Field(type => PrivilegeObject, { nullable: true })\n privilege?: PrivilegeObject\n\n @CreateDateColumn()\n @Field({ nullable: true })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true })\n updatedAt?: Date\n\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true })\n creator?: User\n\n @RelationId((scenario: Scenario) => scenario.creator)\n creatorId?: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true })\n updater?: User\n\n @RelationId((scenario: Scenario) => scenario.updater)\n updaterId?: string\n\n async start(instanceName, variables?: any) {\n try {\n await ScenarioEngine.load(instanceName || this.name, this, { domain: this.domain, user: this.updater, variables })\n } catch (ex) {}\n }\n\n async stop(instanceName?) {\n try {\n await ScenarioEngine.unload(this.domain, instanceName || this.name)\n } finally {\n }\n }\n}\n"]}
1
+ {"version":3,"file":"scenario.js","sourceRoot":"","sources":["../../../server/service/scenario/scenario.ts"],"names":[],"mappings":";;;;AAAA,+CAAoE;AACpE,qCAUgB;AAEhB,yDAAiF;AACjF,iDAA8C;AAE9C,yCAA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M,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAClG,IAAA,yBAAU,GAAE;GACA,QAAQ,CAqGpB;AArGY,4BAAQ","sourcesContent":["import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'\nimport {\n Column,\n CreateDateColumn,\n Entity,\n Index,\n ManyToOne,\n OneToMany,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\n\nimport { PrivilegeObject, PrivilegeInput, User } from '@things-factory/auth-base'\nimport { Domain } from '@things-factory/shell'\n\nimport { ScenarioEngine } from '../../engine'\nimport { Step } from '../step/step-type'\n\n@Entity()\n@Index('ix_scenario_0', (scenario: Scenario) => [scenario.domain, scenario.name], { unique: true })\n@ObjectType()\nexport class Scenario {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID)\n id?: string\n\n @ManyToOne(type => Domain)\n @Field({ nullable: true })\n domain?: Domain\n\n @RelationId((scenario: Scenario) => scenario.domain)\n domainId?: string\n\n @Column()\n @Field()\n name?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n description?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n type?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'accessible and executable system-wide' })\n public?: boolean\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: '[will be deprecated] automatically be started when this server start' })\n active?: boolean\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n schedule?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n scheduleId?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n timezone?: string\n\n @OneToMany(type => Step, step => step.scenario)\n @Field(type => [Step], { nullable: true })\n steps?: Step[]\n\n @Column({ type: 'simple-json', nullable: true })\n @Field(type => PrivilegeObject, { nullable: true })\n privilege?: PrivilegeObject\n\n @CreateDateColumn()\n @Field({ nullable: true })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true })\n updatedAt?: Date\n\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true })\n creator?: User\n\n @RelationId((scenario: Scenario) => scenario.creator)\n creatorId?: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true })\n updater?: User\n\n @RelationId((scenario: Scenario) => scenario.updater)\n updaterId?: string\n\n async start(options?: {\n instanceName?: string;\n domain?: Domain;\n user?: User;\n variables?: any;\n }) {\n try {\n await ScenarioEngine.load(options?.instanceName || this.name, \n this, \n { \n domain: options?.domain || this.domain, \n user: options?.user || this.updater, \n variables: options?.variables \n })\n } catch (ex) {}\n }\n\n async stop(options?: {\n instanceName?: string;\n domain?: Domain,\n user?: User\n }) {\n try {\n await ScenarioEngine.unload(options?.domain || this.domain, options?.instanceName || this.name)\n } finally {\n }\n }\n}\n"]}