@fixefy/fixefy-ui-utils 0.0.6 → 0.0.7

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 (54) hide show
  1. package/dist-cjs/auth/index.js +13 -0
  2. package/dist-cjs/aws/aws_lambda_helper.js +49 -0
  3. package/dist-cjs/aws/aws_s3_helper.js +1 -0
  4. package/dist-cjs/aws/data_models.js +2 -0
  5. package/dist-cjs/aws/index.js +4 -0
  6. package/dist-cjs/commander/index.jsx +63 -67
  7. package/dist-cjs/contents/index.jsx +32 -0
  8. package/dist-cjs/files/index.js +27 -0
  9. package/dist-cjs/graphql/index.js +217 -0
  10. package/dist-cjs/images/index.js +10 -2
  11. package/dist-cjs/index.js +8 -0
  12. package/dist-cjs/json/index.js +135 -0
  13. package/dist-cjs/redirect/index.js +15 -0
  14. package/dist-cjs/renderer/index.jsx +66 -0
  15. package/dist-cjs/resolvers/index.js +35 -0
  16. package/dist-cjs/transform/index.js +40 -0
  17. package/dist-cjs/validate/index.js +44 -0
  18. package/dist-es/auth/index.js +11 -0
  19. package/dist-es/aws/aws_lambda_helper.js +41 -0
  20. package/dist-es/aws/aws_s3_helper.js +1 -0
  21. package/dist-es/aws/data_models.js +1 -0
  22. package/dist-es/aws/index.js +1 -0
  23. package/dist-es/commander/index.jsx +59 -63
  24. package/dist-es/contents/index.jsx +31 -0
  25. package/dist-es/files/index.js +22 -0
  26. package/dist-es/graphql/index.js +235 -0
  27. package/dist-es/images/index.js +9 -1
  28. package/dist-es/index.js +8 -0
  29. package/dist-es/json/index.js +125 -0
  30. package/dist-es/redirect/index.js +12 -0
  31. package/dist-es/renderer/index.jsx +60 -0
  32. package/dist-es/resolvers/index.js +31 -0
  33. package/dist-es/transform/index.js +35 -0
  34. package/dist-es/validate/index.js +37 -0
  35. package/dist-types/auth/index.d.ts +2 -0
  36. package/dist-types/aws/aws_lambda_helper.d.ts +5 -0
  37. package/dist-types/aws/aws_s3_helper.d.ts +0 -0
  38. package/dist-types/aws/data_models.d.ts +21 -0
  39. package/dist-types/aws/index.d.ts +1 -0
  40. package/dist-types/contents/index.d.ts +3 -0
  41. package/dist-types/files/index.d.ts +2 -0
  42. package/dist-types/graphql/index.d.ts +38 -0
  43. package/dist-types/images/index.d.ts +4 -1
  44. package/dist-types/index.d.ts +8 -0
  45. package/dist-types/json/index.d.ts +7 -0
  46. package/dist-types/redirect/index.d.ts +2 -0
  47. package/dist-types/renderer/index.d.ts +9 -0
  48. package/dist-types/resolvers/index.d.ts +11 -0
  49. package/dist-types/transform/index.d.ts +2 -0
  50. package/dist-types/validate/index.d.ts +4 -0
  51. package/package.json +6 -1
  52. package/dist-cjs/images/image_loader.js +0 -13
  53. package/dist-es/images/image_loader.js +0 -9
  54. package/dist-types/images/image_loader.d.ts +0 -4
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getToken = exports.attachAuth = void 0;
4
+ const nookies_1 = require("nookies");
5
+ const attachAuth = (ctx, headers) => {
6
+ const token = (0, exports.getToken)(ctx);
7
+ return Object.assign(Object.assign({}, headers), { authorization: `Bearer ${token}` });
8
+ };
9
+ exports.attachAuth = attachAuth;
10
+ const getToken = (ctx) => {
11
+ return (0, nookies_1.parseCookies)(ctx)['token'];
12
+ };
13
+ exports.getToken = getToken;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLambdaResult = exports.generateMappings = exports.getLambdaParams = exports.getLambda = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const aws_sdk_1 = tslib_1.__importDefault(require("aws-sdk"));
6
+ const getLambda = (args) => {
7
+ const { key, region, secret } = args, lambdaCredentials = new aws_sdk_1.default.Credentials({ accessKeyId: key, secretAccessKey: secret }), rv = new aws_sdk_1.default.Lambda({ credentials: lambdaCredentials, region, maxRetries: 0, httpOptions: { connectTimeout: 30000, timeout: 300000 } });
8
+ return rv;
9
+ };
10
+ exports.getLambda = getLambda;
11
+ const getLambdaParams = (args) => {
12
+ const { authorization, file_name, function_name: functionName, raw, ws } = args, clientContextObj = { authorization, file_name, ws }, clientContext = '';
13
+ const rv = {
14
+ ClientContext: clientContext,
15
+ FunctionName: functionName,
16
+ InvocationType: 'RequestResponse',
17
+ Payload: '',
18
+ };
19
+ return rv;
20
+ };
21
+ exports.getLambdaParams = getLambdaParams;
22
+ const generateMappings = (args) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
23
+ const params = (0, exports.getLambdaParams)(args);
24
+ const lambda = (0, exports.getLambda)(args);
25
+ const p = new Promise((resolve, reject) => {
26
+ lambda.invoke(params, (err, data) => {
27
+ if (err) {
28
+ reject(err);
29
+ }
30
+ else {
31
+ resolve(data);
32
+ }
33
+ });
34
+ });
35
+ const result = yield p;
36
+ const rv = (0, exports.getLambdaResult)({ result });
37
+ return rv;
38
+ });
39
+ exports.generateMappings = generateMappings;
40
+ const getLambdaResult = (args) => {
41
+ const { result: { ExecutedVersion: executedVersion, FunctionError: functionError, LogResult: logResult, Payload: payload, StatusCode: statusCode }, } = args;
42
+ let rv = { execute_version: executedVersion, function_error: functionError, log_result: logResult, status_code: statusCode };
43
+ if (payload != null) {
44
+ const payloadObject = JSON.parse(payload);
45
+ rv = Object.assign(Object.assign({}, rv), { body: payloadObject, error: payloadObject.errorMessage });
46
+ }
47
+ return rv;
48
+ };
49
+ exports.getLambdaResult = getLambdaResult;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./aws_lambda_helper"), exports);
@@ -2,22 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getScoreColor = exports.useStatePromisify = exports.trimRuleCode = exports.toWords = exports.toPascalCase = exports.toInitials = exports.toCurrency = exports.toCamelCaseString = exports.toCamelCase = exports.titleCase = exports.normalizeStringBodyRaw = exports.normalizeTimestamp = exports.nest = exports.makeString = exports.lineString = exports.isValidTimestamp = exports.isInServer = exports.getVal = exports.getStringValueByValueType = exports.getNormalizationKeyForEntity = exports.formatNumberWithCommas = exports.determineIconByEvent = exports.convertToString = exports.copyToClipboard = exports.buildCode = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const fixefy_numeric_1 = tslib_1.__importDefault(require("@fixefy/fixefy-numeric"));
5
+ const __1 = require("../");
6
6
  const date_fns_1 = require("date-fns");
