@prismatic-io/spectral 10.18.7-preview.1 → 10.18.7-preview.2

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.
@@ -1,6 +1,12 @@
1
1
  import { type ComponentDefinition, type ComponentHooks, type ConfigVarResultCollection, type ConnectionDefinition, type ConnectionInput, type ConnectionTemplateInputField, type InputFieldDefinition, type Inputs, type OnPremConnectionInput, type TriggerDefinition, type TriggerPayload, type TriggerResult } from "../types";
2
2
  import { type PollingTriggerDefinition } from "../types/PollingTriggerDefinition";
3
3
  import type { Component as ServerComponent, Connection as ServerConnection, Input as ServerInput, Trigger as ServerTrigger } from ".";
4
+ import { type CleanFn } from "./perform";
5
+ /** Auto-generated cleaner for structuredObject/dynamicObject containers.
6
+ * Recursively delegates to each child's clean function. Developers do not
7
+ * declare a top-level clean on these containers — the conversion always
8
+ * supplies one so nested clean functions are applied at runtime. */
9
+ export declare const cleanerFor: (input: InputFieldDefinition) => CleanFn | undefined;
4
10
  export declare const convertInput: (key: string, definition: InputFieldDefinition | OnPremConnectionInput | ConnectionInput) => ServerInput;
