@prismatic-io/spectral 7.0.12-pre → 7.0.13-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/testing.d.ts CHANGED
@@ -59,6 +59,8 @@ export declare const invokeDataSource: <TInputs extends Inputs, TDataSourceType
59
59
  export declare class ComponentTestHarness<TComponent extends Component> {
60
60
  component: TComponent;
61
61
  constructor(component: TComponent);
62
+ private buildContext;
63
+ private buildParams;
62
64
  connectionValue({ key }: ConnectionDefinition): ConnectionValue;
63
65
  trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>;
64
66
  action(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<ActionPerformReturn>;
package/dist/testing.js CHANGED
@@ -144,6 +144,13 @@ class ComponentTestHarness {
144
144
  constructor(component) {
145
145
  this.component = component;
146
146
  }
147
+ buildContext(context) {
148
+ return Object.assign(Object.assign({}, baseContext), context);
149
+ }
150
+ buildParams(inputs, params) {
151
+ const defaults = inputs.reduce((result, { key, default: defaultValue }) => (Object.assign(Object.assign({}, result), { [key]: `${defaultValue !== null && defaultValue !== void 0 ? defaultValue : ""}` })), {});
152
+ return Object.assign(Object.assign({}, defaults), params);
153
+ }
147
154
  connectionValue({ key }) {
148
155
  const { PRISMATIC_CONNECTION_VALUE: value } = process.env;
149
156
  if (!value) {
@@ -154,22 +161,20 @@ class ComponentTestHarness {
154
161
  }
155
162
  trigger(key, payload, params, context) {
156
163
  return __awaiter(this, void 0, void 0, function* () {
157
- const realizedContext = Object.assign(Object.assign({}, baseContext), context);
158
164
  const trigger = this.component.triggers[key];
159
- return trigger.perform(realizedContext, Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), Object.assign({}, params));
165
+ return trigger.perform(this.buildContext(context), Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), this.buildParams(trigger.inputs, params));
160
166
  });
161
167
  }
162
168
  action(key, params, context) {
163
169
  return __awaiter(this, void 0, void 0, function* () {
164
- const realizedContext = Object.assign(Object.assign({}, baseContext), context);
165
170
  const action = this.component.actions[key];
166
- return action.perform(realizedContext, Object.assign({}, params));
171
+ return action.perform(this.buildContext(context), this.buildParams(action.inputs, params));
167
172
  });
168
173
  }
169
174
  dataSource(key, params) {
170
175
  return __awaiter(this, void 0, void 0, function* () {
171
176
  const dataSource = this.component.dataSources[key];
172
- return dataSource.perform(Object.assign({}, params));
177
+ return dataSource.perform(this.buildParams(dataSource.inputs, params));
173
178
  });
174
179
  }
175
180
  }
@@ -16,7 +16,7 @@ export declare type ObjectFieldMap = {
16
16
  defaultObject?: Element;
17
17
  defaultField?: Element;
18
18
  }[];
19
- options: {
19
+ options?: {
20
20
  object: Element;
21
21
  fields: Element[];
22
22
  }[];
package/dist/util.js CHANGED
@@ -25,25 +25,11 @@ const isObjectWithTruthyKeys = (value, keys) => {
25
25
  * @returns This function returns true if the type of `value` is an ObjectSelection, or false otherwise.
26
26
  */
27
27
  const isObjectSelection = (value) => {
28
- if (Array.isArray(value)) {
29
- for (const selection of value) {
30
- if (isObjectWithTruthyKeys(selection, ["key"])) {
31
- const { fields } = selection;
32
- if (Array.isArray(fields) &&
33
- fields.length > 0 &&
34
- !fields.every((field) => isObjectWithTruthyKeys(field, ["key"]))) {
35
- return false;
36
- }
37
- }
38
- else {
39
- return false;
40
- }
41
- }
42
- }
43
- else {
44
- return false;
28
+ if (typeof value === "string" && isJSON(value)) {
29
+ return isObjectSelection(JSON.parse(value));
45
30
  }
46
- return true;
31
+ return (Array.isArray(value) &&
32
+ value.every((item) => isObjectWithTruthyKeys(item, ["object"])));
47
33
  };
48
34
  /**
49
35
  * This function coerces a provided value into an ObjectSelection if possible.
@@ -51,33 +37,31 @@ const isObjectSelection = (value) => {
51
37
  * @returns This function returns the the value as an ObjectSelection if possible.
52
38
  */
53
39
  const toObjectSelection = (value) => {
40
+ if (typeof value === "string" && isJSON(value)) {
41
+ return toObjectSelection(JSON.parse(value));
42
+ }
54
43
  if (isObjectSelection(value)) {
55
44
  return value;
56
45
  }
57
- throw new Error(`Value '${value}' cannot be coerced to ObjectSelection.`);
46
+ throw new Error(`Value '${typeof value === "string" ? value : JSON.stringify(value)}' cannot be coerced to ObjectSelection.`);
58
47
  };
59
48
  /**
60
49
  * @param value The value to test
61
50
  * @returns This function returns true if the type of `value` is an ObjectFieldMap, or false otherwise.
62
51
  */
63
52
  const isObjectFieldMap = (value) => {
64
- if (Array.isArray(value)) {
65
- for (const fieldMap of value) {
66
- if (isObjectWithTruthyKeys(fieldMap, ["key", "value"])) {
67
- const { value: val } = fieldMap;
68
- if (!isObjectWithTruthyKeys(val, ["objectKey", "fieldKey"])) {
69
- return false;
70
- }
71
- }
72
- else {
73
- return false;
74
- }
75
- }
53
+ if (typeof value === "string" && isJSON(value)) {
54
+ return isObjectFieldMap(JSON.parse(value));
76
55
  }
77
- else {
78
- return false;
56
+ if (Boolean(value) && typeof value === "object") {
57
+ const { fields } = value;
58
+ return (Array.isArray(fields) &&
59
+ fields.every((item) => isObjectWithTruthyKeys(item, ["field"]) &&
60
+ isObjectWithTruthyKeys(item === null || item === void 0 ? void 0 : item.field, [
61
+ "key",
62
+ ])));
79
63
  }
80
- return true;
64
+ return false;
81
65
  };
82
66
  /**
83
67
  * This function coerces a provided value into an ObjectFieldMap if possible.
@@ -85,16 +69,22 @@ const isObjectFieldMap = (value) => {
85
69
  * @returns This function returns the the value as an ObjectFieldMap if possible.
86
70
  */
87
71
  const toObjectFieldMap = (value) => {
72
+ if (typeof value === "string" && isJSON(value)) {
73
+ return toObjectFieldMap(JSON.parse(value));
74
+ }
88
75
  if (isObjectFieldMap(value)) {
89
76
  return value;
90
77
  }
91
- throw new Error(`Value '${value}' cannot be coerced to ObjectFieldMap.`);
78
+ throw new Error(`Value '${typeof value === "string" ? value : JSON.stringify(value)}' cannot be coerced to ObjectFieldMap.`);
92
79
  };
93
80
  /**
94
81
  * @param value The value to test
95
82
  * @returns This function returns true if the type of `value` is a JSONForm, or false otherwise.
96
83
  */
97
84
  const isJSONForm = (value) => {
85
+ if (typeof value === "string" && isJSON(value)) {
86
+ return isJSONForm(JSON.parse(value));
87
+ }
98
88
  return isObjectWithTruthyKeys(value, ["schema", "uiSchema", "data"]);
99
89
  };
100
90
  /**
@@ -103,10 +93,13 @@ const isJSONForm = (value) => {
103
93
  * @returns This function returns the the value as a JSONForm if possible.
104
94
  */
105
95
  const toJSONForm = (value) => {
96
+ if (typeof value === "string" && isJSON(value)) {
97
+ return toJSONForm(JSON.parse(value));
98
+ }
106
99
  if (isJSONForm(value)) {
107
100
  return value;
108
101
  }
109
- throw new Error(`Value '${value}' cannot be coerced to JSONForm.`);
102
+ throw new Error(`Value '${typeof value === "string" ? value : JSON.stringify(value)}' cannot be coerced to JSONForm.`);
110
103
  };
111
104
  /**
112
105
  * Determine if a variable is a boolean (true or false).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "7.0.12-pre",
3
+ "version": "7.0.13-pre",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"