prismatic-io / spectral

Prismatic's typescript library for custom components
https://prismatic.io/docs/spectral/custom-component-library
35 stars 2 forks source link

CNI - Update derived type interfaces to format invalid type interfaces names #250

Closed jasoncomes closed 2 months ago

jasoncomes commented 2 months ago

DRAFT

In older legacy components, some did not utilize the action(), connection(), dataSource(), and trigger() wrappers. This enabled developers at the time to add the key property with arbitrary values, including invalid ones like computemd5-sha1 and Smartsheet OAuth2. Now, we need to convert these to adhere to valid interface and import file naming conventions.

# azure-service-bus, bynder, fluent-commerce, servicedesk-plus, smartsheet, hash

SyntaxError: ',' expected. (2:20)
  1 | import { oauth } from "./oauth";
> 2 | import { connection-string } from "./connection-string";

SyntaxError: ',' expected. (1:21)
> 1 | import { Smartsheet OAuth2 } from "./Smartsheet OAuth2";
    |                     ^
  2 | import { apiKey } from "./apiKey";

SyntaxError: ',' expected. (7:20)
   5 | import { computemd4 } from "./computemd4";
   6 | import { computemd5 } from "./computemd5";
>  7 | import { computemd5-sha1 } from "./computemd5-sha1";
     |                    ^
   8 | import { computeripemd160 } from "./computeripemd160";
   9 | import { computesha1 } from "./computesha1";
  10 | import { computesha224 } from "./computesha224";
    at hV (file:///Users/ryan/src/spectral/node_modules/prettier/plugins/typescript.mjs:23:524)
    at UV (file:///Users/ryan/src/spectral/node_modules/prettier/plugins/typescript.mjs:25:14870)
    at Object.WV [as parse] (file:///Users/ryan/src/spectral/node_modules/prettier/plugins/typescript.mjs:25:15270)
    at parse (file:///Users/ryan/src/spectral/node_modules/prettier/index.mjs:16786:24)
    at async coreFormat (file:///Users/ryan/src/spectral/node_modules/prettier/index.mjs:18107:7)
    at async formatWithCursor (file:///Users/ryan/src/spectral/node_modules/prettier/index.mjs:18309:14)
    at async Module.format2 (file:///Users/ryan/src/spectral/node_modules/prettier/index.mjs:21504:25) {
  loc: { start: { line: 7, column: 20 }, end: { line: 7, column: 20 } },

The input keys have arbitrary values, which could potentially include non-alphanumeric characters. To ensure proper formatting, we'll need to check if the input keys contain any characters outside the range of [a-zA-Z0-9] and, if so, add quotes around the 'type' field.

SyntaxError: Property or signature expected. (30:3)
  28 |  * @placeholder Ocp-Apim-Subscription-Key
  29 |  */
> 30 |   ocp-apim-subscription-key: string;
     |   ^
  31 |    /**
  32 |  * Sage 200 Edition
  33 |  * The Sage 200 Edition you are connecting to.
    at qe (/Users/ryan/.asdf/installs/nodejs/18.20.3/lib/node_modules/@prismatic-io/spectral/node_modules/prettier/parser-typescript.js:1:15607)

Update naming convention solution:

The action, trigger, connection, and datasource keys should remain consistent with what they named.

Component:

export const connectionString = connection({
  key: "connection-string",
  label: "Connection String",
  inputs: {
    connectionString: {
      label: "Connection String",
      type: "password",
      required: true,
      shown: true,
      comments:
        "The connection string for your Azure Service Bus namespace. You can find this in the Azure Portal under the 'Shared access policies' tab.",
    },
  },
});

Manifest:

# connectionString.ts <-- UPDATED FILE NAME (MATTERS)

export interface ConnectionStringValues { <-- UPDATED INTERFACE (DOESN'T MATTER)
  /**
   * Connection String
   * The connection string for your Azure Service Bus namespace. You can find this in the Azure Portal under the 'Shared access policies' tab.
   *
   */
  connectionString: string;
}

/**
 * Connection String
 *
 */
export const connectionString = {
  key: "connection-string", <-- PRESERVED KEY (MATTERS)
  perform: (_values: ConnectionStringValues): Promise<void> =>
    Promise.resolve(),
  inputs: {
    connectionString: {
      inputType: "password",
      collection: undefined,
      required: true,
    },
  },
} as const;

CNI:

example: connectionConfigVar({
  stableKey: "2503a901-63d9-4b54-a2ba-bc241ae54a2b",
  dataType: "connection",
  connection: {
    component: "azureServiceBus",
    key: "connection-string",
    values: {
      connectionString: {
        value: "",
      },
    },
  },
}),