@things-factory/dataset 6.2.136 → 6.2.138

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const typeorm_1 = require("typeorm");
4
4
  const shell_1 = require("@things-factory/shell");
5
+ const auth_base_1 = require("@things-factory/auth-base");
5
6
  const integration_base_1 = require("@things-factory/integration-base");
6
7
  const create_data_sample_1 = require("./controllers/create-data-sample");
7
8
  const jasper_report_1 = require("./controllers/jasper-report");
@@ -39,18 +40,20 @@ process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) =>
39
40
  if (!sensor.appliance) {
40
41
  throw new Error(`Appliance of the sensor given deviceId(${deviceId}) is not set up`);
41
42
  }
42
- // if (!sensor.dataSet) {
43
- // throw new Error(`DataSet of the sensor given deviceId(${deviceId}) is not set up`)
44
- // }
45
43
  const domain = sensor.domain;
46
44
  const dataSet = sensor.dataSet;
47
- // const user: User = await tx.getRepository(User).findOne({
48
- // where: {
49
- // reference: sensor.appliance.id,
50
- // userType: 'appliance'
51
- // }
52
- // })
53
- context.state = Object.assign(Object.assign({}, context.state), { domain,
45
+ /*
46
+ 원칙적으로 user 인증정보를 가지고 요청해야 하지만, 인증정보를 보낼 수 없는 상황이라고 전제하여 처리한다.
47
+ 앞으로, 보완되어야 한다.
48
+ */
49
+ const user = context.user ||
50
+ (await tx.getRepository(auth_base_1.User).findOne({
51
+ where: {
52
+ reference: sensor.appliance.id,
53
+ userType: 'appliance'
54
+ }
55
+ }));
56
+ context.state = Object.assign(Object.assign({ user }, context.state), { domain,
54
57
  tx });
55
58
  var decoded;
56
59
  if (sensor.decoder) {
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,qCAA4B;AAE5B,iDAA6D;AAE7D,uEAA8D;AAG9D,yEAAmE;AACnE,+DAAgE;AAChE,6DAA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,CAAA;QACnC,OAAO,CAAC,IAAI,GAAG,GAAG,UAAU,mBAAmB,CAAA;IACjD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { In } from 'typeorm'\n\nimport { Domain, getDataSource } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\nimport { runScenario } from '@things-factory/integration-base'\nimport { ScheduleRegisterRequest } from '@things-factory/scheduler-client'\n\nimport { createDataSample } from './controllers/create-data-sample'\nimport { renderJasperReport } from './controllers/jasper-report'\nimport { renderShinyReport } from './controllers/shiny-report'\nimport { issueCollectData } from './controllers/issue-collect-data'\nimport { DataSensor } from './service/data-sensor/data-sensor'\nimport { DataSet } from './service/data-set/data-set'\n\nprocess.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {\n /*\n * can add global public routes to application (auth not required, tenancy not required)\n *\n * ex) routes.get('/path', async(context, next) => {})\n * ex) routes.post('/path', async(context, next) => {})\n */\n\n globalPublicRouter.post('/sensor-data', async (context, next) => {\n // 데이타 검증\n const { deviceId, data, rawData, timestamp = Date.now() } = context.request.body\n if (!deviceId) {\n throw new Error(`The deviceId(${deviceId}) property are mandatory`)\n }\n\n // make new data-sample\n await getDataSource().transaction(async tx => {\n // find sensor through deviceId\n const sensor = await tx.getRepository(DataSensor).findOne({\n where: { deviceId },\n relations: ['domain', 'appliance', 'dataSet', 'decoder']\n })\n\n if (!sensor) {\n throw new Error(`Sensor having given deviceId(${deviceId}) not found`)\n }\n\n if (!sensor.active) {\n throw new Error(`State of the sensor given deviceId(${deviceId}) is not active`)\n }\n\n if (!sensor.appliance) {\n throw new Error(`Appliance of the sensor given deviceId(${deviceId}) is not set up`)\n }\n\n // if (!sensor.dataSet) {\n // throw new Error(`DataSet of the sensor given deviceId(${deviceId}) is not set up`)\n // }\n\n const domain = sensor.domain\n const dataSet = sensor.dataSet\n // const user: User = await tx.getRepository(User).findOne({\n // where: {\n // reference: sensor.appliance.id,\n // userType: 'appliance'\n // }\n // })\n\n context.state = {\n ...context.state,\n domain,\n tx\n }\n\n var decoded\n if (sensor.decoder) {\n const { name: scenarioName } = sensor.decoder\n const variables = {\n dataSensor: sensor,\n source: deviceId,\n data,\n rawData,\n timestamp\n }\n\n decoded = (await runScenario(null, scenarioName, variables, context))?.result\n }\n\n if (dataSet) {\n await createDataSample(\n {\n dataSet,\n data,\n rawData,\n source: deviceId,\n collectedAt: new Date(timestamp),\n ...decoded\n },\n context\n )\n }\n\n context.status = 200\n context.body = {\n data,\n ...decoded\n }\n })\n })\n\n /* When a callback occurs from the scheduler when a scheduled dataset is on schedule, data collection task for the dataset should be issued. */\n globalPublicRouter.post('/callback-schedule-for-dataset', async (context, next) => {\n const { client } = context.request.body as ScheduleRegisterRequest\n\n if (!client || typeof client !== 'object') {\n throw new Error('client property should be a part of callback body.')\n }\n\n const { group: domainId, key: dataSetId } = client\n\n if (!domainId || !dataSetId) {\n throw new Error(`group(${domainId}) and key(${dataSetId}) properties should not be empty`)\n }\n\n await issueCollectData(domainId, dataSetId, context)\n\n context.status = 200\n })\n\n /* When a callback occurs from the scheduler when a scheduled summary is on schedule, data summary procedure for the dataset should be executed. */\n globalPublicRouter.post('/callback-schedule-for-data-summary', async (context, next) => {\n const { client } = context.request.body as ScheduleRegisterRequest\n\n if (!client || typeof client !== 'object') {\n throw new Error('client property should be a part of callback body.')\n }\n\n const { group: domainId, key: dataSetId } = client\n\n if (!domainId || !dataSetId) {\n throw new Error(`group(${domainId}) and key(${dataSetId}) properties should not be empty`)\n }\n\n await getDataSource().transaction(async tx => {\n const domain = await tx.getRepository(Domain).findOneBy({ id: domainId })\n\n if (!domain) {\n throw new Error(`domain(${domainId}) not found`)\n }\n\n const dataSet = await tx.getRepository(DataSet).findOne({ where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id: dataSetId } })\n\n // do what you gotta do\n })\n\n context.status = 200\n })\n})\n\nprocess.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {\n /*\n * can add global private routes to application (auth required, tenancy not required)\n */\n})\n\nprocess.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {\n /*\n * can add domain public routes to application (auth not required, tenancy required)\n */\n})\n\nprocess.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {\n /*\n * can add domain private routes to application (auth required, tenancy required)\n */\n domainPrivateRouter.get('/data-report/jasper', async (context, next) => {\n context.body = await renderJasperReport(context)\n })\n\n domainPrivateRouter.get('/data-report/shiny', async (context, next) => {\n await renderShinyReport(context)\n })\n\n domainPrivateRouter.get('/data-report/:reportType', async (context, next) => {\n let { reportType } = context.params\n context.body = `${reportType} Not Implemented.`\n })\n})\n"]}
1
+ {"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,qCAA4B;AAE5B,iDAA6D;AAC7D,yDAAgD;AAChD,uEAA8D;AAG9D,yEAAmE;AACnE,+DAAgE;AAChE,6DAA8D;AAC9D,yEAAmE;AACnE,mEAA8D;AAC9D,0DAAqD;AAErD,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF;;;;;OAKG;IAEH,kBAAkB,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC9D,SAAS;QACT,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAA;QAChF,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,gBAAgB,QAAQ,0BAA0B,CAAC,CAAA;SACpE;QAED,uBAAuB;QACvB,MAAM,IAAA,qBAAa,GAAE,CAAC,WAAW,CAAC,KAAK,EAAC,EAAE,EAAC,EAAE;;YAC3C,+BAA+B;YAC/B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CA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AAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF;;OAEG;AACL,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACtF;;OAEG;IACH,mBAAmB,CAAC,GAAG,CAAC,qBAAqB,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QACrE,OAAO,CAAC,IAAI,GAAG,MAAM,IAAA,kCAAkB,EAAC,OAAO,CAAC,CAAA;IAClD,CAAC,CAAC,CAAA;IAEF,mBAAmB,CAAC,GAAG,CAAC,oBAAoB,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QACpE,MAAM,IAAA,gCAAiB,EAAC,OAAO,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,mBAAmB,CAAC,GAAG,CAAC,0BAA0B,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC1E,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,MAAM,CAAA;QACnC,OAAO,CAAC,IAAI,GAAG,GAAG,UAAU,mBAAmB,CAAA;IACjD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { In } from 'typeorm'\n\nimport { Domain, getDataSource } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\nimport { runScenario } from '@things-factory/integration-base'\nimport { ScheduleRegisterRequest } from '@things-factory/scheduler-client'\n\nimport { createDataSample } from './controllers/create-data-sample'\nimport { renderJasperReport } from './controllers/jasper-report'\nimport { renderShinyReport } from './controllers/shiny-report'\nimport { issueCollectData } from './controllers/issue-collect-data'\nimport { DataSensor } from './service/data-sensor/data-sensor'\nimport { DataSet } from './service/data-set/data-set'\n\nprocess.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {\n /*\n * can add global public routes to application (auth not required, tenancy not required)\n *\n * ex) routes.get('/path', async(context, next) => {})\n * ex) routes.post('/path', async(context, next) => {})\n */\n\n globalPublicRouter.post('/sensor-data', async (context, next) => {\n // 데이타 검증\n const { deviceId, data, rawData, timestamp = Date.now() } = context.request.body\n if (!deviceId) {\n throw new Error(`The deviceId(${deviceId}) property are mandatory`)\n }\n\n // make new data-sample\n await getDataSource().transaction(async tx => {\n // find sensor through deviceId\n const sensor = await tx.getRepository(DataSensor).findOne({\n where: { deviceId },\n relations: ['domain', 'appliance', 'dataSet', 'decoder']\n })\n\n if (!sensor) {\n throw new Error(`Sensor having given deviceId(${deviceId}) not found`)\n }\n\n if (!sensor.active) {\n throw new Error(`State of the sensor given deviceId(${deviceId}) is not active`)\n }\n\n if (!sensor.appliance) {\n throw new Error(`Appliance of the sensor given deviceId(${deviceId}) is not set up`)\n }\n\n const domain = sensor.domain\n const dataSet = sensor.dataSet\n\n /* \n 원칙적으로 user 인증정보를 가지고 요청해야 하지만, 인증정보를 보낼 수 없는 상황이라고 전제하여 처리한다.\n 앞으로, 보완되어야 한다.\n */\n const user: User =\n context.user ||\n (await tx.getRepository(User).findOne({\n where: {\n reference: sensor.appliance.id,\n userType: 'appliance'\n }\n }))\n\n context.state = {\n user,\n ...context.state,\n domain,\n tx\n }\n\n var decoded\n if (sensor.decoder) {\n const { name: scenarioName } = sensor.decoder\n const variables = {\n dataSensor: sensor,\n source: deviceId,\n data,\n rawData,\n timestamp\n }\n\n decoded = (await runScenario(null, scenarioName, variables, context))?.result\n }\n\n if (dataSet) {\n await createDataSample(\n {\n dataSet,\n data,\n rawData,\n source: deviceId,\n collectedAt: new Date(timestamp),\n ...decoded\n },\n context\n )\n }\n\n context.status = 200\n context.body = {\n data,\n ...decoded\n }\n })\n })\n\n /* When a callback occurs from the scheduler when a scheduled dataset is on schedule, data collection task for the dataset should be issued. */\n globalPublicRouter.post('/callback-schedule-for-dataset', async (context, next) => {\n const { client } = context.request.body as ScheduleRegisterRequest\n\n if (!client || typeof client !== 'object') {\n throw new Error('client property should be a part of callback body.')\n }\n\n const { group: domainId, key: dataSetId } = client\n\n if (!domainId || !dataSetId) {\n throw new Error(`group(${domainId}) and key(${dataSetId}) properties should not be empty`)\n }\n\n await issueCollectData(domainId, dataSetId, context)\n\n context.status = 200\n })\n\n /* When a callback occurs from the scheduler when a scheduled summary is on schedule, data summary procedure for the dataset should be executed. */\n globalPublicRouter.post('/callback-schedule-for-data-summary', async (context, next) => {\n const { client } = context.request.body as ScheduleRegisterRequest\n\n if (!client || typeof client !== 'object') {\n throw new Error('client property should be a part of callback body.')\n }\n\n const { group: domainId, key: dataSetId } = client\n\n if (!domainId || !dataSetId) {\n throw new Error(`group(${domainId}) and key(${dataSetId}) properties should not be empty`)\n }\n\n await getDataSource().transaction(async tx => {\n const domain = await tx.getRepository(Domain).findOneBy({ id: domainId })\n\n if (!domain) {\n throw new Error(`domain(${domainId}) not found`)\n }\n\n const dataSet = await tx.getRepository(DataSet).findOne({ where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id: dataSetId } })\n\n // do what you gotta do\n })\n\n context.status = 200\n })\n})\n\nprocess.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {\n /*\n * can add global private routes to application (auth required, tenancy not required)\n */\n})\n\nprocess.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {\n /*\n * can add domain public routes to application (auth not required, tenancy required)\n */\n})\n\nprocess.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {\n /*\n * can add domain private routes to application (auth required, tenancy required)\n */\n domainPrivateRouter.get('/data-report/jasper', async (context, next) => {\n context.body = await renderJasperReport(context)\n })\n\n domainPrivateRouter.get('/data-report/shiny', async (context, next) => {\n await renderShinyReport(context)\n })\n\n domainPrivateRouter.get('/data-report/:reportType', async (context, next) => {\n let { reportType } = context.params\n context.body = `${reportType} Not Implemented.`\n })\n})\n"]}