@remoteoss/json-schema-form 0.1.1-dev.20230616083258 → 0.1.1-dev.20230616112349
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 +4 -3
- package/dist/index.js +4 -3
- package/dist/standalone.js +4 -3
- package/package.json +3 -4
- package/src/tests/createHeadlessForm.test.js +19 -15
- package/json-schema-form.d.ts +0 -48
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.1-dev.
|
|
5
|
-
Generated: Fri, 16 Jun 2023
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.1.1-dev.20230616112349
|
|
5
|
+
Generated: Fri, 16 Jun 2023 11:24:06 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -371,8 +371,9 @@ var baseString = (0, import_yup.string)().trim();
|
|
|
371
371
|
var todayDateHint = (/* @__PURE__ */ new Date()).toISOString().substring(0, 10);
|
|
372
372
|
var convertBytesToKB = convertDiskSizeFromTo("Bytes", "KB");
|
|
373
373
|
var convertKbBytesToMB = convertDiskSizeFromTo("KB", "MB");
|
|
374
|
+
var validateOnlyStrings = (0, import_yup.string)().trim().nullable().test("is-string", (value, context) => typeof context.originalValue === "string");
|
|
374
375
|
var yupSchemas = {
|
|
375
|
-
text:
|
|
376
|
+
text: validateOnlyStrings,
|
|
376
377
|
select: (0, import_yup.string)().trim().nullable(),
|
|
377
378
|
radio: (0, import_yup.string)().trim().nullable(),
|
|
378
379
|
date: (0, import_yup.string)().nullable().trim().matches(
|
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.1-dev.
|
|
5
|
-
Generated: Fri, 16 Jun 2023
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.1.1-dev.20230616112349
|
|
5
|
+
Generated: Fri, 16 Jun 2023 11:24:06 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -335,8 +335,9 @@ var baseString = string().trim();
|
|
|
335
335
|
var todayDateHint = (/* @__PURE__ */ new Date()).toISOString().substring(0, 10);
|
|
336
336
|
var convertBytesToKB = convertDiskSizeFromTo("Bytes", "KB");
|
|
337
337
|
var convertKbBytesToMB = convertDiskSizeFromTo("KB", "MB");
|
|
338
|
+
var validateOnlyStrings = string().trim().nullable().test("is-string", (value, context) => typeof context.originalValue === "string");
|
|
338
339
|
var yupSchemas = {
|
|
339
|
-
text:
|
|
340
|
+
text: validateOnlyStrings,
|
|
340
341
|
select: string().trim().nullable(),
|
|
341
342
|
radio: string().trim().nullable(),
|
|
342
343
|
date: string().nullable().trim().matches(
|
package/dist/standalone.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.1-dev.
|
|
5
|
-
Generated: Fri, 16 Jun 2023
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.1.1-dev.20230616112349
|
|
5
|
+
Generated: Fri, 16 Jun 2023 11:24:06 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11739,8 +11739,9 @@ var baseString = StringSchema().trim();
|
|
|
11739
11739
|
var todayDateHint = (/* @__PURE__ */ new Date()).toISOString().substring(0, 10);
|
|
11740
11740
|
var convertBytesToKB = convertDiskSizeFromTo("Bytes", "KB");
|
|
11741
11741
|
var convertKbBytesToMB = convertDiskSizeFromTo("KB", "MB");
|
|
11742
|
+
var validateOnlyStrings = StringSchema().trim().nullable().test("is-string", (value, context) => typeof context.originalValue === "string");
|
|
11742
11743
|
var yupSchemas = {
|
|
11743
|
-
text:
|
|
11744
|
+
text: validateOnlyStrings,
|
|
11744
11745
|
select: StringSchema().trim().nullable(),
|
|
11745
11746
|
radio: StringSchema().trim().nullable(),
|
|
11746
11747
|
date: StringSchema().nullable().trim().matches(
|
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.20230616112349",
|
|
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,48 +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
|
-
| {
|
|
31
|
-
fields: Fields;
|
|
32
|
-
handleValidation: Function;
|
|
33
|
-
isError: boolean;
|
|
34
|
-
error?: undefined;
|
|
35
|
-
}
|
|
36
|
-
| {
|
|
37
|
-
fields: never[];
|
|
38
|
-
isError: boolean;
|
|
39
|
-
error: any;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Generates the Headless form based on the provided JSON schema
|
|
44
|
-
*/
|
|
45
|
-
export function createHeadlessForm(
|
|
46
|
-
jsonSchema: Record<string, unknown>,
|
|
47
|
-
customConfig: JSConfig = {}
|
|
48
|
-
): HeadlessFormOutput;
|