@prismatic-io/spectral 9.0.0-rc.7 → 9.0.0-rc.9

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.
@@ -26,26 +26,7 @@ const runMain = (process) => __awaiter(void 0, void 0, void 0, function* () {
26
26
  var _a, _b;
27
27
  const componentDir = process.cwd();
28
28
  const componentDistDir = path_1.default.join(componentDir, "dist", "index.js");
29
- if (!componentDir) {
30
- console.error("Please run this script using npm or yarn.");
31
- process.exit(1);
32
- }
33
- if (!(0, fs_extra_1.existsSync)(componentDistDir)) {
34
- console.error("Component build directory `dist` does not exist. Please verify that the component has been built.");
35
- process.exit(1);
36
- }
37
- const component = require(componentDistDir).default;
38
- if (!component ||
39
- !(0, util_1.isObjectWithTruthyKeys)(component, ["key", "display"]) ||
40
- !(0, util_1.isObjectWithOneTruthyKey)(component, [
41
- "actions",
42
- "connections",
43
- "dataSources",
44
- ])) {
45
- console.error("Component is invalid.");
46
- process.exit(1);
47
- }
48
- const args = process.argv.slice(3);
29
+ const args = process.argv.slice(2);
49
30
  const flags = {
50
31
  name: {
51
32
  flag: ["--name", "-n"],
@@ -111,6 +92,25 @@ const runMain = (process) => __awaiter(void 0, void 0, void 0, function* () {
111
92
  });
112
93
  process.exit(0);
113
94
  }
95
+ if (!componentDir) {
96
+ console.error("Please run this script using npm or yarn.");
97
+ process.exit(1);
98
+ }
99
+ if (!(0, fs_extra_1.existsSync)(componentDistDir)) {
100
+ console.error("Component build directory `dist` does not exist. Please verify that the component has been built.");
101
+ process.exit(1);
102
+ }
103
+ const component = require(componentDistDir).default;
104
+ if (!component ||
105
+ !(0, util_1.isObjectWithTruthyKeys)(component, ["key", "display"]) ||
106
+ !(0, util_1.isObjectWithOneTruthyKey)(component, [
107
+ "actions",
108
+ "connections",
109
+ "dataSources",
110
+ ])) {
111
+ console.error("Component is invalid.");
112
+ process.exit(1);
113
+ }
114
114
  const packageJson = (0, fs_extra_1.readJsonSync)(path_1.default.join(__dirname, "../../../package.json"));
115
115
  yield (0, index_1.createComponentManifest)({
116
116
  component,
@@ -1,4 +1,4 @@
1
- import { Component } from "../../serverTypes";
1
+ import type { Component } from "../../serverTypes";
2
2
  interface CreateActionsProps {
3
3
  component: Component;
4
4
  dryRun: boolean;
@@ -18,11 +18,19 @@ const getInputs_1 = require("./getInputs");
18
18
  const getImports_1 = require("./getImports");
19
19
  const helpers_1 = require("./helpers");
20
20
  const createTemplate_1 = require("../utils/createTemplate");
21
- const DOCUMENT_PROPERTIES = [
22
- "comments",
23
- "default",
24
- "example",
25
- "placeholder",
21
+ const DOC_BLOCK = [
22
+ {
23
+ propertyKey: "comments",
24
+ },
25
+ {
26
+ propertyKey: "default",
27
+ },
28
+ {
29
+ propertyKey: "example",
30
+ },
31
+ {
32
+ propertyKey: "placeholder",
33
+ },
26
34
  ];
27
35
  const createActions = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
28
36
  var _a, _b;
@@ -43,7 +51,7 @@ const createActions = ({ component, dryRun, verbose, sourceDir, destinationDir,
43
51
  const actions = yield Promise.all(Object.entries((_b = component.actions) !== null && _b !== void 0 ? _b : {}).map(([actionKey, action]) => __awaiter(void 0, void 0, void 0, function* () {
44
52
  const inputs = (0, getInputs_1.getInputs)({
45
53
  inputs: action.inputs,
46
- documentProperties: DOCUMENT_PROPERTIES,
54
+ docBlock: DOC_BLOCK,
47
55
  });
48
56
  const imports = (0, getImports_1.getImports)({ inputs });
49
57
  return yield renderAction({
@@ -1,4 +1,4 @@
1
- import { Component } from "../../serverTypes";
1
+ import type { Component } from "../../serverTypes";
2
2
  interface CreateConnectionsProps {
3
3
  component: Component;
4
4
  dryRun: boolean;
@@ -18,11 +18,29 @@ const getInputs_1 = require("./getInputs");
18
18
  const getImports_1 = require("./getImports");
19
19
  const helpers_1 = require("./helpers");
20
20
  const createTemplate_1 = require("../utils/createTemplate");
21
- const DOCUMENT_PROPERTIES = [
22
- "comments",
23
- "default",
24
- "example",
25
- "placeholder",
21
+ const DOC_BLOCK = [
22
+ {
23
+ propertyKey: "comments",
24
+ },
25
+ {
26
+ propertyKey: "default",
27
+ },
28
+ {
29
+ propertyKey: "example",
30
+ },
31
+ {
32
+ propertyKey: "placeholder",
33
+ },
34
+ {
35
+ propertyKey: "onPremControlled",
36
+ propertyValue: true,
37
+ output: "This input will be supplied when using an on prem resource.",
38
+ },
39
+ {
40
+ propertyKey: "onPremiseControlled",
41
+ propertyValue: true,
42
+ output: "This input will be supplied when using an on prem resource.",
43
+ },
26
44
  ];
27
45
  const createConnections = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
28
46
  var _a, _b;
@@ -43,15 +61,17 @@ const createConnections = ({ component, dryRun, verbose, sourceDir, destinationD
43
61
  const connections = yield Promise.all(((_b = component.connections) !== null && _b !== void 0 ? _b : []).map((connection) => __awaiter(void 0, void 0, void 0, function* () {
44
62
  const inputs = (0, getInputs_1.getInputs)({
45
63
  inputs: connection.inputs,
46
- documentProperties: DOCUMENT_PROPERTIES,
64
+ docBlock: DOC_BLOCK,
47
65
  });
48
66
  const imports = (0, getImports_1.getImports)({ inputs });
67
+ const onPremAvailable = connection.inputs.some((input) => input.onPremControlled || input.onPremiseControlled);
49
68
  return yield renderConnection({
50
69
  connection: {
51
70
  key: connection.key,
52
71
  label: connection.label,
53
72
  comments: connection.comments,
54
73
  inputs,
74
+ onPremAvailable,
55
75
  },
56
76
  imports,
57
77
  dryRun,
@@ -1,4 +1,4 @@
1
- import { Component } from "../../serverTypes";
1
+ import type { Component } from "../../serverTypes";
2
2
  interface CreateDataSourcesProps {
3
3
  component: Component;
4
4
  dryRun: boolean;
@@ -18,11 +18,19 @@ const getInputs_1 = require("./getInputs");
18
18
  const getImports_1 = require("./getImports");
19
19
  const helpers_1 = require("./helpers");
20
20
  const createTemplate_1 = require("../utils/createTemplate");
21
- const DOCUMENT_PROPERTIES = [
22
- "comments",
23
- "default",
24
- "example",
25
- "placeholder",
21
+ const DOC_BLOCK = [
22
+ {
23
+ propertyKey: "comments",
24
+ },
25
+ {
26
+ propertyKey: "default",
27
+ },
28
+ {
29
+ propertyKey: "example",
30
+ },
31
+ {
32
+ propertyKey: "placeholder",
33
+ },
26
34
  ];
27
35
  const createDataSources = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
28
36
  var _a, _b;
@@ -43,7 +51,7 @@ const createDataSources = ({ component, dryRun, verbose, sourceDir, destinationD
43
51
  const dataSources = yield Promise.all(Object.entries((_b = component.dataSources) !== null && _b !== void 0 ? _b : {}).map(([dataSourceKey, dataSource]) => __awaiter(void 0, void 0, void 0, function* () {
44
52
  const inputs = (0, getInputs_1.getInputs)({
45
53
  inputs: dataSource.inputs,
46
- documentProperties: DOCUMENT_PROPERTIES,
54
+ docBlock: DOC_BLOCK,
47
55
  });
48
56
  const imports = (0, getImports_1.getImports)({ inputs });
49
57
  return yield renderDataSource({
@@ -1,4 +1,4 @@
1
- import { Component } from "../../serverTypes";
1
+ import type { Component } from "../../serverTypes";
2
2
  export interface PackageDependencies {
3
3
  spectral: string;
4
4
  dependencies: Record<string, string>;
@@ -1,4 +1,4 @@
1
- import { Component } from "../../serverTypes";
1
+ import type { Component } from "../../serverTypes";
2
2
  interface CreateTriggersProps {
3
3
  component: Component;
4
4
  dryRun: boolean;
@@ -18,11 +18,19 @@ const getInputs_1 = require("./getInputs");
18
18
  const getImports_1 = require("./getImports");
19
19
  const helpers_1 = require("./helpers");
20
20
  const createTemplate_1 = require("../utils/createTemplate");
21
- const DOCUMENT_PROPERTIES = [
22
- "comments",
23
- "default",
24
- "example",
25
- "placeholder",
21
+ const DOC_BLOCK = [
22
+ {
23
+ propertyKey: "comments",
24
+ },
25
+ {
26
+ propertyKey: "default",
27
+ },
28
+ {
29
+ propertyKey: "example",
30
+ },
31
+ {
32
+ propertyKey: "placeholder",
33
+ },
26
34
  ];
27
35
  const createTriggers = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
28
36
  var _a, _b;
@@ -43,7 +51,7 @@ const createTriggers = ({ component, dryRun, verbose, sourceDir, destinationDir,
43
51
  const triggers = yield Promise.all(Object.entries((_b = component.triggers) !== null && _b !== void 0 ? _b : {}).map(([triggerKey, trigger]) => __awaiter(void 0, void 0, void 0, function* () {
44
52
  const inputs = (0, getInputs_1.getInputs)({
45
53
  inputs: trigger.inputs,
46
- documentProperties: DOCUMENT_PROPERTIES,
54
+ docBlock: DOC_BLOCK,
47
55
  });
48
56
  const imports = (0, getImports_1.getImports)({ inputs });
49
57
  return yield renderTrigger({
@@ -1,4 +1,4 @@
1
- import { Input } from "./getInputs";
1
+ import type { Input } from "./getInputs";
2
2
  export declare type Imports = Record<string, string[]>;
3
3
  interface GetImportsProps {
4
4
  inputs: Input[];
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getImports = void 0;
4
4
  const getImports = ({ inputs }) => {
5
5
  return inputs.reduce((acc, input) => {
6
- if (typeof input.type === "string") {
6
+ if (typeof input.valueType === "string") {
7
7
  return acc;
8
8
  }
9
- return Object.assign(Object.assign({}, acc), { [input.type.module]: acc[input.type.module]
10
- ? !acc[input.type.module].includes(input.type.type)
11
- ? [...acc[input.type.module], input.type.type]
12
- : acc[input.type.module]
13
- : [input.type.type] });
9
+ return Object.assign(Object.assign({}, acc), { [input.valueType.module]: acc[input.valueType.module]
10
+ ? !acc[input.valueType.module].includes(input.valueType.type)
11
+ ? [...acc[input.valueType.module], input.valueType.type]
12
+ : acc[input.valueType.module]
13
+ : [input.valueType.type] });
14
14
  }, {});
15
15
  };
16
16
  exports.getImports = getImports;
@@ -1,23 +1,33 @@
1
- import { Input as ServerTypeInput } from "../../serverTypes";
2
- import { InputFieldDefinition } from "../../types/Inputs";
1
+ import type { Input as InputBase } from "../../serverTypes";
2
+ import type { InputFieldDefinition } from "../../types/Inputs";
3
+ declare type ServerTypeInput = InputBase & {
4
+ onPremControlled?: boolean;
5
+ };
3
6
  export interface Input {
4
7
  key: string;
5
8
  label: string;
6
- type: InputType;
9
+ inputType: string;
10
+ valueType: ValueType;
7
11
  required: boolean | undefined;
8
12
  properties: {
9
13
  key: keyof ServerTypeInput;
10
14
  value: string;
11
15
  }[];
12
16
  }
13
- export declare type InputType = string | {
17
+ export declare type ValueType = string | {
14
18
  type: string;
15
19
  module: string;
16
20
  };
21
+ export declare type DocBlock = {
22
+ inputKey?: string;
23
+ propertyKey: keyof ServerTypeInput;
24
+ propertyValue?: unknown;
25
+ output?: string;
26
+ }[];
17
27
  interface GetInputsProps {
18
28
  inputs: ServerTypeInput[];
19
- documentProperties: (keyof ServerTypeInput)[];
29
+ docBlock: DocBlock;
20
30
  }
21
- export declare const getInputs: ({ inputs, documentProperties, }: GetInputsProps) => Input[];
22
- export declare const INPUT_TYPE_MAP: Record<InputFieldDefinition["type"], InputType>;
31
+ export declare const getInputs: ({ inputs, docBlock }: GetInputsProps) => Input[];
32
+ export declare const INPUT_TYPE_MAP: Record<InputFieldDefinition["type"], ValueType>;
23
33
  export {};
@@ -1,29 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.INPUT_TYPE_MAP = exports.getInputs = void 0;
4
- const getInputs = ({ inputs, documentProperties, }) => {
4
+ const getInputs = ({ inputs, docBlock }) => {
5
5
  return inputs.map((input) => {
6
6
  return {
7
7
  key: input.key,
8
8
  label: input.label,
9
- type: getInputType(input),
9
+ inputType: input.type,
10
+ valueType: getInputValueType(input),
10
11
  required: input.required,
11
12
  collection: input.collection,
12
- inputType: input.type,
13
- properties: documentProperties.reduce((acc, key) => {
14
- const value = input[key]
15
- ? JSON.stringify(input[key])
16
- .replace(/(^"|"$)|(^'|'$)/g, "")
17
- .trim()
18
- : null;
19
- if (typeof value === "undefined" || value === null || value === "") {
13
+ onPremControlled: input.onPremiseControlled || input.onPremControlled,
14
+ properties: docBlock.reduce((acc, { propertyKey, inputKey, propertyValue, output }) => {
15
+ if (inputKey && inputKey !== input.key) {
16
+ return acc;
17
+ }
18
+ if (output &&
19
+ (input[propertyKey] === propertyValue ||
20
+ typeof propertyValue === "undefined")) {
21
+ return [
22
+ ...acc,
23
+ {
24
+ key: propertyKey,
25
+ value: output,
26
+ },
27
+ ];
28
+ }
29
+ if (typeof input[propertyKey] === "undefined" ||
30
+ input[propertyKey] === null ||
31
+ input[propertyKey] === "" ||
32
+ (typeof propertyValue !== "undefined" &&
33
+ input[propertyKey] !== propertyValue)) {
20
34
  return acc;
21
35
  }
22
36
  return [
23
37
  ...acc,
24
38
  {
25
- key,
26
- value,
39
+ key: propertyKey,
40
+ value: JSON.stringify(input[propertyKey])
41
+ .replace(/(^"|"$)|(^'|'$)/g, "")
42
+ .trim(),
27
43
  },
28
44
  ];
29
45
  }, []),
@@ -61,12 +77,12 @@ exports.INPUT_TYPE_MAP = {
61
77
  dynamicObjectSelection: "string",
62
78
  dynamicFieldSelection: "string",
63
79
  };
64
- const getInputType = (input) => {
80
+ const getInputValueType = (input) => {
65
81
  const valueType = input.model
66
82
  ? input.model.map((choice) => `"${choice.value}"`).join(" | ")
67
83
  : exports.INPUT_TYPE_MAP[input.type] || "never";
68
84
  if (input.collection === "keyvaluelist") {
69
- return `Record<string, ${valueType}>`;
85
+ return `Record<string, ${valueType}> | Array<{key: string, value: ${valueType}}>`;
70
86
  }
71
87
  if (input.collection === "valuelist") {
72
88
  return `${valueType}[]`;
@@ -1,5 +1,5 @@
1
- import { PackageDependencies } from "./createStaticFiles";
2
- import { Component } from "../../serverTypes";
1
+ import { type PackageDependencies } from "./createStaticFiles";
2
+ import type { Component } from "../../serverTypes";
3
3
  interface CreateComponentManifestProps {
4
4
  component: Component;
5
5
  dryRun: boolean;
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeComponentManifest = void 0;
4
- const fs_extra_1 = require("fs-extra");
4
+ const fs_1 = require("fs");
5
5
  const removeComponentManifest = ({ destinationDir, verbose, }) => {
6
6
  if (verbose) {
7
7
  console.info("Removing existing component manifest files...");
8
8
  }
9
9
  try {
10
- (0, fs_extra_1.removeSync)(destinationDir);
10
+ if ((0, fs_1.existsSync)(destinationDir)) {
11
+ (0, fs_1.rmSync)(destinationDir, { recursive: true, force: true });
12
+ }
11
13
  }
12
14
  catch (err) {
13
15
  console.error(err);
@@ -13,6 +13,9 @@ export const <%= connection.key %> = {
13
13
  perform: (
14
14
  _values: <%= helpers.capitalizeFirstLetter(connection.key) %>Values
15
15
  ): Promise<void> => Promise.resolve(),
16
+ <%_ if (connection.onPremAvailable) { -%>
17
+ onPremAvailable: true,
18
+ <%_ } -%>
16
19
  inputs: {
17
20
  <%- include('../partials/inputs.ejs', { inputs: connection.inputs }) -%>
18
21
  }
@@ -1,6 +1,7 @@
1
1
  <% inputs.forEach((input) => { -%>
2
2
  <%= input.key %>: {
3
- inputType: "<%= input.defaultType %>",
3
+ valueType: "<%- input.valueType.type ? input.valueType.type : input.valueType %>",
4
+ inputType: "<%= input.inputType %>",
4
5
  <%_ if (input.collection) { -%>
5
6
  collection: "<%= input.collection %>" as const,
6
7
  <%_ } else { -%>
@@ -12,8 +13,8 @@
12
13
  <%_ if (input.required) { -%>
13
14
  required: <%= input.required %>,
14
15
  <%_ } -%>
15
- <%_ if (typeof input.onPremiseControlled !== "undefined") { -%>
16
- onPremiseControlled: <%= input.onPremiseControlled %>,
16
+ <%_ if (typeof input.onPremControlled !== "undefined") { -%>
17
+ onPremControlled: <%= input.onPremControlled %>,
17
18
  <%_ } -%>
18
19
  },
19
20
  <% }); -%>
@@ -6,5 +6,5 @@
6
6
  * @<%= property.key %> <%- property.value %>
7
7
  <%_ }); -%>
8
8
  */
9
- <%= input.key %><%= input.required ? "" : "?" %>: <%- input.type.type ? input.type.type : input.type %>;
9
+ <%= input.key %><%= input.required ? "" : "?" %>: <%- input.valueType.type ? input.valueType.type : input.valueType %>;
10
10
  <% }); -%>
@@ -1,4 +1,4 @@
1
- import { Imports } from "../componentManifest/getImports";
1
+ import type { Imports } from "../componentManifest/getImports";
2
2
  export interface CreateDependencyImportsProps {
3
3
  imports: Imports;
4
4
  }
@@ -160,16 +160,17 @@ const convertConfigVarPermissionAndVisibility = ({ permissionAndVisibilityType,
160
160
  };
161
161
  };
162
162
  const convertComponentReference = (componentReference, componentRegistry) => {
163
- var _a, _b, _c;
163
+ var _a, _b;
164
+ const manifest = componentRegistry[componentReference.component];
164
165
  const ref = {
165
166
  component: {
166
- key: componentReference.component,
167
- signature: (_b = (_a = componentRegistry[componentReference.component]) === null || _a === void 0 ? void 0 : _a.signature) !== null && _b !== void 0 ? _b : "",
168
- isPublic: componentReference.isPublic,
167
+ key: manifest.key,
168
+ signature: (_a = manifest.signature) !== null && _a !== void 0 ? _a : "",
169
+ isPublic: manifest.public,
169
170
  },
170
171
  key: componentReference.key,
171
172
  };
172
- const inputs = Object.entries((_c = componentReference.values) !== null && _c !== void 0 ? _c : {}).reduce((result, [key, value]) => {
173
+ const inputs = Object.entries((_b = componentReference.values) !== null && _b !== void 0 ? _b : {}).reduce((result, [key, value]) => {
173
174
  if ("value" in value) {
174
175
  const type = value.value instanceof Object ? "complex" : "value";
175
176
  const valueExpr = value.value instanceof Object && !Array.isArray(value.value)
@@ -387,6 +388,13 @@ const convertOnExecution = (onExecution, componentRegistry) => (context, params)
387
388
  // Transform the input values based on the action's inputs
388
389
  const transformedValues = Object.entries(values).reduce((transformedAccumulator, [inputKey, inputValue]) => {
389
390
  const { collection } = action.inputs[inputKey];
391
+ if (collection === "keyvaluelist" &&
392
+ Array.isArray(inputValue)) {
393
+ transformedAccumulator[inputKey] = inputValue.reduce((acc, { key, value }) => {
394
+ return [...acc, { key, value }];
395
+ }, []);
396
+ return transformedAccumulator;
397
+ }
390
398
  // Transform key-value list inputs
391
399
  if (collection === "keyvaluelist" &&
392
400
  Object.keys(inputValue).length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "9.0.0-rc.7",
3
+ "version": "9.0.0-rc.9",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"