@prismatic-io/spectral 7.0.9-pre → 7.0.12-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.
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * authors create inputs, actions, and components that can
4
4
  * be processed by the Prismatic API.
5
5
  */
6
- import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, DataSourceResult } from "./types";
6
+ import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition } from "./types";
7
7
  import { convertComponent } from "./serverTypes/convert";
8
8
  /**
9
9
  * This function creates a component object that can be
@@ -43,7 +43,23 @@ export declare const trigger: <TInputs extends Inputs, TAllowsBranching extends
43
43
  * @param definition A DataSourceDefinition type object that includes UI display information, a function to perform when the data source is invoked, and a an object containing inputs for the perform function.
44
44
  * @returns This function validates the shape of the `definition` object provided, and returns the same data source object.
45
45
  */
46
- export declare const dataSource: <TInputs extends Inputs, TResult extends DataSourceResult<unknown>>(definition: DataSourceDefinition<TInputs, TResult>) => DataSourceDefinition<TInputs, TResult>;
46
+ export declare const dataSource: <TInputs extends Inputs, TDataSourceType extends keyof {
47
+ string: string;
48
+ date: string;
49
+ timestamp: string;
50
+ picklist: string[];
51
+ schedule: {
52
+ value: string;
53
+ };
54
+ code: string;
55
+ credential: unknown;
56
+ boolean: boolean;
57
+ number: number;
58
+ connection: import("./types").ConnectionDefinition;
59
+ objectSelection: import("./types").ObjectSelection;
60
+ objectFieldMap: import("./types").ObjectFieldMap;
61
+ jsonForm: import("./types").JSONForm;
62
+ }>(definition: DataSourceDefinition<TInputs, TDataSourceType>) => DataSourceDefinition<TInputs, TDataSourceType>;
47
63
  /**
48
64
  * For information and examples on how to write inputs
49
65
  * for custom component actions and triggers, see
@@ -34,16 +34,18 @@ const convertAction = (actionKey, _a, hooks) => {
34
34
  const convertTrigger = (triggerKey, _a, hooks) => {
35
35
  var { inputs = {}, perform } = _a, trigger = __rest(_a, ["inputs", "perform"]);
36
36
  const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
37
+ const inputCleaners = Object.entries(inputs).reduce((result, [key, { clean }]) => (Object.assign(Object.assign({}, result), { [key]: clean })), {});
37
38
  return Object.assign(Object.assign({}, trigger), { key: triggerKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
38
- inputCleaners: {},
39
+ inputCleaners,
39
40
  errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
40
41
  }) });
41
42
  };
42
43
  const convertDataSource = (dataSourceKey, _a, hooks) => {
43
44
  var { inputs = {}, perform } = _a, dataSource = __rest(_a, ["inputs", "perform"]);
44
45
  const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
46
+ const inputCleaners = Object.entries(inputs).reduce((result, [key, { clean }]) => (Object.assign(Object.assign({}, result), { [key]: clean })), {});
45
47
  return Object.assign(Object.assign({}, dataSource), { key: dataSourceKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
46
- inputCleaners: {},
48
+ inputCleaners,
47
49
  errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
48
50
  }) });
49
51
  };
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { DataSourceResultType, DataSourceResultFieldType, Instance, Customer } from "../types";
2
+ import { Instance, Customer, DataSourceType, DataSourceResultType } from "../types";
3
3
  interface DisplayDefinition {
4
4
  label: string;
5
5
  description: string;
@@ -131,7 +131,7 @@ export interface DataSource {
131
131
  };
132
132
  inputs: Input[];
133
133
  perform: DataSourcePerformFunction;
134
- resultFieldType: DataSourceResultFieldType;
134
+ dataSourceType: DataSourceType;
135
135
  examplePayload?: unknown;
136
136
  }
137
137
  export declare enum OAuth2Type {
package/dist/testing.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * https://prismatic.io/docs/custom-components/writing-custom-components/#testing-a-component
6
6
  */
7
7
  import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult } from "./serverTypes";
8
- import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult } from "./types";
8
+ import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult } from "./types";
9
9
  export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>) => ConnectionValue;
