Skip to content

Commit

Permalink
Remove some deprecated items (#91)
Browse files Browse the repository at this point in the history
* removing deprecated FunctionHandler type export

* removing CustomType callback_id

* remove callback_id logic from export

* adding manifest workflows test
  • Loading branch information
selfcontained committed Aug 29, 2022
1 parent 6650c12 commit f6b5a15
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 79 deletions.
6 changes: 0 additions & 6 deletions src/functions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,6 @@ export type BaseSlackFunctionHandler<
| AsyncFunctionHandler<InputParameters, OutputParameters>
| SyncFunctionHandler<InputParameters, OutputParameters>;

// Exporting this alias for backwards compatability
/**
* @deprecated Use either SlackFunctionHandler<Definition> or BaseSlackFunctionHandler<Inputs, Outputs>
*/
export type FunctionHandler<I, O> = BaseSlackFunctionHandler<I, O>;

type SuccessfulFunctionReturnArgs<
OutputParameters extends FunctionParameters,
> = {
Expand Down
49 changes: 38 additions & 11 deletions src/manifest/manifest_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DefineFunction,
DefineOAuth2Provider,
DefineType,
DefineWorkflow,
Schema,
} from "../mod.ts";
import {
Expand Down Expand Up @@ -179,10 +180,30 @@ Deno.test("Manifest() automatically registers types used by function input and o
});
});

Deno.test("Manifest() properly converts name to proper key", () => {
const UsingName = DefineType({
name: "Using Name",
type: Schema.types.boolean,
Deno.test("Manifest() automatically registers functions used by workflows", () => {
const Function = DefineFunction(
{
callback_id: "test_function",
title: "Function title",
source_file: "functions/test_function.ts",
input_parameters: {
properties: { aString: { type: Schema.types.string } },
required: [],
},
output_parameters: {
properties: { aType: { type: Schema.types.string } },
required: [],
},
},
);

const Workflow = DefineWorkflow({
title: "test workflow",
callback_id: "test_workflow",
});

Workflow.addStep(Function, {
aString: "test",
});

const definition: SlackManifestType = {
Expand All @@ -191,15 +212,21 @@ Deno.test("Manifest() properly converts name to proper key", () => {
icon: "icon.png",
longDescription: "LongDescription",
botScopes: [],
types: [UsingName],
workflows: [Workflow],
};
const manifest = Manifest(definition);
assertEquals(manifest.types, { "Using Name": { type: "boolean" } });

assertEquals(manifest.workflows, {
[Workflow.id]: Workflow.export(),
});
assertEquals(manifest.functions, {
[Function.id]: Function.export(),
});
});

Deno.test("Manifest() properly converts callback_id to proper key", () => {
const UsingCallback = DefineType({
callback_id: "Using Callback",
Deno.test("Manifest() properly converts name to proper key", () => {
const UsingName = DefineType({
name: "Using Name",
type: Schema.types.boolean,
});

Expand All @@ -209,10 +236,10 @@ Deno.test("Manifest() properly converts callback_id to proper key", () => {
icon: "icon.png",
longDescription: "LongDescription",
botScopes: [],
types: [UsingCallback],
types: [UsingName],
};
const manifest = Manifest(definition);
assertEquals(manifest.types, { "Using Callback": { type: "boolean" } });
assertEquals(manifest.types, { "Using Name": { type: "boolean" } });
});

Deno.test("Manifest() always sets token_management_enabled to false for runOnSlack: true apps", () => {
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export type {
BaseSlackFunctionHandler,
BlockActionHandler,
FunctionHandler, // Deprecated
SlackFunctionHandler,
} from "./functions/types.ts";

Expand Down
13 changes: 4 additions & 9 deletions src/types/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class CustomType<Def extends CustomTypeDefinition>
constructor(
public definition: Def,
) {
this.id = "name" in definition ? definition.name : definition.callback_id;
this.id = definition.name;
this.definition = definition;
this.description = definition.description;
this.title = definition.title;
Expand Down Expand Up @@ -59,13 +59,8 @@ export class CustomType<Def extends CustomTypeDefinition>
}
}
export(): ManifestCustomTypeSchema {
// remove callback_id or name from the definition we pass to the manifest
if ("name" in this.definition) {
const { name: _n, ...definition } = this.definition;
return definition;
} else {
const { callback_id: _c, ...definition } = this.definition;
return definition;
}
// remove name from the definition we pass to the manifest
const { name: _n, ...definition } = this.definition;
return definition;
}
}
13 changes: 2 additions & 11 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ import { SlackManifest } from "../manifest/mod.ts";
import { ManifestCustomTypeSchema } from "../manifest/manifest_schema.ts";
import { CustomType } from "./mod.ts";

export type NameTypeDefinition =
export type CustomTypeDefinition =
& { name: string }
& TypedParameterDefinition;
export type CallbackTypeDefinition =
& { callback_id: string }
& TypedParameterDefinition;

export type CustomTypeDefinition = NameTypeDefinition | CallbackTypeDefinition;

export type DefineTypeFunction = {
<Def extends NameTypeDefinition>(definition: Def): CustomType<Def>;
/**
* @deprecated Use name instead of callback_id
*/
<Def extends CallbackTypeDefinition>(definition: Def): CustomType<Def>;
<Def extends CustomTypeDefinition>(definition: Def): CustomType<Def>;
};

export interface ICustomType {
Expand Down
41 changes: 0 additions & 41 deletions src/types/types_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,6 @@ Deno.test("DefineType test against id using the name parameter", () => {
assertEquals(Type.id, "Name");
});

Deno.test("DefineType test against id using the callback_id parameter", () => {
const Type = DefineType({
title: "Title",
description: "Description",
callback_id: "Callback_id",
type: "Type",
});

assertEquals(Type.id, "Callback_id");
});

Deno.test("DefineType test toString using the callback_id parameter", () => {
const Type = DefineType({
title: "Title",
description: "Description",
callback_id: "Callback_id",
type: "Type",
});

const typeString = Type.toString();

assertEquals(typeString, "#/types/Callback_id");
});

Deno.test("DefineType test toString using the name parameter", () => {
const Type = DefineType({
title: "Title",
Expand Down Expand Up @@ -65,20 +41,3 @@ Deno.test("DefineType test export using the name parameter", () => {
type: "Type",
});
});

Deno.test("DefineType test export using the callback_id parameter", () => {
const Type = DefineType({
title: "Title",
description: "Description",
callback_id: "Callback_id",
type: "Type",
});

const exportType = Type.export();

assertEquals(exportType, {
title: "Title",
description: "Description",
type: "Type",
});
});

0 comments on commit f6b5a15

Please sign in to comment.