@things-factory/reference-app 6.2.102 → 6.2.104
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/dist-server/constants/index.js +5 -0
- package/dist-server/constants/index.js.map +1 -0
- package/dist-server/constants/type-constants.js +26 -0
- package/dist-server/constants/type-constants.js.map +1 -0
- package/dist-server/controllers/create-data-sample-mockup.js +240 -0
- package/dist-server/controllers/create-data-sample-mockup.js.map +1 -0
- package/dist-server/controllers/index.js +5 -0
- package/dist-server/controllers/index.js.map +1 -0
- package/dist-server/index.js +8 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/middlewares/index.js +8 -0
- package/dist-server/middlewares/index.js.map +1 -0
- package/dist-server/migrations/index.js +12 -0
- package/dist-server/migrations/index.js.map +1 -0
- package/dist-server/routes.js +24 -0
- package/dist-server/routes.js.map +1 -0
- package/dist-server/service/data-sample-mockup/data-sample-mockup-mutation.js +28 -0
- package/dist-server/service/data-sample-mockup/data-sample-mockup-mutation.js.map +1 -0
- package/dist-server/service/data-sample-mockup/data-sample-mockup-type.js +20 -0
- package/dist-server/service/data-sample-mockup/data-sample-mockup-type.js.map +1 -0
- package/dist-server/service/data-sample-mockup/index.js +7 -0
- package/dist-server/service/data-sample-mockup/index.js.map +1 -0
- package/dist-server/service/index.js +20 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/reference/index.js +8 -0
- package/dist-server/service/reference/index.js.map +1 -0
- package/dist-server/service/reference/lambda-call.js +68 -0
- package/dist-server/service/reference/lambda-call.js.map +1 -0
- package/dist-server/service/reference/reference-mutation.js +63 -0
- package/dist-server/service/reference/reference-mutation.js.map +1 -0
- package/dist-server/service/reference/reference-query.js +84 -0
- package/dist-server/service/reference/reference-query.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +34 -34
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/constants/index.ts"],"names":[],"mappings":";;;AAAA,2DAAgC","sourcesContent":["export * from './type-constants'\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WAREHOUSE_TYPE = exports.PRODUCT_TYPE = exports.FINISHED_INVENTORY = exports.ROH_INVENTORY = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Inventory Type
|
|
6
|
+
*/
|
|
7
|
+
exports.ROH_INVENTORY = 'ROH';
|
|
8
|
+
exports.FINISHED_INVENTORY = 'FINISHED';
|
|
9
|
+
/**
|
|
10
|
+
* Product Type
|
|
11
|
+
*/
|
|
12
|
+
exports.PRODUCT_TYPE = {
|
|
13
|
+
FERT: '완제품',
|
|
14
|
+
HALB: '반제품',
|
|
15
|
+
ROH: '원자재'
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Warehouse Type
|
|
19
|
+
*/
|
|
20
|
+
exports.WAREHOUSE_TYPE = {
|
|
21
|
+
FINISHED: '완제품',
|
|
22
|
+
HALF_COLD: '반제품(냉장)',
|
|
23
|
+
HALF_FROZEN: '반제품(냉동)',
|
|
24
|
+
ROH: '원자재'
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=type-constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-constants.js","sourceRoot":"","sources":["../../server/constants/type-constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,aAAa,GAAG,KAAK,CAAA;AACrB,QAAA,kBAAkB,GAAG,UAAU,CAAA;AAE5C;;GAEG;AACU,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,GAAG,EAAE,KAAK;CACX,CAAA;AAED;;GAEG;AACU,QAAA,cAAc,GAAG;IAC5B,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,SAAS;IACpB,WAAW,EAAE,SAAS;IACtB,GAAG,EAAE,KAAK;CACX,CAAA","sourcesContent":["/**\n * Inventory Type\n */\nexport const ROH_INVENTORY = 'ROH'\nexport const FINISHED_INVENTORY = 'FINISHED'\n\n/**\n * Product Type\n */\nexport const PRODUCT_TYPE = {\n FERT: '완제품',\n HALB: '반제품',\n ROH: '원자재'\n}\n\n/**\n * Warehouse Type\n */\nexport const WAREHOUSE_TYPE = {\n FINISHED: '완제품',\n HALF_COLD: '반제품(냉장)',\n HALF_FROZEN: '반제품(냉동)',\n ROH: '원자재'\n}\n"]}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateMockupData = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const moment_timezone_1 = tslib_1.__importDefault(require("moment-timezone"));
|
|
6
|
+
const dataset_1 = require("@things-factory/dataset");
|
|
7
|
+
const product_base_1 = require("@things-factory/product-base");
|
|
8
|
+
const routing_base_1 = require("@things-factory/routing-base");
|
|
9
|
+
const work_shift_1 = require("@things-factory/work-shift");
|
|
10
|
+
process.env.TZ = 'UTC';
|
|
11
|
+
const randomWords = require('random-words');
|
|
12
|
+
const fillDataKeys = (dataKeySet, data) => {
|
|
13
|
+
const keys = (dataKeySet === null || dataKeySet === void 0 ? void 0 : dataKeySet.dataKeyItems) || [];
|
|
14
|
+
return keys.reduce((sum, key, index) => {
|
|
15
|
+
const value = data[key.dataKey];
|
|
16
|
+
if (value != null) {
|
|
17
|
+
sum[`key0${index + 1}`] = value instanceof Array ? value[0] : value;
|
|
18
|
+
}
|
|
19
|
+
return sum;
|
|
20
|
+
}, {});
|
|
21
|
+
};
|
|
22
|
+
// parse variable javascript string pattern
|
|
23
|
+
const replaceVariables = (keys, dic) => {
|
|
24
|
+
for (const k in keys) {
|
|
25
|
+
const matches = keys[k].match(/\$\{\w*\}/g);
|
|
26
|
+
matches &&
|
|
27
|
+
matches.forEach(m => {
|
|
28
|
+
keys[k] = keys[k].replace(m, dic[m.slice(2, -1)]);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return keys;
|
|
32
|
+
};
|
|
33
|
+
// It is required UTC date for Partitioning File System like AWS S3 from Athena.
|
|
34
|
+
// ex) %YYYY, %MM, %DD
|
|
35
|
+
const formatDate = (keys, _moment) => {
|
|
36
|
+
for (const k in keys) {
|
|
37
|
+
const matches = keys[k].match(/%\w*/g);
|
|
38
|
+
matches &&
|
|
39
|
+
matches.forEach(m => {
|
|
40
|
+
keys[k] = keys[k].replace(m, _moment.format(m.substr(1)));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return keys;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Normal Distribution
|
|
47
|
+
* https://stackoverflow.com/questions/25582882/javascript-math-random-normal-distribution-gaussian-bell-curve
|
|
48
|
+
*/
|
|
49
|
+
function normal_dist(min, max, skew) {
|
|
50
|
+
let u = 0, v = 0;
|
|
51
|
+
while (u === 0)
|
|
52
|
+
u = Math.random(); //Converting [0,1) to (0,1)
|
|
53
|
+
while (v === 0)
|
|
54
|
+
v = Math.random();
|
|
55
|
+
let num = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
|
|
56
|
+
num = num / 10.0 + 0.5; // Translate to 0 -> 1
|
|
57
|
+
if (num > 1 || num < 0)
|
|
58
|
+
num = normal_dist(min, max, skew); // resample between 0 and 1 if out of range
|
|
59
|
+
else {
|
|
60
|
+
num = Math.pow(num, skew); // Skew
|
|
61
|
+
num *= max - min; // Stretch to fill range
|
|
62
|
+
num += min; // offset to min
|
|
63
|
+
}
|
|
64
|
+
return num;
|
|
65
|
+
}
|
|
66
|
+
function randomIndex(max = 2) {
|
|
67
|
+
return Math.floor(Math.random() * max);
|
|
68
|
+
}
|
|
69
|
+
function fillColumns(prev, next, dict) {
|
|
70
|
+
let values = [];
|
|
71
|
+
try {
|
|
72
|
+
const gap = 20;
|
|
73
|
+
const timeFormat = 'HH:mm';
|
|
74
|
+
const dateFormat = 'YYYY-MM-DD';
|
|
75
|
+
const atFormat = 'YYYY-MM-DD HH:mm:ss';
|
|
76
|
+
const now = (0, moment_timezone_1.default)();
|
|
77
|
+
const { type, spec, quota } = next;
|
|
78
|
+
const isValidSpec = spec && Object.keys(spec).length;
|
|
79
|
+
const arr = Array.from(Array(quota).keys());
|
|
80
|
+
if (type == 'number') {
|
|
81
|
+
if (isValidSpec) {
|
|
82
|
+
/* generate values refer to spec info. */
|
|
83
|
+
const { CCP: { criticalLimits: { minimum, maximum } } } = spec;
|
|
84
|
+
while (values.length < quota) {
|
|
85
|
+
let value = 0;
|
|
86
|
+
if (typeof minimum === 'number' && typeof maximum === 'number') {
|
|
87
|
+
value = Math.floor(normal_dist(minimum, maximum, 1));
|
|
88
|
+
}
|
|
89
|
+
else if (typeof minimum === 'number' && typeof maximum !== 'number') {
|
|
90
|
+
const max = minimum + gap;
|
|
91
|
+
value = Math.floor(normal_dist(minimum, max, 1));
|
|
92
|
+
}
|
|
93
|
+
else if (typeof minimum !== 'number' && typeof maximum === 'number') {
|
|
94
|
+
const min = maximum - gap;
|
|
95
|
+
value = Math.floor(normal_dist(min, maximum, 1));
|
|
96
|
+
}
|
|
97
|
+
values.push(value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
/* random number */
|
|
102
|
+
const p = Math.random();
|
|
103
|
+
const q = () => randomIndex(10) + 1;
|
|
104
|
+
// fixed
|
|
105
|
+
if (p > 0.33) {
|
|
106
|
+
values = Array(quota).fill(q());
|
|
107
|
+
}
|
|
108
|
+
else if (p > 0.66) {
|
|
109
|
+
/* or random */
|
|
110
|
+
values = arr.map(i => q());
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
/* or incremental */
|
|
114
|
+
values = arr.reduce((prev, i) => {
|
|
115
|
+
prev.push(!!prev.length ? prev[0] + i : q());
|
|
116
|
+
return prev;
|
|
117
|
+
}, []);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (type == 'select') {
|
|
122
|
+
const options = next['options']['options'];
|
|
123
|
+
values = arr.map(i => options[randomIndex(options.length)]['value']);
|
|
124
|
+
}
|
|
125
|
+
else if (type == 'boolean') {
|
|
126
|
+
values = arr.map(i => !!randomIndex());
|
|
127
|
+
}
|
|
128
|
+
else if (next['tag'].toLowerCase().indexOf('time') >= 0) {
|
|
129
|
+
/* ex) startTime => 09:21 */
|
|
130
|
+
arr.reduce(curr => {
|
|
131
|
+
values.push(curr.format(timeFormat));
|
|
132
|
+
curr.add(randomIndex(60), 'minutes');
|
|
133
|
+
return curr;
|
|
134
|
+
}, now);
|
|
135
|
+
}
|
|
136
|
+
else if (next['tag'].indexOf('edAt') > 0) {
|
|
137
|
+
/* ex) createdAt => '2022-06-15 09:21:30 */
|
|
138
|
+
arr.reduce(curr => {
|
|
139
|
+
values.push(curr.format(atFormat));
|
|
140
|
+
curr.add(randomIndex(12), 'hours');
|
|
141
|
+
return curr;
|
|
142
|
+
}, now);
|
|
143
|
+
}
|
|
144
|
+
else if (next['tag'].toLowerCase().indexOf('date') > 0) {
|
|
145
|
+
/* ex) startDate => '2022-06-15 */
|
|
146
|
+
arr.reduce(curr => {
|
|
147
|
+
values.push(curr.format(dateFormat));
|
|
148
|
+
curr.add(randomIndex(7), 'days');
|
|
149
|
+
return curr;
|
|
150
|
+
}, now);
|
|
151
|
+
}
|
|
152
|
+
else if (dict.hasOwnProperty(next['tag'])) {
|
|
153
|
+
values = Array(quota).fill(dict[next['tag']]);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
if (type == 'text') {
|
|
157
|
+
values = randomWords(quota);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
prev[next['tag']] = values;
|
|
163
|
+
return prev;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function _generateMockupData(dataSources, tx) {
|
|
167
|
+
const { user, domain, dataSet, spec, products, operations } = dataSources;
|
|
168
|
+
const collectedAt = new Date();
|
|
169
|
+
const timezone = dataSet.timezone || domain.timezone || 'UTC';
|
|
170
|
+
const format = 'YYYY-MM-DD';
|
|
171
|
+
// workDate ex) 2022-04-04
|
|
172
|
+
const { workDate, workShift } = await (0, work_shift_1.getWorkDateAndShift)(domain, collectedAt, { timezone, format });
|
|
173
|
+
// local time dataSet timezone or domain timezone or default 'UTC'
|
|
174
|
+
// const collectedAt = dataSample.collectedAt || new Date()
|
|
175
|
+
const localDateTz = (0, moment_timezone_1.default)(collectedAt).tz(timezone);
|
|
176
|
+
const defaultPartitionKeys = {
|
|
177
|
+
domain: domain.subdomain,
|
|
178
|
+
datasetid: dataSet.id /* It should not be 'data_set_id' as column name duplicated for Glue */,
|
|
179
|
+
date: localDateTz.format(format) /* local time date */,
|
|
180
|
+
workdate: workDate /* working date */,
|
|
181
|
+
workshift: workShift
|
|
182
|
+
};
|
|
183
|
+
var partitionKeys = Object.assign(Object.assign({}, defaultPartitionKeys), dataSet.partitionKeys);
|
|
184
|
+
// get product, operation as a map
|
|
185
|
+
const oper = operations[Math.floor(Math.random() * operations.length)];
|
|
186
|
+
const prod = products[Math.floor(Math.random() * products.length)];
|
|
187
|
+
const dict = {
|
|
188
|
+
operation: oper['name'],
|
|
189
|
+
operationId: oper['id'],
|
|
190
|
+
product: prod['name'],
|
|
191
|
+
productId: prod['id']
|
|
192
|
+
};
|
|
193
|
+
const sample = dataSet.dataItems.reduce((prev, next) => fillColumns(prev, next, dict), {});
|
|
194
|
+
partitionKeys = formatDate(partitionKeys, localDateTz);
|
|
195
|
+
partitionKeys = replaceVariables(partitionKeys, Object.assign({}, sample));
|
|
196
|
+
const dataKeys = fillDataKeys(dataSet === null || dataSet === void 0 ? void 0 : dataSet.dataKeySet, sample);
|
|
197
|
+
const { ooc, oos, judgment } = dataset_1.DataUseCase.evaluate(dataSet, dataSet.dataItems, sample) || {};
|
|
198
|
+
const result = await tx.getRepository(dataset_1.DataSample).save(Object.assign(Object.assign({ name: dataSet.name, description: dataSet.description, useCase: dataSet.useCase, type: dataSet.type, dataSet: dataSet, dataSetVersion: dataSet.version, data: sample, domain,
|
|
199
|
+
partitionKeys }, dataKeys), { spec,
|
|
200
|
+
ooc,
|
|
201
|
+
oos,
|
|
202
|
+
judgment,
|
|
203
|
+
collectedAt,
|
|
204
|
+
workDate,
|
|
205
|
+
workShift, creator: user, updater: user }));
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
async function generateMockupData(params, context) {
|
|
209
|
+
const { domain, user, tx } = context.state;
|
|
210
|
+
const dataSet = await tx.getRepository(dataset_1.DataSet).findOne({
|
|
211
|
+
where: { id: params.dataSetId },
|
|
212
|
+
relations: ['dataKeySet']
|
|
213
|
+
});
|
|
214
|
+
const products = await tx.getRepository(product_base_1.Product).find({
|
|
215
|
+
select: ['id', 'name', 'description'],
|
|
216
|
+
where: {
|
|
217
|
+
domain: { id: domain.id }
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
const operations = await tx.getRepository(routing_base_1.Operation).find({
|
|
221
|
+
select: ['id', 'name', 'description'],
|
|
222
|
+
where: {
|
|
223
|
+
domain: { id: domain.id }
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
const dataItems = dataSet.dataItems;
|
|
227
|
+
const spec = dataItems.reduce((spec, dataItem) => {
|
|
228
|
+
spec[dataItem.tag] = Object.assign(Object.assign({}, dataItem.spec), { name: dataItem.name /* do we need ? */, hidden: dataItem.hidden });
|
|
229
|
+
return spec;
|
|
230
|
+
}, {});
|
|
231
|
+
const promises = Array(params.numSamples)
|
|
232
|
+
.fill(0)
|
|
233
|
+
.map(x => {
|
|
234
|
+
return _generateMockupData({ domain, user, dataSet, products, operations, spec }, tx);
|
|
235
|
+
});
|
|
236
|
+
await Promise.all(promises);
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
exports.generateMockupData = generateMockupData;
|
|
240
|
+
//# sourceMappingURL=create-data-sample-mockup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-data-sample-mockup.js","sourceRoot":"","sources":["../../server/controllers/create-data-sample-mockup.ts"],"names":[],"mappings":";;;;AAAA,8EAAoC;AAIpC,qDAA0E;AAC1E,+DAAsD;AACtD,+DAAwD;AAExD,2DAAgE;AAIhE,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,CAAA;AACtB,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAE3C,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE;IACxC,MAAM,IAAI,GAAG,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,YAAY,KAAI,EAAE,CAAA;IAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAC/B,IAAI,KAAK,IAAI,IAAI,EAAE;YACjB,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;SACpE;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA;AAED,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,YAAY,CAAC,CAAA;QAC3C,OAAO;YACL,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;gBAClB,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAA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AAC;SACtC,IAAI,CAAC,CAAC,CAAC;SACP,GAAG,CAAC,CAAC,CAAC,EAAE;QACP,OAAO,mBAAmB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAA;IACvF,CAAC,CAAC,CAAA;IAEJ,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC3B,OAAO,IAAI,CAAA;AACb,CAAC;AAnDD,gDAmDC","sourcesContent":["import moment from 'moment-timezone'\nimport { EntityManager } from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { DataSample, DataSet, DataUseCase } from '@things-factory/dataset'\nimport { Product } from '@things-factory/product-base'\nimport { Operation } from '@things-factory/routing-base'\nimport { Domain } from '@things-factory/shell'\nimport { getWorkDateAndShift } from '@things-factory/work-shift'\n\nimport { DataSampleMockupInfo } from '../service/data-sample-mockup/data-sample-mockup-type'\n\nprocess.env.TZ = 'UTC'\nconst randomWords = require('random-words')\n\nconst fillDataKeys = (dataKeySet, data) => {\n const keys = dataKeySet?.dataKeyItems || []\n return keys.reduce((sum, key, index) => {\n const value = data[key.dataKey]\n if (value != null) {\n sum[`key0${index + 1}`] = value instanceof Array ? value[0] : value\n }\n return sum\n }, {})\n}\n\n// parse variable javascript string pattern\nconst replaceVariables = (keys, dic) => {\n for (const k in keys) {\n const matches = keys[k].match(/\\$\\{\\w*\\}/g)\n matches &&\n matches.forEach(m => {\n keys[k] = keys[k].replace(m, dic[m.slice(2, -1)])\n })\n }\n return keys\n}\n\n// It is required UTC date for Partitioning File System like AWS S3 from Athena.\n// ex) %YYYY, %MM, %DD\nconst formatDate = (keys, _moment) => {\n for (const k in keys) {\n const matches = keys[k].match(/%\\w*/g)\n matches &&\n matches.forEach(m => {\n keys[k] = keys[k].replace(m, _moment.format(m.substr(1)))\n })\n }\n return keys\n}\n\n/**\n * Normal Distribution\n * https://stackoverflow.com/questions/25582882/javascript-math-random-normal-distribution-gaussian-bell-curve\n */\nfunction normal_dist(min, max, skew) {\n let u = 0,\n v = 0\n while (u === 0) u = Math.random() //Converting [0,1) to (0,1)\n while (v === 0) v = Math.random()\n let num = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v)\n\n num = num / 10.0 + 0.5 // Translate to 0 -> 1\n if (num > 1 || num < 0) num = normal_dist(min, max, skew) // resample between 0 and 1 if out of range\n else {\n num = Math.pow(num, skew) // Skew\n num *= max - min // Stretch to fill range\n num += min // offset to min\n }\n return num\n}\n\nfunction randomIndex(max = 2) {\n return Math.floor(Math.random() * max)\n}\n\nfunction fillColumns(prev, next, dict) {\n let values = []\n try {\n const gap = 20\n const timeFormat = 'HH:mm'\n const dateFormat = 'YYYY-MM-DD'\n const atFormat = 'YYYY-MM-DD HH:mm:ss'\n const now = moment()\n const { type, spec, quota } = next\n const isValidSpec = spec && Object.keys(spec).length\n const arr = Array.from(Array(quota).keys())\n\n if (type == 'number') {\n if (isValidSpec) {\n /* generate values refer to spec info. */\n const {\n CCP: {\n criticalLimits: { minimum, maximum }\n }\n } = spec\n while (values.length < quota) {\n let value = 0\n if (typeof minimum === 'number' && typeof maximum === 'number') {\n value = Math.floor(normal_dist(minimum, maximum, 1))\n } else if (typeof minimum === 'number' && typeof maximum !== 'number') {\n const max = minimum + gap\n value = Math.floor(normal_dist(minimum, max, 1))\n } else if (typeof minimum !== 'number' && typeof maximum === 'number') {\n const min = maximum - gap\n value = Math.floor(normal_dist(min, maximum, 1))\n }\n values.push(value)\n }\n } else {\n /* random number */\n const p = Math.random()\n const q = () => randomIndex(10) + 1\n // fixed\n if (p > 0.33) {\n values = Array(quota).fill(q())\n } else if (p > 0.66) {\n /* or random */\n values = arr.map(i => q())\n } else {\n /* or incremental */\n values = arr.reduce((prev, i) => {\n prev.push(!!prev.length ? prev[0] + i : q())\n return prev\n }, [])\n }\n }\n } else if (type == 'select') {\n const options = next['options']['options']\n values = arr.map(i => options[randomIndex(options.length)]['value'])\n } else if (type == 'boolean') {\n values = arr.map(i => !!randomIndex())\n } else if (next['tag'].toLowerCase().indexOf('time') >= 0) {\n /* ex) startTime => 09:21 */\n arr.reduce(curr => {\n values.push(curr.format(timeFormat))\n curr.add(randomIndex(60), 'minutes')\n return curr\n }, now)\n } else if (next['tag'].indexOf('edAt') > 0) {\n /* ex) createdAt => '2022-06-15 09:21:30 */\n arr.reduce(curr => {\n values.push(curr.format(atFormat))\n curr.add(randomIndex(12), 'hours')\n return curr\n }, now)\n } else if (next['tag'].toLowerCase().indexOf('date') > 0) {\n /* ex) startDate => '2022-06-15 */\n arr.reduce(curr => {\n values.push(curr.format(dateFormat))\n curr.add(randomIndex(7), 'days')\n return curr\n }, now)\n } else if (dict.hasOwnProperty(next['tag'])) {\n values = Array(quota).fill(dict[next['tag']])\n } else {\n if (type == 'text') {\n values = randomWords(quota)\n }\n }\n } finally {\n prev[next['tag']] = values\n return prev\n }\n}\n\nasync function _generateMockupData(dataSources: any, tx: EntityManager) {\n const { user, domain, dataSet, spec, products, operations } = dataSources\n\n const collectedAt = new Date()\n\n const timezone = dataSet.timezone || domain.timezone || 'UTC'\n const format = 'YYYY-MM-DD'\n\n // workDate ex) 2022-04-04\n const { workDate, workShift } = await getWorkDateAndShift(domain, collectedAt, { timezone, format })\n\n // local time dataSet timezone or domain timezone or default 'UTC'\n\n // const collectedAt = dataSample.collectedAt || new Date()\n const localDateTz = moment(collectedAt).tz(timezone)\n const defaultPartitionKeys = {\n domain: domain.subdomain,\n datasetid: dataSet.id /* It should not be 'data_set_id' as column name duplicated for Glue */,\n date: localDateTz.format(format) /* local time date */,\n workdate: workDate /* working date */,\n workshift: workShift\n }\n\n var partitionKeys = {\n ...defaultPartitionKeys,\n ...dataSet.partitionKeys\n }\n\n // get product, operation as a map\n const oper = operations[Math.floor(Math.random() * operations.length)]\n const prod = products[Math.floor(Math.random() * products.length)]\n const dict = {\n operation: oper['name'],\n operationId: oper['id'],\n product: prod['name'],\n productId: prod['id']\n }\n\n const sample = dataSet.dataItems.reduce((prev, next) => fillColumns(prev, next, dict), {})\n\n partitionKeys = formatDate(partitionKeys, localDateTz)\n partitionKeys = replaceVariables(partitionKeys, {\n ...sample\n })\n\n const dataKeys = fillDataKeys(dataSet?.dataKeySet, sample)\n\n const { ooc, oos, judgment } = DataUseCase.evaluate(dataSet, dataSet.dataItems, sample) || {}\n const result = await tx.getRepository(DataSample).save({\n name: dataSet.name,\n description: dataSet.description,\n useCase: dataSet.useCase,\n type: dataSet.type,\n dataSet: dataSet,\n dataSetVersion: dataSet.version,\n data: sample,\n domain,\n partitionKeys,\n ...dataKeys,\n spec,\n ooc,\n oos,\n judgment,\n collectedAt,\n workDate,\n workShift,\n creator: user,\n updater: user\n })\n\n return true\n}\n\nexport async function generateMockupData(\n params: DataSampleMockupInfo,\n context: {\n state: {\n domain: Domain\n user: User\n tx: EntityManager\n }\n }\n): Promise<Boolean> {\n const { domain, user, tx } = context.state\n\n const dataSet: DataSet = await tx.getRepository(DataSet).findOne({\n where: { id: params.dataSetId },\n relations: ['dataKeySet']\n })\n\n const products = await tx.getRepository(Product).find({\n select: ['id', 'name', 'description'],\n where: {\n domain: { id: domain.id }\n }\n })\n\n const operations = await tx.getRepository(Operation).find({\n select: ['id', 'name', 'description'],\n where: {\n domain: { id: domain.id }\n }\n })\n\n const dataItems = dataSet.dataItems\n\n const spec = dataItems.reduce((spec, dataItem) => {\n spec[dataItem.tag] = {\n ...dataItem.spec,\n name: dataItem.name /* do we need ? */,\n hidden: dataItem.hidden\n }\n\n return spec\n }, {})\n\n const promises = Array(params.numSamples)\n .fill(0)\n .map(x => {\n return _generateMockupData({ domain, user, dataSet, products, operations, spec }, tx)\n })\n\n await Promise.all(promises)\n return true\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/controllers/index.ts"],"names":[],"mappings":";;;AAAA,sEAA2C","sourcesContent":["export * from './create-data-sample-mockup'"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
require("./routes");
|
|
5
|
+
tslib_1.__exportStar(require("./service"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./migrations"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./middlewares"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,oBAAiB;AAEjB,oDAAyB;AACzB,uDAA4B;AAC5B,wDAA6B","sourcesContent":["import './routes'\n\nexport * from './service'\nexport * from './migrations'\nexport * from './middlewares'\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initMiddlewares = void 0;
|
|
4
|
+
function initMiddlewares(app) {
|
|
5
|
+
/* can add middlewares into app */
|
|
6
|
+
}
|
|
7
|
+
exports.initMiddlewares = initMiddlewares;
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/middlewares/index.ts"],"names":[],"mappings":";;;AAAA,SAAgB,eAAe,CAAC,GAAG;IACjC,kCAAkC;AACpC,CAAC;AAFD,0CAEC","sourcesContent":["export function initMiddlewares(app) {\n /* can add middlewares into app */\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrations = void 0;
|
|
4
|
+
const glob = require('glob');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
exports.migrations = [];
|
|
7
|
+
glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function (file) {
|
|
8
|
+
if (file.indexOf('index.js') !== -1)
|
|
9
|
+
return;
|
|
10
|
+
exports.migrations = exports.migrations.concat(Object.values(require(path.resolve(file))) || []);
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/migrations/index.ts"],"names":[],"mappings":";;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAEjB,QAAA,UAAU,GAAG,EAAE,CAAA;AAE1B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,UAAS,IAAI;IACzE,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAAE,OAAM;IAC3C,kBAAU,GAAG,kBAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;AAClF,CAAC,CAAC,CAAA","sourcesContent":["const glob = require('glob')\nconst path = require('path')\n\nexport var migrations = []\n\nglob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function(file) {\n if (file.indexOf('index.js') !== -1) return\n migrations = migrations.concat(Object.values(require(path.resolve(file))) || [])\n})\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) => {
|
|
2
|
+
/*
|
|
3
|
+
* can add global public routes to application (auth not required, tenancy not required)
|
|
4
|
+
*
|
|
5
|
+
* ex) routes.get('/path', async(context, next) => {})
|
|
6
|
+
* ex) routes.post('/path', async(context, next) => {})
|
|
7
|
+
*/
|
|
8
|
+
});
|
|
9
|
+
process.on('bootstrap-module-global-private-route', (app, globalPrivateRouter) => {
|
|
10
|
+
/*
|
|
11
|
+
* can add global private routes to application (auth required, tenancy not required)
|
|
12
|
+
*/
|
|
13
|
+
});
|
|
14
|
+
process.on('bootstrap-module-domain-public-route', (app, domainPublicRouter) => {
|
|
15
|
+
/*
|
|
16
|
+
* can add domain public routes to application (auth not required, tenancy required)
|
|
17
|
+
*/
|
|
18
|
+
});
|
|
19
|
+
process.on('bootstrap-module-domain-private-route', (app, domainPrivateRouter) => {
|
|
20
|
+
/*
|
|
21
|
+
* can add domain private routes to application (auth required, tenancy required)
|
|
22
|
+
*/
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF;;;;;OAKG;AACL,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACtF;;OAEG;AACL,CAAC,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;AACL,CAAC,CAAC,CAAA","sourcesContent":["process.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\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})\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSampleMockupMutation = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const type_graphql_1 = require("type-graphql");
|
|
6
|
+
const dataset_1 = require("@things-factory/dataset");
|
|
7
|
+
const create_data_sample_mockup_1 = require("../../controllers/create-data-sample-mockup");
|
|
8
|
+
const data_sample_mockup_type_1 = require("./data-sample-mockup-type");
|
|
9
|
+
let DataSampleMockupMutation = class DataSampleMockupMutation {
|
|
10
|
+
async generateMockupData(params, context) {
|
|
11
|
+
return await (0, create_data_sample_mockup_1.generateMockupData)(params, context);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
tslib_1.__decorate([
|
|
15
|
+
(0, type_graphql_1.Directive)('@privilege(category: "data-sample", privilege: "mutation", domainOwnerGranted: true)'),
|
|
16
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
17
|
+
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To generate data sample one' }),
|
|
18
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('params')),
|
|
19
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
20
|
+
tslib_1.__metadata("design:type", Function),
|
|
21
|
+
tslib_1.__metadata("design:paramtypes", [data_sample_mockup_type_1.DataSampleMockupInfo, Object]),
|
|
22
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
23
|
+
], DataSampleMockupMutation.prototype, "generateMockupData", null);
|
|
24
|
+
DataSampleMockupMutation = tslib_1.__decorate([
|
|
25
|
+
(0, type_graphql_1.Resolver)(dataset_1.DataSample)
|
|
26
|
+
], DataSampleMockupMutation);
|
|
27
|
+
exports.DataSampleMockupMutation = DataSampleMockupMutation;
|
|
28
|
+
//# sourceMappingURL=data-sample-mockup-mutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-sample-mockup-mutation.js","sourceRoot":"","sources":["../../../server/service/data-sample-mockup/data-sample-mockup-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AAEtE,qDAAoD;AAEpD,2FAAgF;AAChF,uEAAgE;AAGzD,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAI7B,AAAN,KAAK,CAAC,kBAAkB,CACP,MAA4B,EACpC,OAAwB;QAE/B,OAAO,MAAM,IAAA,8CAAkB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClD,CAAC;CACF,CAAA;AANO;IAHL,IAAA,wBAAS,EAAC,sFAAsF,CAAC;IACjG,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,6BAA6B,EAAE,CAAC;IAE1E,mBAAA,IAAA,kBAAG,EAAC,QAAQ,CAAC,CAAA;IACb,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CADiB,8CAAoB;;kEAI5C;AATU,wBAAwB;IADpC,IAAA,uBAAQ,EAAC,oBAAU,CAAC;GACR,wBAAwB,CAUpC;AAVY,4DAAwB","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\n\nimport { DataSample } from '@things-factory/dataset'\n\nimport { generateMockupData } from '../../controllers/create-data-sample-mockup'\nimport { DataSampleMockupInfo } from './data-sample-mockup-type'\n\n@Resolver(DataSample)\nexport class DataSampleMockupMutation {\n @Directive('@privilege(category: \"data-sample\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To generate data sample one' })\n async generateMockupData(\n @Arg('params') params: DataSampleMockupInfo,\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n return await generateMockupData(params, context)\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSampleMockupInfo = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const type_graphql_1 = require("type-graphql");
|
|
6
|
+
let DataSampleMockupInfo = class DataSampleMockupInfo {
|
|
7
|
+
};
|
|
8
|
+
tslib_1.__decorate([
|
|
9
|
+
(0, type_graphql_1.Field)(),
|
|
10
|
+
tslib_1.__metadata("design:type", String)
|
|
11
|
+
], DataSampleMockupInfo.prototype, "dataSetId", void 0);
|
|
12
|
+
tslib_1.__decorate([
|
|
13
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
14
|
+
tslib_1.__metadata("design:type", Number)
|
|
15
|
+
], DataSampleMockupInfo.prototype, "numSamples", void 0);
|
|
16
|
+
DataSampleMockupInfo = tslib_1.__decorate([
|
|
17
|
+
(0, type_graphql_1.InputType)()
|
|
18
|
+
], DataSampleMockupInfo);
|
|
19
|
+
exports.DataSampleMockupInfo = DataSampleMockupInfo;
|
|
20
|
+
//# sourceMappingURL=data-sample-mockup-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-sample-mockup-type.js","sourceRoot":"","sources":["../../../server/service/data-sample-mockup/data-sample-mockup-type.ts"],"names":[],"mappings":";;;;AAAA,+CAA+C;AAGxC,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAMhC,CAAA;AALC;IAAC,IAAA,oBAAK,GAAE;;uDACU;AAElB;IAAC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;wDACP;AALR,oBAAoB;IADhC,IAAA,wBAAS,GAAE;GACC,oBAAoB,CAMhC;AANY,oDAAoB","sourcesContent":["import { Field, InputType } from 'type-graphql'\n\n@InputType()\nexport class DataSampleMockupInfo {\n @Field()\n dataSetId?: string\n\n @Field({ nullable: true })\n numSamples?: number\n}"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvers = exports.entities = void 0;
|
|
4
|
+
const data_sample_mockup_mutation_1 = require("./data-sample-mockup-mutation");
|
|
5
|
+
exports.entities = [];
|
|
6
|
+
exports.resolvers = [data_sample_mockup_mutation_1.DataSampleMockupMutation];
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/data-sample-mockup/index.ts"],"names":[],"mappings":";;;AAAA,+EAAwE;AAE3D,QAAA,QAAQ,GAAG,EAAE,CAAA;AACb,QAAA,SAAS,GAAG,CAAC,sDAAwB,CAAC,CAAA","sourcesContent":["import { DataSampleMockupMutation } from './data-sample-mockup-mutation'\n\nexport const entities = []\nexport const resolvers = [DataSampleMockupMutation]\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* EXPORT ENTITY TYPES */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.schema = exports.entities = void 0;
|
|
5
|
+
/* IMPORT ENTITIES AND RESOLVERS */
|
|
6
|
+
const reference_1 = require("./reference");
|
|
7
|
+
const data_sample_mockup_1 = require("./data-sample-mockup");
|
|
8
|
+
exports.entities = [
|
|
9
|
+
/* ENTITIES */
|
|
10
|
+
...reference_1.entities,
|
|
11
|
+
...data_sample_mockup_1.entities
|
|
12
|
+
];
|
|
13
|
+
exports.schema = {
|
|
14
|
+
resolverClasses: [
|
|
15
|
+
/* RESOLVER CLASSES */
|
|
16
|
+
...reference_1.resolvers,
|
|
17
|
+
...data_sample_mockup_1.resolvers
|
|
18
|
+
]
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";AAAA,yBAAyB;;;AAEzB,mCAAmC;AACnC,2CAA4F;AAC5F,6DAAkH;AAErG,QAAA,QAAQ,GAAG;IACtB,cAAc;IACd,GAAG,oBAAiB;IACpB,GAAG,6BAAwB;CAC5B,CAAA;AAEY,QAAA,MAAM,GAAG;IACpB,eAAe,EAAE;QACf,sBAAsB;QACtB,GAAG,qBAAkB;QACrB,GAAG,8BAAwB;KAC5B;CACF,CAAA","sourcesContent":["/* EXPORT ENTITY TYPES */\n\n/* IMPORT ENTITIES AND RESOLVERS */\nimport { entities as ReferenceEntities, resolvers as ReferenceResolvers } from './reference'\nimport { entities as DataSampleMockupEntities, resolvers as DataSampleMockupMutation } from './data-sample-mockup'\n\nexport const entities = [\n /* ENTITIES */\n ...ReferenceEntities,\n ...DataSampleMockupEntities\n]\n\nexport const schema = {\n resolverClasses: [\n /* RESOLVER CLASSES */\n ...ReferenceResolvers,\n ...DataSampleMockupMutation\n ]\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvers = exports.entities = void 0;
|
|
4
|
+
const reference_mutation_1 = require("./reference-mutation");
|
|
5
|
+
const reference_query_1 = require("./reference-query");
|
|
6
|
+
exports.entities = [];
|
|
7
|
+
exports.resolvers = [reference_mutation_1.ReferenceMutation, reference_query_1.ReferenceQuery];
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/reference/index.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AACxD,uDAAkD;AAErC,QAAA,QAAQ,GAAG,EAAE,CAAA;AACb,QAAA,SAAS,GAAG,CAAC,sCAAiB,EAAE,gCAAc,CAAC,CAAA","sourcesContent":["import { ReferenceMutation } from './reference-mutation'\nimport { ReferenceQuery } from './reference-query'\n\nexport const entities = []\nexport const resolvers = [ReferenceMutation, ReferenceQuery]\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractInfos = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
6
|
+
const env_1 = require("@things-factory/env");
|
|
7
|
+
const utils_1 = require("@things-factory/utils");
|
|
8
|
+
const appSyncConfig = env_1.config.get('awsAppSync');
|
|
9
|
+
async function extractInfos(images) {
|
|
10
|
+
const extraction = {
|
|
11
|
+
success_count: true,
|
|
12
|
+
failure_count: true,
|
|
13
|
+
result: {
|
|
14
|
+
boundaries: true,
|
|
15
|
+
texts: true
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const query = utils_1.gqlBuilder.jsonToGraphQLQuery({
|
|
19
|
+
mutation: {
|
|
20
|
+
extractInfos: {
|
|
21
|
+
__args: {
|
|
22
|
+
images
|
|
23
|
+
},
|
|
24
|
+
ocr: extraction,
|
|
25
|
+
barcode: extraction
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const body = JSON.stringify({ query });
|
|
30
|
+
const response = await (0, node_fetch_1.default)(appSyncConfig['apiUrl'], {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/graphql',
|
|
34
|
+
'x-api-key': appSyncConfig['apiKey']
|
|
35
|
+
},
|
|
36
|
+
body
|
|
37
|
+
});
|
|
38
|
+
const jsonRes = await response.json();
|
|
39
|
+
return jsonRes;
|
|
40
|
+
}
|
|
41
|
+
exports.extractInfos = extractInfos;
|
|
42
|
+
// @deprecated
|
|
43
|
+
function getRequestBody(images) {
|
|
44
|
+
// @things-factory/utils gqlBuilder.buildArgs 와 유사
|
|
45
|
+
const imageArgs = images.map(obj => {
|
|
46
|
+
const args = [];
|
|
47
|
+
for (let key in obj) {
|
|
48
|
+
args.push(`${key}: \"${obj[key]}\"`);
|
|
49
|
+
}
|
|
50
|
+
return '{' + args.join(',') + '}';
|
|
51
|
+
});
|
|
52
|
+
// console.log(gqlBuilder.buildArgs(images))
|
|
53
|
+
// console.log(imageArgs)
|
|
54
|
+
const body = JSON.stringify({
|
|
55
|
+
query: `mutation {
|
|
56
|
+
upload(images: ${imageArgs}) {
|
|
57
|
+
success_count
|
|
58
|
+
failure_count
|
|
59
|
+
results {
|
|
60
|
+
boundaries
|
|
61
|
+
texts
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}`
|
|
65
|
+
});
|
|
66
|
+
return body;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=lambda-call.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambda-call.js","sourceRoot":"","sources":["../../../server/service/reference/lambda-call.ts"],"names":[],"mappings":";;;;AAAA,oEAA8B;AAE9B,6CAA4C;AAC5C,iDAAkD;AAElD,MAAM,aAAa,GAAG,YAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;AAEvC,KAAK,UAAU,YAAY,CAAC,MAAM;IACvC,MAAM,UAAU,GAAG;QACjB,aAAa,EAAE,IAAI;QACnB,aAAa,EAAE,IAAI;QACnB,MAAM,EAAE;YACN,UAAU,EAAE,IAAI;YAChB,KAAK,EAAE,IAAI;SACZ;KACF,CAAA;IACD,MAAM,KAAK,GAAG,kBAAU,CAAC,kBAAkB,CAAC;QAC1C,QAAQ,EAAE;YACR,YAAY,EAAE;gBACZ,MAAM,EAAE;oBACN,MAAM;iBACP;gBACD,GAAG,EAAE,UAAU;gBACf,OAAO,EAAE,UAAU;aACpB;SACF;KACF,CAAC,CAAA;IAEF,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IACtC,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,aAAa,CAAC,QAAQ,CAAC,EAAE;QACpD,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,qBAAqB;YACrC,WAAW,EAAE,aAAa,CAAC,QAAQ,CAAC;SACrC;QACD,IAAI;KACL,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IACrC,OAAO,OAAO,CAAA;AAChB,CAAC;AAjCD,oCAiCC;AAED,cAAc;AACd,SAAS,cAAc,CAAC,MAAM;IAC5B,kDAAkD;IAClD,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACjC,MAAM,IAAI,GAAG,EAAE,CAAA;QACf,KAAK,IAAI,GAAG,IAAI,GAAG,EAAE;YACnB,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;SACrC;QACD,OAAO,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAA;IACnC,CAAC,CAAC,CAAA;IAEF,4CAA4C;IAC5C,yBAAyB;IAEzB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;QAC1B,KAAK,EAAE;uBACY,SAAS;;;;;;;;MAQ1B;KACH,CAAC,CAAA;IAEF,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import fetch from 'node-fetch'\n\nimport { config } from '@things-factory/env'\nimport { gqlBuilder } from '@things-factory/utils'\n\nconst appSyncConfig = config.get('awsAppSync')\n\nexport async function extractInfos(images) {\n const extraction = {\n success_count: true,\n failure_count: true,\n result: {\n boundaries: true,\n texts: true\n }\n }\n const query = gqlBuilder.jsonToGraphQLQuery({\n mutation: {\n extractInfos: {\n __args: {\n images\n },\n ocr: extraction,\n barcode: extraction\n }\n }\n })\n\n const body = JSON.stringify({ query })\n const response = await fetch(appSyncConfig['apiUrl'], {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/graphql',\n 'x-api-key': appSyncConfig['apiKey']\n },\n body\n })\n\n const jsonRes = await response.json()\n return jsonRes\n}\n\n// @deprecated\nfunction getRequestBody(images) {\n // @things-factory/utils gqlBuilder.buildArgs 와 유사\n const imageArgs = images.map(obj => {\n const args = []\n for (let key in obj) {\n args.push(`${key}: \\\"${obj[key]}\\\"`)\n }\n return '{' + args.join(',') + '}'\n })\n\n // console.log(gqlBuilder.buildArgs(images))\n // console.log(imageArgs)\n\n const body = JSON.stringify({\n query: `mutation {\n upload(images: ${imageArgs}) { \n success_count\n failure_count\n results {\n boundaries\n texts\n } \n }\n }`\n })\n\n return body\n}\n"]}
|