@prismatic-io/spectral
Advanced tools
Comparing version 7.0.0-pre to 7.0.0
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, DataSourceResult } from "./types"; | ||
import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition } from "./types"; | ||
import { convertComponent } from "./serverTypes/convert"; | ||
@@ -47,3 +47,19 @@ /** | ||
*/ | ||
export declare const dataSource: <TInputs extends Inputs, TResult extends DataSourceResult<unknown>>(definition: DataSourceDefinition<TInputs, TResult>) => DataSourceDefinition<TInputs, TResult>; | ||
export declare const dataSource: <TInputs extends Inputs, TDataSourceType extends keyof { | ||
string: string; | ||
date: string; | ||
timestamp: string; | ||
picklist: string[]; | ||
schedule: { | ||
value: string; | ||
}; | ||
code: string; | ||
credential: unknown; | ||
boolean: boolean; | ||
number: number; | ||
connection: import("./types").ConnectionDefinition; | ||
objectSelection: import("./types").ObjectSelection; | ||
objectFieldMap: import("./types").ObjectFieldMap; | ||
jsonForm: import("./types").JSONForm; | ||
}>(definition: DataSourceDefinition<TInputs, TDataSourceType>) => DataSourceDefinition<TInputs, TDataSourceType>; | ||
/** | ||
@@ -50,0 +66,0 @@ * For information and examples on how to write inputs |
@@ -37,4 +37,5 @@ "use strict"; | ||
const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value)); | ||
const inputCleaners = Object.entries(inputs).reduce((result, [key, { clean }]) => (Object.assign(Object.assign({}, result), { [key]: clean })), {}); | ||
return Object.assign(Object.assign({}, trigger), { key: triggerKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, { | ||
inputCleaners: {}, | ||
inputCleaners, | ||
errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error, | ||
@@ -46,4 +47,5 @@ }) }); | ||
const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value)); | ||
const inputCleaners = Object.entries(inputs).reduce((result, [key, { clean }]) => (Object.assign(Object.assign({}, result), { [key]: clean })), {}); | ||
return Object.assign(Object.assign({}, dataSource), { key: dataSourceKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, { | ||
inputCleaners: {}, | ||
inputCleaners, | ||
errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error, | ||
@@ -50,0 +52,0 @@ }) }); |
/// <reference types="node" /> | ||
import { DataSourceType } from "../types"; | ||
import { Instance, Customer, DataSourceType, DataSourceResultType } from "../types"; | ||
interface DisplayDefinition { | ||
@@ -7,2 +7,4 @@ label: string; | ||
} | ||
export { Instance } from "../types"; | ||
export { Customer } from "../types"; | ||
export interface Component { | ||
@@ -56,11 +58,4 @@ key: string; | ||
invokeUrl: string; | ||
customer: { | ||
id: string | null; | ||
externalId: string | null; | ||
name: string | null; | ||
}; | ||
instance: { | ||
id: string | null; | ||
name: string | null; | ||
}; | ||
customer: Customer; | ||
instance: Instance; | ||
} | ||
@@ -84,11 +79,4 @@ declare type TriggerOptionChoice = "invalid" | "valid" | "required"; | ||
executionId: string; | ||
customer: { | ||
id: string | null; | ||
externalId: string | null; | ||
name: string | null; | ||
}; | ||
instance: { | ||
id: string | null; | ||
name: string | null; | ||
}; | ||
customer: Customer; | ||
instance: Instance; | ||
} | ||
@@ -133,5 +121,10 @@ interface HttpResponse { | ||
} | ||
export interface DataSourceContext { | ||
logger: ActionLogger; | ||
customer: Customer; | ||
instance: Instance; | ||
} | ||
export declare type DataSourceResult = { | ||
content: DataSourceType; | ||
supplementalData: { | ||
result: DataSourceResultType; | ||
supplementalData?: { | ||
data: unknown; | ||
@@ -141,3 +134,3 @@ contentType: string; | ||
}; | ||
export declare type DataSourcePerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<DataSourceResult>; | ||
export declare type DataSourcePerformFunction = (context: DataSourceContext, params: Record<string, unknown>) => Promise<DataSourceResult>; | ||
export interface DataSource { | ||
@@ -151,2 +144,3 @@ key: string; | ||
perform: DataSourcePerformFunction; | ||
dataSourceType: DataSourceType; | ||
examplePayload?: unknown; | ||
@@ -223,2 +217,1 @@ } | ||
} | ||
export {}; |
@@ -25,2 +25,6 @@ "use strict"; | ||
try { | ||
if (args.length === 1) { | ||
const [params] = args; | ||
return yield performFn(cleanParams(params, inputCleaners)); | ||
} | ||
if (args.length === 2) { | ||
@@ -27,0 +31,0 @@ const [context, params] = args; |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult } from "./serverTypes"; | ||
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult, DataSourceContext } from "./serverTypes"; | ||
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult } from "./types"; | ||
@@ -17,3 +17,3 @@ export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>) => ConnectionValue; | ||
/** | ||
* The type of data returned by an `invoke()` function used for unit testing component actions. | ||
* The type of data returned by an `invoke()` function used for unit testing component actions and triggers. | ||
*/ | ||
@@ -40,15 +40,32 @@ interface InvokeReturn<ReturnData> { | ||
/** | ||
* Invokes specified DataSourceDefinition perform function using supplied params | ||
* and optional context. Accepts a generic type matching DataSourceResult as a convenience | ||
* to avoid extra casting within test methods. Returns an InvokeResult containing both the | ||
* action result and a mock logger for asserting logging. | ||
* Invokes specified DataSourceDefinition perform function using supplied params. | ||
* Accepts a generic type matching DataSourceResult as a convenience to avoid extra | ||
* casting within test methods. Returns a DataSourceResult. | ||
*/ | ||
export declare const invokeDataSource: <TInputs extends Inputs, TReturn extends InvokeDataSourceResult<unknown>>({ perform }: DataSourceDefinition<TInputs, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn>>; | ||
export declare const invokeDataSource: <TInputs extends Inputs, TDataSourceType extends keyof { | ||
string: string; | ||
date: string; | ||
timestamp: string; | ||
picklist: string[]; | ||
schedule: { | ||
value: string; | ||
}; | ||
code: string; | ||
credential: unknown; | ||
boolean: boolean; | ||
number: number; | ||
connection: ConnectionDefinition; | ||
objectSelection: import("./types").ObjectSelection; | ||
objectFieldMap: import("./types").ObjectFieldMap; | ||
jsonForm: import("./types").JSONForm; | ||
}>({ perform }: DataSourceDefinition<TInputs, TDataSourceType>, params: ActionInputParameters<TInputs>, context?: Partial<DataSourceContext> | undefined) => Promise<InvokeDataSourceResult<TDataSourceType>>; | ||
export declare class ComponentTestHarness<TComponent extends Component> { | ||
component: TComponent; | ||
constructor(component: TComponent); | ||
private buildContext; | ||
private buildParams; | ||
connectionValue({ key }: ConnectionDefinition): ConnectionValue; | ||
trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>; | ||
action(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<ActionPerformReturn>; | ||
dataSource(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<DataSourceResult>; | ||
dataSource(key: string, params?: Record<string, unknown>, context?: Partial<DataSourceContext>): Promise<DataSourceResult>; | ||
} | ||
@@ -61,4 +78,20 @@ export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>; | ||
createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>; | ||
invokeDataSource: <TInputs_2 extends Inputs, TReturn_1 extends InvokeDataSourceResult<unknown>>({ perform }: DataSourceDefinition<TInputs_2, TReturn_1>, params: ActionInputParameters<TInputs_2>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn_1>>; | ||
invokeDataSource: <TInputs_2 extends Inputs, TDataSourceType extends keyof { | ||
string: string; | ||
date: string; | ||
timestamp: string; | ||
picklist: string[]; | ||
schedule: { | ||
value: string; | ||
}; | ||
code: string; | ||
credential: unknown; | ||
boolean: boolean; | ||
number: number; | ||
connection: ConnectionDefinition; | ||
objectSelection: import("./types").ObjectSelection; | ||
objectFieldMap: import("./types").ObjectFieldMap; | ||
jsonForm: import("./types").JSONForm; | ||
}>({ perform }: DataSourceDefinition<TInputs_2, TDataSourceType>, params: ActionInputParameters<TInputs_2>, context?: Partial<DataSourceContext> | undefined) => Promise<InvokeDataSourceResult<TDataSourceType>>; | ||
}; | ||
export default _default; |
@@ -40,3 +40,3 @@ "use strict"; | ||
exports.loggerMock = loggerMock; | ||
const baseContext = { | ||
const baseActionContext = { | ||
logger: (0, exports.loggerMock)(), | ||
@@ -72,3 +72,3 @@ instanceState: {}, | ||
const invoke = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () { | ||
const realizedContext = Object.assign(Object.assign({}, baseContext), context); | ||
const realizedContext = Object.assign(Object.assign({}, baseActionContext), context); | ||
const result = yield perform(realizedContext, params); | ||
@@ -125,3 +125,3 @@ return { | ||
const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void 0, void 0, void 0, function* () { | ||
const realizedContext = Object.assign(Object.assign({}, baseContext), context); | ||
const realizedContext = Object.assign(Object.assign({}, baseActionContext), context); | ||
const realizedPayload = Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload); | ||
@@ -136,15 +136,23 @@ const realizedParams = params || {}; | ||
exports.invokeTrigger = invokeTrigger; | ||
const baseDataSourceContext = { | ||
logger: (0, exports.loggerMock)(), | ||
customer: { | ||
id: "customerId", | ||
name: "Customer 1", | ||
externalId: "1234", | ||
}, | ||
instance: { | ||
id: "instanceId", | ||
name: "Instance 1", | ||
}, | ||
}; | ||
/** | ||
* Invokes specified DataSourceDefinition perform function using supplied params | ||
* and optional context. Accepts a generic type matching DataSourceResult as a convenience | ||
* to avoid extra casting within test methods. Returns an InvokeResult containing both the | ||
* action result and a mock logger for asserting logging. | ||
* Invokes specified DataSourceDefinition perform function using supplied params. | ||
* Accepts a generic type matching DataSourceResult as a convenience to avoid extra | ||
* casting within test methods. Returns a DataSourceResult. | ||
*/ | ||
const invokeDataSource = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () { | ||
const realizedContext = Object.assign(Object.assign({}, baseContext), context); | ||
const realizedContext = Object.assign(Object.assign({}, baseDataSourceContext), context); | ||
const result = yield perform(realizedContext, params); | ||
return { | ||
result, | ||
loggerMock: realizedContext.logger, | ||
}; | ||
return result; | ||
}); | ||
@@ -156,2 +164,9 @@ exports.invokeDataSource = invokeDataSource; | ||
} | ||
buildContext(baseContext, context) { | ||
return Object.assign(Object.assign({}, baseContext), context); | ||
} | ||
buildParams(inputs, params) { | ||
const defaults = inputs.reduce((result, { key, default: defaultValue }) => (Object.assign(Object.assign({}, result), { [key]: `${defaultValue !== null && defaultValue !== void 0 ? defaultValue : ""}` })), {}); | ||
return Object.assign(Object.assign({}, defaults), params); | ||
} | ||
connectionValue({ key }) { | ||
@@ -167,5 +182,4 @@ const { PRISMATIC_CONNECTION_VALUE: value } = process.env; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const realizedContext = Object.assign(Object.assign({}, baseContext), context); | ||
const trigger = this.component.triggers[key]; | ||
return trigger.perform(realizedContext, Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), Object.assign({}, params)); | ||
return trigger.perform(this.buildContext(baseActionContext, context), Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), this.buildParams(trigger.inputs, params)); | ||
}); | ||
@@ -175,5 +189,4 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const realizedContext = Object.assign(Object.assign({}, baseContext), context); | ||
const action = this.component.actions[key]; | ||
return action.perform(realizedContext, Object.assign({}, params)); | ||
return action.perform(this.buildContext(baseActionContext, context), this.buildParams(action.inputs, params)); | ||
}); | ||
@@ -183,5 +196,4 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const realizedContext = Object.assign(Object.assign({}, baseContext), context); | ||
const dataSource = this.component.dataSources[key]; | ||
return dataSource.perform(realizedContext, Object.assign({}, params)); | ||
return dataSource.perform(this.buildContext(baseDataSourceContext, context), this.buildParams(dataSource.inputs, params)); | ||
}); | ||
@@ -188,0 +200,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Inputs, ActionPerformReturn, ActionInputParameters, ActionLogger } from "."; | ||
import { Inputs, ActionPerformReturn, ActionInputParameters, ActionLogger, Instance, Customer } from "."; | ||
/** Definition of the function to perform when an Action is invoked. */ | ||
@@ -24,13 +24,6 @@ export declare type ActionPerformFunction<TInputs extends Inputs, TAllowsBranching extends boolean | undefined, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>> = (context: ActionContext, params: ActionInputParameters<TInputs>) => Promise<TReturn>; | ||
invokeUrl: string; | ||
/** An object containing the ID, External ID and name of the customer the instance is deployed to */ | ||
customer: { | ||
id: string | null; | ||
externalId: string | null; | ||
name: string | null; | ||
}; | ||
/** An object containing the ID ad name of the currently running instance */ | ||
instance: { | ||
id: string | null; | ||
name: string | null; | ||
}; | ||
/** Contains attributes of the Customer for whom an Instance is being executed. */ | ||
customer: Customer; | ||
/** Contains attributes of the Instance that is being executed. */ | ||
instance: Instance; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { ActionDisplayDefinition, DataSourcePerformFunction, Inputs, DataSourceResult, DataSourceType } from "."; | ||
import { ActionDisplayDefinition, DataSourcePerformFunction, Inputs, DataSourceType } from "."; | ||
/** | ||
@@ -6,7 +6,9 @@ * DataSourceDefinition is the type of the object that is passed in to `dataSource` function to | ||
*/ | ||
export interface DataSourceDefinition<TInputs extends Inputs, TDataSourceResult extends DataSourceResult<DataSourceType>> { | ||
export interface DataSourceDefinition<TInputs extends Inputs, TDataSourceType extends DataSourceType> { | ||
/** Defines how the Data Source is displayed in the Prismatic interface. */ | ||
display: ActionDisplayDefinition; | ||
/** Function to perform when this Data Source is invoked. */ | ||
perform: DataSourcePerformFunction<TInputs, TDataSourceResult>; | ||
/** Function to perform when this Data Source is invoked; fetches data from the data source. */ | ||
perform: DataSourcePerformFunction<TInputs, TDataSourceType>; | ||
/** The type of data that this Data Source represents. */ | ||
dataSourceType: TDataSourceType; | ||
/** InputFields to present in the Prismatic interface for configuration of this Data Source. */ | ||
@@ -16,2 +18,4 @@ inputs: TInputs; | ||
examplePayload?: Awaited<ReturnType<this["perform"]>>; | ||
/** Specifies the name of a Data Source in this Component which can provide additional details about the content for this Data Source, such as example values when selecting particular API object fields. */ | ||
detailDataSource?: string; | ||
} |
@@ -1,3 +0,9 @@ | ||
import { Inputs, DataSourceResult, DataSourceType, ActionInputParameters, ActionContext } from "."; | ||
import { Inputs, DataSourceResult, DataSourceType, ActionInputParameters, ActionLogger, Customer, Instance } from "."; | ||
/** Context provided to perform method containing helpers and contextual data */ | ||
export interface DataSourceContext { | ||
logger: ActionLogger; | ||
customer: Customer; | ||
instance: Instance; | ||
} | ||
/** Definition of the function to perform when a Data Source is invoked. */ | ||
export declare type DataSourcePerformFunction<T extends Inputs, TResult extends DataSourceResult<DataSourceType>> = (context: ActionContext, params: ActionInputParameters<T>) => Promise<TResult>; | ||
export declare type DataSourcePerformFunction<TInputs extends Inputs, TDataSourceType extends DataSourceType> = (context: DataSourceContext, params: ActionInputParameters<TInputs>) => Promise<DataSourceResult<TDataSourceType>>; |
@@ -0,6 +1,30 @@ | ||
import { ConnectionDefinition } from "./ConnectionDefinition"; | ||
import { ObjectSelection, ObjectFieldMap, JSONForm } from "./Inputs"; | ||
/** The type of field that is appropriate for rendering the data that is the result of the data source perform function. */ | ||
declare type DataSourceTypeMap = { | ||
string: string; | ||
date: string; | ||
timestamp: string; | ||
picklist: string[]; | ||
schedule: { | ||
value: string; | ||
}; | ||
code: string; | ||
credential: unknown; | ||
boolean: boolean; | ||
number: number; | ||
connection: ConnectionDefinition; | ||
objectSelection: ObjectSelection; | ||
objectFieldMap: ObjectFieldMap; | ||
jsonForm: JSONForm; | ||
}; | ||
export declare type DataSourceType = keyof DataSourceTypeMap; | ||
export declare type DataSourceResultType = DataSourceTypeMap[DataSourceType]; | ||
/** Represents the result of a Data Source action. */ | ||
export declare type DataSourceResult<ContentData> = { | ||
/** The data that will be used as content. */ | ||
content: ContentData; | ||
/** Additional data that may be useful for out-of-band processing at a later time. */ | ||
export declare type DataSourceResult<TDataSourceType extends DataSourceType> = { | ||
/** The resulting data that is returned from the data source. */ | ||
result: DataSourceTypeMap[TDataSourceType]; | ||
/** Additional data that may be useful for out-of-band processing at a later time. | ||
* NOTE: This is only available when the Data Source is called as part of fetching | ||
* contents for a Configuration Wizard Page. */ | ||
supplementalData?: { | ||
@@ -11,1 +35,2 @@ data: unknown; | ||
}; | ||
export {}; |
@@ -24,2 +24,4 @@ /** | ||
export * from "./DataSourceResult"; | ||
export * from "./DataSourceType"; | ||
export * from "./Instance"; | ||
export * from "./Customer"; | ||
export * as serverTypes from "../serverTypes"; |
@@ -17,6 +17,19 @@ "use strict"; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serverTypes = void 0; | ||
__exportStar(require("./ActionDefinition"), exports); | ||
@@ -41,2 +54,4 @@ __exportStar(require("./ComponentDefinition"), exports); | ||
__exportStar(require("./DataSourceResult"), exports); | ||
__exportStar(require("./DataSourceType"), exports); | ||
__exportStar(require("./Instance"), exports); | ||
__exportStar(require("./Customer"), exports); | ||
exports.serverTypes = __importStar(require("../serverTypes")); |
import { ConditionalExpression } from "./conditional-logic"; | ||
import { ObjectSelection, ObjectFieldMap } from "./DataSourceType"; | ||
export declare type Element = { | ||
key: string; | ||
label?: string; | ||
}; | ||
export declare type ObjectSelection = { | ||
object: Element; | ||
fields?: Element[]; | ||
defaultSelected?: boolean; | ||
}[]; | ||
export declare type ObjectFieldMap = { | ||
fields: { | ||
field: Element; | ||
mappedObject?: Element; | ||
mappedField?: Element; | ||
defaultObject?: Element; | ||
defaultField?: Element; | ||
}[]; | ||
options?: { | ||
object: Element; | ||
fields: Element[]; | ||
}[]; | ||
}; | ||
export declare type JSONForm = { | ||
schema: Record<string, unknown>; | ||
uiSchema: Record<string, unknown>; | ||
data: unknown; | ||
}; | ||
export declare type DynamicObjectSelection = string; | ||
export declare type DynamicFieldSelection = string; | ||
/** InputField type enumeration. */ | ||
@@ -10,3 +38,3 @@ export declare type InputFieldType = InputFieldDefinition["type"]; | ||
}; | ||
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField; | ||
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField | JSONFormInputField | DynamicObjectSelectionInputField | DynamicFieldSelectionInputField; | ||
export declare type InputCleanFunction<TValue, TResult = TValue> = (value: TValue) => TResult; | ||
@@ -140,3 +168,3 @@ interface BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "objectselection"; | ||
type: "objectSelection"; | ||
/** Collection type of the InputField */ | ||
@@ -152,3 +180,3 @@ collection?: InputFieldCollection; | ||
/** Data type the InputField will collect. */ | ||
type: "objectfieldmap"; | ||
type: "objectFieldMap"; | ||
/** Collection type of the InputField */ | ||
@@ -161,2 +189,35 @@ collection?: InputFieldCollection; | ||
} | ||
/** Defines attributes of a JSONFormInputField. */ | ||
export interface JSONFormInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "jsonForm"; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Default value for this field. */ | ||
default?: JSONForm; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
/** Defines attributes of a DynamicObjectSelectionInputField */ | ||
export interface DynamicObjectSelectionInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "dynamicObjectSelection"; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Default value for this field. */ | ||
default?: unknown; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
/** Defines attributes of a SelectedFieldInputField */ | ||
export interface DynamicFieldSelectionInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "dynamicFieldSelection"; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Default value for this field. */ | ||
default?: unknown; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
/** Defines a single Choice option for a InputField. */ | ||
@@ -163,0 +224,0 @@ export interface InputFieldChoice { |
@@ -13,4 +13,7 @@ "use strict"; | ||
connection: undefined, | ||
objectselection: undefined, | ||
objectfieldmap: undefined, | ||
objectSelection: undefined, | ||
objectFieldMap: undefined, | ||
jsonForm: undefined, | ||
dynamicObjectSelection: "", | ||
dynamicFieldSelection: "", | ||
}; |
@@ -0,1 +1,2 @@ | ||
import { Instance, Customer } from "."; | ||
/** Represents a Trigger Payload, which is data passed into a Trigger to invoke an Integration execution. */ | ||
@@ -30,11 +31,6 @@ export interface TriggerPayload { | ||
executionId: string; | ||
customer: { | ||
id: string | null; | ||
externalId: string | null; | ||
name: string | null; | ||
}; | ||
instance: { | ||
id: string | null; | ||
name: string | null; | ||
}; | ||
/** Contains attributes of the Customer for whom an Instance is being executed. */ | ||
customer: Customer; | ||
/** Contains attributes of the Instance that is being executed. */ | ||
instance: Instance; | ||
} |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap } from "./types"; | ||
import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap, JSONForm, ConnectionDefinition } from "./types"; | ||
/** | ||
@@ -35,2 +35,3 @@ * This function returns a lower cased version of the headers passed to it. | ||
toData: (value: unknown) => DataPayload; | ||
isString: (value: unknown) => value is string; | ||
toString: (value: unknown, defaultValue?: string) => string; | ||
@@ -45,2 +46,7 @@ keyValPairListToObject: <TValue = unknown>(kvpList: KeyValuePair<unknown>[], valueConverter?: ((value: unknown) => TValue) | undefined) => Record<string, TValue>; | ||
toObjectFieldMap: (value: unknown) => ObjectFieldMap; | ||
isJSONForm: (value: unknown) => value is JSONForm; | ||
toJSONForm: (value: unknown) => JSONForm; | ||
isPicklist: (value: unknown) => boolean; | ||
isSchedule: (value: unknown) => boolean; | ||
isConnection: (value: unknown) => value is ConnectionDefinition; | ||
}; | ||
@@ -47,0 +53,0 @@ docs: { |
138
dist/util.js
@@ -28,21 +28,7 @@ "use strict"; | ||
const isObjectSelection = (value) => { | ||
if (Array.isArray(value)) { | ||
for (const selection of value) { | ||
if (isObjectWithTruthyKeys(selection, ["key", "fields"])) { | ||
const { fields } = selection; | ||
if (!Array.isArray(fields) || | ||
fields.length === 0 || | ||
!fields.every((field) => isObjectWithTruthyKeys(field, ["key"]))) { | ||
return false; | ||
} | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
if (typeof value === "string" && isJSON(value)) { | ||
return isObjectSelection(JSON.parse(value)); | ||
} | ||
else { | ||
return false; | ||
} | ||
return true; | ||
return (Array.isArray(value) && | ||
value.every((item) => isObjectWithTruthyKeys(item, ["object"]))); | ||
}; | ||
@@ -55,6 +41,9 @@ /** | ||
const toObjectSelection = (value) => { | ||
if (typeof value === "string" && isJSON(value)) { | ||
return toObjectSelection(JSON.parse(value)); | ||
} | ||
if (isObjectSelection(value)) { | ||
return value; | ||
} | ||
throw new Error(`Value '${value}' cannot be coerced to ObjectSelection.`); | ||
throw new Error(`Value '${typeof value === "string" ? value : JSON.stringify(value)}' cannot be coerced to ObjectSelection.`); | ||
}; | ||
@@ -66,19 +55,14 @@ /** | ||
const isObjectFieldMap = (value) => { | ||
if (Array.isArray(value)) { | ||
for (const fieldMap of value) { | ||
if (isObjectWithTruthyKeys(fieldMap, ["key", "value"])) { | ||
const { value: val } = fieldMap; | ||
if (!isObjectWithTruthyKeys(val, ["objectKey", "fieldKey"])) { | ||
return false; | ||
} | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
if (typeof value === "string" && isJSON(value)) { | ||
return isObjectFieldMap(JSON.parse(value)); | ||
} | ||
else { | ||
return false; | ||
if (Boolean(value) && typeof value === "object") { | ||
const { fields } = value; | ||
return (Array.isArray(fields) && | ||
fields.every((item) => isObjectWithTruthyKeys(item, ["field"]) && | ||
isObjectWithTruthyKeys(item === null || item === void 0 ? void 0 : item.field, [ | ||
"key", | ||
]))); | ||
} | ||
return true; | ||
return false; | ||
}; | ||
@@ -91,8 +75,35 @@ /** | ||
const toObjectFieldMap = (value) => { | ||
if (typeof value === "string" && isJSON(value)) { | ||
return toObjectFieldMap(JSON.parse(value)); | ||
} | ||
if (isObjectFieldMap(value)) { | ||
return value; | ||
} | ||
throw new Error(`Value '${value}' cannot be coerced to ObjectFieldMap.`); | ||
throw new Error(`Value '${typeof value === "string" ? value : JSON.stringify(value)}' cannot be coerced to ObjectFieldMap.`); | ||
}; | ||
/** | ||
* @param value The value to test | ||
* @returns This function returns true if the type of `value` is a JSONForm, or false otherwise. | ||
*/ | ||
const isJSONForm = (value) => { | ||
if (typeof value === "string" && isJSON(value)) { | ||
return isJSONForm(JSON.parse(value)); | ||
} | ||
return isObjectWithTruthyKeys(value, ["schema", "uiSchema", "data"]); | ||
}; | ||
/** | ||
* This function coerces a provided value into a JSONForm if possible. | ||
* @param value The value to coerce to JSONForm. | ||
* @returns This function returns the the value as a JSONForm if possible. | ||
*/ | ||
const toJSONForm = (value) => { | ||
if (typeof value === "string" && isJSON(value)) { | ||
return toJSONForm(JSON.parse(value)); | ||
} | ||
if (isJSONForm(value)) { | ||
return value; | ||
} | ||
throw new Error(`Value '${typeof value === "string" ? value : JSON.stringify(value)}' cannot be coerced to JSONForm.`); | ||
}; | ||
/** | ||
* Determine if a variable is a boolean (true or false). | ||
@@ -270,2 +281,21 @@ * | ||
/** | ||
* This function checks if value is a valid picklist. | ||
* | ||
* - `util.types.isPicklist(["value", new String("value")])` will return `true`. | ||
* | ||
* @param value The variable to test. | ||
* @returns This function returns true if `value` is a valid picklist. | ||
*/ | ||
const isPicklist = (value) => Array.isArray(value) && value.every(isString); | ||
/** | ||
* This function checks if value is a valid schedule. | ||
* | ||
* - `util.types.isSchedule({value: "00 00 * * 2,3"})` will return `true`. | ||
* - `util.types.isSchedule({value: "00 00 * * 2,3", scheduleType: "week", timeZone: "America/Chicago"})` will return `true`. | ||
* | ||
* @param value The variable to test. | ||
* @returns This function returns true if `value` is a valid schedule. | ||
*/ | ||
const isSchedule = (value) => isObjectWithTruthyKeys(value, ["value"]); | ||
/** | ||
* This function helps to transform key-value lists to objects. | ||
@@ -364,2 +394,9 @@ * This is useful for transforming inputs that are key-value collections into objects. | ||
/** | ||
* This function checks if value is a string. | ||
* `util.types.isString("value")` and `util.types.isString(new String("value"))` return true. | ||
* @param value The variable to test. | ||
* @returns This function returns true or false, depending on if `value` is a string. | ||
*/ | ||
const isString = (value) => typeof value === "string" || value instanceof String; | ||
/** | ||
* This function converts a `value` to a string. | ||
@@ -378,2 +415,27 @@ * If `value` is undefined or an empty string, an optional `defaultValue` can be returned. | ||
/** | ||
* This function checks if value is a valid connection. | ||
* @param value The variable to test. | ||
* @returns This function returns true or false, depending on if `value` is a valid connection. | ||
*/ | ||
const isConnection = (value) => { | ||
if (typeof value === "string" && isJSON(value)) { | ||
return isConnection(JSON.parse(value)); | ||
} | ||
if (Boolean(value) && typeof value === "object") { | ||
const { inputs } = value; | ||
if (isObjectWithTruthyKeys(value, ["key", "label", "oauth2Type"])) { | ||
return (isObjectWithTruthyKeys(inputs, [ | ||
"authorizeUrl", | ||
"tokenUrl", | ||
"clientId", | ||
"clientSecret", | ||
]) || | ||
isObjectWithTruthyKeys(inputs, ["tokenUrl", "clientId", "clientSecret"])); | ||
} | ||
return (isObjectWithTruthyKeys(value, ["key", "label"]) && | ||
typeof inputs === "object"); | ||
} | ||
return false; | ||
}; | ||
/** | ||
* This function returns true if `value` resembles the shape of JSON, and false otherwise. | ||
@@ -437,2 +499,3 @@ * | ||
toData, | ||
isString, | ||
toString, | ||
@@ -447,2 +510,7 @@ keyValPairListToObject, | ||
toObjectFieldMap, | ||
isJSONForm, | ||
toJSONForm, | ||
isPicklist, | ||
isSchedule, | ||
isConnection, | ||
}, | ||
@@ -449,0 +517,0 @@ docs: { |
{ | ||
"name": "@prismatic-io/spectral", | ||
"version": "7.0.0-pre", | ||
"version": "7.0.0", | ||
"description": "Utility library for building Prismatic components", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
154079
71
3452
0