@things-factory/dataset 5.0.0-alpha.1 → 5.0.0-alpha.12

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.
Files changed (73) hide show
  1. package/client/bootstrap.js +15 -2
  2. package/client/pages/data-entry-form.js +75 -0
  3. package/client/pages/data-item-list.js +65 -16
  4. package/client/pages/data-sample.js +51 -16
  5. package/client/pages/data-sensor.js +446 -0
  6. package/client/pages/data-set.js +61 -16
  7. package/client/route.js +4 -0
  8. package/dist-server/index.js +1 -0
  9. package/dist-server/index.js.map +1 -1
  10. package/dist-server/routes.js +64 -0
  11. package/dist-server/routes.js.map +1 -1
  12. package/dist-server/service/data-item/data-item-mutation.js +5 -1
  13. package/dist-server/service/data-item/data-item-mutation.js.map +1 -1
  14. package/dist-server/service/data-item/data-item-type.js +15 -6
  15. package/dist-server/service/data-item/data-item-type.js.map +1 -1
  16. package/dist-server/service/data-item/data-item.js +26 -6
  17. package/dist-server/service/data-item/data-item.js.map +1 -1
  18. package/dist-server/service/data-sample/data-sample-mutation.js +41 -7
  19. package/dist-server/service/data-sample/data-sample-mutation.js.map +1 -1
  20. package/dist-server/service/data-sample/data-sample-type.js +23 -2
  21. package/dist-server/service/data-sample/data-sample-type.js.map +1 -1
  22. package/dist-server/service/data-sample/data-sample.js +44 -5
  23. package/dist-server/service/data-sample/data-sample.js.map +1 -1
  24. package/dist-server/service/data-sensor/data-sensor-mutation.js +120 -0
  25. package/dist-server/service/data-sensor/data-sensor-mutation.js.map +1 -0
  26. package/dist-server/service/data-sensor/data-sensor-query.js +108 -0
  27. package/dist-server/service/data-sensor/data-sensor-query.js.map +1 -0
  28. package/dist-server/service/data-sensor/data-sensor-type.js +147 -0
  29. package/dist-server/service/data-sensor/data-sensor-type.js.map +1 -0
  30. package/dist-server/service/data-sensor/data-sensor.js +168 -0
  31. package/dist-server/service/data-sensor/data-sensor.js.map +1 -0
  32. package/dist-server/service/data-sensor/index.js +9 -0
  33. package/dist-server/service/data-sensor/index.js.map +1 -0
  34. package/dist-server/service/data-set/data-set-type.js +18 -0
  35. package/dist-server/service/data-set/data-set-type.js.map +1 -1
  36. package/dist-server/service/data-set/data-set.js +22 -3
  37. package/dist-server/service/data-set/data-set.js.map +1 -1
  38. package/dist-server/service/data-spec/data-spec-manager.js +20 -0
  39. package/dist-server/service/data-spec/data-spec-manager.js.map +1 -0
  40. package/dist-server/service/data-spec/data-spec-query.js +48 -0
  41. package/dist-server/service/data-spec/data-spec-query.js.map +1 -0
  42. package/dist-server/service/data-spec/data-spec.js +78 -0
  43. package/dist-server/service/data-spec/data-spec.js.map +1 -0
  44. package/dist-server/service/data-spec/index.js +8 -0
  45. package/dist-server/service/data-spec/index.js.map +1 -0
  46. package/dist-server/service/index.js +10 -2
  47. package/dist-server/service/index.js.map +1 -1
  48. package/package.json +14 -11
  49. package/server/index.ts +2 -0
  50. package/server/routes.ts +76 -0
  51. package/server/service/data-item/data-item-mutation.ts +6 -1
  52. package/server/service/data-item/data-item-type.ts +11 -6
  53. package/server/service/data-item/data-item.ts +21 -5
  54. package/server/service/data-sample/data-sample-mutation.ts +51 -5
  55. package/server/service/data-sample/data-sample-type.ts +17 -2
  56. package/server/service/data-sample/data-sample.ts +37 -2
  57. package/server/service/data-sensor/data-sensor-mutation.ts +110 -0
  58. package/server/service/data-sensor/data-sensor-query.ts +56 -0
  59. package/server/service/data-sensor/data-sensor-type.ts +98 -0
  60. package/server/service/data-sensor/data-sensor.ts +139 -0
  61. package/server/service/data-sensor/index.ts +6 -0
  62. package/server/service/data-set/data-set-type.ts +14 -0
  63. package/server/service/data-set/data-set.ts +17 -1
  64. package/server/service/data-spec/data-spec-manager.ts +21 -0
  65. package/server/service/data-spec/data-spec-query.ts +21 -0
  66. package/server/service/data-spec/data-spec.ts +44 -0
  67. package/server/service/data-spec/index.ts +5 -0
  68. package/server/service/index.ts +12 -4
  69. package/things-factory.config.js +4 -0
  70. package/translations/en.json +18 -4
  71. package/translations/ko.json +17 -3
  72. package/translations/ms.json +18 -4
  73. package/translations/zh.json +18 -4
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DataSpecQuery = void 0;
16
+ const type_graphql_1 = require("type-graphql");
17
+ const data_spec_1 = require("./data-spec");
18
+ const data_spec_manager_1 = require("./data-spec-manager");
19
+ let DataSpecQuery = class DataSpecQuery {
20
+ dataSpec(name) {
21
+ return data_spec_manager_1.DataSpecManager.getDataSpec(name);
22
+ }
23
+ dataSpecs() {
24
+ const items = data_spec_manager_1.DataSpecManager.getDataSpecs();
25
+ return {
26
+ items,
27
+ total: items.length
28
+ };
29
+ }
30
+ };
31
+ __decorate([
32
+ (0, type_graphql_1.Query)(returns => data_spec_1.DataSpec, { description: 'To fetch a data-spec' }),
33
+ __param(0, (0, type_graphql_1.Arg)('name')),
34
+ __metadata("design:type", Function),
35
+ __metadata("design:paramtypes", [String]),
36
+ __metadata("design:returntype", data_spec_1.DataSpec)
37
+ ], DataSpecQuery.prototype, "dataSpec", null);
38
+ __decorate([
39
+ (0, type_graphql_1.Query)(returns => data_spec_1.DataSpecList, { description: 'To fetch all data-specs' }),
40
+ __metadata("design:type", Function),
41
+ __metadata("design:paramtypes", []),
42
+ __metadata("design:returntype", data_spec_1.DataSpecList)
43
+ ], DataSpecQuery.prototype, "dataSpecs", null);
44
+ DataSpecQuery = __decorate([
45
+ (0, type_graphql_1.Resolver)(data_spec_1.DataSpec)
46
+ ], DataSpecQuery);
47
+ exports.DataSpecQuery = DataSpecQuery;
48
+ //# sourceMappingURL=data-spec-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-spec-query.js","sourceRoot":"","sources":["../../../server/service/data-spec/data-spec-query.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAmD;AACnD,2CAAoD;AACpD,2DAAqD;AAGrD,IAAa,aAAa,GAA1B,MAAa,aAAa;IAExB,QAAQ,CAAc,IAAY;QAChC,OAAO,mCAAe,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC;IAGD,SAAS;QACP,MAAM,KAAK,GAAG,mCAAe,CAAC,YAAY,EAAE,CAAA;QAE5C,OAAO;YACL,KAAK;YACL,KAAK,EAAE,KAAK,CAAC,MAAM;SACpB,CAAA;IACH,CAAC;CACF,CAAA;AAbC;IADC,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,oBAAQ,EAAE,EAAE,WAAW,EAAE,sBAAsB,EAAE,CAAC;IAC1D,WAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;;;oCAAgB,oBAAQ;6CAE5C;AAGD;IADC,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,wBAAY,EAAE,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;;;oCAC9D,wBAAY;8CAOxB;AAdU,aAAa;IADzB,IAAA,uBAAQ,EAAC,oBAAQ,CAAC;GACN,aAAa,CAezB;AAfY,sCAAa"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var _a;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.DataSpecList = exports.DataSpec = exports.DataSpecItem = void 0;
14
+ const type_graphql_1 = require("type-graphql");
15
+ const shell_1 = require("@things-factory/shell");
16
+ let DataSpecItem = class DataSpecItem {
17
+ };
18
+ __decorate([
19
+ (0, type_graphql_1.Field)(),
20
+ __metadata("design:type", String)
21
+ ], DataSpecItem.prototype, "type", void 0);
22
+ __decorate([
23
+ (0, type_graphql_1.Field)(),
24
+ __metadata("design:type", String)
25
+ ], DataSpecItem.prototype, "label", void 0);
26
+ __decorate([
27
+ (0, type_graphql_1.Field)(),
28
+ __metadata("design:type", String)
29
+ ], DataSpecItem.prototype, "name", void 0);
30
+ __decorate([
31
+ (0, type_graphql_1.Field)({ nullable: true }),
32
+ __metadata("design:type", String)
33
+ ], DataSpecItem.prototype, "placeholder", void 0);
34
+ __decorate([
35
+ (0, type_graphql_1.Field)(type => shell_1.ScalarObject, { nullable: true }),
36
+ __metadata("design:type", typeof (_a = typeof shell_1.ScalarObject !== "undefined" && shell_1.ScalarObject) === "function" ? _a : Object)
37
+ ], DataSpecItem.prototype, "property", void 0);
38
+ DataSpecItem = __decorate([
39
+ (0, type_graphql_1.ObjectType)()
40
+ ], DataSpecItem);
41
+ exports.DataSpecItem = DataSpecItem;
42
+ let DataSpec = class DataSpec {
43
+ };
44
+ __decorate([
45
+ (0, type_graphql_1.Field)(),
46
+ __metadata("design:type", String)
47
+ ], DataSpec.prototype, "name", void 0);
48
+ __decorate([
49
+ (0, type_graphql_1.Field)({ nullable: true }),
50
+ __metadata("design:type", String)
51
+ ], DataSpec.prototype, "description", void 0);
52
+ __decorate([
53
+ (0, type_graphql_1.Field)({ nullable: true }),
54
+ __metadata("design:type", String)
55
+ ], DataSpec.prototype, "help", void 0);
56
+ __decorate([
57
+ (0, type_graphql_1.Field)(type => [DataSpecItem], { nullable: true }),
58
+ __metadata("design:type", Array)
59
+ ], DataSpec.prototype, "specItems", void 0);
60
+ DataSpec = __decorate([
61
+ (0, type_graphql_1.ObjectType)()
62
+ ], DataSpec);
63
+ exports.DataSpec = DataSpec;
64
+ let DataSpecList = class DataSpecList {
65
+ };
66
+ __decorate([
67
+ (0, type_graphql_1.Field)(type => [DataSpec]),
68
+ __metadata("design:type", Array)
69
+ ], DataSpecList.prototype, "items", void 0);
70
+ __decorate([
71
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int),
72
+ __metadata("design:type", Number)
73
+ ], DataSpecList.prototype, "total", void 0);
74
+ DataSpecList = __decorate([
75
+ (0, type_graphql_1.ObjectType)()
76
+ ], DataSpecList);
77
+ exports.DataSpecList = DataSpecList;
78
+ //# sourceMappingURL=data-spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-spec.js","sourceRoot":"","sources":["../../../server/service/data-spec/data-spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAAqD;AACrD,iDAAoD;AAGpD,IAAa,YAAY,GAAzB,MAAa,YAAY;CAexB,CAAA;AAbC;IADC,IAAA,oBAAK,GAAE;;0CACI;AAGZ;IADC,IAAA,oBAAK,GAAE;;2CACK;AAGb;IADC,IAAA,oBAAK,GAAE;;0CACI;AAGZ;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;iDACN;AAGpB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,oBAAY,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;kDACrC,oBAAY,oBAAZ,oBAAY;8CAAA;AAdZ,YAAY;IADxB,IAAA,yBAAU,GAAE;GACA,YAAY,CAexB;AAfY,oCAAY;AAkBzB,IAAa,QAAQ,GAArB,MAAa,QAAQ;CAYpB,CAAA;AAVC;IADC,IAAA,oBAAK,GAAE;;sCACI;AAGZ;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;6CACP;AAGnB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;sCACd;AAGZ;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;2CACzB;AAXd,QAAQ;IADpB,IAAA,yBAAU,GAAE;GACA,QAAQ,CAYpB;AAZY,4BAAQ;AAerB,IAAa,YAAY,GAAzB,MAAa,YAAY;CAMxB,CAAA;AAJC;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;;2CACT;AAGjB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,CAAC;;2CACN;AALF,YAAY;IADxB,IAAA,yBAAU,GAAE;GACA,YAAY,CAMxB;AANY,oCAAY"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvers = exports.entities = void 0;
4
+ const data_spec_1 = require("./data-spec");
5
+ const data_spec_query_1 = require("./data-spec-query");
6
+ exports.entities = [data_spec_1.DataSpec];
7
+ exports.resolvers = [data_spec_query_1.DataSpecQuery];
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/data-spec/index.ts"],"names":[],"mappings":";;;AAAA,2CAAsC;AACtC,uDAAiD;AAEpC,QAAA,QAAQ,GAAG,CAAC,oBAAQ,CAAC,CAAA;AACrB,QAAA,SAAS,GAAG,CAAC,+BAAa,CAAC,CAAA"}
@@ -16,25 +16,33 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.schema = exports.entities = void 0;
18
18
  /* IMPORT ENTITIES AND RESOLVERS */
