/src/WasmEdge/include/validator/component_name.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright The WasmEdge Authors |
3 | | #pragma once |
4 | | |
5 | | #include "common/errcode.h" |
6 | | #include "common/expected.h" |
7 | | #include "common/variant.h" |
8 | | |
9 | | #include <string_view> |
10 | | |
11 | | namespace WasmEdge { |
12 | | namespace Validator { |
13 | | |
14 | | enum class ComponentNameKind { |
15 | | Invalid, |
16 | | Constructor, |
17 | | Method, |
18 | | Static, |
19 | | InterfaceType, |
20 | | Label, |
21 | | LockedDep, |
22 | | UnlockedDep, |
23 | | Url, |
24 | | Integrity |
25 | | }; |
26 | | |
27 | | struct ConstructorDetail { |
28 | | std::string_view Label; |
29 | | }; |
30 | | struct MethodDetail { |
31 | | std::string_view Resource; |
32 | | std::string_view Method; |
33 | | }; |
34 | | struct StaticDetail { |
35 | | std::string_view Resource; |
36 | | std::string_view Method; |
37 | | }; |
38 | | struct InterfaceDetail { |
39 | | std::string_view Namespace; |
40 | | std::string_view Package; |
41 | | std::string_view Interface; |
42 | | std::string_view Version; |
43 | | }; |
44 | | struct LabelDetail {}; |
45 | | struct LockedDepDetail { |
46 | | std::string_view Namespace; |
47 | | std::string_view Package; |
48 | | std::string_view Version; |
49 | | std::string_view Integrity; |
50 | | }; |
51 | | struct UnlockedDepDetail { |
52 | | std::string_view Namespace; |
53 | | std::string_view Package; |
54 | | std::string_view VersionRange; |
55 | | }; |
56 | | struct UrlDetail { |
57 | | std::string_view Url; |
58 | | std::string_view Integrity; |
59 | | }; |
60 | | struct IntegrityDetail { |
61 | | std::string_view Integrity; |
62 | | }; |
63 | | |
64 | | using ComponentNameDetail = |
65 | | Variant<LabelDetail, ConstructorDetail, MethodDetail, StaticDetail, |
66 | | InterfaceDetail, LockedDepDetail, UnlockedDepDetail, UrlDetail, |
67 | | IntegrityDetail>; |
68 | | |
69 | | /// Returns true if Input is a valid kebab-case label per the Component Model |
70 | | /// spec: `label ::= <first-fragment> ( '-' <fragment> )*` |
71 | | bool isKebabString(std::string_view Input); |
72 | | |
73 | | class ComponentName { |
74 | | const std::string_view OriName; |
75 | | std::string_view NoTagName; |
76 | | ComponentNameKind Kind; |
77 | | ComponentNameDetail Detail; |
78 | | |
79 | | ComponentName(std::string_view Name) |
80 | 0 | : OriName(Name), Kind(ComponentNameKind::Invalid) {} |
81 | | |
82 | | public: |
83 | | static Expect<ComponentName> parse(std::string_view Name); |
84 | | |
85 | 0 | ComponentNameKind getKind() const noexcept { return Kind; } |
86 | 0 | std::string_view getOriginalName() const noexcept { return OriName; } |
87 | 0 | std::string_view getNoTagName() const noexcept { return NoTagName; } |
88 | 0 | const ComponentNameDetail &getDetail() const noexcept { return Detail; } |
89 | | }; |
90 | | |
91 | | } // namespace Validator |
92 | | } // namespace WasmEdge |