-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathbook-library.webidl
More file actions
67 lines (51 loc) · 1.4 KB
/
book-library.webidl
File metadata and controls
67 lines (51 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
// This WebIDL file will be used to automatically generate WIT,
// using the `webidl2wit` tool.
//
// see: https://github.com/MendyBerger/webidl2wit/tree/main
// WebIDL enums are converted as standard WIT enums
enum BookGenre {
"fiction",
"non-fiction",
"mystery",
"fantasy",
"science-fiction",
"biography"
};
// WebIDL typedefs are converted into WIT type aliases
typedef DOMString BookTitle;
// WebIDL dictionaries are turned into WIT structs
dictionary Book {
required BookTitle title;
required DOMString author;
BookGenre genre;
unsigned short pages;
};
// WebIDL interfaces become WIT resources
interface Library {
constructor();
readonly attribute unsigned long totalBooks;
// Add a Book
boolean addBook(Book book);
// Remove a book
boolean removeBook(DOMString title);
// Retrieve a book by title (if present)
Book? getBookByTitle(DOMString title);
// List all the books
sequence<Book>? listBooks();
};
interface AdvancedLibrary : Library {
FrozenArray<Book> filterBooks(DOMString name);
};
partial interface Library {
readonly attribute LibraryName libraryName;
// Rename this library
undefined renameLibrary(LibraryName newName);
};
typedef DOMString LibraryName;
// WebIDL interfaces become WIT resources
interface BookManager {
constructor();
readonly attribute Library library;
// Initialize a library
undefined initLibrary(LibraryName name);
};