Skip to content

Commit

Permalink
remove workaround for too complex types
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf committed Apr 1, 2024
1 parent 40b129e commit 8598b02
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ function check(original: string[], preprocessed: string[][]): string[][] {
function checkOne(filter: string[]): string | true {
const [l1, l2, l3, ...n] = filter;
if (l1 === undefined) return "Empty filter query given";
if (
!(l1 in UPDATE_KEYS ||
l1 === "chat_boost" || l1 === "removed_chat_boost") // TODO: remove
) {
if (!(l1 in UPDATE_KEYS)) {
const permitted = Object.keys(UPDATE_KEYS);
return `Invalid L1 filter '${l1}' given in '${filter.join(":")}'. \
Permitted values are: ${permitted.map((k) => `'${k}'`).join(", ")}.`;
Expand Down Expand Up @@ -358,8 +355,8 @@ const UPDATE_KEYS = {
chat_join_request: {},
message_reaction: MESSAGE_REACTION_UPDATED_KEYS,
message_reaction_count: MESSAGE_REACTION_COUNT_UPDATED_KEYS,
// chat_boost: {},
// removed_chat_boost: {},
chat_boost: {},
removed_chat_boost: {},
} as const;

// === Build up all possible filter queries from the above validation structure
Expand Down Expand Up @@ -407,10 +404,7 @@ type CollapseL2<
: never
: never);
// All queries
type ComputeFilterQueryList =
| InjectShortcuts
| "chat_boost" // TODO: remove
| "removed_chat_boost";
type ComputeFilterQueryList = InjectShortcuts;

/**
* Represents a filter query that can be passed to `bot.on`. There are three
Expand Down Expand Up @@ -621,14 +615,11 @@ const L2_SHORTCUTS = {
type L1Shortcuts = KeyOf<typeof L1_SHORTCUTS>;
type L2Shortcuts = KeyOf<typeof L2_SHORTCUTS>;

type ExpandShortcuts<Q extends string> = Exclude<
Q extends `${infer L1}:${infer L2}:${infer L3}`
? `${ExpandL1<L1>}:${ExpandL2<L2>}:${L3}`
: Q extends `${infer L1}:${infer L2}`
? `${ExpandL1<L1>}:${ExpandL2<L2>}`
: ExpandL1<Q>,
"chat_boost" | "removed_chat_boost" // TODO: remove
>;
type ExpandShortcuts<Q extends string> = Q extends
`${infer L1}:${infer L2}:${infer L3}`
? `${ExpandL1<L1>}:${ExpandL2<L2>}:${L3}`
: Q extends `${infer L1}:${infer L2}` ? `${ExpandL1<L1>}:${ExpandL2<L2>}`
: ExpandL1<Q>;
type ExpandL1<S extends string> = S extends L1Shortcuts
? typeof L1_SHORTCUTS[S][number]
: S;
Expand Down

0 comments on commit 8598b02

Please sign in to comment.