@prismatic-io/spectral 10.5.1 → 10.5.3

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,8 +1,16 @@
1
- import { InputFieldDefinition, ComponentDefinition, ConnectionDefinition, TriggerDefinition, ComponentHooks, ConfigVarResultCollection, OnPremConnectionInput, TriggerPayload, ConnectionTemplateInputField } from "../types";
1
+ import { InputFieldDefinition, ComponentDefinition, ConnectionDefinition, TriggerDefinition, ComponentHooks, ConfigVarResultCollection, OnPremConnectionInput, TriggerPayload, ConnectionTemplateInputField, ConnectionInput } from "../types";
2
2
  import { Component as ServerComponent, Connection as ServerConnection, Trigger as ServerTrigger, Input as ServerInput } from ".";
3
3
  import { PollingTriggerDefinition } from "../types/PollingTriggerDefinition";
4
4
  export declare const convertInput: (key: string, { default: defaultValue, type, label, collection, ...rest }: InputFieldDefinition | OnPremConnectionInput) => ServerInput;
5
- export declare const convertTemplateInput: (key: string, { templateValue, label, ...rest }: ConnectionTemplateInputField) => ServerInput;
5
+ export declare const _isValidTemplateValue: (template: string, inputs: {
6
+ [key: string]: ConnectionInput | ConnectionTemplateInputField;
7
+ }) => {
8
+ isValid: boolean;
9
+ error?: string;
10
+ };
11
+ export declare const convertTemplateInput: (key: string, { templateValue, label, ...rest }: ConnectionTemplateInputField, inputs: {
12
+ [key: string]: ConnectionInput | ConnectionTemplateInputField;
13
+ }) => ServerInput;
6
14
  export declare const convertTrigger: (triggerKey: string, trigger: TriggerDefinition<any> | PollingTriggerDefinition<any, ConfigVarResultCollection, TriggerPayload, boolean, any, any>, hooks?: ComponentHooks) => ServerTrigger;
7
15
  export declare const convertConnection: ({ inputs, ...connection }: ConnectionDefinition) => ServerConnection;
8
16
  export declare const convertComponent: <TPublic extends boolean, TKey extends string>({ connections, actions, triggers, dataSources, hooks, ...definition }: ComponentDefinition<TPublic, TKey>) => ServerComponent;
@@ -14,7 +14,7 @@ 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.convertInput = void 0;
17
+ exports.convertComponent = exports.convertConnection = exports.convertTrigger = exports.convertTemplateInput = exports._isValidTemplateValue = exports.convertInput = void 0;
18
18
  const types_1 = require("../types");
19
19
  const perform_1 = require("./perform");
20
20
  const omit_1 = __importDefault(require("lodash/omit"));
@@ -31,8 +31,42 @@ const convertInput = (key, _a) => {
31
31
  type, default: defaultValue !== null && defaultValue !== void 0 ? defaultValue : types_1.InputFieldDefaultMap[type], collection, label: typeof label === "string" ? label : label.value, keyLabel, onPremiseControlled: ("onPremControlled" in rest && rest.onPremControlled) || undefined });
32
32
  };
33
33
  exports.convertInput = convertInput;
