graphql-form 0.0.2 → 0.0.5
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/lib/FormBuilder.d.ts +3 -0
- package/lib/FormBuilder.js +51 -0
- package/lib/FormBuilder.js.map +1 -0
- package/lib/FormDisplayer.d.ts +3 -0
- package/lib/FormDisplayer.js +50 -0
- package/lib/FormDisplayer.js.map +1 -0
- package/lib/FormToCode/gql/index.d.ts +6 -0
- package/lib/FormToCode/gql/index.js +12 -0
- package/lib/FormToCode/gql/index.js.map +1 -0
- package/lib/FormToCode/{gql.d.ts → gql/reducers.d.ts} +2 -9
- package/lib/FormToCode/gql/reducers.js +44 -0
- package/lib/FormToCode/gql/reducers.js.map +1 -0
- package/lib/FormToCode/gql/resolvers.d.ts +4 -0
- package/lib/FormToCode/gql/resolvers.js +54 -0
- package/lib/FormToCode/gql/resolvers.js.map +1 -0
- package/lib/FormToCode/index.d.ts +3 -0
- package/lib/FormToCode/index.js +20 -0
- package/lib/FormToCode/index.js.map +1 -0
- package/lib/FormToCode/models.d.ts +8 -0
- package/lib/FormToCode/models.js +3 -0
- package/lib/FormToCode/models.js.map +1 -0
- package/lib/FormToCode/zeus/index.d.ts +6 -0
- package/lib/FormToCode/zeus/index.js +12 -0
- package/lib/FormToCode/zeus/index.js.map +1 -0
- package/lib/FormToCode/{zeus.d.ts → zeus/resolvers.d.ts} +2 -9
- package/lib/FormToCode/zeus/resolvers.js +54 -0
- package/lib/FormToCode/zeus/resolvers.js.map +1 -0
- package/lib/{renderer/widgets/models.d.ts → createWidget.d.ts} +4 -4
- package/lib/{renderer/widgets/models.js → createWidget.js} +1 -1
- package/lib/createWidget.js.map +1 -0
- package/lib/index.d.ts +5 -6
- package/lib/index.js +5 -53
- package/lib/index.js.map +1 -1
- package/lib/models.d.ts +19 -17
- package/package.json +1 -1
- package/src/FormBuilder.tsx +46 -0
- package/src/FormDisplayer.tsx +40 -0
- package/src/FormToCode/gql/index.ts +9 -0
- package/src/FormToCode/gql/reducers.ts +40 -0
- package/src/FormToCode/gql/resolvers.ts +51 -0
- package/src/FormToCode/index.ts +3 -0
- package/src/FormToCode/models.ts +9 -0
- package/src/FormToCode/zeus/index.ts +9 -0
- package/src/FormToCode/zeus/resolvers.tsx +55 -0
- package/src/{renderer/widgets/models.ts → createWidget.tsx} +0 -1
- package/src/index.tsx +5 -57
- package/src/models.ts +21 -20
- package/lib/FormToCode/gql.js +0 -91
- package/lib/FormToCode/gql.js.map +0 -1
- package/lib/FormToCode/zeus.js +0 -101
- package/lib/FormToCode/zeus.js.map +0 -1
- package/lib/renderer/widgets/models.js.map +0 -1
- package/src/FormToCode/gql.tsx +0 -95
- package/src/FormToCode/zeus.tsx +0 -110
package/src/FormToCode/gql.tsx
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
import { FormObject, FormValue } from '@/models';
|
2
|
-
import { ParserField, TypeDefinition, ScalarTypes, getTypeName } from 'graphql-js-tree';
|
3
|
-
|
4
|
-
export const fieldsToReductor = (toggledFields: Record<string, FormObject>): Reductor =>
|
5
|
-
Object.entries(toggledFields).reduce((a, [key, value]) => {
|
6
|
-
const pathElements = key.split('.');
|
7
|
-
let start = a;
|
8
|
-
pathElements.forEach((el, index) => {
|
9
|
-
if (index === 0 && !!value.node.type.operations?.length) {
|
10
|
-
el = value.node.type.operations[0];
|
11
|
-
}
|
12
|
-
start[el] = start[el] || {};
|
13
|
-
start[el].node = start[el].node || {};
|
14
|
-
if (index === pathElements.length - 1) {
|
15
|
-
if (value.value && Object.keys(value.value).length > 0) {
|
16
|
-
start[el].value = value.value;
|
17
|
-
}
|
18
|
-
}
|
19
|
-
start = start[el].node;
|
20
|
-
});
|
21
|
-
return a;
|
22
|
-
}, {} as Reductor);
|
23
|
-
|
24
|
-
export const reduceQl = (o: Reductor, nodes: ParserField[], tabs = ''): string => {
|
25
|
-
return Object.entries(o)
|
26
|
-
.map(([k, v]) => {
|
27
|
-
const kName =
|
28
|
-
v.value && Object.keys(v.value).length > 0
|
29
|
-
? `${k}(${resolveQlValue(v.value, nodes, tabs)}\n${tabs})`
|
30
|
-
: k;
|
31
|
-
const kObject =
|
32
|
-
Object.keys(v.node).length > 0
|
33
|
-
? `${tabs}${kName}{\n${reduceQl(v.node, nodes, tabs + '\t')}${tabs}}\n`
|
34
|
-
: `${tabs}${kName}\n`;
|
35
|
-
return kObject;
|
36
|
-
})
|
37
|
-
.join('');
|
38
|
-
};
|
39
|
-
|
40
|
-
const resolveSingularValue = (v: FormObject, nodes: ParserField[], tabs = ''): string => {
|
41
|
-
if (v.value === null) {
|
42
|
-
return 'null';
|
43
|
-
}
|
44
|
-
if (Array.isArray(v.value)) {
|
45
|
-
return `[${v.value
|
46
|
-
.map((subVal) => resolveSingularValue({ node: v.node, value: (subVal as FormObject).value }, nodes, tabs))
|
47
|
-
.join(', ')}]`;
|
48
|
-
}
|
49
|
-
const seekNode = nodes.find((n) => n.name === getTypeName(v.node.type.fieldType));
|
50
|
-
if (seekNode?.data.type === TypeDefinition.EnumTypeDefinition) {
|
51
|
-
return v.value as string;
|
52
|
-
}
|
53
|
-
if (seekNode?.data.type === TypeDefinition.ScalarTypeDefinition) {
|
54
|
-
return v.value as string;
|
55
|
-
}
|
56
|
-
if (seekNode) {
|
57
|
-
return `{${resolveQlValue(v.value, nodes, tabs + '\t')}\n${tabs}\t}`;
|
58
|
-
}
|
59
|
-
return getTypeName(v.node.type.fieldType) === ScalarTypes.String ? `"${v.value}"` : `${v.value}`;
|
60
|
-
};
|
61
|
-
|
62
|
-
const resolveQlValue = (v: FormValue | undefined, nodes: ParserField[], tabs = '') => {
|
63
|
-
if (typeof v === 'undefined' || v === null) {
|
64
|
-
return '';
|
65
|
-
}
|
66
|
-
return Object.entries(v).reduce((a, [key, v]: [key: string, value: FormObject]) => {
|
67
|
-
if (typeof v.value === 'undefined' || v.value === '') {
|
68
|
-
return a;
|
69
|
-
}
|
70
|
-
if (Array.isArray(v.value) && v.value.length === 0) {
|
71
|
-
return a;
|
72
|
-
}
|
73
|
-
if (
|
74
|
-
typeof v.value === 'object' &&
|
75
|
-
v.value !== null &&
|
76
|
-
!Object.values(v.value).some(
|
77
|
-
(val) =>
|
78
|
-
typeof val === 'object' && val !== null && 'value' in val && (!!val.value || val.value === false),
|
79
|
-
)
|
80
|
-
) {
|
81
|
-
return a;
|
82
|
-
}
|
83
|
-
const resolvedValue = resolveSingularValue(v, nodes, tabs);
|
84
|
-
a = `${a}\n\t${tabs}${key}: ${resolvedValue}`;
|
85
|
-
return a;
|
86
|
-
}, '');
|
87
|
-
};
|
88
|
-
|
89
|
-
type ReductorValue = {
|
90
|
-
node: Reductor;
|
91
|
-
value?: FormValue;
|
92
|
-
};
|
93
|
-
type Reductor = {
|
94
|
-
[key: string]: ReductorValue;
|
95
|
-
};
|
package/src/FormToCode/zeus.tsx
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
import { FormObject, FormValue } from '@/models';
|
2
|
-
import { ParserField, TypeDefinition, ScalarTypes, getTypeName } from 'graphql-js-tree';
|
3
|
-
|
4
|
-
export const zeusFieldsToReductor = (toggledFields: Record<string, FormObject>): Reductor => {
|
5
|
-
const r = Object.entries(toggledFields).reduce((a, [key, value]) => {
|
6
|
-
const pathElements = key.split('.');
|
7
|
-
let start = a;
|
8
|
-
pathElements.forEach((el, index) => {
|
9
|
-
if (index === 0 && !!value.node.type.operations?.length) {
|
10
|
-
el = value.node.type.operations[0];
|
11
|
-
return;
|
12
|
-
}
|
13
|
-
start[el] = start[el] || {};
|
14
|
-
start[el].node = start[el].node || {};
|
15
|
-
if (index === pathElements.length - 1) {
|
16
|
-
if (value.value && Object.keys(value.value).length > 0) {
|
17
|
-
start[el].value = value.value;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
start = start[el].node;
|
21
|
-
});
|
22
|
-
return a;
|
23
|
-
}, {} as Reductor);
|
24
|
-
return r;
|
25
|
-
};
|
26
|
-
|
27
|
-
export const zeusReduceQl = (o: Reductor, nodes: ParserField[], tabs = '', level = 0): string => {
|
28
|
-
const lUP = level + 1;
|
29
|
-
return Object.entries(o)
|
30
|
-
.map(([k, v]) => {
|
31
|
-
if (v.value && Object.keys(v.value).length > 0) {
|
32
|
-
return Object.keys(v.node).length > 0
|
33
|
-
? `${tabs}${k}:[{${resolveQlValue(v.value, nodes, tabs)}\n${tabs}}, {\n${zeusReduceQl(
|
34
|
-
v.node,
|
35
|
-
nodes,
|
36
|
-
tabs + '\t',
|
37
|
-
lUP,
|
38
|
-
)}${tabs}}]\n`
|
39
|
-
: `${tabs}${k}:[{${resolveQlValue(v.value, nodes, tabs)}\n${tabs}}, true]`;
|
40
|
-
}
|
41
|
-
if (level === 0) {
|
42
|
-
return `const result = await api("${
|
43
|
-
nodes.find((n) => n.name === k)?.type.operations?.[0]
|
44
|
-
}")({\n${zeusReduceQl(v.node, nodes, tabs + '\t', lUP)}})`;
|
45
|
-
}
|
46
|
-
const kObject =
|
47
|
-
Object.keys(v.node).length > 0
|
48
|
-
? `${tabs}${k}:{\n${zeusReduceQl(v.node, nodes, tabs + '\t', lUP)}${tabs}}\n`
|
49
|
-
: `${tabs}${k}: true\n`;
|
50
|
-
return kObject;
|
51
|
-
})
|
52
|
-
.join('');
|
53
|
-
};
|
54
|
-
|
55
|
-
const resolveSingularValue = (v: FormObject, nodes: ParserField[], tabs = ''): string => {
|
56
|
-
if (v.value === null) {
|
57
|
-
return 'null';
|
58
|
-
}
|
59
|
-
if (Array.isArray(v.value)) {
|
60
|
-
return `[${v.value
|
61
|
-
.map((subVal) => resolveSingularValue({ node: v.node, value: (subVal as FormObject).value }, nodes, tabs))
|
62
|
-
.join(', ')}]`;
|
63
|
-
}
|
64
|
-
const seekNode = nodes.find((n) => n.name === getTypeName(v.node.type.fieldType));
|
65
|
-
if (seekNode?.data.type === TypeDefinition.EnumTypeDefinition) {
|
66
|
-
return v.value as string;
|
67
|
-
}
|
68
|
-
if (seekNode?.data.type === TypeDefinition.ScalarTypeDefinition) {
|
69
|
-
return v.value as string;
|
70
|
-
}
|
71
|
-
if (seekNode) {
|
72
|
-
return `{${resolveQlValue(v.value, nodes, tabs + '\t')}\n${tabs}\t}`;
|
73
|
-
}
|
74
|
-
return getTypeName(v.node.type.fieldType) === ScalarTypes.String ? `"${v.value}"` : `${v.value}`;
|
75
|
-
};
|
76
|
-
|
77
|
-
const resolveQlValue = (v: FormValue | undefined, nodes: ParserField[], tabs = '') => {
|
78
|
-
if (typeof v === 'undefined' || v === null) {
|
79
|
-
return '';
|
80
|
-
}
|
81
|
-
return Object.entries(v).reduce((a, [key, v]: [key: string, value: FormObject]) => {
|
82
|
-
if (typeof v.value === 'undefined' || v.value === '') {
|
83
|
-
return a;
|
84
|
-
}
|
85
|
-
if (Array.isArray(v.value) && v.value.length === 0) {
|
86
|
-
return a;
|
87
|
-
}
|
88
|
-
if (
|
89
|
-
typeof v.value === 'object' &&
|
90
|
-
v.value !== null &&
|
91
|
-
!Object.values(v.value).some(
|
92
|
-
(val) =>
|
93
|
-
typeof val === 'object' && val !== null && 'value' in val && (!!val.value || val.value === false),
|
94
|
-
)
|
95
|
-
) {
|
96
|
-
return a;
|
97
|
-
}
|
98
|
-
const resolvedValue = resolveSingularValue(v, nodes, tabs);
|
99
|
-
a = `${a}\n\t${tabs}${key}: ${resolvedValue}`;
|
100
|
-
return a;
|
101
|
-
}, '');
|
102
|
-
};
|
103
|
-
|
104
|
-
type ReductorValue = {
|
105
|
-
node: Reductor;
|
106
|
-
value?: FormValue;
|
107
|
-
};
|
108
|
-
type Reductor = {
|
109
|
-
[key: string]: ReductorValue;
|
110
|
-
};
|