19
+ const data_sensor_1 = require("./data-sensor");
19
20
  const data_sample_1 = require("./data-sample");
20
21
  const data_item_1 = require("./data-item");
21
22
  const data_set_1 = require("./data-set");
23
+ const data_spec_1 = require("./data-spec");
22
24
  /* EXPORT ENTITY TYPES */
25
+ __exportStar(require("./data-sensor/data-sensor"), exports);
23
26
  __exportStar(require("./data-sample/data-sample"), exports);
24
27
  __exportStar(require("./data-item/data-item"), exports);
25
28
  __exportStar(require("./data-set/data-set"), exports);
29
+ __exportStar(require("./data-spec/data-spec"), exports);
26
30
  exports.entities = [
27
31
  /* ENTITIES */
32
+ ...data_sensor_1.entities,
28
33
  ...data_sample_1.entities,
29
34
  ...data_item_1.entities,
30
- ...data_set_1.entities
35
+ ...data_set_1.entities,
36
+ ...data_spec_1.entities
31
37
  ];
32
38
  exports.schema = {
33
39
  resolverClasses: [
34
40
  /* RESOLVER CLASSES */
41
+ ...data_sensor_1.resolvers,
35
42
  ...data_sample_1.resolvers,
36
43
  ...data_item_1.resolvers,
37
- ...data_set_1.resolvers
44
+ ...data_set_1.resolvers,
45
+ ...data_spec_1.resolvers
38
46
  ]
39
47
  };
