Skip to content
File

Blob: src/workerd/jsg/rtti.capnp

6.7 KB
1# Copyright (c) 2017-2022 Cloudflare, Inc.
2# Licensed under the Apache 2.0 license found in the LICENSE file or at:
3# https://opensource.org/licenses/Apache-2.0
4 
5@0xb042d6da9e1721ad;
6# Runtime information about jsg types and definitions
7 
8using Cxx = import "/capnp/c++.capnp";
9$Cxx.namespace("workerd::jsg::rtti");
10$Cxx.allowCancellation;
11# TODO: I can't figure out how to make both capnpc-ts and capnpc-cpp generators to see this import
12# without code changes. capnpc-ts code is weird:
13# https://github.com/jdiaz5513/capnp-ts/blob/master/packages/capnpc-ts/src/generators.ts#L92
14# using Modules = import "/workerd/jsg/modules.capnp";
15 
16struct Type {
17 # A description of the C++ type.
18 # It is as precise as needed for applications, and is mostly how the type looks from the js side.
19 
20 union {
21 unknown @0 :Void;
22 # statically unknown type
23 
24 voidt @1 :Void;
25 # void type
26 
27 boolt @2 :Void;
28 # boolean type
29 
30 number @3 :NumberType;
31 # number type
32 
33 promise @4 :PromiseType;
34 # jsg, kj Promise
35 
36 structure @5 :StructureType;
37 # jsg resource or struct
38 
39 string @6 :StringType;
40 # any string-like type
41 
42 object @7 :Void;
43 # generic object type
44 
45 array @8 :ArrayType;
46 # Array or ArrayPtr
47 
48 maybe @9 :MaybeType;
49 # kj::Maybe or jsg::Optional
50 
51 dict @10 :DictType;
52 # jsg::Dict
53 
54 oneOf @11: OneOfType;
55 # kj::OneOf
56 
57 builtin @12 :BuiltinType;
58 # one of the builtin types
59 
60 intrinsic @13 :IntrinsicType;
61 # one of v8 intrinsics
62 
63 function @14 :FunctionType;
64 # jsg::Function
65 
66 jsgImpl @15 :JsgImplType;
67 # jsg implementation type
68 
69 jsBuiltin @16: JsBuiltinType;
70 }
71}
72 
73struct NumberType {
74 # Any c++ number type
75 name @0 :Text;
76}
77 
78struct PromiseType {
79 # kj or jsg Promise<T>
80 value @0 :Type;
81}
82 
83struct StructureType {
84 # Structure types need to be resolved separately to prevent circular references with types
85 
86 name @0 :Text;
87 
88 fullyQualifiedName @1 :Text;
89}
90 
91struct StringType {
92 # any string or string-like type
93 name @0 :Text;
94}
95 
96struct IntrinsicType {
97 # v8::Intrinsic
98 
99 name @0 :Text;
100}
101 
102struct ArrayType {
103 # Array like structure
104 element @0 :Type;
105 
106 name @1 :Text;
107}
108 
109struct MaybeType {
110 # kj::Maybe, jsg::Optional, jsg::LenientOptional
111 value @0 :Type;
112 
113 name @1 :Text;
114}
115 
116struct DictType {
117 # jsg::dict
118 key @0 :Type;
119 value @1 :Type;
120}
121 
122struct OneOfType {
123 # kj::OneOf
124 variants @0 :List(Type);
125}
126 
127struct BuiltinType {
128 # One of the types provided by the JS or Runtime platform.
129 
130 enum Type {
131 v8Uint8Array @0;
132 # v8::UInt8Array
133 
134 v8ArrayBufferView @1;
135 # v8::ArrayBufferView
136 
137 jsgBufferSource @2;
138 # BufferSource
139 
140 kjDate @3;
141 # kj::Date
142 
143 v8Function @4;
144 # v8::Function
145 
146 v8ArrayBuffer @5;
147 # v8::ArrayBuffer
148 }
149 
150 type @0 :Type;
151}
152 
153struct FunctionType {
154 # jsg::Function type
155 
156 returnType @0 :Type;
157 
158 args @1 :List(Type);
159}
160 
161struct JsgImplType {
162 # one of the internal jsg types that are not exposed directly but handled specially
163 
164 enum Type {
165 configuration @0;
166 # api meta configuration object
167 
168 v8Isolate @1;
169 
170 jsgLock @2;
171 
172 jsgTypeHandler @3;
173 
174 jsgUnimplemented @4;
175 
176 jsgVarargs @5;
177 
178 jsgSelfRef @6;
179 
180 v8FunctionCallbackInfo @7;
181 
182 v8PropertyCallbackInfo @8;
183 
184 jsgName @9;
185 }
186 
187 type @0 :Type;
188}
189 
190struct Structure {
191 # A description of either JSG_RESOURCE or JSG_STRUCT
192 
193 name @0 :Text;
194 # Structure name
195 
196 fullyQualifiedName @5 :Text;
197 # Fully-qualified structure name including namespaces and parents
198 
199 members @1 :List(Member);
200 # All members in declaration order
201 
202 extends @2 :Type;
203 # base type
204 
205 iterable @3 :Bool;
206 # true if the structure is iterable
207 iterator @6 :Method;
208 # Method returning iterator if the structure is iterable
209 
210 asyncIterable @4 :Bool;
211 # true if the structure is async iterable
212 asyncIterator @7 :Method;
213 # Method returning async iterator if the structure is async iterable
214 
215 disposable @13 :Bool;
216 # true if the structure is disposable
217 dispose @14 :Method;
218 # dispose method
219 
220 asyncDisposable @15 :Bool;
221 # true if the structure is async disposable
222 asyncDispose @16 :Method;
223 # asyncDispose method
224 
225 tsRoot @8 :Bool;
226 # See `JSG_TS_ROOT`'s documentation in the `## TypeScript` section of the JSG README.md.
227 # If `JSG_(STRUCT_)TS_ROOT` is declared for a type, this value will be `true`.
228 
229 tsOverride @9 :Text;
230 # See `JSG_TS_OVERRIDE`'s documentation in the `## TypeScript` section of the JSG README.md.
231 # If `JSG_(STRUCT_)TS_OVERRIDE` is declared for a type, this value will be the contents of the
232 # macro declaration verbatim.
233 
234 tsDefine @10 :Text;
235 # See `JSG_TS_DEFINE`'s documentation in the `## TypeScript` section of the JSG README.md.
236 # If `JSG_(STRUCT_)TS_DEFINE` is declared for a type, this value will be the contents of the
237 # macro declaration verbatim.
238 
239 callable @11 :FunctionType;
240 # If this type is callable as a function, the signature of said function. Otherwise, null.
241 
242 builtinModules @12 :List(Module);
243 # List of all builtin modules provided by the context.
244}
245 
246struct Member {
247 # One of structure members
248 
249 union {
250 method @0 :Method;
251 # any kind of method
252 
253 property @1 :Property;
254 # any kind of property
255 
256 nested :group {
257 structure @2 :Structure;
258 
259 name @5 :Text;
260 # For JSG_NESTED_TYPE_NAMED, if name is different to structure
261 }
262 # nested type
263 
264 constant @3 :Constant;
265 # static constant
266 
267 constructor @4 :Constructor;
268 # structure constructor
269 }
270}
271 
272struct Method {
273 name @0 :Text;
274 returnType @1 :Type;
275 args @2 :List(Type);
276 static @3 :Bool;
277 fastApiCompatible @4: Bool;
278}
279 
280struct Property {
281 name @0 :Text;
282 type @1 :Type;
283 readonly @2 :Bool;
284 lazy @3 :Bool;
285 prototype @4 :Bool;
286 getterFastApiCompatible @5: Bool;
287 setterFastApiCompatible @6: Bool;
288}
289 
290struct Constant {
291 # static constant in the resource
292 
293 name @0 :Text;
294 
295 value @1 :Int64;
296 # TODO: we may need a union here
297}
298 
299struct Constructor {
300 args @0 :List(Type);
301}
302 
303struct Module {
304 specifier @0 :Text;
305 # if anyone ever needs module type, it can be implemented by either fixing the Modules reference
306 # problem above or copying the original enum.
307 # type @1 :Modules.ModuleType;
308 union {
309 structureName @1 :Text;
310 tsDeclarations @2 :Text;
311 }
312}
313 
314struct StructureGroups {
315 # Collection of structure groups, consumed by TypeScript definitions generator
316 
317 struct StructureGroup {
318 # Collection of related structures
319 
320 name @0 :Text;
321 
322 structures @1 :List(Structure);
323 }
324 
325 groups @0 :List(StructureGroup);
326 
327 modules @1 :List(Module);
328}
329 
330struct JsBuiltinType {
331 # special type for properties whose value is supplied by built-in javascript
332 
333 module @0 :Text;
334 # module from which the property is imported
335 
336 export @1 :Text;
337 # export name of the property
338}