forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumNamespace.swift
More file actions
83 lines (71 loc) · 1.68 KB
/
EnumNamespace.swift
File metadata and controls
83 lines (71 loc) · 1.68 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Empty enums to act as namespace wrappers for nested elements
@JS enum Utils {
@JS class Converter {
@JS var precision: Int
@JS init() {
self.precision = 2
}
@JS func toString(value: Int) -> String {
return String(value)
}
}
}
@JS enum Networking {
@JS enum API {
@JS enum Method {
case get
case post
case put
case delete
}
// Invalid to declare @JS(namespace) here as it would be conflicting with nesting
@JS class HTTPServer {
@JS init() {}
@JS func call(_ method: Method) {}
}
}
}
@JS enum Configuration {
@JS enum LogLevel: String {
case debug = "debug"
case info = "info"
case warning = "warning"
case error = "error"
}
@JS enum Port: Int {
case http = 80
case https = 443
case development = 3000
}
}
@JS(namespace: "Networking.APIV2")
enum Internal {
@JS enum SupportedMethod {
case get
case post
}
@JS class TestServer {
@JS init() {}
@JS func call(_ method: SupportedMethod) {}
}
}
@JS enum Formatting {
@JS class Converter {
@JS init() {}
@JS func format(value: Int) -> String {
return "formatted_\(value)"
}
}
}
@JS(namespace: "Services.Graph")
enum GraphOperations {
@JS static func createGraph(rootId: Int) -> Int {
return rootId * 10
}
@JS static func nodeCount(graphId: Int) -> Int {
return graphId
}
@JS static func validate(graphId: Int) throws(JSException) -> Bool {
return graphId > 0
}
}