5
11
  export declare const _isValidTemplateValue: (template: string, inputs: {
6
12
  [key: string]: ConnectionInput | ConnectionTemplateInputField;
@@ -14,12 +14,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.convertComponent = exports.convertConnection = exports.convertTrigger = exports.convertTemplateInput = exports._isValidTemplateValue = exports.convertInput = void 0;
17
+ exports.convertComponent = exports.convertConnection = exports.convertTrigger = exports.convertTemplateInput = exports._isValidTemplateValue = exports.convertInput = exports.cleanerFor = void 0;
18
18
  const omit_1 = __importDefault(require("lodash/omit"));
19
19
  const types_1 = require("../types");
20
20
  const PollingTriggerDefinition_1 = require("../types/PollingTriggerDefinition");
21
21
  const perform_1 = require("./perform");
22
- const cleanerFor = (input) => "clean" in input ? input.clean : undefined;
22
+ const isPlainObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
23
+ /** Auto-generated cleaner for structuredObject/dynamicObject containers.
24
+ * Recursively delegates to each child's clean function. Developers do not
25
+ * declare a top-level clean on these containers — the conversion always
26
+ * supplies one so nested clean functions are applied at runtime. */
27
+ const cleanerFor = (input) => {
28
+ if (input.type === "structuredObject") {
29
+ const childCleaners = Object.entries(input.inputs).reduce((acc, [childKey, childDef]) => (Object.assign(Object.assign({}, acc), { [childKey]: (0, exports.cleanerFor)(childDef) })), {});
30
+ return (value) => {
31
+ if (!isPlainObject(value)) {
32
+ return value;
33
+ }
34
+ return (0, perform_1.cleanParams)(value, childCleaners);
35
+ };
36
+ }
37
+ if (input.type === "dynamicObject") {
38
+ const configCleaners = {};
39
+ for (const [configKey, configDef] of Object.entries(input.configurations)) {
40
+ configCleaners[configKey] = Object.entries(configDef.inputs).reduce((acc, [childKey, childDef]) => (Object.assign(Object.assign({}, acc), { [childKey]: (0, exports.cleanerFor)(childDef) })), {});
41
+ }
42
+ return (value) => {
43
+ if (!isPlainObject(value)) {
44
+ return value;
45
+ }
46
+ const { configuration, values } = value;
47
+ if (typeof configuration !== "string") {
48
+ return value;
49
+ }
50
+ const cleaners = configCleaners[configuration];
51
+ if (!cleaners) {
52
+ return { configuration, values };
53
+ }
54
+ return {
55
+ configuration,
56
+ values: isPlainObject(values) ? (0, perform_1.cleanParams)(values, cleaners) : values,
57
+ };
58
+ };
59
+ }
60
+ return "clean" in input ? input.clean : undefined;
61
+ };
62
+ exports.cleanerFor = cleanerFor;
23
63
  const convertInput = (key, definition) => {
24
64
  // Cast: the field union is wider than any single member; runtime guards below handle it.
25
65
  const _a = definition, { default: defaultValue, type, label, collection, inputs: childInputs, configurations } = _a, rest = __rest(_a, ["default", "type", "label", "collection", "inputs", "configurations"]);
@@ -86,7 +126,7 @@ exports.convertTemplateInput = convertTemplateInput;
86
126
  const convertAction = (actionKey, _a, hooks) => {
87
127
  var { inputs = {}, perform } = _a, action = __rest(_a, ["inputs", "perform"]);
88
128
  const convertedInputs = Object.entries(inputs).map(([key, value]) => (0, exports.convertInput)(key, value));
89
- const inputCleaners = Object.entries(inputs).reduce((result, [key, value]) => (Object.assign(Object.assign({}, result), { [key]: cleanerFor(value) })), {});
129
+ const inputCleaners = Object.entries(inputs).reduce((result, [key, value]) => (Object.assign(Object.assign({}, result), { [key]: (0, exports.cleanerFor)(value) })), {});
90
130
  return Object.assign(Object.assign({}, action), { key: actionKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
91
131
  inputCleaners,
92
132
  errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
@@ -101,7 +141,7 @@ const convertTrigger = (triggerKey, trigger, hooks) => {
101
141
  const convertedTriggerInputs = Object.entries(inputs).map(([key, value]) => {
102
142
  return (0, exports.convertInput)(key, value);
103
143
  });
104
- const triggerInputCleaners = Object.entries(inputs).reduce((result, [key, value]) => (Object.assign(Object.assign({}, result), { [key]: cleanerFor(value) })), {});
144
+ const triggerInputCleaners = Object.entries(inputs).reduce((result, [key, value]) => (Object.assign(Object.assign({}, result), { [key]: (0, exports.cleanerFor)(value) })), {});
105
145
  let scheduleSupport = "scheduleSupport" in trigger ? trigger.scheduleSupport : "invalid";
106
146
  let convertedActionInputs = [];
107
147
  let performToUse;
@@ -117,7 +157,7 @@ const convertTrigger = (triggerKey, trigger, hooks) => {
117
157
  accum.push((0, exports.convertInput)(key, value));
118
158
  return accum;
119
159
  }, []);
120
- actionInputCleaners = Object.entries(action.inputs).reduce((result, [key, value]) => (Object.assign(Object.assign({}, result), { [key]: cleanerFor(value) })), {});
160
+ actionInputCleaners = Object.entries(action.inputs).reduce((result, [key, value]) => (Object.assign(Object.assign({}, result), { [key]: (0, exports.cleanerFor)(value) })), {});
121
161
  }
122
162
  const combinedCleaners = Object.assign({}, actionInputCleaners, triggerInputCleaners);
123
163
  performToUse = (0, perform_1.createPollingPerform)(trigger, {
@@ -169,7 +209,7 @@ exports.convertTrigger = convertTrigger;
169
209
  const convertDataSource = (dataSourceKey, _a, hooks) => {
170
210
  var { inputs = {}, perform } = _a, dataSource = __rest(_a, ["inputs", "perform"]);
171
211
  const convertedInputs = Object.entries(inputs).map(([key, value]) => (0, exports.convertInput)(key, value));
172
- const inputCleaners = Object.entries(inputs).reduce((result, [key, value]) => (Object.assign(Object.assign({}, result), { [key]: cleanerFor(value) })), {});
212
+ const inputCleaners = Object.entries(inputs).reduce((result, [key, value]) => (Object.assign(Object.assign({}, result), { [key]: (0, exports.cleanerFor)(value) })), {});
173
213
  return Object.assign(Object.assign({}, dataSource), { key: dataSourceKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
174
214
  inputCleaners,
175
215
  errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "10.18.7-preview.1",
3
+ "version": "10.18.7-preview.2",
4
4
  "description": "Utility library for building Prismatic connectors and code-native integrations",
5
5
  "keywords": [
6
6
  "prismatic"