34
- const convertTemplateInput = (key, _a) => {
34
+ const TEMPLATE_VALUE_REGEX = /{{#(\w+)}}/g;
35
+ const TEMPLATE_VALUE_ERRORS = {
36
+ NO_SLOTS: "No template slots were found. Declare a template slot with this notation: {{#someInputKey}}",
37
+ INVALID_KEYS: "Invalid keys were found in the template string. All referenced keys must be non-template inputs declared in the first argument:",
38
+ };
39
+ const _isValidTemplateValue = (template, inputs) => {
40
+ const matches = [...template.matchAll(TEMPLATE_VALUE_REGEX)];
41
+ if (matches.length === 0) {
42
+ return {
43
+ isValid: false,
44
+ error: TEMPLATE_VALUE_ERRORS.NO_SLOTS,
45
+ };
46
+ }
47
+ const invalidKeys = [];
48
+ for (const [_substr, key] of matches) {
49
+ if (!inputs[key] || inputs[key].type === "template") {
50
+ invalidKeys.push(key);
51
+ }
52
+ }
53
+ if (invalidKeys.length > 0) {
54
+ return {
55
+ isValid: false,
56
+ error: `${TEMPLATE_VALUE_ERRORS.INVALID_KEYS} ${invalidKeys}`,
57
+ };
58
+ }
59
+ return {
60
+ isValid: true,
61
+ };
62
+ };
63
+ exports._isValidTemplateValue = _isValidTemplateValue;
64
+ const convertTemplateInput = (key, _a, inputs) => {
35
65
  var { templateValue, label } = _a, rest = __rest(_a, ["templateValue", "label"]);
66
+ const validation = (0, exports._isValidTemplateValue)(templateValue, inputs);
67
+ if (!validation.isValid) {
68
+ throw `Template input "${key}": ${validation.error}`;
69
+ }
36
70
  return Object.assign(Object.assign({}, (0, omit_1.default)(rest, ["permissionAndVisibilityType", "visibleToOrgDeployer", "writeOnly"])), { key, type: "template", default: templateValue !== null && templateValue !== void 0 ? templateValue : "", label: typeof label === "string" ? label : label.value, shown: false });
37
71
  };
38
72
  exports.convertTemplateInput = convertTemplateInput;
@@ -122,7 +156,7 @@ const convertConnection = (_a) => {
122
156
  const { display: { label, icons, description: comments } } = connection, remaining = __rest(connection, ["display"]);
123
157
  const convertedInputs = Object.entries(inputs).map(([key, value]) => {
124
158
  if ("templateValue" in value) {
125
- return (0, exports.convertTemplateInput)(key, value);
159
+ return (0, exports.convertTemplateInput)(key, value, inputs);
126
160
  }
127
161
  return (0, exports.convertInput)(key, value);
128
162
  });
@@ -1,4 +1,4 @@
1
- import { ValidationMode } from "@jsonforms/core";
1
+ import { ValidationMode } from "./jsonforms/ValidationMode";
2
2
  import { type DataSourceDefinition, type ConnectionDefinition, type Inputs, type DataSourceType, type Connection, type JSONForm, type ObjectFieldMap, type ObjectSelection, type ConfigVarResultCollection, type Schedule, type CollectionDataSourceType, type DataSourceReference, type ConfigPage, type ConfigPages, type ConfigPageElement, type ComponentRegistryDataSource, type ComponentRegistryConnection, type UserLevelConfigPages, type OrganizationActivatedConnectionConfigVar, type ScopedConfigVarMap } from ".";
3
3
  import type { Prettify, UnionToIntersection } from "./utils";
4
4
  /** Supported data types for config variables. */
@@ -1,5 +1,6 @@
1
1
  import { ConditionalExpression } from "./conditional-logic";
2
- import { JsonSchema, UISchemaElement } from "@jsonforms/core";
2
+ import { JsonSchema } from "./jsonforms/JsonSchema";
3
+ import { UISchemaElement } from "./jsonforms/UISchemaElement";
3
4
  /**
4
5
  * KeyValuePair input parameter type.
5
6
  * This allows users to input multiple keys / values as an input.
@@ -0,0 +1,231 @@
1
+ export type JsonSchema = JsonSchema4 | JsonSchema7;
2
+ interface JsonSchema4 {
3
+ $ref?: string;
4
+ /**
5
+ * This is important because it tells refs where
6
+ * the root of the document is located
7
+ */
8
+ id?: string;
9
+ /**
10
+ * It is recommended that the meta-schema is
11
+ * included in the root of any JSON Schema
12
+ */
13
+ $schema?: string;
14
+ /**
15
+ * Title of the schema
16
+ */
17
+ title?: string;
18
+ /**
19
+ * Schema description
20
+ */
21
+ description?: string;
22
+ /**
23
+ * Default json for the object represented by
24
+ * this schema
25
+ */
26
+ default?: any;
27
+ /**
28
+ * The value must be a multiple of the number
29
+ * (e.g. 10 is a multiple of 5)
30
+ */
31
+ multipleOf?: number;
32
+ maximum?: number;
33
+ /**
34
+ * If true maximum must be > value, >= otherwise
35
+ */
36
+ exclusiveMaximum?: boolean;
37
+ minimum?: number;
38
+ /**
39
+ * If true minimum must be < value, <= otherwise
40
+ */
41
+ exclusiveMinimum?: boolean;
42
+ maxLength?: number;
43
+ minLength?: number;
44
+ /**
45
+ * This is a regex string that the value must
46
+ * conform to
47
+ */
48
+ pattern?: string;
49
+ additionalItems?: boolean | JsonSchema4;
50
+ items?: JsonSchema4 | JsonSchema4[];
51
+ maxItems?: number;
52
+ minItems?: number;
53
+ uniqueItems?: boolean;
54
+ maxProperties?: number;
55
+ minProperties?: number;
56
+ required?: string[];
57
+ additionalProperties?: boolean | JsonSchema4;
58
+ /**
59
+ * Holds simple JSON Schema definitions for
60
+ * referencing from elsewhere.
61
+ */
62
+ definitions?: {
63
+ [key: string]: JsonSchema4;
64
+ };
65
+ /**
66
+ * The keys that can exist on the object with the
67
+ * json schema that should validate their value
68
+ */
69
+ properties?: {
70
+ [property: string]: JsonSchema4;
71
+ };
72
+ /**
73
+ * The key of this object is a regex for which
74
+ * properties the schema applies to
75
+ */
76
+ patternProperties?: {
77
+ [pattern: string]: JsonSchema4;
78
+ };
79
+ /**
80
+ * If the key is present as a property then the
81
+ * string of properties must also be present.
82
+ * If the value is a JSON Schema then it must
83
+ * also be valid for the object if the key is
84
+ * present.
85
+ */
86
+ dependencies?: {
87
+ [key: string]: JsonSchema4 | string[];
88
+ };
89
+ /**
90
+ * Enumerates the values that this schema can be
91
+ * e.g.
92
+ * {"type": "string",
93
+ * "enum": ["red", "green", "blue"]}
94
+ */
95
+ enum?: any[];
96
+ /**
97
+ * The basic type of this schema, can be one of
98
+ * [string, number, object, array, boolean, null]
99
+ * or an array of the acceptable types
100
+ */
101
+ type?: string | string[];
102
+ allOf?: JsonSchema4[];
103
+ anyOf?: JsonSchema4[];
104
+ oneOf?: JsonSchema4[];
105
+ /**
106
+ * The entity being validated must not match this schema
107
+ */
108
+ not?: JsonSchema4;
109
+ format?: string;
110
+ const?: any;
111
+ }
112
+ interface JsonSchema7 {
113
+ $ref?: string;
114
+ /**
115
+ * This is important because it tells refs where
116
+ * the root of the document is located
117
+ */
118
+ $id?: string;
119
+ /**
120
+ * It is recommended that the meta-schema is
121
+ * included in the root of any JSON Schema
122
+ */
123
+ $schema?: string;
124
+ /**
125
+ * Title of the schema
126
+ */
127
+ title?: string;
128
+ /**
129
+ * Schema description
130
+ */
131
+ description?: string;
132
+ /**
133
+ * Default json for the object represented by
134
+ * this schema
135
+ */
136
+ default?: any;
137
+ /**
138
+ * The value must be a multiple of the number
139
+ * (e.g. 10 is a multiple of 5)
140
+ */
141
+ multipleOf?: number;
142
+ maximum?: number;
143
+ /**
144
+ * If true maximum must be > value, >= otherwise
145
+ */
146
+ exclusiveMaximum?: number;
147
+ minimum?: number;
148
+ /**
149
+ * If true minimum must be < value, <= otherwise
150
+ */
151
+ exclusiveMinimum?: number;
152
+ maxLength?: number;
153
+ minLength?: number;
154
+ /**
155
+ * This is a regex string that the value must
156
+ * conform to
157
+ */
158
+ pattern?: string;
159
+ additionalItems?: boolean | JsonSchema7;
160
+ items?: JsonSchema7 | JsonSchema7[];
161
+ maxItems?: number;
162
+ minItems?: number;
163
+ uniqueItems?: boolean;
164
+ maxProperties?: number;
165
+ minProperties?: number;
166
+ required?: string[];
167
+ additionalProperties?: boolean | JsonSchema7;
168
+ /**
169
+ * Holds simple JSON Schema definitions for
170
+ * referencing from elsewhere.
171
+ */
172
+ definitions?: {
173
+ [key: string]: JsonSchema7;
174
+ };
175
+ /**
176
+ * The keys that can exist on the object with the
177
+ * json schema that should validate their value
178
+ */
179
+ properties?: {
180
+ [property: string]: JsonSchema7;
181
+ };
182
+ /**
183
+ * The key of this object is a regex for which
184
+ * properties the schema applies to
185
+ */
186
+ patternProperties?: {
187
+ [pattern: string]: JsonSchema7;
188
+ };
189
+ /**
190
+ * If the key is present as a property then the
191
+ * string of properties must also be present.
192
+ * If the value is a JSON Schema then it must
193
+ * also be valid for the object if the key is
194
+ * present.
195
+ */
196
+ dependencies?: {
197
+ [key: string]: JsonSchema7 | string[];
198
+ };
199
+ /**
200
+ * Enumerates the values that this schema can be
201
+ * e.g.
202
+ * {"type": "string",
203
+ * "enum": ["red", "green", "blue"]}
204
+ */
205
+ enum?: any[];
206
+ /**
207
+ * The basic type of this schema, can be one of
208
+ * [string, number, object, array, boolean, null]
209
+ * or an array of the acceptable types
210
+ */
211
+ type?: string | string[];
212
+ allOf?: JsonSchema7[];
213
+ anyOf?: JsonSchema7[];
214
+ oneOf?: JsonSchema7[];
215
+ /**
216
+ * The entity being validated must not match this schema
217
+ */
218
+ not?: JsonSchema7;
219
+ format?: string;
220
+ readOnly?: boolean;
221
+ writeOnly?: boolean;
222
+ examples?: any[];
223
+ contains?: JsonSchema7;
224
+ propertyNames?: JsonSchema7;
225
+ const?: any;
226
+ if?: JsonSchema7;
227
+ then?: JsonSchema7;
228
+ else?: JsonSchema7;
229
+ errorMessage?: any;
230
+ }
231
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Common base interface for any UI schema element.
3
+ */
4
+ export interface UISchemaElement {
5
+ /**
6
+ * The type of this UI schema element.
7
+ */
8
+ type: string;
9
+ /**
10
+ * An optional rule.
11
+ */
12
+ rule?: Rule;
13
+ /**
14
+ * Any additional options.
15
+ */
16
+ options?: {
17
+ [key: string]: any;
18
+ };
19
+ }
20
+ /**
21
+ * A rule that may be attached to any UI schema element.
22
+ */
23
+ interface Rule {
24
+ /**
25
+ * The effect of the rule
26
+ */
27
+ effect: RuleEffect;
28
+ /**
29
+ * The condition of the rule that must evaluate to true in order
30
+ * to trigger the effect.
31
+ */
32
+ condition: Condition;
33
+ }
34
+ /**
35
+ * The different rule effects.
36
+ */
37
+ declare enum RuleEffect {
38
+ /**
39
+ * Effect that hides the associated element.
40
+ */
41
+ HIDE = "HIDE",
42
+ /**
43
+ * Effect that shows the associated element.
44
+ */
45
+ SHOW = "SHOW",
46
+ /**
47
+ * Effect that enables the associated element.
48
+ */
49
+ ENABLE = "ENABLE",
50
+ /**
51
+ * Effect that disables the associated element.
52
+ */
53
+ DISABLE = "DISABLE"
54
+ }
55
+ /**
56
+ * Represents a condition to be evaluated.
57
+ */
58
+ interface Condition {
59
+ /**
60
+ * The type of condition.
61
+ */
62
+ readonly type?: string;
63
+ }
64
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * The different rule effects.
5
+ */
6
+ var RuleEffect;
7
+ (function (RuleEffect) {
8
+ /**
9
+ * Effect that hides the associated element.
10
+ */
11
+ RuleEffect["HIDE"] = "HIDE";
12
+ /**
13
+ * Effect that shows the associated element.
14
+ */
15
+ RuleEffect["SHOW"] = "SHOW";
16
+ /**
17
+ * Effect that enables the associated element.
18
+ */
19
+ RuleEffect["ENABLE"] = "ENABLE";
20
+ /**
21
+ * Effect that disables the associated element.
22
+ */
23
+ RuleEffect["DISABLE"] = "DISABLE";
24
+ })(RuleEffect || (RuleEffect = {}));
@@ -0,0 +1 @@
1
+ export type ValidationMode = "ValidateAndShow" | "ValidateAndHide" | "NoValidation";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "10.5.1",
3
+ "version": "10.5.3",
4
4
  "description": "Utility library for building Prismatic connectors and code-native integrations",
5
5
  "keywords": ["prismatic"],
6
6
  "main": "dist/index.js",
@@ -33,12 +33,10 @@
33
33
  "format": "yarn run lint-fix && biome format --write .",
34
34
  "check-format": "biome format .",
35
35
  "check": "yarn run check-format && yarn run lint",
36
- "test": "jest",
37
- "docs": "rm -f sidebars.{js,jse} && typedoc"
36
+ "test": "jest"
38
37
  },
39
38
  "files": ["dist/"],
40
39
  "dependencies": {
41
- "@jsonforms/core": "3.0.0",
42
40
  "axios": "1.8.3",
43
41
  "axios-retry": "4.5.0",
44
42
  "date-fns": "2.30.0",
@@ -71,9 +69,6 @@
71
69
  "fast-check": "2.16.0",
72
70
  "jest": "29.7.0",
73
71
  "ts-jest": "29.1.2",
74
- "typedoc": "0.17.7",
75
- "typedoc-plugin-markdown": "2.4.2",
76
- "typedoc-plugin-remove-references": "0.0.5",
77
72
  "typescript": "5.5.3"
78
73
  }
79
74
  }