40
48
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAmC;AACnC,+CAAgG;AAChG,2CAA0F;AAC1F,yCAAuF;AAEvF,yBAAyB;AACzB,4DAAyC;AACzC,wDAAqC;AACrC,sDAAmC;AAEtB,QAAA,QAAQ,GAAG;IACtB,cAAc;IACf,GAAG,sBAAkB;IACpB,GAAG,oBAAgB;IACnB,GAAG,mBAAe;CACnB,CAAA;AAEY,QAAA,MAAM,GAAG;IACpB,eAAe,EAAE;QACf,sBAAsB;QACxB,GAAG,uBAAmB;QACpB,GAAG,qBAAiB;QACpB,GAAG,oBAAgB;KACpB;CACF,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAmC;AACnC,+CAAgG;AAChG,+CAAgG;AAChG,2CAA0F;AAC1F,yCAAuF;AACvF,2CAA0F;AAE1F,yBAAyB;AACzB,4DAAyC;AACzC,4DAAyC;AACzC,wDAAqC;AACrC,sDAAmC;AACnC,wDAAqC;AAExB,QAAA,QAAQ,GAAG;IACtB,cAAc;IACd,GAAG,sBAAkB;IACrB,GAAG,sBAAkB;IACrB,GAAG,oBAAgB;IACnB,GAAG,mBAAe;IAClB,GAAG,oBAAgB;CACpB,CAAA;AAEY,QAAA,MAAM,GAAG;IACpB,eAAe,EAAE;QACf,sBAAsB;QACtB,GAAG,uBAAmB;QACtB,GAAG,uBAAmB;QACtB,GAAG,qBAAiB;QACpB,GAAG,oBAAgB;QACnB,GAAG,qBAAiB;KACrB;CACF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/dataset",
3
- "version": "5.0.0-alpha.1",
3
+ "version": "5.0.0-alpha.12",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -24,15 +24,18 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
25
  },
