@things-factory/reference-app 9.0.0-beta.27 → 9.0.0-beta.29

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 (50) hide show
  1. package/dist-server/constants/index.d.ts +1 -0
  2. package/dist-server/constants/index.js +5 -0
  3. package/dist-server/constants/index.js.map +1 -0
  4. package/dist-server/constants/type-constants.d.ts +22 -0
  5. package/dist-server/constants/type-constants.js +26 -0
  6. package/dist-server/constants/type-constants.js.map +1 -0
  7. package/dist-server/controllers/create-data-sample-mockup.d.ts +2 -0
  8. package/dist-server/controllers/create-data-sample-mockup.js +239 -0
  9. package/dist-server/controllers/create-data-sample-mockup.js.map +1 -0
  10. package/dist-server/controllers/index.d.ts +1 -0
  11. package/dist-server/controllers/index.js +5 -0
  12. package/dist-server/controllers/index.js.map +1 -0
  13. package/dist-server/index.d.ts +4 -0
  14. package/dist-server/index.js +8 -0
  15. package/dist-server/index.js.map +1 -0
  16. package/dist-server/middlewares/index.d.ts +1 -0
  17. package/dist-server/middlewares/index.js +7 -0
  18. package/dist-server/middlewares/index.js.map +1 -0
  19. package/dist-server/migrations/index.d.ts +1 -0
  20. package/dist-server/migrations/index.js +12 -0
  21. package/dist-server/migrations/index.js.map +1 -0
  22. package/dist-server/routes.d.ts +0 -0
  23. package/dist-server/routes.js +24 -0
  24. package/dist-server/routes.js.map +1 -0
  25. package/dist-server/service/data-sample-mockup/data-sample-mockup-mutation.d.ts +4 -0
  26. package/dist-server/service/data-sample-mockup/data-sample-mockup-mutation.js +28 -0
  27. package/dist-server/service/data-sample-mockup/data-sample-mockup-mutation.js.map +1 -0
  28. package/dist-server/service/data-sample-mockup/data-sample-mockup-type.d.ts +4 -0
  29. package/dist-server/service/data-sample-mockup/data-sample-mockup-type.js +20 -0
  30. package/dist-server/service/data-sample-mockup/data-sample-mockup-type.js.map +1 -0
  31. package/dist-server/service/data-sample-mockup/index.d.ts +3 -0
  32. package/dist-server/service/data-sample-mockup/index.js +7 -0
  33. package/dist-server/service/data-sample-mockup/index.js.map +1 -0
  34. package/dist-server/service/index.d.ts +4 -0
  35. package/dist-server/service/index.js +20 -0
  36. package/dist-server/service/index.js.map +1 -0
  37. package/dist-server/service/reference/index.d.ts +4 -0
  38. package/dist-server/service/reference/index.js +8 -0
  39. package/dist-server/service/reference/index.js.map +1 -0
  40. package/dist-server/service/reference/lambda-call.d.ts +1 -0
  41. package/dist-server/service/reference/lambda-call.js +67 -0
  42. package/dist-server/service/reference/lambda-call.js.map +1 -0
  43. package/dist-server/service/reference/reference-mutation.d.ts +5 -0
  44. package/dist-server/service/reference/reference-mutation.js +63 -0
  45. package/dist-server/service/reference/reference-mutation.js.map +1 -0
  46. package/dist-server/service/reference/reference-query.d.ts +7 -0
  47. package/dist-server/service/reference/reference-query.js +84 -0
  48. package/dist-server/service/reference/reference-query.js.map +1 -0
  49. package/dist-server/tsconfig.tsbuildinfo +1 -0
  50. package/package.json +36 -36
