@things-factory/dataset 5.0.0-alpha.15 → 5.0.0-alpha.19
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.
- package/client/pages/data-item-list.js +1 -1
- package/client/pages/data-ooc-view.js +134 -0
- package/client/pages/data-ooc.js +54 -4
- package/client/pages/data-sample-view.js +96 -0
- package/client/pages/data-sample.js +19 -1
- package/client/pages/data-set.js +2 -2
- package/dist-server/controllers/create-data-sample.js +104 -0
- package/dist-server/controllers/create-data-sample.js.map +1 -0
- package/dist-server/routes.js +9 -24
- package/dist-server/routes.js.map +1 -1
- package/dist-server/service/data-ooc/data-ooc-subscription.js +65 -0
- package/dist-server/service/data-ooc/data-ooc-subscription.js.map +1 -0
- package/dist-server/service/data-ooc/data-ooc.js +7 -0
- package/dist-server/service/data-ooc/data-ooc.js.map +1 -1
- package/dist-server/service/data-ooc/index.js +2 -1
- package/dist-server/service/data-ooc/index.js.map +1 -1
- package/dist-server/service/data-sample/data-sample-mutation.js +2 -80
- package/dist-server/service/data-sample/data-sample-mutation.js.map +1 -1
- package/dist-server/service/data-sample/data-sample.js +10 -3
- package/dist-server/service/data-sample/data-sample.js.map +1 -1
- package/package.json +14 -14
- package/server/controllers/create-data-sample.ts +143 -0
- package/server/routes.ts +18 -32
- package/server/service/data-ooc/data-ooc-subscription.ts +51 -0
- package/server/service/data-ooc/data-ooc.ts +6 -0
- package/server/service/data-ooc/index.ts +2 -1
- package/server/service/data-sample/data-sample-mutation.ts +2 -105
- package/server/service/data-sample/data-sample.ts +9 -4
- package/translations/en.json +3 -1
- package/translations/ko.json +3 -1
- package/translations/ms.json +4 -2
- package/translations/zh.json +4 -2
@@ -0,0 +1,134 @@
|
|
1
|
+
import '@operato/dataset/ox-data-sample-view.js'
|
2
|
+
|
3
|
+
import { LitElement, css, html } from 'lit'
|
4
|
+
import { i18next, localize } from '@operato/i18n'
|
5
|
+
|
6
|
+
import { ScrollbarStyles } from '@operato/styles'
|
7
|
+
import { client } from '@operato/graphql'
|
8
|
+
import gql from 'graphql-tag'
|
9
|
+
|
10
|
+
class DataOocView extends localize(i18next)(LitElement) {
|
11
|
+
static get properties() {
|
12
|
+
return {
|
13
|
+
dataSet: Object,
|
14
|
+
dataSample: Object
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
static get styles() {
|
19
|
+
return [
|
20
|
+
ScrollbarStyles,
|
21
|
+
css`
|
22
|
+
:host {
|
23
|
+
display: flex;
|
24
|
+
flex-direction: column;
|
25
|
+
|
26
|
+
background-color: #fff;
|
27
|
+
}
|
28
|
+
|
29
|
+
div[content] {
|
30
|
+
flex: 1;
|
31
|
+
|
32
|
+
display: flex;
|
33
|
+
overflow: scroll;
|
34
|
+
}
|
35
|
+
|
36
|
+
ox-data-sample-view {
|
37
|
+
flex: 1;
|
38
|
+
}
|
39
|
+
|
40
|
+
.button-container {
|
41
|
+
display: flex;
|
42
|
+
margin-left: auto;
|
43
|
+
padding: var(--padding-default);
|
44
|
+
}
|
45
|
+
`
|
46
|
+
]
|
47
|
+
}
|
48
|
+
|
49
|
+
get sampleView() {
|
50
|
+
return this.renderRoot.querySelector('ox-data-sample-view')
|
51
|
+
}
|
52
|
+
|
53
|
+
render() {
|
54
|
+
return html`
|
55
|
+
<div content>
|
56
|
+
<ox-data-sample-view .dataSet=${this.dataSet} .dataSample=${this.dataSample}></ox-data-sample-view>
|
57
|
+
</div>
|
58
|
+
|
59
|
+
<div class="button-container">
|
60
|
+
<mwc-button raised @click=${this._updateDataSample.bind(this)}>${i18next.t('button.save')}</mwc-button>
|
61
|
+
</div>
|
62
|
+
`
|
63
|
+
}
|
64
|
+
|
65
|
+
updated(changes) {
|
66
|
+
if (changes.has('dataSample')) {
|
67
|
+
this.fetchDataSet()
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
async fetchDataSet() {
|
72
|
+
const id = this.dataSample?.dataSet?.id
|
73
|
+
|
74
|
+
if (id) {
|
75
|
+
const response = await client.query({
|
76
|
+
query: gql`
|
77
|
+
query ($id: String!) {
|
78
|
+
dataSet(id: $id) {
|
79
|
+
id
|
80
|
+
name
|
81
|
+
description
|
82
|
+
useCase
|
83
|
+
dataItems {
|
84
|
+
id
|
85
|
+
name
|
86
|
+
description
|
87
|
+
active
|
88
|
+
unit
|
89
|
+
tag
|
90
|
+
type
|
91
|
+
spec
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
`,
|
96
|
+
variables: {
|
97
|
+
id: this.dataSample.dataSet.id
|
98
|
+
}
|
99
|
+
})
|
100
|
+
|
101
|
+
this.dataSet = response.data.dataSet
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
async _updateDataSample() {
|
106
|
+
// const data = this.sampleView.buildValue()
|
107
|
+
// const dataSample = {
|
108
|
+
// dataSet: {
|
109
|
+
// id: this.dataSet.id
|
110
|
+
// },
|
111
|
+
// data
|
112
|
+
// }
|
113
|
+
// const response = await client.mutate({
|
114
|
+
// mutation: gql`
|
115
|
+
// mutation ($dataSample: NewDataSample!) {
|
116
|
+
// createDataSample(dataSample: $dataSample) {
|
117
|
+
// id
|
118
|
+
// collectedAt
|
119
|
+
// }
|
120
|
+
// }
|
121
|
+
// `,
|
122
|
+
// variables: {
|
123
|
+
// dataSample
|
124
|
+
// }
|
125
|
+
// })
|
126
|
+
// if (!response.errors) {
|
127
|
+
// document.dispatchEvent(
|
128
|
+
// new CustomEvent('notify', { detail: { message: i18next.t('text.data sample created successfully') } })
|
129
|
+
// )
|
130
|
+
// }
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
window.customElements.define('data-ooc-view', DataOocView)
|
package/client/pages/data-ooc.js
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
import '@operato/data-grist'
|
2
|
+
import './data-ooc-view.js'
|
2
3
|
|
3
4
|
import { CommonButtonStyles, ScrollbarStyles } from '@operato/styles'
|
4
5
|
import { PageView, store } from '@operato/shell'
|
5
6
|
import { css, html } from 'lit'
|
6
7
|
import { i18next, localize } from '@operato/i18n'
|
8
|
+
import { notify, openPopup } from '@operato/layout'
|
7
9
|
|
8
10
|
import { client } from '@operato/graphql'
|
9
11
|
import { connect } from 'pwa-helpers/connect-mixin'
|
10
12
|
import gql from 'graphql-tag'
|
11
13
|
import { isMobileDevice } from '@operato/utils'
|
12
|
-
import { notify } from '@operato/layout'
|
13
14
|
|
14
15
|
export class DataOoc extends connect(store)(localize(i18next)(PageView)) {
|
15
16
|
static get properties() {
|
@@ -56,9 +57,9 @@ export class DataOoc extends connect(store)(localize(i18next)(PageView)) {
|
|
56
57
|
help: 'integration/ui/data-ooc',
|
57
58
|
actions: [
|
58
59
|
{
|
59
|
-
title: i18next.t('button.
|
60
|
-
action: this.
|
61
|
-
...CommonButtonStyles.
|
60
|
+
title: i18next.t('button.save'),
|
61
|
+
action: this._updateDataOoc.bind(this),
|
62
|
+
...CommonButtonStyles.save
|
62
63
|
}
|
63
64
|
],
|
64
65
|
exportable: {
|
@@ -117,6 +118,23 @@ export class DataOoc extends connect(store)(localize(i18next)(PageView)) {
|
|
117
118
|
columns: [
|
118
119
|
{ type: 'gutter', gutterName: 'sequence' },
|
119
120
|
{ type: 'gutter', gutterName: 'row-selector', multiple: true },
|
121
|
+
{
|
122
|
+
type: 'gutter',
|
123
|
+
gutterName: 'button',
|
124
|
+
icon: 'assignment_turned_in',
|
125
|
+
handlers: {
|
126
|
+
click: (columns, data, column, record, rowIndex) => {
|
127
|
+
openPopup(
|
128
|
+
html` <data-ooc-view .dataSample=${record} style="background-color: white;"></data-ooc-view> `,
|
129
|
+
{
|
130
|
+
backdrop: true,
|
131
|
+
size: 'large',
|
132
|
+
title: i18next.t('title.data-ooc view')
|
133
|
+
}
|
134
|
+
)
|
135
|
+
}
|
136
|
+
}
|
137
|
+
},
|
120
138
|
{
|
121
139
|
type: 'string',
|
122
140
|
name: 'name',
|
@@ -350,6 +368,38 @@ export class DataOoc extends connect(store)(localize(i18next)(PageView)) {
|
|
350
368
|
}
|
351
369
|
}
|
352
370
|
|
371
|
+
async _updateDataOoc() {
|
372
|
+
let patches = this.grist.dirtyRecords
|
373
|
+
if (patches && patches.length) {
|
374
|
+
patches = patches.map(patch => {
|
375
|
+
let patchField = patch.id ? { id: patch.id } : {}
|
376
|
+
const dirtyFields = patch.__dirtyfields__
|
377
|
+
for (let key in dirtyFields) {
|
378
|
+
patchField[key] = dirtyFields[key].after
|
379
|
+
}
|
380
|
+
this._setDefaultFieldsValue(patchField)
|
381
|
+
patchField.cuFlag = patch.__dirty__
|
382
|
+
|
383
|
+
return patchField
|
384
|
+
})
|
385
|
+
|
386
|
+
const response = await client.mutate({
|
387
|
+
mutation: gql`
|
388
|
+
mutation ($patches: [DataOocPatch!]!) {
|
389
|
+
updateMultipleDataOoc(patches: $patches) {
|
390
|
+
name
|
391
|
+
}
|
392
|
+
}
|
393
|
+
`,
|
394
|
+
variables: {
|
395
|
+
patches
|
396
|
+
}
|
397
|
+
})
|
398
|
+
|
399
|
+
if (!response.errors) this.grist.fetch()
|
400
|
+
}
|
401
|
+
}
|
402
|
+
|
353
403
|
async _deleteDataOoc() {
|
354
404
|
if (confirm(i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }))) {
|
355
405
|
const ids = this.grist.selected.map(record => record.id)
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import '@operato/dataset/ox-data-sample-view.js'
|
2
|
+
|
3
|
+
import { LitElement, css, html } from 'lit'
|
4
|
+
import { i18next, localize } from '@operato/i18n'
|
5
|
+
|
6
|
+
import { ScrollbarStyles } from '@operato/styles'
|
7
|
+
import { client } from '@operato/graphql'
|
8
|
+
import gql from 'graphql-tag'
|
9
|
+
|
10
|
+
class DataSampleView extends localize(i18next)(LitElement) {
|
11
|
+
static get properties() {
|
12
|
+
return {
|
13
|
+
dataSet: Object,
|
14
|
+
dataSample: Object
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
static get styles() {
|
19
|
+
return [
|
20
|
+
ScrollbarStyles,
|
21
|
+
css`
|
22
|
+
:host {
|
23
|
+
display: flex;
|
24
|
+
flex-direction: column;
|
25
|
+
|
26
|
+
background-color: #fff;
|
27
|
+
}
|
28
|
+
|
29
|
+
div[content] {
|
30
|
+
flex: 1;
|
31
|
+
|
32
|
+
display: flex;
|
33
|
+
overflow: scroll;
|
34
|
+
}
|
35
|
+
|
36
|
+
ox-data-sample-view {
|
37
|
+
flex: 1;
|
38
|
+
}
|
39
|
+
`
|
40
|
+
]
|
41
|
+
}
|
42
|
+
|
43
|
+
get sampleView() {
|
44
|
+
return this.renderRoot.querySelector('ox-data-sample-view')
|
45
|
+
}
|
46
|
+
|
47
|
+
render() {
|
48
|
+
return html`
|
49
|
+
<div content>
|
50
|
+
<ox-data-sample-view .dataSet=${this.dataSet} .dataSample=${this.dataSample}></ox-data-sample-view>
|
51
|
+
</div>
|
52
|
+
`
|
53
|
+
}
|
54
|
+
|
55
|
+
updated(changes) {
|
56
|
+
if (changes.has('dataSample')) {
|
57
|
+
this.fetchDataSet()
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
async fetchDataSet() {
|
62
|
+
const id = this.dataSample?.dataSet?.id
|
63
|
+
|
64
|
+
if (id) {
|
65
|
+
const response = await client.query({
|
66
|
+
query: gql`
|
67
|
+
query ($id: String!) {
|
68
|
+
dataSet(id: $id) {
|
69
|
+
id
|
70
|
+
name
|
71
|
+
description
|
72
|
+
useCase
|
73
|
+
dataItems {
|
74
|
+
id
|
75
|
+
name
|
76
|
+
description
|
77
|
+
active
|
78
|
+
unit
|
79
|
+
tag
|
80
|
+
type
|
81
|
+
spec
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
`,
|
86
|
+
variables: {
|
87
|
+
id: this.dataSample.dataSet.id
|
88
|
+
}
|
89
|
+
})
|
90
|
+
|
91
|
+
this.dataSet = response.data.dataSet
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
window.customElements.define('data-sample-view', DataSampleView)
|
@@ -1,15 +1,16 @@
|
|
1
1
|
import '@operato/data-grist'
|
2
|
+
import './data-sample-view.js'
|
2
3
|
|
3
4
|
import { PageView, store } from '@operato/shell'
|
4
5
|
import { css, html } from 'lit'
|
5
6
|
import { i18next, localize } from '@operato/i18n'
|
7
|
+
import { notify, openPopup } from '@operato/layout'
|
6
8
|
|
7
9
|
import { ScrollbarStyles } from '@operato/styles'
|
8
10
|
import { client } from '@operato/graphql'
|
9
11
|
import { connect } from 'pwa-helpers/connect-mixin'
|
10
12
|
import gql from 'graphql-tag'
|
11
13
|
import { isMobileDevice } from '@operato/utils'
|
12
|
-
import { notify } from '@operato/layout'
|
13
14
|
|
14
15
|
export class DataSample extends connect(store)(localize(i18next)(PageView)) {
|
15
16
|
static get properties() {
|
@@ -109,6 +110,23 @@ export class DataSample extends connect(store)(localize(i18next)(PageView)) {
|
|
109
110
|
columns: [
|
110
111
|
{ type: 'gutter', gutterName: 'sequence' },
|
111
112
|
{ type: 'gutter', gutterName: 'row-selector', multiple: true },
|
113
|
+
{
|
114
|
+
type: 'gutter',
|
115
|
+
gutterName: 'button',
|
116
|
+
icon: 'assignment',
|
117
|
+
handlers: {
|
118
|
+
click: (columns, data, column, record, rowIndex) => {
|
119
|
+
openPopup(
|
120
|
+
html` <data-sample-view .dataSample=${record} style="background-color: white;"></data-sample-view> `,
|
121
|
+
{
|
122
|
+
backdrop: true,
|
123
|
+
size: 'large',
|
124
|
+
title: i18next.t('title.data-sample view')
|
125
|
+
}
|
126
|
+
)
|
127
|
+
}
|
128
|
+
}
|
129
|
+
},
|
112
130
|
{
|
113
131
|
type: 'string',
|
114
132
|
name: 'name',
|
package/client/pages/data-set.js
CHANGED
@@ -9,7 +9,7 @@ import { css, html } from 'lit'
|
|
9
9
|
import { i18next, localize } from '@operato/i18n'
|
10
10
|
import { notify, openPopup } from '@operato/layout'
|
11
11
|
|
12
|
-
import {
|
12
|
+
import { OxDataUseCase } from '@operato/dataset'
|
13
13
|
import { client } from '@operato/graphql'
|
14
14
|
import { connect } from 'pwa-helpers/connect-mixin'
|
15
15
|
import gql from 'graphql-tag'
|
@@ -233,7 +233,7 @@ export class DataSet extends connect(store)(localize(i18next)(PageView)) {
|
|
233
233
|
record: {
|
234
234
|
editable: true,
|
235
235
|
options: () => {
|
236
|
-
return ['', ...
|
236
|
+
return ['', ...OxDataUseCase.getUseCaseNames()].map(name => {
|
237
237
|
return {
|
238
238
|
display: name,
|
239
239
|
value: name
|
@@ -0,0 +1,104 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.createDataSample = void 0;
|
7
|
+
const data_ooc_1 = require("../service/data-ooc/data-ooc");
|
8
|
+
const shell_1 = require("@things-factory/shell");
|
9
|
+
const data_item_1 = require("../service/data-item/data-item");
|
10
|
+
const data_sample_1 = require("../service/data-sample/data-sample");
|
11
|
+
const data_set_1 = require("../service/data-set/data-set");
|
12
|
+
const data_use_case_1 = require("./data-use-case");
|
13
|
+
const moment_1 = __importDefault(require("moment"));
|
14
|
+
const debug = require('debug')('things-factory:dataset:controller/save-data-sample');
|
15
|
+
// parse variable javascript string pattern
|
16
|
+
const replaceVariables = (keys, dic) => {
|
17
|
+
for (const k in keys) {
|
18
|
+
const matches = keys[k].match(/\$\{\w*\}/g);
|
19
|
+
matches &&
|
20
|
+
matches.forEach(m => {
|
21
|
+
keys[k] = keys[k].replace(m, dic[m.slice(2, -1)]);
|
22
|
+
});
|
23
|
+
}
|
24
|
+
return keys;
|
25
|
+
};
|
26
|
+
// It is required UTC date for Partitioning File System like AWS S3 from Athena.
|
27
|
+
// ex) %YYYY, %MM, %DD
|
28
|
+
const formatDate = (keys, _moment) => {
|
29
|
+
for (const k in keys) {
|
30
|
+
const matches = keys[k].match(/%\w*/g);
|
31
|
+
matches &&
|
32
|
+
matches.forEach(m => {
|
33
|
+
keys[k] = keys[k].replace(m, _moment.format(m.substr(1)));
|
34
|
+
});
|
35
|
+
}
|
36
|
+
return keys;
|
37
|
+
};
|
38
|
+
async function createDataSample(dataSample, context) {
|
39
|
+
const { domain, user, tx } = context.state;
|
40
|
+
const dataSet = await tx.getRepository(data_set_1.DataSet).findOne({
|
41
|
+
where: { id: dataSample.dataSet.id }
|
42
|
+
});
|
43
|
+
const dataItems = await tx.getRepository(data_item_1.DataItem).find({
|
44
|
+
where: {
|
45
|
+
domain,
|
46
|
+
dataSet
|
47
|
+
},
|
48
|
+
order: {
|
49
|
+
sequence: 'DESC'
|
50
|
+
}
|
51
|
+
});
|
52
|
+
const spec = dataItems.reduce((spec, dataItem) => {
|
53
|
+
spec[dataItem.tag] = Object.assign(Object.assign({}, dataItem.spec), { name: dataItem.name /* do we need ? */ });
|
54
|
+
return spec;
|
55
|
+
}, {});
|
56
|
+
var partitionKeys = Object.assign({}, dataSet.partitionKeys);
|
57
|
+
const collectedAt = dataSample.collectedAt || new Date();
|
58
|
+
partitionKeys = formatDate(partitionKeys, (0, moment_1.default)(collectedAt).utc());
|
59
|
+
partitionKeys = replaceVariables(partitionKeys, Object.assign({ domain: domain.subdomain, dataSetId: dataSample.dataSet.id }, dataSample.data));
|
60
|
+
const { ooc, oos } = data_use_case_1.DataUseCase.evaluate(dataSet, dataItems, dataSample.data) || {};
|
61
|
+
const result = await tx.getRepository(data_sample_1.DataSample).save(Object.assign(Object.assign({ name: dataSet.name, description: dataSet.description, useCase: dataSet.useCase }, dataSample), { domain,
|
62
|
+
partitionKeys,
|
63
|
+
spec,
|
64
|
+
ooc,
|
65
|
+
oos,
|
66
|
+
collectedAt, creator: user, updater: user }));
|
67
|
+
if (ooc || oos) {
|
68
|
+
const dataOoc = await tx.getRepository(data_ooc_1.DataOoc).save({
|
69
|
+
name: dataSet.name,
|
70
|
+
description: dataSet.description,
|
71
|
+
useCase: dataSet.useCase,
|
72
|
+
dataSet,
|
73
|
+
dataSample: result,
|
74
|
+
data: dataSample.data,
|
75
|
+
domain,
|
76
|
+
partitionKeys,
|
77
|
+
spec,
|
78
|
+
ooc,
|
79
|
+
oos,
|
80
|
+
state: data_ooc_1.DataOocStatus.CREATED,
|
81
|
+
collectedAt,
|
82
|
+
creator: user,
|
83
|
+
updater: user
|
84
|
+
});
|
85
|
+
debug('dataOoc is about to publish...', dataOoc);
|
86
|
+
shell_1.pubsub.publish('data-ooc', {
|
87
|
+
dataOoc,
|
88
|
+
supervisoryRoleId: dataSet.supervisoryRoleId
|
89
|
+
});
|
90
|
+
shell_1.pubsub.publish('notification', {
|
91
|
+
notification: {
|
92
|
+
domain,
|
93
|
+
type: 'error',
|
94
|
+
title: `Data OOC occurred on '${dataSet.name}'`,
|
95
|
+
body: `Data OOC occurred on '${dataSet.name}'`,
|
96
|
+
url: (0, shell_1.getRedirectSubdomainPath)(context, domain.subdomain, `/data-ooc/${dataOoc.id}`),
|
97
|
+
timestamp: collectedAt
|
98
|
+
}
|
99
|
+
});
|
100
|
+
}
|
101
|
+
return result;
|
102
|
+
}
|
103
|
+
exports.createDataSample = createDataSample;
|
104
|
+
//# sourceMappingURL=create-data-sample.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"create-data-sample.js","sourceRoot":"","sources":["../../server/controllers/create-data-sample.ts"],"names":[],"mappings":";;;;;;AAAA,2DAAqE;AACrE,iDAAgF;AAEhF,8DAAyD;AACzD,oEAA+D;AAC/D,2DAAsD;AACtD,mDAA6C;AAI7C,oDAA2B;AAE3B,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAEpF,2CAA2C;AAC3C,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;IACrC,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE;QACpB,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,Y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IACb,CAAA;IAEF,IAAI,GAAG,IAAI,GAAG,EAAE;QACd,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,kBAAO,CAAC,CAAC,IAAI,CAAC;YACnD,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO;YACP,UAAU,EAAE,MAAM;YAClB,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,MAAM;YACN,aAAa;YACb,IAAI;YACJ,GAAG;YACH,GAAG;YACH,KAAK,EAAE,wBAAa,CAAC,OAAO;YAC5B,WAAW;YACX,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QAEF,KAAK,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAA;QAEhD,cAAM,CAAC,OAAO,CAAC,UAAU,EAAE;YACzB,OAAO;YACP,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;SAC7C,CAAC,CAAA;QAEF,cAAM,CAAC,OAAO,CAAC,cAAc,EAAE;YAC7B,YAAY,EAAE;gBACZ,MAAM;gBACN,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,yBAAyB,OAAO,CAAC,IAAI,GAAG;gBAC/C,IAAI,EAAE,yBAAyB,OAAO,CAAC,IAAI,GAAG;gBAC9C,GAAG,EAAE,IAAA,gCAAwB,EAAC,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,aAAa,OAAO,CAAC,EAAE,EAAE,CAAC;gBACnF,SAAS,EAAE,WAAW;aACvB;SACF,CAAC,CAAA;KACH;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAvGD,4CAuGC"}
|
package/dist-server/routes.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
const typeorm_1 = require("typeorm");
|
4
|
-
const
|
5
|
-
const
|
4
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
5
|
+
const create_data_sample_1 = require("./controllers/create-data-sample");
|
6
6
|
const data_sensor_1 = require("./service/data-sensor/data-sensor");
|
7
7
|
const debug = require('debug')('things-factory:dataset:routes');
|
8
8
|
process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) => {
|
@@ -39,36 +39,21 @@ process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) =>
|
|
39
39
|
}
|
40
40
|
const domain = sensor.domain;
|
41
41
|
const dataSet = sensor.dataSet;
|
42
|
-
const user =
|
43
|
-
const dataItems = await tx.getRepository(data_item_1.DataItem).find({
|
42
|
+
const user = await tx.getRepository(auth_base_1.User).findOne({
|
44
43
|
where: {
|
45
|
-
|
46
|
-
|
47
|
-
},
|
48
|
-
order: {
|
49
|
-
sequence: 'DESC'
|
44
|
+
reference: sensor.appliance.id,
|
45
|
+
userType: 'appliance'
|
50
46
|
}
|
51
47
|
});
|
52
|
-
|
53
|
-
dataItems.forEach(dataItem => {
|
54
|
-
spec[dataItem.name] = dataItem.spec;
|
55
|
-
});
|
56
|
-
await tx.getRepository(service_1.DataSample).save({
|
57
|
-
domain,
|
58
|
-
name: dataSet.name,
|
59
|
-
description: dataSet.description,
|
60
|
-
partitionKeys: dataSet.partitionKeys,
|
48
|
+
return await (0, create_data_sample_1.createDataSample)({
|
61
49
|
dataSet,
|
62
50
|
data,
|
63
51
|
rawData,
|
64
|
-
spec,
|
65
52
|
source: deviceId,
|
66
|
-
collectedAt: new Date(timestamp)
|
67
|
-
|
68
|
-
updater: user
|
69
|
-
});
|
53
|
+
collectedAt: new Date(timestamp)
|
54
|
+
}, { state: { domain, user, tx } });
|
70
55
|
});
|
71
|
-
|
56
|
+
context.status = 200;
|
72
57
|
});
|
73
58
|
});
|
74
59
|
process.on('bootstrap-module-global-private-route', (app, globalPrivateRouter) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";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ACL,CAAC,CAAC,CAAA"}
|
@@ -0,0 +1,65 @@
|
|
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.DataOocSubscription = void 0;
|
16
|
+
const type_graphql_1 = require("type-graphql");
|
17
|
+
const graphql_subscriptions_1 = require("graphql-subscriptions");
|
18
|
+
const shell_1 = require("@things-factory/shell");
|
19
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
20
|
+
const data_ooc_1 = require("./data-ooc");
|
21
|
+
const typeorm_1 = require("typeorm");
|
22
|
+
const debug = require('debug')('things-factory:dataset:data-ooc-subscription');
|
23
|
+
let DataOocSubscription = class DataOocSubscription {
|
24
|
+
dataOoc(payload) {
|
25
|
+
return payload.dataOoc;
|
26
|
+
}
|
27
|
+
};
|
28
|
+
__decorate([
|
29
|
+
(0, type_graphql_1.Subscription)({
|
30
|
+
subscribe: (_, args, context, info) => {
|
31
|
+
var _a;
|
32
|
+
const { domain, user } = context.state;
|
33
|
+
const subdomain = domain === null || domain === void 0 ? void 0 : domain.subdomain;
|
34
|
+
debug('subscribe', subdomain);
|
35
|
+
if (!domain) {
|
36
|
+
throw new Error('domain required');
|
37
|
+
}
|
38
|
+
if (!((_a = user.domains) === null || _a === void 0 ? void 0 : _a.find(d => d.subdomain === subdomain))) {
|
39
|
+
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
40
|
+
}
|
41
|
+
return (0, graphql_subscriptions_1.withFilter)(() => shell_1.pubsub.asyncIterator('data-ooc'), async (payload, variables, context, info) => {
|
42
|
+
const { dataOoc, supervisoryRoleId } = payload;
|
43
|
+
const { domain } = dataOoc;
|
44
|
+
if (subdomain !== (domain === null || domain === void 0 ? void 0 : domain.subdomain)) {
|
45
|
+
return false;
|
46
|
+
}
|
47
|
+
// check if the user has that role
|
48
|
+
const userWithRoles = await (0, typeorm_1.getRepository)(auth_base_1.User).findOne({
|
49
|
+
where: { id: user.id },
|
50
|
+
relations: ['roles']
|
51
|
+
});
|
52
|
+
return userWithRoles.roles.find(role => role.id === supervisoryRoleId);
|
53
|
+
})(_, args, context, info);
|
54
|
+
}
|
55
|
+
}),
|
56
|
+
__param(0, (0, type_graphql_1.Root)()),
|
57
|
+
__metadata("design:type", Function),
|
58
|
+
__metadata("design:paramtypes", [Object]),
|
59
|
+
__metadata("design:returntype", data_ooc_1.DataOoc)
|
60
|
+
], DataOocSubscription.prototype, "dataOoc", null);
|
61
|
+
DataOocSubscription = __decorate([
|
62
|
+
(0, type_graphql_1.Resolver)(data_ooc_1.DataOoc)
|
63
|
+
], DataOocSubscription);
|
64
|
+
exports.DataOocSubscription = DataOocSubscription;
|
65
|
+
//# sourceMappingURL=data-ooc-subscription.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"data-ooc-subscription.js","sourceRoot":"","sources":["../../../server/service/data-ooc/data-ooc-subscription.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAA2D;AAC3D,iEAAkD;AAClD,iDAA8C;AAC9C,yDAAgD;AAChD,yCAAoC;AACpC,qCAAuC;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AClC,MAAM,aAAa,GAAS,MAAM,IAAA,uBAAa,EAAC,gBAAI,CAAC,CAAC,OAAO,CAAC;oBAC5D,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE;oBACtB,SAAS,EAAE,CAAC,OAAO,CAAC;iBACrB,CAAC,CAAA;gBAEF,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,iBAAiB,CAAC,CAAA;YACxE,CAAC,CACF,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;QAC3B,CAAC;KACF,CAAC;IACO,WAAA,IAAA,mBAAI,GAAE,CAAA;;;oCAA4D,kBAAO;kDAEjF;AAvCU,mBAAmB;IAD/B,IAAA,uBAAQ,EAAC,kBAAO,CAAC;GACL,mBAAmB,CAwC/B;AAxCY,kDAAmB"}
|
@@ -120,6 +120,13 @@ __decorate([
|
|
120
120
|
(0, type_graphql_1.Field)({ nullable: true }),
|
121
121
|
__metadata("design:type", String)
|
122
122
|
], DataOoc.prototype, "type", void 0);
|
123
|
+
__decorate([
|
124
|
+
(0, typeorm_1.Column)({
|
125
|
+
nullable: true
|
126
|
+
}),
|
127
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
128
|
+
__metadata("design:type", String)
|
129
|
+
], DataOoc.prototype, "useCase", void 0);
|
123
130
|
__decorate([
|
124
131
|
(0, typeorm_1.Column)('simple-json', { nullable: true }),
|
125
132
|
(0, type_graphql_1.Field)(type => shell_1.ScalarObject, { nullable: true }),
|