swoop-common 1.0.13 → 1.0.15
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/README.md +1 -1
- package/package.json +1 -1
- package/dist/api/consts.d.ts +0 -1
- package/dist/api/consts.js +0 -2
- package/dist/components/SchemaValidator.d.ts +0 -3
- package/dist/components/SchemaValidator.js +0 -6
- package/dist/components/StyledFormView.d.ts +0 -34
- package/dist/components/StyledFormView.js +0 -12
- package/dist/default_registration/fields_base.d.ts +0 -1
- package/dist/default_registration/fields_base.js +0 -129
- package/dist/hooks/errors.d.ts +0 -6
- package/dist/hooks/errors.js +0 -17
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -9
- package/dist/prebuild/generated/import_generated.d.ts +0 -15
- package/dist/prebuild/generated/import_generated.js +0 -18
- package/dist/prebuild/import.d.ts +0 -1
- package/dist/prebuild/import.js +0 -32
- package/dist/registry/components.d.ts +0 -13
- package/dist/registry/components.js +0 -49
- package/dist/registry/fields.d.ts +0 -10
- package/dist/registry/fields.js +0 -19
- package/dist/registry/types.d.ts +0 -5
- package/dist/registry/types.js +0 -5
- package/dist/renderers/Address.d.ts +0 -1
- package/dist/renderers/Address.js +0 -67
- package/dist/renderers/ComponentPicker.d.ts +0 -19
- package/dist/renderers/ComponentPicker.js +0 -68
- package/dist/renderers/Debug.d.ts +0 -1
- package/dist/renderers/Debug.js +0 -13
- package/dist/renderers/Example.d.ts +0 -1
- package/dist/renderers/Example.js +0 -31
- package/dist/renderers/Image/ImageForm.d.ts +0 -10
- package/dist/renderers/Image/ImageForm.js +0 -78
- package/dist/renderers/Image/ImagePresentation.d.ts +0 -6
- package/dist/renderers/Image/ImagePresentation.js +0 -62
- package/dist/renderers/StagedText.d.ts +0 -1
- package/dist/renderers/StagedText.js +0 -20
- package/dist/renderers/TemplatePicker.d.ts +0 -1
- package/dist/renderers/TemplatePicker.js +0 -55
- package/dist/renderers/address/AddressForm.d.ts +0 -1
- package/dist/renderers/address/AddressForm.js +0 -46
- package/dist/renderers/address/AddressPresentation.d.ts +0 -1
- package/dist/renderers/address/AddressPresentation.js +0 -34
- package/dist/renderers/textfield/MultilineForm.d.ts +0 -1
- package/dist/renderers/textfield/MultilineForm.js +0 -21
- package/dist/renderers/textfield/MultilinePresentation.d.ts +0 -1
- package/dist/renderers/textfield/MultilinePresentation.js +0 -13
- package/dist/schema/formBuilders/formBuilderJsonSchema.d.ts +0 -11
- package/dist/schema/formBuilders/formBuilderJsonSchema.js +0 -178
- package/dist/schema/formBuilders/formBuilderUiSchema.d.ts +0 -2
- package/dist/schema/formBuilders/formBuilderUiSchema.js +0 -208
- package/dist/schema/formSchemaTypes.d.ts +0 -15
- package/dist/schema/formSchemaTypes.js +0 -6
- package/dist/schema/generate/formSchemaGenerate.d.ts +0 -3
- package/dist/schema/generate/formSchemaGenerate.js +0 -19
- package/dist/schema/generate/jsonSchemaGenerate.d.ts +0 -3
- package/dist/schema/generate/jsonSchemaGenerate.js +0 -150
- package/dist/schema/generate/jsonSchemaGeneratewip.d.ts +0 -4
- package/dist/schema/generate/jsonSchemaGeneratewip.js +0 -59
- package/dist/schema/generate/uiSchemaGenerate.d.ts +0 -3
- package/dist/schema/generate/uiSchemaGenerate.js +0 -33
- package/dist/schema/schema.d.ts +0 -48
- package/dist/schema/schema.js +0 -1
- package/dist/schema/template/constraint.d.ts +0 -17
- package/dist/schema/template/constraint.js +0 -119
- package/dist/schema/template/type.d.ts +0 -94
- package/dist/schema/template/type.js +0 -1
- package/dist/schema/util.d.ts +0 -1
- package/dist/schema/util.js +0 -22
- package/dist/test.d.ts +0 -6
- package/dist/test.js +0 -5
- package/dist/types/address.d.ts +0 -10
- package/dist/types/address.js +0 -1
- package/dist/types/jsonSchema.d.ts +0 -4
- package/dist/types/jsonSchema.js +0 -1
- package/dist/types/util.d.ts +0 -1
- package/dist/types/util.js +0 -1
- package/dist/util/xtype.d.ts +0 -3
- package/dist/util/xtype.js +0 -18
- package/dist/validation/schemaValidator.d.ts +0 -4
- package/dist/validation/schemaValidator.js +0 -6
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { getAllTypes } from "../../registry/fields";
|
|
2
|
-
const fields = getAllTypes();
|
|
3
|
-
// Object and array are semi hard coded, due to their recursive nature
|
|
4
|
-
const generateFieldControlElements = (exclude = []) => {
|
|
5
|
-
return fields.reduce((prev, curr) => {
|
|
6
|
-
if (!curr.options || Object.keys(curr.options).length === 0 || exclude.includes(curr.name)) {
|
|
7
|
-
return prev;
|
|
8
|
-
}
|
|
9
|
-
prev.push({
|
|
10
|
-
type: "Control",
|
|
11
|
-
scope: `#/properties/${curr.name}Options`,
|
|
12
|
-
rule: {
|
|
13
|
-
effect: "SHOW",
|
|
14
|
-
condition: {
|
|
15
|
-
scope: "#/properties/fieldType",
|
|
16
|
-
schema: { const: curr.name }
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return prev;
|
|
21
|
-
}, []);
|
|
22
|
-
};
|
|
23
|
-
const fieldDetailLayout = {
|
|
24
|
-
type: "VerticalLayout",
|
|
25
|
-
elements: [
|
|
26
|
-
{
|
|
27
|
-
type: "Control",
|
|
28
|
-
scope: "#/properties/name",
|
|
29
|
-
label: "Field Name",
|
|
30
|
-
},
|
|
31
|
-
{ type: "Control", scope: "#/properties/fieldType" },
|
|
32
|
-
{ type: "Control", scope: "#/properties/description" },
|
|
33
|
-
{ type: "Control", scope: "#/properties/required" },
|
|
34
|
-
...generateFieldControlElements(["object", "array"]),
|
|
35
|
-
{
|
|
36
|
-
type: "Control",
|
|
37
|
-
scope: "#/properties/objectOptions/properties/properties",
|
|
38
|
-
rule: {
|
|
39
|
-
effect: "SHOW",
|
|
40
|
-
condition: {
|
|
41
|
-
scope: "#/properties/fieldType",
|
|
42
|
-
schema: { const: "object" },
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
options: { detail: null },
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
type: "Control",
|
|
49
|
-
scope: "#/properties/arrayOptions/properties/minItems",
|
|
50
|
-
rule: {
|
|
51
|
-
effect: "SHOW",
|
|
52
|
-
condition: {
|
|
53
|
-
scope: "#/properties/fieldType",
|
|
54
|
-
schema: { const: "array" },
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
type: "Control",
|
|
60
|
-
scope: "#/properties/arrayOptions/properties/maxItems",
|
|
61
|
-
rule: {
|
|
62
|
-
effect: "SHOW",
|
|
63
|
-
condition: {
|
|
64
|
-
scope: "#/properties/fieldType",
|
|
65
|
-
schema: { const: "array" },
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
type: "Control",
|
|
71
|
-
scope: "#/properties/arrayOptions/properties/uniqueItems",
|
|
72
|
-
rule: {
|
|
73
|
-
effect: "SHOW",
|
|
74
|
-
condition: {
|
|
75
|
-
scope: "#/properties/fieldType",
|
|
76
|
-
schema: { const: "array" },
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
type: "Control",
|
|
82
|
-
scope: "#/properties/arrayOptions/properties/itemDefinition",
|
|
83
|
-
rule: {
|
|
84
|
-
effect: "SHOW",
|
|
85
|
-
condition: {
|
|
86
|
-
scope: "#/properties/fieldType",
|
|
87
|
-
schema: { const: "array" },
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
options: { detail: null },
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
};
|
|
94
|
-
const arrayItemDetailLayout = {
|
|
95
|
-
type: "VerticalLayout",
|
|
96
|
-
elements: [
|
|
97
|
-
{ type: "Control", scope: "#/properties/fieldType" },
|
|
98
|
-
...generateFieldControlElements(["object", "array"]),
|
|
99
|
-
{
|
|
100
|
-
type: "Control",
|
|
101
|
-
scope: "#/properties/objectOptions/properties/properties",
|
|
102
|
-
rule: {
|
|
103
|
-
effect: "SHOW",
|
|
104
|
-
condition: {
|
|
105
|
-
scope: "#/properties/fieldType",
|
|
106
|
-
schema: { const: "object" },
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
options: { detail: null },
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
type: "Control",
|
|
113
|
-
scope: "#/properties/arrayOptions/properties/minItems",
|
|
114
|
-
rule: {
|
|
115
|
-
effect: "SHOW",
|
|
116
|
-
condition: {
|
|
117
|
-
scope: "#/properties/fieldType",
|
|
118
|
-
schema: { const: "array" },
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
type: "Control",
|
|
124
|
-
scope: "#/properties/arrayOptions/properties/maxItems",
|
|
125
|
-
rule: {
|
|
126
|
-
effect: "SHOW",
|
|
127
|
-
condition: {
|
|
128
|
-
scope: "#/properties/fieldType",
|
|
129
|
-
schema: { const: "array" },
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
type: "Control",
|
|
135
|
-
scope: "#/properties/arrayOptions/properties/uniqueItems",
|
|
136
|
-
rule: {
|
|
137
|
-
effect: "SHOW",
|
|
138
|
-
condition: {
|
|
139
|
-
scope: "#/properties/fieldType",
|
|
140
|
-
schema: { const: "array" },
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
type: "Control",
|
|
146
|
-
scope: "#/properties/arrayOptions/properties/itemDefinition",
|
|
147
|
-
rule: {
|
|
148
|
-
effect: "SHOW",
|
|
149
|
-
condition: {
|
|
150
|
-
scope: "#/properties/fieldType",
|
|
151
|
-
schema: { const: "array" },
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
options: { detail: null }
|
|
155
|
-
},
|
|
156
|
-
],
|
|
157
|
-
};
|
|
158
|
-
const setupLayoutReferences = () => {
|
|
159
|
-
const objectField = fieldDetailLayout.elements.find((e) => e.scope === "#/properties/objectOptions/properties/properties");
|
|
160
|
-
if (objectField === null || objectField === void 0 ? void 0 : objectField.options) {
|
|
161
|
-
objectField.options.detail = fieldDetailLayout;
|
|
162
|
-
}
|
|
163
|
-
const arrayField = fieldDetailLayout.elements.find((e) => e.scope === "#/properties/arrayOptions/properties/itemDefinition");
|
|
164
|
-
if (arrayField === null || arrayField === void 0 ? void 0 : arrayField.options) {
|
|
165
|
-
arrayField.options.detail = arrayItemDetailLayout;
|
|
166
|
-
}
|
|
167
|
-
const arrayObjectField = arrayItemDetailLayout.elements.find((e) => e.scope === "#/properties/objectOptions/properties/properties");
|
|
168
|
-
if (arrayObjectField === null || arrayObjectField === void 0 ? void 0 : arrayObjectField.options) {
|
|
169
|
-
arrayObjectField.options.detail = fieldDetailLayout;
|
|
170
|
-
}
|
|
171
|
-
const nestedArrayField = arrayItemDetailLayout.elements.find((e) => e.scope === "#/properties/arrayOptions/properties/itemDefinition");
|
|
172
|
-
if (nestedArrayField === null || nestedArrayField === void 0 ? void 0 : nestedArrayField.options) {
|
|
173
|
-
nestedArrayField.options.detail = arrayItemDetailLayout;
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
setupLayoutReferences();
|
|
177
|
-
export const FORM_BUILDER_UI_SCHEMA = {
|
|
178
|
-
type: "VerticalLayout",
|
|
179
|
-
elements: [
|
|
180
|
-
{
|
|
181
|
-
type: "Control",
|
|
182
|
-
scope: "#/properties/name",
|
|
183
|
-
label: "Template Name",
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
type: "Group",
|
|
187
|
-
label: "Component-Driven Fields",
|
|
188
|
-
elements: [
|
|
189
|
-
{
|
|
190
|
-
type: "Control",
|
|
191
|
-
scope: "#/properties/formFields",
|
|
192
|
-
options: { detail: fieldDetailLayout },
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
type: "Group",
|
|
198
|
-
label: "IB-Driven Fields",
|
|
199
|
-
elements: [
|
|
200
|
-
{
|
|
201
|
-
type: "Control",
|
|
202
|
-
scope: "#/properties/ibFormFields",
|
|
203
|
-
options: { detail: fieldDetailLayout },
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
},
|
|
207
|
-
],
|
|
208
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type FormSchema = Array<FieldDefinition>;
|
|
2
|
-
export declare enum Stage {
|
|
3
|
-
Comp = 0,
|
|
4
|
-
Inst = 1,
|
|
5
|
-
User = 2
|
|
6
|
-
}
|
|
7
|
-
export interface FieldDefinition {
|
|
8
|
-
fieldType: string;
|
|
9
|
-
name: string;
|
|
10
|
-
description?: string;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
[key: `${string}Options`]: Record<string, any> | undefined;
|
|
13
|
-
editableIn: Array<Stage>;
|
|
14
|
-
existsFrom: Stage;
|
|
15
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import Ajv from "ajv";
|
|
2
|
-
import { FORM_BUILDER_JSON_SCHEMA } from "../formBuilders/formBuilderJsonSchema";
|
|
3
|
-
// This accepts any as it is designed to consume directly from a json form
|
|
4
|
-
export const generateFormSchema = (data) => {
|
|
5
|
-
// Wrapped with tc for now
|
|
6
|
-
try {
|
|
7
|
-
const ajv = new Ajv();
|
|
8
|
-
const validator = ajv.compile(FORM_BUILDER_JSON_SCHEMA);
|
|
9
|
-
if (!validator(data)) {
|
|
10
|
-
throw new Error("Data does not conform to a valid form schema");
|
|
11
|
-
}
|
|
12
|
-
console.log(data);
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
catch (e) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
// This needs to build the form schema, this is where custom field data schemas would be used, e.g. address should have a schema, which is utilised here to generate the form schema
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { generateFieldId } from "../util";
|
|
2
|
-
export const generateJsonSchema1 = (formSchema) => {
|
|
3
|
-
// Lazy try catch rn
|
|
4
|
-
try {
|
|
5
|
-
console.log("SRTART");
|
|
6
|
-
const built = {
|
|
7
|
-
type: "object",
|
|
8
|
-
properties: {},
|
|
9
|
-
required: [],
|
|
10
|
-
};
|
|
11
|
-
formSchema.forEach(s => {
|
|
12
|
-
const fieldSchema = jsonSchemaFromFieldDefinition(s);
|
|
13
|
-
built.properties[generateFieldId(s.name)] = fieldSchema;
|
|
14
|
-
if (s.required)
|
|
15
|
-
built.required.push(generateFieldId(s.name));
|
|
16
|
-
});
|
|
17
|
-
console.log("BI", built);
|
|
18
|
-
return built;
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
console.log("err", e);
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const jsonSchemaFromFieldDefinition = (field) => {
|
|
26
|
-
switch (field.fieldType) {
|
|
27
|
-
case "string":
|
|
28
|
-
return jsonSchemaFromStringFieldDefinition(field);
|
|
29
|
-
case "number":
|
|
30
|
-
return jsonSchemaFromNumberFieldDefinition(field);
|
|
31
|
-
case "integer":
|
|
32
|
-
return jsonSchemaFromIntegerFieldDefinition(field);
|
|
33
|
-
case "boolean":
|
|
34
|
-
return jsonSchemaFromBooleanFieldDefinition(field);
|
|
35
|
-
case "enum":
|
|
36
|
-
return jsonSchemaFromEnumFieldDefinition(field);
|
|
37
|
-
case "object":
|
|
38
|
-
return jsonSchemaFromObjectFieldDefinition(field);
|
|
39
|
-
case "array":
|
|
40
|
-
return jsonSchemaFromArrayFieldDefinition(field);
|
|
41
|
-
case "address":
|
|
42
|
-
return jsonSchemaFromAddressFieldDefinition(field);
|
|
43
|
-
case "stagedText":
|
|
44
|
-
return jsonSchemaFromStagedTextFieldDefinition(field);
|
|
45
|
-
case "liveData":
|
|
46
|
-
return jsonSchemaFromLiveDataFieldDefinition(field);
|
|
47
|
-
case "component":
|
|
48
|
-
return jsonSchemaFromComponentFieldDefinition(field);
|
|
49
|
-
default:
|
|
50
|
-
throw new Error(`Unsupported field type: ${field.fieldType}`);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const jsonSchemaFromStringFieldDefinition = (field) => {
|
|
54
|
-
var _a;
|
|
55
|
-
return Object.assign({ title: field.name, description: field.description, type: "string" }, ((_a = field.stringOptions) !== null && _a !== void 0 ? _a : {}));
|
|
56
|
-
};
|
|
57
|
-
const jsonSchemaFromNumberFieldDefinition = (field) => {
|
|
58
|
-
var _a;
|
|
59
|
-
return Object.assign({ title: field.name, description: field.description, type: "number" }, ((_a = field.numberOptions) !== null && _a !== void 0 ? _a : {}));
|
|
60
|
-
};
|
|
61
|
-
const jsonSchemaFromIntegerFieldDefinition = (field) => {
|
|
62
|
-
var _a;
|
|
63
|
-
return Object.assign({ title: field.name, description: field.description, type: "integer" }, ((_a = field.numberOptions) !== null && _a !== void 0 ? _a : {}));
|
|
64
|
-
};
|
|
65
|
-
const jsonSchemaFromBooleanFieldDefinition = (field) => {
|
|
66
|
-
return {
|
|
67
|
-
title: field.name,
|
|
68
|
-
description: field.description,
|
|
69
|
-
type: "boolean"
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
const jsonSchemaFromEnumFieldDefinition = (field) => {
|
|
73
|
-
var _a, _b, _c;
|
|
74
|
-
// Temp, errors if invalid enum
|
|
75
|
-
if (((_b = (_a = field.enumOptions) === null || _a === void 0 ? void 0 : _a.enumValues) === null || _b === void 0 ? void 0 : _b.length) === 0)
|
|
76
|
-
throw new Error("Invalid enum count");
|
|
77
|
-
// Hopefully temp.
|
|
78
|
-
// The enum is stupid, it errors in jsonschema if it has no options
|
|
79
|
-
let opts = ((_c = field.enumOptions) === null || _c === void 0 ? void 0 : _c.enumValues) || [];
|
|
80
|
-
if (opts.length === 0)
|
|
81
|
-
opts.push("");
|
|
82
|
-
return {
|
|
83
|
-
title: field.name,
|
|
84
|
-
description: field.description,
|
|
85
|
-
type: "string",
|
|
86
|
-
enum: opts
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
const jsonSchemaFromObjectFieldDefinition = (field) => {
|
|
90
|
-
var _a, _b;
|
|
91
|
-
const properties = {};
|
|
92
|
-
const required = [];
|
|
93
|
-
for (const child of (_b = (_a = field.objectOptions) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : []) {
|
|
94
|
-
const fieldId = generateFieldId(child.name);
|
|
95
|
-
properties[fieldId] = jsonSchemaFromFieldDefinition(child);
|
|
96
|
-
if (child.required)
|
|
97
|
-
required.push(fieldId);
|
|
98
|
-
}
|
|
99
|
-
return Object.assign({ title: field.name, description: field.description, type: "object", properties }, (required.length > 0 && { required }));
|
|
100
|
-
};
|
|
101
|
-
const jsonSchemaFromArrayFieldDefinition = (field) => {
|
|
102
|
-
var _a, _b;
|
|
103
|
-
const items = ((_a = field.arrayOptions) === null || _a === void 0 ? void 0 : _a.itemDefinition)
|
|
104
|
-
? jsonSchemaFromFieldDefinition(field.arrayOptions.itemDefinition)
|
|
105
|
-
:
|
|
106
|
-
{
|
|
107
|
-
type: "string"
|
|
108
|
-
};
|
|
109
|
-
return Object.assign({ title: field.name, description: field.description, type: "array", items }, ((_b = field.arrayOptions) !== null && _b !== void 0 ? _b : {}));
|
|
110
|
-
};
|
|
111
|
-
const jsonSchemaFromAddressFieldDefinition = (field) => {
|
|
112
|
-
const schema = {
|
|
113
|
-
title: field.name,
|
|
114
|
-
description: field.description,
|
|
115
|
-
type: "object",
|
|
116
|
-
"x-type": "address",
|
|
117
|
-
properties: {
|
|
118
|
-
line1: { type: "string", title: "Address Line 1" },
|
|
119
|
-
line2: { type: "string", title: "Address Line 2" },
|
|
120
|
-
city: { type: "string", title: "City" },
|
|
121
|
-
county: { type: "string", title: "County" },
|
|
122
|
-
postcode: {
|
|
123
|
-
type: "string",
|
|
124
|
-
title: "Postcode",
|
|
125
|
-
pattern: "^[A-Z]{1,2}[0-9][0-9A-Z]? ?[0-9][A-Z]{2}$"
|
|
126
|
-
},
|
|
127
|
-
number: { type: "number", title: "Number" }
|
|
128
|
-
},
|
|
129
|
-
required: ["line1", "city", "postcode"]
|
|
130
|
-
};
|
|
131
|
-
return schema;
|
|
132
|
-
};
|
|
133
|
-
const jsonSchemaFromStagedTextFieldDefinition = (field) => {
|
|
134
|
-
return Object.assign({ title: field.name, description: field.description, type: "object", properties: {
|
|
135
|
-
website: { type: "string", title: "Website" },
|
|
136
|
-
quote: { type: "string", title: "Quote" },
|
|
137
|
-
finalItinerary: { type: "string", title: "Final Itinerary" }
|
|
138
|
-
} }, (field.required && { required: ["website", "quote", "finalItinerary"] }));
|
|
139
|
-
};
|
|
140
|
-
const jsonSchemaFromLiveDataFieldDefinition = (field) => {
|
|
141
|
-
return Object.assign({ title: field.name, description: field.description, type: "object", properties: {
|
|
142
|
-
liveDataId: { type: "string", title: "Live Data ID" }
|
|
143
|
-
} }, (field.required && { required: ["liveDataId"] }));
|
|
144
|
-
};
|
|
145
|
-
const jsonSchemaFromComponentFieldDefinition = (field) => {
|
|
146
|
-
var _a, _b;
|
|
147
|
-
return Object.assign({ title: field.name, description: field.description, type: "string",
|
|
148
|
-
// @ts-ignore
|
|
149
|
-
"x-templateIds": (_b = (_a = field.componentOptions) === null || _a === void 0 ? void 0 : _a.templateIds) !== null && _b !== void 0 ? _b : [] }, (field.required && { required: ["componentId"] }));
|
|
150
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { getType } from "../../registry/fields";
|
|
2
|
-
import { generateFieldId } from "../util";
|
|
3
|
-
import "../../prebuild/generated/import_generated";
|
|
4
|
-
export const generateJsonSchema = (formSchema, stage) => {
|
|
5
|
-
// Lazy try catch rn
|
|
6
|
-
try {
|
|
7
|
-
const built = {
|
|
8
|
-
type: "object",
|
|
9
|
-
properties: {},
|
|
10
|
-
required: [],
|
|
11
|
-
};
|
|
12
|
-
formSchema.forEach(s => {
|
|
13
|
-
if (stage < s.existsFrom)
|
|
14
|
-
return;
|
|
15
|
-
const fieldSchema = defaultConverter(s, stage);
|
|
16
|
-
built.properties[generateFieldId(s.name)] = fieldSchema;
|
|
17
|
-
if (s.required)
|
|
18
|
-
built.required.push(generateFieldId(s.name));
|
|
19
|
-
});
|
|
20
|
-
return built;
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
console.error(e);
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const defaultConverter = (field, stage, omitTitle, isChild) => {
|
|
28
|
-
var _a, _b, _c, _d, _e;
|
|
29
|
-
// Default field type
|
|
30
|
-
field.fieldType = (_a = field.fieldType) !== null && _a !== void 0 ? _a : "string";
|
|
31
|
-
let schema = getType(field.fieldType);
|
|
32
|
-
if (!schema)
|
|
33
|
-
throw new Error("tried to generate schema from unknown type: " + field.fieldType + "\nFull object: " + JSON.stringify(field, null, 2));
|
|
34
|
-
const requiredFields = [];
|
|
35
|
-
if (field.required)
|
|
36
|
-
requiredFields.push(field.name);
|
|
37
|
-
// Specific for array
|
|
38
|
-
let arrayItems = field.fieldType === "array" ? defaultConverter((_b = field.arrayOptions) === null || _b === void 0 ? void 0 : _b.itemDefinition, stage, true, true) : undefined;
|
|
39
|
-
// Obj childs
|
|
40
|
-
const properties = {};
|
|
41
|
-
for (const child of (_d = (_c = field.objectOptions) === null || _c === void 0 ? void 0 : _c.properties) !== null && _d !== void 0 ? _d : []) {
|
|
42
|
-
const fieldId = generateFieldId(child.name);
|
|
43
|
-
properties[fieldId] = defaultConverter(child, stage, false, true);
|
|
44
|
-
if (child.required)
|
|
45
|
-
requiredFields.push(fieldId);
|
|
46
|
-
}
|
|
47
|
-
// Enum fails if empty, fixes
|
|
48
|
-
let enumOpts = field.fieldType === "enum" ? (() => {
|
|
49
|
-
var _a;
|
|
50
|
-
let enumOptions = (((_a = field.enumOptions) === null || _a === void 0 ? void 0 : _a.enumValues) || []);
|
|
51
|
-
if (enumOptions.length === 0)
|
|
52
|
-
enumOptions.push("");
|
|
53
|
-
return enumOptions;
|
|
54
|
-
})() : undefined;
|
|
55
|
-
// Component (probably should change this)
|
|
56
|
-
let templates = field.fieldType === "componentPicker" ? { "x-templateIds": (_e = field.componentOptions) === null || _e === void 0 ? void 0 : _e.templateIds } : {};
|
|
57
|
-
let title = omitTitle ? undefined : field.name;
|
|
58
|
-
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((!isChild && !field.editableIn.includes(stage)) && { readOnly: true })), { title, type: schema.schema.type, "x-type": schema.schema["x-type"] }), templates), (schema.schema.type === "object" && { properties })), { required: requiredFields }), (enumOpts && { enum: enumOpts })), (arrayItems && { items: arrayItems })), (field.fieldType === "object" && { properties }));
|
|
59
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { generateFieldId } from "../util";
|
|
2
|
-
import { getAllTypes } from "../../registry/fields";
|
|
3
|
-
export const generateUiSchema = (formSchema, stage) => {
|
|
4
|
-
const uiSchema = { type: "VerticalLayout", elements: [] };
|
|
5
|
-
formSchema.forEach((field) => {
|
|
6
|
-
if (stage < field.existsFrom)
|
|
7
|
-
return;
|
|
8
|
-
uiSchema.elements.push(uiFieldSchemaFromFieldDefinition(field));
|
|
9
|
-
});
|
|
10
|
-
return uiSchema;
|
|
11
|
-
};
|
|
12
|
-
const uiFieldSchemaFromFieldDefinition = (field, path = []) => {
|
|
13
|
-
var _a;
|
|
14
|
-
const scope = ["#", ...path, "properties", generateFieldId(field.name)].join("/");
|
|
15
|
-
if (field.fieldType !== "object" || getAllTypes().find((t => t.name === field.fieldType))) {
|
|
16
|
-
const uiElem = {
|
|
17
|
-
type: "Control",
|
|
18
|
-
scope,
|
|
19
|
-
};
|
|
20
|
-
return uiElem;
|
|
21
|
-
}
|
|
22
|
-
const children = ((_a = field.objectOptions) === null || _a === void 0 ? void 0 : _a.properties) || [];
|
|
23
|
-
const group = {
|
|
24
|
-
type: "Group",
|
|
25
|
-
label: field.name,
|
|
26
|
-
elements: children.map((child) => uiFieldSchemaFromFieldDefinition(child, [
|
|
27
|
-
...path,
|
|
28
|
-
"properties",
|
|
29
|
-
generateFieldId(field.name),
|
|
30
|
-
])),
|
|
31
|
-
};
|
|
32
|
-
return group;
|
|
33
|
-
};
|
package/dist/schema/schema.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export type JSONSchemaType = (JSONSchemaString | JSONSchemaNumber | JSONSchemaInteger | JSONSchemaBoolean | JSONSchemaEnum | JSONSchemaObject | JSONSchemaArray) & {
|
|
2
|
-
"x-type"?: string;
|
|
3
|
-
};
|
|
4
|
-
interface JSONSchemaBase {
|
|
5
|
-
title?: string;
|
|
6
|
-
description?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface JSONSchemaString extends JSONSchemaBase {
|
|
9
|
-
type: "string";
|
|
10
|
-
minLength?: number;
|
|
11
|
-
maxLength?: number;
|
|
12
|
-
pattern?: string;
|
|
13
|
-
format?: "" | "email" | "uri" | "date-time" | "date" | "time";
|
|
14
|
-
enum?: string[];
|
|
15
|
-
}
|
|
16
|
-
export interface JSONSchemaNumber extends JSONSchemaBase {
|
|
17
|
-
type: "number";
|
|
18
|
-
minimum?: number;
|
|
19
|
-
maximum?: number;
|
|
20
|
-
multipleOf?: number;
|
|
21
|
-
}
|
|
22
|
-
export interface JSONSchemaInteger extends JSONSchemaBase {
|
|
23
|
-
type: "integer";
|
|
24
|
-
minimum?: number;
|
|
25
|
-
maximum?: number;
|
|
26
|
-
multipleOf?: number;
|
|
27
|
-
}
|
|
28
|
-
export interface JSONSchemaBoolean extends JSONSchemaBase {
|
|
29
|
-
type: "boolean";
|
|
30
|
-
}
|
|
31
|
-
export interface JSONSchemaEnum extends JSONSchemaString {
|
|
32
|
-
enum: string[];
|
|
33
|
-
}
|
|
34
|
-
export interface JSONSchemaObject extends JSONSchemaBase {
|
|
35
|
-
type: "object";
|
|
36
|
-
properties: {
|
|
37
|
-
[key: string]: JSONSchemaType;
|
|
38
|
-
};
|
|
39
|
-
required?: string[];
|
|
40
|
-
}
|
|
41
|
-
export interface JSONSchemaArray extends JSONSchemaBase {
|
|
42
|
-
type: "array";
|
|
43
|
-
items: JSONSchemaType;
|
|
44
|
-
minItems?: number;
|
|
45
|
-
maxItems?: number;
|
|
46
|
-
uniqueItems?: boolean;
|
|
47
|
-
}
|
|
48
|
-
export {};
|
package/dist/schema/schema.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { JSONSchemaType } from "../schema";
|
|
2
|
-
export type ConstraintType = "MustHaveOneOf" | "MustHaveAllOf" | "MustNotHave" | "Custom";
|
|
3
|
-
export interface ConstraintDefinition {
|
|
4
|
-
type: ConstraintType;
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
schema: JSONSchemaType;
|
|
8
|
-
uiSchema: {
|
|
9
|
-
type: "VerticalLayout" | "HorizontalLayout";
|
|
10
|
-
elements: Array<{
|
|
11
|
-
type: "Control";
|
|
12
|
-
scope: string;
|
|
13
|
-
label?: string;
|
|
14
|
-
}>;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export declare const CONSTRAINT_DEFINITIONS: Record<ConstraintType, ConstraintDefinition>;
|