@@ -0,0 +1 @@
1
+ export * from './type-constants';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./type-constants"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -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,22 @@
1
+ /**
2
+ * Inventory Type
3
+ */
4
+ export declare const ROH_INVENTORY = "ROH";
5
+ export declare const FINISHED_INVENTORY = "FINISHED";
6
+ /**
7
+ * Product Type
8
+ */
9
+ export declare const PRODUCT_TYPE: {
10
+ FERT: string;
11
+ HALB: string;
12
+ ROH: string;
13
+ };
14
+ /**
15
+ * Warehouse Type
16
+ */
17
+ export declare const WAREHOUSE_TYPE: {
18
+ FINISHED: string;
19
+ HALF_COLD: string;
20
+ HALF_FROZEN: string;
21
+ ROH: string;
22
+ };
@@ -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,2 @@
1
+ import { DataSampleMockupInfo } from '../service/data-sample-mockup/data-sample-mockup-type';
2
+ export declare function generateMockupData(params: DataSampleMockupInfo, context: ResolverContext): Promise<Boolean>;
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateMockupData = generateMockupData;
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
+ //# 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":";;AA+OA,gDA0CC;;AAzRD,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,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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(params: DataSampleMockupInfo, context: ResolverContext): 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
+ export * from './create-data-sample-mockup';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./create-data-sample-mockup"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -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,4 @@
1
+ import './routes';
2
+ export * from './service';
3
+ export * from './migrations';
4
+ export * from './middlewares';
@@ -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 @@
1
+ export declare function initMiddlewares(app: any): void;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initMiddlewares = initMiddlewares;
4
+ function initMiddlewares(app) {
5
+ /* can add middlewares into app */
6
+ }
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/middlewares/index.ts"],"names":[],"mappings":";;AAAA,0CAEC;AAFD,SAAgB,eAAe,CAAC,GAAG;IACjC,kCAAkC;AACpC,CAAC","sourcesContent":["export function initMiddlewares(app) {\n /* can add middlewares into app */\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare var migrations: any[];
@@ -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"]}
File without changes
@@ -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,4 @@
1
+ import { DataSampleMockupInfo } from './data-sample-mockup-type';
2
+ export declare class DataSampleMockupMutation {
3
+ generateMockupData(params: DataSampleMockupInfo, context: ResolverContext): Promise<Boolean>;
4
+ }
@@ -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
+ exports.DataSampleMockupMutation = DataSampleMockupMutation;
15
+ tslib_1.__decorate([
16
+ (0, type_graphql_1.Directive)('@privilege(category: "data-sample", privilege: "mutation", domainOwnerGranted: true)'),
17
+ (0, type_graphql_1.Directive)('@transaction'),
18
+ (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To generate data sample one' }),
19
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('params')),
20
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
21
+ tslib_1.__metadata("design:type", Function),
22
+ tslib_1.__metadata("design:paramtypes", [data_sample_mockup_type_1.DataSampleMockupInfo, Object]),
23
+ tslib_1.__metadata("design:returntype", Promise)
24
+ ], DataSampleMockupMutation.prototype, "generateMockupData", null);
25
+ exports.DataSampleMockupMutation = DataSampleMockupMutation = tslib_1.__decorate([
26
+ (0, type_graphql_1.Resolver)(dataset_1.DataSample)
27
+ ], 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;AAGtE,qDAAoD;AAEpD,2FAAgF;AAChF,uEAAgE;AAGzD,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAI7B,AAAN,KAAK,CAAC,kBAAkB,CAAgB,MAA4B,EAAS,OAAwB;QACnG,OAAO,MAAM,IAAA,8CAAkB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClD,CAAC;CACF,CAAA;AAPY,4DAAwB;AAI7B;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;IACnD,mBAAA,IAAA,kBAAG,EAAC,QAAQ,CAAC,CAAA;IAAgC,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAA5B,8CAAoB;;kEAEnE;mCANU,wBAAwB;IADpC,IAAA,uBAAQ,EAAC,oBAAU,CAAC;GACR,wBAAwB,CAOpC","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { User } from '@things-factory/auth-base'\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(@Arg('params') params: DataSampleMockupInfo, @Ctx() context: ResolverContext): Promise<Boolean> {\n return await generateMockupData(params, context)\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export declare class DataSampleMockupInfo {
2
+ dataSetId?: string;
3
+ numSamples?: number;
4
+ }
@@ -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
+ exports.DataSampleMockupInfo = DataSampleMockupInfo;
9
+ tslib_1.__decorate([
10
+ (0, type_graphql_1.Field)(),
11
+ tslib_1.__metadata("design:type", String)
12
+ ], DataSampleMockupInfo.prototype, "dataSetId", void 0);
13
+ tslib_1.__decorate([
14
+ (0, type_graphql_1.Field)({ nullable: true }),
15
+ tslib_1.__metadata("design:type", Number)
16
+ ], DataSampleMockupInfo.prototype, "numSamples", void 0);
17
+ exports.DataSampleMockupInfo = DataSampleMockupInfo = tslib_1.__decorate([
18
+ (0, type_graphql_1.InputType)()
19
+ ], 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;AANY,oDAAoB;AAE/B;IADC,IAAA,oBAAK,GAAE;;uDACU;AAGlB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;wDACP;+BALR,oBAAoB;IADhC,IAAA,wBAAS,GAAE;GACC,oBAAoB,CAMhC","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,3 @@
1
+ import { DataSampleMockupMutation } from './data-sample-mockup-mutation';
2
+ export declare const entities: any[];
3
+ export declare const resolvers: (typeof DataSampleMockupMutation)[];
@@ -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,4 @@
1
+ export declare const entities: any[];
2
+ export declare const schema: {
3
+ resolverClasses: (typeof import("./reference/reference-mutation").ReferenceMutation | typeof import("./reference/reference-query").ReferenceQuery | typeof import("./data-sample-mockup/data-sample-mockup-mutation").DataSampleMockupMutation)[];
4
+ };
@@ -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,4 @@
1
+ import { ReferenceMutation } from './reference-mutation';
2
+ import { ReferenceQuery } from './reference-query';
3
+ export declare const entities: any[];
4
+ export declare const resolvers: (typeof ReferenceMutation | typeof ReferenceQuery)[];
@@ -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 @@
1
+ export declare function extractInfos(images: any): Promise<any>;