@makehq/forman-schema 1.1.1 → 1.2.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 CHANGED
@@ -58,14 +58,36 @@ const formanSchema = toFormanSchema(jsonSchemaField);
58
58
 
59
59
  ### Forman Schema Types
60
60
 
61
- - textstring
62
- - numbernumber
63
- - booleanboolean
61
+ - accountnumber
62
+ - aiagentstring
63
+ - arrayarray
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
- - collectionobject
68
- - arrayarray
84
+ - textstring
85
+ - timestring
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
@@ -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] || "string",
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
  });
@@ -240,7 +240,12 @@ function handleSelectType(field, result, context) {
240
240
  const nested = isObject(field.options) ? isObject(field.options.nested) ? field.options.nested.store : field.options.nested : void 0;
241
241
  const domain = isObject(field.options) ? isObject(field.options.nested) && field.options.nested.domain ? field.options.nested.domain : void 0 : void 0;
242
242
  if (typeof options === "string") {
243
- result["x-fetch"] = appendQueryString(options, context.domain, context.tail);
243
+ Object.defineProperty(result, "x-fetch", {
244
+ configurable: true,
245
+ enumerable: true,
246
+ writable: true,
247
+ value: appendQueryString(options, context.domain, context.tail)
248
+ });
244
249
  } else if (options?.some((option) => option.label || option.nested)) {
245
250
  result.oneOf = (options || []).map((option) => {
246
251
  const localNested = (isObject(option.nested) ? option.nested.store : option.nested) || nested;
@@ -283,14 +288,19 @@ function handleSelectType(field, result, context) {
283
288
  }
284
289
  root.addFields(nested, [...context.tail, field.name]);
285
290
  } else if (nested) {
286
- result["x-nested"] = typeof nested === "string" ? nested : toJSONSchemaInternal(
287
- { type: "collection", spec: nested },
288
- {
289
- ...context,
290
- domain: domain || context.domain,
291
- tail: [...context.tail, field.name]
292
- }
293
- );
291
+ Object.defineProperty(result, "x-nested", {
292
+ configurable: true,
293
+ enumerable: true,
294
+ writable: true,
295
+ value: typeof nested === "string" ? nested : toJSONSchemaInternal(
296
+ { type: "collection", spec: nested },
297
+ {
298
+ ...context,
299
+ domain: domain || context.domain,
300
+ tail: [...context.tail, field.name]
301
+ }
302
+ )
303
+ });
294
304
  }
295
305
  return result;
296
306
  }
@@ -319,6 +329,7 @@ function handlePrimitiveType(field, result) {
319
329
  var JSON_PRIMITIVE_TYPE_MAP = {
320
330
  string: "text",
321
331
  number: "number",
332
+ integer: "number",
322
333
  boolean: "boolean"
323
334
  };
324
335
  function toFormanSchema(field) {
@@ -385,8 +396,9 @@ function toFormanSchema(field) {
385
396
  return textField;
386
397
  default:
387
398
  const primitiveField = {
388
- type: JSON_PRIMITIVE_TYPE_MAP[field.type] || "text",
389
- help: field.description,
399
+ type: JSON_PRIMITIVE_TYPE_MAP[field.type] || "any",
400
+ label: noEmpty(field.title),
401
+ help: noEmpty(field.description),
390
402
  default: field.default
391
403
  };
392
404
  if (field.minimum !== void 0 || field.maximum !== void 0) {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { JSONSchema7 } from 'json-schema';
2
- export { JSONSchema7 } from 'json-schema';
3
2
 
4
3
  /**
5
4
  * Valid Forman Schema field types
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { JSONSchema7 } from 'json-schema';
2
- export { JSONSchema7 } from 'json-schema';
3
2
 
4
3
  /**
5
4
  * Valid Forman Schema field types
package/dist/index.js CHANGED
@@ -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] || "string",
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
  });
@@ -213,7 +213,12 @@ function handleSelectType(field, result, context) {
213
213
  const nested = isObject(field.options) ? isObject(field.options.nested) ? field.options.nested.store : field.options.nested : void 0;
214
214
  const domain = isObject(field.options) ? isObject(field.options.nested) && field.options.nested.domain ? field.options.nested.domain : void 0 : void 0;
215
215
  if (typeof options === "string") {
216
- result["x-fetch"] = appendQueryString(options, context.domain, context.tail);
216
+ Object.defineProperty(result, "x-fetch", {
217
+ configurable: true,
218
+ enumerable: true,
219
+ writable: true,
220
+ value: appendQueryString(options, context.domain, context.tail)
221
+ });
217
222
  } else if (options?.some((option) => option.label || option.nested)) {
218
223
  result.oneOf = (options || []).map((option) => {
219
224
  const localNested = (isObject(option.nested) ? option.nested.store : option.nested) || nested;
@@ -256,14 +261,19 @@ function handleSelectType(field, result, context) {
256
261
  }
257
262
  root.addFields(nested, [...context.tail, field.name]);
258
263
  } else if (nested) {
259
- result["x-nested"] = typeof nested === "string" ? nested : toJSONSchemaInternal(
260
- { type: "collection", spec: nested },
261
- {
262
- ...context,
263
- domain: domain || context.domain,
264
- tail: [...context.tail, field.name]
265
- }
266
- );
264
+ Object.defineProperty(result, "x-nested", {
265
+ configurable: true,
266
+ enumerable: true,
267
+ writable: true,
268
+ value: typeof nested === "string" ? nested : toJSONSchemaInternal(
269
+ { type: "collection", spec: nested },
270
+ {
271
+ ...context,
272
+ domain: domain || context.domain,
273
+ tail: [...context.tail, field.name]
274
+ }
275
+ )
276
+ });
267
277
  }
268
278
  return result;
269
279
  }
@@ -292,6 +302,7 @@ function handlePrimitiveType(field, result) {
292
302
  var JSON_PRIMITIVE_TYPE_MAP = {
293
303
  string: "text",
294
304
  number: "number",
305
+ integer: "number",
295
306
  boolean: "boolean"
296
307
  };
297
308
  function toFormanSchema(field) {
@@ -358,8 +369,9 @@ function toFormanSchema(field) {
358
369
  return textField;
359
370
  default:
360
371
  const primitiveField = {
361
- type: JSON_PRIMITIVE_TYPE_MAP[field.type] || "text",
362
- help: field.description,
372
+ type: JSON_PRIMITIVE_TYPE_MAP[field.type] || "any",
373
+ label: noEmpty(field.title),
374
+ help: noEmpty(field.description),
363
375
  default: field.default
364
376
  };
365
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.1",
3
+ "version": "1.2.0",
4
4
  "description": "Forman Schema Tools",
5
5
  "license": "MIT",
6
6
  "author": "Make",