@makehq/forman-schema 0.1.1 → 0.1.3
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/index.cjs +139 -0
- package/dist/{esm/index.d.ts → index.d.cts} +6 -4
- package/dist/{cjs/index.d.ts → index.d.ts} +6 -4
- package/dist/index.js +113 -0
- package/package.json +17 -11
- package/dist/cjs/index.js +0 -118
- package/dist/esm/index.js +0 -114
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
toFormanSchema: () => toFormanSchema,
|
|
24
|
+
toJSONSchema: () => toJSONSchema
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var FORMAN_PRIMITIVE_TYPE_MAP = {
|
|
28
|
+
text: "string",
|
|
29
|
+
number: "number",
|
|
30
|
+
boolean: "boolean",
|
|
31
|
+
date: "string",
|
|
32
|
+
json: "string"
|
|
33
|
+
};
|
|
34
|
+
var JSON_PRIMITIVE_TYPE_MAP = {
|
|
35
|
+
string: "text",
|
|
36
|
+
number: "number",
|
|
37
|
+
boolean: "boolean"
|
|
38
|
+
};
|
|
39
|
+
function noEmpty(text) {
|
|
40
|
+
if (!text) return void 0;
|
|
41
|
+
return text;
|
|
42
|
+
}
|
|
43
|
+
function toJSONSchema(field) {
|
|
44
|
+
switch (field.type) {
|
|
45
|
+
case "collection":
|
|
46
|
+
const required = [];
|
|
47
|
+
const properties = (Array.isArray(field.spec) ? field.spec : []).reduce(
|
|
48
|
+
(object, subField) => {
|
|
49
|
+
if (!subField.name) return object;
|
|
50
|
+
if (subField.required) required.push(subField.name);
|
|
51
|
+
return Object.defineProperty(object, subField.name, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
value: toJSONSchema(subField)
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
{}
|
|
57
|
+
);
|
|
58
|
+
return {
|
|
59
|
+
type: "object",
|
|
60
|
+
description: noEmpty(field.help),
|
|
61
|
+
properties,
|
|
62
|
+
required
|
|
63
|
+
};
|
|
64
|
+
case "array":
|
|
65
|
+
return {
|
|
66
|
+
type: "array",
|
|
67
|
+
description: noEmpty(field.help),
|
|
68
|
+
items: field.spec && toJSONSchema(
|
|
69
|
+
Array.isArray(field.spec) ? {
|
|
70
|
+
type: "collection",
|
|
71
|
+
spec: field.spec
|
|
72
|
+
} : field.spec
|
|
73
|
+
)
|
|
74
|
+
};
|
|
75
|
+
case "select":
|
|
76
|
+
return {
|
|
77
|
+
type: "string",
|
|
78
|
+
description: noEmpty(field.help),
|
|
79
|
+
enum: (field.options || []).map((option) => option.value)
|
|
80
|
+
};
|
|
81
|
+
default:
|
|
82
|
+
return {
|
|
83
|
+
type: FORMAN_PRIMITIVE_TYPE_MAP[field.type],
|
|
84
|
+
default: field.default != "" && field.default != null ? field.default : void 0,
|
|
85
|
+
description: noEmpty(field.help)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function toFormanSchema(field) {
|
|
90
|
+
switch (field.type) {
|
|
91
|
+
case "object":
|
|
92
|
+
const spec = field.properties ? Object.entries(field.properties).map(([name, property]) => {
|
|
93
|
+
const subField = toFormanSchema(property);
|
|
94
|
+
subField.name = name;
|
|
95
|
+
subField.required = field.required?.includes(name) || false;
|
|
96
|
+
return subField;
|
|
97
|
+
}) : [];
|
|
98
|
+
return {
|
|
99
|
+
type: "collection",
|
|
100
|
+
help: field.description,
|
|
101
|
+
spec
|
|
102
|
+
};
|
|
103
|
+
case "array":
|
|
104
|
+
return {
|
|
105
|
+
type: "array",
|
|
106
|
+
help: field.description,
|
|
107
|
+
spec: field.items && (field.items?.type === "object" && field.items.properties ? Object.entries(field.items.properties).map(([name, property]) => {
|
|
108
|
+
const subField = toFormanSchema(property);
|
|
109
|
+
subField.name = name;
|
|
110
|
+
subField.required = field.items?.required?.includes(name) || false;
|
|
111
|
+
return subField;
|
|
112
|
+
}) : toFormanSchema(field.items))
|
|
113
|
+
};
|
|
114
|
+
case "string":
|
|
115
|
+
if (field.enum) {
|
|
116
|
+
return {
|
|
117
|
+
type: "select",
|
|
118
|
+
help: field.description,
|
|
119
|
+
options: field.enum.map((value) => ({ value }))
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
type: "text",
|
|
124
|
+
help: field.description,
|
|
125
|
+
default: field.default
|
|
126
|
+
};
|
|
127
|
+
default:
|
|
128
|
+
return {
|
|
129
|
+
type: JSON_PRIMITIVE_TYPE_MAP[field.type],
|
|
130
|
+
help: field.description,
|
|
131
|
+
default: field.default
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
+
0 && (module.exports = {
|
|
137
|
+
toFormanSchema,
|
|
138
|
+
toJSONSchema
|
|
139
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type FormanSchemaField = {
|
|
2
2
|
name?: string;
|
|
3
3
|
type: string;
|
|
4
4
|
required?: boolean;
|
|
@@ -9,7 +9,7 @@ export type FormanSchemaField = {
|
|
|
9
9
|
help?: string;
|
|
10
10
|
spec?: FormanSchemaField[] | FormanSchemaField;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
type JSONSchemaField = {
|
|
13
13
|
type: string;
|
|
14
14
|
description?: string;
|
|
15
15
|
default?: string | number | boolean | null;
|
|
@@ -18,5 +18,7 @@ export type JSONSchemaField = {
|
|
|
18
18
|
items?: JSONSchemaField;
|
|
19
19
|
required?: string[];
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
declare function toJSONSchema(field: FormanSchemaField): JSONSchemaField;
|
|
22
|
+
declare function toFormanSchema(field: JSONSchemaField): FormanSchemaField;
|
|
23
|
+
|
|
24
|
+
export { type FormanSchemaField, type JSONSchemaField, toFormanSchema, toJSONSchema };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type FormanSchemaField = {
|
|
2
2
|
name?: string;
|
|
3
3
|
type: string;
|
|
4
4
|
required?: boolean;
|
|
@@ -9,7 +9,7 @@ export type FormanSchemaField = {
|
|
|
9
9
|
help?: string;
|
|
10
10
|
spec?: FormanSchemaField[] | FormanSchemaField;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
type JSONSchemaField = {
|
|
13
13
|
type: string;
|
|
14
14
|
description?: string;
|
|
15
15
|
default?: string | number | boolean | null;
|
|
@@ -18,5 +18,7 @@ export type JSONSchemaField = {
|
|
|
18
18
|
items?: JSONSchemaField;
|
|
19
19
|
required?: string[];
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
declare function toJSONSchema(field: FormanSchemaField): JSONSchemaField;
|
|
22
|
+
declare function toFormanSchema(field: JSONSchemaField): FormanSchemaField;
|
|
23
|
+
|
|
24
|
+
export { type FormanSchemaField, type JSONSchemaField, toFormanSchema, toJSONSchema };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var FORMAN_PRIMITIVE_TYPE_MAP = {
|
|
3
|
+
text: "string",
|
|
4
|
+
number: "number",
|
|
5
|
+
boolean: "boolean",
|
|
6
|
+
date: "string",
|
|
7
|
+
json: "string"
|
|
8
|
+
};
|
|
9
|
+
var JSON_PRIMITIVE_TYPE_MAP = {
|
|
10
|
+
string: "text",
|
|
11
|
+
number: "number",
|
|
12
|
+
boolean: "boolean"
|
|
13
|
+
};
|
|
14
|
+
function noEmpty(text) {
|
|
15
|
+
if (!text) return void 0;
|
|
16
|
+
return text;
|
|
17
|
+
}
|
|
18
|
+
function toJSONSchema(field) {
|
|
19
|
+
switch (field.type) {
|
|
20
|
+
case "collection":
|
|
21
|
+
const required = [];
|
|
22
|
+
const properties = (Array.isArray(field.spec) ? field.spec : []).reduce(
|
|
23
|
+
(object, subField) => {
|
|
24
|
+
if (!subField.name) return object;
|
|
25
|
+
if (subField.required) required.push(subField.name);
|
|
26
|
+
return Object.defineProperty(object, subField.name, {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
value: toJSONSchema(subField)
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
{}
|
|
32
|
+
);
|
|
33
|
+
return {
|
|
34
|
+
type: "object",
|
|
35
|
+
description: noEmpty(field.help),
|
|
36
|
+
properties,
|
|
37
|
+
required
|
|
38
|
+
};
|
|
39
|
+
case "array":
|
|
40
|
+
return {
|
|
41
|
+
type: "array",
|
|
42
|
+
description: noEmpty(field.help),
|
|
43
|
+
items: field.spec && toJSONSchema(
|
|
44
|
+
Array.isArray(field.spec) ? {
|
|
45
|
+
type: "collection",
|
|
46
|
+
spec: field.spec
|
|
47
|
+
} : field.spec
|
|
48
|
+
)
|
|
49
|
+
};
|
|
50
|
+
case "select":
|
|
51
|
+
return {
|
|
52
|
+
type: "string",
|
|
53
|
+
description: noEmpty(field.help),
|
|
54
|
+
enum: (field.options || []).map((option) => option.value)
|
|
55
|
+
};
|
|
56
|
+
default:
|
|
57
|
+
return {
|
|
58
|
+
type: FORMAN_PRIMITIVE_TYPE_MAP[field.type],
|
|
59
|
+
default: field.default != "" && field.default != null ? field.default : void 0,
|
|
60
|
+
description: noEmpty(field.help)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function toFormanSchema(field) {
|
|
65
|
+
switch (field.type) {
|
|
66
|
+
case "object":
|
|
67
|
+
const spec = field.properties ? Object.entries(field.properties).map(([name, property]) => {
|
|
68
|
+
const subField = toFormanSchema(property);
|
|
69
|
+
subField.name = name;
|
|
70
|
+
subField.required = field.required?.includes(name) || false;
|
|
71
|
+
return subField;
|
|
72
|
+
}) : [];
|
|
73
|
+
return {
|
|
74
|
+
type: "collection",
|
|
75
|
+
help: field.description,
|
|
76
|
+
spec
|
|
77
|
+
};
|
|
78
|
+
case "array":
|
|
79
|
+
return {
|
|
80
|
+
type: "array",
|
|
81
|
+
help: field.description,
|
|
82
|
+
spec: field.items && (field.items?.type === "object" && field.items.properties ? Object.entries(field.items.properties).map(([name, property]) => {
|
|
83
|
+
const subField = toFormanSchema(property);
|
|
84
|
+
subField.name = name;
|
|
85
|
+
subField.required = field.items?.required?.includes(name) || false;
|
|
86
|
+
return subField;
|
|
87
|
+
}) : toFormanSchema(field.items))
|
|
88
|
+
};
|
|
89
|
+
case "string":
|
|
90
|
+
if (field.enum) {
|
|
91
|
+
return {
|
|
92
|
+
type: "select",
|
|
93
|
+
help: field.description,
|
|
94
|
+
options: field.enum.map((value) => ({ value }))
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
type: "text",
|
|
99
|
+
help: field.description,
|
|
100
|
+
default: field.default
|
|
101
|
+
};
|
|
102
|
+
default:
|
|
103
|
+
return {
|
|
104
|
+
type: JSON_PRIMITIVE_TYPE_MAP[field.type],
|
|
105
|
+
help: field.description,
|
|
106
|
+
default: field.default
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
toFormanSchema,
|
|
112
|
+
toJSONSchema
|
|
113
|
+
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@makehq/forman-schema",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Forman Schema Tools",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Make",
|
|
7
7
|
"repository": "github:integromat/forman-schema",
|
|
8
8
|
"homepage": "https://www.make.com",
|
|
9
9
|
"type": "module",
|
|
10
|
-
"main": "
|
|
11
|
-
"
|
|
12
|
-
"types": "./dist/esm/index.d.ts",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.cts",
|
|
13
12
|
"exports": {
|
|
14
13
|
".": {
|
|
15
|
-
"import":
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
18
22
|
}
|
|
19
23
|
},
|
|
20
24
|
"engines": {
|
|
@@ -25,18 +29,20 @@
|
|
|
25
29
|
],
|
|
26
30
|
"scripts": {
|
|
27
31
|
"test": "jest --runInBand --forceExit --verbose false",
|
|
28
|
-
"build": "
|
|
29
|
-
"
|
|
30
|
-
"
|
|
32
|
+
"build": "tsup",
|
|
33
|
+
"lint": "tsc",
|
|
34
|
+
"check-exports": "attw --pack .",
|
|
31
35
|
"format": "npx prettier . --write"
|
|
32
36
|
},
|
|
33
37
|
"devDependencies": {
|
|
38
|
+
"@arethetypeswrong/cli": "^0.17.4",
|
|
34
39
|
"@jest/globals": "^29.7.0",
|
|
35
40
|
"@types/node": "^22.13.10",
|
|
36
41
|
"jest": "^29.7.0",
|
|
37
42
|
"prettier": "^3.5.3",
|
|
38
43
|
"ts-jest": "^29.2.6",
|
|
39
44
|
"ts-node": "^10.9.2",
|
|
45
|
+
"tsup": "^8.4.0",
|
|
40
46
|
"typescript": "^5.8.2"
|
|
41
47
|
}
|
|
42
48
|
}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toJSONSchema = toJSONSchema;
|
|
4
|
-
exports.toFormanSchema = toFormanSchema;
|
|
5
|
-
const FORMAN_PRIMITIVE_TYPE_MAP = {
|
|
6
|
-
text: 'string',
|
|
7
|
-
number: 'number',
|
|
8
|
-
boolean: 'boolean',
|
|
9
|
-
date: 'string',
|
|
10
|
-
json: 'string',
|
|
11
|
-
};
|
|
12
|
-
const JSON_PRIMITIVE_TYPE_MAP = {
|
|
13
|
-
string: 'text',
|
|
14
|
-
number: 'number',
|
|
15
|
-
boolean: 'boolean',
|
|
16
|
-
};
|
|
17
|
-
function noEmpty(text) {
|
|
18
|
-
if (!text)
|
|
19
|
-
return undefined;
|
|
20
|
-
return text;
|
|
21
|
-
}
|
|
22
|
-
function toJSONSchema(field) {
|
|
23
|
-
switch (field.type) {
|
|
24
|
-
case 'collection':
|
|
25
|
-
const required = [];
|
|
26
|
-
const properties = (Array.isArray(field.spec) ? field.spec : []).reduce((object, subField) => {
|
|
27
|
-
if (!subField.name)
|
|
28
|
-
return object;
|
|
29
|
-
if (subField.required)
|
|
30
|
-
required.push(subField.name);
|
|
31
|
-
return Object.defineProperty(object, subField.name, {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
value: toJSONSchema(subField),
|
|
34
|
-
});
|
|
35
|
-
}, {});
|
|
36
|
-
return {
|
|
37
|
-
type: 'object',
|
|
38
|
-
description: noEmpty(field.help),
|
|
39
|
-
properties,
|
|
40
|
-
required,
|
|
41
|
-
};
|
|
42
|
-
case 'array':
|
|
43
|
-
return {
|
|
44
|
-
type: 'array',
|
|
45
|
-
description: noEmpty(field.help),
|
|
46
|
-
items: field.spec &&
|
|
47
|
-
toJSONSchema(Array.isArray(field.spec)
|
|
48
|
-
? {
|
|
49
|
-
type: 'collection',
|
|
50
|
-
spec: field.spec,
|
|
51
|
-
}
|
|
52
|
-
: field.spec),
|
|
53
|
-
};
|
|
54
|
-
case 'select':
|
|
55
|
-
return {
|
|
56
|
-
type: 'string',
|
|
57
|
-
description: noEmpty(field.help),
|
|
58
|
-
enum: (field.options || []).map(option => option.value),
|
|
59
|
-
};
|
|
60
|
-
default:
|
|
61
|
-
return {
|
|
62
|
-
type: FORMAN_PRIMITIVE_TYPE_MAP[field.type],
|
|
63
|
-
default: field.default != '' && field.default != null ? field.default : undefined,
|
|
64
|
-
description: noEmpty(field.help),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function toFormanSchema(field) {
|
|
69
|
-
switch (field.type) {
|
|
70
|
-
case 'object':
|
|
71
|
-
const spec = field.properties
|
|
72
|
-
? Object.entries(field.properties).map(([name, property]) => {
|
|
73
|
-
const subField = toFormanSchema(property);
|
|
74
|
-
subField.name = name;
|
|
75
|
-
subField.required = field.required?.includes(name) || false;
|
|
76
|
-
return subField;
|
|
77
|
-
})
|
|
78
|
-
: [];
|
|
79
|
-
return {
|
|
80
|
-
type: 'collection',
|
|
81
|
-
help: field.description,
|
|
82
|
-
spec,
|
|
83
|
-
};
|
|
84
|
-
case 'array':
|
|
85
|
-
return {
|
|
86
|
-
type: 'array',
|
|
87
|
-
help: field.description,
|
|
88
|
-
spec: field.items &&
|
|
89
|
-
(field.items?.type === 'object' && field.items.properties
|
|
90
|
-
? Object.entries(field.items.properties).map(([name, property]) => {
|
|
91
|
-
const subField = toFormanSchema(property);
|
|
92
|
-
subField.name = name;
|
|
93
|
-
subField.required = field.items?.required?.includes(name) || false;
|
|
94
|
-
return subField;
|
|
95
|
-
})
|
|
96
|
-
: toFormanSchema(field.items)),
|
|
97
|
-
};
|
|
98
|
-
case 'string':
|
|
99
|
-
if (field.enum) {
|
|
100
|
-
return {
|
|
101
|
-
type: 'select',
|
|
102
|
-
help: field.description,
|
|
103
|
-
options: field.enum.map(value => ({ value })),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
type: 'text',
|
|
108
|
-
help: field.description,
|
|
109
|
-
default: field.default,
|
|
110
|
-
};
|
|
111
|
-
default:
|
|
112
|
-
return {
|
|
113
|
-
type: JSON_PRIMITIVE_TYPE_MAP[field.type],
|
|
114
|
-
help: field.description,
|
|
115
|
-
default: field.default,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
}
|
package/dist/esm/index.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
const FORMAN_PRIMITIVE_TYPE_MAP = {
|
|
2
|
-
text: 'string',
|
|
3
|
-
number: 'number',
|
|
4
|
-
boolean: 'boolean',
|
|
5
|
-
date: 'string',
|
|
6
|
-
json: 'string',
|
|
7
|
-
};
|
|
8
|
-
const JSON_PRIMITIVE_TYPE_MAP = {
|
|
9
|
-
string: 'text',
|
|
10
|
-
number: 'number',
|
|
11
|
-
boolean: 'boolean',
|
|
12
|
-
};
|
|
13
|
-
function noEmpty(text) {
|
|
14
|
-
if (!text)
|
|
15
|
-
return undefined;
|
|
16
|
-
return text;
|
|
17
|
-
}
|
|
18
|
-
export function toJSONSchema(field) {
|
|
19
|
-
switch (field.type) {
|
|
20
|
-
case 'collection':
|
|
21
|
-
const required = [];
|
|
22
|
-
const properties = (Array.isArray(field.spec) ? field.spec : []).reduce((object, subField) => {
|
|
23
|
-
if (!subField.name)
|
|
24
|
-
return object;
|
|
25
|
-
if (subField.required)
|
|
26
|
-
required.push(subField.name);
|
|
27
|
-
return Object.defineProperty(object, subField.name, {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
value: toJSONSchema(subField),
|
|
30
|
-
});
|
|
31
|
-
}, {});
|
|
32
|
-
return {
|
|
33
|
-
type: 'object',
|
|
34
|
-
description: noEmpty(field.help),
|
|
35
|
-
properties,
|
|
36
|
-
required,
|
|
37
|
-
};
|
|
38
|
-
case 'array':
|
|
39
|
-
return {
|
|
40
|
-
type: 'array',
|
|
41
|
-
description: noEmpty(field.help),
|
|
42
|
-
items: field.spec &&
|
|
43
|
-
toJSONSchema(Array.isArray(field.spec)
|
|
44
|
-
? {
|
|
45
|
-
type: 'collection',
|
|
46
|
-
spec: field.spec,
|
|
47
|
-
}
|
|
48
|
-
: field.spec),
|
|
49
|
-
};
|
|
50
|
-
case 'select':
|
|
51
|
-
return {
|
|
52
|
-
type: 'string',
|
|
53
|
-
description: noEmpty(field.help),
|
|
54
|
-
enum: (field.options || []).map(option => option.value),
|
|
55
|
-
};
|
|
56
|
-
default:
|
|
57
|
-
return {
|
|
58
|
-
type: FORMAN_PRIMITIVE_TYPE_MAP[field.type],
|
|
59
|
-
default: field.default != '' && field.default != null ? field.default : undefined,
|
|
60
|
-
description: noEmpty(field.help),
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export function toFormanSchema(field) {
|
|
65
|
-
switch (field.type) {
|
|
66
|
-
case 'object':
|
|
67
|
-
const spec = field.properties
|
|
68
|
-
? Object.entries(field.properties).map(([name, property]) => {
|
|
69
|
-
const subField = toFormanSchema(property);
|
|
70
|
-
subField.name = name;
|
|
71
|
-
subField.required = field.required?.includes(name) || false;
|
|
72
|
-
return subField;
|
|
73
|
-
})
|
|
74
|
-
: [];
|
|
75
|
-
return {
|
|
76
|
-
type: 'collection',
|
|
77
|
-
help: field.description,
|
|
78
|
-
spec,
|
|
79
|
-
};
|
|
80
|
-
case 'array':
|
|
81
|
-
return {
|
|
82
|
-
type: 'array',
|
|
83
|
-
help: field.description,
|
|
84
|
-
spec: field.items &&
|
|
85
|
-
(field.items?.type === 'object' && field.items.properties
|
|
86
|
-
? Object.entries(field.items.properties).map(([name, property]) => {
|
|
87
|
-
const subField = toFormanSchema(property);
|
|
88
|
-
subField.name = name;
|
|
89
|
-
subField.required = field.items?.required?.includes(name) || false;
|
|
90
|
-
return subField;
|
|
91
|
-
})
|
|
92
|
-
: toFormanSchema(field.items)),
|
|
93
|
-
};
|
|
94
|
-
case 'string':
|
|
95
|
-
if (field.enum) {
|
|
96
|
-
return {
|
|
97
|
-
type: 'select',
|
|
98
|
-
help: field.description,
|
|
99
|
-
options: field.enum.map(value => ({ value })),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
type: 'text',
|
|
104
|
-
help: field.description,
|
|
105
|
-
default: field.default,
|
|
106
|
-
};
|
|
107
|
-
default:
|
|
108
|
-
return {
|
|
109
|
-
type: JSON_PRIMITIVE_TYPE_MAP[field.type],
|
|
110
|
-
help: field.description,
|
|
111
|
-
default: field.default,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|