26
26
  "dependencies": {
27
- "@operato/data-grist": "^0.4.1",
28
- "@operato/graphql": "^0.4.1",
29
- "@operato/i18n": "^0.4.1",
30
- "@operato/layout": "^0.4.1",
31
- "@operato/shell": "^0.4.1",
32
- "@operato/styles": "^0.4.1",
33
- "@operato/utils": "^0.4.1",
34
- "@things-factory/auth-base": "^5.0.0-alpha.1",
35
- "@things-factory/shell": "^5.0.0-alpha.1"
27
+ "@operato/app": "1.0.0-alpha.30",
28
+ "@operato/data-grist": "1.0.0-alpha.30",
29
+ "@operato/dataset": "1.0.0-alpha.30",
30
+ "@operato/graphql": "1.0.0-alpha.30",
31
+ "@operato/i18n": "1.0.0-alpha.30",
32
+ "@operato/layout": "1.0.0-alpha.30",
33
+ "@operato/shell": "1.0.0-alpha.30",
34
+ "@operato/styles": "1.0.0-alpha.30",
35
+ "@operato/utils": "1.0.0-alpha.30",
36
+ "@things-factory/auth-base": "^5.0.0-alpha.12",
37
+ "@things-factory/env": "^5.0.0-alpha.12",
38
+ "@things-factory/shell": "^5.0.0-alpha.12"
36
39
  },
