jsii-reflect 1.62.0 → 1.63.2

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/lib/assembly.d.ts CHANGED
@@ -111,11 +111,11 @@ export declare class Assembly extends ModuleLike {
111
111
  * it after all. Throws an exception if validation fails.
112
112
  */
113
113
  validate(): void;
114
- protected get submoduleMap(): Readonly<Record<string, Submodule>>;
114
+ protected get submoduleMap(): ReadonlyMap<string, Submodule>;
115
115
  /**
116
116
  * All types in the root of the assembly
117
117
  */
118
- protected get typeMap(): Readonly<Record<string, Type>>;
118
+ protected get typeMap(): ReadonlyMap<string, Type>;
119
119
  private get _dependencies();
120
120
  private _analyzeTypes;
121
121
  /**
package/lib/assembly.js CHANGED
@@ -101,10 +101,10 @@ class Assembly extends module_like_1.ModuleLike {
101
101
  * Dependencies on other assemblies (with semver), the key is the JSII assembly name.
102
102
  */
103
103
  get dependencies() {
104
- return Object.keys(this._dependencies).map((name) => this._dependencies[name]);
104
+ return Array.from(this._dependencies.values());
105
105
  }
106
106
  findDependency(name) {
107
- const dep = this._dependencies[name];
107
+ const dep = this._dependencies.get(name);
108
108
  if (!dep) {
109
109
  throw new Error(`Dependency ${name} not found for assembly ${this.name}`);
110
110
  }
@@ -127,7 +127,7 @@ class Assembly extends module_like_1.ModuleLike {
127
127
  */
128
128
  get submodules() {
129
129
  const { submodules } = this._analyzeTypes();
130
- return Object.entries(submodules)
130
+ return Array.from(submodules.entries())
131
131
  .filter(([name, _]) => name.split('.').length === 2)
132
132
  .map(([_, submodule]) => submodule);
133
133
  }
@@ -136,13 +136,13 @@ class Assembly extends module_like_1.ModuleLike {
136
136
  */
137
137
  get allSubmodules() {
138
138
  const { submodules } = this._analyzeTypes();
139
- return Object.values(submodules);
139
+ return Array.from(submodules.values());
140
140
  }
141
141
  /**
142
142
  * All types, even those in submodules and nested submodules.
143
143
  */
144
144
  get types() {
145
- return Object.values(this.typeMap);
145
+ return Array.from(this.typeMap.values());
146
146
  }
147
147
  /**
148
148
  * Return all types in the current assembly/submodule and all submodules underneath
@@ -177,10 +177,10 @@ class Assembly extends module_like_1.ModuleLike {
177
177
  }
178
178
  get _dependencies() {
179
179
  if (!this._dependencyCache) {
180
- this._dependencyCache = {};
180
+ this._dependencyCache = new Map();
181
181
  if (this.spec.dependencies) {
182
182
  for (const name of Object.keys(this.spec.dependencies)) {
183
- this._dependencyCache[name] = new dependency_1.Dependency(this.system, name, this.spec.dependencies[name]);
183
+ this._dependencyCache.set(name, new dependency_1.Dependency(this.system, name, this.spec.dependencies[name]));
184
184
  }
185
185
  }
186
186
  }
@@ -188,7 +188,7 @@ class Assembly extends module_like_1.ModuleLike {
188
188
  }
189
189
  _analyzeTypes() {
190
190
  if (!this._typeCache || !this._submoduleCache) {
191
- this._typeCache = {};
191
+ this._typeCache = new Map();
192
192
  const submoduleBuilders = this.discoverSubmodules();
193
193
  const ts = this.spec.types ?? {};
194
194
  for (const [fqn, typeSpec] of Object.entries(ts)) {
@@ -214,10 +214,10 @@ class Assembly extends module_like_1.ModuleLike {
214
214
  }
215
215
  if (submodule != null) {
216
216
  const moduleName = `${this.spec.name}.${submodule}`;
217
- submoduleBuilders[moduleName].addType(type);
217
+ submoduleBuilders.get(moduleName).addType(type);
218
218
  }
219
219
  else {
220
- this._typeCache[fqn] = type;
220
+ this._typeCache.set(fqn, type);
221
221
  }
222
222
  }
223
223
  this._submoduleCache = mapValues(submoduleBuilders, (b) => b.build());
@@ -230,9 +230,9 @@ class Assembly extends module_like_1.ModuleLike {
230
230
  */
231
231
  discoverSubmodules() {
232
232
  const system = this.system;
233
- const ret = {};
233
+ const ret = new Map();
234
234
  for (const [submoduleName, submoduleSpec] of Object.entries(this.spec.submodules ?? {})) {
235
- ret[submoduleName] = new SubmoduleBuilder(system, submoduleSpec, submoduleName, ret);
235
+ ret.set(submoduleName, new SubmoduleBuilder(system, submoduleSpec, submoduleName, ret));
236
236
  }
237
237
  return ret;
238
238
  }
@@ -252,7 +252,7 @@ class SubmoduleBuilder {
252
252
  this.spec = spec;
253
253
  this.fullName = fullName;
254
254
  this.allModuleBuilders = allModuleBuilders;
255
- this.types = {};
255
+ this.types = new Map();
256
256
  }
257
257
  /**
258
258
  * Whether this submodule is a direct child of another submodule
@@ -271,22 +271,22 @@ class SubmoduleBuilder {
271
271
  * Return all the builders from the map that are nested underneath ourselves.
272
272
  */
273
273
  findSubmoduleBuilders() {
274
- const ret = {};
275
- for (const [k, child] of Object.entries(this.allModuleBuilders)) {
274
+ const ret = new Map();
275
+ for (const [k, child] of this.allModuleBuilders) {
276
276
  if (child.isChildOf(this)) {
277
- ret[k] = child;
277
+ ret.set(k, child);
278
278
  }
279
279
  }
280
280
  return ret;
281
281
  }
282
282
  addType(type) {
283
- this.types[type.fqn] = type;
283
+ this.types.set(type.fqn, type);
284
284
  }
285
285
  }
286
286
  function mapValues(xs, fn) {
287
- const ret = {};
288
- for (const [k, v] of Object.entries(xs)) {
289
- ret[k] = fn(v);
287
+ const ret = new Map();
288
+ for (const [k, v] of xs) {
289
+ ret.set(k, fn(v));
290
290
  }
291
291
  return ret;
292
292
  }
package/lib/class.js CHANGED
@@ -5,7 +5,6 @@ const initializer_1 = require("./initializer");
5
5
  const method_1 = require("./method");
6
6
  const property_1 = require("./property");
7
7
  const reference_type_1 = require("./reference-type");
8
- const util_1 = require("./util");
9
8
  class ClassType extends reference_type_1.ReferenceType {
10
9
  constructor(system, assembly, spec) {
11
10
  super(system, assembly, spec);
@@ -57,14 +56,14 @@ class ClassType extends reference_type_1.ReferenceType {
57
56
  * @param inherited include all properties inherited from base classes (default: false)
58
57
  */
59
58
  getProperties(inherited = false) {
60
- return this._getProperties(inherited, this);
59
+ return Object.fromEntries(this._getProperties(inherited, this));
61
60
  }
62
61
  /**
63
62
  * List all methods in this class.
64
63
  * @param inherited include all methods inherited from base classes (default: false)
65
64
  */
66
65
  getMethods(inherited = false) {
67
- return this._getMethods(inherited, this);
66
+ return Object.fromEntries(this._getMethods(inherited, this));
68
67
  }
69
68
  /**
70
69
  * Lists all interfaces this class implements.
@@ -89,16 +88,22 @@ class ClassType extends reference_type_1.ReferenceType {
89
88
  return true;
90
89
  }
91
90
  _getProperties(inherited, parentType) {
92
- const base = inherited && this.base
91
+ const result = inherited && this.base
93
92
  ? this.base._getProperties(inherited, parentType)
94
- : {};
95
- return Object.assign(base, (0, util_1.indexBy)((this.spec.properties ?? []).map((p) => new property_1.Property(this.system, this.assembly, parentType, this, p)), (p) => p.name));
93
+ : new Map();
94
+ for (const p of this.spec.properties ?? []) {
95
+ result.set(p.name, new property_1.Property(this.system, this.assembly, parentType, this, p));
96
+ }
97
+ return result;
96
98
  }
97
99
  _getMethods(inherited, parentType) {
98
- const base = inherited && this.base
100
+ const result = inherited && this.base
99
101
  ? this.base._getMethods(inherited, parentType)
100
- : {};
101
- return Object.assign(base, (0, util_1.indexBy)((this.spec.methods ?? []).map((m) => new method_1.Method(this.system, this.assembly, parentType, this, m)), (m) => m.name));
102
+ : new Map();
103
+ for (const m of this.spec.methods ?? []) {
104
+ result.set(m.name, new method_1.Method(this.system, this.assembly, parentType, this, m));
105
+ }
106
+ return result;
102
107
  }
103
108
  }
104
109
  exports.ClassType = ClassType;
package/lib/interface.js CHANGED
@@ -10,7 +10,6 @@ exports.InterfaceType = void 0;
10
10
  const method_1 = require("./method");
11
11
  const property_1 = require("./property");
12
12
  const reference_type_1 = require("./reference-type");
13
- const util_1 = require("./util");
14
13
  class InterfaceType extends reference_type_1.ReferenceType {
15
14
  constructor(system, assembly, spec) {
16
15
  super(system, assembly, spec);
@@ -59,14 +58,14 @@ class InterfaceType extends reference_type_1.ReferenceType {
59
58
  * @param inherited include all properties inherited from base classes (default: false)
60
59
  */
61
60
  getProperties(inherited = false) {
62
- return this._getProperties(inherited, this);
61
+ return Object.fromEntries(this._getProperties(inherited, this));
63
62
  }
64
63
  /**
65
64
  * List all methods in this class.
66
65
  * @param inherited include all methods inherited from base classes (default: false)
67
66
  */
68
67
  getMethods(inherited = false) {
69
- return this._getMethods(inherited, this);
68
+ return Object.fromEntries(this._getMethods(inherited, this));
70
69
  }
71
70
  isDataType() {
72
71
  return !!this.spec.datatype;
@@ -75,22 +74,32 @@ class InterfaceType extends reference_type_1.ReferenceType {
75
74
  return true;
76
75
  }
77
76
  _getProperties(inherited, parentType) {
78
- const base = {};
77
+ const result = new Map();
79
78
  if (inherited) {
80
79
  for (const parent of this.getInterfaces()) {
81
- Object.assign(base, parent._getProperties(inherited, parentType));
80
+ for (const [key, value] of parent._getProperties(inherited, parentType)) {
81
+ result.set(key, value);
82
+ }
82
83
  }
83
84
  }
84
- return Object.assign(base, (0, util_1.indexBy)((this.spec.properties ?? []).map((p) => new property_1.Property(this.system, this.assembly, parentType, this, p)), (p) => p.name));
85
+ for (const p of this.spec.properties ?? []) {
86
+ result.set(p.name, new property_1.Property(this.system, this.assembly, parentType, this, p));
87
+ }
88
+ return result;
85
89
  }
86
90
  _getMethods(inherited, parentType) {
87
- const base = {};
91
+ const methods = new Map();
88
92
  if (inherited) {
89
93
  for (const parent of this.getInterfaces()) {
90
- Object.assign(base, parent._getMethods(inherited, parentType));
94
+ for (const [key, value] of parent._getMethods(inherited, parentType)) {
95
+ methods.set(key, value);
96
+ }
91
97
  }
92
98
  }
93
- return Object.assign(base, (0, util_1.indexBy)((this.spec.methods ?? []).map((m) => new method_1.Method(this.system, this.assembly, parentType, this, m)), (m) => m.name));
99
+ for (const m of this.spec.methods ?? []) {
100
+ methods.set(m.name, new method_1.Method(this.system, this.assembly, parentType, this, m));
101
+ }
102
+ return methods;
94
103
  }
95
104
  }
96
105
  exports.InterfaceType = InterfaceType;
@@ -14,8 +14,8 @@ export declare abstract class ModuleLike {
14
14
  */
15
15
  abstract readonly targets?: jsii.AssemblyTargets;
16
16
  abstract readonly readme?: jsii.ReadMe;
17
- protected abstract readonly submoduleMap: Readonly<Record<string, Submodule>>;
18
- protected abstract readonly typeMap: Readonly<Record<string, Type>>;
17
+ protected abstract readonly submoduleMap: ReadonlyMap<string, Submodule>;
18
+ protected abstract readonly typeMap: ReadonlyMap<string, Type>;
19
19
  /**
20
20
  * Cache for the results of `tryFindType`.
21
21
  */
@@ -13,10 +13,10 @@ class ModuleLike {
13
13
  this.typeLocatorCache = new Map();
14
14
  }
15
15
  get submodules() {
16
- return Object.values(this.submoduleMap);
16
+ return Array.from(this.submoduleMap.values());
17
17
  }
18
18
  get types() {
19
- return Object.values(this.typeMap);
19
+ return Array.from(this.typeMap.values());
20
20
  }
21
21
  get classes() {
22
22
  return this.types
@@ -37,7 +37,7 @@ class ModuleLike {
37
37
  if (this.typeLocatorCache.has(fqn)) {
38
38
  return this.typeLocatorCache.get(fqn);
39
39
  }
40
- const ownType = this.typeMap[fqn];
40
+ const ownType = this.typeMap.get(fqn);
41
41
  if (ownType != null) {
42
42
  this.typeLocatorCache.set(fqn, ownType);
43
43
  return ownType;
@@ -51,7 +51,7 @@ class ModuleLike {
51
51
  .split('.')
52
52
  .slice(0, myFqnLength + 1)
53
53
  .join('.');
54
- const sub = this.submoduleMap[subFqn];
54
+ const sub = this.submoduleMap.get(subFqn);
55
55
  const submoduleType = sub?.tryFindType(fqn);
56
56
  this.typeLocatorCache.set(fqn, submoduleType);
57
57
  return submoduleType;
@@ -5,13 +5,13 @@ import { TypeSystem } from './type-system';
5
5
  export declare class Submodule extends ModuleLike {
6
6
  readonly spec: jsii.Submodule;
7
7
  readonly fqn: string;
8
- protected readonly submoduleMap: Readonly<Record<string, Submodule>>;
9
- protected readonly typeMap: Readonly<Record<string, Type>>;
8
+ protected readonly submoduleMap: ReadonlyMap<string, Submodule>;
9
+ protected readonly typeMap: ReadonlyMap<string, Type>;
10
10
  /**
11
11
  * The simple name of the submodule (the last segment of the `fullName`).
12
12
  */
13
13
  readonly name: string;
14
- constructor(system: TypeSystem, spec: jsii.Submodule, fqn: string, submoduleMap: Readonly<Record<string, Submodule>>, typeMap: Readonly<Record<string, Type>>);
14
+ constructor(system: TypeSystem, spec: jsii.Submodule, fqn: string, submoduleMap: ReadonlyMap<string, Submodule>, typeMap: ReadonlyMap<string, Type>);
15
15
  /**
16
16
  * A map of target name to configuration, which is used when generating packages for
17
17
  * various languages.
@@ -6,15 +6,15 @@ import { Method } from './method';
6
6
  import { Property } from './property';
7
7
  import { Type } from './type';
8
8
  export declare class TypeSystem {
9
- /**
10
- * All assemblies in this type system.
11
- */
12
- readonly assemblies: Assembly[];
13
9
  /**
14
10
  * The "root" assemblies (ones that loaded explicitly via a "load" call).
15
11
  */
16
12
  readonly roots: Assembly[];
17
13
  private readonly _assemblyLookup;
14
+ /**
15
+ * All assemblies in this type system.
16
+ */
17
+ get assemblies(): readonly Assembly[];
18
18
  /**
19
19
  * Load all JSII dependencies of the given NPM package directory.
20
20
  *
@@ -11,15 +11,17 @@ const interface_1 = require("./interface");
11
11
  const util_1 = require("./util");
12
12
  class TypeSystem {
13
13
  constructor() {
14
- /**
15
- * All assemblies in this type system.
16
- */
17
- this.assemblies = new Array();
18
14
  /**
19
15
  * The "root" assemblies (ones that loaded explicitly via a "load" call).
20
16
  */
21
17
  this.roots = new Array();
22
- this._assemblyLookup = {};
18
+ this._assemblyLookup = new Map();
19
+ }
20
+ /**
21
+ * All assemblies in this type system.
22
+ */
23
+ get assemblies() {
24
+ return Array.from(this._assemblyLookup.values());
23
25
  }
24
26
  /**
25
27
  * Load all JSII dependencies of the given NPM package directory.
@@ -120,9 +122,8 @@ class TypeSystem {
120
122
  if (asm.system !== this) {
121
123
  throw new Error('Assembly has been created for different typesystem');
122
124
  }
123
- if (!this._assemblyLookup[asm.name]) {
124
- this._assemblyLookup[asm.name] = asm;
125
- this.assemblies.push(asm);
125
+ if (!this._assemblyLookup.has(asm.name)) {
126
+ this._assemblyLookup.set(asm.name, asm);
126
127
  }
127
128
  if (options.isRoot !== false) {
128
129
  this.addRoot(asm);
@@ -135,7 +136,7 @@ class TypeSystem {
135
136
  * @param name the name of the assembly being looked for.
136
137
  */
137
138
  includesAssembly(name) {
138
- return name in this._assemblyLookup;
139
+ return this._assemblyLookup.has(name);
139
140
  }
140
141
  isRoot(name) {
141
142
  return this.roots.map((r) => r.name).includes(name);
@@ -148,7 +149,7 @@ class TypeSystem {
148
149
  return ret;
149
150
  }
150
151
  tryFindAssembly(name) {
151
- return this._assemblyLookup[name];
152
+ return this._assemblyLookup.get(name);
152
153
  }
153
154
  findFqn(fqn) {
154
155
  const [assembly] = fqn.split('.');
@@ -247,7 +248,7 @@ class TypeSystem {
247
248
  return new assembly_1.Assembly(this, contents);
248
249
  }
249
250
  addRoot(asm) {
250
- if (!this.roots.map((r) => r.name).includes(asm.name)) {
251
+ if (!this.roots.some((r) => r.name === asm.name)) {
251
252
  this.roots.push(asm);
252
253
  }
253
254
  }
package/lib/util.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- export declare function indexBy<T>(xs: T[], f: (x: T) => string): {
2
- [key: string]: T;
3
- };
4
1
  /**
5
2
  * Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory
6
3
  *
package/lib/util.js CHANGED
@@ -1,16 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findUp = exports.findPackageJsonUp = exports.isBuiltinModule = exports.findDependencyDirectory = exports.indexBy = void 0;
3
+ exports.findUp = exports.findPackageJsonUp = exports.isBuiltinModule = exports.findDependencyDirectory = void 0;
4
4
  const fs = require("fs-extra");
5
5
  const path = require("path");
6
- function indexBy(xs, f) {
7
- const ret = {};
8
- for (const x of xs) {
9
- ret[f(x)] = x;
10
- }
11
- return ret;
12
- }
13
- exports.indexBy = indexBy;
14
6
  /**
15
7
  * Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory
16
8
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsii-reflect",
3
- "version": "1.62.0",
3
+ "version": "1.63.2",
4
4
  "description": "strongly-typed reflection library and tools for jsii",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -34,18 +34,18 @@
34
34
  "package": "package-js"
35
35
  },
36
36
  "dependencies": {
37
- "@jsii/check-node": "1.62.0",
38
- "@jsii/spec": "^1.62.0",
37
+ "@jsii/check-node": "1.63.2",
38
+ "@jsii/spec": "^1.63.2",
39
39
  "chalk": "^4",
40
40
  "fs-extra": "^10.1.0",
41
- "oo-ascii-tree": "^1.62.0",
41
+ "oo-ascii-tree": "^1.63.2",
42
42
  "yargs": "^16.2.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@scope/jsii-calc-lib": "^1.62.0",
45
+ "@scope/jsii-calc-lib": "^1.63.2",
46
46
  "@types/fs-extra": "^9.0.13",
47
- "jsii": "^1.62.0",
48
- "jsii-build-tools": "^1.62.0",
47
+ "jsii": "^1.63.2",
48
+ "jsii-build-tools": "^1.63.2",
49
49
  "jsii-calc": "^3.20.120"
50
50
  }
51
51
  }