jsii-pacmak 1.113.0 → 1.115.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.
Files changed (39) hide show
  1. package/bin/jsii-pacmak.js +1 -1
  2. package/lib/index.js +2 -0
  3. package/lib/npm-modules.d.ts +1 -1
  4. package/lib/npm-modules.js +1 -3
  5. package/lib/packaging.d.ts +1 -5
  6. package/lib/packaging.js +12 -6
  7. package/lib/rosetta-assembly.d.ts +20 -0
  8. package/lib/rosetta-assembly.js +29 -0
  9. package/lib/targets/dotnet/dotnetdocgenerator.d.ts +4 -1
  10. package/lib/targets/dotnet/dotnetdocgenerator.js +69 -13
  11. package/lib/targets/dotnet/dotnetgenerator.d.ts +0 -4
  12. package/lib/targets/dotnet/dotnetgenerator.js +24 -14
  13. package/lib/targets/dotnet/dotnetruntimegenerator.js +11 -2
  14. package/lib/targets/dotnet/dotnettyperesolver.d.ts +13 -0
  15. package/lib/targets/dotnet/dotnettyperesolver.js +42 -4
  16. package/lib/targets/dotnet.d.ts +1 -1
  17. package/lib/targets/dotnet.js +6 -4
  18. package/lib/targets/go/runtime/runtime-type-checking.js +1 -0
  19. package/lib/targets/go/types/go-type-reference.d.ts +3 -0
  20. package/lib/targets/go/types/go-type-reference.js +20 -0
  21. package/lib/targets/go.js +1 -1
  22. package/lib/targets/java.d.ts +28 -4
  23. package/lib/targets/java.js +411 -219
  24. package/lib/targets/python/requirements-dev.txt +2 -2
  25. package/lib/targets/python/type-name.d.ts +18 -0
  26. package/lib/targets/python/type-name.js +59 -1
  27. package/lib/targets/python.d.ts +2 -1
  28. package/lib/targets/python.js +53 -18
  29. package/lib/targets/type-literals.d.ts +22 -0
  30. package/lib/targets/type-literals.js +39 -0
  31. package/lib/type-utils.d.ts +3 -0
  32. package/lib/type-utils.js +10 -0
  33. package/lib/type-visitor.d.ts +19 -0
  34. package/lib/type-visitor.js +47 -0
  35. package/lib/util.d.ts +18 -5
  36. package/lib/util.js +80 -13
  37. package/lib/version.d.ts +1 -1
  38. package/lib/version.js +3 -3
  39. package/package.json +15 -14
@@ -4,9 +4,9 @@
4
4
  # package (wheel, sdist), but not declared as build-system dependencies.
5
5
 
6
6
  setuptools~=75.3.2 # build-system
7
- build~=1.2.2.post1 # build-system
7
+ build~=1.3.0 # build-system
8
8
 
9
- twine~=6.1.0
9
+ twine~=6.2.0
10
10
 
11
11
  # The dependency on packaging is necessary to work around an incompatibility between
12
12
  # what setuptools generates and what twine expects. <https://github.com/pypa/twine/issues/1216>
@@ -1,4 +1,8 @@
1
1
  import { Assembly, OptionalValue, TypeReference, Type } from '@jsii/spec';