37
- "gitHead": "2b3e3818a5d7ab7fdfff9214cc65f56885b27ad0"
40
+ "gitHead": "fdfb881f0a6ae429387c04494449ed50c2a117b0"
38
41
  }
package/server/index.ts CHANGED
@@ -3,3 +3,5 @@ import './routes'
3
3
  export * from './migrations'
4
4
  export * from './middlewares'
5
5
  export * from './service'
6
+
7
+ export * from './service/data-spec/data-spec-manager'
package/server/routes.ts CHANGED
@@ -1,3 +1,9 @@
1
+ import { getConnection } from 'typeorm'
2
+
3
+ import { DataSample } from './service'
4
+ import { DataItem } from './service/data-item/data-item'
5
+ import { DataSensor } from './service/data-sensor/data-sensor'
6
+
1
7
  const debug = require('debug')('things-factory:dataset:routes')
2
8
 
3
9
  process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
@@ -7,6 +13,76 @@ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRout
7
13
  * ex) routes.get('/path', async(context, next) => {})
8
14
  * ex) routes.post('/path', async(context, next) => {})
9
15
  */
16
+
17
+ globalPublicRouter.post('/sensor-data', async (context, next) => {
18
+ // 데이타 검증
19
+ const { deviceId, data, rawData, timestamp = Date.now() } = context.request.body
20
+ if (!deviceId || !data) {
21
+ throw new Error(`deviceId(${deviceId}) and data(${JSON.stringify(data)}) properties are mandatory`)
22
+ }
23
+
24
+ // make new data-sample
25
+ await getConnection().transaction(async tx => {
26
+ // find sensor through deviceId
27
+ const sensor = await tx.getRepository(DataSensor).findOne({
28
+ where: { deviceId },
29
+ relations: ['domain', 'appliance', 'dataSet']
30
+ })
31
+
32
+ if (!sensor) {
33
+ throw new Error(`Sensor having given deviceId(${deviceId}) not found`)
34
+ }
35
+
36
+ if (!sensor.active) {
37
+ throw new Error(`State of the sensor given deviceId(${deviceId}) is not active`)
38
+ }
39
+
40
+ if (!sensor.appliance) {
41
+ throw new Error(`Appliance of the sensor given deviceId(${deviceId}) is not set up`)
42
+ }
43
+
44
+ if (!sensor.dataSet) {
45
+ throw new Error(`DataSet of the sensor given deviceId(${deviceId}) is not set up`)
46
+ }
47
+
48
+ const domain = sensor.domain
49
+ const dataSet = sensor.dataSet
50
+ const user = sensor.appliance
51
+
52
+ const dataItems = await tx.getRepository(DataItem).find({
53
+ where: {
54
+ domain,
55
+ dataSet
56
+ },
57
+ order: {
58
+ sequence: 'DESC'
59
+ }
60
+ })
61
+
62
+ var spec = {} as any
63
+
64
+ dataItems.forEach(dataItem => {
65
+ spec[dataItem.name] = dataItem.spec
66
+ })
67
+
68
+ await tx.getRepository(DataSample).save({
69
+ domain,
70
+ name: dataSet.name,
71
+ description: dataSet.description,
72
+ partitionKeys: dataSet.partitionKeys,
73
+ dataSet,
74
+ data,
75
+ rawData,
76
+ spec,
77
+ source: deviceId,
78
+ collectedAt: new Date(timestamp),
79
+ creator: user,
80
+ updater: user
81
+ })
82
+ })
83
+
84
+ return 'OK'
85
+ })
10
86
  })
