Skip to content

Commit

Permalink
Provide typeahead for the type property in function parameters and …
Browse files Browse the repository at this point in the history
…datastore attributes (#186)
  • Loading branch information
shapirone authored Jun 23, 2023
1 parent 11ea50e commit abd4e33
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/datastore/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { ICustomType } from "../types/types.ts";
import { ManifestDatastoreSchema } from "../manifest/manifest_schema.ts";
import { SlackManifest } from "../manifest/mod.ts";
import { SlackPrimitiveTypes } from "../schema/slack/types/mod.ts";
import type { ValidSchemaTypes } from "../schema/schema_types.ts";
import type { ValidSlackPrimitiveTypes } from "../schema/slack/types/mod.ts";
import type { LooseStringAutocomplete } from "../type_utils.ts";

type InvalidDatastoreTypes =
| typeof SlackPrimitiveTypes.blocks
| typeof SlackPrimitiveTypes.oauth2;

type ValidDatastoreTypes = Exclude<
| ValidSchemaTypes
| ValidSlackPrimitiveTypes,
InvalidDatastoreTypes
>;

export type SlackDatastoreAttribute = {
// supports custom types, primitive types, inline objects and lists
type: string | ICustomType;
type: LooseStringAutocomplete<ValidDatastoreTypes> | ICustomType;
};

export type SlackDatastoreAttributes = Record<string, SlackDatastoreAttribute>;
Expand Down
10 changes: 7 additions & 3 deletions src/parameters/definition_types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import SchemaTypes from "../schema/schema_types.ts";
import { SlackPrimitiveTypes } from "../schema/slack/types/mod.ts";
import SchemaTypes, { ValidSchemaTypes } from "../schema/schema_types.ts";
import {
SlackPrimitiveTypes,
ValidSlackPrimitiveTypes,
} from "../schema/slack/types/mod.ts";
import { LooseStringAutocomplete } from "../type_utils.ts";
import { ICustomType } from "../types/types.ts";

export type ParameterDefinition = TypedParameterDefinition;
Expand Down Expand Up @@ -27,7 +31,7 @@ export interface CustomTypeParameterDefinition

interface BaseParameterDefinition<T> {
/** Defines the parameter type. */
type: string;
type: LooseStringAutocomplete<ValidSchemaTypes | ValidSlackPrimitiveTypes>;
/** An optional parameter title. */
title?: string;
/** An optional parameter description. */
Expand Down
2 changes: 2 additions & 0 deletions src/schema/schema_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ const SchemaTypes = {
array: "array",
} as const;

export type ValidSchemaTypes = typeof SchemaTypes[keyof typeof SchemaTypes];

export default SchemaTypes;
3 changes: 3 additions & 0 deletions src/schema/slack/types/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ const SlackPrimitiveTypes = {
message_ts: "slack#/types/message_ts",
} as const;

export type ValidSlackPrimitiveTypes =
typeof SlackPrimitiveTypes[keyof typeof SlackPrimitiveTypes];

export { SlackPrimitiveTypes };
4 changes: 4 additions & 0 deletions src/type_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ export type IncreaseDepth<Depth extends RecursionDepthLevel = 0> = Depth extends
: Depth extends 4 ? 5
: Depth extends 5 ? MaxRecursionDepth
: MaxRecursionDepth;

/** @description Provides typeahead for passed strict string values while allowing any other string to be passed as well */
// deno-lint-ignore ban-types
export type LooseStringAutocomplete<T> = T | (string & {});

0 comments on commit abd4e33

Please sign in to comment.