@prismatic-io/spectral
Advanced tools
Comparing version 6.3.0 to 6.4.0
@@ -9,2 +9,3 @@ import { Method, ResponseType } from "axios"; | ||
example: string; | ||
clean: (value: unknown) => string; | ||
}; | ||
@@ -18,2 +19,3 @@ export declare const data: { | ||
example: string; | ||
clean: (value: unknown) => string; | ||
}; | ||
@@ -26,2 +28,3 @@ export declare const timeout: { | ||
example: string; | ||
clean: (value: unknown) => number; | ||
}; | ||
@@ -36,2 +39,3 @@ export declare const method: { | ||
comments: string; | ||
clean: (value: unknown) => string; | ||
}; | ||
@@ -49,2 +53,3 @@ export declare const responseType: { | ||
}[]; | ||
clean: (value: unknown) => string; | ||
}; | ||
@@ -75,2 +80,3 @@ export declare const headers: { | ||
default: string; | ||
clean: (value: unknown) => number; | ||
}; | ||
@@ -91,2 +97,3 @@ export declare const retryDelayMS: { | ||
comments: string; | ||
clean: (value: unknown) => boolean; | ||
}; | ||
@@ -99,2 +106,3 @@ export declare const retryOnAllErrors: { | ||
comments: string; | ||
clean: (value: unknown) => boolean; | ||
}; | ||
@@ -124,2 +132,3 @@ export declare const formData: { | ||
comments: string; | ||
clean: (value: unknown) => boolean; | ||
}; |
@@ -30,2 +30,3 @@ "use strict"; | ||
example: "/sobjects/Account", | ||
clean: (value) => __1.util.types.toString(value), | ||
}); | ||
@@ -39,2 +40,3 @@ exports.data = (0, __1.input)({ | ||
example: '{"exampleKey": "Example Data"}', | ||
clean: (value) => __1.util.types.toString(value), | ||
}); | ||
@@ -47,2 +49,3 @@ exports.timeout = (0, __1.input)({ | ||
example: "2000", | ||
clean: (value) => __1.util.types.toNumber(value), | ||
}); | ||
@@ -54,2 +57,3 @@ exports.method = (0, __1.input)({ | ||
comments: "The HTTP method to use.", | ||
clean: (value) => __1.util.types.toString(value), | ||
}); | ||
@@ -67,2 +71,3 @@ exports.responseType = (0, __1.input)({ | ||
})), | ||
clean: (value) => __1.util.types.toString(value), | ||
}); | ||
@@ -93,2 +98,3 @@ exports.headers = (0, __1.input)({ | ||
default: "0", | ||
clean: (value) => __1.util.types.toNumber(value), | ||
}); | ||
@@ -109,2 +115,3 @@ exports.retryDelayMS = (0, __1.input)({ | ||
comments: "Specifies whether to use a pre-defined exponential backoff strategy for retries.", | ||
clean: (value) => __1.util.types.toBool(value), | ||
}); | ||
@@ -117,2 +124,3 @@ exports.retryOnAllErrors = (0, __1.input)({ | ||
comments: "If true, retries on all erroneous responses regardless of type.", | ||
clean: (value) => __1.util.types.toBool(value), | ||
}); | ||
@@ -142,2 +150,3 @@ exports.formData = (0, __1.input)({ | ||
comments: "Enabling this flag will log out the current request.", | ||
clean: (value) => __1.util.types.toBool(value), | ||
}); |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
@@ -24,38 +15,40 @@ var t = {}; | ||
exports.convertComponent = void 0; | ||
const serialize_error_1 = require("serialize-error"); | ||
const util_1 = require("../util"); | ||
const types_1 = require("../types"); | ||
const wrapPerform = (fn, errorHandler) => { | ||
return (...args) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
return yield fn(...args); | ||
} | ||
catch (error) { | ||
throw new Error((0, util_1.toJSON)((0, serialize_error_1.serializeError)(errorHandler(error)))); | ||
} | ||
}); | ||
}; | ||
const perform_1 = require("./perform"); | ||
const convertInput = (key, _a) => { | ||
var { default: defaultValue, type, label, collection } = _a, rest = __rest(_a, ["default", "type", "label", "collection"]); | ||
return (Object.assign(Object.assign({}, rest), { key, | ||
type, default: defaultValue !== null && defaultValue !== void 0 ? defaultValue : types_1.InputFieldDefaultMap[type], collection, label: typeof label === "string" ? label : label.value, keyLabel: collection === "keyvaluelist" && typeof label === "object" | ||
? label.key | ||
: undefined })); | ||
const keyLabel = collection === "keyvaluelist" && typeof label === "object" | ||
? label.key | ||
: undefined; | ||
return Object.assign(Object.assign({}, rest), { key, | ||
type, default: defaultValue !== null && defaultValue !== void 0 ? defaultValue : types_1.InputFieldDefaultMap[type], collection, label: typeof label === "string" ? label : label.value, keyLabel }); | ||
}; | ||
const convertAction = (actionKey, _a, hooks) => { | ||
var { inputs = {}, perform } = _a, action = __rest(_a, ["inputs", "perform"]); | ||
return (Object.assign(Object.assign({}, action), { key: actionKey, perform: (hooks === null || hooks === void 0 ? void 0 : hooks.error) ? wrapPerform(perform, hooks.error) : perform, inputs: Object.entries(inputs).map(([key, value]) => convertInput(key, value)) })); | ||
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({}, action), { key: actionKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, { | ||
inputCleaners, | ||
errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error, | ||
}) }); | ||
}; | ||
const convertTrigger = (triggerKey, _a, hooks) => { | ||
var { inputs = {}, perform } = _a, trigger = __rest(_a, ["inputs", "perform"]); | ||
return (Object.assign(Object.assign({}, trigger), { key: triggerKey, perform: (hooks === null || hooks === void 0 ? void 0 : hooks.error) ? wrapPerform(perform, hooks.error) : perform, inputs: Object.entries(inputs).map(([key, value]) => convertInput(key, value)) })); | ||
const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value)); | ||
return Object.assign(Object.assign({}, trigger), { key: triggerKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, { | ||
inputCleaners: {}, | ||
errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error, | ||
}) }); | ||
}; | ||
const convertConnection = (connection) => { | ||
var _a; | ||
return (Object.assign(Object.assign({}, connection), { inputs: Object.entries((_a = connection.inputs) !== null && _a !== void 0 ? _a : {}).map(([key, value]) => convertInput(key, value)) })); | ||
const convertConnection = (_a) => { | ||
var { inputs = {} } = _a, connection = __rest(_a, ["inputs"]); | ||
const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value)); | ||
return Object.assign(Object.assign({}, connection), { inputs: convertedInputs }); | ||
}; | ||
const convertComponent = (_a) => { | ||
var { connections = [], actions = {}, triggers = {}, hooks } = _a, definition = __rest(_a, ["connections", "actions", "triggers", "hooks"]); | ||
return (Object.assign(Object.assign({}, definition), { connections: connections.map(convertConnection), actions: Object.entries(actions).reduce((result, [actionKey, action]) => (Object.assign(Object.assign({}, result), { [actionKey]: convertAction(actionKey, action, hooks) })), {}), triggers: Object.entries(triggers).reduce((result, [triggerKey, trigger]) => (Object.assign(Object.assign({}, result), { [triggerKey]: convertTrigger(triggerKey, trigger, hooks) })), {}) })); | ||
const convertedActions = Object.entries(actions).reduce((result, [actionKey, action]) => (Object.assign(Object.assign({}, result), { [actionKey]: convertAction(actionKey, action, hooks) })), {}); | ||
const convertedTriggers = Object.entries(triggers).reduce((result, [triggerKey, trigger]) => (Object.assign(Object.assign({}, result), { [triggerKey]: convertTrigger(triggerKey, trigger, hooks) })), {}); | ||
return Object.assign(Object.assign({}, definition), { connections: connections.map(convertConnection), actions: convertedActions, triggers: convertedTriggers }); | ||
}; | ||
exports.convertComponent = convertComponent; |
@@ -1,2 +0,4 @@ | ||
import { InputFieldDefinition, Inputs, InputFieldTypeMap } from "."; | ||
import { Inputs } from "."; | ||
import { ConditionalExpression } from "./conditional-logic"; | ||
import { InputFieldCollection, InputCleanFunction, Connection } from "./Inputs"; | ||
/** | ||
@@ -8,6 +10,5 @@ * Collection of input parameters. | ||
export declare type ActionInputParameters<TInputs extends Inputs> = { | ||
[Property in keyof TInputs]: ExtractValue<TInputs[Property]>; | ||
[Property in keyof TInputs]: TInputs[Property]["clean"] extends InputCleanFunction<any> ? ReturnType<TInputs[Property]["clean"]> : TInputs[Property]["type"] extends "connection" ? ExtractValue<Connection, TInputs[Property]["collection"]> : TInputs[Property]["type"] extends "conditional" ? ExtractValue<ConditionalExpression, TInputs[Property]["collection"]> : ExtractValue<TInputs[Property]["default"], TInputs[Property]["collection"]>; | ||
}; | ||
export declare type ExtractValue<TValue extends InputFieldDefinition> = MapCollectionValues<InputFieldTypeMap[TValue["type"]], TValue["collection"]>; | ||
export declare type MapCollectionValues<TType, TCollection extends InputFieldDefinition["collection"]> = TCollection extends "keyvaluelist" ? KeyValuePair<TType>[] : TCollection extends "valuelist" ? TType[] : TType; | ||
export declare type ExtractValue<TType, TCollection extends InputFieldCollection | undefined> = TCollection extends "keyvaluelist" ? KeyValuePair<TType>[] : TCollection extends "valuelist" ? TType[] : TType; | ||
/** | ||
@@ -14,0 +15,0 @@ * KeyValuePair input parameter type. |
@@ -15,3 +15,2 @@ /** | ||
export * from "./ActionPerformFunction"; | ||
export * from "./InputFieldType"; | ||
export * from "./conditional-logic"; | ||
@@ -18,0 +17,0 @@ export * from "./TriggerResult"; |
@@ -31,3 +31,2 @@ "use strict"; | ||
__exportStar(require("./ActionPerformFunction"), exports); | ||
__exportStar(require("./InputFieldType"), exports); | ||
__exportStar(require("./conditional-logic"), exports); | ||
@@ -34,0 +33,0 @@ __exportStar(require("./TriggerResult"), exports); |
@@ -1,10 +0,12 @@ | ||
import { InputFieldDefaultMap, InputFieldType } from "."; | ||
import { ConditionalExpression } from "./conditional-logic"; | ||
/** InputField type enumeration. */ | ||
export declare type InputFieldType = InputFieldDefinition["type"]; | ||
export declare const InputFieldDefaultMap: Record<InputFieldType, string | undefined>; | ||
export declare type Inputs = Record<string, InputFieldDefinition>; | ||
export declare type ConnectionInput = DefaultInputFieldDefinition & { | ||
export declare type ConnectionInput = (StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField) & { | ||
shown?: boolean; | ||
}; | ||
export declare type InputFieldDefinition = DefaultInputFieldDefinition | CodeInputFieldDefinition | ConditionalInputField | ConnectionInputField; | ||
interface BaseInputFieldDefinition { | ||
/** Data type the InputField will collect. */ | ||
type: InputFieldType; | ||
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField; | ||
export declare type InputCleanFunction<TValue, TResult = TValue> = (value: TValue) => TResult; | ||
interface BaseInputField { | ||
/** Interface label of the InputField. */ | ||
@@ -15,8 +17,4 @@ label: { | ||
} | string; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Text to show as the InputField placeholder. */ | ||
placeholder?: string; | ||
/** Default value for this field. */ | ||
default?: typeof InputFieldDefaultMap[this["type"]]; | ||
/** Additional text to give guidance to the user configuring the InputField. */ | ||
@@ -29,11 +27,70 @@ comments?: string; | ||
} | ||
/** Defines attributes of a InputField. */ | ||
export interface DefaultInputFieldDefinition extends BaseInputFieldDefinition { | ||
type: Exclude<InputFieldType, "code" | "conditional" | "connection">; | ||
export interface StringInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "string"; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Default value for this field. */ | ||
default?: unknown; | ||
/** Dictates possible choices for the input. */ | ||
model?: InputFieldChoice[]; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
export interface DataInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "data"; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Default value for this field. */ | ||
default?: unknown; | ||
/** Dictates possible choices for the input. */ | ||
model?: InputFieldChoice[]; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
export interface TextInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "text"; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Default value for this field. */ | ||
default?: unknown; | ||
/** Dictates possible choices for the input. */ | ||
model?: InputFieldChoice[]; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
export interface PasswordInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "password"; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Default value for this field. */ | ||
default?: unknown; | ||
/** Dictates possible choices for the input. */ | ||
model?: InputFieldChoice[]; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
export interface BooleanInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "boolean"; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Default value for this field. */ | ||
default?: unknown; | ||
/** Dictates possible choices for the input. */ | ||
model?: InputFieldChoice[]; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
/** Defines attributes of a CodeInputField. */ | ||
export interface CodeInputFieldDefinition extends BaseInputFieldDefinition { | ||
type: Extract<InputFieldType, "code">; | ||
export interface CodeInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "code"; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Default value for this field. */ | ||
default?: unknown; | ||
/** Code language of this field. */ | ||
@@ -43,10 +100,26 @@ language?: string; | ||
model?: InputFieldChoice[]; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
/** Defines attributes of a ConditionalInputField. */ | ||
export interface ConditionalInputField extends BaseInputFieldDefinition { | ||
type: Extract<InputFieldType, "conditional">; | ||
export interface ConditionalInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "conditional"; | ||
/** Collection type of the InputField */ | ||
collection: Extract<InputFieldCollection, "valuelist">; | ||
/** Default value for this field. */ | ||
default?: ConditionalExpression; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
/** Defines attributes of a ConnectionInputField. */ | ||
export interface ConnectionInputField extends BaseInputFieldDefinition { | ||
type: Extract<InputFieldType, "connection">; | ||
export interface ConnectionInputField extends BaseInputField { | ||
/** Data type the InputField will collect. */ | ||
type: "connection"; | ||
/** Collection type of the InputField */ | ||
collection?: InputFieldCollection; | ||
/** Default value for this field. */ | ||
default?: Connection; | ||
/** Clean function */ | ||
clean?: InputCleanFunction<NonNullable<this["default"]>>; | ||
} | ||
@@ -53,0 +126,0 @@ export interface Connection { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InputFieldDefaultMap = void 0; | ||
exports.InputFieldDefaultMap = { | ||
string: "", | ||
data: "", | ||
text: "", | ||
password: "", | ||
boolean: "false", | ||
code: "", | ||
conditional: undefined, | ||
connection: undefined, | ||
}; |
{ | ||
"name": "@prismatic-io/spectral", | ||
"version": "6.3.0", | ||
"version": "6.4.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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
114605
2482
0