11
87
 
12
88
  process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
@@ -24,9 +24,14 @@ export class DataItemMutation {
24
24
  await dataItemRepo.delete({ domain, dataSet: dataSetId })
25
25
 
26
26
  for (let i = 0; i < patches.length; i++) {
27
+ const patch = patches[i]
28
+ if (!patch.options) {
29
+ patch.options = {}
30
+ }
31
+
27
32
  const result = await dataItemRepo.save({
28
33
  quota: 1,
29
- ...patches[i],
34
+ ...patch,
30
35
  sequence: i,
31
36
  dataSet,
32
37
  domain,
@@ -1,9 +1,8 @@
1
+ import { DataItem, DataItemType } from './data-item'
1
2
  import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
2
3
 
3
4
  import { ScalarObject } from '@things-factory/shell'
4
5
 
5
- import { DataItem, DataItemType } from './data-item'
6
-
7
6
  @InputType()
8
7
  export class DataItemPatch {
9
8
  @Field(type => ID, { nullable: true })
@@ -21,20 +20,26 @@ export class DataItemPatch {
21
20
  @Field(type => Int, { nullable: true })
22
21
  sequence?: number
23
22
 
23
+ @Field({ nullable: true })
24
+ tag?: string
25
+
24
26
  @Field(type => DataItemType, { nullable: true })
25
27
  type?: DataItemType
26
28
 
27
- @Field(type => Int, { nullable: true })
28
- quota?: number
29
+ @Field(type => ScalarObject, { nullable: true })
30
+ options?: ScalarObject
29
31
 
30
32
  @Field({ nullable: true })
31
- options?: string
33
+ unit?: string
34
+
35
+ @Field(type => Int, { nullable: true })
36
+ quota?: number
32
37
 
33
38
  @Field({ nullable: true })
34
39
  active?: boolean
35
40
 
36
41
  @Field(type => ScalarObject, { nullable: true })
37
- spec?: object
42
+ spec?: ScalarObject
38
43
 
39
44
  @Field({ nullable: true })
40
45
  cuFlag?: string
@@ -1,4 +1,3 @@
1
- import { Field, ID, Int, ObjectType, registerEnumType } from 'type-graphql'
2
1
  import {
3
2
  Column,
4
3
  CreateDateColumn,
@@ -9,17 +8,18 @@ import {
9
8
  RelationId,
10
9
  UpdateDateColumn
11
10
  } from 'typeorm'
12
-
13
- import { User } from '@things-factory/auth-base'
14
11
  import { Domain, ScalarObject } from '@things-factory/shell'
12
+ import { Field, ID, Int, ObjectType, registerEnumType } from 'type-graphql'
15
13
 
16
14
  import { DataSet } from '../data-set/data-set'
15
+ import { User } from '@things-factory/auth-base'
17
16
 
18
17
  export enum DataItemType {
19
18
  number = 'number',
20
19
  text = 'text',
21
20
  boolean = 'boolean',
22
- select = 'select'
21
+ select = 'select',
22
+ file = 'file'
23
23
  }
24
24
 
25
25
  registerEnumType(DataItemType, {
@@ -63,6 +63,12 @@ export class DataItem {
63
63
  @Field(type => Int, { nullable: true })
64
64
  sequence: number
65
65
 
66
+ @Column({
67
+ nullable: true
68
+ })
69
+ @Field({ nullable: true })
70
+ tag?: string
71
+
66
72
  @Column({
67
73
  nullable: true
68
74
  })
@@ -75,6 +81,16 @@ export class DataItem {
75
81
  @Field({ nullable: true })
76
82
  type?: DataItemType
77
83
 
84
+ @Column('simple-json', { nullable: true })
85
+ @Field(type => ScalarObject, { nullable: true })
86
+ options?: ScalarObject
87
+
88
+ @Column({
89
+ nullable: true
90
+ })
91
+ @Field({ nullable: true })
92
+ unit?: string
93
+
78
94
  @Column({
79
95
  nullable: true
80
96
  })
@@ -83,7 +99,7 @@ export class DataItem {
83
99
 
84
100
  @Column('simple-json', { nullable: true })
85
101
  @Field(type => ScalarObject, { nullable: true })
86
- spec?: object
102
+ spec?: ScalarObject
87
103
 
88
104
  @CreateDateColumn()
89
105
  @Field({ nullable: true })
@@ -6,6 +6,35 @@ import { DataSet } from '../data-set/data-set'
6
6
  import { DataSample } from './data-sample'
7
7
  import { DataSamplePatch, NewDataSample } from './data-sample-type'
8
8
 
9
+ import moment from 'moment'
10
+
11
+ const debug = require('debug')('things-factory:dataset:data-sample:data-sample-mutation')
12
+
13
+ // parse variable javascript string pattern
14
+ const replaceVariables = (keys, dic) => {
15
+ for (const k in keys) {
16
+ const matches = keys[k].match(/\$\{\w*\}/g)
17
+ matches &&
18
+ matches.forEach(m => {
19
+ keys[k] = keys[k].replace(m, dic[m.slice(2, -1)])
20
+ })
21
+ }
22
+ return keys
23
+ }
24
+
25
+ // It is required UTC date for Partitioning File System like AWS S3.
26
+ // ex) %YYYY, %MM, %DD
27
+ const formatDate = (keys, _moment) => {
28
+ for (const k in keys) {
29
+ const matches = keys[k].match(/%\w*/g)
30
+ matches &&
31
+ matches.forEach(m => {
32
+ keys[k] = keys[k].replace(m, _moment.format(m.substr(1)))
33
+ })
34
+ }
35
+ return keys
36
+ }
37
+
9
38
  @Resolver(DataSample)
10
39
  export class DataSampleMutation {
11
40
  @Directive('@privilege(category: "data-sample", privilege: "mutation", domainOwnerGranted: true)')
@@ -16,19 +45,34 @@ export class DataSampleMutation {
16
45
 
17
46
  const dataSet = await tx.getRepository(DataSet).findOne({ id: dataSample.dataSetId })
18
47
  const dataItems = await tx.getRepository(DataItem).find({
19
- select: {
48
+ where: {
20
49
  domain,
21
- dataSetId: dataSample.dataSetId
50
+ dataSet
22
51
  },
23
52
  order: {
24
53
  sequence: 'DESC'
25
54
  }
26
55
  })
27
56
 
28
- var spec = {} as any
57
+ const spec = dataItems.reduce((spec, dataItem) => {
58
+ spec[dataItem.tag] = {
59
+ ...dataItem.spec,
60
+ name: dataItem.name /* do we need ? */
61
+ }
62
+
63
+ return spec
64
+ }, {})
65
+
66
+ var partitionKeys = {
67
+ ...dataSet.partitionKeys
68
+ }
29
69
 
30
- dataItems.sortforEach(dataItem => {
31
- spec[dataItem.name] = dataItem.spec
70
+ const collectedAt = dataSample.collectedAt || new Date()
71
+ partitionKeys = formatDate(partitionKeys, moment(collectedAt).utc())
72
+ partitionKeys = replaceVariables(partitionKeys, {
73
+ domainId: domain.id,
74
+ dataSetId: dataSample.dataSetId,
75
+ ...dataSample.data
32
76
  })
33
77
 
34
78
  return await tx.getRepository(DataSample).save({
@@ -36,7 +80,9 @@ export class DataSampleMutation {
36
80
  description: dataSet.description,
37
81
  ...dataSample,
38
82
  domain,
83
+ partitionKeys,
39
84
  spec,
85
+ collectedAt,
40
86
  creator: user,
41
87
  updater: user
42
88
  })
@@ -16,7 +16,16 @@ export class NewDataSample {
16
16
  dataSetId?: string
17
17
 
18
18
  @Field(type => ScalarObject, { nullable: true })
19
- data?: object
19
+ data?: ScalarObject
20
+
21
+ @Field({ nullable: true })
22
+ rawData?: string
23
+
24
+ @Field({ nullable: true })
25
+ source?: string
26
+
27
+ @Field({ nullable: true })
28
+ collectedAt?: Date
20
29
  }
21
30
 
22
31
  @InputType()
@@ -34,7 +43,13 @@ export class DataSamplePatch {
34
43
  dataSetId?: string
35
44
 
36
45
  @Field(type => ScalarObject, { nullable: true })
37
- data?: object
46
+ data?: ScalarObject
47
+
48
+ @Field({ nullable: true })
49
+ rawData?: string
50
+
51
+ @Field({ nullable: true })
52
+ source?: string
38
53
 
39
54
  @Field()
40
55
  cuFlag: string
@@ -11,10 +11,13 @@ import {
11
11
  } from 'typeorm'
12
12
 
13
13
  import { User } from '@things-factory/auth-base'
14
+ import { config } from '@things-factory/env'
14
15
  import { Domain, ScalarObject } from '@things-factory/shell'
15
16
 
16
17
  import { DataSet } from '../data-set/data-set'
17
18
 
19
+ const ORMCONFIG = config.get('ormconfig', {})
20
+ const DATABASE_TYPE = ORMCONFIG.type
18
21
  @Entity()
19
22
  @Index('ix_data_sample_0', (dataSample: DataSample) => [dataSample.domain, dataSample.dataSet], { unique: false })
20
23
  @ObjectType({ description: 'Entity for DataSample' })
@@ -40,6 +43,16 @@ export class DataSample {
40
43
  @Field({ nullable: true })
41
44
  description?: string
42
45
 
46
+ @Column({
47
+ nullable: true
48
+ })
49
+ @Field({ nullable: true })
50
+ type?: string
51
+
52
+ @Column('simple-json', { nullable: true })
53
+ @Field(type => ScalarObject, { nullable: true })
54
+ partitionKeys?: ScalarObject
55
+
43
56
  @ManyToOne(type => DataSet, dataSet => dataSet.dataSamples)
44
57
  @Field(type => DataSet, { nullable: true })
45
58
  dataSet?: DataSet
@@ -50,11 +63,33 @@ export class DataSample {
50
63
 
51
64
  @Column('simple-json', { nullable: true })
52
65
  @Field(type => ScalarObject, { nullable: true })
53
- data?: object
66
+ data?: ScalarObject
54
67
 
55
68
  @Column('simple-json', { nullable: true })
56
69
  @Field(type => ScalarObject, { nullable: true })
57
- spec?: object
70
+ spec?: ScalarObject
71
+
72
+ @Column({
73
+ nullable: true,
74
+ type:
75
+ DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
76
+ ? 'longtext'
77
+ : DATABASE_TYPE == 'oracle'
78
+ ? 'clob'
79
+ : 'varchar'
80
+ })
81
+ @Field({ nullable: true })
82
+ rawData?: string
83
+
84
+ @Column({
85
+ nullable: true
86
+ })
87
+ @Field({ nullable: true })
88
+ source?: string
89
+
90
+ @Column({ nullable: true })
91
+ @Field({ nullable: true })
92
+ collectedAt?: Date
58
93
 
59
94
  @CreateDateColumn()
60
95
  @Field({ nullable: true })