jsii-pacmak 1.65.0 → 1.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generate.sh +2 -1
- package/lib/targets/dotnet/dotnetgenerator.js +19 -110
- package/lib/targets/dotnet/dotnettyperesolver.js +5 -4
- package/lib/targets/dotnet/runtime-type-checking.d.ts +13 -0
- package/lib/targets/dotnet/runtime-type-checking.js +146 -0
- package/lib/targets/go/dependencies.d.ts +16 -0
- package/lib/targets/go/dependencies.js +59 -0
- package/lib/targets/go/emit-context.d.ts +2 -0
- package/lib/targets/go/package.d.ts +1 -0
- package/lib/targets/go/package.js +54 -33
- package/lib/targets/go/runtime/class-constructor.d.ts +2 -1
- package/lib/targets/go/runtime/class-constructor.js +4 -1
- package/lib/targets/go/runtime/method-call.d.ts +2 -2
- package/lib/targets/go/runtime/method-call.js +11 -5
- package/lib/targets/go/runtime/property-access.d.ts +3 -2
- package/lib/targets/go/runtime/property-access.js +7 -2
- package/lib/targets/go/runtime/runtime-type-checking.d.ts +29 -0
- package/lib/targets/go/runtime/runtime-type-checking.js +408 -0
- package/lib/targets/go/types/class.d.ts +10 -5
- package/lib/targets/go/types/class.js +60 -30
- package/lib/targets/go/types/enum.d.ts +2 -2
- package/lib/targets/go/types/enum.js +6 -2
- package/lib/targets/go/types/go-type-reference.d.ts +6 -1
- package/lib/targets/go/types/go-type-reference.js +37 -21
- package/lib/targets/go/types/go-type.d.ts +4 -1
- package/lib/targets/go/types/go-type.js +3 -0
- package/lib/targets/go/types/interface.d.ts +5 -3
- package/lib/targets/go/types/interface.js +40 -17
- package/lib/targets/go/types/struct.d.ts +7 -3
- package/lib/targets/go/types/struct.js +41 -2
- package/lib/targets/go/types/type-member.d.ts +8 -1
- package/lib/targets/go/types/type-member.js +63 -18
- package/lib/targets/go.d.ts +6 -2
- package/lib/targets/go.js +6 -4
- package/lib/targets/java.d.ts +19 -0
- package/lib/targets/java.js +223 -1
- package/lib/targets/python/type-name.js +3 -3
- package/lib/targets/python.js +5 -1
- package/lib/version.d.ts +2 -2
- package/lib/version.js +4 -3
- package/package.json +14 -14
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
13
|
+
var _GoClass_parameterValidators, _GoClassConstructor_validator;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.StaticMethod = exports.ClassMethod = exports.GoClassConstructor = exports.GoClass = void 0;
|
|
4
16
|
const naming_util_1 = require("../../../naming-util");
|
|
5
17
|
const comparators = require("../comparators");
|
|
6
18
|
const runtime_1 = require("../runtime");
|
|
19
|
+
const runtime_type_checking_1 = require("../runtime/runtime-type-checking");
|
|
7
20
|
const util_1 = require("../util");
|
|
8
21
|
const go_type_1 = require("./go-type");
|
|
9
22
|
const go_type_reference_1 = require("./go-type-reference");
|
|
@@ -14,6 +27,7 @@ const type_member_1 = require("./type-member");
|
|
|
14
27
|
class GoClass extends go_type_1.GoType {
|
|
15
28
|
constructor(pkg, type) {
|
|
16
29
|
super(pkg, type);
|
|
30
|
+
_GoClass_parameterValidators.set(this, void 0);
|
|
17
31
|
const methods = new Array();
|
|
18
32
|
const staticMethods = new Array();
|
|
19
33
|
for (const method of type.allMethods) {
|
|
@@ -44,6 +58,20 @@ class GoClass extends go_type_1.GoType {
|
|
|
44
58
|
this.initializer = new GoClassConstructor(this, type.initializer);
|
|
45
59
|
}
|
|
46
60
|
}
|
|
61
|
+
get parameterValidators() {
|
|
62
|
+
if (__classPrivateFieldGet(this, _GoClass_parameterValidators, "f") === undefined) {
|
|
63
|
+
__classPrivateFieldSet(this, _GoClass_parameterValidators, [
|
|
64
|
+
...this.methods.map((m) => m.validator).filter((v) => v != null),
|
|
65
|
+
...this.staticMethods.map((m) => m.validator).filter((v) => v != null),
|
|
66
|
+
...this.properties.map((m) => m.validator).filter((v) => v != null),
|
|
67
|
+
...this.staticProperties
|
|
68
|
+
.map((m) => m.validator)
|
|
69
|
+
.filter((v) => v != null),
|
|
70
|
+
...(this.initializer?.validator ? [this.initializer.validator] : []),
|
|
71
|
+
], "f");
|
|
72
|
+
}
|
|
73
|
+
return __classPrivateFieldGet(this, _GoClass_parameterValidators, "f");
|
|
74
|
+
}
|
|
47
75
|
get extends() {
|
|
48
76
|
// Cannot compute in constructor, as dependencies may not have finished
|
|
49
77
|
// resolving just yet.
|
|
@@ -80,13 +108,14 @@ class GoClass extends go_type_1.GoType {
|
|
|
80
108
|
method.emit(context);
|
|
81
109
|
}
|
|
82
110
|
for (const prop of this.staticProperties) {
|
|
83
|
-
|
|
111
|
+
prop.emitGetterProxy(context);
|
|
112
|
+
prop.emitSetterProxy(context);
|
|
84
113
|
}
|
|
85
114
|
for (const method of this.methods) {
|
|
86
115
|
method.emit(context);
|
|
87
116
|
}
|
|
88
117
|
}
|
|
89
|
-
emitRegistration(code) {
|
|
118
|
+
emitRegistration({ code }) {
|
|
90
119
|
code.open(`${runtime_1.JSII_RT_ALIAS}.RegisterClass(`);
|
|
91
120
|
code.line(`"${this.fqn}",`);
|
|
92
121
|
code.line(`reflect.TypeOf((*${this.name})(nil)).Elem(),`);
|
|
@@ -122,10 +151,11 @@ class GoClass extends go_type_1.GoType {
|
|
|
122
151
|
}
|
|
123
152
|
get specialDependencies() {
|
|
124
153
|
return {
|
|
125
|
-
|
|
154
|
+
fmt: false,
|
|
126
155
|
init: this.initializer != null ||
|
|
127
156
|
this.members.some((m) => m.specialDependencies.init),
|
|
128
157
|
internal: this.baseTypes.some((base) => this.pkg.isExternalType(base)),
|
|
158
|
+
runtime: this.initializer != null || this.members.length > 0,
|
|
129
159
|
time: !!this.initializer?.specialDependencies.time ||
|
|
130
160
|
this.members.some((m) => m.specialDependencies.time),
|
|
131
161
|
};
|
|
@@ -175,23 +205,6 @@ class GoClass extends go_type_1.GoType {
|
|
|
175
205
|
code.closeBlock();
|
|
176
206
|
code.line();
|
|
177
207
|
}
|
|
178
|
-
emitStaticProperty({ code }, prop) {
|
|
179
|
-
const getCaller = new runtime_1.StaticGetProperty(prop);
|
|
180
|
-
const propertyName = (0, naming_util_1.jsiiToPascalCase)(prop.name);
|
|
181
|
-
const name = `${this.name}_${propertyName}`;
|
|
182
|
-
code.openBlock(`func ${name}() ${prop.returnType}`);
|
|
183
|
-
getCaller.emit(code);
|
|
184
|
-
code.closeBlock();
|
|
185
|
-
code.line();
|
|
186
|
-
if (!prop.immutable) {
|
|
187
|
-
const setCaller = new runtime_1.StaticSetProperty(prop);
|
|
188
|
-
const name = `${this.name}_Set${propertyName}`;
|
|
189
|
-
code.openBlock(`func ${name}(val ${prop.returnType})`);
|
|
190
|
-
setCaller.emit(code);
|
|
191
|
-
code.closeBlock();
|
|
192
|
-
code.line();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
208
|
// emits the implementation of the setters for the struct
|
|
196
209
|
emitSetters(context) {
|
|
197
210
|
for (const property of this.properties) {
|
|
@@ -214,18 +227,27 @@ class GoClass extends go_type_1.GoType {
|
|
|
214
227
|
}
|
|
215
228
|
}
|
|
216
229
|
exports.GoClass = GoClass;
|
|
230
|
+
_GoClass_parameterValidators = new WeakMap();
|
|
217
231
|
class GoClassConstructor extends type_member_1.GoMethod {
|
|
218
232
|
constructor(parent, type) {
|
|
219
233
|
super(parent, type);
|
|
220
234
|
this.parent = parent;
|
|
221
235
|
this.type = type;
|
|
236
|
+
_GoClassConstructor_validator.set(this, null);
|
|
222
237
|
this.constructorRuntimeCall = new runtime_1.ClassConstructor(this);
|
|
223
238
|
}
|
|
239
|
+
get validator() {
|
|
240
|
+
if (__classPrivateFieldGet(this, _GoClassConstructor_validator, "f") === null) {
|
|
241
|
+
__classPrivateFieldSet(this, _GoClassConstructor_validator, runtime_type_checking_1.ParameterValidator.forConstructor(this), "f");
|
|
242
|
+
}
|
|
243
|
+
return __classPrivateFieldGet(this, _GoClassConstructor_validator, "f");
|
|
244
|
+
}
|
|
224
245
|
get specialDependencies() {
|
|
225
246
|
return {
|
|
226
|
-
|
|
247
|
+
fmt: false,
|
|
227
248
|
init: true,
|
|
228
249
|
internal: false,
|
|
250
|
+
runtime: true,
|
|
229
251
|
time: this.parameters.some((p) => p.reference.specialDependencies.time),
|
|
230
252
|
};
|
|
231
253
|
}
|
|
@@ -239,14 +261,15 @@ class GoClassConstructor extends type_member_1.GoMethod {
|
|
|
239
261
|
this.emitOverride(context);
|
|
240
262
|
}
|
|
241
263
|
}
|
|
242
|
-
emitNew(
|
|
264
|
+
emitNew(context) {
|
|
265
|
+
const { code, documenter } = context;
|
|
243
266
|
const constr = `New${this.parent.name}`;
|
|
244
267
|
const paramString = this.parameters.length === 0
|
|
245
268
|
? ''
|
|
246
269
|
: this.parameters.map((p) => p.toString()).join(', ');
|
|
247
270
|
documenter.emit(this.type.docs, this.apiLocation);
|
|
248
271
|
code.openBlock(`func ${constr}(${paramString}) ${this.parent.name}`);
|
|
249
|
-
this.constructorRuntimeCall.emit(
|
|
272
|
+
this.constructorRuntimeCall.emit(context);
|
|
250
273
|
code.closeBlock();
|
|
251
274
|
code.line();
|
|
252
275
|
}
|
|
@@ -263,6 +286,7 @@ class GoClassConstructor extends type_member_1.GoMethod {
|
|
|
263
286
|
}
|
|
264
287
|
}
|
|
265
288
|
exports.GoClassConstructor = GoClassConstructor;
|
|
289
|
+
_GoClassConstructor_validator = new WeakMap();
|
|
266
290
|
class ClassMethod extends type_member_1.GoMethod {
|
|
267
291
|
constructor(parent, method) {
|
|
268
292
|
super(parent, method);
|
|
@@ -271,11 +295,12 @@ class ClassMethod extends type_member_1.GoMethod {
|
|
|
271
295
|
this.runtimeCall = new runtime_1.MethodCall(this);
|
|
272
296
|
}
|
|
273
297
|
/* emit generates method implementation on the class */
|
|
274
|
-
emit(
|
|
298
|
+
emit(context) {
|
|
275
299
|
const name = this.name;
|
|
276
300
|
const returnTypeString = this.reference?.void ? '' : ` ${this.returnType}`;
|
|
301
|
+
const { code } = context;
|
|
277
302
|
code.openBlock(`func (${this.instanceArg} *${this.parent.proxyName}) ${name}(${this.paramString()})${returnTypeString}`);
|
|
278
|
-
this.runtimeCall.emit(
|
|
303
|
+
this.runtimeCall.emit(context);
|
|
279
304
|
code.closeBlock();
|
|
280
305
|
code.line();
|
|
281
306
|
}
|
|
@@ -288,11 +313,15 @@ class ClassMethod extends type_member_1.GoMethod {
|
|
|
288
313
|
get instanceArg() {
|
|
289
314
|
return this.parent.name.substring(0, 1).toLowerCase();
|
|
290
315
|
}
|
|
316
|
+
get static() {
|
|
317
|
+
return !!this.method.spec.static;
|
|
318
|
+
}
|
|
291
319
|
get specialDependencies() {
|
|
292
320
|
return {
|
|
293
|
-
|
|
321
|
+
fmt: false,
|
|
294
322
|
init: this.method.static,
|
|
295
323
|
internal: false,
|
|
324
|
+
runtime: true,
|
|
296
325
|
time: !!this.parameters.some((p) => p.reference.specialDependencies.time) ||
|
|
297
326
|
!!this.reference?.specialDependencies.time,
|
|
298
327
|
};
|
|
@@ -304,13 +333,14 @@ class StaticMethod extends ClassMethod {
|
|
|
304
333
|
super(parent, method);
|
|
305
334
|
this.parent = parent;
|
|
306
335
|
this.method = method;
|
|
336
|
+
this.name = `${this.parent.name}_${(0, naming_util_1.jsiiToPascalCase)(method.name)}`;
|
|
307
337
|
}
|
|
308
|
-
emit(
|
|
309
|
-
const name = `${this.parent.name}_${this.name}`;
|
|
338
|
+
emit(context) {
|
|
310
339
|
const returnTypeString = this.reference?.void ? '' : ` ${this.returnType}`;
|
|
340
|
+
const { code, documenter } = context;
|
|
311
341
|
documenter.emit(this.method.docs, this.apiLocation);
|
|
312
|
-
code.openBlock(`func ${name}(${this.paramString()})${returnTypeString}`);
|
|
313
|
-
this.runtimeCall.emit(
|
|
342
|
+
code.openBlock(`func ${this.name}(${this.paramString()})${returnTypeString}`);
|
|
343
|
+
this.runtimeCall.emit(context);
|
|
314
344
|
code.closeBlock();
|
|
315
345
|
code.line();
|
|
316
346
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CodeMaker } from 'codemaker';
|
|
2
1
|
import { EnumType } from 'jsii-reflect';
|
|
3
2
|
import { SpecialDependencies } from '../dependencies';
|
|
4
3
|
import { EmitContext } from '../emit-context';
|
|
@@ -7,8 +6,9 @@ import { GoType } from './go-type';
|
|
|
7
6
|
export declare class Enum extends GoType<EnumType> {
|
|
8
7
|
private readonly members;
|
|
9
8
|
constructor(pkg: Package, type: EnumType);
|
|
9
|
+
get parameterValidators(): never[];
|
|
10
10
|
emit(context: EmitContext): void;
|
|
11
|
-
emitRegistration(code:
|
|
11
|
+
emitRegistration({ code }: EmitContext): void;
|
|
12
12
|
get dependencies(): Package[];
|
|
13
13
|
get specialDependencies(): SpecialDependencies;
|
|
14
14
|
}
|
|
@@ -8,6 +8,9 @@ class Enum extends go_type_1.GoType {
|
|
|
8
8
|
super(pkg, type);
|
|
9
9
|
this.members = type.members.map((mem) => new GoEnumMember(this, mem));
|
|
10
10
|
}
|
|
11
|
+
get parameterValidators() {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
11
14
|
emit(context) {
|
|
12
15
|
this.emitDocs(context);
|
|
13
16
|
const { code } = context;
|
|
@@ -23,7 +26,7 @@ class Enum extends go_type_1.GoType {
|
|
|
23
26
|
code.close(`)`);
|
|
24
27
|
code.line();
|
|
25
28
|
}
|
|
26
|
-
emitRegistration(code) {
|
|
29
|
+
emitRegistration({ code }) {
|
|
27
30
|
code.open(`${runtime_1.JSII_RT_ALIAS}.RegisterEnum(`);
|
|
28
31
|
code.line(`"${this.fqn}",`);
|
|
29
32
|
code.line(`reflect.TypeOf((*${this.name})(nil)).Elem(),`);
|
|
@@ -39,9 +42,10 @@ class Enum extends go_type_1.GoType {
|
|
|
39
42
|
}
|
|
40
43
|
get specialDependencies() {
|
|
41
44
|
return {
|
|
42
|
-
|
|
45
|
+
fmt: false,
|
|
43
46
|
init: false,
|
|
44
47
|
internal: false,
|
|
48
|
+
runtime: false,
|
|
45
49
|
time: false,
|
|
46
50
|
};
|
|
47
51
|
}
|
|
@@ -27,8 +27,11 @@ declare type TypeMap = {
|
|
|
27
27
|
export declare class GoTypeRef {
|
|
28
28
|
readonly root: Package;
|
|
29
29
|
readonly reference: TypeReference;
|
|
30
|
+
private readonly options;
|
|
30
31
|
private _typeMap?;
|
|
31
|
-
constructor(root: Package, reference: TypeReference
|
|
32
|
+
constructor(root: Package, reference: TypeReference, options?: {
|
|
33
|
+
readonly opaqueUnionTypes: boolean;
|
|
34
|
+
});
|
|
32
35
|
get type(): GoType | undefined;
|
|
33
36
|
get specialDependencies(): SpecialDependencies;
|
|
34
37
|
get primitiveType(): string | undefined;
|
|
@@ -41,6 +44,8 @@ export declare class GoTypeRef {
|
|
|
41
44
|
* The go `import`s required in order to be able to use this type in code.
|
|
42
45
|
*/
|
|
43
46
|
get dependencies(): readonly Package[];
|
|
47
|
+
get unionOfTypes(): readonly GoTypeRef[] | undefined;
|
|
48
|
+
get withTransparentUnions(): GoTypeRef;
|
|
44
49
|
scopedName(scope: Package): string;
|
|
45
50
|
scopedReference(scope: Package): string;
|
|
46
51
|
private buildTypeMap;
|
|
@@ -29,9 +29,12 @@ class PrimitiveMapper {
|
|
|
29
29
|
* Accepts a JSII TypeReference and Go Package and can resolve the GoType within the module tree.
|
|
30
30
|
*/
|
|
31
31
|
class GoTypeRef {
|
|
32
|
-
constructor(root, reference
|
|
32
|
+
constructor(root, reference, options = {
|
|
33
|
+
opaqueUnionTypes: true,
|
|
34
|
+
}) {
|
|
33
35
|
this.root = root;
|
|
34
36
|
this.reference = reference;
|
|
37
|
+
this.options = options;
|
|
35
38
|
}
|
|
36
39
|
get type() {
|
|
37
40
|
if (this.reference.fqn) {
|
|
@@ -41,27 +44,25 @@ class GoTypeRef {
|
|
|
41
44
|
}
|
|
42
45
|
get specialDependencies() {
|
|
43
46
|
return {
|
|
44
|
-
|
|
47
|
+
fmt: false,
|
|
45
48
|
init: false,
|
|
46
49
|
internal: false,
|
|
47
|
-
|
|
50
|
+
runtime: false,
|
|
51
|
+
time: containsDate(this.reference, this.options.opaqueUnionTypes),
|
|
48
52
|
};
|
|
49
|
-
function containsDate(ref) {
|
|
53
|
+
function containsDate(ref, opaqueUnionType) {
|
|
50
54
|
if (ref.primitive === 'date') {
|
|
51
55
|
return true;
|
|
52
56
|
}
|
|
53
57
|
if (ref.arrayOfType) {
|
|
54
|
-
return containsDate(ref.arrayOfType);
|
|
58
|
+
return containsDate(ref.arrayOfType, opaqueUnionType);
|
|
55
59
|
}
|
|
56
60
|
if (ref.mapOfType) {
|
|
57
|
-
return containsDate(ref.mapOfType);
|
|
61
|
+
return containsDate(ref.mapOfType, opaqueUnionType);
|
|
62
|
+
}
|
|
63
|
+
if (!opaqueUnionType && ref.unionOfTypes) {
|
|
64
|
+
return ref.unionOfTypes.some((item) => containsDate(item, opaqueUnionType));
|
|
58
65
|
}
|
|
59
|
-
// NOTE: UNION gets represented as interface{} so we don't need to import
|
|
60
|
-
// individual types here...
|
|
61
|
-
//
|
|
62
|
-
// if (ref.unionOfTypes) {
|
|
63
|
-
// return ref.unionOfTypes.some(containsDate);
|
|
64
|
-
// }
|
|
65
66
|
return false;
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -106,12 +107,11 @@ class GoTypeRef {
|
|
|
106
107
|
ret.push(...this.typeMap.value.dependencies);
|
|
107
108
|
break;
|
|
108
109
|
case 'union':
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
// }
|
|
110
|
+
if (!this.options.opaqueUnionTypes) {
|
|
111
|
+
for (const t of this.typeMap.value) {
|
|
112
|
+
ret.push(...t.dependencies);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
115
|
break;
|
|
116
116
|
case 'void':
|
|
117
117
|
case 'primitive':
|
|
@@ -119,6 +119,22 @@ class GoTypeRef {
|
|
|
119
119
|
}
|
|
120
120
|
return ret;
|
|
121
121
|
}
|
|
122
|
+
get unionOfTypes() {
|
|
123
|
+
const typeMap = this.typeMap;
|
|
124
|
+
if (typeMap.type !== 'union') {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
return typeMap.value;
|
|
128
|
+
}
|
|
129
|
+
get withTransparentUnions() {
|
|
130
|
+
if (!this.options.opaqueUnionTypes) {
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
return new GoTypeRef(this.root, this.reference, {
|
|
134
|
+
...this.options,
|
|
135
|
+
opaqueUnionTypes: false,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
122
138
|
/*
|
|
123
139
|
* Return the name of a type for reference from the `Package` passed in
|
|
124
140
|
*/
|
|
@@ -135,19 +151,19 @@ class GoTypeRef {
|
|
|
135
151
|
else if (ref.reference.arrayOfType) {
|
|
136
152
|
return {
|
|
137
153
|
type: 'array',
|
|
138
|
-
value: new GoTypeRef(this.root, ref.reference.arrayOfType),
|
|
154
|
+
value: new GoTypeRef(this.root, ref.reference.arrayOfType, this.options),
|
|
139
155
|
};
|
|
140
156
|
}
|
|
141
157
|
else if (ref.reference.mapOfType) {
|
|
142
158
|
return {
|
|
143
159
|
type: 'map',
|
|
144
|
-
value: new GoTypeRef(this.root, ref.reference.mapOfType),
|
|
160
|
+
value: new GoTypeRef(this.root, ref.reference.mapOfType, this.options),
|
|
145
161
|
};
|
|
146
162
|
}
|
|
147
163
|
else if (ref.reference.unionOfTypes) {
|
|
148
164
|
return {
|
|
149
165
|
type: 'union',
|
|
150
|
-
value: ref.reference.unionOfTypes.map((typeRef) => new GoTypeRef(this.root, typeRef)),
|
|
166
|
+
value: ref.reference.unionOfTypes.map((typeRef) => new GoTypeRef(this.root, typeRef, this.options)),
|
|
151
167
|
};
|
|
152
168
|
}
|
|
153
169
|
else if (ref.reference.void) {
|
|
@@ -4,6 +4,7 @@ import { ApiLocation } from 'jsii-rosetta';
|
|
|
4
4
|
import { SpecialDependencies } from '../dependencies';
|
|
5
5
|
import { EmitContext } from '../emit-context';
|
|
6
6
|
import { Package } from '../package';
|
|
7
|
+
import { ParameterValidator, StructValidator } from '../runtime/runtime-type-checking';
|
|
7
8
|
import { GoClass } from './class';
|
|
8
9
|
import { GoInterface } from './interface';
|
|
9
10
|
export declare abstract class GoType<T extends Type = Type> {
|
|
@@ -14,8 +15,10 @@ export declare abstract class GoType<T extends Type = Type> {
|
|
|
14
15
|
readonly proxyName: string;
|
|
15
16
|
protected readonly apiLocation: ApiLocation;
|
|
16
17
|
constructor(pkg: Package, type: T);
|
|
18
|
+
get structValidator(): StructValidator | undefined;
|
|
19
|
+
abstract get parameterValidators(): readonly ParameterValidator[];
|
|
17
20
|
abstract emit(context: EmitContext): void;
|
|
18
|
-
abstract emitRegistration(
|
|
21
|
+
abstract emitRegistration(context: EmitContext): void;
|
|
19
22
|
abstract get dependencies(): Package[];
|
|
20
23
|
abstract get specialDependencies(): SpecialDependencies;
|
|
21
24
|
get namespace(): string;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { CodeMaker } from 'codemaker';
|
|
2
1
|
import { InterfaceType, Method, Property } from 'jsii-reflect';
|
|
3
2
|
import { SpecialDependencies } from '../dependencies';
|
|
4
3
|
import { EmitContext } from '../emit-context';
|
|
5
4
|
import { Package } from '../package';
|
|
6
5
|
import { MethodCall } from '../runtime';
|
|
6
|
+
import { ParameterValidator } from '../runtime/runtime-type-checking';
|
|
7
7
|
import { GoType } from './go-type';
|
|
8
8
|
import { GoMethod, GoProperty } from './type-member';
|
|
9
9
|
export declare class GoInterface extends GoType<InterfaceType> {
|
|
10
|
+
#private;
|
|
10
11
|
readonly methods: InterfaceMethod[];
|
|
11
12
|
readonly reimplementedMethods: readonly InterfaceMethod[];
|
|
12
13
|
readonly properties: InterfaceProperty[];
|
|
13
14
|
readonly reimplementedProperties: readonly InterfaceProperty[];
|
|
14
15
|
constructor(pkg: Package, type: InterfaceType);
|
|
16
|
+
get parameterValidators(): readonly ParameterValidator[];
|
|
15
17
|
emit(context: EmitContext): void;
|
|
16
|
-
emitRegistration(code:
|
|
18
|
+
emitRegistration({ code }: EmitContext): void;
|
|
17
19
|
get specialDependencies(): SpecialDependencies;
|
|
18
20
|
get extends(): GoInterface[];
|
|
19
21
|
get extendsDependencies(): Package[];
|
|
@@ -32,7 +34,7 @@ declare class InterfaceMethod extends GoMethod {
|
|
|
32
34
|
readonly runtimeCall: MethodCall;
|
|
33
35
|
constructor(parent: GoInterface, method: Method);
|
|
34
36
|
emitDecl({ code, documenter }: EmitContext): void;
|
|
35
|
-
emit(
|
|
37
|
+
emit(context: EmitContext): void;
|
|
36
38
|
get specialDependencies(): SpecialDependencies;
|
|
37
39
|
private get returnTypeString();
|
|
38
40
|
}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
13
|
+
var _GoInterface_parameterValidators;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.GoInterface = void 0;
|
|
4
16
|
const comparators = require("../comparators");
|
|
17
|
+
const dependencies_1 = require("../dependencies");
|
|
5
18
|
const runtime_1 = require("../runtime");
|
|
6
19
|
const util_1 = require("../util");
|
|
7
20
|
const go_type_1 = require("./go-type");
|
|
@@ -10,6 +23,7 @@ const type_member_1 = require("./type-member");
|
|
|
10
23
|
class GoInterface extends go_type_1.GoType {
|
|
11
24
|
constructor(pkg, type) {
|
|
12
25
|
super(pkg, type);
|
|
26
|
+
_GoInterface_parameterValidators.set(this, void 0);
|
|
13
27
|
this.methods = type.ownMethods
|
|
14
28
|
.map((method) => new InterfaceMethod(this, method))
|
|
15
29
|
.sort(comparators.byName);
|
|
@@ -39,6 +53,21 @@ class GoInterface extends go_type_1.GoType {
|
|
|
39
53
|
this.reimplementedProperties = [];
|
|
40
54
|
}
|
|
41
55
|
}
|
|
56
|
+
get parameterValidators() {
|
|
57
|
+
if (__classPrivateFieldGet(this, _GoInterface_parameterValidators, "f") == null) {
|
|
58
|
+
__classPrivateFieldSet(this, _GoInterface_parameterValidators, [
|
|
59
|
+
...this.methods.map((m) => m.validator).filter((v) => v != null),
|
|
60
|
+
...this.reimplementedMethods
|
|
61
|
+
.map((m) => m.validator)
|
|
62
|
+
.filter((v) => v != null),
|
|
63
|
+
...this.properties.map((p) => p.validator).filter((v) => v != null),
|
|
64
|
+
...this.reimplementedProperties
|
|
65
|
+
.map((p) => p.validator)
|
|
66
|
+
.filter((v) => v != null),
|
|
67
|
+
], "f");
|
|
68
|
+
}
|
|
69
|
+
return __classPrivateFieldGet(this, _GoInterface_parameterValidators, "f");
|
|
70
|
+
}
|
|
42
71
|
emit(context) {
|
|
43
72
|
this.emitDocs(context);
|
|
44
73
|
const { code } = context;
|
|
@@ -87,7 +116,7 @@ class GoInterface extends go_type_1.GoType {
|
|
|
87
116
|
}
|
|
88
117
|
}
|
|
89
118
|
}
|
|
90
|
-
emitRegistration(code) {
|
|
119
|
+
emitRegistration({ code }) {
|
|
91
120
|
code.open(`${runtime_1.JSII_RT_ALIAS}.RegisterInterface(`);
|
|
92
121
|
code.line(`"${this.fqn}",`);
|
|
93
122
|
code.line(`reflect.TypeOf((*${this.name})(nil)).Elem(),`);
|
|
@@ -113,22 +142,13 @@ class GoInterface extends go_type_1.GoType {
|
|
|
113
142
|
code.close(')');
|
|
114
143
|
}
|
|
115
144
|
get specialDependencies() {
|
|
116
|
-
return
|
|
117
|
-
|
|
118
|
-
...this.reimplementedProperties.map((p) => p.specialDependencies),
|
|
119
|
-
...this.methods.map((m) => m.specialDependencies),
|
|
120
|
-
...this.reimplementedMethods.map((m) => m.specialDependencies),
|
|
121
|
-
].reduce((acc, elt) => ({
|
|
122
|
-
runtime: acc.runtime || elt.runtime,
|
|
123
|
-
init: acc.init || elt.init,
|
|
124
|
-
internal: acc.internal,
|
|
125
|
-
time: acc.time || elt.time,
|
|
126
|
-
}), {
|
|
127
|
-
runtime: false,
|
|
145
|
+
return (0, dependencies_1.reduceSpecialDependencies)({
|
|
146
|
+
fmt: false,
|
|
128
147
|
init: false,
|
|
129
148
|
internal: this.extends.some((base) => this.pkg.isExternalType(base)),
|
|
149
|
+
runtime: false,
|
|
130
150
|
time: false,
|
|
131
|
-
});
|
|
151
|
+
}, ...this.properties.map((p) => p.specialDependencies), ...this.reimplementedProperties.map((p) => p.specialDependencies), ...this.methods.map((m) => m.specialDependencies), ...this.reimplementedMethods.map((m) => m.specialDependencies));
|
|
132
152
|
}
|
|
133
153
|
get extends() {
|
|
134
154
|
return this.type.interfaces
|
|
@@ -158,6 +178,7 @@ class GoInterface extends go_type_1.GoType {
|
|
|
158
178
|
}
|
|
159
179
|
}
|
|
160
180
|
exports.GoInterface = GoInterface;
|
|
181
|
+
_GoInterface_parameterValidators = new WeakMap();
|
|
161
182
|
class InterfaceProperty extends type_member_1.GoProperty {
|
|
162
183
|
constructor(parent, property) {
|
|
163
184
|
super(parent, property);
|
|
@@ -190,18 +211,20 @@ class InterfaceMethod extends type_member_1.GoMethod {
|
|
|
190
211
|
documenter.emit(this.method.docs, this.apiLocation);
|
|
191
212
|
code.line(`${this.name}(${this.paramString()})${this.returnTypeString}`);
|
|
192
213
|
}
|
|
193
|
-
emit(
|
|
214
|
+
emit(context) {
|
|
194
215
|
const name = this.name;
|
|
216
|
+
const { code } = context;
|
|
195
217
|
code.openBlock(`func (${this.instanceArg} *${this.parent.proxyName}) ${name}(${this.paramString()})${this.returnTypeString}`);
|
|
196
|
-
this.runtimeCall.emit(
|
|
218
|
+
this.runtimeCall.emit(context);
|
|
197
219
|
code.closeBlock();
|
|
198
220
|
code.line();
|
|
199
221
|
}
|
|
200
222
|
get specialDependencies() {
|
|
201
223
|
return {
|
|
202
|
-
|
|
224
|
+
fmt: false,
|
|
203
225
|
init: false,
|
|
204
226
|
internal: false,
|
|
227
|
+
runtime: true,
|
|
205
228
|
time: this.parameters.some((p) => p.reference.specialDependencies.time) ||
|
|
206
229
|
!!this.reference?.specialDependencies.time,
|
|
207
230
|
};
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { CodeMaker } from 'codemaker';
|
|
2
1
|
import { InterfaceType } from 'jsii-reflect';
|
|
3
2
|
import { SpecialDependencies } from '../dependencies';
|
|
4
3
|
import { EmitContext } from '../emit-context';
|
|
5
4
|
import { Package } from '../package';
|
|
5
|
+
import { ParameterValidator, StructValidator } from '../runtime/runtime-type-checking';
|
|
6
6
|
import { GoType } from './go-type';
|
|
7
|
+
import { GoProperty } from './type-member';
|
|
7
8
|
export declare class Struct extends GoType<InterfaceType> {
|
|
8
|
-
private
|
|
9
|
+
#private;
|
|
10
|
+
readonly properties: readonly GoProperty[];
|
|
9
11
|
constructor(parent: Package, type: InterfaceType);
|
|
12
|
+
get parameterValidators(): readonly ParameterValidator[];
|
|
13
|
+
get structValidator(): StructValidator | undefined;
|
|
10
14
|
get dependencies(): Package[];
|
|
11
15
|
get specialDependencies(): SpecialDependencies;
|
|
12
16
|
emit(context: EmitContext): void;
|
|
13
|
-
emitRegistration(code:
|
|
17
|
+
emitRegistration({ code, runtimeTypeChecking }: EmitContext): void;
|
|
14
18
|
}
|
|
15
19
|
//# sourceMappingURL=struct.d.ts.map
|