@prismatic-io/spectral 7.0.0-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,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { DataSourceType } from "../types";
2
+ import { DataSourceResultType, DataSourceResultFieldType } from "../types";
3
3
  interface DisplayDefinition {
4
4
  label: string;
5
5
  description: string;
@@ -128,7 +128,7 @@ export interface Trigger {
128
128
  isCommonTrigger?: boolean;
129
129
  }
130
130
  export declare type DataSourceResult = {
131
- content: DataSourceType;
131
+ result: DataSourceResultType;
132
132
  supplementalData: {
133
133
  data: unknown;
134
134
  contentType: string;
@@ -143,6 +143,7 @@ export interface DataSource {
143
143
  };
144
144
  inputs: Input[];
145
145
  perform: DataSourcePerformFunction;
146
+ resultFieldType: DataSourceResultFieldType;
146
147
  examplePayload?: unknown;
147
148
  }
148
149
  export declare enum OAuth2Type {
@@ -1,13 +1,15 @@
1
- import { ActionDisplayDefinition, DataSourcePerformFunction, Inputs, DataSourceResult, DataSourceType } from ".";
1
+ import { ActionDisplayDefinition, DataSourcePerformFunction, Inputs, DataSourceResult, DataSourceResultType, DataSourceResultFieldType } from ".";
2
2
  /**
3
3
  * DataSourceDefinition is the type of the object that is passed in to `dataSource` function to
4
4
  * define a component Data Source.
5
5
  */
6
- export interface DataSourceDefinition<TInputs extends Inputs, TDataSourceResult extends DataSourceResult<DataSourceType>> {
6
+ export interface DataSourceDefinition<TInputs extends Inputs, TDataSourceResult extends DataSourceResult<DataSourceResultType>> {
7
7
  /** Defines how the Data Source is displayed in the Prismatic interface. */
8
8
  display: ActionDisplayDefinition;
9
9
  /** Function to perform when this Data Source is invoked. */
10
10
  perform: DataSourcePerformFunction<TInputs, TDataSourceResult>;
11
+ /** Field type of the data produced by the data source perform function. */
12
+ resultFieldType: DataSourceResultFieldType;
11
13
  /** InputFields to present in the Prismatic interface for configuration of this Data Source. */
12
14
  inputs: TInputs;
13
15
  /** An example of the payload outputted by this Data Source. */
@@ -1,3 +1,3 @@
1
- import { Inputs, DataSourceResult, DataSourceType, ActionInputParameters, ActionContext } from ".";
1
+ import { Inputs, DataSourceResult, DataSourceResultType, ActionInputParameters, ActionContext } from ".";
2
2
  /** Definition of the function to perform when a Data Source is invoked. */
3
- export declare type DataSourcePerformFunction<T extends Inputs, TResult extends DataSourceResult<DataSourceType>> = (context: ActionContext, params: ActionInputParameters<T>) => Promise<TResult>;
3
+ export declare type DataSourcePerformFunction<T extends Inputs, TResult extends DataSourceResult<DataSourceResultType>> = (context: ActionContext, params: ActionInputParameters<T>) => Promise<TResult>;
@@ -1,7 +1,13 @@
1
+ /// <reference types="node" />
2
+ import { ObjectSelection, ObjectFieldMap, InputFieldDefaultMap, JSONForm } from "./Inputs";
3
+ /** The type of field that is appropriate for rendering the data that is the result of the data source perform function. */
4
+ export declare type DataSourceResultFieldType = keyof typeof InputFieldDefaultMap;
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 | JSONForm | Buffer | boolean | number | string | Record<string, unknown> | unknown[] | unknown;
1
7
  /** Represents the result of a Data Source action. */
2
- export declare type DataSourceResult<ContentData> = {
3
- /** The data that will be used as content. */
4
- content: ContentData;
8
+ export declare type DataSourceResult<TDataSourceResultType> = {
9
+ /** The resulting data that is returned from the data source. */
10
+ result: TDataSourceResultType;
5
11
  /** Additional data that may be useful for out-of-band processing at a later time. */
6
12
  supplementalData?: {
7
13
  data: unknown;
@@ -1,5 +1,27 @@
1
1
  import { ConditionalExpression } from "./conditional-logic";
2
- import { ObjectSelection, ObjectFieldMap } from "./DataSourceType";
2
+ export declare type ObjectSelection = {
3
+ key: string;
4
+ label?: string;
5
+ fields: {
6
+ key: string;
7
+ label?: string;
8
+ }[];
9
+ }[];
10
+ export declare type ObjectFieldMap = {
11
+ key: string;
12
+ label?: string;
13
+ value: {
14
+ objectKey: string;
15
+ objectLabel?: string;
16
+ fieldKey: string;
17
+ fieldLabel?: string;
18
+ };
19
+ }[];
20
+ export declare type JSONForm = {
21
+ schema: Record<string, unknown>;
22
+ uiSchema: Record<string, unknown>;
23
+ data: unknown;
24
+ };
3
25
  /** InputField type enumeration. */
4
26
  export declare type InputFieldType = InputFieldDefinition["type"];
5
27
  export declare const InputFieldDefaultMap: Record<InputFieldType, string | undefined>;
@@ -7,7 +29,7 @@ export declare type Inputs = Record<string, InputFieldDefinition>;
7
29
  export declare type ConnectionInput = (StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField) & {
8
30
  shown?: boolean;
9
31
  };
10
- 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;
11
33
  export declare type InputCleanFunction<TValue, TResult = TValue> = (value: TValue) => TResult;
12
34
  interface BaseInputField {
13
35
  /** Interface label of the InputField. */
@@ -155,6 +177,17 @@ export interface ObjectFieldMapInputField extends BaseInputField {
155
177
  /** Clean function */
156
178
  clean?: InputCleanFunction<NonNullable<this["default"]>>;
157
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
+ }
158
191
  /** Defines a single Choice option for a InputField. */
159
192
  export interface InputFieldChoice {
160
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
  };
@@ -21,4 +21,4 @@ export * from "./TriggerPayload";
21
21
  export * from "./DataSourceDefinition";
22
22
  export * from "./DataSourcePerformFunction";
23
23
  export * from "./DataSourceResult";
24
- export * from "./DataSourceType";
24
+ export * as serverTypes from "../serverTypes";
@@ -14,10 +14,23 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
14
14
  if (k2 === undefined) k2 = k;
15
15
  o[k2] = m[k];
16
16
  }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
17
22
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
23
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
24
  };
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
20
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.serverTypes = void 0;
21
34
  __exportStar(require("./ActionDefinition"), exports);
22
35
  __exportStar(require("./ComponentDefinition"), exports);
23
36
  __exportStar(require("./ConnectionDefinition"), exports);
@@ -37,4 +50,4 @@ __exportStar(require("./TriggerPayload"), exports);
37
50
  __exportStar(require("./DataSourceDefinition"), exports);
38
51
  __exportStar(require("./DataSourcePerformFunction"), exports);
39
52
  __exportStar(require("./DataSourceResult"), exports);
40
- __exportStar(require("./DataSourceType"), exports);
53
+ exports.serverTypes = __importStar(require("../serverTypes"));
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.0-pre",
3
+ "version": "7.0.3-pre",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"
@@ -1,20 +0,0 @@
1
- /// <reference types="node" />
2
- export declare type ObjectSelection = {
3
- key: string;
4
- label?: string;
5
- fields: {
6
- key: string;
7
- label?: string;
8
- }[];
9
- }[];
10
- export declare type ObjectFieldMap = {
11
- key: string;
12
- label?: string;
13
- value: {
14
- objectKey: string;
15
- objectLabel?: string;
16
- fieldKey: string;
17
- fieldLabel?: string;
18
- };
19
- }[];
20
- export declare type DataSourceType = ObjectSelection | ObjectFieldMap | Buffer | boolean | number | string | Record<string, unknown> | unknown[] | unknown;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });