Skip to content

Commit

Permalink
deno fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Maj committed Jun 7, 2024
1 parent 12a514c commit 3b8b514
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
} from "./utils.ts";
import { AllowedTypeValue, AllowedTypeValueObject } from "./types.ts";

type AllowedHiddenParamsMap = Record<string, Record<'input' | 'output', string[]>>;
type AllowedHiddenParamsMap = Record<
string,
Record<"input" | "output", string[]>
>;
// Oops we accidentally exposed hidden parameters. That's ok, we'll keep them public for now.
export const allowedHiddenParams: AllowedHiddenParamsMap = {
"open_form": {
Expand All @@ -30,11 +33,21 @@ export const allowedHiddenParams: AllowedHiddenParamsMap = {
},
"send_dm": {
input: ["files"],
output: ["action", "interactivity", "timestamp_started", "timestamp_completed"],
output: [
"action",
"interactivity",
"timestamp_started",
"timestamp_completed",
],
},
"send_message": {
input: ["files"],
output: ["action", "interactivity", "timestamp_started", "timestamp_completed"],
output: [
"action",
"interactivity",
"timestamp_started",
"timestamp_completed",
],
},
};

Expand Down Expand Up @@ -101,10 +114,12 @@ const manifestParametersToTypeScript = (
functionParameters: FunctionParameter[],
) => {
const typescript: string[] = [];
console.log(allowedHiddenParams, functionParameters.map(p => p.name));
console.log(allowedHiddenParams, functionParameters.map((p) => p.name));
typescript.push(
`properties: {${
functionParameters.filter((p) => allowedHiddenParams.includes(p.name) || !p.is_hidden).map((parameter) =>
functionParameters.filter((p) =>
allowedHiddenParams.includes(p.name) || !p.is_hidden
).map((parameter) =>
`${parameter.name}: ${propertyToTypeScript(parameter)}`
).join(",\n")
}}`,
Expand All @@ -123,7 +138,6 @@ export function manifestFunctionFieldsToTypeScript(
allowedParamsMap: AllowedHiddenParamsMap,
functionRecord: FunctionRecord,
) {

const typescript: string[] = [];
typescript.push(`source_file: ""`);
if (functionRecord.title) {
Expand All @@ -136,15 +150,22 @@ export function manifestFunctionFieldsToTypeScript(
`description: ${sanitize(functionRecord.description)}`,
);
}
const allowedHiddenParams = allowedParamsMap[functionRecord.callback_id] || { input: [], output: [] };
const allowedHiddenParams = allowedParamsMap[functionRecord.callback_id] ||
{ input: [], output: [] };
typescript.push(
`input_parameters: ${
manifestParametersToTypeScript(allowedHiddenParams.input, functionRecord.input_parameters)
manifestParametersToTypeScript(
allowedHiddenParams.input,
functionRecord.input_parameters,
)
}`,
);
typescript.push(
`output_parameters: ${
manifestParametersToTypeScript(allowedHiddenParams.output, functionRecord.output_parameters)
manifestParametersToTypeScript(
allowedHiddenParams.output,
functionRecord.output_parameters,
)
}`,
);
return typescript.join(",\n");
Expand All @@ -157,7 +178,9 @@ const defineFunctionInputToTypeScript = (
typescript.push(
`callback_id: ${sanitize(getSlackCallbackId(functionRecord))}`,
);
typescript.push(manifestFunctionFieldsToTypeScript(allowedHiddenParams, functionRecord));
typescript.push(
manifestFunctionFieldsToTypeScript(allowedHiddenParams, functionRecord),
);
return `{${typescript.join(",\n")}}`;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import {
renderTypeImports,
} from "./utils.ts";
import { FunctionParameter, FunctionRecord } from "../types.ts";
import { allowedHiddenParams, manifestFunctionFieldsToTypeScript } from "./template_function.ts";
import {
allowedHiddenParams,
manifestFunctionFieldsToTypeScript,
} from "./template_function.ts";

export const manifestFunctionToTypeScript = (
functionRecord: FunctionRecord,
) => {
return `{${manifestFunctionFieldsToTypeScript(allowedHiddenParams, functionRecord)}}`;
return `{${
manifestFunctionFieldsToTypeScript(allowedHiddenParams, functionRecord)
}}`;
};

const renderFunctionManifestTest = (
Expand Down

0 comments on commit 3b8b514

Please sign in to comment.