@prismatic-io/spectral
Advanced tools
Comparing version 7.0.12-pre to 7.0.13-pre
@@ -62,2 +62,4 @@ /** | ||
constructor(component: TComponent); | ||
private buildContext; | ||
private buildParams; | ||
connectionValue({ key }: ConnectionDefinition): ConnectionValue; | ||
@@ -64,0 +66,0 @@ trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>; |
@@ -147,2 +147,9 @@ "use strict"; | ||
} | ||
buildContext(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 }) { | ||
@@ -158,5 +165,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(context), Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), this.buildParams(trigger.inputs, params)); | ||
}); | ||
@@ -166,5 +172,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(context), this.buildParams(action.inputs, params)); | ||
}); | ||
@@ -175,3 +180,3 @@ } | ||
const dataSource = this.component.dataSources[key]; | ||
return dataSource.perform(Object.assign({}, params)); | ||
return dataSource.perform(this.buildParams(dataSource.inputs, params)); | ||
}); | ||
@@ -178,0 +183,0 @@ } |
@@ -19,3 +19,3 @@ import { ConditionalExpression } from "./conditional-logic"; | ||
}[]; | ||
options: { | ||
options?: { | ||
object: Element; | ||
@@ -22,0 +22,0 @@ fields: Element[]; |
@@ -28,21 +28,7 @@ "use strict"; | ||
const isObjectSelection = (value) => { | ||
if (Array.isArray(value)) { | ||
for (const selection of value) { | ||
if (isObjectWithTruthyKeys(selection, ["key"])) { | ||
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,6 +75,9 @@ /** | ||
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.`); | ||
}; | ||
@@ -102,2 +89,5 @@ /** | ||
const isJSONForm = (value) => { | ||
if (typeof value === "string" && isJSON(value)) { | ||
return isJSONForm(JSON.parse(value)); | ||
} | ||
return isObjectWithTruthyKeys(value, ["schema", "uiSchema", "data"]); | ||
@@ -111,6 +101,9 @@ }; | ||
const toJSONForm = (value) => { | ||
if (typeof value === "string" && isJSON(value)) { | ||
return toJSONForm(JSON.parse(value)); | ||
} | ||
if (isJSONForm(value)) { | ||
return value; | ||
} | ||
throw new Error(`Value '${value}' cannot be coerced to JSONForm.`); | ||
throw new Error(`Value '${typeof value === "string" ? value : JSON.stringify(value)}' cannot be coerced to JSONForm.`); | ||
}; | ||
@@ -117,0 +110,0 @@ /** |
{ | ||
"name": "@prismatic-io/spectral", | ||
"version": "7.0.12-pre", | ||
"version": "7.0.13-pre", | ||
"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
150823