@fixefy/fixefy-ui-utils 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.js +39 -17
- package/dist-cjs/index.js.map +1 -0
- package/{dist-types → dist-cjs/types}/index.d.ts +0 -3
- package/{dist-types → dist-cjs/types}/types/index.d.ts +5 -5
- package/dist-es/index.js +39 -14
- package/dist-es/index.js.map +1 -0
- package/dist-es/types/auth/index.d.ts +2 -0
- package/dist-es/types/aws/data_models.d.ts +21 -0
- package/dist-es/types/commander/index.d.ts +33 -0
- package/dist-es/types/constants/index.d.ts +6 -0
- package/dist-es/types/files/index.d.ts +2 -0
- package/dist-es/types/graphql/index.d.ts +38 -0
- package/dist-es/types/headers/index.d.ts +12 -0
- package/dist-es/types/images/index.d.ts +4 -0
- package/dist-es/types/index.d.ts +11 -0
- package/dist-es/types/json/index.d.ts +7 -0
- package/dist-es/types/page_context/index.d.ts +248 -0
- package/dist-es/types/redirect/index.d.ts +2 -0
- package/dist-es/types/resolvers/index.d.ts +11 -0
- package/dist-es/types/transform/index.d.ts +2 -0
- package/dist-es/types/types/index.d.ts +39 -0
- package/dist-es/types/validate/index.d.ts +5 -0
- package/package.json +71 -64
- package/dist-cjs/auth/index.jsx +0 -13
- package/dist-cjs/aws/aws_lambda_helper.js +0 -49
- package/dist-cjs/aws/aws_s3_helper.js +0 -1
- package/dist-cjs/aws/data_models.js +0 -2
- package/dist-cjs/aws/index.js +0 -4
- package/dist-cjs/commander/index.jsx +0 -280
- package/dist-cjs/constants/index.jsx +0 -87
- package/dist-cjs/contents/index.jsx +0 -32
- package/dist-cjs/files/index.jsx +0 -27
- package/dist-cjs/graphql/index.jsx +0 -217
- package/dist-cjs/headers/index.jsx +0 -68
- package/dist-cjs/images/index.jsx +0 -13
- package/dist-cjs/json/index.js +0 -135
- package/dist-cjs/package.json +0 -3
- package/dist-cjs/page_context/index.jsx +0 -494
- package/dist-cjs/redirect/index.jsx +0 -15
- package/dist-cjs/renderer/index.jsx +0 -66
- package/dist-cjs/resolvers/index.jsx +0 -35
- package/dist-cjs/transform/index.jsx +0 -40
- package/dist-cjs/types/index.js +0 -2
- package/dist-cjs/validate/index.jsx +0 -48
- package/dist-es/auth/index.jsx +0 -11
- package/dist-es/aws/aws_lambda_helper.js +0 -41
- package/dist-es/aws/aws_s3_helper.js +0 -1
- package/dist-es/aws/data_models.js +0 -1
- package/dist-es/aws/index.js +0 -1
- package/dist-es/commander/index.jsx +0 -250
- package/dist-es/constants/index.jsx +0 -84
- package/dist-es/contents/index.jsx +0 -31
- package/dist-es/files/index.jsx +0 -22
- package/dist-es/graphql/index.jsx +0 -235
- package/dist-es/headers/index.jsx +0 -57
- package/dist-es/images/index.jsx +0 -9
- package/dist-es/json/index.js +0 -125
- package/dist-es/package.json +0 -3
- package/dist-es/page_context/index.jsx +0 -511
- package/dist-es/redirect/index.jsx +0 -12
- package/dist-es/renderer/index.jsx +0 -60
- package/dist-es/resolvers/index.jsx +0 -31
- package/dist-es/transform/index.jsx +0 -35
- package/dist-es/types/index.js +0 -1
- package/dist-es/validate/index.jsx +0 -40
- package/dist-types/aws/aws_lambda_helper.d.ts +0 -5
- package/dist-types/aws/aws_s3_helper.d.ts +0 -0
- package/dist-types/aws/index.d.ts +0 -1
- package/dist-types/contents/index.d.ts +0 -3
- package/dist-types/renderer/index.d.ts +0 -9
- /package/{dist-types → dist-cjs/types}/auth/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/aws/data_models.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/commander/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/constants/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/files/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/graphql/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/headers/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/images/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/json/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/page_context/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/redirect/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/resolvers/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/transform/index.d.ts +0 -0
- /package/{dist-types → dist-cjs/types}/validate/index.d.ts +0 -0
|
@@ -1,217 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCurrency = exports.setCurrency = exports.flushAll = exports.flushWorkspace = exports.setWorkspace = exports.getWorkspace = exports.flushLastActivity = exports.setLastActivity = exports.getLastActivity = exports.setHeaders = exports.getHeaders = exports.defaultHeaders = void 0;
|
|
4
|
-
const nookies_1 = require("nookies");
|
|
5
|
-
exports.defaultHeaders = {
|
|
6
|
-
'bundle-name': '',
|
|
7
|
-
cur: {
|
|
8
|
-
_id: '5e8c8dfdfca1360007d7b654',
|
|
9
|
-
value: '5e8c8dfdfca1360007d7b654',
|
|
10
|
-
code: 'usd',
|
|
11
|
-
namePlural: 'us dollars',
|
|
12
|
-
symbol: '$',
|
|
13
|
-
},
|
|
14
|
-
hl: 'en',
|
|
15
|
-
'is-explain': true,
|
|
16
|
-
'last-activity': 0,
|
|
17
|
-
};
|
|
18
|
-
const getHeaders = (ctx, options = {}) => {
|
|
19
|
-
let _headers = (0, nookies_1.parseCookies)(ctx)['fixefy:headers'];
|
|
20
|
-
_headers = _headers && typeof _headers === 'string' ? JSON.parse(_headers) : typeof _headers === 'object' ? _headers : {};
|
|
21
|
-
const headers = Object.assign(Object.assign({}, exports.defaultHeaders), { ws: (0, exports.getWorkspace)(ctx), cur: (0, exports.getCurrency)(ctx)._id, 'last-activity': (0, exports.getLastActivity)(ctx) });
|
|
22
|
-
return headers;
|
|
23
|
-
};
|
|
24
|
-
exports.getHeaders = getHeaders;
|
|
25
|
-
const setHeaders = (ctx, _headers) => {
|
|
26
|
-
typeof _headers === 'string' ? (0, nookies_1.setCookie)(ctx, 'fixefy:headers', Object.assign({}, JSON.parse(_headers)), { maxAge: 7 * 24 * 60 * 60, path: '/' }) : (0, nookies_1.setCookie)(ctx, 'fixefy:headers', Object.assign({}, _headers), { maxAge: 7 * 24 * 60 * 60, path: '/' });
|
|
27
|
-
};
|
|
28
|
-
exports.setHeaders = setHeaders;
|
|
29
|
-
const getLastActivity = (ctx) => { };
|
|
30
|
-
exports.getLastActivity = getLastActivity;
|
|
31
|
-
const setLastActivity = (ctx) => { };
|
|
32
|
-
exports.setLastActivity = setLastActivity;
|
|
33
|
-
const flushLastActivity = (ctx) => { };
|
|
34
|
-
exports.flushLastActivity = flushLastActivity;
|
|
35
|
-
const getWorkspace = (ctx) => {
|
|
36
|
-
var _a;
|
|
37
|
-
const rv = (_a = (0, nookies_1.parseCookies)(ctx)['ws']) !== null && _a !== void 0 ? _a : exports.defaultHeaders['ws'];
|
|
38
|
-
return rv;
|
|
39
|
-
};
|
|
40
|
-
exports.getWorkspace = getWorkspace;
|
|
41
|
-
const setWorkspace = (ctx, ws) => {
|
|
42
|
-
(0, nookies_1.setCookie)(ctx, 'ws', ws, { maxAge: 7 * 24 * 60 * 60, path: '/' });
|
|
43
|
-
};
|
|
44
|
-
exports.setWorkspace = setWorkspace;
|
|
45
|
-
const flushWorkspace = (ctx) => {
|
|
46
|
-
(0, nookies_1.destroyCookie)(ctx, 'ws', { path: '/' });
|
|
47
|
-
};
|
|
48
|
-
exports.flushWorkspace = flushWorkspace;
|
|
49
|
-
const flushAll = (ctx) => {
|
|
50
|
-
(0, exports.flushLastActivity)(ctx);
|
|
51
|
-
(0, exports.flushWorkspace)(ctx);
|
|
52
|
-
};
|
|
53
|
-
exports.flushAll = flushAll;
|
|
54
|
-
const setCurrency = (ctx, currency) => {
|
|
55
|
-
(0, nookies_1.setCookie)(ctx, 'cur', JSON.stringify(currency), { maxAge: 7 * 24 * 60 * 60, path: '/' });
|
|
56
|
-
};
|
|
57
|
-
exports.setCurrency = setCurrency;
|
|
58
|
-
const getCurrency = (ctx) => {
|
|
59
|
-
var _a;
|
|
60
|
-
const cur = (_a = (0, nookies_1.parseCookies)(ctx)['cur']) !== null && _a !== void 0 ? _a : exports.defaultHeaders['cur'];
|
|
61
|
-
if (cur) {
|
|
62
|
-
if (cur === 'usd' || cur === 'eur') {
|
|
63
|
-
(0, exports.setCurrency)(ctx, exports.defaultHeaders['cur']);
|
|
64
|
-
}
|
|
65
|
-
return typeof cur === 'string' ? JSON.parse(cur) : cur;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
exports.getCurrency = getCurrency;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.imageLoader = void 0;
|
|
4
|
-
const imageLoader = ({ src, root }) => {
|
|
5
|
-
const transformedSrc = src.split('/');
|
|
6
|
-
transformedSrc.splice(transformedSrc.length - 1, 1, transformedSrc[transformedSrc.length - 1]
|
|
7
|
-
.split(/(?=[A-Z])/)
|
|
8
|
-
.join('_')
|
|
9
|
-
.toLowerCase());
|
|
10
|
-
const url = transformedSrc.join('/');
|
|
11
|
-
return `${root}${url}`;
|
|
12
|
-
};
|
|
13
|
-
exports.imageLoader = imageLoader;
|
package/dist-cjs/json/index.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setJToken = exports.isResultValid = exports.isNested = exports.isJson = exports.isHasKey = exports.getJPart = exports.getJToken = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
const getJToken = (jToken, jsonPath, defaultValue) => {
|
|
6
|
-
if ((0, __1.isObjectValid)(jToken) === false)
|
|
7
|
-
return defaultValue;
|
|
8
|
-
jsonPath = jsonPath.replace(/\[(\w+)\]/g, '.$1');
|
|
9
|
-
jsonPath = jsonPath.replace(/^\./, '');
|
|
10
|
-
let isContinueLoop = true, currentToken, jsonPathParts = jsonPath.split('.');
|
|
11
|
-
try {
|
|
12
|
-
for (let i = 0, n = jsonPathParts.length; isContinueLoop && i < n; ++i) {
|
|
13
|
-
currentToken = jsonPathParts[i];
|
|
14
|
-
if (typeof jToken === 'string') {
|
|
15
|
-
jToken = JSON.parse(jToken);
|
|
16
|
-
}
|
|
17
|
-
if (currentToken in jToken) {
|
|
18
|
-
jToken = jToken[currentToken];
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
jToken = defaultValue;
|
|
22
|
-
isContinueLoop = false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
jToken = 'No Value Found';
|
|
28
|
-
}
|
|
29
|
-
return jToken;
|
|
30
|
-
};
|
|
31
|
-
exports.getJToken = getJToken;
|
|
32
|
-
const getJPart = (j, jsonPath, defaultValue) => {
|
|
33
|
-
if (j == null)
|
|
34
|
-
return defaultValue;
|
|
35
|
-
jsonPath = jsonPath.replace(/\[(\w+)\]/g, '.$1');
|
|
36
|
-
jsonPath = jsonPath.replace(/^\./, '');
|
|
37
|
-
let _isArrayValid = false, _isStringValid = false, currentPathPart, pathParts = jsonPath.split('.'), isLoop = true;
|
|
38
|
-
for (let i = 0, n = pathParts.length; isLoop && i < n; ++i) {
|
|
39
|
-
currentPathPart = pathParts[i];
|
|
40
|
-
_isStringValid = (0, __1.isStringValid)(j);
|
|
41
|
-
_isArrayValid = (0, __1.isArrayValid)(j);
|
|
42
|
-
if (_isStringValid === true || _isArrayValid === true) {
|
|
43
|
-
if (_isStringValid === true) {
|
|
44
|
-
j = JSON.parse(j);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
j = j.reduce((acc, cur, idx, src) => {
|
|
48
|
-
const innerJ = (0, exports.getJPart)(cur, pathParts.slice(i).join('.'), defaultValue);
|
|
49
|
-
if ((0, __1.isArrayValid)(innerJ)) {
|
|
50
|
-
acc.push(...innerJ);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
acc.push(innerJ);
|
|
54
|
-
}
|
|
55
|
-
return acc;
|
|
56
|
-
}, []);
|
|
57
|
-
isLoop = false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
if (j[currentPathPart] != null && currentPathPart in j) {
|
|
62
|
-
j = j[currentPathPart];
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
j = defaultValue;
|
|
66
|
-
isLoop = false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return j;
|
|
71
|
-
};
|
|
72
|
-
exports.getJPart = getJPart;
|
|
73
|
-
const isHasKey = (array, key) => {
|
|
74
|
-
let rv = false, isContinueLoop = true, current_keys;
|
|
75
|
-
for (let i = 0; i < array.length && isContinueLoop; ++i) {
|
|
76
|
-
current_keys = Object.keys(array[i]);
|
|
77
|
-
if ((current_keys || []).indexOf(key) > -1) {
|
|
78
|
-
rv = true;
|
|
79
|
-
isContinueLoop = false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return rv;
|
|
83
|
-
};
|
|
84
|
-
exports.isHasKey = isHasKey;
|
|
85
|
-
const isJson = (obj) => {
|
|
86
|
-
let objAsString;
|
|
87
|
-
try {
|
|
88
|
-
objAsString = JSON.stringify(obj);
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
objAsString = null;
|
|
92
|
-
}
|
|
93
|
-
if (!objAsString || (0, __1.isStringValid)(objAsString) === false)
|
|
94
|
-
return false;
|
|
95
|
-
const rv = (objAsString === null || objAsString === void 0 ? void 0 : objAsString.indexOf('{')) === 0 && (objAsString === null || objAsString === void 0 ? void 0 : objAsString.indexOf('}')) === (objAsString === null || objAsString === void 0 ? void 0 : objAsString.length) - 1;
|
|
96
|
-
return rv;
|
|
97
|
-
};
|
|
98
|
-
exports.isJson = isJson;
|
|
99
|
-
const isNested = (obj) => {
|
|
100
|
-
const rv = Object.keys(obj).some((key) => {
|
|
101
|
-
return obj[key] && typeof obj[key] === 'object';
|
|
102
|
-
});
|
|
103
|
-
return rv;
|
|
104
|
-
};
|
|
105
|
-
exports.isNested = isNested;
|
|
106
|
-
const isResultValid = (jResult) => {
|
|
107
|
-
if ((0, __1.isObjectValid)(jResult) === false)
|
|
108
|
-
return false;
|
|
109
|
-
const rv = (0, exports.getJPart)(jResult, 'ok', 0);
|
|
110
|
-
return !!rv;
|
|
111
|
-
};
|
|
112
|
-
exports.isResultValid = isResultValid;
|
|
113
|
-
const setJToken = (jEntity, fieldPathsAndValues) => {
|
|
114
|
-
let jCurrentToken, currentPath, pathParts, fieldName;
|
|
115
|
-
for (let i = 0; i < fieldPathsAndValues.length; ++i) {
|
|
116
|
-
currentPath = fieldPathsAndValues[i]['json_path'];
|
|
117
|
-
if ((0, __1.isStringValid)(currentPath)) {
|
|
118
|
-
fieldName = currentPath;
|
|
119
|
-
pathParts = currentPath.split('.');
|
|
120
|
-
if ((0, __1.isArrayValid)(pathParts)) {
|
|
121
|
-
fieldName = pathParts[pathParts.length - 1];
|
|
122
|
-
pathParts = pathParts.splice(0, Math.max(0, pathParts.length - 1));
|
|
123
|
-
if ((0, __1.isArrayValid)(pathParts)) {
|
|
124
|
-
currentPath = pathParts.join('.');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
jCurrentToken = (0, exports.getJPart)(jEntity, currentPath, null);
|
|
128
|
-
if ((0, __1.isObjectValid)(jCurrentToken) || (0, exports.isJson)(jCurrentToken) === false) {
|
|
129
|
-
jCurrentToken = jEntity;
|
|
130
|
-
}
|
|
131
|
-
jCurrentToken[fieldName] = fieldPathsAndValues[i]['value'];
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
exports.setJToken = setJToken;
|
package/dist-cjs/package.json
DELETED