@makehq/forman-schema 0.1.4 → 1.0.0
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 +92 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +1 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1 +1,92 @@
|
|
|
1
|
-
# Forman Schema
|
|
1
|
+
# Forman Schema
|
|
2
|
+
|
|
3
|
+
A utility for converting between Forman Schema and JSON Schema.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @makehq/forman-schema
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Converting from Forman Schema to JSON Schema
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { toJSONSchema } from '@makehq/forman-schema';
|
|
17
|
+
|
|
18
|
+
const formanField = {
|
|
19
|
+
type: 'collection',
|
|
20
|
+
spec: [
|
|
21
|
+
{
|
|
22
|
+
name: 'name',
|
|
23
|
+
type: 'text',
|
|
24
|
+
required: true,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'age',
|
|
28
|
+
type: 'number',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const jsonSchema = toJSONSchema(formanField);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Converting from JSON Schema to Forman Schema
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { toFormanSchema } from '@makehq/forman-schema';
|
|
40
|
+
|
|
41
|
+
const jsonSchemaField = {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
name: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
},
|
|
47
|
+
age: {
|
|
48
|
+
type: 'number',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
required: ['name'],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const formanSchema = toFormanSchema(jsonSchemaField);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Supported Types
|
|
58
|
+
|
|
59
|
+
### Forman Schema Types
|
|
60
|
+
|
|
61
|
+
- text → string
|
|
62
|
+
- number → number
|
|
63
|
+
- boolean → boolean
|
|
64
|
+
- date → string
|
|
65
|
+
- json → string
|
|
66
|
+
- select → string with enum
|
|
67
|
+
- collection → object
|
|
68
|
+
- array → array
|
|
69
|
+
|
|
70
|
+
### JSON Schema Types
|
|
71
|
+
|
|
72
|
+
- string → text
|
|
73
|
+
- number → number
|
|
74
|
+
- boolean → boolean
|
|
75
|
+
- object → collection
|
|
76
|
+
- array → array
|
|
77
|
+
|
|
78
|
+
## Testing
|
|
79
|
+
|
|
80
|
+
To test the project:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm test
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Building
|
|
87
|
+
|
|
88
|
+
To build the project:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm run build # Builds both ESM and CJS versions
|
|
92
|
+
```
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,24 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a field in Forman Schema format.
|
|
3
|
+
*/
|
|
1
4
|
type FormanSchemaField = {
|
|
5
|
+
/** Field name identifier */
|
|
2
6
|
name?: string;
|
|
7
|
+
/** The field type (e.g., 'text', 'number', 'boolean', 'collection', 'array', etc.) */
|
|
3
8
|
type: string;
|
|
9
|
+
/** Whether the field is required or not */
|
|
4
10
|
required?: boolean;
|
|
11
|
+
/** Default value for the field */
|
|
5
12
|
default?: string | number | boolean | null;
|
|
13
|
+
/** Available options for select type fields */
|
|
6
14
|
options?: {
|
|
15
|
+
/** Option value */
|
|
7
16
|
value: string;
|
|
8
17
|
}[];
|
|
18
|
+
/** Help text or description for the field */
|
|
9
19
|
help?: string;
|
|
20
|
+
/** Sub-fields specification for collection or array types */
|
|
10
21
|
spec?: FormanSchemaField[] | FormanSchemaField;
|
|
11
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Represents a field in JSON Schema format.
|
|
25
|
+
*/
|
|
12
26
|
type JSONSchemaField = {
|
|
27
|
+
/** The JSON Schema type (e.g., 'string', 'number', 'boolean', 'object', 'array', etc.) */
|
|
13
28
|
type: string;
|
|
29
|
+
/** Field description */
|
|
14
30
|
description?: string;
|
|
31
|
+
/** Default value for the field */
|
|
15
32
|
default?: string | number | boolean | null;
|
|
33
|
+
/** Enumeration of allowed values for the field */
|
|
16
34
|
enum?: string[];
|
|
35
|
+
/** Child properties for object type */
|
|
17
36
|
properties?: Record<string, JSONSchemaField>;
|
|
37
|
+
/** Array item specification for array type */
|
|
18
38
|
items?: JSONSchemaField;
|
|
39
|
+
/** List of required property names */
|
|
19
40
|
required?: string[];
|
|
20
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Converts a Forman Schema field to its JSON Schema equivalent.
|
|
44
|
+
* @param field - The Forman Schema field to convert
|
|
45
|
+
* @returns The equivalent JSON Schema field
|
|
46
|
+
*/
|
|
21
47
|
declare function toJSONSchema(field: FormanSchemaField): JSONSchemaField;
|
|
48
|
+
/**
|
|
49
|
+
* Converts a JSON Schema field to its Forman Schema equivalent.
|
|
50
|
+
* @param field - The JSON Schema field to convert
|
|
51
|
+
* @returns The equivalent Forman Schema field
|
|
52
|
+
*/
|
|
22
53
|
declare function toFormanSchema(field: JSONSchemaField): FormanSchemaField;
|
|
23
54
|
|
|
24
55
|
export { type FormanSchemaField, type JSONSchemaField, toFormanSchema, toJSONSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a field in Forman Schema format.
|
|
3
|
+
*/
|
|
1
4
|
type FormanSchemaField = {
|
|
5
|
+
/** Field name identifier */
|
|
2
6
|
name?: string;
|
|
7
|
+
/** The field type (e.g., 'text', 'number', 'boolean', 'collection', 'array', etc.) */
|
|
3
8
|
type: string;
|
|
9
|
+
/** Whether the field is required or not */
|
|
4
10
|
required?: boolean;
|
|
11
|
+
/** Default value for the field */
|
|
5
12
|
default?: string | number | boolean | null;
|
|
13
|
+
/** Available options for select type fields */
|
|
6
14
|
options?: {
|
|
15
|
+
/** Option value */
|
|
7
16
|
value: string;
|
|
8
17
|
}[];
|
|
18
|
+
/** Help text or description for the field */
|
|
9
19
|
help?: string;
|
|
20
|
+
/** Sub-fields specification for collection or array types */
|
|
10
21
|
spec?: FormanSchemaField[] | FormanSchemaField;
|
|
11
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Represents a field in JSON Schema format.
|
|
25
|
+
*/
|
|
12
26
|
type JSONSchemaField = {
|
|
27
|
+
/** The JSON Schema type (e.g., 'string', 'number', 'boolean', 'object', 'array', etc.) */
|
|
13
28
|
type: string;
|
|
29
|
+
/** Field description */
|
|
14
30
|
description?: string;
|
|
31
|
+
/** Default value for the field */
|
|
15
32
|
default?: string | number | boolean | null;
|
|
33
|
+
/** Enumeration of allowed values for the field */
|
|
16
34
|
enum?: string[];
|
|
35
|
+
/** Child properties for object type */
|
|
17
36
|
properties?: Record<string, JSONSchemaField>;
|
|
37
|
+
/** Array item specification for array type */
|
|
18
38
|
items?: JSONSchemaField;
|
|
39
|
+
/** List of required property names */
|
|
19
40
|
required?: string[];
|
|
20
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Converts a Forman Schema field to its JSON Schema equivalent.
|
|
44
|
+
* @param field - The Forman Schema field to convert
|
|
45
|
+
* @returns The equivalent JSON Schema field
|
|
46
|
+
*/
|
|
21
47
|
declare function toJSONSchema(field: FormanSchemaField): JSONSchemaField;
|
|
48
|
+
/**
|
|
49
|
+
* Converts a JSON Schema field to its Forman Schema equivalent.
|
|
50
|
+
* @param field - The JSON Schema field to convert
|
|
51
|
+
* @returns The equivalent Forman Schema field
|
|
52
|
+
*/
|
|
22
53
|
declare function toFormanSchema(field: JSONSchemaField): FormanSchemaField;
|
|
23
54
|
|
|
24
55
|
export { type FormanSchemaField, type JSONSchemaField, toFormanSchema, toJSONSchema };
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@makehq/forman-schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
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": "dist/index.js",
|
|
11
|
-
"types": "dist/index.d.cts",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.cts",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"import": {
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"scripts": {
|
|
31
31
|
"test": "jest --runInBand --forceExit --verbose false",
|
|
32
32
|
"build": "tsup",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
33
|
+
"build:version": "node scripts/build-version.mjs",
|
|
34
|
+
"format": "npx prettier . --write",
|
|
35
|
+
"publish:jsr": "npx jsr publish",
|
|
36
|
+
"lint": "tsc"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@arethetypeswrong/cli": "^0.17.4",
|
|
39
39
|
"@jest/globals": "^29.7.0",
|
|
40
40
|
"@types/node": "^22.13.10",
|
|
41
41
|
"jest": "^29.7.0",
|