Skip to content

Commit

Permalink
Fix and improve types for configVars and CNI conversions (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwersal authored Feb 1, 2024
1 parent 5587773 commit 936c017
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packages/generator-spectral/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismatic-io/generator-spectral",
"version": "3.0.1",
"version": "3.0.2",
"description": "Yeoman generator for scaffolding out Prismatic components",
"keywords": [
"prismatic",
Expand Down Expand Up @@ -40,7 +40,7 @@
],
"dependencies": {
"@apidevtools/swagger-parser": "10.1.0",
"@prismatic-io/spectral": "8.0.1",
"@prismatic-io/spectral": "8.0.2",
"lodash": "4.17.21",
"number-to-words": "1.2.4",
"openapi-types": "11.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/spectral/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismatic-io/spectral",
"version": "8.0.1",
"version": "8.0.2",
"description": "Utility library for building Prismatic components",
"keywords": [
"prismatic"
Expand Down
32 changes: 21 additions & 11 deletions packages/spectral/src/serverTypes/convertIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,23 @@ export const convertIntegration = (
};
};

const convertConfigPages = (pages: ConfigPages): ServerConfigPage[] => {
return Object.entries(pages).map(([name, { tagline, elements }]) => ({
name,
tagline,
elements: Object.keys(elements).map((key) => ({
type: "configVar",
value: key,
})),
}));
const convertConfigPages = (
pages: ConfigPages
): ServerConfigPage[] | undefined => {
if (!pages || !Object.keys(pages).length) {
return;
}

return Object.entries(pages).map<ServerConfigPage>(
([name, { tagline, elements }]) => ({
name,
tagline,
elements: Object.keys(elements).map((key) => ({
type: "configVar",
value: key,
})),
})
);
};

const codeNativeIntegrationYaml = (
Expand Down Expand Up @@ -343,8 +351,10 @@ const codeNativeIntegrationComponent = (
"The function that will be executed by the flow to return an HTTP response.",
},
perform: onTrigger,
onInstanceDeploy: onInstanceDeploy,
onInstanceDelete: onInstanceDelete,
onInstanceDeploy,
hasOnInstanceDeploy: !!onInstanceDeploy,
onInstanceDelete,
hasOnInstanceDelete: !!onInstanceDelete,
inputs: [],
scheduleSupport: "valid",
synchronousResponseSupport: "valid",
Expand Down
14 changes: 8 additions & 6 deletions packages/spectral/src/serverTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export interface ActionLogger {
error: ActionLoggerFunction;
}

export type ActionContext<TConfigVars extends ConfigVarResultCollection> = {
export type ActionContext<
TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection
> = {
logger: ActionLogger;
instanceState: Record<string, unknown>;
crossFlowState: Record<string, unknown>;
Expand Down Expand Up @@ -132,15 +134,15 @@ export type TriggerResult =
| undefined;

export type TriggerPerformFunction = (
context: ActionContext<any>,
context: ActionContext,
payload: TriggerPayload,
params: Record<string, unknown>
) => Promise<TriggerResult>;

export type TriggerEventFunctionResult = TriggerEventFunctionReturn | void;

export type TriggerEventFunction = (
context: ActionContext<any>,
context: ActionContext,
params: Record<string, unknown>
) => Promise<TriggerEventFunctionResult>;

Expand All @@ -165,7 +167,7 @@ export interface Trigger {
}

export interface DataSourceContext<
TConfigVars extends ConfigVarResultCollection
TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection
> {
logger: ActionLogger;
configVars: TConfigVars;
Expand All @@ -180,7 +182,7 @@ export type DataSourceResult = {
};

export type DataSourcePerformFunction = (
context: DataSourceContext<any>,
context: DataSourceContext,
params: Record<string, unknown>
) => Promise<DataSourceResult>;

Expand Down Expand Up @@ -262,7 +264,7 @@ export type ActionPerformReturn =
| undefined; // Allow an action to return nothing to reduce component implementation boilerplate

export type ActionPerformFunction = (
context: ActionContext<any>,
context: ActionContext,
params: Record<string, unknown>
) => Promise<ActionPerformReturn>;

Expand Down
8 changes: 7 additions & 1 deletion packages/spectral/src/types/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export type ObjectFieldMap = {
}[];
};

export type Schedule = {
value: string;
schedule_type: string;
time_zone: string;
};

export type JSONForm = {
/**
* The data/JSON schema defines the underlying data to
Expand Down Expand Up @@ -337,5 +343,5 @@ export type InputFieldCollection = "valuelist" | "keyvaluelist";
/** Config variable result collection */
export type ConfigVarResultCollection = Record<
string,
string | Connection | JSONForm | ObjectSelection | ObjectFieldMap
string | Schedule | Connection | JSONForm | ObjectSelection | ObjectFieldMap
>;
6 changes: 5 additions & 1 deletion packages/spectral/src/types/IntegrationDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ObjectFieldMap,
ObjectSelection,
ConfigVarResultCollection,
Schedule,
} from ".";
import { Prettify, UnionToIntersection, ValueOf } from "./utils";

Expand All @@ -26,13 +27,16 @@ type ToDataSourceRuntimeType<TType extends DataSourceType> =
? ObjectFieldMap
: string;

type ToRuntimeType<TType extends ConfigVarDataType> =
TType extends ConfigVarDataType.Schedule ? Schedule : string;

export type ElementToRuntimeType<TElement extends ConfigPageElement> =
TElement extends ConnectionConfigVar
? Connection
: TElement extends DataSourceConfigVar
? ToDataSourceRuntimeType<TElement["dataSourceType"]>
: TElement extends StandardConfigVar
? string
? ToRuntimeType<TElement["dataType"]>
: never;

type GetElements<TConfigPages extends ConfigPages> =
Expand Down

0 comments on commit 936c017

Please sign in to comment.