2
+ import { CodeMaker } from 'codemaker';
3
+ /**
4
+ * Actually more of a TypeNameFactory than a TypeName
5
+ */
2
6
  export interface TypeName {
3
7
  pythonType(context: NamingContext): string;
4
8
  requiredImports(context: NamingContext): PythonImports;
@@ -21,6 +25,8 @@ export interface NamingContext {
21
25
  readonly typeResolver: (fqn: string) => Type;
22
26
  /** The submodule of the assembly in which the PythonType is expressed (could be the module root) */
23
27
  readonly submodule: string;
28
+ /** Holds the set of intersection types used in the current module */
29
+ readonly intersectionTypes: IntersectionTypesRegistry;
24
30
  /**
25
31
  * The declaration is made in the context of a type annotation (so it can be quoted)
26
32
  *
@@ -70,4 +76,16 @@ export declare function toPythonFqn(fqn: string, rootAssm: Assembly): {
70
76
  packageName: string;
71
77
  pythonFqn: string;
72
78
  };
79
+ /**
80
+ * Holds a set of intersection types used by the current set of modules
81
+ */
82
+ export declare class IntersectionTypesRegistry {
83
+ private readonly types;
84
+ /**
85
+ * Return a unique name for a protocol that extends the given types
86
+ */
87
+ obtain(types: string[]): string;
88
+ get typeNames(): string[];
89
+ flushHelperTypes(code: CodeMaker): void;
90
+ }
73
91
  //# sourceMappingURL=type-name.d.ts.map
@@ -10,8 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  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");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _Dict_element, _List_element, _Optional_wrapped, _Primitive_pythonType, _Union_options, _UserType_fqn;
13
+ var _Dict_element, _List_element, _Optional_wrapped, _Primitive_pythonType, _Union_options, _Intersection_types, _UserType_fqn;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.IntersectionTypesRegistry = void 0;
15
16
  exports.toTypeName = toTypeName;
16
17
  exports.toPackageName = toPackageName;
17
18
  exports.mergePythonImports = mergePythonImports;
@@ -45,6 +46,13 @@ function toTypeName(ref) {
45
46
  else if ((0, spec_1.isNamedTypeReference)(type)) {
46
47
  result = new UserType(type.fqn);
47
48
  }
49
+ else if ((0, spec_1.isIntersectionTypeReference)(type)) {
50
+ const types = type.intersection.types.map(toTypeName);
51
+ if (types.some((t) => !(t instanceof UserType))) {
52
+ throw new Error('Only user types are supported in intersections');
53
+ }
54
+ result = new Intersection(types);
55
+ }
48
56
  return optional ? new Optional(result) : result;
49
57
  }
50
58
  /**
@@ -178,6 +186,23 @@ class Union {
178
186
  }
179
187
  }
180
188
  _Union_options = new WeakMap();
189
+ class Intersection {
190
+ constructor(types) {
191
+ // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
192
+ _Intersection_types.set(this, void 0);
193
+ __classPrivateFieldSet(this, _Intersection_types, types, "f");
194
+ }
195
+ pythonType(context) {
196
+ // We will be generating a special type to represent the intersection
197
+ const name = context.intersectionTypes.obtain(__classPrivateFieldGet(this, _Intersection_types, "f").map((t) => t.pythonType(context)).map(stripQuotes));
198
+ // This will never be in scope already, so always render between quotes
199
+ return `'${name}'`;
200
+ }
201
+ requiredImports(context) {
202
+ return mergePythonImports(...__classPrivateFieldGet(this, _Intersection_types, "f").map((o) => o.requiredImports(context)));
203
+ }
204
+ }
205
+ _Intersection_types = new WeakMap();
181
206
  class UserType {
182
207
  constructor(fqn) {
183
208
  // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
@@ -346,4 +371,37 @@ function findParentSubmodule(type, assm) {
346
371
  }
347
372
  return namespaceFqn;
348
373
  }
374
+ /**
375
+ * Holds a set of intersection types used by the current set of modules
376
+ */
377
+ class IntersectionTypesRegistry {
378
+ constructor() {
379
+ this.types = new Map();
380
+ }
381
+ /**
382
+ * Return a unique name for a protocol that extends the given types
383
+ */
384
+ obtain(types) {
385
+ const derivedName = `_${types.map(lastComponent).join('_')}`;
386
+ this.types.set(derivedName, types);
387
+ return derivedName;
388
+ }
389
+ get typeNames() {
390
+ return Array.from(this.types.keys());
391
+ }
392
+ flushHelperTypes(code) {
393
+ for (const [name, types] of this.types.entries()) {
394
+ code.line('');
395
+ code.line(`class ${name}(${types.join(', ')}, typing_extensions.Protocol):`);
396
+ code.line(' pass');
397
+ }
398
+ }
399
+ }
400
+ exports.IntersectionTypesRegistry = IntersectionTypesRegistry;
401
+ function lastComponent(x) {
402
+ return x.split('.').slice(-1)[0];
403
+ }
404
+ function stripQuotes(x) {
405
+ return x.replace(/^"|"$/g, '');
406
+ }
349
407
  //# sourceMappingURL=type-name.js.map
@@ -40,13 +40,14 @@ type FindModuleCallback = (fqn: string) => spec.AssemblyConfiguration;
40
40
  type FindTypeCallback = (fqn: string) => spec.Type;
41
41
  declare class TypeResolver {
42
42
  private readonly types;
43
+ private readonly assembly;
43
44
  private readonly boundTo?;
44
45
  private readonly boundRe;
45
46
  private readonly moduleName?;
46
47
  private readonly moduleRe;
47
48
  private readonly findModule;
48
49
  private readonly findType;
49
- constructor(types: Map<string, PythonType>, findModule: FindModuleCallback, findType: FindTypeCallback, boundTo?: string, moduleName?: string);
50
+ constructor(types: Map<string, PythonType>, assembly: spec.Assembly, findModule: FindModuleCallback, findType: FindTypeCallback, boundTo?: string, moduleName?: string);
50
51
  bind(fqn: string, moduleName?: string): TypeResolver;
51
52
  isInModule(typeRef: spec.NamedTypeReference | string): boolean;
52
53
  isInNamespace(typeRef: spec.NamedTypeReference | string): boolean;
@@ -30,6 +30,7 @@ const _utils_1 = require("./_utils");
30
30
  const type_name_1 = require("./python/type-name");
31
31
  const util_2 = require("./python/util");
32
32
  const version_utils_1 = require("./version-utils");
33
+ const rosetta_assembly_1 = require("../rosetta-assembly");
33
34
  const index_1 = require("./index");
34
35
  // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-require-imports
35
36
  const spdxLicenseList = require('spdx-license-list');
@@ -54,7 +55,7 @@ class Python extends target_1.Target {
54
55
  // shim, but using this actually results in a WinError with Python 3.7 and 3.8 where venv will
55
56
  // fail to copy the python binary if it's not invoked as python.exe). More on this particular
56
57
  // issue can be read here: https://bugs.python.org/issue43749
57
- await (0, util_1.shell)(process.platform === 'win32' ? 'python' : 'python3', [
58
+ await (0, util_1.subprocess)(process.platform === 'win32' ? 'python' : 'python3', [
58
59
  '-m',
59
60
  'venv',
60
61
  '--system-site-packages', // Allow using globally installed packages (saves time & disk space)
@@ -67,18 +68,18 @@ class Python extends target_1.Target {
67
68
  };
68
69
  const python = path.join(venvBin, 'python');
69
70
  // Install the necessary things
70
- await (0, util_1.shell)(python, ['-m', 'pip', 'install', '--no-input', '-r', requirementsFile], {
71
+ await (0, util_1.subprocess)(python, ['-m', 'pip', 'install', '--no-input', '-r', requirementsFile], {
71
72
  cwd: sourceDir,
72
73
  env,
73
74
  retry: { maxAttempts: 5 },
74
75
  });
75
76
  // Actually package up our code, both as a sdist and a wheel for publishing.
76
- await (0, util_1.shell)(python, ['-m', 'build', '--outdir', outDir, sourceDir], {
77
+ await (0, util_1.subprocess)(python, ['-m', 'build', '--outdir', outDir, sourceDir], {
77
78
  cwd: sourceDir,
78
79
  env,
79
80
  retry: { maxAttempts: 5 },
80
81
  });
81
- await (0, util_1.shell)(python, ['-m', 'twine', 'check', path.join(outDir, '*')], {
82
+ await (0, util_1.shell)(`${python} -m twine check ${path.join(outDir, '*')}`, {
82
83
  cwd: sourceDir,
83
84
  env,
84
85
  });
@@ -404,17 +405,18 @@ class BaseMethod {
404
405
  liftedPropNames.add(toPythonParameterName(prop.name));
405
406
  }
406
407
  }
408
+ const typeFacs = this.parameters.map(type_name_1.toTypeName);
407
409
  // We need to turn a list of JSII parameters, into Python style arguments with
408
410
  // gradual typing, so we'll have to iterate over the list of parameters, and
409
411
  // build the list, converting as we go.
410
412
  const pythonParams = [];
411
- for (const param of this.parameters) {
413
+ for (const [param, typeFac] of (0, util_1.zip)(this.parameters, typeFacs)) {
412
414
  // We cannot (currently?) blindly use the names given to us by the JSII for
413
415
  // initializers, because our keyword lifting will allow two names to clash.
414
416
  // This can hopefully be removed once we get https://github.com/aws/jsii/issues/288
415
417
  // resolved.
416
418
  const paramName = toPythonParameterName(param.name, liftedPropNames);
417
- const paramType = (0, type_name_1.toTypeName)(param).pythonType({
419
+ const paramType = typeFac.pythonType({
418
420
  ...context,
419
421
  parameterType: true,
420
422
  });
@@ -1161,6 +1163,7 @@ class PythonModule {
1161
1163
  context = {
1162
1164
  ...context,
1163
1165
  submodule: this.fqn ?? context.submodule,
1166
+ intersectionTypes: new type_name_1.IntersectionTypesRegistry(),
1164
1167
  resolver,
1165
1168
  };
1166
1169
  // Before we write anything else, we need to write out our module headers, this
@@ -1288,6 +1291,15 @@ class PythonModule {
1288
1291
  code.line(`from . import ${submodule}`);
1289
1292
  }
1290
1293
  }
1294
+ context.typeCheckingHelper.flushStubs(code);
1295
+ context.intersectionTypes.flushHelperTypes(code);
1296
+ const interfaces = this.members
1297
+ .filter((m) => m instanceof Interface)
1298
+ .map((m) => m.pythonName);
1299
+ this.emitProtocolStripper(code, [
1300
+ ...interfaces,
1301
+ ...context.intersectionTypes.typeNames,
1302
+ ]);
1291
1303
  }
1292
1304
  /**
1293
1305
  * Emit the bin scripts if bin section defined.
@@ -1329,6 +1341,32 @@ class PythonModule {
1329
1341
  }
1330
1342
  return scripts;
1331
1343
  }
1344
+ /**
1345
+ * Emit a helper that will strip magic jsii elements from all protocol classes
1346
+ *
1347
+ * This is necessary because we attach the `__jsii_proxy_class__` and
1348
+ * `__jsii_type__` fields to Protocols/interfaces, which are then going to
1349
+ * show up when someone calls `typing.get_protocol_members()`, and interfere
1350
+ * with run-time type checking done by `typeguard`.
1351
+ *
1352
+ * `typing.get_protocol_members(x)` reads cached members from
1353
+ * `x.__protocol_attrs__` (put there by the `Protocol` metaclass), so what we
1354
+ * do is remove our magic members from that cached set.
1355
+ *
1356
+ * This is extremely hacky, and in a hypothetical future rewrite we should
1357
+ * store our metadata off-object (for example in a dict or `WeakKeyDictionary`),
1358
+ * so that our magic members don't interfere with built-in Python functions.
1359
+ * But for now we fiddle with the metadata to hide our magic members wherever
1360
+ * necessary.
1361
+ */
1362
+ emitProtocolStripper(code, protocolNames) {
1363
+ if (protocolNames.length === 0) {
1364
+ return;
1365
+ }
1366
+ code.line('');
1367
+ code.line(`for cls in [${protocolNames.join(', ')}]:`);
1368
+ code.line(` typing.cast(typing.Any, cls).__protocol_attrs__ = typing.cast(typing.Any, cls).__protocol_attrs__ - set(['__jsii_proxy_class__', '__jsii_type__'])`);
1369
+ }
1332
1370
  isDirectChild(pyMod) {
1333
1371
  if (this.pythonName === pyMod.pythonName ||
1334
1372
  !pyMod.pythonName.startsWith(`${this.pythonName}.`)) {
@@ -1438,7 +1476,6 @@ class Package {
1438
1476
  const filename = path.join('src', pythonModuleNameToFilename(mod.pythonName), '__init__.py');
1439
1477
  code.openFile(filename);
1440
1478
  mod.emit(code, context);
1441
- context.typeCheckingHelper.flushStubs(code);
1442
1479
  code.closeFile(filename);
1443
1480
  scripts.push(...mod.emitBinScripts(code));
1444
1481
  }
@@ -1606,8 +1643,9 @@ class Package {
1606
1643
  }
1607
1644
  }
1608
1645
  class TypeResolver {
1609
- constructor(types, findModule, findType, boundTo, moduleName) {
1646
+ constructor(types, assembly, findModule, findType, boundTo, moduleName) {
1610
1647
  this.types = types;
1648
+ this.assembly = assembly;
1611
1649
  this.findModule = findModule;
1612
1650
  this.findType = findType;
1613
1651
  this.moduleName = moduleName;
@@ -1620,7 +1658,7 @@ class TypeResolver {
1620
1658
  }
1621
1659
  }
1622
1660
  bind(fqn, moduleName) {
1623
- return new TypeResolver(this.types, this.findModule, this.findType, fqn, moduleName !== undefined
1661
+ return new TypeResolver(this.types, this.assembly, this.findModule, this.findType, fqn, moduleName !== undefined
1624
1662
  ? moduleName.startsWith('.')
1625
1663
  ? `${this.moduleName}${moduleName}`
1626
1664
  : moduleName
@@ -1678,14 +1716,8 @@ class TypeResolver {
1678
1716
  return this.findType(typeRef);
1679
1717
  }
1680
1718
  toPythonFQN(fqn) {
1681
- const [assemblyName, ...qualifiedIdentifiers] = fqn.split('.');
1682
- const fqnParts = [
1683
- this.findModule(assemblyName).targets.python.module,
1684
- ];
1685
- for (const part of qualifiedIdentifiers) {
1686
- fqnParts.push((0, util_2.toPythonIdentifier)(part));
1687
- }
1688
- return fqnParts.join('.');
1719
+ const { pythonFqn } = (0, type_name_1.toPythonFqn)(fqn, this.assembly);
1720
+ return pythonFqn;
1689
1721
  }
1690
1722
  }
1691
1723
  class PythonGenerator extends generator_1.Generator {
@@ -1801,10 +1833,12 @@ class PythonGenerator extends generator_1.Generator {
1801
1833
  }
1802
1834
  }
1803
1835
  convertExample(example, apiLoc) {
1836
+ (0, rosetta_assembly_1.assertSpecIsRosettaCompatible)(this.assembly);
1804
1837
  const translated = this.rosetta.translateExample(apiLoc, example, jsii_rosetta_1.TargetLanguage.PYTHON, (0, jsii_rosetta_1.enforcesStrictMode)(this.assembly));
1805
1838
  return translated.source;
1806
1839
  }
1807
1840
  convertMarkdown(markdown, apiLoc) {
1841
+ (0, rosetta_assembly_1.assertSpecIsRosettaCompatible)(this.assembly);
1808
1842
  return this.rosetta.translateSnippetsInMarkdown(apiLoc, markdown, jsii_rosetta_1.TargetLanguage.PYTHON, (0, jsii_rosetta_1.enforcesStrictMode)(this.assembly));
1809
1843
  }
1810
1844
  getPythonType(fqn) {
@@ -1830,7 +1864,7 @@ class PythonGenerator extends generator_1.Generator {
1830
1864
  this.package.addData(assemblyModule, this.getAssemblyFileName(), undefined);
1831
1865
  }
1832
1866
  onEndAssembly(assm, _fingerprint) {
1833
- const resolver = new TypeResolver(this.types, (fqn) => this.findModule(fqn), (fqn) => this.findType(fqn));
1867
+ const resolver = new TypeResolver(this.types, assm, (fqn) => this.findModule(fqn), (fqn) => this.findType(fqn));
1834
1868
  this.package.write(this.code, {
1835
1869
  assembly: assm,
1836
1870
  emittedTypes: new Set(),
@@ -1839,6 +1873,7 @@ class PythonGenerator extends generator_1.Generator {
1839
1873
  submodule: assm.name,
1840
1874
  typeCheckingHelper: new TypeCheckingHelper(),
1841
1875
  typeResolver: (fqn) => resolver.dereference(fqn),
1876
+ intersectionTypes: new type_name_1.IntersectionTypesRegistry(),
1842
1877
  });
1843
1878
  }
1844
1879
  /**
@@ -0,0 +1,22 @@
1
+ import * as spec from '@jsii/spec';
2
+ /**
3
+ * Make a type reference that references exactly a literal.
4
+ *
5
+ * This is useful if we don't want to reference a real type but a locally bound
6
+ * type parameter.
7
+ *
8
+ * This is a slightly hacky way to get the rendering functio to render a
9
+ * literal string, without looking it up. It gets us to embed the notion of
10
+ * rendering literal type parameters in the existing jsii spec without having to
11
+ * explicitly model it only for the purpose of a couple of code generators.
12
+ */
13
+ export declare function makeLiteralTypeReference(typeParameterName: string): spec.NamedTypeReference;
14
+ /**
15
+ * Return the type parameter name if the type reference is a type literal
16
+ */
17
+ export declare function literalTypeReference(x: spec.TypeReference): string | undefined;
18
+ /**
19
+ * Whether the given type is a literal type reference
20
+ */
21
+ export declare function isLiteralTypeReference(x: spec.TypeReference): boolean;
22
+ //# sourceMappingURL=type-literals.d.ts.map
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeLiteralTypeReference = makeLiteralTypeReference;
4
+ exports.literalTypeReference = literalTypeReference;
5
+ exports.isLiteralTypeReference = isLiteralTypeReference;
6
+ const spec = require("@jsii/spec");
7
+ const LITERAL_TYPE_PREFIX = '$lit:';
8
+ /**
9
+ * Make a type reference that references exactly a literal.
10
+ *
11
+ * This is useful if we don't want to reference a real type but a locally bound
12
+ * type parameter.
13
+ *
14
+ * This is a slightly hacky way to get the rendering functio to render a
15
+ * literal string, without looking it up. It gets us to embed the notion of
16
+ * rendering literal type parameters in the existing jsii spec without having to
17
+ * explicitly model it only for the purpose of a couple of code generators.
18
+ */
19
+ function makeLiteralTypeReference(typeParameterName) {
20
+ return { fqn: `${LITERAL_TYPE_PREFIX}${typeParameterName}` };
21
+ }
22
+ /**
23
+ * Return the type parameter name if the type reference is a type literal
24
+ */
25
+ function literalTypeReference(x) {
26
+ if (!spec.isNamedTypeReference(x)) {
27
+ return undefined;
28
+ }
29
+ return x.fqn.startsWith(LITERAL_TYPE_PREFIX)
30
+ ? x.fqn.slice(LITERAL_TYPE_PREFIX.length)
31
+ : undefined;
32
+ }
33
+ /**
34
+ * Whether the given type is a literal type reference
35
+ */
36
+ function isLiteralTypeReference(x) {
37
+ return literalTypeReference(x) !== undefined;
38
+ }
39
+ //# sourceMappingURL=type-literals.js.map
@@ -0,0 +1,3 @@
1
+ import * as spec from '@jsii/spec';
2
+ export declare function containsUnionType(typeRef: spec.TypeReference): typeRef is spec.UnionTypeReference | spec.CollectionTypeReference;
3
+ //# sourceMappingURL=type-utils.d.ts.map
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.containsUnionType = containsUnionType;
4
+ const spec = require("@jsii/spec");
5
+ function containsUnionType(typeRef) {
6
+ return (spec.isUnionTypeReference(typeRef) ||
7
+ (spec.isCollectionTypeReference(typeRef) &&
8
+ containsUnionType(typeRef.collection.elementtype)));
9
+ }
10
+ //# sourceMappingURL=type-utils.js.map
@@ -0,0 +1,19 @@
1
+ import * as spec from '@jsii/spec';
2
+ export interface TypeReferenceVisitor<A = void> {
3
+ named(ref: spec.NamedTypeReference): A;
4
+ primitive(ref: spec.PrimitiveTypeReference): A;
5
+ collection(ref: spec.CollectionTypeReference): A;
6
+ union(ref: spec.UnionTypeReference): A;
7
+ intersection(ref: spec.IntersectionTypeReference): A;
8
+ }
9
+ export declare function visitTypeReference<A>(typeRef: spec.TypeReference, visitor: TypeReferenceVisitor<A>): A;
10
+ export interface TypeVisitor<A = void> {
11
+ classType(t: spec.ClassType): A;
12
+ interfaceType(t: spec.InterfaceType): A;
13
+ dataType(t: spec.InterfaceType): A;
14
+ enumType(t: spec.EnumType): A;
15
+ }
16
+ export declare function visitType<A>(t: spec.Type, visitor: TypeVisitor<A>): A;
17
+ export declare function isDataType(t: spec.Type): t is spec.InterfaceType;
18
+ export declare function isBehavioralInterfaceType(t: spec.Type): t is spec.InterfaceType;
19
+ //# sourceMappingURL=type-visitor.d.ts.map
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.visitTypeReference = visitTypeReference;
4
+ exports.visitType = visitType;
5
+ exports.isDataType = isDataType;
6
+ exports.isBehavioralInterfaceType = isBehavioralInterfaceType;
7
+ const spec = require("@jsii/spec");
8
+ function visitTypeReference(typeRef, visitor) {
9
+ if (spec.isNamedTypeReference(typeRef)) {
10
+ return visitor.named(typeRef);
11
+ }
12
+ else if (spec.isPrimitiveTypeReference(typeRef)) {
13
+ return visitor.primitive(typeRef);
14
+ }
15
+ else if (spec.isCollectionTypeReference(typeRef)) {
16
+ return visitor.collection(typeRef);
17
+ }
18
+ else if (spec.isUnionTypeReference(typeRef)) {
19
+ return visitor.union(typeRef);
20
+ }
21
+ else if (spec.isIntersectionTypeReference(typeRef)) {
22
+ return visitor.intersection(typeRef);
23
+ }
24
+ throw new Error(`Unknown type reference: ${JSON.stringify(typeRef)}`);
25
+ }
26
+ function visitType(t, visitor) {
27
+ if (spec.isClassType(t)) {
28
+ return visitor.classType(t);
29
+ }
30
+ else if (spec.isInterfaceType(t) && t.datatype) {
31
+ return visitor.dataType(t);
32
+ }
33
+ else if (spec.isInterfaceType(t)) {
34
+ return visitor.interfaceType(t);
35
+ }
36
+ else if (spec.isEnumType(t)) {
37
+ return visitor.enumType(t);
38
+ }
39
+ throw new Error(`Unknown type: ${JSON.stringify(t)}`);
40
+ }
41
+ function isDataType(t) {
42
+ return spec.isInterfaceType(t) && !!t.datatype;
43
+ }
44
+ function isBehavioralInterfaceType(t) {
45
+ return spec.isInterfaceType(t) && !t.datatype;
46
+ }
47
+ //# sourceMappingURL=type-visitor.js.map
package/lib/util.d.ts CHANGED
@@ -62,7 +62,7 @@ export interface RetryOptions {
62
62
  * be awaited before making the next attempt (if
63
63
  * there are attempts left)
64
64
  */
65
- onFailedAttempt?: (error: unknown, attemptsLeft: number, backoffMilliseconds: number) => void;
65
+ onFailedAttempt?: (error: Error, attemptsLeft: number, backoffMilliseconds: number) => void;
66
66
  }
67
67
  export declare class AllAttemptsFailed<R> extends Error {
68
68
  readonly callback: () => Promise<R>;
@@ -87,16 +87,28 @@ export interface ShellOptions extends Omit<SpawnOptions, 'shell' | 'stdio'> {
87
87
  readonly retry?: RetryOptions;
88
88
  }
89
89
  /**
90
- * Spawns a child process with the provided command and arguments. The child
91
- * process is always spawned using `shell: true`, and the contents of
90
+ * Spawns a shell with the provided commandline.
91
+ *
92
+ * The child process is always spawned using `shell: true`, and the contents of
92
93
  * `process.env` is used as the initial value of the `env` spawn option (values
93
94
  * provided in `options.env` can override those).
95
+ */
96
+ export declare function shell(commandLine: string, options?: ShellOptions): Promise<string>;
97
+ /**
98
+ * Spawns a subprocess with the provided command and arguments.
99
+ *
100
+ * The child process is always spawned using `shell: false`, and the contents of
101
+ * `process.env` is used as the initial value of the `env` spawn option (values
102
+ * provided in `options.env` can override those).
103
+ *
104
+ * To make this work on Windows, if the binary happens to resolve to a batch file
105
+ * we run it through cmd.exe.
94
106
  *
95
- * @param cmd the command to shell out to.
107
+ * @param binary the command to shell out to.
96
108
  * @param args the arguments to provide to `cmd`
97
109
  * @param options any options to pass to `spawn`
98
110
  */
99
- export declare function shell(cmd: string, args: string[], { retry: retryOptions, ...options }?: ShellOptions): Promise<string>;
111
+ export declare function subprocess(binary: string, args: string[], options?: ShellOptions): Promise<string>;
100
112
  /**
101
113
  * Strip filesystem unsafe characters from a string
102
114
  */
@@ -119,4 +131,5 @@ export declare function setExtend<A>(xs: Set<A>, els: Iterable<A>): void;
119
131
  export declare function filterAsync<A>(xs: A[], pred: (x: A) => Promise<boolean>): Promise<A[]>;
120
132
  export declare function wait(ms: number): Promise<void>;
121
133
  export declare function flatten<A>(xs: readonly A[][]): A[];
134
+ export declare function zip<A, B>(xs: A[], ys: B[]): Array<[A, B]>;
122
135
  //# sourceMappingURL=util.d.ts.map