@fixefy/fixefy-ui-utils 0.0.6 → 0.0.8

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