@abyss-project/runtime 3.1.0 → 3.3.0
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 +36 -3
- package/dist/discord/discord.types.d.ts +79 -2
- package/dist/discord/discord.types.js +12 -1
- package/dist/discord/discord.types.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/schedule/schedule.types.d.ts +51 -0
- package/dist/schedule/schedule.types.js +23 -0
- package/dist/schedule/schedule.types.js.map +1 -0
- package/package.json +1 -1
- package/src/discord/discord.types.ts +279 -155
- package/src/index.ts +1 -0
- package/src/schedule/schedule.types.ts +98 -0
package/README.md
CHANGED
|
@@ -20,21 +20,54 @@ The host sends the names `collectGlobalReferences(definition, 'config')` finds.
|
|
|
20
20
|
|
|
21
21
|
A host that grants the `DiscordCapability` names (`discord.reply`, `discord.update`,
|
|
22
22
|
`discord.showModal`, `discord.followUp`, `discord.sendMessage`, `discord.editMessage`,
|
|
23
|
-
`discord.deleteMessage`, `discord.addRole`, `discord.removeRole`, `discord.sendDirectMessage
|
|
24
|
-
|
|
23
|
+
`discord.deleteMessage`, `discord.addRole`, `discord.removeRole`, `discord.sendDirectMessage`,
|
|
24
|
+
`discord.getMember`, `discord.getGuildRoles`, `discord.getChannel`, `discord.getGuild`) lets the
|
|
25
|
+
client code call `abyss.discord.<name>(...)`. Every helper always exists; one whose capability the
|
|
26
|
+
function does not declare rejects with an error naming the action to declare:
|
|
25
27
|
|
|
26
28
|
- `reply(message)`, `update(message)`, `followUp(message)`, `showModal({ customId, title, fields })`
|
|
27
29
|
- `sendMessage(channelId, message)`, `editMessage(channelId, messageId, message)`,
|
|
28
30
|
`deleteMessage(channelId, messageId)`, `sendDirectMessage(userId, message)`
|
|
29
31
|
- `addRole(guildId, userId, roleId)`, `removeRole(guildId, userId, roleId)`
|
|
32
|
+
- reads: `getMember(guildId, userId)` (a `DiscordMember`, or `null` when the user is not in the
|
|
33
|
+
server), `getGuildRoles(guildId)` (`DiscordRole[]`), `getChannel(channelId)` (`DiscordChannel`),
|
|
34
|
+
`getGuild(guildId)` (`DiscordGuild`). The shapes are Discord's in camelCase; permissions are
|
|
35
|
+
decimal strings, since they exceed 2^53.
|
|
30
36
|
|
|
31
|
-
`
|
|
37
|
+
`reply`, `update`, `showModal` and `followUp` need an interaction: in an execution no interaction
|
|
38
|
+
started (a task, a delayed run) the host rejects them with `NO_INTERACTION`.
|
|
39
|
+
|
|
40
|
+
`message` is a `DiscordMessage` (`{ content?, embeds?, components?, ephemeral?, allowedMentions? }`).
|
|
41
|
+
By default a message pings the users it mentions and nobody else: `@everyone`, `@here` and roles
|
|
42
|
+
stay plain text. `allowedMentions` (`DiscordAllowedMentions`: `parse` of `DiscordMentionType`
|
|
43
|
+
values, `users`, `roles`, `repliedUser`) replaces that default. The `args` of
|
|
32
44
|
each host `call` are the types `Discord*Args` (a `DiscordMessage` itself for `reply`, `update`,
|
|
33
45
|
`followUp`). A host failing a call with the message `<DiscordErrorCode>: <detail>` (or the bare
|
|
34
46
|
code) makes the helper throw an `Error` named `DiscordError` with `code` and `message` set; any
|
|
35
47
|
other failure is thrown unchanged. `DiscordInteractionInput` types the `input` of a function
|
|
36
48
|
triggered by a Discord interaction.
|
|
37
49
|
|
|
50
|
+
## Schedule helpers
|
|
51
|
+
|
|
52
|
+
A host that grants the `ScheduleCapability` names (`schedule.after`, `schedule.at`,
|
|
53
|
+
`schedule.cancel`) lets the client code schedule a delayed run of a named task. Every helper always
|
|
54
|
+
exists; one whose capability the function does not declare rejects with an error naming the action
|
|
55
|
+
to declare:
|
|
56
|
+
|
|
57
|
+
- `after(seconds, taskName, payload?, { key? })` and `at(isoDate, taskName, payload?, { key? })`
|
|
58
|
+
(`isoDate` an ISO 8601 string, or a `Date`) resolve to a `ScheduleResult` (`{ id, deduplicated }`).
|
|
59
|
+
While a run with the same `key` is pending, scheduling again returns its `id` with
|
|
60
|
+
`deduplicated: true`.
|
|
61
|
+
- `cancel(idOrKey)` resolves to a `ScheduleCancelResult` (`{ cancelled }`).
|
|
62
|
+
|
|
63
|
+
The `args` of each host `call` are `ScheduleAfterArgs`, `ScheduleAtArgs` and `ScheduleCancelArgs`
|
|
64
|
+
(`payload` and `key` left out when not given). A host failing a call with the message
|
|
65
|
+
`<ScheduleErrorCode>: <detail>` (or the bare code) makes the helper throw an `Error` named
|
|
66
|
+
`ScheduleError` with `code` and `message` set; any other failure is thrown unchanged.
|
|
67
|
+
`ScheduledRunInput` (`{ kind, task: { id, name }, scheduledFor, firedAt, attempt, payload? }`, `kind`
|
|
68
|
+
a `ScheduledRunKind`: `SCHEDULE` for a cron tick, `DELAYED` for a delayed run) types the `input` of a
|
|
69
|
+
function started by a task.
|
|
70
|
+
|
|
38
71
|
## Installation
|
|
39
72
|
|
|
40
73
|
```bash
|
|
@@ -9,23 +9,40 @@ export declare enum DiscordCapability {
|
|
|
9
9
|
DELETE_MESSAGE = "discord.deleteMessage",
|
|
10
10
|
ADD_ROLE = "discord.addRole",
|
|
11
11
|
REMOVE_ROLE = "discord.removeRole",
|
|
12
|
-
SEND_DIRECT_MESSAGE = "discord.sendDirectMessage"
|
|
12
|
+
SEND_DIRECT_MESSAGE = "discord.sendDirectMessage",
|
|
13
|
+
GET_MEMBER = "discord.getMember",
|
|
14
|
+
GET_GUILD_ROLES = "discord.getGuildRoles",
|
|
15
|
+
GET_CHANNEL = "discord.getChannel",
|
|
16
|
+
GET_GUILD = "discord.getGuild"
|
|
13
17
|
}
|
|
14
18
|
export declare enum DiscordErrorCode {
|
|
15
19
|
MODAL_TOO_LATE = "MODAL_TOO_LATE",
|
|
16
20
|
DISCORD_TOKEN_INVALID = "DISCORD_TOKEN_INVALID",
|
|
17
21
|
DISCORD_FORBIDDEN = "DISCORD_FORBIDDEN",
|
|
18
22
|
DISCORD_NOT_FOUND = "DISCORD_NOT_FOUND",
|
|
19
|
-
DISCORD_RATE_LIMITED = "DISCORD_RATE_LIMITED"
|
|
23
|
+
DISCORD_RATE_LIMITED = "DISCORD_RATE_LIMITED",
|
|
24
|
+
NO_INTERACTION = "NO_INTERACTION"
|
|
20
25
|
}
|
|
21
26
|
export type DiscordJsonObject = {
|
|
22
27
|
[key: string]: JSONValue;
|
|
23
28
|
};
|
|
29
|
+
export declare enum DiscordMentionType {
|
|
30
|
+
USERS = "users",
|
|
31
|
+
ROLES = "roles",
|
|
32
|
+
EVERYONE = "everyone"
|
|
33
|
+
}
|
|
34
|
+
export interface DiscordAllowedMentions {
|
|
35
|
+
parse?: DiscordMentionType[];
|
|
36
|
+
users?: string[];
|
|
37
|
+
roles?: string[];
|
|
38
|
+
repliedUser?: boolean;
|
|
39
|
+
}
|
|
24
40
|
export interface DiscordMessage {
|
|
25
41
|
content?: string;
|
|
26
42
|
embeds?: DiscordJsonObject[];
|
|
27
43
|
components?: DiscordJsonObject[];
|
|
28
44
|
ephemeral?: boolean;
|
|
45
|
+
allowedMentions?: DiscordAllowedMentions;
|
|
29
46
|
}
|
|
30
47
|
export declare enum DiscordModalFieldStyle {
|
|
31
48
|
SHORT = "SHORT",
|
|
@@ -68,6 +85,66 @@ export interface DiscordSendDirectMessageArgs {
|
|
|
68
85
|
userId: string;
|
|
69
86
|
message: DiscordMessage;
|
|
70
87
|
}
|
|
88
|
+
export interface DiscordGetMemberArgs {
|
|
89
|
+
guildId: string;
|
|
90
|
+
userId: string;
|
|
91
|
+
}
|
|
92
|
+
export interface DiscordGetGuildRolesArgs {
|
|
93
|
+
guildId: string;
|
|
94
|
+
}
|
|
95
|
+
export interface DiscordGetChannelArgs {
|
|
96
|
+
channelId: string;
|
|
97
|
+
}
|
|
98
|
+
export interface DiscordGetGuildArgs {
|
|
99
|
+
guildId: string;
|
|
100
|
+
}
|
|
101
|
+
export interface DiscordUser {
|
|
102
|
+
id: string;
|
|
103
|
+
username: string;
|
|
104
|
+
globalName: string | null;
|
|
105
|
+
bot: boolean;
|
|
106
|
+
}
|
|
107
|
+
export interface DiscordMember {
|
|
108
|
+
userId: string;
|
|
109
|
+
nick: string | null;
|
|
110
|
+
roles: string[];
|
|
111
|
+
joinedAt: string | null;
|
|
112
|
+
premiumSince: string | null;
|
|
113
|
+
communicationDisabledUntil: string | null;
|
|
114
|
+
pending: boolean;
|
|
115
|
+
avatar: string | null;
|
|
116
|
+
user: DiscordUser;
|
|
117
|
+
}
|
|
118
|
+
export interface DiscordRole {
|
|
119
|
+
id: string;
|
|
120
|
+
name: string;
|
|
121
|
+
color: number;
|
|
122
|
+
position: number;
|
|
123
|
+
permissions: string;
|
|
124
|
+
managed: boolean;
|
|
125
|
+
mentionable: boolean;
|
|
126
|
+
hoist: boolean;
|
|
127
|
+
}
|
|
128
|
+
export interface DiscordChannel {
|
|
129
|
+
id: string;
|
|
130
|
+
type: number;
|
|
131
|
+
name: string | null;
|
|
132
|
+
guildId: string | null;
|
|
133
|
+
parentId: string | null;
|
|
134
|
+
topic: string | null;
|
|
135
|
+
nsfw: boolean;
|
|
136
|
+
position: number | null;
|
|
137
|
+
}
|
|
138
|
+
export interface DiscordGuild {
|
|
139
|
+
id: string;
|
|
140
|
+
name: string;
|
|
141
|
+
icon: string | null;
|
|
142
|
+
ownerId: string;
|
|
143
|
+
preferredLocale: string;
|
|
144
|
+
roles: DiscordRole[];
|
|
145
|
+
approximateMemberCount: number | null;
|
|
146
|
+
approximatePresenceCount: number | null;
|
|
147
|
+
}
|
|
71
148
|
export declare enum DiscordInteractionKind {
|
|
72
149
|
COMMAND = "COMMAND",
|
|
73
150
|
COMPONENT = "COMPONENT",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EPHEMERAL_FLAG = exports.DiscordCallbackType = exports.DiscordInteractionType = exports.DiscordInteractionKind = exports.DiscordModalFieldStyle = exports.DiscordErrorCode = exports.DiscordCapability = void 0;
|
|
3
|
+
exports.EPHEMERAL_FLAG = exports.DiscordCallbackType = exports.DiscordInteractionType = exports.DiscordInteractionKind = exports.DiscordModalFieldStyle = exports.DiscordMentionType = exports.DiscordErrorCode = exports.DiscordCapability = void 0;
|
|
4
4
|
var DiscordCapability;
|
|
5
5
|
(function (DiscordCapability) {
|
|
6
6
|
DiscordCapability["REPLY"] = "discord.reply";
|
|
@@ -13,6 +13,10 @@ var DiscordCapability;
|
|
|
13
13
|
DiscordCapability["ADD_ROLE"] = "discord.addRole";
|
|
14
14
|
DiscordCapability["REMOVE_ROLE"] = "discord.removeRole";
|
|
15
15
|
DiscordCapability["SEND_DIRECT_MESSAGE"] = "discord.sendDirectMessage";
|
|
16
|
+
DiscordCapability["GET_MEMBER"] = "discord.getMember";
|
|
17
|
+
DiscordCapability["GET_GUILD_ROLES"] = "discord.getGuildRoles";
|
|
18
|
+
DiscordCapability["GET_CHANNEL"] = "discord.getChannel";
|
|
19
|
+
DiscordCapability["GET_GUILD"] = "discord.getGuild";
|
|
16
20
|
})(DiscordCapability || (exports.DiscordCapability = DiscordCapability = {}));
|
|
17
21
|
var DiscordErrorCode;
|
|
18
22
|
(function (DiscordErrorCode) {
|
|
@@ -21,7 +25,14 @@ var DiscordErrorCode;
|
|
|
21
25
|
DiscordErrorCode["DISCORD_FORBIDDEN"] = "DISCORD_FORBIDDEN";
|
|
22
26
|
DiscordErrorCode["DISCORD_NOT_FOUND"] = "DISCORD_NOT_FOUND";
|
|
23
27
|
DiscordErrorCode["DISCORD_RATE_LIMITED"] = "DISCORD_RATE_LIMITED";
|
|
28
|
+
DiscordErrorCode["NO_INTERACTION"] = "NO_INTERACTION";
|
|
24
29
|
})(DiscordErrorCode || (exports.DiscordErrorCode = DiscordErrorCode = {}));
|
|
30
|
+
var DiscordMentionType;
|
|
31
|
+
(function (DiscordMentionType) {
|
|
32
|
+
DiscordMentionType["USERS"] = "users";
|
|
33
|
+
DiscordMentionType["ROLES"] = "roles";
|
|
34
|
+
DiscordMentionType["EVERYONE"] = "everyone";
|
|
35
|
+
})(DiscordMentionType || (exports.DiscordMentionType = DiscordMentionType = {}));
|
|
25
36
|
var DiscordModalFieldStyle;
|
|
26
37
|
(function (DiscordModalFieldStyle) {
|
|
27
38
|
DiscordModalFieldStyle["SHORT"] = "SHORT";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discord.types.js","sourceRoot":"","sources":["../../src/discord/discord.types.ts"],"names":[],"mappings":";;;AAOA,IAAY,
|
|
1
|
+
{"version":3,"file":"discord.types.js","sourceRoot":"","sources":["../../src/discord/discord.types.ts"],"names":[],"mappings":";;;AAOA,IAAY,iBA6BX;AA7BD,WAAY,iBAAiB;IAE3B,4CAAuB,CAAA;IAEvB,8CAAyB,CAAA;IAEzB,qDAAgC,CAAA;IAEhC,mDAA8B,CAAA;IAE9B,yDAAoC,CAAA;IAEpC,yDAAoC,CAAA;IAEpC,6DAAwC,CAAA;IAExC,iDAA4B,CAAA;IAE5B,uDAAkC,CAAA;IAElC,sEAAiD,CAAA;IAEjD,qDAAgC,CAAA;IAEhC,8DAAyC,CAAA;IAEzC,uDAAkC,CAAA;IAElC,mDAA8B,CAAA;AAChC,CAAC,EA7BW,iBAAiB,iCAAjB,iBAAiB,QA6B5B;AAOD,IAAY,gBAgBX;AAhBD,WAAY,gBAAgB;IAE1B,qDAAiC,CAAA;IAEjC,mEAA+C,CAAA;IAE/C,2DAAuC,CAAA;IAEvC,2DAAuC,CAAA;IAEvC,iEAA6C,CAAA;IAK7C,qDAAiC,CAAA;AACnC,CAAC,EAhBW,gBAAgB,gCAAhB,gBAAgB,QAgB3B;AASD,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,qCAAe,CAAA;IACf,qCAAe,CAAA;IACf,2CAAqB,CAAA;AACvB,CAAC,EAJW,kBAAkB,kCAAlB,kBAAkB,QAI7B;AA2BD,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,iDAAuB,CAAA;AACzB,CAAC,EAHW,sBAAsB,sCAAtB,sBAAsB,QAGjC;AAoID,IAAY,sBAIX;AAJD,WAAY,sBAAsB;IAChC,6CAAmB,CAAA;IACnB,iDAAuB,CAAA;IACvB,yCAAe,CAAA;AACjB,CAAC,EAJW,sBAAsB,sCAAtB,sBAAsB,QAIjC;AAGD,IAAY,sBAKX;AALD,WAAY,sBAAsB;IAChC,mEAAQ,CAAA;IACR,iGAAuB,CAAA;IACvB,6FAAqB,CAAA;IACrB,mFAAgB,CAAA;AAClB,CAAC,EALW,sBAAsB,sCAAtB,sBAAsB,QAKjC;AAGD,IAAY,mBAOX;AAPD,WAAY,mBAAmB;IAC7B,6DAAQ,CAAA;IACR,2GAA+B,CAAA;IAC/B,6HAAwC,CAAA;IACxC,mGAA2B,CAAA;IAC3B,iFAAkB,CAAA;IAClB,+DAAS,CAAA;AACX,CAAC,EAPW,mBAAmB,mCAAnB,mBAAmB,QAO9B;AAGY,QAAA,cAAc,GAAG,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export { InterpreterError } from './interpreter/interpreter-error';
|
|
|
13
13
|
export { runToCompletion } from './interpreter/test-host';
|
|
14
14
|
export type { TestHostHandlers, TestRunResult } from './interpreter/test-host';
|
|
15
15
|
export * from './discord/discord.types';
|
|
16
|
+
export * from './schedule/schedule.types';
|
|
16
17
|
export * from './runner-protocol/evaluation.types';
|
|
17
18
|
export * from './runner-protocol/execution-protocol.types';
|
|
18
19
|
export { runInIsolate, EngineResultKind } from './engine/run-in-isolate';
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "InterpreterError", { enumerable: true, get: func
|
|
|
35
35
|
var test_host_1 = require("./interpreter/test-host");
|
|
36
36
|
Object.defineProperty(exports, "runToCompletion", { enumerable: true, get: function () { return test_host_1.runToCompletion; } });
|
|
37
37
|
__exportStar(require("./discord/discord.types"), exports);
|
|
38
|
+
__exportStar(require("./schedule/schedule.types"), exports);
|
|
38
39
|
__exportStar(require("./runner-protocol/evaluation.types"), exports);
|
|
39
40
|
__exportStar(require("./runner-protocol/execution-protocol.types"), exports);
|
|
40
41
|
var run_in_isolate_1 = require("./engine/run-in-isolate");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAGA,mEAAiD;AACjD,wDAAsC;AACtC,kDAAkD;AAAzC,yGAAA,WAAW,OAAA;AACpB,gEAA8C;AAC9C,wEAAsE;AAA7D,yHAAA,kBAAkB,OAAA;AAE3B,oEAAsE;AAA7D,yHAAA,oBAAoB,OAAA;AAC7B,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAElB,kEAAgD;AAChD,yDAAwD;AAA/C,oGAAA,KAAK,OAAA;AAAE,mGAAA,IAAI,OAAA;AACpB,qEAAmE;AAA1D,qHAAA,gBAAgB,OAAA;AACzB,qDAA0D;AAAjD,4GAAA,eAAe,OAAA;AAExB,0DAAwC;AACxC,qEAAmD;AACnD,6EAA2D;AAC3D,0DAAyE;AAAhE,8GAAA,YAAY,OAAA;AAAE,kHAAA,gBAAgB,OAAA;AAQvC,wDAA4D;AAAnD,mHAAA,kBAAkB,OAAA;AAC3B,+DAAoE;AAA3D,4HAAA,uBAAuB,OAAA;AAChC,wDAAsC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAGA,mEAAiD;AACjD,wDAAsC;AACtC,kDAAkD;AAAzC,yGAAA,WAAW,OAAA;AACpB,gEAA8C;AAC9C,wEAAsE;AAA7D,yHAAA,kBAAkB,OAAA;AAE3B,oEAAsE;AAA7D,yHAAA,oBAAoB,OAAA;AAC7B,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAElB,kEAAgD;AAChD,yDAAwD;AAA/C,oGAAA,KAAK,OAAA;AAAE,mGAAA,IAAI,OAAA;AACpB,qEAAmE;AAA1D,qHAAA,gBAAgB,OAAA;AACzB,qDAA0D;AAAjD,4GAAA,eAAe,OAAA;AAExB,0DAAwC;AACxC,4DAA0C;AAC1C,qEAAmD;AACnD,6EAA2D;AAC3D,0DAAyE;AAAhE,8GAAA,YAAY,OAAA;AAAE,kHAAA,gBAAgB,OAAA;AAQvC,wDAA4D;AAAnD,mHAAA,kBAAkB,OAAA;AAC3B,+DAAoE;AAA3D,4HAAA,uBAAuB,OAAA;AAChC,wDAAsC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { JSONValue } from '../runner-protocol/execution-protocol.types';
|
|
2
|
+
export declare enum ScheduleCapability {
|
|
3
|
+
SCHEDULE_AFTER = "schedule.after",
|
|
4
|
+
SCHEDULE_AT = "schedule.at",
|
|
5
|
+
SCHEDULE_CANCEL = "schedule.cancel"
|
|
6
|
+
}
|
|
7
|
+
export declare enum ScheduleErrorCode {
|
|
8
|
+
SCHEDULE_TASK_UNKNOWN = "SCHEDULE_TASK_UNKNOWN",
|
|
9
|
+
SCHEDULE_HORIZON_EXCEEDED = "SCHEDULE_HORIZON_EXCEEDED",
|
|
10
|
+
SCHEDULE_LIMIT_REACHED = "SCHEDULE_LIMIT_REACHED",
|
|
11
|
+
SCHEDULE_PAYLOAD_TOO_LARGE = "SCHEDULE_PAYLOAD_TOO_LARGE",
|
|
12
|
+
SCHEDULE_INVALID = "SCHEDULE_INVALID"
|
|
13
|
+
}
|
|
14
|
+
export interface ScheduleOptions {
|
|
15
|
+
key?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ScheduleAfterArgs extends ScheduleOptions {
|
|
18
|
+
seconds: number;
|
|
19
|
+
taskName: string;
|
|
20
|
+
payload?: JSONValue;
|
|
21
|
+
}
|
|
22
|
+
export interface ScheduleAtArgs extends ScheduleOptions {
|
|
23
|
+
at: string;
|
|
24
|
+
taskName: string;
|
|
25
|
+
payload?: JSONValue;
|
|
26
|
+
}
|
|
27
|
+
export interface ScheduleCancelArgs {
|
|
28
|
+
idOrKey: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ScheduleResult {
|
|
31
|
+
id: string;
|
|
32
|
+
deduplicated: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface ScheduleCancelResult {
|
|
35
|
+
cancelled: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare enum ScheduledRunKind {
|
|
38
|
+
SCHEDULE = "SCHEDULE",
|
|
39
|
+
DELAYED = "DELAYED"
|
|
40
|
+
}
|
|
41
|
+
export interface ScheduledRunInput {
|
|
42
|
+
kind: ScheduledRunKind;
|
|
43
|
+
task: {
|
|
44
|
+
id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
};
|
|
47
|
+
scheduledFor: string;
|
|
48
|
+
firedAt: string;
|
|
49
|
+
attempt: number;
|
|
50
|
+
payload?: JSONValue;
|
|
51
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScheduledRunKind = exports.ScheduleErrorCode = exports.ScheduleCapability = void 0;
|
|
4
|
+
var ScheduleCapability;
|
|
5
|
+
(function (ScheduleCapability) {
|
|
6
|
+
ScheduleCapability["SCHEDULE_AFTER"] = "schedule.after";
|
|
7
|
+
ScheduleCapability["SCHEDULE_AT"] = "schedule.at";
|
|
8
|
+
ScheduleCapability["SCHEDULE_CANCEL"] = "schedule.cancel";
|
|
9
|
+
})(ScheduleCapability || (exports.ScheduleCapability = ScheduleCapability = {}));
|
|
10
|
+
var ScheduleErrorCode;
|
|
11
|
+
(function (ScheduleErrorCode) {
|
|
12
|
+
ScheduleErrorCode["SCHEDULE_TASK_UNKNOWN"] = "SCHEDULE_TASK_UNKNOWN";
|
|
13
|
+
ScheduleErrorCode["SCHEDULE_HORIZON_EXCEEDED"] = "SCHEDULE_HORIZON_EXCEEDED";
|
|
14
|
+
ScheduleErrorCode["SCHEDULE_LIMIT_REACHED"] = "SCHEDULE_LIMIT_REACHED";
|
|
15
|
+
ScheduleErrorCode["SCHEDULE_PAYLOAD_TOO_LARGE"] = "SCHEDULE_PAYLOAD_TOO_LARGE";
|
|
16
|
+
ScheduleErrorCode["SCHEDULE_INVALID"] = "SCHEDULE_INVALID";
|
|
17
|
+
})(ScheduleErrorCode || (exports.ScheduleErrorCode = ScheduleErrorCode = {}));
|
|
18
|
+
var ScheduledRunKind;
|
|
19
|
+
(function (ScheduledRunKind) {
|
|
20
|
+
ScheduledRunKind["SCHEDULE"] = "SCHEDULE";
|
|
21
|
+
ScheduledRunKind["DELAYED"] = "DELAYED";
|
|
22
|
+
})(ScheduledRunKind || (exports.ScheduledRunKind = ScheduledRunKind = {}));
|
|
23
|
+
//# sourceMappingURL=schedule.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schedule.types.js","sourceRoot":"","sources":["../../src/schedule/schedule.types.ts"],"names":[],"mappings":";;;AAQA,IAAY,kBAOX;AAPD,WAAY,kBAAkB;IAE5B,uDAAiC,CAAA;IAEjC,iDAA2B,CAAA;IAE3B,yDAAmC,CAAA;AACrC,CAAC,EAPW,kBAAkB,kCAAlB,kBAAkB,QAO7B;AAOD,IAAY,iBAWX;AAXD,WAAY,iBAAiB;IAE3B,oEAA+C,CAAA;IAE/C,4EAAuD,CAAA;IAEvD,sEAAiD,CAAA;IAEjD,8EAAyD,CAAA;IAEzD,0DAAqC,CAAA;AACvC,CAAC,EAXW,iBAAiB,iCAAjB,iBAAiB,QAW5B;AA+CD,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,yCAAqB,CAAA;IACrB,uCAAmB,CAAA;AACrB,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B"}
|
package/package.json
CHANGED
|
@@ -1,155 +1,279 @@
|
|
|
1
|
-
import type { JSONValue } from '../runner-protocol/execution-protocol.types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Host capabilities of a Discord bot Service. The host declares them in the execution's
|
|
5
|
-
* capabilities; client code reaches them through `abyss.discord.<name>(...)
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export enum DiscordCapability {
|
|
9
|
-
/** Answers the interaction. Arguments: a `DiscordMessage`. */
|
|
10
|
-
REPLY = 'discord.reply',
|
|
11
|
-
/** Edits the message a component interaction came from. Arguments: a `DiscordMessage`. */
|
|
12
|
-
UPDATE = 'discord.update',
|
|
13
|
-
/** Opens a modal, before the interaction is acknowledged. Arguments: `DiscordShowModalArgs`. */
|
|
14
|
-
SHOW_MODAL = 'discord.showModal',
|
|
15
|
-
/** Sends an additional message for the interaction. Arguments: a `DiscordMessage`. */
|
|
16
|
-
FOLLOW_UP = 'discord.followUp',
|
|
17
|
-
/** Posts a message in a channel as the bot. Arguments: `DiscordSendMessageArgs`. */
|
|
18
|
-
SEND_MESSAGE = 'discord.sendMessage',
|
|
19
|
-
/** Edits a message of the bot. Arguments: `DiscordEditMessageArgs`. */
|
|
20
|
-
EDIT_MESSAGE = 'discord.editMessage',
|
|
21
|
-
/** Deletes a message. Arguments: `DiscordDeleteMessageArgs`. */
|
|
22
|
-
DELETE_MESSAGE = 'discord.deleteMessage',
|
|
23
|
-
/** Gives a role to a member. Arguments: `DiscordRoleArgs`. */
|
|
24
|
-
ADD_ROLE = 'discord.addRole',
|
|
25
|
-
/** Takes a role from a member. Arguments: `DiscordRoleArgs`. */
|
|
26
|
-
REMOVE_ROLE = 'discord.removeRole',
|
|
27
|
-
/** Sends a direct message to a user. Arguments: `DiscordSendDirectMessageArgs`. */
|
|
28
|
-
SEND_DIRECT_MESSAGE = 'discord.sendDirectMessage',
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export interface
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
guildId
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
1
|
+
import type { JSONValue } from '../runner-protocol/execution-protocol.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Host capabilities of a Discord bot Service. The host declares them in the execution's
|
|
5
|
+
* capabilities; client code reaches them through `abyss.discord.<name>(...)`; every helper exists,
|
|
6
|
+
* and one whose capability is not granted rejects with an error naming the action to declare. The argument shapes below are the `args` of the `call`.
|
|
7
|
+
*/
|
|
8
|
+
export enum DiscordCapability {
|
|
9
|
+
/** Answers the interaction. Arguments: a `DiscordMessage`. */
|
|
10
|
+
REPLY = 'discord.reply',
|
|
11
|
+
/** Edits the message a component interaction came from. Arguments: a `DiscordMessage`. */
|
|
12
|
+
UPDATE = 'discord.update',
|
|
13
|
+
/** Opens a modal, before the interaction is acknowledged. Arguments: `DiscordShowModalArgs`. */
|
|
14
|
+
SHOW_MODAL = 'discord.showModal',
|
|
15
|
+
/** Sends an additional message for the interaction. Arguments: a `DiscordMessage`. */
|
|
16
|
+
FOLLOW_UP = 'discord.followUp',
|
|
17
|
+
/** Posts a message in a channel as the bot. Arguments: `DiscordSendMessageArgs`. */
|
|
18
|
+
SEND_MESSAGE = 'discord.sendMessage',
|
|
19
|
+
/** Edits a message of the bot. Arguments: `DiscordEditMessageArgs`. */
|
|
20
|
+
EDIT_MESSAGE = 'discord.editMessage',
|
|
21
|
+
/** Deletes a message. Arguments: `DiscordDeleteMessageArgs`. */
|
|
22
|
+
DELETE_MESSAGE = 'discord.deleteMessage',
|
|
23
|
+
/** Gives a role to a member. Arguments: `DiscordRoleArgs`. */
|
|
24
|
+
ADD_ROLE = 'discord.addRole',
|
|
25
|
+
/** Takes a role from a member. Arguments: `DiscordRoleArgs`. */
|
|
26
|
+
REMOVE_ROLE = 'discord.removeRole',
|
|
27
|
+
/** Sends a direct message to a user. Arguments: `DiscordSendDirectMessageArgs`. */
|
|
28
|
+
SEND_DIRECT_MESSAGE = 'discord.sendDirectMessage',
|
|
29
|
+
/** Reads a member of a server. Arguments: `DiscordGetMemberArgs`; result: `DiscordMember | null`. */
|
|
30
|
+
GET_MEMBER = 'discord.getMember',
|
|
31
|
+
/** Reads the roles of a server. Arguments: `DiscordGetGuildRolesArgs`; result: `DiscordRole[]`. */
|
|
32
|
+
GET_GUILD_ROLES = 'discord.getGuildRoles',
|
|
33
|
+
/** Reads a channel. Arguments: `DiscordGetChannelArgs`; result: `DiscordChannel`. */
|
|
34
|
+
GET_CHANNEL = 'discord.getChannel',
|
|
35
|
+
/** Reads a server. Arguments: `DiscordGetGuildArgs`; result: `DiscordGuild`. */
|
|
36
|
+
GET_GUILD = 'discord.getGuild',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Codes of the errors `abyss.discord.*` throws. The host fails the call with the message
|
|
41
|
+
* `<code>: <detail>` (or the bare code); the helper rethrows an `Error` named `DiscordError`
|
|
42
|
+
* whose `code` is the code and whose `message` is the detail.
|
|
43
|
+
*/
|
|
44
|
+
export enum DiscordErrorCode {
|
|
45
|
+
/** `showModal` after the interaction was acknowledged (more than 2.5 s after it arrived). */
|
|
46
|
+
MODAL_TOO_LATE = 'MODAL_TOO_LATE',
|
|
47
|
+
/** The bot's token is refused (circuit breaker open): no call was made to Discord. */
|
|
48
|
+
DISCORD_TOKEN_INVALID = 'DISCORD_TOKEN_INVALID',
|
|
49
|
+
/** Discord answered 403. */
|
|
50
|
+
DISCORD_FORBIDDEN = 'DISCORD_FORBIDDEN',
|
|
51
|
+
/** Discord answered 404. */
|
|
52
|
+
DISCORD_NOT_FOUND = 'DISCORD_NOT_FOUND',
|
|
53
|
+
/** Discord answered 429. */
|
|
54
|
+
DISCORD_RATE_LIMITED = 'DISCORD_RATE_LIMITED',
|
|
55
|
+
/**
|
|
56
|
+
* `reply`, `update`, `showModal` or `followUp` in an execution no interaction started (a task,
|
|
57
|
+
* a delayed run): there is no interaction to answer.
|
|
58
|
+
*/
|
|
59
|
+
NO_INTERACTION = 'NO_INTERACTION',
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Embed and component payloads are Discord's own JSON, relayed as is. */
|
|
63
|
+
export type DiscordJsonObject = { [key: string]: JSONValue };
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* What a message may notify. `users` and `roles` let the mentions of every user or role ping;
|
|
67
|
+
* `everyone` lets `@everyone` and `@here` notify the whole server.
|
|
68
|
+
*/
|
|
69
|
+
export enum DiscordMentionType {
|
|
70
|
+
USERS = 'users',
|
|
71
|
+
ROLES = 'roles',
|
|
72
|
+
EVERYONE = 'everyone',
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Who a message may notify: Discord's `allowed_mentions` in camelCase. Without it a message pings
|
|
77
|
+
* the users it mentions and nobody else: `@everyone`, `@here` and roles stay plain text. An object
|
|
78
|
+
* replaces that default as a whole, so what it leaves out notifies nobody. `parse` allows every
|
|
79
|
+
* mention of a type; `users` and `roles` allow those ids only (at most 100 each). A type is given
|
|
80
|
+
* by `parse` or by its list, never both. `repliedUser` is Discord's reply ping.
|
|
81
|
+
*/
|
|
82
|
+
export interface DiscordAllowedMentions {
|
|
83
|
+
parse?: DiscordMentionType[];
|
|
84
|
+
users?: string[];
|
|
85
|
+
roles?: string[];
|
|
86
|
+
repliedUser?: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface DiscordMessage {
|
|
90
|
+
content?: string;
|
|
91
|
+
embeds?: DiscordJsonObject[];
|
|
92
|
+
components?: DiscordJsonObject[];
|
|
93
|
+
/** Only the reply to an interaction can be ephemeral. */
|
|
94
|
+
ephemeral?: boolean;
|
|
95
|
+
/** Who the message may notify; by default the mentioned users only (see `DiscordAllowedMentions`). */
|
|
96
|
+
allowedMentions?: DiscordAllowedMentions;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Text input style of a modal field. */
|
|
100
|
+
export enum DiscordModalFieldStyle {
|
|
101
|
+
SHORT = 'SHORT',
|
|
102
|
+
PARAGRAPH = 'PARAGRAPH',
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface DiscordModalField {
|
|
106
|
+
customId: string;
|
|
107
|
+
label: string;
|
|
108
|
+
style?: DiscordModalFieldStyle;
|
|
109
|
+
required?: boolean;
|
|
110
|
+
placeholder?: string;
|
|
111
|
+
value?: string;
|
|
112
|
+
minLength?: number;
|
|
113
|
+
maxLength?: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface DiscordShowModalArgs {
|
|
117
|
+
customId: string;
|
|
118
|
+
title: string;
|
|
119
|
+
fields: DiscordModalField[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface DiscordSendMessageArgs {
|
|
123
|
+
channelId: string;
|
|
124
|
+
message: DiscordMessage;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface DiscordEditMessageArgs {
|
|
128
|
+
channelId: string;
|
|
129
|
+
messageId: string;
|
|
130
|
+
message: DiscordMessage;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface DiscordDeleteMessageArgs {
|
|
134
|
+
channelId: string;
|
|
135
|
+
messageId: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface DiscordRoleArgs {
|
|
139
|
+
guildId: string;
|
|
140
|
+
userId: string;
|
|
141
|
+
roleId: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface DiscordSendDirectMessageArgs {
|
|
145
|
+
userId: string;
|
|
146
|
+
message: DiscordMessage;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface DiscordGetMemberArgs {
|
|
150
|
+
guildId: string;
|
|
151
|
+
userId: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface DiscordGetGuildRolesArgs {
|
|
155
|
+
guildId: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface DiscordGetChannelArgs {
|
|
159
|
+
channelId: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface DiscordGetGuildArgs {
|
|
163
|
+
guildId: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** A Discord user, as the reads return it. */
|
|
167
|
+
export interface DiscordUser {
|
|
168
|
+
id: string;
|
|
169
|
+
username: string;
|
|
170
|
+
globalName: string | null;
|
|
171
|
+
bot: boolean;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* A member of a server (`discord.getMember`): Discord's guild member in camelCase. The read gives
|
|
176
|
+
* `null` instead when the user is not in the server. Dates are ISO 8601.
|
|
177
|
+
*/
|
|
178
|
+
export interface DiscordMember {
|
|
179
|
+
userId: string;
|
|
180
|
+
nick: string | null;
|
|
181
|
+
/** Role ids. */
|
|
182
|
+
roles: string[];
|
|
183
|
+
joinedAt: string | null;
|
|
184
|
+
premiumSince: string | null;
|
|
185
|
+
communicationDisabledUntil: string | null;
|
|
186
|
+
/** True while the member has not passed the server's membership screening. */
|
|
187
|
+
pending: boolean;
|
|
188
|
+
/** Avatar hash specific to the server. */
|
|
189
|
+
avatar: string | null;
|
|
190
|
+
user: DiscordUser;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A role of a server (`discord.getGuildRoles`, `DiscordGuild.roles`). `permissions` is Discord's
|
|
195
|
+
* permission bit set as a decimal string: it exceeds 2^53.
|
|
196
|
+
*/
|
|
197
|
+
export interface DiscordRole {
|
|
198
|
+
id: string;
|
|
199
|
+
name: string;
|
|
200
|
+
/** RGB color as an integer, 0 for none. */
|
|
201
|
+
color: number;
|
|
202
|
+
position: number;
|
|
203
|
+
permissions: string;
|
|
204
|
+
managed: boolean;
|
|
205
|
+
mentionable: boolean;
|
|
206
|
+
hoist: boolean;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** A channel (`discord.getChannel`). `type` is Discord's channel type number. */
|
|
210
|
+
export interface DiscordChannel {
|
|
211
|
+
id: string;
|
|
212
|
+
type: number;
|
|
213
|
+
name: string | null;
|
|
214
|
+
guildId: string | null;
|
|
215
|
+
parentId: string | null;
|
|
216
|
+
topic: string | null;
|
|
217
|
+
nsfw: boolean;
|
|
218
|
+
position: number | null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** A server (`discord.getGuild`). The approximate counts are null when Discord does not give them. */
|
|
222
|
+
export interface DiscordGuild {
|
|
223
|
+
id: string;
|
|
224
|
+
name: string;
|
|
225
|
+
/** Icon hash. */
|
|
226
|
+
icon: string | null;
|
|
227
|
+
ownerId: string;
|
|
228
|
+
preferredLocale: string;
|
|
229
|
+
roles: DiscordRole[];
|
|
230
|
+
approximateMemberCount: number | null;
|
|
231
|
+
approximatePresenceCount: number | null;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The kind of interaction a function was started by. */
|
|
235
|
+
export enum DiscordInteractionKind {
|
|
236
|
+
COMMAND = 'COMMAND',
|
|
237
|
+
COMPONENT = 'COMPONENT',
|
|
238
|
+
MODAL = 'MODAL',
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Discord's interaction types (`type` of the payload) a bot's edge serves. */
|
|
242
|
+
export enum DiscordInteractionType {
|
|
243
|
+
PING = 1,
|
|
244
|
+
APPLICATION_COMMAND = 2,
|
|
245
|
+
MESSAGE_COMPONENT = 3,
|
|
246
|
+
MODAL_SUBMIT = 5,
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Discord's interaction callback types the edge answers with. */
|
|
250
|
+
export enum DiscordCallbackType {
|
|
251
|
+
PONG = 1,
|
|
252
|
+
CHANNEL_MESSAGE_WITH_SOURCE = 4,
|
|
253
|
+
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5,
|
|
254
|
+
DEFERRED_UPDATE_MESSAGE = 6,
|
|
255
|
+
UPDATE_MESSAGE = 7,
|
|
256
|
+
MODAL = 9,
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Discord's message flag that makes a message visible to its recipient only. */
|
|
260
|
+
export const EPHEMERAL_FLAG = 64;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* The `input` of a function triggered by a Discord interaction. The interaction token never
|
|
264
|
+
* appears here: it stays in the edge.
|
|
265
|
+
*/
|
|
266
|
+
export interface DiscordInteractionInput {
|
|
267
|
+
kind: DiscordInteractionKind;
|
|
268
|
+
/** Resolved option values, by option name. */
|
|
269
|
+
command?: { name: string; options: Record<string, string | number | boolean> };
|
|
270
|
+
component?: { customId: string; values?: string[] };
|
|
271
|
+
modal?: { customId: string; fields: Record<string, string> };
|
|
272
|
+
user: { id: string; username: string; globalName: string | null };
|
|
273
|
+
member?: { roles: string[]; permissions: string };
|
|
274
|
+
guildId?: string;
|
|
275
|
+
channelId?: string;
|
|
276
|
+
locale: string;
|
|
277
|
+
/** Discord's payload, without the interaction token. */
|
|
278
|
+
interaction: { id: string; applicationId: string; type: number; data: JSONValue };
|
|
279
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { InterpreterError } from './interpreter/interpreter-error';
|
|
|
16
16
|
export { runToCompletion } from './interpreter/test-host';
|
|
17
17
|
export type { TestHostHandlers, TestRunResult } from './interpreter/test-host';
|
|
18
18
|
export * from './discord/discord.types';
|
|
19
|
+
export * from './schedule/schedule.types';
|
|
19
20
|
export * from './runner-protocol/evaluation.types';
|
|
20
21
|
export * from './runner-protocol/execution-protocol.types';
|
|
21
22
|
export { runInIsolate, EngineResultKind } from './engine/run-in-isolate';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { JSONValue } from '../runner-protocol/execution-protocol.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Host capabilities of the delayed runs of a Service. The host declares them in the execution's
|
|
5
|
+
* capabilities; client code reaches them through `abyss.schedule.<name>(...)`; every helper
|
|
6
|
+
* exists, and one whose capability is not granted rejects with an error naming the action to
|
|
7
|
+
* declare. The argument shapes below are the `args` of the `call`.
|
|
8
|
+
*/
|
|
9
|
+
export enum ScheduleCapability {
|
|
10
|
+
/** Schedules a run of a task after a delay. Arguments: `ScheduleAfterArgs`; result: `ScheduleResult`. */
|
|
11
|
+
SCHEDULE_AFTER = 'schedule.after',
|
|
12
|
+
/** Schedules a run of a task at a date. Arguments: `ScheduleAtArgs`; result: `ScheduleResult`. */
|
|
13
|
+
SCHEDULE_AT = 'schedule.at',
|
|
14
|
+
/** Cancels a pending delayed run. Arguments: `ScheduleCancelArgs`; result: `ScheduleCancelResult`. */
|
|
15
|
+
SCHEDULE_CANCEL = 'schedule.cancel',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Codes of the errors `abyss.schedule.*` throws. The host fails the call with the message
|
|
20
|
+
* `<code>: <detail>` (or the bare code); the helper rethrows an `Error` named `ScheduleError`
|
|
21
|
+
* whose `code` is the code and whose `message` is the detail.
|
|
22
|
+
*/
|
|
23
|
+
export enum ScheduleErrorCode {
|
|
24
|
+
/** No task of that name in the version in service. */
|
|
25
|
+
SCHEDULE_TASK_UNKNOWN = 'SCHEDULE_TASK_UNKNOWN',
|
|
26
|
+
/** The due date is less than the minimal delay away, or beyond the horizon. */
|
|
27
|
+
SCHEDULE_HORIZON_EXCEEDED = 'SCHEDULE_HORIZON_EXCEEDED',
|
|
28
|
+
/** The Service already has as many pending delayed runs in this environment as its plan allows. */
|
|
29
|
+
SCHEDULE_LIMIT_REACHED = 'SCHEDULE_LIMIT_REACHED',
|
|
30
|
+
/** The attached payload is longer than allowed once serialized to JSON. */
|
|
31
|
+
SCHEDULE_PAYLOAD_TOO_LARGE = 'SCHEDULE_PAYLOAD_TOO_LARGE',
|
|
32
|
+
/** The arguments are malformed (delay not a number, date not ISO 8601, empty key...). */
|
|
33
|
+
SCHEDULE_INVALID = 'SCHEDULE_INVALID',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Options shared by `abyss.schedule.after` and `abyss.schedule.at`. */
|
|
37
|
+
export interface ScheduleOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Deduplication key: while a delayed run with the same key is pending for the Service and
|
|
40
|
+
* environment, scheduling again returns that run's id with `deduplicated: true`.
|
|
41
|
+
*/
|
|
42
|
+
key?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ScheduleAfterArgs extends ScheduleOptions {
|
|
46
|
+
/** Delay before the run, in seconds. */
|
|
47
|
+
seconds: number;
|
|
48
|
+
/** Name of the task of the Service to run. */
|
|
49
|
+
taskName: string;
|
|
50
|
+
/** Data handed to the run as `input.payload`. */
|
|
51
|
+
payload?: JSONValue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ScheduleAtArgs extends ScheduleOptions {
|
|
55
|
+
/** Due date, ISO 8601. */
|
|
56
|
+
at: string;
|
|
57
|
+
/** Name of the task of the Service to run. */
|
|
58
|
+
taskName: string;
|
|
59
|
+
/** Data handed to the run as `input.payload`. */
|
|
60
|
+
payload?: JSONValue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ScheduleCancelArgs {
|
|
64
|
+
/** The id `schedule.after` or `schedule.at` returned, or the deduplication key of the run. */
|
|
65
|
+
idOrKey: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ScheduleResult {
|
|
69
|
+
/** Id of the delayed run. */
|
|
70
|
+
id: string;
|
|
71
|
+
/** True when a pending run with the same key already existed: its id is returned, nothing is added. */
|
|
72
|
+
deduplicated: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ScheduleCancelResult {
|
|
76
|
+
/** False when no pending run matched (unknown, already run or already cancelled). */
|
|
77
|
+
cancelled: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** What started a scheduled run: a tick of the task's cron, or a delayed run. */
|
|
81
|
+
export enum ScheduledRunKind {
|
|
82
|
+
SCHEDULE = 'SCHEDULE',
|
|
83
|
+
DELAYED = 'DELAYED',
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The `input` of a function started by a task: a cron tick or a delayed run. */
|
|
87
|
+
export interface ScheduledRunInput {
|
|
88
|
+
kind: ScheduledRunKind;
|
|
89
|
+
task: { id: string; name: string };
|
|
90
|
+
/** When the run was due, ISO 8601. */
|
|
91
|
+
scheduledFor: string;
|
|
92
|
+
/** When this attempt started, ISO 8601. */
|
|
93
|
+
firedAt: string;
|
|
94
|
+
/** Attempt number, from 1. */
|
|
95
|
+
attempt: number;
|
|
96
|
+
/** The payload of a delayed run, when it has one. */
|
|
97
|
+
payload?: JSONValue;
|
|
98
|
+
}
|