7
7
  const react_1 = require("react");
8
- const constants_1 = require("../constants");
8
+ const fixefy_numeric_1 = tslib_1.__importDefault(require("@fixefy/fixefy-numeric"));
9
9
  function buildCode(obj, level = 0, name) {
10
10
  const toRender = [];
11
11
  const keys = Object.keys(obj);
12
12
  if (keys.length < 1) {
13
- toRender.push(lineString(level, name) + "{}");
13
+ toRender.push(lineString(level, name) + '{}');
14
14
  return toRender;
15
15
  }
16
- toRender.push(lineString(level, name) + "{");
16
+ toRender.push(lineString(level, name) + '{');
17
17
  keys.forEach((key) => {
18
- if (key === "__typename")
18
+ if (key === '__typename')
19
19
  return;
20
- if (typeof obj[key] === "object" && obj[key] !== null) {
20
+ if (typeof obj[key] === 'object' && obj[key] !== null) {
21
21
  toRender.push(...buildCode(obj[key], level + 1, key));
22
22
  }
23
23
  else {
@@ -25,27 +25,27 @@ function buildCode(obj, level = 0, name) {
25
25
  toRender.push(lineString(level + 1, key) + val);
26
26
  }
27
27
  });
28
- toRender.push(lineString(level) + "}");
28
+ toRender.push(lineString(level) + '}');
29
29
  return toRender;
30
30
  }
31
31
  exports.buildCode = buildCode;
32
32
  const copyToClipboard = (str) => {
33
33
  if (window == undefined)
34
34
  return;
35
- const el = document.createElement("textarea");
35
+ const el = document.createElement('textarea');
36
36
  el.value = str;
37
- el.setAttribute("readonly", "");
38
- el.style.position = "absolute";
39
- el.style.left = "-9999px";
37
+ el.setAttribute('readonly', '');
38
+ el.style.position = 'absolute';
39
+ el.style.left = '-9999px';
40
40
  document.body.appendChild(el);
41
41
  el.select();
42
- document.execCommand("copy");
42
+ document.execCommand('copy');
43
43
  document.body.removeChild(el);
44
44
  };
45
45
  exports.copyToClipboard = copyToClipboard;
46
46
  function convertToString(input) {
47
47
  if (input) {
48
- return typeof input === "string" ? input : String(input);
48
+ return typeof input === 'string' ? input : String(input);
49
49
  }
50
50
  }
51
51
  exports.convertToString = convertToString;
@@ -53,14 +53,14 @@ const determineIconByEvent = (event) => {
53
53
  let rv;
54
54
  if (event) {
55
55
  switch (event.type) {
56
- case "charged":
57
- rv = "../../static/images/transactions/billing.svg";
56
+ case 'charged':
57
+ rv = '../../static/images/transactions/billing.svg';
58
58
  break;
59
- case "packed":
60
- rv = "../../static/images/transactions/system.svg";
59
+ case 'packed':
60
+ rv = '../../static/images/transactions/system.svg';
61
61
  break;
62
62
  default:
63
- rv = "../../static/images/transactions/user.svg";
63
+ rv = '../../static/images/transactions/user.svg';
64
64
  break;
65
65
  }
66
66
  }
@@ -68,27 +68,27 @@ const determineIconByEvent = (event) => {
68
68
  };
69
69
  exports.determineIconByEvent = determineIconByEvent;
70
70
  function formatNumberWithCommas(number) {
71
- return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
71
+ return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
72
72
  }
73
73
  exports.formatNumberWithCommas = formatNumberWithCommas;
74
74
  function getNormalizationKeyForEntity(entity_type) {
75
75
  let rv;
76
76
  switch (entity_type.toLowerCase()) {
77
- case constants_1.EntityTypes.User:
78
- rv = "username";
77
+ case __1.EntityTypes.User:
78
+ rv = 'username';
79
79
  break;
80
- case constants_1.EntityTypes.Pricing:
81
- rv = "value";
80
+ case __1.EntityTypes.Pricing:
81
+ rv = 'value';
82
82
  break;
83
- case constants_1.EntityTypes.Metadata:
84
- rv = "title";
83
+ case __1.EntityTypes.Metadata:
84
+ rv = 'title';
85
85
  break;
86
- case constants_1.EntityTypes.Transaction:
87
- case constants_1.EntityTypes.Transmission:
88
- rv = "readable_id";
86
+ case __1.EntityTypes.Transaction:
87
+ case __1.EntityTypes.Transmission:
88
+ rv = 'readable_id';
89
89
  break;
90
90
  default:
91
- rv = "title";
91
+ rv = 'title';
92
92
  break;
93
93
  }
94
94
  return rv;
@@ -97,16 +97,16 @@ exports.getNormalizationKeyForEntity = getNormalizationKeyForEntity;
97
97
  const getStringValueByValueType = ({ value, name }) => {
98
98
  let rv;
99
99
  switch (typeof value) {
100
- case "boolean":
101
- rv = value === true ? "YES" : "NO";
100
+ case 'boolean':
101
+ rv = value === true ? 'YES' : 'NO';
102
102
  break;
103
- case "number":
103
+ case 'number':
104
104
  if ((0, exports.isValidTimestamp)(value)) {
105
105
  rv = normalizeTimestamp(value, false);
106
106
  break;
107
107
  }
108
108
  let _rv = Number(value) === value && value % 1 === 0 ? value : value.toFixed(2);
109
- if (name === "variance") {
109
+ if (name === 'variance') {
110
110
  _rv = (_rv * 100).toFixed(1);
111
111
  rv = `${_rv}%`;
112
112
  }
@@ -114,16 +114,16 @@ const getStringValueByValueType = ({ value, name }) => {
114
114
  rv = _rv;
115
115
  }
116
116
  break;
117
- case "object":
117
+ case 'object':
118
118
  if (Array.isArray(value)) {
119
- rv = value.join(", ");
119
+ rv = value.join(', ');
120
120
  }
121
121
  else {
122
122
  const entity_type = value && value.__typename && value.__typename.toLowerCase();
123
123
  rv = titleCase(value[getNormalizationKeyForEntity(entity_type)]);
124
124
  }
125
125
  break;
126
- case "string":
126
+ case 'string':
127
127
  rv = titleCase(value);
128
128
  break;
129
129
  }
@@ -131,36 +131,36 @@ const getStringValueByValueType = ({ value, name }) => {
131
131
  };
132
132
  exports.getStringValueByValueType = getStringValueByValueType;
133
133
  function getVal(val) {
134
- if (typeof val === "number")
134
+ if (typeof val === 'number')
135
135
  return val;
136
- if (typeof val === "string")
136
+ if (typeof val === 'string')
137
137
  return `"${val}"`;
138
138
  return val;
139
139
  }
140
140
  exports.getVal = getVal;
141
- const isInServer = () => typeof window === "undefined";
141
+ const isInServer = () => typeof window === 'undefined';
142
142
  exports.isInServer = isInServer;
143
143
  const isValidTimestamp = (_timestamp) => {
144
- const parsedNumber = typeof _timestamp == "string" ? parseInt(_timestamp) : _timestamp;
144
+ const parsedNumber = typeof _timestamp == 'string' ? parseInt(_timestamp) : _timestamp;
145
145
  const newTimestamp = new Date(parsedNumber).getTime();
146
146
  const rv = fixefy_numeric_1.default.isFloat(newTimestamp) && newTimestamp.toString().length >= 10;
147
147
  return rv;
148
148
  };
149
149
  exports.isValidTimestamp = isValidTimestamp;
150
150
  function lineString(level, name) {
151
- let str = "";
151
+ let str = '';
152
152
  for (let i = 0; i < level; i++) {
153
- str += " ";
153
+ str += ' ';
154
154
  }
155
155
  if (name) {
156
- str += name + ": ";
156
+ str += name + ': ';
157
157
  }
158
158
  return str;
159
159
  }
160
160
  exports.lineString = lineString;
161
161
  function makeString(len = 5) {
162
- var text = "";
163
- var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
162
+ var text = '';
163
+ var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
164
164
  for (var i = 0; i < len; i++)
165
165
  text += possible.charAt(Math.floor(Math.random() * possible.length));
166
166
  return text;
@@ -173,8 +173,7 @@ const nest = ({ items }) => {
173
173
  items.forEach((item) => {
174
174
  if (item) {
175
175
  if (item.parent)
176
- mappedArray[item.parent] &&
177
- mappedArray[item.parent].children.push(mappedArray[item.id]);
176
+ mappedArray[item.parent] && mappedArray[item.parent].children.push(mappedArray[item.id]);
178
177
  else
179
178
  nestedArray.push(mappedArray[item.id]);
180
179
  }
@@ -184,24 +183,22 @@ const nest = ({ items }) => {
184
183
  exports.nest = nest;
185
184
  function normalizeTimestamp(timestamp, options) {
186
185
  const { dateOnly, format: _format } = options || {};
187
- const _timestamp = typeof timestamp == "string" ? parseInt(timestamp) : timestamp;
188
- const rv = (0, date_fns_1.format)(new Date(_timestamp), _format ? _format : dateOnly ? "dd/MM/yyyy" : "dd/MM/yyyy hh:mm");
186
+ const _timestamp = typeof timestamp == 'string' ? parseInt(timestamp) : timestamp;
187
+ const rv = (0, date_fns_1.format)(new Date(_timestamp), _format ? _format : dateOnly ? 'dd/MM/yyyy' : 'dd/MM/yyyy hh:mm');
189
188
  return rv;
190
189
  }
191
190
  exports.normalizeTimestamp = normalizeTimestamp;
192
191
  function normalizeStringBodyRaw(key, body) {
193
- return typeof body[key] === "string" && (key === "body" || key === "raw")
194
- ? JSON.parse(body[key])
195
- : body[key];
192
+ return typeof body[key] === 'string' && (key === 'body' || key === 'raw') ? JSON.parse(body[key]) : body[key];
196
193
  }
197
194
  exports.normalizeStringBodyRaw = normalizeStringBodyRaw;
198
- function titleCase(str = "") {
195
+ function titleCase(str = '') {
199
196
  return str && toPascalCase(str.toString(), true);
200
197
  }
201
198
  exports.titleCase = titleCase;
202
199
  function toCamelCase(inputArray) {
203
200
  var _a;
204
- let result = "";
201
+ let result = '';
205
202
  for (let i = 0, len = (_a = inputArray === null || inputArray === void 0 ? void 0 : inputArray.length) !== null && _a !== void 0 ? _a : 0; i < len; i++) {
206
203
  let currentStr = inputArray === null || inputArray === void 0 ? void 0 : inputArray.at(i);
207
204
  let tempStr = currentStr.toLowerCase();
@@ -219,19 +216,18 @@ function toCamelCaseString(input) {
219
216
  }
220
217
  exports.toCamelCaseString = toCamelCaseString;
221
218
  const toCurrency = (input) => {
222
- return input ? input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : input;
219
+ return input ? input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') : input;
223
220
  };
224
221
  exports.toCurrency = toCurrency;
225
222
  const toInitials = (str) => {
226
- if (str === "")
223
+ if (str === '')
227
224
  return str;
228
225
  var matches = str.match(/\b(\w)/g);
229
- return matches === null || matches === void 0 ? void 0 : matches.join("").toUpperCase();
226
+ return matches === null || matches === void 0 ? void 0 : matches.join('').toUpperCase();
230
227
  };
231
228
  exports.toInitials = toInitials;
232
229
  function toPascalCase(string, title = false) {
233
- return (string &&
234
- string.replace(/(_[a-z])?(^[a-z])?(_|\s[a-z])?/g, ($1) => $1.toUpperCase().replace("_", title ? " " : "")));
230
+ return string && string.replace(/(_[a-z])?(^[a-z])?(_|\s[a-z])?/g, ($1) => $1.toUpperCase().replace('_', title ? ' ' : ''));
235
231
  }
236
232
  exports.toPascalCase = toPascalCase;
237
233
  function toWords(input) {
@@ -241,9 +237,9 @@ function toWords(input) {
241
237
  }
242
238
  exports.toWords = toWords;
243
239
  function trimRuleCode(input) {
244
- const stringefied = typeof input == "string" ? input : JSON.stringify(input);
245
- let match = stringefied.substring(stringefied.indexOf("{") + 1, stringefied.lastIndexOf("}"));
246
- return match ? match : "";
240
+ const stringefied = typeof input == 'string' ? input : JSON.stringify(input);
241
+ let match = stringefied.substring(stringefied.indexOf('{') + 1, stringefied.lastIndexOf('}'));
242
+ return match ? match : '';
247
243
  }
248
244
  exports.trimRuleCode = trimRuleCode;
249
245
  const useStatePromisify = (_state) => {
@@ -266,19 +262,19 @@ const useStatePromisify = (_state) => {
266
262
  exports.useStatePromisify = useStatePromisify;
267
263
  const getScoreColor = (value) => {
268
264
  if (value <= 20) {
269
- return "bad";
265
+ return 'bad';
270
266
  }
271
267
  else if (value <= 40) {
272
- return "low";
268
+ return 'low';
273
269
  }
274
270
  else if (value <= 60) {
275
- return "medium";
271
+ return 'medium';
276
272
  }
277
273
  else if (value <= 80) {
278
- return "high";
274
+ return 'high';
279
275
  }
280
276
  else {
281
- return "excellent";
277
+ return 'excellent';
282
278
  }
283
279
  };
284
280
  exports.getScoreColor = getScoreColor;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseInput = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const __1 = require("../");
7
+ const fixefy_ui_components_1 = require("@fixefy/fixefy-ui-components");
8
+ const parseInput = (_a) => {
9
+ var { client, fetcher, control, structure, droppedItem, state, onInputChange, classes, args } = _a, rest = tslib_1.__rest(_a, ["client", "fetcher", "control", "structure", "droppedItem", "state", "onInputChange", "classes", "args"]);
10
+ const { type, children } = structure;
11
+ const { AsyncDropdown, Textfield, clear, dropdownOptions } = __1.ComponentTypes;
12
+ switch (type) {
13
+ case AsyncDropdown: {
14
+ return <fixefy_ui_components_1.FxAsyncDropdown classes={classes} structure={structure} fetcher={fetcher} onChange={() => { }} {...rest}/>;
15
+ }
16
+ case Textfield: {
17
+ return <fixefy_ui_components_1.FxTextField autoFocus={true} droppedItem={droppedItem} defaultValue={args && args.data && args.data.default_value} onChange={(e) => onInputChange({ structure, value: e.target.value })} structure={structure} {...rest}/>;
18
+ }
19
+ case dropdownOptions:
20
+ return children.map((child) => {
21
+ return (0, exports.parseInput)(Object.assign({ client,
22
+ control, structure: child, droppedItem,
23
+ state,
24
+ onInputChange,
25
+ classes,
26
+ args }, rest));
27
+ });
28
+ case clear:
29
+ return <fixefy_ui_components_1.FxButton {...rest}>{structure.name}</fixefy_ui_components_1.FxButton>;
30
+ }
31
+ };
32
+ exports.parseInput = parseInput;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertFileTypeToIcon = exports.convertFileSize = void 0;
4
+ const convertFileSize = (fileSize) => {
5
+ if (fileSize < 10000) {
6
+ return `${(fileSize / 1000).toFixed(1)} KB`;
7
+ }
8
+ else if (fileSize < 10000000) {
9
+ return `${(fileSize / 1000000).toFixed(1)} MB`;
10
+ }
11
+ };
12
+ exports.convertFileSize = convertFileSize;
13
+ const convertFileTypeToIcon = (fileType) => {
14
+ switch (fileType) {
15
+ case 'text/csv':
16
+ return 'uploader/file_type_csv.svg';
17
+ case 'text/xml':
18
+ return 'uploader/file_type_xml.svg';
19
+ case 'text/json':
20
+ return 'uploader/file_type_json.svg';
21
+ case 'text/xls':
22
+ return 'uploader/file_type_xls.svg';
23
+ default:
24
+ return 'uploader/file_type_csv.svg';
25
+ }
26
+ };
27
+ exports.convertFileTypeToIcon = convertFileTypeToIcon;
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseInputDataToDataObject = exports.isArgMandatory = exports.insertNewVariable = exports.getVariablesKeys = exports.getOperationTypeForMutation = exports.getOperationObjectFromSchema = exports.getTypeName = exports.getTypeKind = exports.getFieldsStringified = exports.getFields = exports.draggableTypes = exports.operationTypes = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
6
+ const language_1 = require("graphql/language");
7
+ exports.operationTypes = {
8
+ MUTATIONS: {
9
+ CREATE: 'mutations.create',
10
+ DELETE: 'mutations.delete',
11
+ UPDATE: 'mutations.update',
12
+ ACTION: 'mutations.action',
13
+ },
14
+ QUERIES: 'queries',
15
+ SUBSCRIPTIONS: 'subscriptions',
16
+ };
17
+ exports.draggableTypes = {
18
+ ACTION: 'action',
19
+ ENTITY: 'entity',
20
+ FRAGMENT: 'fragment',
21
+ VARIABLES: 'variables',
22
+ };
23
+ const getFields = ({ arg }) => (arg.type.getFields ? arg.type.getFields() : arg.type._nameLookup ? arg.type._nameLookup : arg.type.ofType && arg.type.ofType.getFields ? arg.type.ofType.getFields() : arg.type.ofType && arg.type.ofType.ofType && arg.type.ofType.ofType.getFields ? arg.type.ofType.ofType.getFields() : {});
24
+ exports.getFields = getFields;
25
+ const getFieldsStringified = ({ arg }) => (arg.type.getFields ? Object.keys(arg.type.getFields()) : arg.type.getValues ? Object.keys(arg.type.getValues()) : arg.type.ofType && arg.type.ofType.getFields ? Object.keys(arg.type.ofType.getFields()) : []);
26
+ exports.getFieldsStringified = getFieldsStringified;
27
+ const getTypeKind = (object) => {
28
+ return object && object.astNode && object.astNode.type && object.astNode.type.kind ? object.astNode.type.kind : object && object.astNode && object.astNode.kind ? object.astNode.kind : undefined;
29
+ };
30
+ exports.getTypeKind = getTypeKind;
31
+ const getTypeName = (object) => {
32
+ return object && object.type ? (object.type.ofType ? object.type.ofType.name : object && object.type.name && object.type.name) : object.astNode && object.astNode.name;
33
+ };
34
+ exports.getTypeName = getTypeName;
35
+ const getOperationObjectFromSchema = ({ operationName, schema }) => {
36
+ const queries = schema.getQueryType().getFields();
37
+ const mutations = schema.getMutationType().getFields();
38
+ const subscriptions = schema.getSubscriptionType().getFields();
39
+ let operationType;
40
+ let rv;
41
+ if (operationName in mutations) {
42
+ operationType = (0, exports.getOperationTypeForMutation)({ operationName });
43
+ rv = mutations[operationName];
44
+ }
45
+ else if (operationName in queries) {
46
+ operationType = exports.operationTypes.QUERIES;
47
+ rv = queries[operationName];
48
+ }
49
+ else if (operationName in subscriptions) {
50
+ operationType = exports.operationTypes.SUBSCRIPTIONS;
51
+ rv = subscriptions[operationName];
52
+ }
53
+ return [rv, operationType];
54
+ };
55
+ exports.getOperationObjectFromSchema = getOperationObjectFromSchema;
56
+ const getOperationTypeForMutation = ({ operationName }) => {
57
+ let operationType;
58
+ if (operationName.includes('create')) {
59
+ operationType = exports.operationTypes.MUTATIONS.CREATE;
60
+ }
61
+ else if (operationName.includes('update')) {
62
+ operationType = exports.operationTypes.MUTATIONS.UPDATE;
63
+ }
64
+ else if (operationName.includes('delete')) {
65
+ operationType = exports.operationTypes.MUTATIONS.DELETE;
66
+ }
67
+ else {
68
+ operationType = exports.operationTypes.MUTATIONS.ACTION;
69
+ }
70
+ return operationType;
71
+ };
72
+ exports.getOperationTypeForMutation = getOperationTypeForMutation;
73
+ const getVariablesKeys = ({ variables, operationType }) => {
74
+ if (variables && variables != '') {
75
+ variables = JSON.parse(variables);
76
+ switch (operationType) {
77
+ case exports.operationTypes.QUERIES:
78
+ const where = variables && variables.where;
79
+ return where && typeof where === 'object' ? Object.keys(where) : undefined;
80
+ case exports.operationTypes.MUTATIONS.CREATE:
81
+ const data = variables && variables['data'];
82
+ return data && Array.isArray(data) ? Object.keys(data[0]) : typeof data === 'object' ? Object.keys(data) : undefined;
83
+ default:
84
+ const obj = (variables && variables['data']) || variables.where;
85
+ return obj && Array.isArray(obj) && obj.length > 0 ? Object.keys(obj[0]) : typeof obj === 'object' ? Object.keys(obj) : undefined;
86
+ }
87
+ }
88
+ };
89
+ exports.getVariablesKeys = getVariablesKeys;
90
+ const insertNewVariable = ({ operationName, schema, key, value, _variables, action, ctx }) => {
91
+ const [raw, _] = (0, exports.getOperationObjectFromSchema)({ operationName, schema });
92
+ Object.keys(_variables).forEach((upper_key) => {
93
+ if (raw) {
94
+ parseArgs({ raw, _variables, upper_key, key, action, value });
95
+ }
96
+ else {
97
+ throw `No Schema Action - '${operationName} - Go check the schema again'`;
98
+ }
99
+ });
100
+ };
101
+ exports.insertNewVariable = insertNewVariable;
102
+ const isArgMandatory = (arg) => {
103
+ const kind = (0, exports.getTypeKind)(arg);
104
+ const rv = kind === language_1.Kind.NON_NULL_TYPE;
105
+ return rv;
106
+ };
107
+ exports.isArgMandatory = isArgMandatory;
108
+ const parseInputDataToDataObject = (_a) => {
109
+ var { key, value, parent, method, list, state } = _a, rest = tslib_1.__rest(_a, ["key", "value", "parent", "method", "list", "state"]);
110
+ let rv = state;
111
+ const type = typeof value;
112
+ switch (type) {
113
+ case 'string':
114
+ case 'number':
115
+ case 'boolean':
116
+ case 'bigint':
117
+ rv = parent
118
+ ? Object.assign(Object.assign({}, rv), { [parent]: Object.assign(Object.assign({}, rv[parent]), { [method]: Object.assign(Object.assign({}, rv[parent][method]), { [key]: value }) }) }) : Object.assign(Object.assign({}, rv), { [key]: value });
119
+ break;
120
+ case 'object':
121
+ rv = parent
122
+ ? {
123
+ [parent]: Object.assign(Object.assign({}, rv[parent]), { [method]: Object.assign({}, rv[parent][method]) }),
124
+ }
125
+ : Object.assign(Object.assign({}, rv), { [key]: {
126
+ [method]: list ? value.map(({ id }) => ({ id })) : { id: value.id },
127
+ } });
128
+ break;
129
+ }
130
+ return rv;
131
+ };
132
+ exports.parseInputDataToDataObject = parseInputDataToDataObject;
133
+ const buildValue = ({ name, value }) => {
134
+ let rv;
135
+ switch (name) {
136
+ case 'Float':
137
+ rv = value || 0.0;
138
+ break;
139
+ case 'Int':
140
+ rv = value || 0;
141
+ break;
142
+ case 'ID':
143
+ rv = value || '000000000000000000000000';
144
+ break;
145
+ case 'String':
146
+ rv = value || '';
147
+ break;
148
+ default:
149
+ rv = name.includes('many') ? { connect: [{ id: value || '' }] } : { connect: { id: value || '' } };
150
+ break;
151
+ }
152
+ return rv;
153
+ };
154
+ const parseArgs = ({ raw, _variables, upper_key, key, action, value }) => {
155
+ raw.args.forEach((arg) => {
156
+ if (upper_key === arg.name) {
157
+ const fields = (0, exports.getFieldsStringified)({ arg });
158
+ const fields_obj = (0, exports.getFields)({ arg });
159
+ if (fields.length > 0) {
160
+ parseFields({
161
+ fields,
162
+ fields_obj,
163
+ _variables,
164
+ upper_key,
165
+ key,
166
+ action,
167
+ value,
168
+ });
169
+ }
170
+ else {
171
+ throw `Schema Object/Action Does Not Have Any Fields`;
172
+ }
173
+ }
174
+ });
175
+ };
176
+ const parseFields = ({ fields, fields_obj, key, _variables, upper_key, value, action }) => {
177
+ let _existsInFields = false;
178
+ fields.forEach((field) => {
179
+ const _key = (0, pluralize_1.default)(key);
180
+ const exists = field.includes(_key.toLowerCase()) || field.includes(key.toLowerCase());
181
+ if (exists === true) {
182
+ _existsInFields = true;
183
+ const kind = (0, exports.getTypeName)(fields_obj[field]);
184
+ if (action === 'mutation') {
185
+ setMutationEntityVariables({
186
+ field,
187
+ kind,
188
+ _variables,
189
+ upper_key,
190
+ value,
191
+ });
192
+ }
193
+ else {
194
+ setQueryEntityVariables({
195
+ field,
196
+ kind,
197
+ _variables,
198
+ upper_key,
199
+ value,
200
+ });
201
+ }
202
+ }
203
+ });
204
+ if (_existsInFields === false)
205
+ throw `Schema Object/Action Does Not Support - '${key}'`;
206
+ };
207
+ const setMutationEntityVariables = ({ field, kind, _variables, upper_key, value }) => {
208
+ Array.isArray(_variables[upper_key])
209
+ ?
210
+ (_variables[upper_key] = _variables[upper_key].map((item, i) => (Object.assign(Object.assign({}, item), { [field.toLowerCase()]: buildValue({ name: kind, value }) }))))
211
+ : (_variables[upper_key] = Object.assign(Object.assign({}, _variables[upper_key]), { [field.toLowerCase()]: buildValue({ name: kind, value }) }));
212
+ };
213
+ const setQueryEntityVariables = ({ field, kind, _variables, upper_key, value }) => {
214
+ field.includes('some')
215
+ ? (_variables[upper_key] = Object.assign(Object.assign({}, _variables[upper_key]), { [field]: { id_in: [value] } }))
216
+ : (_variables[upper_key] = Object.assign(Object.assign({}, _variables[upper_key]), { [field]: value }));
217
+ };