@remoteoss/json-schema-form 0.1.0-dev.20230517215258 → 0.1.1-dev.20230614173637

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/CHANGELOG.md CHANGED
@@ -1,33 +1,5 @@
1
- # Changelog
1
+ #### 0.1.0-beta.0 (2023-05-18)
2
2
 
3
- All notable changes to this project will be documented in this file.
3
+ ##### New Features
4
4
 
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [Unreleased]
9
-
10
- <!-- Type of changes:
11
- - Added
12
- - Changed
13
- - Deprecated
14
- - Removed
15
- - Fixed
16
- - Security
17
- -->
18
-
19
- <!-- eg:
20
- ### Added
21
- - Short description about it. ([#pr-id](https://github.com/remoteoss/jsf/pull/<pr-id>))
22
-
23
- ### Deprecated
24
- - Deprecated `xxx` in favor of `yyy`. ([#pr-id](https://github.com/remoteoss/jsf/pull/<pr-id>))
25
- -->
26
-
27
- ## [1.0.0-beta.1] - 2023-XX-XX
28
-
29
- ### Added
30
-
31
- - Initial public release. ([#1](https://github.com/remoteoss/jsf/pull/1))
32
-
33
- ---
5
+ - Initial release ([#1](https://github.com/remoteoss/json-schema-form/pull/1)) ([9a687351](https://github.com/remoteoss/json-schema-form/commit/9a6873513445a7a53e9f9222d457c5ce585cbbd8) and ([#5](https://github.com/remoteoss/json-schema-form/pull/5)) ([ceb6f47b](https://github.com/remoteoss/json-schema-form/commit/ceb6f47b3d1ff031e1789a504af32ecc36834d8e))
package/README.md CHANGED
@@ -14,6 +14,17 @@
14
14
 
15
15
  JSON Schemas are the SSoT (Single Source of Truth) that allows you to share form's _structure_ and _validations_ between frontend and backend, regardless of the language used.
16
16
 
17
+ ## Installation
18
+
19
+ Available on [NPM](https://www.npmjs.com/package/@remoteoss/json-schema-form).
20
+
21
+ ```bash
22
+ npm install @remoteoss/json-schema-form
23
+ # or
24
+
25
+ yarn install @remoteoss/json-schema-form
26
+ ```
27
+
17
28
  ## Documentation
18
29
 
19
30
  Check the 📚 **[JSF website](https://json-schema-form.vercel.app/)** for documentation and demos.
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.1.0-dev.20230517215258
5
- Generated: Wed, 17 May 2023 21:53:15 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.1.1-dev.20230614173637
5
+ Generated: Wed, 14 Jun 2023 17:37:05 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -591,7 +591,7 @@ function getField(fieldName, fields) {
591
591
  }
592
592
  function validateFieldSchema(field, value) {
593
593
  const validator = buildYupSchema(field);
594
- return validator().isValidSync(value);
594
+ return validator().isValidSync(value, { strict: true });
595
595
  }
596
596
  function compareFormValueWithSchemaValue(formValue, schemaValue) {
597
597
  const currentPropertyValue = typeof schemaValue === "number" ? schemaValue : schemaValue || void 0;
@@ -899,7 +899,8 @@ var handleValuesChange = (fields, jsonSchema, config) => (values) => {
899
899
  let errors;
900
900
  try {
901
901
  lazySchema.validateSync(values, {
902
- abortEarly: false
902
+ abortEarly: false,
903
+ strict: true
903
904
  });
904
905
  } catch (err) {
905
906
  if (err.name === "ValidationError") {
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.1.0-dev.20230517215258
5
- Generated: Wed, 17 May 2023 21:53:15 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.1.1-dev.20230614173637
5
+ Generated: Wed, 14 Jun 2023 17:37:05 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -555,7 +555,7 @@ function getField(fieldName, fields) {
555
555
  }
556
556
  function validateFieldSchema(field, value) {
557
557
  const validator = buildYupSchema(field);
558
- return validator().isValidSync(value);
558
+ return validator().isValidSync(value, { strict: true });
559
559
  }
560
560
  function compareFormValueWithSchemaValue(formValue, schemaValue) {
561
561
  const currentPropertyValue = typeof schemaValue === "number" ? schemaValue : schemaValue || void 0;
@@ -863,7 +863,8 @@ var handleValuesChange = (fields, jsonSchema, config) => (values) => {
863
863
  let errors;
864
864
  try {
865
865
  lazySchema.validateSync(values, {
866
- abortEarly: false
866
+ abortEarly: false,
867
+ strict: true
867
868
  });
868
869
  } catch (err) {
869
870
  if (err.name === "ValidationError") {
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.1.0-dev.20230517215258
5
- Generated: Wed, 17 May 2023 21:53:15 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.1.1-dev.20230614173637
5
+ Generated: Wed, 14 Jun 2023 17:37:05 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -11959,7 +11959,7 @@ function getField(fieldName, fields) {
11959
11959
  }
11960
11960
  function validateFieldSchema(field, value) {
11961
11961
  const validator = buildYupSchema(field);
11962
- return validator().isValidSync(value);
11962
+ return validator().isValidSync(value, { strict: true });
11963
11963
  }
11964
11964
  function compareFormValueWithSchemaValue(formValue, schemaValue) {
11965
11965
  const currentPropertyValue = typeof schemaValue === "number" ? schemaValue : schemaValue || void 0;
@@ -12267,7 +12267,8 @@ var handleValuesChange = (fields, jsonSchema, config) => (values2) => {
12267
12267
  let errors;
12268
12268
  try {
12269
12269
  lazySchema.validateSync(values2, {
12270
- abortEarly: false
12270
+ abortEarly: false,
12271
+ strict: true
12271
12272
  });
12272
12273
  } catch (err) {
12273
12274
  if (err.name === "ValidationError") {
@@ -0,0 +1,188 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "JSON json-schema-form-Schema",
4
+ "definitions": {
5
+ "schemaArray": {
6
+ "allOf": [
7
+ {
8
+ "$ref": "http://json-schema.org/draft-07/schema#/definitions/schemaArray"
9
+ },
10
+ {
11
+ "items": { "$ref": "#" }
12
+ }
13
+ ]
14
+ }
15
+ },
16
+ "allOf": [{ "$ref": "http://json-schema.org/draft-07/schema#" }],
17
+ "properties": {
18
+ "additionalItems": { "$ref": "#" },
19
+ "additionalProperties": { "$ref": "#" },
20
+ "dependencies": {
21
+ "additionalProperties": {
22
+ "anyOf": [{ "$ref": "#" }, { "type": "array" }]
23
+ }
24
+ },
25
+ "items": {
26
+ "anyOf": [{ "$ref": "#" }, { "$ref": "#/definitions/schemaArray" }]
27
+ },
28
+ "definitions": {
29
+ "additionalProperties": { "$ref": "#" }
30
+ },
31
+ "patternProperties": {
32
+ "additionalProperties": { "$ref": "#" }
33
+ },
34
+ "properties": {
35
+ "additionalProperties": { "$ref": "#" }
36
+ },
37
+ "if": { "$ref": "#" },
38
+ "then": { "$ref": "#" },
39
+ "else": { "$ref": "#" },
40
+ "allOf": { "$ref": "#/definitions/schemaArray" },
41
+ "anyOf": { "$ref": "#/definitions/schemaArray" },
42
+ "oneOf": { "$ref": "#/definitions/schemaArray" },
43
+ "not": { "$ref": "#" },
44
+ "contains": { "$ref": "#" },
45
+ "propertyNames": { "$ref": "#" },
46
+ "x-jsf-order": {
47
+ "description": "This keyword defines the order of fields for a given form or fieldset. It's placed at the schema root and inside of each fieldset.",
48
+ "$ref": "http://json-schema.org/draft-07/schema#/definitions/stringArray"
49
+ },
50
+ "x-jsf-errorMessage": {
51
+ "type": "object",
52
+ "additionalProperties": false,
53
+ "properties": {
54
+ "type": {
55
+ "type": "string",
56
+ "description": "Message shown when the value is not of the correct type."
57
+ },
58
+ "required": {
59
+ "type": "string",
60
+ "description": "Message shown when the value is required and not provided."
61
+ },
62
+ "minimum": {
63
+ "type": "string",
64
+ "description": "Message shown when the value is less than the minimum value."
65
+ },
66
+ "minLength": {
67
+ "type": "string",
68
+ "description": "Message shown when the value is less than the minimum length."
69
+ },
70
+ "maximum": {
71
+ "type": "string",
72
+ "description": "Message shown when the value is greater than the maximum value."
73
+ },
74
+ "maxLength": {
75
+ "type": "string",
76
+ "description": "Message shown when the value is greater than the maximum length."
77
+ },
78
+ "pattern": {
79
+ "type": "string",
80
+ "description": "Message shown when the value is not the correct format and does not match the pattern property."
81
+ },
82
+ "maxFileSize": {
83
+ "type": "string",
84
+ "description": "Message shown when the file size is greater than the maximum file size."
85
+ },
86
+ "accept": {
87
+ "type": "string",
88
+ "description": "Message shown when the file type is not accepted."
89
+ }
90
+ }
91
+ },
92
+ "x-jsf-presentation": {
93
+ "type": "object",
94
+ "description": "Presentation overrides for the schema",
95
+ "properties": {
96
+ "inputType": {
97
+ "description": "Input type for the generated UI field",
98
+ "type": "string",
99
+ "anyOf": [
100
+ {
101
+ "const": "text",
102
+ "description": "Similar to the native HTML input with text type."
103
+ },
104
+ {
105
+ "const": "select",
106
+ "description": "Similar to the native HTML select element."
107
+ },
108
+ {
109
+ "const": "radio",
110
+ "description": "Similar to a native HTML input with radio type."
111
+ },
112
+ {
113
+ "const": "number",
114
+ "description": "Similar to the native HTML input with number type."
115
+ },
116
+ {
117
+ "const": "date",
118
+ "description": "Expects a value with format YYY-MM-DD."
119
+ },
120
+ {
121
+ "const": "checkbox",
122
+ "description": "Similar to the native HTML input with checkbox type."
123
+ },
124
+ {
125
+ "const": "email",
126
+ "description": "Similar to the native HTML input with email type."
127
+ },
128
+ {
129
+ "const": "file",
130
+ "description": "Similar to the native HTML input with file type."
131
+ },
132
+ {
133
+ "const": "fieldset",
134
+ "description": "Groups multiple Fields inside. Its expected value is a nested object."
135
+ },
136
+ {
137
+ "const": "group-array",
138
+ "description": "A list of inputs that can be repeated. Its expected value is an array."
139
+ },
140
+ {
141
+ "type": "string",
142
+ "description": "Any arbitrary custom inputType you might want to represent your UI Field."
143
+ }
144
+ ]
145
+ },
146
+ "accept": {
147
+ "description": "For `inputType: \"file\"`. The accepted file types, as a comma separated string.",
148
+ "type": "string"
149
+ },
150
+ "description": {
151
+ "description": "Field description with HTML. If you don't need HTML, please use the native description keyword.",
152
+ "type": "string"
153
+ },
154
+ "statement": {
155
+ "description": "Special message about the field. Useful in cases where this message is based on the field value.",
156
+ "type": "object",
157
+ "properties": {
158
+ "title": {
159
+ "type": "string"
160
+ },
161
+ "description": {
162
+ "description": "The sentence itself. Might include HTML.",
163
+ "type": "string"
164
+ },
165
+ "severity": {
166
+ "description": "Defines the type of message.",
167
+ "anyOf": [
168
+ { "type": "string", "const": "info" },
169
+ { "type": "string", "const": "warning" },
170
+ { "type": "string", "const": "error" },
171
+ { "type": "string", "const": "success" },
172
+ {}
173
+ ]
174
+ }
175
+ }
176
+ },
177
+ "maxFileSize": {
178
+ "description": "For `inputType: \"file\"`. The maximum file size in KB. It's used to enhanced Yup validation.",
179
+ "type": "number"
180
+ },
181
+ "addFieldText": {
182
+ "description": "Used in `group-array` fields. The button text to add a new field.",
183
+ "type": "string"
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.1.0-dev.20230517215258",
3
+ "version": "0.1.1-dev.20230614173637",
4
4
  "description": "Headless UI form powered by JSON Schemas",
5
5
  "author": "Remote.com <engineering@remote.com> (https://remote.com/)",
6
6
  "license": "MIT",
@@ -14,6 +14,7 @@
14
14
  "files": [
15
15
  "dist",
16
16
  "src/tests",
17
+ "json-schema-form.schema.json",
17
18
  "README.md",
18
19
  "CHANGELOG.md",
19
20
  "LICENSE.md"
@@ -21,6 +22,7 @@
21
22
  "scripts": {
22
23
  "build": "node scripts/build.js",
23
24
  "test": "jest",
25
+ "test:watch": "jest --watchAll",
24
26
  "lint": "eslint \"src/**/*.{js,ts}\"",
25
27
  "format": "npm run format:prettier && npm run format:eslint",
26
28
  "prepare": "husky install",
@@ -419,7 +419,7 @@ describe('createHeadlessForm', () => {
419
419
 
420
420
  describe('field support', () => {
421
421
  it('support "text" field type', () => {
422
- const { fields } = createHeadlessForm(schemaInputTypeText);
422
+ const { fields, handleValidation } = createHeadlessForm(schemaInputTypeText);
423
423
 
424
424
  expect(fields[0]).toMatchObject({
425
425
  description: 'The number of your national identification (max 10 digits)',
@@ -435,10 +435,14 @@ describe('createHeadlessForm', () => {
435
435
  });
436
436
 
437
437
  const fieldValidator = fields[0].schema;
438
- expect(fieldValidator.isValidSync('CI007')).toBe(true);
439
- expect(fieldValidator.isValidSync(true)).toBe(true); // @BUG RMT-446 - cannot be a bool
440
- expect(fieldValidator.isValidSync(1)).toBe(true); // @BUG RMT-446 - cannot be a number
441
- expect(fieldValidator.isValidSync(0)).toBe(true); // @BUG RMT-446 - cannot be a number
438
+ expect(fieldValidator.isValidSync('CI007', { strict: true })).toBe(true);
439
+ expect(fieldValidator.isValidSync(true, { strict: true })).toBe(false);
440
+ expect(fieldValidator.isValidSync(1, { strict: true })).toBe(false);
441
+ expect(fieldValidator.isValidSync(0, { strict: true })).toBe(false);
442
+
443
+ expect(handleValidation({ id_number: 1 }).formErrors).toEqual({
444
+ id_number: 'id_number must be a `string` type, but the final value was: `1`.',
445
+ });
442
446
 
443
447
  expect(() => fieldValidator.validateSync('')).toThrowError('Required field');
444
448
  });
@@ -1307,9 +1311,7 @@ describe('createHeadlessForm', () => {
1307
1311
 
1308
1312
  // The "child.has_child" is required
1309
1313
  expect(validateForm({})).toEqual({
1310
- child: {
1311
- has_child: 'Required field',
1312
- },
1314
+ child: 'Required field',
1313
1315
  });
1314
1316
 
1315
1317
  // The "child.no" is valid
@@ -2313,7 +2315,7 @@ describe('createHeadlessForm', () => {
2313
2315
  validateForm({
2314
2316
  validate_tabs: 'no',
2315
2317
  a_fieldset: {
2316
- id_number: 123,
2318
+ id_number: '123',
2317
2319
  },
2318
2320
  mandatory_group_array: 'no',
2319
2321
  })
@@ -2328,7 +2330,7 @@ describe('createHeadlessForm', () => {
2328
2330
  validateForm({
2329
2331
  validate_tabs: 'yes',
2330
2332
  a_fieldset: {
2331
- id_number: 123,
2333
+ id_number: '123',
2332
2334
  },
2333
2335
  mandatory_group_array: 'no',
2334
2336
  })
@@ -2344,7 +2346,7 @@ describe('createHeadlessForm', () => {
2344
2346
  validateForm({
2345
2347
  validate_tabs: 'yes',
2346
2348
  a_fieldset: {
2347
- id_number: 123,
2349
+ id_number: '123',
2348
2350
  },
2349
2351
  mandatory_group_array: 'yes',
2350
2352
  a_group_array: [{ full_name: 'adfs' }],
@@ -2355,7 +2357,7 @@ describe('createHeadlessForm', () => {
2355
2357
  validateForm({
2356
2358
  validate_tabs: 'yes',
2357
2359
  a_fieldset: {
2358
- id_number: 123,
2360
+ id_number: '123',
2359
2361
  tabs: 2,
2360
2362
  },
2361
2363
  mandatory_group_array: 'no',
@@ -2446,7 +2448,7 @@ describe('createHeadlessForm', () => {
2446
2448
  validateForm({
2447
2449
  validate_fieldset: ['id_number'],
2448
2450
  a_fieldset: {
2449
- id_number: 123,
2451
+ id_number: '123',
2450
2452
  },
2451
2453
  })
2452
2454
  ).toBeUndefined();
@@ -2455,7 +2457,7 @@ describe('createHeadlessForm', () => {
2455
2457
  validateForm({
2456
2458
  validate_fieldset: ['id_number', 'all'],
2457
2459
  a_fieldset: {
2458
- id_number: 123,
2460
+ id_number: '123',
2459
2461
  },
2460
2462
  })
2461
2463
  ).toEqual({
@@ -2468,7 +2470,7 @@ describe('createHeadlessForm', () => {
2468
2470
  validateForm({
2469
2471
  validate_fieldset: ['id_number', 'all'],
2470
2472
  a_fieldset: {
2471
- id_number: 123,
2473
+ id_number: '123',
2472
2474
  tabs: 2,
2473
2475
  },
2474
2476
  })
@@ -2483,7 +2485,7 @@ describe('createHeadlessForm', () => {
2483
2485
  validateForm({
2484
2486
  validate_fieldset: ['id_number'],
2485
2487
  a_fieldset: {
2486
- id_number: 123,
2488
+ id_number: '123',
2487
2489
  },
2488
2490
  })
2489
2491
  ).toBeUndefined();
@@ -2492,7 +2494,7 @@ describe('createHeadlessForm', () => {
2492
2494
  validateForm({
2493
2495
  validate_fieldset: ['id_number', 'all'],
2494
2496
  a_fieldset: {
2495
- id_number: 123,
2497
+ id_number: '123',
2496
2498
  },
2497
2499
  })
2498
2500
  ).toEqual({
@@ -2505,7 +2507,7 @@ describe('createHeadlessForm', () => {
2505
2507
  validateForm({
2506
2508
  validate_fieldset: ['id_number', 'all'],
2507
2509
  a_fieldset: {
2508
- id_number: 123,
2510
+ id_number: '123',
2509
2511
  tabs: 2,
2510
2512
  },
2511
2513
  })