@prismatic-io/spectral 7.0.2-pre → 7.0.3-pre

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.
@@ -1,9 +1,9 @@
1
1
  /// <reference types="node" />
2
- import { ObjectSelection, ObjectFieldMap, InputFieldDefaultMap } from "./Inputs";
2
+ import { ObjectSelection, ObjectFieldMap, InputFieldDefaultMap, JSONForm } from "./Inputs";
3
3
  /** The type of field that is appropriate for rendering the data that is the result of the data source perform function. */
4
4
  export declare type DataSourceResultFieldType = keyof typeof InputFieldDefaultMap;
5
5
  /** The actual data type of the data that is the result of the data source perform function. */
6
- export declare type DataSourceResultType = ObjectSelection | ObjectFieldMap | Buffer | boolean | number | string | Record<string, unknown> | unknown[] | unknown;
6
+ export declare type DataSourceResultType = ObjectSelection | ObjectFieldMap | JSONForm | Buffer | boolean | number | string | Record<string, unknown> | unknown[] | unknown;
7
7
  /** Represents the result of a Data Source action. */
8
8
  export declare type DataSourceResult<TDataSourceResultType> = {
9
9
  /** The resulting data that is returned from the data source. */
@@ -17,6 +17,11 @@ export declare type ObjectFieldMap = {
17
17
  fieldLabel?: string;
18
18
  };
19
19
  }[];
20
+ export declare type JSONForm = {
21
+ schema: Record<string, unknown>;
22
+ uiSchema: Record<string, unknown>;
23
+ data: unknown;
24
+ };
20
25
  /** InputField type enumeration. */
21
26
  export declare type InputFieldType = InputFieldDefinition["type"];
22
27
  export declare const InputFieldDefaultMap: Record<InputFieldType, string | undefined>;
@@ -24,7 +29,7 @@ export declare type Inputs = Record<string, InputFieldDefinition>;
24
29
  export declare type ConnectionInput = (StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField) & {
25
30
  shown?: boolean;
26
31
  };
27
- export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField;
32
+ export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField | JSONFormInputField;
28
33
  export declare type InputCleanFunction<TValue, TResult = TValue> = (value: TValue) => TResult;
29
34
  interface BaseInputField {
30
35
  /** Interface label of the InputField. */
@@ -172,6 +177,17 @@ export interface ObjectFieldMapInputField extends BaseInputField {
172
177
  /** Clean function */
173
178
  clean?: InputCleanFunction<NonNullable<this["default"]>>;
174
179
  }
180
+ /** Defines attributes of a JSONFOrmInputField. */
181
+ export interface JSONFormInputField extends BaseInputField {
182
+ /** Data type the InputField will collect. */
183
+ type: "jsonform";
184
+ /** Collection type of the InputField */
185
+ collection?: InputFieldCollection;
186
+ /** Default value for this field. */
187
+ default?: JSONForm;
188
+ /** Clean function */
189
+ clean?: InputCleanFunction<NonNullable<this["default"]>>;
190
+ }
175
191
  /** Defines a single Choice option for a InputField. */
176
192
  export interface InputFieldChoice {
177
193
  /** Label to display for this Choice. */
@@ -12,4 +12,5 @@ exports.InputFieldDefaultMap = {
12
12
  connection: undefined,
13
13
  objectselection: undefined,
14
14
  objectfieldmap: undefined,
15
+ jsonform: undefined,
15
16
  };
package/dist/util.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Many functions in the `util` module are used to coerce data into a particular type, and can be accessed through `util.types`.
4
4
  * For example, `util.types.toInt("5.5")` will return an integer, `5`.
5
5
  */
6
- import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap } from "./types";
6
+ import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap, JSONForm } from "./types";
7
7
  /**
8
8
  * This function returns a lower cased version of the headers passed to it.
9
9
  *
@@ -40,6 +40,8 @@ declare const _default: {
40
40
  toObjectSelection: (value: unknown) => ObjectSelection;
41
41
  isObjectFieldMap: (value: unknown) => value is ObjectFieldMap;
42
42
  toObjectFieldMap: (value: unknown) => ObjectFieldMap;
43
+ isJSONForm: (value: unknown) => value is JSONForm;
44
+ toJSONForm: (value: unknown) => JSONForm;
43
45
  };
44
46
  docs: {
45
47
  formatJsonExample: (input: unknown) => string;
package/dist/util.js CHANGED
@@ -90,6 +90,24 @@ const toObjectFieldMap = (value) => {
90
90
  }
91
91
  throw new Error(`Value '${value}' cannot be coerced to ObjectFieldMap.`);
92
92
  };
93
+ /**
94
+ * @param value The value to test
95
+ * @returns This function returns true if the type of `value` is a JSONForm, or false otherwise.
96
+ */
97
+ const isJSONForm = (value) => {
98
+ return isObjectWithTruthyKeys(value, ["schema", "uiSchema", "data"]);
99
+ };
100
+ /**
101
+ * This function coerces a provided value into a JSONForm if possible.
102
+ * @param value The value to coerce to JSONForm.
103
+ * @returns This function returns the the value as a JSONForm if possible.
104
+ */
105
+ const toJSONForm = (value) => {
106
+ if (isJSONForm(value)) {
107
+ return value;
108
+ }
109
+ throw new Error(`Value '${value}' cannot be coerced to JSONForm.`);
110
+ };
93
111
  /**
94
112
  * Determine if a variable is a boolean (true or false).
95
113
  *
@@ -436,6 +454,8 @@ exports.default = {
436
454
  toObjectSelection,
437
455
  isObjectFieldMap,
438
456
  toObjectFieldMap,
457
+ isJSONForm,
458
+ toJSONForm,
439
459
  },
440
460
  docs: {
441
461
  formatJsonExample,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "7.0.2-pre",
3
+ "version": "7.0.3-pre",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"