@remoteoss/json-schema-form 0.11.0-dev.20240725074901 → 0.11.1-beta.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/CHANGELOG.md CHANGED
@@ -1,8 +1,33 @@
1
+ #### 0.11.1-beta.0 (2024-07-26)
2
+
3
+ ##### Chores
4
+
5
+ * **modify:** Add missing Typescript declarations ([#84](https://github.com/remoteoss/json-schema-form/pull/84)) ([86b3af2a](https://github.com/remoteoss/json-schema-form/commit/86b3af2a31981718ad349ac8d08fbdce3aa86acf))
6
+
7
+ #### 0.11.0-beta.0 (2024-07-25)
8
+
9
+ ##### Breaking changes
10
+
11
+ - **modify:**
12
+ - Change the return result to include warnings ([#83](https://github.com/remoteoss/json-schema-form/pull/83)) ([e07fcec8](https://github.com/remoteoss/json-schema-form/commit/e07fcec8e11cfcba2b477e5e6339cebbcc42038c))
13
+
14
+ ##### New Features
15
+
16
+ - **modify:**
17
+ - Allow picking fields ([#79](https://github.com/remoteoss/json-schema-form/pull/79)) ([2e044021](https://github.com/remoteoss/json-schema-form/commit/2e044021f30292be81cede3805eefb4f1ea96dd9))
18
+ - Add x-jsf-presentation shorthand ([#81](https://github.com/remoteoss/json-schema-form/pull/81)) ([7cfaab0b](https://github.com/remoteoss/json-schema-form/commit/7cfaab0bdbb05a1555f6c1d74b26b1e6d7fa8c43))
19
+ - Allow creating fields ([#80](https://github.com/remoteoss/json-schema-form/pull/80)) ([8a82254d](https://github.com/remoteoss/json-schema-form/commit/8a82254d7cf5799471fa0bf2d3d09179f1327187))
20
+ - Allow customize fields order ([#78](https://github.com/remoteoss/json-schema-form/pull/78)) ([adc88179](https://github.com/remoteoss/json-schema-form/commit/adc88179a5d1e5bd85371c0cc581b35964bf6edf))
21
+
22
+ ##### Bug Fixes
23
+
24
+ - **modify:** Customize attrs as Array now overrides the value ([#82](https://github.com/remoteoss/json-schema-form/pull/82)) ([7cc0853e](https://github.com/remoteoss/json-schema-form/commit/7cc0853e30f0c06ff160d8a3e4c4b4e402a1e520))
25
+
1
26
  #### 0.10.1-beta.0 (2024-07-23)
2
27
 
3
28
  ##### Chores
4
29
 
5
- * **Text field docs:** Change naming of ID number property ([#74](https://github.com/remoteoss/json-schema-form/pull/74)) ([338ddd2a](https://github.com/remoteoss/json-schema-form/commit/338ddd2a5f008ec089f38db834f075100b856001))
30
+ - **Text field docs:** Change naming of ID number property ([#74](https://github.com/remoteoss/json-schema-form/pull/74)) ([338ddd2a](https://github.com/remoteoss/json-schema-form/commit/338ddd2a5f008ec089f38db834f075100b856001))
6
31
 
7
32
  #### 0.10.0-beta.0 (2024-06-20)
8
33
 
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2024 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.11.0-dev.20240725074901
5
- Generated: Thu, 25 Jul 2024 07:49:16 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.1-beta.0
5
+ Generated: Fri, 26 Jul 2024 12:33:47 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -1853,9 +1853,10 @@ function mergeReplaceArray(_, newVal) {
1853
1853
  return Array.isArray(newVal) ? newVal : void 0;
1854
1854
  }
1855
1855
  function standardizeAttrs(attrs) {
1856
- const { errorMessage, properties, ...rest } = attrs;
1856
+ const { errorMessage, presentation, properties, ...rest } = attrs;
1857
1857
  return {
1858
1858
  ...rest,
1859
+ ...presentation ? { "x-jsf-presentation": presentation } : {},
1859
1860
  ...errorMessage ? { "x-jsf-errorMessage": errorMessage } : {}
1860
1861
  };
1861
1862
  }
@@ -2025,9 +2026,9 @@ function pickFields(originalSchema, fieldsToPick) {
2025
2026
  });
2026
2027
  warnings.push({
2027
2028
  type: WARNING_TYPES.PICK_MISSED_FIELD,
2028
- message: `The picked fields have related conditional fields that got added automatically. ${Object.keys(
2029
+ message: `The picked fields are in conditionals that refeer other fields. They added automatically: ${Object.keys(
2029
2030
  missingFields
2030
- ).join(", ")}. Check "meta" for more details.`,
2031
+ ).map((name) => `"${name}"`).join(", ")}. Check "meta" for more details.`,
2031
2032
  meta: missingFields
2032
2033
  });
2033
2034
  }
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2024 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.11.0-dev.20240725074901
5
- Generated: Thu, 25 Jul 2024 07:49:16 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.1-beta.0
5
+ Generated: Fri, 26 Jul 2024 12:33:47 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -1816,9 +1816,10 @@ function mergeReplaceArray(_, newVal) {
1816
1816
  return Array.isArray(newVal) ? newVal : void 0;
1817
1817
  }
1818
1818
  function standardizeAttrs(attrs) {
1819
- const { errorMessage, properties, ...rest } = attrs;
1819
+ const { errorMessage, presentation, properties, ...rest } = attrs;
1820
1820
  return {
1821
1821
  ...rest,
1822
+ ...presentation ? { "x-jsf-presentation": presentation } : {},
1822
1823
  ...errorMessage ? { "x-jsf-errorMessage": errorMessage } : {}
1823
1824
  };
1824
1825
  }
@@ -1988,9 +1989,9 @@ function pickFields(originalSchema, fieldsToPick) {
1988
1989
  });
1989
1990
  warnings.push({
1990
1991
  type: WARNING_TYPES.PICK_MISSED_FIELD,
1991
- message: `The picked fields have related conditional fields that got added automatically. ${Object.keys(
1992
+ message: `The picked fields are in conditionals that refeer other fields. They added automatically: ${Object.keys(
1992
1993
  missingFields
1993
- ).join(", ")}. Check "meta" for more details.`,
1994
+ ).map((name) => `"${name}"`).join(", ")}. Check "meta" for more details.`,
1994
1995
  meta: missingFields
1995
1996
  });
1996
1997
  }
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2024 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.11.0-dev.20240725074901
5
- Generated: Thu, 25 Jul 2024 07:49:16 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.1-beta.0
5
+ Generated: Fri, 26 Jul 2024 12:33:47 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -13332,9 +13332,10 @@ function mergeReplaceArray(_, newVal) {
13332
13332
  return Array.isArray(newVal) ? newVal : void 0;
13333
13333
  }
13334
13334
  function standardizeAttrs(attrs) {
13335
- const { errorMessage, properties, ...rest } = attrs;
13335
+ const { errorMessage, presentation, properties, ...rest } = attrs;
13336
13336
  return {
13337
13337
  ...rest,
13338
+ ...presentation ? { "x-jsf-presentation": presentation } : {},
13338
13339
  ...errorMessage ? { "x-jsf-errorMessage": errorMessage } : {}
13339
13340
  };
13340
13341
  }
@@ -13504,9 +13505,9 @@ function pickFields(originalSchema, fieldsToPick) {
13504
13505
  });
13505
13506
  warnings.push({
13506
13507
  type: WARNING_TYPES.PICK_MISSED_FIELD,
13507
- message: `The picked fields have related conditional fields that got added automatically. ${Object.keys(
13508
+ message: `The picked fields are in conditionals that refeer other fields. They added automatically: ${Object.keys(
13508
13509
  missingFields
13509
- ).join(", ")}. Check "meta" for more details.`,
13510
+ ).map((name) => `"${name}"`).join(", ")}. Check "meta" for more details.`,
13510
13511
  meta: missingFields
13511
13512
  });
13512
13513
  }
@@ -2,7 +2,6 @@
2
2
  * Shorthand to lookup for keys with `x-jsf-*` preffix.
3
3
  */
4
4
  export function pickXKey(node: Object, key: 'presentation' | 'errorMessage'): Object | undefined;
5
-
6
5
  type ValidationTypes =
7
6
  | 'type'
8
7
  | 'minimum'
@@ -104,6 +103,54 @@ type HeadlessFormOutput = {
104
103
  };
105
104
 
106
105
  type JSONSchemaObjectType = Record<string, unknown>;
106
+ type FieldName = string;
107
+ type FieldAttrs = Record<string, unknown>;
108
+
109
+ type FieldAttrsCallbackFn = (fieldName: FieldName, fieldAttrs: FieldAttrs) => FieldAttrs;
110
+
111
+ type ModConfigProperties = Record<FieldName, FieldAttrs | FieldAttrsCallbackFn>;
112
+
113
+ type ModifyConfig = {
114
+ /**
115
+ * An object with the fields to be modified with the returned attributes.
116
+ */
117
+ fields?: ModConfigProperties;
118
+ /**
119
+ * A callback function that runs through all fields, to modify them with the returned attributes.
120
+ */
121
+ allFields?: FieldAttrsCallbackFn;
122
+ /**
123
+ * An object of new fields to be created with the new attributes.
124
+ */
125
+ create?: ModConfigProperties;
126
+ /**
127
+ * An array of the fields to keep, removing the remaining fields.
128
+ */
129
+ pick?: FieldName[];
130
+ /* An array of fieldNames with the new order. Can be an object or callback function */
131
+ orderRoot?: FieldName[] | ((originalOrder: FieldName[]) => FieldName[]);
132
+ /**
133
+ * Mutes any logs or warnings from the library.
134
+ */
135
+ muteLogging?: boolean;
136
+ };
137
+
138
+ type WarningType =
139
+ | 'FIELD_TO_CHANGE_NOT_FOUND'
140
+ | 'ORDER_MISSING_FIELDS'
141
+ | 'FIELD_TO_CREATE_EXISTS'
142
+ | 'PICK_MISSED_FIELD';
143
+
144
+ type Warning = {
145
+ message: string;
146
+ type: WarningType;
147
+ meta?: Record<string, unknown>;
148
+ };
149
+
150
+ type ModifyOutput = {
151
+ schema: JSONSchemaObjectType;
152
+ warnings: Warning[];
153
+ };
107
154
 
108
155
  /**
109
156
  * Generates the Headless form based on the provided JSON schema
@@ -114,27 +161,17 @@ export function createHeadlessForm(
114
161
  customConfig?: JSFConfig
115
162
  ): HeadlessFormOutput;
116
163
 
117
- type MutationsConfig = {
118
- /**
119
- * An object with the list of fields to be mutated.
120
- */
121
- fields: Record<string, unknown>;
122
- /**
123
- * a callback function that applies a mutation to all the fields.
124
- * @param fieldName
125
- * @param fieldAttrs
126
- * @returns
127
- */
128
- allFields: (fieldName: string, fieldAttrs: Record<string, unknown>) => Record<string, unknown>;
129
- };
130
-
164
+ /**
165
+ * Returns a new JSON Schema modified based a given configuration.
166
+ * This does not mutate the original JSON Schema.
167
+ */
131
168
  export function modify(
132
169
  /**
133
- * The original JSON schema to be modified.
170
+ * The original JSON schema as base to the modifications.
134
171
  */
135
172
  originalSchema: JSONSchemaObjectType,
136
173
  /**
137
- * The configuration object containing the fields and allFields properties.
174
+ * The configuration object to create a new JSON Schema based on the originalSchema.
138
175
  */
139
- config?: MutationsConfig
140
- );
176
+ config?: ModifyConfig
177
+ ): ModifyOutput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.11.0-dev.20240725074901",
3
+ "version": "0.11.1-beta.0",
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",
@@ -53,6 +53,9 @@ const schemaPet = {
53
53
  properties: {
54
54
  street: {
55
55
  title: 'Street',
56
+ 'x-jsf-presentation': {
57
+ inputType: 'text',
58
+ },
56
59
  },
57
60
  },
58
61
  },
@@ -356,7 +359,7 @@ describe('modify() - basic mutations', () => {
356
359
  });
357
360
  });
358
361
 
359
- it('error message', () => {
362
+ it('customize x-jsf-errorMessage (shorthand)', () => {
360
363
  const result = modify(schemaPet, {
361
364
  fields: {
362
365
  pet_age: (fieldAttrs) => {
@@ -396,6 +399,53 @@ describe('modify() - basic mutations', () => {
396
399
  },
397
400
  });
398
401
  });
402
+
403
+ it('customize x-jsf-presentation (shorthand)', () => {
404
+ const result = modify(schemaPet, {
405
+ fields: {
406
+ pet_age: () => {
407
+ return {
408
+ presentation: {
409
+ 'data-foo': 123,
410
+ },
411
+ };
412
+ },
413
+ 'pet_address.street': {
414
+ presentation: {
415
+ 'data-foo': 456,
416
+ },
417
+ },
418
+ },
419
+ });
420
+
421
+ const originalPetAgePresentation = schemaPet.properties.pet_age['x-jsf-presentation'];
422
+ expect(originalPetAgePresentation).toBeDefined();
423
+
424
+ const originalPetStreetPresentation =
425
+ schemaPet.properties.pet_address.properties.street['x-jsf-presentation'];
426
+ expect(originalPetStreetPresentation).toBeDefined();
427
+
428
+ expect(result.schema).toMatchObject({
429
+ properties: {
430
+ pet_age: {
431
+ 'x-jsf-presentation': {
432
+ ...originalPetAgePresentation,
433
+ 'data-foo': 123,
434
+ },
435
+ },
436
+ pet_address: {
437
+ properties: {
438
+ street: {
439
+ 'x-jsf-presentation': {
440
+ ...originalPetStreetPresentation,
441
+ 'data-foo': 456,
442
+ },
443
+ },
444
+ },
445
+ },
446
+ },
447
+ });
448
+ });
399
449
  });
400
450
 
401
451
  const schemaTickets = {
@@ -700,7 +750,7 @@ describe('modify() - pick fields', () => {
700
750
  {
701
751
  type: 'PICK_MISSED_FIELD',
702
752
  message:
703
- 'The picked fields have related conditional fields that got added automatically. premium_id, reason. Check "meta" for more details.',
753
+ 'The picked fields are in conditionals that refeer other fields. They added automatically: "premium_id", "reason". Check "meta" for more details.',
704
754
  meta: { premium_id: { path: 'allOf[1].then' }, reason: { path: 'allOf[2].then' } },
705
755
  },
706
756
  ]);
@@ -729,7 +779,7 @@ describe('modify() - pick fields', () => {
729
779
  {
730
780
  type: 'PICK_MISSED_FIELD',
731
781
  message:
732
- 'The picked fields have related conditional fields that got added automatically. has_premium. Check "meta" for more details.',
782
+ 'The picked fields are in conditionals that refeer other fields. They added automatically: "has_premium". Check "meta" for more details.',
733
783
  meta: { has_premium: { path: 'allOf[1].if' } },
734
784
  },
735
785
  ]);