Skip to content

Commit 88ba0ee

Browse files
committed
feat(wit): Restructure the WIT definitions into deps
- The `plugin` world is now composed of the `core` and `services` worlds. - Shared types have been exported to the `wpbs:shared` dependency. - The `services` world is composed of all available services. - Down the line the implementation of these services will be optional (WebAssembly/component-model#555). - Each service implements the register family of functions itself now. - Support for dependency functions has been removed, components should compose dependencies themselves (https://component-model.bytecodealliance.org/composing-and-distributing/composing.html).
1 parent d7e8435 commit 88ba0ee

10 files changed

Lines changed: 110 additions & 144 deletions

File tree

src/runtime/plugins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515

1616
pub mod builder;
1717

18-
wasmtime::component::bindgen!({ imports: { default: async }, exports: { default: async } });
18+
wasmtime::component::bindgen!({ world: "plugin", imports: { default: async }, exports: { default: async } });
1919

2020
pub struct RuntimePlugin {
2121
pub plugin_pre: PluginPre<InternalRuntime>,

wit/core.wit

Lines changed: 13 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,44 @@
11
/* SPDX-License-Identifier: GPL-3.0-or-later */
22
/* Copyright © 2026 Eduard Smet */
33

4-
interface core-types {
5-
type json = string;
6-
7-
type host-error = string;
4+
use wpbs:shared/shared-types@0.1.0-rc.1;
85

9-
type plugin-error = string;
6+
world core {
7+
import core-import-functions;
8+
export core-export-functions;
109
}
1110

12-
interface core-import-types {
13-
use core-types.{host-error};
14-
15-
// Services
16-
use job-scheduler-import-types.{job-scheduler-registrations, job-scheduler-registrations-result, job-scheduler-deregistrations, job-scheduler-deregistrations-result};
17-
use discord-import-types.{discord-registrations, discord-registrations-result, discord-deregistrations, discord-deregistrations-result};
18-
11+
interface core-types {
1912
enum log-levels {
2013
trace,
2114
debug,
2215
info,
2316
warn,
2417
error,
2518
}
26-
27-
record registrations {
28-
core: option<core-registrations>,
29-
services: option<services-registrations>,
30-
}
31-
32-
record core-registrations {
33-
dependency-functions: option<list<string>>,
34-
}
35-
36-
record services-registrations {
37-
job-scheduler: option<job-scheduler-registrations>,
38-
discord: option<discord-registrations>,
39-
}
40-
41-
record registrations-result {
42-
core: option<core-registrations-result>,
43-
services: option<services-registrations-result>,
44-
}
45-
46-
record core-registrations-result {
47-
dependency-functions: option<result<map<string, string>, host-error>>,
48-
}
49-
50-
record services-registrations-result {
51-
job-scheduler: option<result<job-scheduler-registrations-result, host-error>>,
52-
discord: option<result<discord-registrations-result, host-error>>
53-
}
54-
55-
record deregistrations {
56-
core: option<core-deregistrations>,
57-
services: option<services-deregistrations>,
58-
}
59-
60-
record core-deregistrations {
61-
dependency-functions: option<list<string>>
62-
}
63-
64-
record services-deregistrations {
65-
job-scheduler: option<job-scheduler-deregistrations>,
66-
discord: option<discord-deregistrations>,
67-
}
68-
69-
record deregistrations-result {
70-
core: option<core-deregistrations-result>,
71-
services: option<services-deregistrations-result>,
72-
}
73-
74-
record core-deregistrations-result {
75-
dependency-functions: option<list<string>>
76-
}
77-
78-
record services-deregistrations-result {
79-
job-scheduler: option<result<job-scheduler-deregistrations-result, host-error>>,
80-
discord: option<result<discord-deregistrations-result, host-error>>,
81-
}
8219
}
8320

8421
interface core-import-functions {
85-
use core-types.{host-error};
86-
use core-import-types.{deregistrations, deregistrations-result, log-levels, registrations, registrations-result};
87-
88-
89-
register: func(registrations: registrations) -> registrations-result;
90-
deregister: func(deregistrations: deregistrations) -> deregistrations-result;
22+
use core-types.{log-levels};
23+
use shared-types.{host-error};
9124

9225
log: func(level: log-levels, message: string);
9326

94-
get-state: func(key: string) -> result<option<list<u8>>, host-error>;
95-
set-state: func(key: string, value: list<u8>) -> result<_, host-error>;
96-
clear-state: func() -> result<_, host-error>;
27+
get-value: func(key: string) -> result<option<list<u8>>, host-error>;
28+
set-value: func(key: string, value: list<u8>) -> result<_, host-error>;
29+
remove-value: func(key: string) -> result<option<list<u8>>, host-error>;
9730

98-
dependency-function: func(registry-id: string, plugin-id: string, function-id: string, plugin-version: option<string>, params: list<u8>) -> result<list<u8>, host-error>;
31+
get-all-entries: func() -> result<list<tuple<string, list<u8>>>, host-error>;
32+
clear-all-entries: func() -> result<_, host-error>;
9933

100-
remove: func(reason: string);
10134
shutdown: func(restart: bool) -> result<_, host-error>;
10235
}
10336

10437
interface core-export-functions {
105-
use core-types.{json, plugin-error};
38+
use shared-types.{json, plugin-error};
10639

10740
initialization: func(settings: json) -> result<_, plugin-error>;
10841

109-
dependency-function: func(function-id: string, params: list<u8>) -> result<list<u8>, plugin-error>;
110-
11142
shutdown: func() -> result<_, plugin-error>;
11243
}
11344

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/* SPDX-License-Identifier: GPL-3.0-or-later */
22
/* Copyright © 2026 Eduard Smet */
33

4+
use wpbs:shared/shared-types@0.1.0-rc.1;
5+
46
interface discord-types {
5-
type snowflake = u64;
6-
}
7+
use shared-types.{host-error, json, plugin-error};
78

8-
interface discord-import-types {
9-
use core-types.{host-error, json};
10-
use discord-types.{snowflake};
9+
type snowflake = u64;
1110

1211
enum discord-event-kinds {
1312
message-create,
@@ -120,11 +119,6 @@ interface discord-import-types {
120119

121120
// Discord Responses
122121
type discord-responses = json;
123-
}
124-
125-
interface discord-export-types {
126-
use core-types.{json, plugin-error};
127-
use discord-types.{snowflake};
128122

129123
// Discord Application Command Registrations Result
130124
type discord-registrations-result-application-commands = map<string, result<snowflake, plugin-error>>;
@@ -141,19 +135,3 @@ interface discord-export-types {
141135
thread-update(json),
142136
}
143137
}
144-
145-
interface discord-import-functions {
146-
use core-types.{host-error};
147-
use discord-import-types.{discord-requests, discord-responses};
148-
149-
discord-request: func(request: discord-requests) -> result<option<discord-responses>, host-error>;
150-
}
151-
152-
interface discord-export-functions {
153-
use core-types.{plugin-error};
154-
use discord-export-types.{discord-events, discord-registrations-result-application-commands};
155-
156-
discord-application-commands: func(registrations-result: discord-registrations-result-application-commands);
157-
158-
discord-event: func(event: discord-events) -> result<_, plugin-error>;
159-
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* SPDX-License-Identifier: GPL-3.0-or-later */
2+
/* Copyright © 2026 Eduard Smet */
3+
4+
package wpbs-services:discord@0.1.0-rc.1;
5+
6+
use wpbs:shared/shared-types@0.1.0-rc.1;
7+
8+
world discord {
9+
import discord-import-functions;
10+
export discord-export-functions;
11+
}
12+
13+
interface discord-import-functions {
14+
use discord-types.{discord-deregistrations, discord-deregistrations-result, discord-registrations, discord-registrations-result, discord-requests, discord-responses};
15+
use shared-types.{host-error};
16+
17+
register: func(registrations: discord-registrations) -> discord-registrations-result;
18+
deregister: func(deregistrations: discord-deregistrations) -> discord-deregistrations-result;
19+
20+
discord-request: func(request: discord-requests) -> result<option<discord-responses>, host-error>;
21+
}
22+
23+
interface discord-export-functions {
24+
use discord-types.{discord-events, discord-registrations-result-application-commands};
25+
use shared-types.{host-error, plugin-error};
26+
27+
discord-application-commands: func(registrations-result: discord-registrations-result-application-commands) -> result<_, plugin-error>;
28+
29+
discord-event: func(event: discord-events) -> result<_, plugin-error>;
30+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-License-Identifier: GPL-3.0-or-later */
2+
/* Copyright © 2026 Eduard Smet */
3+
4+
use wpbs:shared/shared-types@0.1.0-rc.1;
5+
6+
interface job-scheduler-types {
7+
use shared-types.{host-error};
8+
9+
type registrations = list<string>;
10+
11+
type registrations-result = result<map<string, result<string, host-error>>, host-error>;
12+
13+
type deregistrations = list<string>;
14+
15+
type deregistrations-result = result<map<string, result<_, host-error>>, host-error>;
16+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* SPDX-License-Identifier: GPL-3.0-or-later */
2+
/* Copyright © 2026 Eduard Smet */
3+
4+
package wpbs-services:job-scheduler@0.1.0-rc.1;
5+
6+
use wpbs:shared/shared-types@0.1.0-rc.1;
7+
8+
world job-scheduler {
9+
import job-scheduler-import-functions;
10+
export job-scheduler-export-functions;
11+
}
12+
13+
interface job-scheduler-import-functions {
14+
use job-scheduler-types.{deregistrations, deregistrations-result, registrations, registrations-result};
15+
16+
register: func(registrations: registrations) -> registrations-result;
17+
deregister: func(deregistrations: deregistrations) -> deregistrations-result;
18+
}
19+
20+
interface job-scheduler-export-functions {
21+
use shared-types.{plugin-error};
22+
23+
scheduled-job: func(job-id: string) -> result<_, plugin-error>;
24+
}

wit/deps/wpbs:shared/types.wit

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* SPDX-License-Identifier: GPL-3.0-or-later */
2+
/* Copyright © 2026 Eduard Smet */
3+
4+
package wpbs:shared@0.1.0-rc.1;
5+
6+
interface shared-types {
7+
type json = list<u8>;
8+
9+
type host-error = string;
10+
11+
type plugin-error = string;
12+
}

wit/job-scheduler.wit

Lines changed: 0 additions & 28 deletions
This file was deleted.

wit/services.wit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* SPDX-License-Identifier: GPL-3.0-or-later */
2+
/* Copyright © 2026 Eduard Smet */
3+
4+
world services {
5+
include wpbs-services:job-scheduler/job-scheduler@0.1.0-rc.1;
6+
include wpbs-services:discord/discord@0.1.0-rc.1;
7+
}

wit/world.wit

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
/* SPDX-License-Identifier: GPL-3.0-or-later */
22
/* Copyright © 2026 Eduard Smet */
33

4-
package wpbs:plugin@0.1.0-rc.4;
4+
package wpbs:plugin@0.1.0-rc.1;
55

66
world plugin {
7-
import core-import-functions;
8-
export core-export-functions;
7+
include core;
98

10-
export job-scheduler-export-functions;
11-
12-
import discord-import-functions;
13-
export discord-export-functions;
9+
include services;
1410
}

0 commit comments

Comments
 (0)