abseil 0.4.0 → 0.5.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,21 +1,15 @@
1
1
  # Abseil
2
2
 
3
- Quickly traverse Discord [Components V2](https://docs.discord.com/developers/components/overview) trees. Either enter at the root with `abseil([...]).initial(type)` or jump to a specific node with `abseil([...]).find(query, type)`.
3
+ Validate and traverse Discord [Components V2](https://docs.discord.com/developers/components/overview) trees.
4
4
 
5
- ## Node Reference
5
+ The `abseil` function validates that the input components array matches a schema. It returns the validated array and functions to interact with it.
6
6
 
7
- | function | description |
8
- | ------------ | ----------------------------------------------------------------------------------------------------- |
9
- | accessory | Access the accessory of a [Section](https://docs.discord.com/developers/components/reference#section) |
10
- | child | Access the first child of a node |
11
- | insertBefore | Insert a sibling before the current node |
12
- | last | Jump to the last neighbouring node of a type in an array |
13
- | next | Jump to the next neighbouring node of a type in an array |
14
- | parent | Access the parent of a node |
15
- | previous | Return to the previous node |
16
- | sibling | Access the next node in an array |
17
- | update | Shallow merge with the current component in place |
18
- | value | The current component |
7
+ | function | description |
8
+ | -------- | -------------------------------------- |
9
+ | parent | Discover the parent node. |
10
+ | remove | Destroy a node. |
11
+ | search | Search the layout for a specific node. |
12
+ | sibling | Discover a neighbouring node. |
19
13
 
20
14
  ## Example
21
15
 
@@ -45,26 +39,41 @@ const message = {
45
39
  </details>
46
40
 
47
41
  ```ts
48
- import abseil, { removeNode } from "abseil";
42
+ import {
43
+ $ActionRow,
44
+ $Button,
45
+ $Container,
46
+ $Section,
47
+ $Separator,
48
+ $TextDisplay,
49
+ abseil,
50
+ } from "abseil";
49
51
  import { editMessage } from "dressed";
50
52
 
51
- const line = abseil(message.components ?? []);
53
+ const tree = abseil(message.components, [
54
+ $Container(
55
+ $Section([$TextDisplay], $Button).or($TextDisplay),
56
+ $TextDisplay,
57
+ $ActionRow($Button, $Button),
58
+ $Separator,
59
+ $Section([$TextDisplay], $Button),
60
+ ),
61
+ ]);
52
62
 
53
- let guessBtn = line.find(/guess-.+/, "Button");
63
+ let guessBtn = tree.search(/guess-.+/, $Button);
54
64
 
55
65
  while (guessBtn) {
56
- guessBtn.update({ disabled: true });
57
- guessBtn = guessBtn.next("Button");
66
+ guessBtn.disabled = true;
67
+ guessBtn = tree.sibling(guessBtn, $Button);
58
68
  }
59
69
 
60
- const header = line.initial("Container").child("Section");
61
-
62
- header.insertBefore(TextDisplay(header.child("TextDisplay").value.content));
63
- removeNode(header);
70
+ const body = tree[0].components;
71
+ if ($Section.$.allows(body[0])) body[0] = TextDisplay(body[0].components[0].content);
64
72
 
65
73
  // Insert-if-not-exists the warning message
66
- if (!header.last("Section")?.sibling) {
67
- header.previous.value.components.push(TextDisplay("-# This has expired!"));
74
+ const warning = "-# This has expired!";
75
+ if (!tree.search(warning, $TextDisplay)) {
76
+ body.push(TextDisplay(warning));
68
77
  }
69
78
 
70
79
  editMessage("<CHANNEL_ID>", "<MESSAGE_ID>", { components: message.components });
package/dist/index.d.ts CHANGED
@@ -1,82 +1,100 @@
1
- /** biome-ignore-all lint/suspicious/noExplicitAny: Not worth my time */
2
- import { type APIComponentInContainer, type APIComponentInMessageActionRow, type APIMessageComponent, type APISectionAccessoryComponent, type APISelectMenuComponent, ComponentType } from "discord-api-types/v10";
3
- type CT = Omit<typeof ComponentType, "SelectMenu" | "ContentInventoryEntry"> & {
4
- "Button:URL": ComponentType.Button;
5
- "Button:SKU": ComponentType.Button;
1
+ import { type Type, type } from "arktype";
2
+ import type { APIActionRowComponent, APIButtonComponentWithCustomId, APIButtonComponentWithSKUId, APIButtonComponentWithURL, APIChannelSelectComponent, APICheckboxComponent, APICheckboxGroupComponent, APIComponentInActionRow, APIComponentInMessageActionRow, APIContainerComponent, APIFileComponent, APIFileUploadComponent, APILabelComponent, APIMediaGalleryComponent, APIMentionableSelectComponent, APIMessageComponent, APIModalComponent, APIRadioGroupComponent, APIRoleSelectComponent, APISectionComponent, APISeparatorComponent, APIStringSelectComponent, APITextDisplayComponent, APITextInputComponent, APIThumbnailComponent, APIUserSelectComponent } from "discord-api-types/v10";
3
+ export declare const $Button: import("arktype/internal/variants/object.ts").ObjectType<APIButtonComponentWithCustomId, {}> & {
4
+ URL: Type<APIButtonComponentWithURL>;
5
+ SKU: Type<APIButtonComponentWithSKUId>;
6
6
  };
7
- type IComponentType = {
8
- [K in keyof CT as CT[K]]: K;
7
+ declare const AnyButton: import("arktype/internal/variants/object.ts").ObjectType<APIButtonComponentWithCustomId | APIButtonComponentWithSKUId | APIButtonComponentWithURL, {}>;
8
+ export declare const $StringSelect: Type<APIStringSelectComponent>;
9
+ export declare const $UserSelect: Type<APIUserSelectComponent>;
10
+ export declare const $RoleSelect: Type<APIRoleSelectComponent>;
11
+ export declare const $MentionableSelect: Type<APIMentionableSelectComponent>;
12
+ export declare const $ChannelSelect: Type<APIChannelSelectComponent>;
13
+ declare const AnySelect: import("arktype/internal/variants/object.ts").ObjectType<APIChannelSelectComponent | APIMentionableSelectComponent | APIRoleSelectComponent | APIStringSelectComponent | APIUserSelectComponent, {}>;
14
+ export declare const $ActionRow: (<const T extends (typeof AnyButton)[] | [typeof AnySelect] | [typeof $TextInput]>(...components: T) => Type<Omit<APIActionRowComponent<APIComponentInActionRow>, "components"> & {
15
+ components: type.infer<T>;
16
+ }>) & {
17
+ $: Type<APIActionRowComponent<APIComponentInMessageActionRow>>;
9
18
  };
10
- type WithCustomIdType = Exclude<IComponentType[Extract<APIMessageComponent, {
11
- custom_id: string;
12
- }>["type"]], `Button:${string}`>;
13
- type Pop<T extends any[]> = T extends [...infer Rest, any] ? Rest : never;
14
- type Last<T extends any[]> = T extends [...any[], infer L] ? L : never;
15
- type Arrable<T> = T | T[];
16
- type Overwriter<T> = Partial<T> | ((prev: T) => Partial<T>);
17
- interface ChildrenMap {
18
- ActionRow: IComponentType[APIComponentInMessageActionRow["type"]];
19
- Container: IComponentType[APIComponentInContainer["type"]];
20
- Section: "TextDisplay";
21
- }
22
- type Depth = [keyof CT, keyof CT][];
23
- type History = Depth[];
24
- type TraverserFn<C extends keyof CT, H extends History, D extends Depth, O extends string = ""> = <T extends C>(type: Arrable<T>) => Omit<Traverser<[...D, [T, C]], H>, O>;
25
- type Component<T extends keyof CT> = Extract<APIMessageComponent, {
26
- type: CT[T extends "Button:URL" | "Button:SKU" ? "Button" : T];
27
- } & (T extends "Button" ? {
28
- custom_id: string;
29
- } : T extends "Button:URL" ? {
30
- url: string;
31
- } : T extends "Button:SKU" ? {
32
- sku_id: string;
33
- } : object)>;
34
- export type Traverser<D extends Depth, H extends History> = {
35
- /** Shallow merge with the current component in place. */
36
- update: (value: Overwriter<Component<Last<D>[0]>>) => Traverser<D, H>;
37
- /** The current component. */
38
- value: Component<Last<D>[0]>;
39
- } & (Last<D>[0] extends IComponentType[APISelectMenuComponent["type"]] ? object : {
40
- /** Insert a sibling before the current node. */
41
- insertBefore: <V extends Component<Last<D>[1]>>(component: V) => Traverser<D, H>;
42
- /** Jump to the last neighbouring node of a type in an array. */
43
- last: <N extends Last<D>[1]>(type: Arrable<N>) => Traverser<[...Pop<D>, [N, Last<D>[1]]], [...H, D]> | undefined;
44
- /** Jump to the next neighbouring node of a type in an array. */
45
- next: <N extends Last<D>[1]>(type: Arrable<N>) => Traverser<[...Pop<D>, [N, Last<D>[1]]], [...H, D]> | undefined;
46
- /** Access the next node in an array. */
47
- sibling: TraverserFn<Last<D>[1], [...H, D], Pop<D>>;
48
- }) & (Last<D>[0] extends keyof ChildrenMap ? {
49
- /** Access the first child of a node. */
50
- child: TraverserFn<ChildrenMap[Last<D>[0]], [...H, D], D>;
51
- } : object) & (Last<D>[0] extends "Section" ? {
52
- /** Access the accessory of a [Section](https://docs.discord.com/developers/components/reference#section). */
53
- accessory: TraverserFn<IComponentType[APISectionAccessoryComponent["type"]], [...H, D], Pop<D>, "sibling">;
54
- } : object) & (H extends [] ? object : {
55
- /** Return to the previous node. */
56
- previous: Traverser<Last<H>, Pop<H>>;
57
- }) & (D extends [any] ? object : {
58
- /** Access the parent of the current node. */
59
- parent: <P extends Last<Pop<D>> extends never ? keyof ChildrenMap : Last<Pop<D>>[0]>(type: Arrable<P>) => Traverser<Last<Pop<D>> extends never ? [...(P extends "Container" ? [] : [never]), [P, keyof CT]] : Pop<D>, [
60
- ...H,
61
- D
62
- ]>;
63
- });
64
- /** Initiate a tree traverser. */
65
- export default function abseil<T extends APIMessageComponent>(components: T[]): {
19
+ export declare const $Thumbnail: Type<APIThumbnailComponent>;
20
+ export declare const $Section: (<const T extends (typeof $TextDisplay)[], const A extends Type<typeof AnyButton.infer | typeof $Thumbnail.infer>>(components: T, accessory: A) => Type<Omit<APISectionComponent, "accessory" | "components"> & {
21
+ accessory: type.infer<A>;
22
+ components: type.infer<T>;
23
+ }>) & {
24
+ $: Type<APISectionComponent>;
25
+ };
26
+ export declare const $TextDisplay: Type<APITextDisplayComponent>;
27
+ export declare const $MediaGallery: Type<APIMediaGalleryComponent>;
28
+ export declare const $File: Type<APIFileComponent>;
29
+ export declare const $Separator: Type<APISeparatorComponent>;
30
+ declare const ComponentInContainer: import("arktype/internal/variants/object.ts").ObjectType<APIFileComponent | APIMediaGalleryComponent | APISeparatorComponent | APITextDisplayComponent | {
31
+ type: 1;
32
+ } | {
33
+ type: 9;
34
+ }, {}>;
35
+ export declare const $Container: (<const T extends (typeof ComponentInContainer)[]>(...components: T) => Type<Omit<APIContainerComponent, "components"> & {
36
+ components: type.infer<T>;
37
+ }>) & {
38
+ $: Type<APIContainerComponent>;
39
+ };
40
+ export declare const $TextInput: Type<APITextInputComponent>;
41
+ export declare const $FileUpload: Type<APIFileUploadComponent>;
42
+ export declare const $RadioGroup: Type<APIRadioGroupComponent>;
43
+ export declare const $CheckboxGroup: Type<APICheckboxGroupComponent>;
44
+ export declare const $Checkbox: Type<APICheckboxComponent>;
45
+ declare const ComponentInLabel: import("arktype/internal/variants/object.ts").ObjectType<APIChannelSelectComponent | APIMentionableSelectComponent | APIRoleSelectComponent | APIStringSelectComponent | APIUserSelectComponent | APITextInputComponent | APICheckboxComponent | APICheckboxGroupComponent | APIFileUploadComponent | APIRadioGroupComponent, {}>;
46
+ export declare const $Label: (<const T extends typeof ComponentInLabel>(component: T) => Type<Omit<APILabelComponent, "component"> & {
47
+ component: type.infer<T>;
48
+ }>) & {
49
+ $: Type<APILabelComponent>;
50
+ };
51
+ type AnyComponent = APIMessageComponent | APIModalComponent;
52
+ export declare const $Any: import("arktype/internal/variants/object.ts").ObjectType<AnyComponent, {}> & {
53
+ ActionRow: import("arktype/internal/variants/object.ts").ObjectType<APIButtonComponentWithCustomId | APIButtonComponentWithSKUId | APIButtonComponentWithURL | APIChannelSelectComponent | APIMentionableSelectComponent | APIRoleSelectComponent | APIStringSelectComponent | APIUserSelectComponent, {}>;
54
+ Button: import("arktype/internal/variants/object.ts").ObjectType<APIButtonComponentWithCustomId | APIButtonComponentWithSKUId | APIButtonComponentWithURL, {}>;
55
+ Container: import("arktype/internal/variants/object.ts").ObjectType<APIFileComponent | APIMediaGalleryComponent | APISeparatorComponent | APITextDisplayComponent | {
56
+ type: 1;
57
+ } | {
58
+ type: 9;
59
+ }, {}>;
60
+ Label: import("arktype/internal/variants/object.ts").ObjectType<APIChannelSelectComponent | APIMentionableSelectComponent | APIRoleSelectComponent | APIStringSelectComponent | APIUserSelectComponent | APITextInputComponent | APICheckboxComponent | APICheckboxGroupComponent | APIFileUploadComponent | APIRadioGroupComponent, {}>;
61
+ Section: {
62
+ Component: import("arktype/internal/variants/object.ts").ObjectType<APITextDisplayComponent, {}>;
63
+ Accessory: import("arktype/internal/variants/object.ts").ObjectType<APIButtonComponentWithCustomId | APIButtonComponentWithSKUId | APIButtonComponentWithURL | APIThumbnailComponent, {}>;
64
+ };
65
+ Select: import("arktype/internal/variants/object.ts").ObjectType<APIChannelSelectComponent | APIMentionableSelectComponent | APIRoleSelectComponent | APIStringSelectComponent | APIUserSelectComponent, {}>;
66
+ };
67
+ interface LayoutFns {
66
68
  /**
67
- * Enter the tree at a specific node.
68
- * @param query Either the component `id` or `custom_id`
69
+ * Discover the parent node.
70
+ * @param node Node to jump from
71
+ * @param $component Schema the found component must match
69
72
  */
70
- find<Q extends number | string | RegExp, F extends Q extends number ? keyof CT : WithCustomIdType>(query: Q, type: Arrable<F>): Omit<Traverser<[never, [F, "File" | "ActionRow" | "Button" | "StringSelect" | "TextInput" | "UserSelect" | "RoleSelect" | "MentionableSelect" | "ChannelSelect" | "Section" | "TextDisplay" | "Thumbnail" | "MediaGallery" | "Separator" | "Container" | "Label" | "FileUpload" | "RadioGroup" | "CheckboxGroup" | "Checkbox" | "Button:URL" | "Button:SKU"]], []>, "previous"> | undefined;
71
- /** Entry point of the tree, visually this is the top-leftmost component. */
72
- initial: TraverserFn<IComponentType[T["type"]], [], [], "parent" | "previous">;
73
- };
73
+ parent: <C extends Type<AnyComponent>>(node: AnyComponent, $component: C) => C["infer"] | undefined;
74
+ /**
75
+ * Destroy a node.
76
+ * @param node Node to remove
77
+ */
78
+ remove: (node: AnyComponent | undefined) => void;
79
+ /**
80
+ * Search the layout for a specific node.
81
+ * @param query Substring of a TextDisplay content, custom_id, or the component `id`
82
+ * @param $component Schema the found component must match
83
+ */
84
+ search: <Q extends number | string | RegExp, C extends Q extends number ? Type<AnyComponent> : typeof AnyButton | typeof ComponentInLabel | typeof $TextDisplay>(query: Q, $component: C) => C["infer"] | undefined;
85
+ /**
86
+ * Discover a neighbouring node.
87
+ * @param node Node to offset from
88
+ * @param $component Schema the found component must match
89
+ * @param offset Difference from {@link node} (defaults to `1`)
90
+ */
91
+ sibling: <C extends Type<AnyComponent>>(node: AnyComponent, $component: C, offset?: number) => C["infer"] | undefined;
92
+ }
74
93
  /**
75
- * Destroy a node in the tree.
76
- * Data on this node will be stripped, attempting to access most functions will throw.
77
- * @important This may cause issues when you try to navigate {@link abseil} instances you've previously created
94
+ * Validates that {@link components} match the {@link schema} and creates traversal functions
95
+ * @returns Validated input components and functions for interacting with the layout
78
96
  */
79
- export declare function removeNode<D extends Depth, H extends History>(node: Traverser<D, H>): void;
80
- /** Assert that a component is of certain type(s). */
81
- export declare const assert: <T extends keyof CT>(component: APIMessageComponent, type: Arrable<T>) => component is Component<T>;
97
+ export default function abseil<const S extends Type<{
98
+ type: number;
99
+ }>[]>(components: unknown[], schema: S): type.infer<S> & LayoutFns;
82
100
  export {};
package/dist/index.js CHANGED
@@ -1,168 +1,132 @@
1
- /** biome-ignore-all lint/suspicious/noExplicitAny: Not worth my time */
2
- import { ComponentType, } from "discord-api-types/v10";
3
- const withChildren = new Set([ComponentType.ActionRow, ComponentType.Section, ComponentType.Container]);
4
- const selects = new Set([
5
- ComponentType.StringSelect,
6
- ComponentType.UserSelect,
7
- ComponentType.RoleSelect,
8
- ComponentType.MentionableSelect,
9
- ComponentType.ChannelSelect,
10
- ]);
11
- function typesMatch(component, expected, throwOnMismatch) {
12
- const expectedTypes = new Set((Array.isArray(expected) ? expected : [expected]).filter(Boolean));
13
- if (!expectedTypes.size) {
14
- throw new Error("Selectors must specify expected type(s)");
15
- }
16
- let actualType = component.type === "Root" ? "Root" : ComponentType[component.type];
17
- if (actualType === "Button") {
18
- if ("url" in component)
19
- actualType += ":URL";
20
- else if ("sku_id" in component)
21
- actualType += ":SKU";
22
- }
23
- else if (actualType === "SelectMenu")
24
- actualType = "StringSelect";
25
- if (!expectedTypes.has(actualType)) {
26
- if (throwOnMismatch) {
27
- throw new TypeError(`Type mismatch: expected ${[...expectedTypes].join(" or ")}, got ${actualType}`);
28
- }
29
- return false;
30
- }
31
- return true;
32
- }
33
- function find(query, components) {
1
+ import { type } from "arktype";
2
+ import { ComponentType } from "discord-api-types/v10";
3
+ const BaseButton = type({ type: `${ComponentType.Button}` });
4
+ export const $Button = Object.assign(BaseButton.and({ custom_id: "string" }), {
5
+ URL: BaseButton.and({ url: "string" }),
6
+ SKU: BaseButton.and({ sku_id: "string" }),
7
+ });
8
+ const AnyButton = $Button.or($Button.URL).or($Button.SKU);
9
+ export const $StringSelect = type({ type: `${ComponentType.StringSelect}` });
10
+ export const $UserSelect = type({ type: `${ComponentType.UserSelect}` });
11
+ export const $RoleSelect = type({ type: `${ComponentType.RoleSelect}` });
12
+ export const $MentionableSelect = type({
13
+ type: `${ComponentType.MentionableSelect}`,
14
+ });
15
+ export const $ChannelSelect = type({ type: `${ComponentType.ChannelSelect}` });
16
+ const AnySelect = $StringSelect.or($UserSelect).or($RoleSelect).or($MentionableSelect).or($ChannelSelect);
17
+ export const $ActionRow = Object.assign((...components) =>
18
+ // @ts-expect-error
19
+ type({ type: `${ComponentType.ActionRow}`, components }), {
20
+ $: type({ type: `${ComponentType.ActionRow}` }),
21
+ });
22
+ export const $Thumbnail = type({ type: `${ComponentType.Thumbnail}` });
23
+ export const $Section = Object.assign((components, accessory) =>
24
+ // @ts-expect-error
25
+ type({ type: `${ComponentType.Section}`, accessory, components }), { $: type({ type: `${ComponentType.Section}` }) });
26
+ export const $TextDisplay = type({ type: `${ComponentType.TextDisplay}` });
27
+ export const $MediaGallery = type({ type: `${ComponentType.MediaGallery}` });
28
+ export const $File = type({ type: `${ComponentType.File}` });
29
+ export const $Separator = type({ type: `${ComponentType.Separator}` });
30
+ const ComponentInContainer = type({ type: `${ComponentType.ActionRow}` })
31
+ .or($File)
32
+ .or($MediaGallery)
33
+ .or({ type: `${ComponentType.Section}` })
34
+ .or($Separator)
35
+ .or($TextDisplay);
36
+ export const $Container = Object.assign((...components) =>
37
+ // @ts-expect-error
38
+ type({ type: `${ComponentType.Container}`, components }), { $: type({ type: `${ComponentType.Container}` }) });
39
+ export const $TextInput = type({ type: `${ComponentType.TextInput}` });
40
+ export const $FileUpload = type({ type: `${ComponentType.FileUpload}` });
41
+ export const $RadioGroup = type({ type: `${ComponentType.RadioGroup}` });
42
+ export const $CheckboxGroup = type({ type: `${ComponentType.CheckboxGroup}` });
43
+ export const $Checkbox = type({ type: `${ComponentType.Checkbox}` });
44
+ const ComponentInLabel = AnySelect.or($TextInput).or($FileUpload).or($RadioGroup).or($CheckboxGroup).or($Checkbox);
45
+ export const $Label = Object.assign((component) =>
46
+ // @ts-expect-error
47
+ type({ type: `${ComponentType.Label}`, component }), { $: type({ type: `${ComponentType.Label}` }) });
48
+ export const $Any = Object.assign(type({ type: "number" }), {
49
+ ActionRow: AnyButton.or(AnySelect),
50
+ Button: AnyButton,
51
+ Container: ComponentInContainer,
52
+ Label: ComponentInLabel,
53
+ Section: { Component: $TextDisplay, Accessory: AnyButton.or($Thumbnail) },
54
+ Select: AnySelect,
55
+ });
56
+ function recurseFind(yesFn, components) {
34
57
  for (const component of components) {
35
- if ((typeof query === "number" && component.id === query) ||
36
- ("custom_id" in component &&
37
- ((typeof query === "string" && component.custom_id === query) ||
38
- (query instanceof RegExp && query.test(component.custom_id))))) {
58
+ if (yesFn(component))
39
59
  return component;
40
- }
41
60
  if ("components" in component) {
42
- const found = find(query, component.components);
61
+ const found = recurseFind(yesFn, component.components);
43
62
  if (found)
44
63
  return found;
45
64
  }
46
65
  if (component.type === ComponentType.Section && component.accessory) {
47
- const found = find(query, [component.accessory]);
66
+ const found = recurseFind(yesFn, [component.accessory]);
48
67
  if (found)
49
68
  return found;
50
69
  }
51
- }
52
- }
53
- function findParent(child, components) {
54
- if (components.includes(child))
55
- return components;
56
- for (const component of components) {
57
- if ("components" in component) {
58
- if (component.components.includes(child))
59
- return component;
60
- const found = findParent(child, component.components);
70
+ if (component.type === ComponentType.Label && component.component) {
71
+ const found = recurseFind(yesFn, [component.component]);
61
72
  if (found)
62
73
  return found;
63
74
  }
64
- if (component.type === ComponentType.Section && component.accessory === child) {
65
- return component;
66
- }
67
75
  }
68
76
  }
69
- /** Initiate a tree traverser. */
70
- export default function abseil(components) {
71
- function createTraverser(component, expected, previous, neighbours) {
72
- typesMatch(component, expected, true);
73
- const traverser = {
74
- value: component,
75
- update(v) {
76
- Object.assign(component, typeof v === "function" ? v(component) : v);
77
- return traverser;
78
- },
79
- parent(t) {
80
- const parentComponent = findParent(component, components);
81
- if (Array.isArray(parentComponent)) {
82
- typesMatch({ type: "Root" }, t, true);
83
- return { value: { components } };
84
- }
85
- if (!parentComponent) {
86
- throw new Error("This node does not have a parent");
77
+ const findParent = (node, components) => recurseFind((component) => ("components" in component && component.components.includes(node)) ||
78
+ ("accessory" in component && component.accessory === node) ||
79
+ ("component" in component && component.component === node), components);
80
+ /**
81
+ * Validates that {@link components} match the {@link schema} and creates traversal functions
82
+ * @returns Validated input components and functions for interacting with the layout
83
+ */
84
+ export default function abseil(components, schema) {
85
+ // @ts-expect-error
86
+ const layout = type(schema).assert(components);
87
+ const fns = {
88
+ parent(node, $component) {
89
+ const parent = findParent(node, layout);
90
+ return $component.allows(parent) ? parent : undefined;
91
+ },
92
+ remove(node) {
93
+ function r(components) {
94
+ if (!node)
95
+ return;
96
+ const index = components.indexOf(node);
97
+ if (index !== -1) {
98
+ components.splice(index, 1);
99
+ return;
87
100
  }
88
- const parentParent = findParent(parentComponent, components);
89
- return createTraverser(parentComponent, t, traverser, parentParent && "components" in parentParent ? parentParent.components : parentParent);
90
- },
91
- };
92
- if (previous)
93
- traverser.previous = previous;
94
- if (neighbours) {
95
- if (!selects.has(component.type)) {
96
- traverser.insertBefore = (v) => {
97
- neighbours.splice(neighbours.indexOf(component), 0, v);
98
- return traverser;
99
- };
100
- traverser.last = (t) => {
101
- for (let i = neighbours.length - 1; i >= 0; --i) {
102
- const sibling = neighbours[i];
103
- if (!typesMatch(sibling, t))
104
- continue;
105
- return createTraverser(sibling, t, traverser, neighbours);
101
+ for (const branch of components) {
102
+ if ("components" in branch) {
103
+ r(branch.components);
106
104
  }
107
- };
108
- traverser.next = (t) => {
109
- const next = neighbours.slice(neighbours.indexOf(component) + 1).find((s) => typesMatch(s, t));
110
- if (!next)
111
- return undefined;
112
- return createTraverser(next, t, traverser, neighbours);
113
- };
114
- }
115
- if (neighbours.length !== neighbours.indexOf(component) + 1) {
116
- traverser.sibling = (t) => createTraverser(neighbours[neighbours.indexOf(component) + 1], t, traverser, neighbours);
105
+ // @ts-expect-error
106
+ if ("accessory" in branch && branch.accessory === node)
107
+ delete branch.accessory;
108
+ // @ts-expect-error
109
+ if ("component" in branch && branch.component === node)
110
+ delete branch.component;
111
+ }
117
112
  }
118
- }
119
- if (withChildren.has(component.type) && "components" in component) {
120
- traverser.child = (t) => createTraverser(component.components[0], t, traverser, component.components);
121
- }
122
- if (component.type === ComponentType.Section) {
123
- traverser.accessory = (t) => createTraverser(component.accessory, t, traverser);
124
- }
125
- return traverser;
126
- }
127
- return {
128
- /**
129
- * Enter the tree at a specific node.
130
- * @param query Either the component `id` or `custom_id`
131
- */
132
- find(query, type) {
133
- const component = find(query, components);
134
- if (!component || !typesMatch(component, type))
135
- return undefined;
136
- const parent = findParent(component, components);
137
- return createTraverser(component, type, undefined, parent && "components" in parent ? parent.components : components);
113
+ r(layout);
114
+ },
115
+ search: (query, $component) => recurseFind((component) => ((typeof query === "number" && component.id === query) ||
116
+ ("custom_id" in component &&
117
+ ((typeof query === "string" && component.custom_id === query) ||
118
+ (query instanceof RegExp && query.test(component.custom_id)))) ||
119
+ (component.type === ComponentType.TextDisplay &&
120
+ ((typeof query === "string" && component.content.includes(query)) ||
121
+ (query instanceof RegExp && query.test(component.content))))) &&
122
+ $component.allows(component), layout),
123
+ sibling(node, $component, offset = 1) {
124
+ var _a, _b;
125
+ const neighbours = (_b = (_a = findParent(node, layout)) === null || _a === void 0 ? void 0 : _a.components) !== null && _b !== void 0 ? _b : layout;
126
+ const next = neighbours[neighbours.indexOf(node) + offset];
127
+ return $component.allows(next) ? next : undefined;
138
128
  },
139
- /** Entry point of the tree, visually this is the top-leftmost component. */
140
- initial: ((t) => createTraverser(components[0], t, undefined, components)),
141
129
  };
130
+ return Object.assign(layout, fns);
142
131
  }
143
- /**
144
- * Destroy a node in the tree.
145
- * Data on this node will be stripped, attempting to access most functions will throw.
146
- * @important This may cause issues when you try to navigate {@link abseil} instances you've previously created
147
- */
148
- export function removeNode(node) {
149
- const { components } = node.parent([
150
- "ActionRow",
151
- "Container",
152
- "Root",
153
- "Section",
154
- ]).value;
155
- components === null || components === void 0 ? void 0 : components.splice(components.indexOf(node.value), 1);
156
- for (const key of Object.keys(node)) {
157
- if (key === "previous" || key === "last")
158
- continue;
159
- node[key] = (key === "value"
160
- ? null
161
- : () => {
162
- throw new RangeError(`Unable to access ${key} on node as it was removed`);
163
- });
164
- }
165
- }
166
- /** Assert that a component is of certain type(s). */
167
- export const assert = (component, type) => typesMatch(component, type);
168
132
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAML,aAAa,GACd,MAAM,uBAAuB,CAAC;AA4F/B,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,CAAC,SAAS,EAAE,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;AAExG,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC;IACtB,aAAa,CAAC,YAAY;IAC1B,aAAa,CAAC,UAAU;IACxB,aAAa,CAAC,UAAU;IACxB,aAAa,CAAC,iBAAiB;IAC/B,aAAa,CAAC,aAAa;CAC5B,CAAC,CAAC;AAEH,SAAS,UAAU,CACjB,SAAiD,EACjD,QAA2B,EAC3B,eAAyB;IAEzB,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACjG,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,UAAU,GAAG,SAAS,CAAC,IAAI,KAAK,MAAM,CAAC,CA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M,CAAC,CAAC;YACpE,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QACpD,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAiC,CAAC;AACpE,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "abseil",
3
- "version": "0.4.0",
4
- "description": "Quickly traverse Discord Components V2 trees.",
3
+ "version": "0.5.0-canary.1",
4
+ "description": "Validate and traverse Discord Components V2 trees.",
5
5
  "scripts": {
6
6
  "dist": "rm -fr dist && tsc",
7
7
  "checks": "tsc --noEmit && biome check --write",
8
8
  "dry-publish": "bun publish --dry-run"
9
9
  },
10
10
  "dependencies": {
11
+ "arktype": "^2.2.0",
11
12
  "discord-api-types": "^0.38.42"
12
13
  },
13
14
  "devDependencies": {