@makehq/forman-schema 1.1.2 → 1.2.1
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 +33 -5
- package/dist/index.cjs +10 -8
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +10 -8
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -58,14 +58,36 @@ const formanSchema = toFormanSchema(jsonSchemaField);
|
|
|
58
58
|
|
|
59
59
|
### Forman Schema Types
|
|
60
60
|
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
61
|
+
- account → number
|
|
62
|
+
- aiagent → string
|
|
63
|
+
- array → array
|
|
64
|
+
- buffer → string
|
|
65
|
+
- cert → string
|
|
66
|
+
- collection → object
|
|
67
|
+
- color → string
|
|
68
|
+
- datastore → number
|
|
64
69
|
- date → string
|
|
70
|
+
- email → string
|
|
71
|
+
- file → string
|
|
72
|
+
- filename → string
|
|
73
|
+
- folder → string
|
|
74
|
+
- hidden → string
|
|
75
|
+
- hook → number
|
|
76
|
+
- integer → number
|
|
65
77
|
- json → string
|
|
78
|
+
- keychain → number
|
|
79
|
+
- number → number
|
|
80
|
+
- path → string
|
|
81
|
+
- pkey → string
|
|
82
|
+
- port → number
|
|
66
83
|
- select → string with enum
|
|
67
|
-
-
|
|
68
|
-
-
|
|
84
|
+
- text → string
|
|
85
|
+
- time → string
|
|
86
|
+
- timestamp → string
|
|
87
|
+
- timezone → string
|
|
88
|
+
- uinteger → number
|
|
89
|
+
- url → string
|
|
90
|
+
- uuid → string
|
|
69
91
|
|
|
70
92
|
### JSON Schema Types
|
|
71
93
|
|
|
@@ -75,6 +97,12 @@ const formanSchema = toFormanSchema(jsonSchemaField);
|
|
|
75
97
|
- object → collection
|
|
76
98
|
- array → array
|
|
77
99
|
|
|
100
|
+
## Error Handling
|
|
101
|
+
|
|
102
|
+
### SchemaConversionError
|
|
103
|
+
|
|
104
|
+
`SchemaConversionError` is thrown when schema conversion fails. It includes a message and optionally the field that caused the error.
|
|
105
|
+
|
|
78
106
|
## Testing
|
|
79
107
|
|
|
80
108
|
To test the project:
|
package/dist/index.cjs
CHANGED
|
@@ -66,7 +66,7 @@ var FORMAN_TYPE_MAP = {
|
|
|
66
66
|
filename: "string",
|
|
67
67
|
file: "string",
|
|
68
68
|
folder: "string",
|
|
69
|
-
hidden:
|
|
69
|
+
hidden: void 0,
|
|
70
70
|
integer: "number",
|
|
71
71
|
uinteger: "number",
|
|
72
72
|
password: "string",
|
|
@@ -78,7 +78,8 @@ var FORMAN_TYPE_MAP = {
|
|
|
78
78
|
timestamp: "string",
|
|
79
79
|
timezone: "string",
|
|
80
80
|
url: "string",
|
|
81
|
-
uuid: "string"
|
|
81
|
+
uuid: "string",
|
|
82
|
+
any: void 0
|
|
82
83
|
};
|
|
83
84
|
function validateFormanField(field) {
|
|
84
85
|
if (!field.type) {
|
|
@@ -145,7 +146,7 @@ function toJSONSchemaInternal(field, context = createDefaultContext()) {
|
|
|
145
146
|
validateFormanField(field);
|
|
146
147
|
const normalizedField = normalizeFieldType(field);
|
|
147
148
|
const result = {
|
|
148
|
-
type: FORMAN_TYPE_MAP[normalizedField.type]
|
|
149
|
+
type: FORMAN_TYPE_MAP[normalizedField.type],
|
|
149
150
|
title: noEmpty(normalizedField.label),
|
|
150
151
|
description: noEmpty(normalizedField.help)
|
|
151
152
|
};
|
|
@@ -168,7 +169,6 @@ function toJSONSchemaInternal(field, context = createDefaultContext()) {
|
|
|
168
169
|
}
|
|
169
170
|
function handleCollectionType(field, result, context) {
|
|
170
171
|
Object.assign(result, {
|
|
171
|
-
type: "object",
|
|
172
172
|
properties: {},
|
|
173
173
|
required: []
|
|
174
174
|
});
|
|
@@ -192,7 +192,7 @@ function handleCollectionType(field, result, context) {
|
|
|
192
192
|
[name]: { const: value }
|
|
193
193
|
}
|
|
194
194
|
},
|
|
195
|
-
then: typeof nested === "string" ? { $ref:
|
|
195
|
+
then: typeof nested === "string" ? { $ref: nested } : nested
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
198
|
})
|
|
@@ -292,7 +292,7 @@ function handleSelectType(field, result, context) {
|
|
|
292
292
|
configurable: true,
|
|
293
293
|
enumerable: true,
|
|
294
294
|
writable: true,
|
|
295
|
-
value: typeof nested === "string" ? nested : toJSONSchemaInternal(
|
|
295
|
+
value: typeof nested === "string" ? { $ref: nested } : toJSONSchemaInternal(
|
|
296
296
|
{ type: "collection", spec: nested },
|
|
297
297
|
{
|
|
298
298
|
...context,
|
|
@@ -329,6 +329,7 @@ function handlePrimitiveType(field, result) {
|
|
|
329
329
|
var JSON_PRIMITIVE_TYPE_MAP = {
|
|
330
330
|
string: "text",
|
|
331
331
|
number: "number",
|
|
332
|
+
integer: "number",
|
|
332
333
|
boolean: "boolean"
|
|
333
334
|
};
|
|
334
335
|
function toFormanSchema(field) {
|
|
@@ -395,8 +396,9 @@ function toFormanSchema(field) {
|
|
|
395
396
|
return textField;
|
|
396
397
|
default:
|
|
397
398
|
const primitiveField = {
|
|
398
|
-
type: JSON_PRIMITIVE_TYPE_MAP[field.type] || "
|
|
399
|
-
|
|
399
|
+
type: JSON_PRIMITIVE_TYPE_MAP[field.type] || "any",
|
|
400
|
+
label: noEmpty(field.title),
|
|
401
|
+
help: noEmpty(field.description),
|
|
400
402
|
default: field.default
|
|
401
403
|
};
|
|
402
404
|
if (field.minimum !== void 0 || field.maximum !== void 0) {
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ var FORMAN_TYPE_MAP = {
|
|
|
39
39
|
filename: "string",
|
|
40
40
|
file: "string",
|
|
41
41
|
folder: "string",
|
|
42
|
-
hidden:
|
|
42
|
+
hidden: void 0,
|
|
43
43
|
integer: "number",
|
|
44
44
|
uinteger: "number",
|
|
45
45
|
password: "string",
|
|
@@ -51,7 +51,8 @@ var FORMAN_TYPE_MAP = {
|
|
|
51
51
|
timestamp: "string",
|
|
52
52
|
timezone: "string",
|
|
53
53
|
url: "string",
|
|
54
|
-
uuid: "string"
|
|
54
|
+
uuid: "string",
|
|
55
|
+
any: void 0
|
|
55
56
|
};
|
|
56
57
|
function validateFormanField(field) {
|
|
57
58
|
if (!field.type) {
|
|
@@ -118,7 +119,7 @@ function toJSONSchemaInternal(field, context = createDefaultContext()) {
|
|
|
118
119
|
validateFormanField(field);
|
|
119
120
|
const normalizedField = normalizeFieldType(field);
|
|
120
121
|
const result = {
|
|
121
|
-
type: FORMAN_TYPE_MAP[normalizedField.type]
|
|
122
|
+
type: FORMAN_TYPE_MAP[normalizedField.type],
|
|
122
123
|
title: noEmpty(normalizedField.label),
|
|
123
124
|
description: noEmpty(normalizedField.help)
|
|
124
125
|
};
|
|
@@ -141,7 +142,6 @@ function toJSONSchemaInternal(field, context = createDefaultContext()) {
|
|
|
141
142
|
}
|
|
142
143
|
function handleCollectionType(field, result, context) {
|
|
143
144
|
Object.assign(result, {
|
|
144
|
-
type: "object",
|
|
145
145
|
properties: {},
|
|
146
146
|
required: []
|
|
147
147
|
});
|
|
@@ -165,7 +165,7 @@ function handleCollectionType(field, result, context) {
|
|
|
165
165
|
[name]: { const: value }
|
|
166
166
|
}
|
|
167
167
|
},
|
|
168
|
-
then: typeof nested === "string" ? { $ref:
|
|
168
|
+
then: typeof nested === "string" ? { $ref: nested } : nested
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
})
|
|
@@ -265,7 +265,7 @@ function handleSelectType(field, result, context) {
|
|
|
265
265
|
configurable: true,
|
|
266
266
|
enumerable: true,
|
|
267
267
|
writable: true,
|
|
268
|
-
value: typeof nested === "string" ? nested : toJSONSchemaInternal(
|
|
268
|
+
value: typeof nested === "string" ? { $ref: nested } : toJSONSchemaInternal(
|
|
269
269
|
{ type: "collection", spec: nested },
|
|
270
270
|
{
|
|
271
271
|
...context,
|
|
@@ -302,6 +302,7 @@ function handlePrimitiveType(field, result) {
|
|
|
302
302
|
var JSON_PRIMITIVE_TYPE_MAP = {
|
|
303
303
|
string: "text",
|
|
304
304
|
number: "number",
|
|
305
|
+
integer: "number",
|
|
305
306
|
boolean: "boolean"
|
|
306
307
|
};
|
|
307
308
|
function toFormanSchema(field) {
|
|
@@ -368,8 +369,9 @@ function toFormanSchema(field) {
|
|
|
368
369
|
return textField;
|
|
369
370
|
default:
|
|
370
371
|
const primitiveField = {
|
|
371
|
-
type: JSON_PRIMITIVE_TYPE_MAP[field.type] || "
|
|
372
|
-
|
|
372
|
+
type: JSON_PRIMITIVE_TYPE_MAP[field.type] || "any",
|
|
373
|
+
label: noEmpty(field.title),
|
|
374
|
+
help: noEmpty(field.description),
|
|
373
375
|
default: field.default
|
|
374
376
|
};
|
|
375
377
|
if (field.minimum !== void 0 || field.maximum !== void 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@makehq/forman-schema",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Forman Schema Tools",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Make",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@types/json-schema": "^7.0.15",
|
|
41
41
|
"@types/node": "^22.13.10",
|
|
42
42
|
"jest": "^29.7.0",
|
|
43
|
+
"json-schema": "^0.4.0",
|
|
43
44
|
"prettier": "^3.5.3",
|
|
44
45
|
"ts-jest": "^29.2.6",
|
|
45
46
|
"ts-node": "^10.9.2",
|