10
10
  /**
11
11
  * Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
@@ -39,7 +39,23 @@ export declare const invokeTrigger: <TInputs extends Inputs, TAllowsBranching ex
39
39
  * Accepts a generic type matching DataSourceResult as a convenience to avoid extra
40
40
  * casting within test methods. Returns a DataSourceResult.
41
41
  */
42
- export declare const invokeDataSource: <TInputs extends Inputs, TReturn extends DataSourceResult>({ perform }: DataSourceDefinition<TInputs, TReturn>, params: ActionInputParameters<TInputs>) => Promise<TReturn>;
42
+ export declare const invokeDataSource: <TInputs extends Inputs, TDataSourceType extends keyof {
43
+ string: string;
44
+ date: string;
45
+ timestamp: string;
46
+ picklist: string[];
47
+ schedule: {
48
+ value: string;
49
+ };
50
+ code: string;
51
+ credential: unknown;
52
+ boolean: boolean;
53
+ number: number;
54
+ connection: ConnectionDefinition;
55
+ objectSelection: import("./types").ObjectSelection;
56
+ objectFieldMap: import("./types").ObjectFieldMap;
57
+ jsonForm: import("./types").JSONForm;
58
+ }>({ perform }: DataSourceDefinition<TInputs, TDataSourceType>, params: ActionInputParameters<TInputs>) => Promise<InvokeDataSourceResult<TDataSourceType>>;
43
59
  export declare class ComponentTestHarness<TComponent extends Component> {
44
60
  component: TComponent;
45
61
  constructor(component: TComponent);
@@ -54,6 +70,22 @@ declare const _default: {
54
70
  invoke: <TInputs extends Inputs, TAllowsBranching extends boolean, TReturn extends InvokeActionPerformReturn<TAllowsBranching, unknown>>({ perform }: ActionDefinition<TInputs, TAllowsBranching, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn>>;
55
71
  invokeTrigger: <TInputs_1 extends Inputs, TAllowsBranching_1 extends boolean, TResult extends InvokeTriggerResult<TAllowsBranching_1>>({ perform }: TriggerDefinition<TInputs_1, TAllowsBranching_1, TResult>, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs_1> | undefined) => Promise<InvokeReturn<TResult>>;
56
72
  createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
57
- invokeDataSource: <TInputs_2 extends Inputs, TReturn_1 extends DataSourceResult>({ perform }: DataSourceDefinition<TInputs_2, TReturn_1>, params: ActionInputParameters<TInputs_2>) => Promise<TReturn_1>;
73
+ invokeDataSource: <TInputs_2 extends Inputs, TDataSourceType extends keyof {
74
+ string: string;
75
+ date: string;
76
+ timestamp: string;
77
+ picklist: string[];
78
+ schedule: {
79
+ value: string;
80
+ };
81
+ code: string;
82
+ credential: unknown;
83
+ boolean: boolean;
84
+ number: number;
85
+ connection: ConnectionDefinition;
86
+ objectSelection: import("./types").ObjectSelection;
87
+ objectFieldMap: import("./types").ObjectFieldMap;
88
+ jsonForm: import("./types").JSONForm;
89
+ }>({ perform }: DataSourceDefinition<TInputs_2, TDataSourceType>, params: ActionInputParameters<TInputs_2>) => Promise<InvokeDataSourceResult<TDataSourceType>>;
58
90
  };
59
91
  export default _default;
@@ -1,15 +1,15 @@
1
- import { ActionDisplayDefinition, DataSourcePerformFunction, Inputs, DataSourceResult, DataSourceResultType, DataSourceResultFieldType } from ".";
1
+ import { ActionDisplayDefinition, DataSourcePerformFunction, Inputs, DataSourceType } 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<DataSourceResultType>> {
6
+ export interface DataSourceDefinition<TInputs extends Inputs, TDataSourceType extends DataSourceType> {
7
7
  /** Defines how the Data Source is displayed in the Prismatic interface. */
8
8
  display: ActionDisplayDefinition;
9
- /** Function to perform when this Data Source is invoked. */
10
- perform: DataSourcePerformFunction<TInputs, TDataSourceResult>;
11
- /** Field type of the data produced by the data source perform function. */
12
- resultFieldType: DataSourceResultFieldType;
9
+ /** Function to perform when this Data Source is invoked; fetches data from the data source. */
10
+ perform: DataSourcePerformFunction<TInputs, TDataSourceType>;
11
+ /** The type of data that this Data Source represents. */
12
+ dataSourceType: TDataSourceType;
13
13
  /** InputFields to present in the Prismatic interface for configuration of this Data Source. */
14
14
  inputs: TInputs;
15
15
  /** An example of the payload outputted by this Data Source. */
@@ -1,3 +1,3 @@
1
- import { Inputs, DataSourceResult, DataSourceResultType, ActionInputParameters } from ".";
1
+ import { Inputs, DataSourceResult, DataSourceType, ActionInputParameters } 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<DataSourceResultType>> = (params: ActionInputParameters<T>) => Promise<TResult>;
3
+ export declare type DataSourcePerformFunction<TInputs extends Inputs, TDataSourceType extends DataSourceType> = (params: ActionInputParameters<TInputs>) => Promise<DataSourceResult<TDataSourceType>>;
@@ -1,13 +1,29 @@
1
- /// <reference types="node" />
1
+ import { ConnectionDefinition } from "./ConnectionDefinition";
2
2
  import { ObjectSelection, ObjectFieldMap, 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
- export declare type DataSourceResultFieldType = "string" | "date" | "timestamp" | "picklist" | "schedule" | "code" | "credential" | "boolean" | "number" | "connection" | "objectSelection" | "objectFieldMap" | "jsonForm";
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;
4
+ declare type DataSourceTypeMap = {
5
+ string: string;
6
+ date: string;
7
+ timestamp: string;
8
+ picklist: string[];
9
+ schedule: {
10
+ value: string;
11
+ };
12
+ code: string;
13
+ credential: unknown;
14
+ boolean: boolean;
15
+ number: number;
16
+ connection: ConnectionDefinition;
17
+ objectSelection: ObjectSelection;
18
+ objectFieldMap: ObjectFieldMap;
19
+ jsonForm: JSONForm;
20
+ };
21
+ export declare type DataSourceType = keyof DataSourceTypeMap;
22
+ export declare type DataSourceResultType = DataSourceTypeMap[DataSourceType];
7
23
  /** Represents the result of a Data Source action. */
8
- export declare type DataSourceResult<TDataSourceResultType> = {
24
+ export declare type DataSourceResult<TDataSourceType extends DataSourceType> = {
9
25
  /** The resulting data that is returned from the data source. */
10
- result: TDataSourceResultType;
26
+ result: DataSourceTypeMap[TDataSourceType];
11
27
  /** Additional data that may be useful for out-of-band processing at a later time.
12
28
  * NOTE: This is only available when the Data Source is called as part of fetching
13
29
  * contents for a Configuration Wizard Page. */
@@ -16,3 +32,4 @@ export declare type DataSourceResult<TDataSourceResultType> = {
16
32
  contentType: string;
17
33
  };
18
34
  };
35
+ export {};
@@ -1,27 +1,26 @@
1
1
  import { ConditionalExpression } from "./conditional-logic";
2
- export declare type ObjectSelection = {
2
+ export declare type Element = {
3
3
  key: string;
4
4
  label?: string;
5
- selected?: boolean;
6
- fields?: {
7
- key: string;
8
- label?: string;
9
- }[];
5
+ };
6
+ export declare type ObjectSelection = {
7
+ object: Element;
8
+ fields?: Element[];
9
+ defaultSelected?: boolean;
10
10
  }[];
11
11
  export declare type ObjectFieldMap = {
12
- key: string;
13
- label?: string;
14
- value: {
15
- objectKey: string;
16
- objectLabel?: string;
17
- fieldKey: string;
18
- fieldLabel?: string;
19
- };
20
- defaultValue?: {
21
- objectKey: string;
22
- fieldKey: string;
23
- };
24
- }[];
12
+ fields: {
13
+ field: Element;
14
+ mappedObject?: Element;
15
+ mappedField?: Element;
16
+ defaultObject?: Element;
17
+ defaultField?: Element;
18
+ }[];
19
+ options: {
20
+ object: Element;
21
+ fields: Element[];
22
+ }[];
23
+ };
25
24
  export declare type JSONForm = {
26
25
  schema: Record<string, unknown>;
27
26
  uiSchema: Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "7.0.9-pre",
3
+ "version": "7.0.12-pre",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"