@abyss-project/runtime 3.5.0 → 3.6.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/.eslintrc.js +32 -32
- package/.prettierrc +5 -5
- package/README.md +88 -88
- package/dist/engine/engine-source.js +1 -1
- package/dist/interpreter/interpreter.js +18 -4
- package/dist/interpreter/interpreter.js.map +1 -1
- package/dist/interpreter/interpreter.types.d.ts +2 -0
- package/dist/interpreter/interpreter.types.js.map +1 -1
- package/dist/runner-protocol/execution-protocol.types.d.ts +11 -0
- package/dist/runner-protocol/execution-protocol.types.js +2 -1
- package/dist/runner-protocol/execution-protocol.types.js.map +1 -1
- package/jest.config.ts +11 -11
- package/package.json +15 -10
- package/scripts/build-engine.cjs +70 -70
- package/src/__tests__/engine-bundle.test.ts +121 -121
- package/src/__tests__/surface.test.ts +70 -66
- package/src/access/__tests__/host-match.test.ts +24 -24
- package/src/access/access.types.ts +25 -25
- package/src/access/host-match.ts +13 -13
- package/src/cost/__tests__/execution-cost.test.ts +196 -196
- package/src/cost/execution-cost.ts +186 -186
- package/src/definition/__tests__/validate-definition.test.ts +354 -354
- package/src/definition/definition.limits.ts +9 -9
- package/src/definition/definition.schema.ts +172 -172
- package/src/definition/definition.types.ts +171 -171
- package/src/definition/validate-definition.ts +206 -206
- package/src/definition/walk-steps.ts +44 -44
- package/src/discord/__tests__/discord-event-input.test.ts +89 -89
- package/src/discord/discord.types.ts +639 -639
- package/src/engine/__tests__/run-in-isolate.test.ts +468 -468
- package/src/engine/engine-entry.ts +3 -3
- package/src/engine/engine-global.ts +2 -2
- package/src/engine/run-in-isolate.ts +404 -404
- package/src/errors/runtime-error-code.enum.ts +37 -37
- package/src/index.ts +32 -32
- package/src/interpreter/__tests__/interpreter.test.ts +854 -854
- package/src/interpreter/__tests__/log-respond-resume.test.ts +270 -223
- package/src/interpreter/interpreter-error.ts +12 -12
- package/src/interpreter/interpreter.ts +482 -461
- package/src/interpreter/interpreter.types.ts +202 -192
- package/src/interpreter/sequence-path.ts +67 -67
- package/src/interpreter/test-host.ts +85 -85
- package/src/runner-protocol/evaluation.types.ts +21 -21
- package/src/runner-protocol/execution-protocol.types.ts +254 -231
- package/src/schedule/schedule.types.ts +100 -100
- package/src/server/__tests__/code-runner-session.test.ts +311 -311
- package/src/server/code-runner-error.ts +12 -12
- package/src/server/code-runner-session.ts +310 -310
- package/src/server/index.ts +11 -11
- package/src/steps/__tests__/global-references.test.ts +133 -133
- package/src/steps/execute-step.ts +186 -186
- package/src/steps/global-references.ts +48 -48
- package/src/steps/step-access.ts +56 -56
- package/src/steps/step-fields.ts +87 -87
- package/src/steps/value-source.ts +69 -69
- package/tsconfig.check.json +15 -15
- package/tsconfig.json +35 -35
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import { DiscordEventInput, DiscordEventType, isDiscordEventInput } from '../discord.types';
|
|
2
|
-
import { ScheduledRunKind } from '../../schedule/schedule.types';
|
|
3
|
-
|
|
4
|
-
const DATA_BY_TYPE: Record<DiscordEventType, DiscordEventInput['data']> = {
|
|
5
|
-
[DiscordEventType.GUILD_MEMBER_ADD]: {
|
|
6
|
-
user: { id: 'u1', username: 'ann', globalName: null, bot: false, avatar: null },
|
|
7
|
-
roles: [],
|
|
8
|
-
joinedAt: '2026-11-21T10:00:00.000Z',
|
|
9
|
-
pending: false,
|
|
10
|
-
},
|
|
11
|
-
[DiscordEventType.GUILD_MEMBER_REMOVE]: {
|
|
12
|
-
user: { id: 'u1', username: 'ann', globalName: 'Ann', bot: false },
|
|
13
|
-
},
|
|
14
|
-
[DiscordEventType.MESSAGE_CREATE]: {
|
|
15
|
-
id: 'm1',
|
|
16
|
-
channelId: 'c1',
|
|
17
|
-
author: { id: 'u1', username: 'ann', globalName: null, bot: false },
|
|
18
|
-
member: { roles: ['r1'], nick: null },
|
|
19
|
-
mentions: [],
|
|
20
|
-
referencedMessageId: null,
|
|
21
|
-
attachmentCount: 0,
|
|
22
|
-
createdAt: '2026-11-21T10:00:00.000Z',
|
|
23
|
-
},
|
|
24
|
-
[DiscordEventType.MESSAGE_REACTION_ADD]: {
|
|
25
|
-
userId: 'u1',
|
|
26
|
-
channelId: 'c1',
|
|
27
|
-
messageId: 'm1',
|
|
28
|
-
messageAuthorId: 'u2',
|
|
29
|
-
member: { roles: [] },
|
|
30
|
-
emoji: { id: null, name: '👍', animated: false },
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const inputOf = (type: DiscordEventType): DiscordEventInput => ({
|
|
35
|
-
kind: 'DISCORD_EVENT',
|
|
36
|
-
event: { id: 'e1', type, trigger: { id: 't1', name: 'welcome' } },
|
|
37
|
-
guildId: 'g1',
|
|
38
|
-
receivedAt: '2026-11-21T10:00:00.000Z',
|
|
39
|
-
firedAt: '2026-11-21T10:00:01.000Z',
|
|
40
|
-
attempt: 1,
|
|
41
|
-
data: DATA_BY_TYPE[type],
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('isDiscordEventInput', () => {
|
|
45
|
-
it.each(Object.values(DiscordEventType))('is true for a %s input', (type) => {
|
|
46
|
-
expect(isDiscordEventInput(inputOf(type))).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('is false for an interaction input', () => {
|
|
50
|
-
expect(
|
|
51
|
-
isDiscordEventInput({
|
|
52
|
-
kind: 'COMMAND',
|
|
53
|
-
command: { name: 'ping', options: {} },
|
|
54
|
-
user: { id: 'u1', username: 'ann', globalName: null },
|
|
55
|
-
locale: 'en-US',
|
|
56
|
-
interaction: { id: 'i1', applicationId: 'a1', type: 2, data: null },
|
|
57
|
-
}),
|
|
58
|
-
).toBe(false);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('is false for a scheduled run input', () => {
|
|
62
|
-
expect(
|
|
63
|
-
isDiscordEventInput({
|
|
64
|
-
kind: ScheduledRunKind.SCHEDULE,
|
|
65
|
-
task: { id: 't1', name: 'daily' },
|
|
66
|
-
scheduledFor: '2026-11-21T10:00:00.000Z',
|
|
67
|
-
firedAt: '2026-11-21T10:00:01.000Z',
|
|
68
|
-
attempt: 1,
|
|
69
|
-
}),
|
|
70
|
-
).toBe(false);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('is false for an unknown event type, a missing envelope field and non-objects', () => {
|
|
74
|
-
expect(
|
|
75
|
-
isDiscordEventInput({
|
|
76
|
-
...inputOf(DiscordEventType.MESSAGE_CREATE),
|
|
77
|
-
event: { id: 'e1', type: 'X', trigger: { id: 't', name: 'n' } },
|
|
78
|
-
}),
|
|
79
|
-
).toBe(false);
|
|
80
|
-
expect(
|
|
81
|
-
isDiscordEventInput({ ...inputOf(DiscordEventType.MESSAGE_CREATE), guildId: undefined }),
|
|
82
|
-
).toBe(false);
|
|
83
|
-
expect(isDiscordEventInput({ ...inputOf(DiscordEventType.MESSAGE_CREATE), data: null })).toBe(
|
|
84
|
-
false,
|
|
85
|
-
);
|
|
86
|
-
expect(isDiscordEventInput(null)).toBe(false);
|
|
87
|
-
expect(isDiscordEventInput('DISCORD_EVENT')).toBe(false);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
1
|
+
import { DiscordEventInput, DiscordEventType, isDiscordEventInput } from '../discord.types';
|
|
2
|
+
import { ScheduledRunKind } from '../../schedule/schedule.types';
|
|
3
|
+
|
|
4
|
+
const DATA_BY_TYPE: Record<DiscordEventType, DiscordEventInput['data']> = {
|
|
5
|
+
[DiscordEventType.GUILD_MEMBER_ADD]: {
|
|
6
|
+
user: { id: 'u1', username: 'ann', globalName: null, bot: false, avatar: null },
|
|
7
|
+
roles: [],
|
|
8
|
+
joinedAt: '2026-11-21T10:00:00.000Z',
|
|
9
|
+
pending: false,
|
|
10
|
+
},
|
|
11
|
+
[DiscordEventType.GUILD_MEMBER_REMOVE]: {
|
|
12
|
+
user: { id: 'u1', username: 'ann', globalName: 'Ann', bot: false },
|
|
13
|
+
},
|
|
14
|
+
[DiscordEventType.MESSAGE_CREATE]: {
|
|
15
|
+
id: 'm1',
|
|
16
|
+
channelId: 'c1',
|
|
17
|
+
author: { id: 'u1', username: 'ann', globalName: null, bot: false },
|
|
18
|
+
member: { roles: ['r1'], nick: null },
|
|
19
|
+
mentions: [],
|
|
20
|
+
referencedMessageId: null,
|
|
21
|
+
attachmentCount: 0,
|
|
22
|
+
createdAt: '2026-11-21T10:00:00.000Z',
|
|
23
|
+
},
|
|
24
|
+
[DiscordEventType.MESSAGE_REACTION_ADD]: {
|
|
25
|
+
userId: 'u1',
|
|
26
|
+
channelId: 'c1',
|
|
27
|
+
messageId: 'm1',
|
|
28
|
+
messageAuthorId: 'u2',
|
|
29
|
+
member: { roles: [] },
|
|
30
|
+
emoji: { id: null, name: '👍', animated: false },
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const inputOf = (type: DiscordEventType): DiscordEventInput => ({
|
|
35
|
+
kind: 'DISCORD_EVENT',
|
|
36
|
+
event: { id: 'e1', type, trigger: { id: 't1', name: 'welcome' } },
|
|
37
|
+
guildId: 'g1',
|
|
38
|
+
receivedAt: '2026-11-21T10:00:00.000Z',
|
|
39
|
+
firedAt: '2026-11-21T10:00:01.000Z',
|
|
40
|
+
attempt: 1,
|
|
41
|
+
data: DATA_BY_TYPE[type],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('isDiscordEventInput', () => {
|
|
45
|
+
it.each(Object.values(DiscordEventType))('is true for a %s input', (type) => {
|
|
46
|
+
expect(isDiscordEventInput(inputOf(type))).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('is false for an interaction input', () => {
|
|
50
|
+
expect(
|
|
51
|
+
isDiscordEventInput({
|
|
52
|
+
kind: 'COMMAND',
|
|
53
|
+
command: { name: 'ping', options: {} },
|
|
54
|
+
user: { id: 'u1', username: 'ann', globalName: null },
|
|
55
|
+
locale: 'en-US',
|
|
56
|
+
interaction: { id: 'i1', applicationId: 'a1', type: 2, data: null },
|
|
57
|
+
}),
|
|
58
|
+
).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('is false for a scheduled run input', () => {
|
|
62
|
+
expect(
|
|
63
|
+
isDiscordEventInput({
|
|
64
|
+
kind: ScheduledRunKind.SCHEDULE,
|
|
65
|
+
task: { id: 't1', name: 'daily' },
|
|
66
|
+
scheduledFor: '2026-11-21T10:00:00.000Z',
|
|
67
|
+
firedAt: '2026-11-21T10:00:01.000Z',
|
|
68
|
+
attempt: 1,
|
|
69
|
+
}),
|
|
70
|
+
).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('is false for an unknown event type, a missing envelope field and non-objects', () => {
|
|
74
|
+
expect(
|
|
75
|
+
isDiscordEventInput({
|
|
76
|
+
...inputOf(DiscordEventType.MESSAGE_CREATE),
|
|
77
|
+
event: { id: 'e1', type: 'X', trigger: { id: 't', name: 'n' } },
|
|
78
|
+
}),
|
|
79
|
+
).toBe(false);
|
|
80
|
+
expect(
|
|
81
|
+
isDiscordEventInput({ ...inputOf(DiscordEventType.MESSAGE_CREATE), guildId: undefined }),
|
|
82
|
+
).toBe(false);
|
|
83
|
+
expect(isDiscordEventInput({ ...inputOf(DiscordEventType.MESSAGE_CREATE), data: null })).toBe(
|
|
84
|
+
false,
|
|
85
|
+
);
|
|
86
|
+
expect(isDiscordEventInput(null)).toBe(false);
|
|
87
|
+
expect(isDiscordEventInput('DISCORD_EVENT')).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
});
|