@remoteoss/json-schema-form 0.1.1-dev.20230616085129 → 0.1.1-dev.20230619163824
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 +13 -3
- package/dist/index.js +13 -3
- package/dist/standalone.js +368 -786
- package/package.json +3 -4
- package/src/tests/createHeadlessForm.test.js +19 -15
- package/json-schema-form.d.ts +0 -42
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.1.1-dev.
|
|
3
|
+
"version": "0.1.1-dev.20230619163824",
|
|
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",
|
|
@@ -11,12 +11,10 @@
|
|
|
11
11
|
},
|
|
12
12
|
"main": "dist/index.cjs",
|
|
13
13
|
"module": "dist/index.js",
|
|
14
|
-
"typings": "./json-schema-form.d.ts",
|
|
15
14
|
"files": [
|
|
16
15
|
"dist",
|
|
17
16
|
"src/tests",
|
|
18
17
|
"json-schema-form.schema.json",
|
|
19
|
-
"json-schema-form.d.ts",
|
|
20
18
|
"README.md",
|
|
21
19
|
"CHANGELOG.md",
|
|
22
20
|
"LICENSE.md"
|
|
@@ -24,6 +22,7 @@
|
|
|
24
22
|
"scripts": {
|
|
25
23
|
"build": "node scripts/build.js",
|
|
26
24
|
"test": "jest",
|
|
25
|
+
"test:watch": "jest --watchAll",
|
|
27
26
|
"lint": "eslint \"src/**/*.{js,ts}\"",
|
|
28
27
|
"format": "npm run format:prettier && npm run format:eslint",
|
|
29
28
|
"prepare": "husky install",
|
|
@@ -48,7 +47,7 @@
|
|
|
48
47
|
"dependencies": {
|
|
49
48
|
"lodash": "^4.17.21",
|
|
50
49
|
"randexp": "^0.5.3",
|
|
51
|
-
"yup": "^0.
|
|
50
|
+
"yup": "^0.30.0"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
53
|
"@babel/core": "^7.21.5",
|
|
@@ -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(
|
|
440
|
-
expect(fieldValidator.isValidSync(1)).toBe(
|
|
441
|
-
expect(fieldValidator.isValidSync(0)).toBe(
|
|
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
|
});
|
|
@@ -2313,7 +2317,7 @@ describe('createHeadlessForm', () => {
|
|
|
2313
2317
|
validateForm({
|
|
2314
2318
|
validate_tabs: 'no',
|
|
2315
2319
|
a_fieldset: {
|
|
2316
|
-
id_number: 123,
|
|
2320
|
+
id_number: '123',
|
|
2317
2321
|
},
|
|
2318
2322
|
mandatory_group_array: 'no',
|
|
2319
2323
|
})
|
|
@@ -2328,7 +2332,7 @@ describe('createHeadlessForm', () => {
|
|
|
2328
2332
|
validateForm({
|
|
2329
2333
|
validate_tabs: 'yes',
|
|
2330
2334
|
a_fieldset: {
|
|
2331
|
-
id_number: 123,
|
|
2335
|
+
id_number: '123',
|
|
2332
2336
|
},
|
|
2333
2337
|
mandatory_group_array: 'no',
|
|
2334
2338
|
})
|
|
@@ -2344,7 +2348,7 @@ describe('createHeadlessForm', () => {
|
|
|
2344
2348
|
validateForm({
|
|
2345
2349
|
validate_tabs: 'yes',
|
|
2346
2350
|
a_fieldset: {
|
|
2347
|
-
id_number: 123,
|
|
2351
|
+
id_number: '123',
|
|
2348
2352
|
},
|
|
2349
2353
|
mandatory_group_array: 'yes',
|
|
2350
2354
|
a_group_array: [{ full_name: 'adfs' }],
|
|
@@ -2355,7 +2359,7 @@ describe('createHeadlessForm', () => {
|
|
|
2355
2359
|
validateForm({
|
|
2356
2360
|
validate_tabs: 'yes',
|
|
2357
2361
|
a_fieldset: {
|
|
2358
|
-
id_number: 123,
|
|
2362
|
+
id_number: '123',
|
|
2359
2363
|
tabs: 2,
|
|
2360
2364
|
},
|
|
2361
2365
|
mandatory_group_array: 'no',
|
|
@@ -2446,7 +2450,7 @@ describe('createHeadlessForm', () => {
|
|
|
2446
2450
|
validateForm({
|
|
2447
2451
|
validate_fieldset: ['id_number'],
|
|
2448
2452
|
a_fieldset: {
|
|
2449
|
-
id_number: 123,
|
|
2453
|
+
id_number: '123',
|
|
2450
2454
|
},
|
|
2451
2455
|
})
|
|
2452
2456
|
).toBeUndefined();
|
|
@@ -2455,7 +2459,7 @@ describe('createHeadlessForm', () => {
|
|
|
2455
2459
|
validateForm({
|
|
2456
2460
|
validate_fieldset: ['id_number', 'all'],
|
|
2457
2461
|
a_fieldset: {
|
|
2458
|
-
id_number: 123,
|
|
2462
|
+
id_number: '123',
|
|
2459
2463
|
},
|
|
2460
2464
|
})
|
|
2461
2465
|
).toEqual({
|
|
@@ -2468,7 +2472,7 @@ describe('createHeadlessForm', () => {
|
|
|
2468
2472
|
validateForm({
|
|
2469
2473
|
validate_fieldset: ['id_number', 'all'],
|
|
2470
2474
|
a_fieldset: {
|
|
2471
|
-
id_number: 123,
|
|
2475
|
+
id_number: '123',
|
|
2472
2476
|
tabs: 2,
|
|
2473
2477
|
},
|
|
2474
2478
|
})
|
|
@@ -2483,7 +2487,7 @@ describe('createHeadlessForm', () => {
|
|
|
2483
2487
|
validateForm({
|
|
2484
2488
|
validate_fieldset: ['id_number'],
|
|
2485
2489
|
a_fieldset: {
|
|
2486
|
-
id_number: 123,
|
|
2490
|
+
id_number: '123',
|
|
2487
2491
|
},
|
|
2488
2492
|
})
|
|
2489
2493
|
).toBeUndefined();
|
|
@@ -2492,7 +2496,7 @@ describe('createHeadlessForm', () => {
|
|
|
2492
2496
|
validateForm({
|
|
2493
2497
|
validate_fieldset: ['id_number', 'all'],
|
|
2494
2498
|
a_fieldset: {
|
|
2495
|
-
id_number: 123,
|
|
2499
|
+
id_number: '123',
|
|
2496
2500
|
},
|
|
2497
2501
|
})
|
|
2498
2502
|
).toEqual({
|
|
@@ -2505,7 +2509,7 @@ describe('createHeadlessForm', () => {
|
|
|
2505
2509
|
validateForm({
|
|
2506
2510
|
validate_fieldset: ['id_number', 'all'],
|
|
2507
2511
|
a_fieldset: {
|
|
2508
|
-
id_number: 123,
|
|
2512
|
+
id_number: '123',
|
|
2509
2513
|
tabs: 2,
|
|
2510
2514
|
},
|
|
2511
2515
|
})
|
package/json-schema-form.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shorthand to lookup for keys with `x-jsf-*` preffix.
|
|
3
|
-
*/
|
|
4
|
-
export function pickXKey(node: Object, key: 'presentation' | 'error-message'): Object | undefined;
|
|
5
|
-
|
|
6
|
-
type JSConfig = {
|
|
7
|
-
initialValues?: Record<string, unknown>;
|
|
8
|
-
strictInputType?: boolean;
|
|
9
|
-
customProperties?: {
|
|
10
|
-
description: Function | string;
|
|
11
|
-
[key: string]: unknown;
|
|
12
|
-
};
|
|
13
|
-
inputTypes?: {
|
|
14
|
-
errorMessage: Record<string, unknown>;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type Fields = Record<string, unknown>[]; // TODO: We don't know what type we have here, we need to investigate
|
|
19
|
-
|
|
20
|
-
type $TsFixMe = any;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Returns the Yup schema structure of given fields.
|
|
24
|
-
* These fields must be the same from
|
|
25
|
-
* const { fields } = createHeadlessForm()
|
|
26
|
-
*/
|
|
27
|
-
export function buildCompleteYupSchema(fields: Fields, config: JSConfig): $TsFixMe; // TODO: We don't what yup returns here, we'll fix it later
|
|
28
|
-
|
|
29
|
-
type HeadlessFormOutput = {
|
|
30
|
-
fields: Fields;
|
|
31
|
-
handleValidation: () => $TsFixMe;
|
|
32
|
-
isError: boolean;
|
|
33
|
-
error?: undefined;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Generates the Headless form based on the provided JSON schema
|
|
38
|
-
*/
|
|
39
|
-
export function createHeadlessForm(
|
|
40
|
-
jsonSchema: Record<string, unknown>,
|
|
41
|
-
customConfig: JSConfig
|
|
42
|
-
): HeadlessFormOutput;
|