@abyss-project/runtime 3.3.0 → 3.4.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 +88 -88
- package/dist/discord/discord.types.d.ts +77 -0
- package/dist/discord/discord.types.js +28 -1
- package/dist/discord/discord.types.js.map +1 -1
- package/dist/schedule/schedule.types.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/surface.test.ts +66 -53
- package/src/discord/__tests__/discord-event-input.test.ts +89 -0
- package/src/discord/discord.types.ts +380 -279
- package/src/schedule/schedule.types.ts +100 -98
|
@@ -1,98 +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 with the same key is pending
|
|
40
|
-
* environment, scheduling again returns that run's id with `deduplicated: true`.
|
|
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
|
-
/** When
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
|
|
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 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
|
+
}
|