@abyss-project/runtime 3.2.0 → 3.3.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 +30 -1
- package/dist/discord/discord.types.d.ts +67 -2
- package/dist/discord/discord.types.js +5 -0
- 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 +98 -0
- package/src/index.ts +1 -0
- package/src/schedule/schedule.types.ts +100 -0
package/README.md
CHANGED
|
@@ -20,7 +20,8 @@ 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
|
|
23
|
+
`discord.deleteMessage`, `discord.addRole`, `discord.removeRole`, `discord.sendDirectMessage`,
|
|
24
|
+
`discord.getMember`, `discord.getGuildRoles`, `discord.getChannel`, `discord.getGuild`) lets the
|
|
24
25
|
client code call `abyss.discord.<name>(...)`. Every helper always exists; one whose capability the
|
|
25
26
|
function does not declare rejects with an error naming the action to declare:
|
|
26
27
|
|
|
@@ -28,6 +29,13 @@ function does not declare rejects with an error naming the action to declare:
|
|
|
28
29
|
- `sendMessage(channelId, message)`, `editMessage(channelId, messageId, message)`,
|
|
29
30
|
`deleteMessage(channelId, messageId)`, `sendDirectMessage(userId, message)`
|
|
30
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.
|
|
36
|
+
|
|
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`.
|
|
31
39
|
|
|
32
40
|
`message` is a `DiscordMessage` (`{ content?, embeds?, components?, ephemeral?, allowedMentions? }`).
|
|
33
41
|
By default a message pings the users it mentions and nobody else: `@everyone`, `@here` and roles
|
|
@@ -39,6 +47,27 @@ code) makes the helper throw an `Error` named `DiscordError` with `code` and `me
|
|
|
39
47
|
other failure is thrown unchanged. `DiscordInteractionInput` types the `input` of a function
|
|
40
48
|
triggered by a Discord interaction.
|
|
41
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
|
+
|
|
42
71
|
## Installation
|
|
43
72
|
|
|
44
73
|
```bash
|
|
@@ -9,14 +9,19 @@ 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;
|
|
@@ -80,6 +85,66 @@ export interface DiscordSendDirectMessageArgs {
|
|
|
80
85
|
userId: string;
|
|
81
86
|
message: DiscordMessage;
|
|
82
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
|
+
}
|
|
83
148
|
export declare enum DiscordInteractionKind {
|
|
84
149
|
COMMAND = "COMMAND",
|
|
85
150
|
COMPONENT = "COMPONENT",
|
|
@@ -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,6 +25,7 @@ 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 = {}));
|
|
25
30
|
var DiscordMentionType;
|
|
26
31
|
(function (DiscordMentionType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discord.types.js","sourceRoot":"","sources":["../../src/discord/discord.types.ts"],"names":[],"mappings":";;;AAOA,IAAY,
|
|
1
|
+
{"version":3,"file":"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AAC,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,yGAA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ChC,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;AAiDD,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,yCAAqB,CAAA;IACrB,uCAAmB,CAAA;AACrB,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B"}
|
package/package.json
CHANGED
|
@@ -26,6 +26,14 @@ export enum DiscordCapability {
|
|
|
26
26
|
REMOVE_ROLE = 'discord.removeRole',
|
|
27
27
|
/** Sends a direct message to a user. Arguments: `DiscordSendDirectMessageArgs`. */
|
|
28
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',
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
/**
|
|
@@ -44,6 +52,11 @@ export enum DiscordErrorCode {
|
|
|
44
52
|
DISCORD_NOT_FOUND = 'DISCORD_NOT_FOUND',
|
|
45
53
|
/** Discord answered 429. */
|
|
46
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',
|
|
47
60
|
}
|
|
48
61
|
|
|
49
62
|
/** Embed and component payloads are Discord's own JSON, relayed as is. */
|
|
@@ -133,6 +146,91 @@ export interface DiscordSendDirectMessageArgs {
|
|
|
133
146
|
message: DiscordMessage;
|
|
134
147
|
}
|
|
135
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
|
+
|
|
136
234
|
/** The kind of interaction a function was started by. */
|
|
137
235
|
export enum DiscordInteractionKind {
|
|
138
236
|
COMMAND = 'COMMAND',
|
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,100 @@
|
|
|
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 of the same task with the same key is pending in the
|
|
40
|
+
* environment, scheduling again returns that run's id with `deduplicated: true`.
|
|
41
|
+
* `abyss.schedule.cancel(key)` cancels the pending runs with that key across every task of the
|
|
42
|
+
* Service in the environment.
|
|
43
|
+
*/
|
|
44
|
+
key?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ScheduleAfterArgs extends ScheduleOptions {
|
|
48
|
+
/** Delay before the run, in seconds. */
|
|
49
|
+
seconds: number;
|
|
50
|
+
/** Name of the task of the Service to run. */
|
|
51
|
+
taskName: string;
|
|
52
|
+
/** Data handed to the run as `input.payload`. */
|
|
53
|
+
payload?: JSONValue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ScheduleAtArgs extends ScheduleOptions {
|
|
57
|
+
/** Due date, ISO 8601. */
|
|
58
|
+
at: string;
|
|
59
|
+
/** Name of the task of the Service to run. */
|
|
60
|
+
taskName: string;
|
|
61
|
+
/** Data handed to the run as `input.payload`. */
|
|
62
|
+
payload?: JSONValue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface ScheduleCancelArgs {
|
|
66
|
+
/** The id `schedule.after` or `schedule.at` returned, or the deduplication key of the run. */
|
|
67
|
+
idOrKey: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ScheduleResult {
|
|
71
|
+
/** Id of the delayed run. */
|
|
72
|
+
id: string;
|
|
73
|
+
/** True when a pending run with the same key already existed: its id is returned, nothing is added. */
|
|
74
|
+
deduplicated: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ScheduleCancelResult {
|
|
78
|
+
/** False when no pending run matched (unknown, already run or already cancelled). */
|
|
79
|
+
cancelled: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** What started a scheduled run: a tick of the task's cron, or a delayed run. */
|
|
83
|
+
export enum ScheduledRunKind {
|
|
84
|
+
SCHEDULE = 'SCHEDULE',
|
|
85
|
+
DELAYED = 'DELAYED',
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The `input` of a function started by a task: a cron tick or a delayed run. */
|
|
89
|
+
export interface ScheduledRunInput {
|
|
90
|
+
kind: ScheduledRunKind;
|
|
91
|
+
task: { id: string; name: string };
|
|
92
|
+
/** When the run was due, ISO 8601. */
|
|
93
|
+
scheduledFor: string;
|
|
94
|
+
/** When this attempt started, ISO 8601. */
|
|
95
|
+
firedAt: string;
|
|
96
|
+
/** Attempt number, from 1. */
|
|
97
|
+
attempt: number;
|
|
98
|
+
/** The payload of a delayed run, when it has one. */
|
|
99
|
+
payload?: JSONValue;
|
|
100
|
+
}
|