@jsii/kernel 1.85.0 → 1.86.1
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/disk-cache/disk-cache.d.ts +1 -4
- package/lib/disk-cache/disk-cache.js +30 -30
- package/lib/kernel.d.ts +5 -48
- package/lib/kernel.js +662 -655
- package/lib/link.js +11 -0
- package/lib/objects.d.ts +10 -11
- package/lib/objects.js +86 -51
- package/lib/serialization.d.ts +10 -5
- package/lib/serialization.js +73 -73
- package/lib/tar-cache/index.js +5 -3
- package/package.json +5 -5
package/lib/link.js
CHANGED
|
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.link = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
+
/**
|
|
7
|
+
* If `node` is started with `--preserve-symlinks`, the module loaded will
|
|
8
|
+
* preserve symbolic links instead of resolving them, making it possible to
|
|
9
|
+
* symbolically link packages in place instead of fully copying them.
|
|
10
|
+
*/
|
|
11
|
+
const PRESERVE_SYMLINKS = process.execArgv.includes('--preserve-symlinks');
|
|
6
12
|
/**
|
|
7
13
|
* Creates directories containing hard links if possible, and falls back on
|
|
8
14
|
* copy otherwise.
|
|
@@ -11,6 +17,11 @@ const path_1 = require("path");
|
|
|
11
17
|
* @param destination is the new file or directory to create.
|
|
12
18
|
*/
|
|
13
19
|
function link(existing, destination) {
|
|
20
|
+
if (PRESERVE_SYMLINKS) {
|
|
21
|
+
(0, fs_1.mkdirSync)((0, path_1.dirname)(destination), { recursive: true });
|
|
22
|
+
(0, fs_1.symlinkSync)(existing, destination);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
14
25
|
const stat = (0, fs_1.statSync)(existing);
|
|
15
26
|
if (!stat.isDirectory()) {
|
|
16
27
|
try {
|
package/lib/objects.d.ts
CHANGED
|
@@ -6,8 +6,11 @@ import * as api from './api';
|
|
|
6
6
|
* This will return something if the object was constructed from a JSII-enabled
|
|
7
7
|
* class/constructor, or if a literal object was annotated with type
|
|
8
8
|
* information.
|
|
9
|
+
*
|
|
10
|
+
* @param obj the object for which a jsii FQN is requested.
|
|
11
|
+
* @param isVisibleType a function that determines if a type is visible.
|
|
9
12
|
*/
|
|
10
|
-
export declare function jsiiTypeFqn(obj: any):
|
|
13
|
+
export declare function jsiiTypeFqn(obj: any, isVisibleType: (fqn: spec.FQN) => boolean): spec.FQN | undefined;
|
|
11
14
|
/**
|
|
12
15
|
* If this object was previously serialized under a given reference, return the same reference
|
|
13
16
|
*
|
|
@@ -17,7 +20,7 @@ export declare function objectReference(obj: unknown): api.ObjRef | undefined;
|
|
|
17
20
|
/**
|
|
18
21
|
* Set the JSII FQN for classes produced by a given constructor
|
|
19
22
|
*/
|
|
20
|
-
export declare function tagJsiiConstructor(constructor: any, fqn:
|
|
23
|
+
export declare function tagJsiiConstructor(constructor: any, fqn: spec.FQN): void;
|
|
21
24
|
/**
|
|
22
25
|
* Table of JSII objects
|
|
23
26
|
*
|
|
@@ -25,16 +28,14 @@ export declare function tagJsiiConstructor(constructor: any, fqn: string): void;
|
|
|
25
28
|
* type.
|
|
26
29
|
*/
|
|
27
30
|
export declare class ObjectTable {
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
private nextid;
|
|
31
|
-
constructor(resolveType: (fqn: string) => spec.Type);
|
|
31
|
+
#private;
|
|
32
|
+
constructor(resolveType: (fqn: spec.FQN) => spec.Type);
|
|
32
33
|
/**
|
|
33
34
|
* Register the given object with the given type
|
|
34
35
|
*
|
|
35
36
|
* Return the existing registration if available.
|
|
36
37
|
*/
|
|
37
|
-
registerObject(obj: unknown, fqn:
|
|
38
|
+
registerObject(obj: unknown, fqn: spec.FQN, interfaces?: spec.FQN[]): api.ObjRef;
|
|
38
39
|
/**
|
|
39
40
|
* Find the object and registered type for the given ObjRef
|
|
40
41
|
*/
|
|
@@ -44,12 +45,10 @@ export declare class ObjectTable {
|
|
|
44
45
|
*/
|
|
45
46
|
deleteObject({ [api.TOKEN_REF]: objid }: api.ObjRef): void;
|
|
46
47
|
get count(): number;
|
|
47
|
-
private makeId;
|
|
48
|
-
private removeRedundant;
|
|
49
48
|
}
|
|
50
49
|
export interface RegisteredObject {
|
|
51
50
|
instance: any;
|
|
52
|
-
fqn:
|
|
53
|
-
interfaces?:
|
|
51
|
+
fqn: spec.FQN;
|
|
52
|
+
interfaces?: spec.FQN[];
|
|
54
53
|
}
|
|
55
54
|
//# sourceMappingURL=objects.d.ts.map
|
package/lib/objects.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
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
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _ObjectTable_instances, _ObjectTable_resolveType, _ObjectTable_objects, _ObjectTable_nextid, _ObjectTable_makeId, _ObjectTable_removeRedundant, _InterfaceCollection_resolveType, _InterfaceCollection_interfaces;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.ObjectTable = exports.tagJsiiConstructor = exports.objectReference = exports.jsiiTypeFqn = void 0;
|
|
4
16
|
const spec = require("@jsii/spec");
|
|
@@ -15,18 +27,42 @@ const OBJID_SYMBOL = Symbol.for('$__jsii__objid__$');
|
|
|
15
27
|
*/
|
|
16
28
|
const IFACES_SYMBOL = Symbol.for('$__jsii__interfaces__$');
|
|
17
29
|
/**
|
|
18
|
-
* Symbol
|
|
30
|
+
* Symbol under which jsii runtime type information is stored.
|
|
19
31
|
*/
|
|
20
|
-
const
|
|
32
|
+
const JSII_RTTI_SYMBOL = Symbol.for('jsii.rtti');
|
|
33
|
+
/**
|
|
34
|
+
* Cache for resolved associations between constructors and FQNs.
|
|
35
|
+
*/
|
|
36
|
+
const RESOLVED_TYPE_FQN = new WeakMap();
|
|
21
37
|
/**
|
|
22
38
|
* Get the JSII fqn for an object (if available)
|
|
23
39
|
*
|
|
24
40
|
* This will return something if the object was constructed from a JSII-enabled
|
|
25
41
|
* class/constructor, or if a literal object was annotated with type
|
|
26
42
|
* information.
|
|
43
|
+
*
|
|
44
|
+
* @param obj the object for which a jsii FQN is requested.
|
|
45
|
+
* @param isVisibleType a function that determines if a type is visible.
|
|
27
46
|
*/
|
|
28
|
-
function jsiiTypeFqn(obj) {
|
|
29
|
-
|
|
47
|
+
function jsiiTypeFqn(obj, isVisibleType) {
|
|
48
|
+
var _a;
|
|
49
|
+
const ctor = obj.constructor;
|
|
50
|
+
// We've already resolved for this type, return the cached value.
|
|
51
|
+
if (RESOLVED_TYPE_FQN.has(ctor)) {
|
|
52
|
+
return RESOLVED_TYPE_FQN.get(ctor);
|
|
53
|
+
}
|
|
54
|
+
let curr = ctor;
|
|
55
|
+
while ((_a = curr[JSII_RTTI_SYMBOL]) === null || _a === void 0 ? void 0 : _a.fqn) {
|
|
56
|
+
if (isVisibleType(curr[JSII_RTTI_SYMBOL].fqn)) {
|
|
57
|
+
const fqn = curr[JSII_RTTI_SYMBOL].fqn;
|
|
58
|
+
tagJsiiConstructor(curr, fqn);
|
|
59
|
+
tagJsiiConstructor(ctor, fqn);
|
|
60
|
+
return fqn;
|
|
61
|
+
}
|
|
62
|
+
// Walk up the prototype chain...
|
|
63
|
+
curr = Object.getPrototypeOf(curr);
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
30
66
|
}
|
|
31
67
|
exports.jsiiTypeFqn = jsiiTypeFqn;
|
|
32
68
|
/**
|
|
@@ -74,17 +110,13 @@ function tagObject(obj, objid, interfaces) {
|
|
|
74
110
|
* Set the JSII FQN for classes produced by a given constructor
|
|
75
111
|
*/
|
|
76
112
|
function tagJsiiConstructor(constructor, fqn) {
|
|
77
|
-
|
|
78
|
-
|
|
113
|
+
const existing = RESOLVED_TYPE_FQN.get(constructor);
|
|
114
|
+
if (existing != null) {
|
|
115
|
+
return assert.strictEqual(existing, fqn, `Unable to register ${constructor.name} as ${fqn}: it is already registerd with FQN ${existing}`);
|
|
79
116
|
}
|
|
80
117
|
// Mark this constructor as exported from a jsii module, so we know we
|
|
81
118
|
// should be considering it's FQN as a valid exported type.
|
|
82
|
-
|
|
83
|
-
configurable: false,
|
|
84
|
-
enumerable: false,
|
|
85
|
-
writable: false,
|
|
86
|
-
value: fqn,
|
|
87
|
-
});
|
|
119
|
+
RESOLVED_TYPE_FQN.set(constructor, fqn);
|
|
88
120
|
}
|
|
89
121
|
exports.tagJsiiConstructor = tagJsiiConstructor;
|
|
90
122
|
/**
|
|
@@ -95,9 +127,11 @@ exports.tagJsiiConstructor = tagJsiiConstructor;
|
|
|
95
127
|
*/
|
|
96
128
|
class ObjectTable {
|
|
97
129
|
constructor(resolveType) {
|
|
98
|
-
this
|
|
99
|
-
this
|
|
100
|
-
this
|
|
130
|
+
_ObjectTable_instances.add(this);
|
|
131
|
+
_ObjectTable_resolveType.set(this, void 0);
|
|
132
|
+
_ObjectTable_objects.set(this, new Map());
|
|
133
|
+
_ObjectTable_nextid.set(this, 10000);
|
|
134
|
+
__classPrivateFieldSet(this, _ObjectTable_resolveType, resolveType, "f");
|
|
101
135
|
}
|
|
102
136
|
/**
|
|
103
137
|
* Register the given object with the given type
|
|
@@ -121,17 +155,17 @@ class ObjectTable {
|
|
|
121
155
|
if (!Object.prototype.hasOwnProperty.call(obj, IFACES_SYMBOL)) {
|
|
122
156
|
console.error(`[jsii/kernel] WARNING: referenced object ${existingRef[api.TOKEN_REF]} does not have the ${String(IFACES_SYMBOL)} property!`);
|
|
123
157
|
}
|
|
124
|
-
this.
|
|
158
|
+
__classPrivateFieldGet(this, _ObjectTable_objects, "f").get(existingRef[api.TOKEN_REF]).interfaces =
|
|
125
159
|
obj[IFACES_SYMBOL] =
|
|
126
160
|
existingRef[api.TOKEN_INTERFACES] =
|
|
127
161
|
interfaces =
|
|
128
|
-
this.
|
|
162
|
+
__classPrivateFieldGet(this, _ObjectTable_instances, "m", _ObjectTable_removeRedundant).call(this, Array.from(allIfaces), fqn);
|
|
129
163
|
}
|
|
130
164
|
return existingRef;
|
|
131
165
|
}
|
|
132
|
-
interfaces = this.
|
|
133
|
-
const objid = this.
|
|
134
|
-
this.
|
|
166
|
+
interfaces = __classPrivateFieldGet(this, _ObjectTable_instances, "m", _ObjectTable_removeRedundant).call(this, interfaces, fqn);
|
|
167
|
+
const objid = __classPrivateFieldGet(this, _ObjectTable_instances, "m", _ObjectTable_makeId).call(this, fqn);
|
|
168
|
+
__classPrivateFieldGet(this, _ObjectTable_objects, "f").set(objid, { instance: obj, fqn, interfaces });
|
|
135
169
|
tagObject(obj, objid, interfaces);
|
|
136
170
|
return { [api.TOKEN_REF]: objid, [api.TOKEN_INTERFACES]: interfaces };
|
|
137
171
|
}
|
|
@@ -144,7 +178,7 @@ class ObjectTable {
|
|
|
144
178
|
throw new kernel_1.JsiiFault(`Malformed object reference: ${JSON.stringify(objref)}`);
|
|
145
179
|
}
|
|
146
180
|
const objid = objref[api.TOKEN_REF];
|
|
147
|
-
const obj = this.
|
|
181
|
+
const obj = __classPrivateFieldGet(this, _ObjectTable_objects, "f").get(objid);
|
|
148
182
|
if (!obj) {
|
|
149
183
|
throw new kernel_1.JsiiFault(`Object ${objid} not found`);
|
|
150
184
|
}
|
|
@@ -172,40 +206,41 @@ class ObjectTable {
|
|
|
172
206
|
* Delete the registration with the given objref
|
|
173
207
|
*/
|
|
174
208
|
deleteObject({ [api.TOKEN_REF]: objid }) {
|
|
175
|
-
if (!this.
|
|
209
|
+
if (!__classPrivateFieldGet(this, _ObjectTable_objects, "f").delete(objid)) {
|
|
176
210
|
throw new kernel_1.JsiiFault(`Object ${objid} not found`);
|
|
177
211
|
}
|
|
178
212
|
}
|
|
179
213
|
get count() {
|
|
180
|
-
return this.
|
|
181
|
-
}
|
|
182
|
-
makeId(fqn) {
|
|
183
|
-
return `${fqn}@${this.nextid++}`;
|
|
184
|
-
}
|
|
185
|
-
removeRedundant(interfaces, fqn) {
|
|
186
|
-
if (!interfaces || interfaces.length === 0) {
|
|
187
|
-
return undefined;
|
|
188
|
-
}
|
|
189
|
-
const result = new Set(interfaces);
|
|
190
|
-
const builtIn = new InterfaceCollection(this.resolveType);
|
|
191
|
-
if (fqn !== serialization_1.EMPTY_OBJECT_FQN) {
|
|
192
|
-
builtIn.addFromClass(fqn);
|
|
193
|
-
}
|
|
194
|
-
interfaces.forEach(builtIn.addFromInterface.bind(builtIn));
|
|
195
|
-
for (const iface of builtIn) {
|
|
196
|
-
result.delete(iface);
|
|
197
|
-
}
|
|
198
|
-
return result.size > 0 ? Array.from(result).sort() : undefined;
|
|
214
|
+
return __classPrivateFieldGet(this, _ObjectTable_objects, "f").size;
|
|
199
215
|
}
|
|
200
216
|
}
|
|
201
217
|
exports.ObjectTable = ObjectTable;
|
|
218
|
+
_ObjectTable_resolveType = new WeakMap(), _ObjectTable_objects = new WeakMap(), _ObjectTable_nextid = new WeakMap(), _ObjectTable_instances = new WeakSet(), _ObjectTable_makeId = function _ObjectTable_makeId(fqn) {
|
|
219
|
+
var _a, _b;
|
|
220
|
+
return `${fqn}@${__classPrivateFieldSet(this, _ObjectTable_nextid, (_b = __classPrivateFieldGet(this, _ObjectTable_nextid, "f"), _a = _b++, _b), "f"), _a}`;
|
|
221
|
+
}, _ObjectTable_removeRedundant = function _ObjectTable_removeRedundant(interfaces, fqn) {
|
|
222
|
+
if (!interfaces || interfaces.length === 0) {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
const result = new Set(interfaces);
|
|
226
|
+
const builtIn = new InterfaceCollection(__classPrivateFieldGet(this, _ObjectTable_resolveType, "f"));
|
|
227
|
+
if (fqn !== serialization_1.EMPTY_OBJECT_FQN) {
|
|
228
|
+
builtIn.addFromClass(fqn);
|
|
229
|
+
}
|
|
230
|
+
interfaces.forEach(builtIn.addFromInterface.bind(builtIn));
|
|
231
|
+
for (const iface of builtIn) {
|
|
232
|
+
result.delete(iface);
|
|
233
|
+
}
|
|
234
|
+
return result.size > 0 ? Array.from(result).sort() : undefined;
|
|
235
|
+
};
|
|
202
236
|
class InterfaceCollection {
|
|
203
237
|
constructor(resolveType) {
|
|
204
|
-
this
|
|
205
|
-
this
|
|
238
|
+
_InterfaceCollection_resolveType.set(this, void 0);
|
|
239
|
+
_InterfaceCollection_interfaces.set(this, new Set());
|
|
240
|
+
__classPrivateFieldSet(this, _InterfaceCollection_resolveType, resolveType, "f");
|
|
206
241
|
}
|
|
207
242
|
addFromClass(fqn) {
|
|
208
|
-
const ti = this.
|
|
243
|
+
const ti = __classPrivateFieldGet(this, _InterfaceCollection_resolveType, "f").call(this, fqn);
|
|
209
244
|
if (!spec.isClassType(ti)) {
|
|
210
245
|
throw new kernel_1.JsiiFault(`Expected a class, but received ${spec.describeTypeReference(ti)}`);
|
|
211
246
|
}
|
|
@@ -214,16 +249,16 @@ class InterfaceCollection {
|
|
|
214
249
|
}
|
|
215
250
|
if (ti.interfaces) {
|
|
216
251
|
for (const iface of ti.interfaces) {
|
|
217
|
-
if (this.
|
|
252
|
+
if (__classPrivateFieldGet(this, _InterfaceCollection_interfaces, "f").has(iface)) {
|
|
218
253
|
continue;
|
|
219
254
|
}
|
|
220
|
-
this.
|
|
255
|
+
__classPrivateFieldGet(this, _InterfaceCollection_interfaces, "f").add(iface);
|
|
221
256
|
this.addFromInterface(iface);
|
|
222
257
|
}
|
|
223
258
|
}
|
|
224
259
|
}
|
|
225
260
|
addFromInterface(fqn) {
|
|
226
|
-
const ti = this.
|
|
261
|
+
const ti = __classPrivateFieldGet(this, _InterfaceCollection_resolveType, "f").call(this, fqn);
|
|
227
262
|
if (!spec.isInterfaceType(ti)) {
|
|
228
263
|
throw new kernel_1.JsiiFault(`Expected an interface, but received ${spec.describeTypeReference(ti)}`);
|
|
229
264
|
}
|
|
@@ -231,15 +266,15 @@ class InterfaceCollection {
|
|
|
231
266
|
return;
|
|
232
267
|
}
|
|
233
268
|
for (const iface of ti.interfaces) {
|
|
234
|
-
if (this.
|
|
269
|
+
if (__classPrivateFieldGet(this, _InterfaceCollection_interfaces, "f").has(iface)) {
|
|
235
270
|
continue;
|
|
236
271
|
}
|
|
237
|
-
this.
|
|
272
|
+
__classPrivateFieldGet(this, _InterfaceCollection_interfaces, "f").add(iface);
|
|
238
273
|
this.addFromInterface(iface);
|
|
239
274
|
}
|
|
240
275
|
}
|
|
241
|
-
[Symbol.iterator]() {
|
|
242
|
-
return this
|
|
276
|
+
[(_InterfaceCollection_resolveType = new WeakMap(), _InterfaceCollection_interfaces = new WeakMap(), Symbol.iterator)]() {
|
|
277
|
+
return __classPrivateFieldGet(this, _InterfaceCollection_interfaces, "f")[Symbol.iterator]();
|
|
243
278
|
}
|
|
244
279
|
}
|
|
245
280
|
//# sourceMappingURL=objects.js.map
|
package/lib/serialization.d.ts
CHANGED
|
@@ -63,12 +63,15 @@ export declare const enum SerializationClass {
|
|
|
63
63
|
ReferenceType = "RefType",
|
|
64
64
|
Any = "Any"
|
|
65
65
|
}
|
|
66
|
-
declare type
|
|
66
|
+
declare type FindSymbol = (fqn: spec.FQN) => any;
|
|
67
|
+
declare type IsVisibleType = (fqn: spec.FQN) => boolean;
|
|
68
|
+
declare type LookupType = (fqn: spec.FQN) => spec.Type;
|
|
67
69
|
export interface SerializerHost {
|
|
68
70
|
readonly objects: ObjectTable;
|
|
69
71
|
debug(...args: any[]): void;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
isVisibleType: IsVisibleType;
|
|
73
|
+
lookupType: LookupType;
|
|
74
|
+
findSymbol: FindSymbol;
|
|
72
75
|
}
|
|
73
76
|
interface Serializer {
|
|
74
77
|
serialize(value: unknown, type: OptionalValueOrVoid, host: SerializerHost): any;
|
|
@@ -88,13 +91,15 @@ export interface TypeSerialization {
|
|
|
88
91
|
*
|
|
89
92
|
* There can be multiple, because the type can be a type union.
|
|
90
93
|
*/
|
|
91
|
-
export declare function serializationType(typeRef: OptionalValueOrVoid, lookup:
|
|
94
|
+
export declare function serializationType(typeRef: OptionalValueOrVoid, lookup: LookupType): TypeSerialization[];
|
|
92
95
|
export declare function process(host: SerializerHost, serde: keyof Serializer, value: unknown, type: OptionalValueOrVoid, context: string): any;
|
|
93
96
|
export declare class SerializationError extends Error {
|
|
94
97
|
readonly value: unknown;
|
|
95
98
|
readonly causes: readonly any[];
|
|
96
99
|
readonly name: string;
|
|
97
|
-
constructor(message: string, value: unknown,
|
|
100
|
+
constructor(message: string, value: unknown, { isVisibleType }: {
|
|
101
|
+
readonly isVisibleType: (fqn: string) => boolean;
|
|
102
|
+
}, causes?: readonly any[], { renderValue }?: {
|
|
98
103
|
renderValue?: boolean;
|
|
99
104
|
});
|
|
100
105
|
}
|