@jsii/kernel 1.60.1 → 1.63.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/jest.config.mjs +3 -0
- package/lib/kernel.d.ts +6 -17
- package/lib/kernel.js +111 -150
- package/lib/objects.d.ts +2 -2
- package/lib/objects.js +15 -11
- package/lib/recording.js +1 -1
- package/lib/serialization.d.ts +9 -1
- package/lib/serialization.js +170 -90
- package/package.json +6 -6
package/lib/objects.js
CHANGED
|
@@ -24,7 +24,8 @@ const JSII_SYMBOL = Symbol.for('__jsii__');
|
|
|
24
24
|
* information.
|
|
25
25
|
*/
|
|
26
26
|
function jsiiTypeFqn(obj) {
|
|
27
|
-
|
|
27
|
+
var _a;
|
|
28
|
+
return (_a = obj.constructor[JSII_SYMBOL]) === null || _a === void 0 ? void 0 : _a.fqn;
|
|
28
29
|
}
|
|
29
30
|
exports.jsiiTypeFqn = jsiiTypeFqn;
|
|
30
31
|
/**
|
|
@@ -89,7 +90,7 @@ exports.tagJsiiConstructor = tagJsiiConstructor;
|
|
|
89
90
|
class ObjectTable {
|
|
90
91
|
constructor(resolveType) {
|
|
91
92
|
this.resolveType = resolveType;
|
|
92
|
-
this.objects =
|
|
93
|
+
this.objects = new Map();
|
|
93
94
|
this.nextid = 10000;
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
@@ -98,6 +99,7 @@ class ObjectTable {
|
|
|
98
99
|
* Return the existing registration if available.
|
|
99
100
|
*/
|
|
100
101
|
registerObject(obj, fqn, interfaces) {
|
|
102
|
+
var _a;
|
|
101
103
|
if (fqn === undefined) {
|
|
102
104
|
throw new Error('FQN cannot be undefined');
|
|
103
105
|
}
|
|
@@ -105,7 +107,7 @@ class ObjectTable {
|
|
|
105
107
|
if (existingRef) {
|
|
106
108
|
if (interfaces) {
|
|
107
109
|
const allIfaces = new Set(interfaces);
|
|
108
|
-
for (const iface of existingRef[api.TOKEN_INTERFACES]
|
|
110
|
+
for (const iface of (_a = existingRef[api.TOKEN_INTERFACES]) !== null && _a !== void 0 ? _a : []) {
|
|
109
111
|
allIfaces.add(iface);
|
|
110
112
|
}
|
|
111
113
|
// Note - obj[INTERFACES_SYMBOL] should already have been declared as a
|
|
@@ -113,7 +115,7 @@ class ObjectTable {
|
|
|
113
115
|
if (!Object.prototype.hasOwnProperty.call(obj, IFACES_SYMBOL)) {
|
|
114
116
|
console.error(`[jsii/kernel] WARNING: referenced object ${existingRef[api.TOKEN_REF]} does not have the ${String(IFACES_SYMBOL)} property!`);
|
|
115
117
|
}
|
|
116
|
-
this.objects
|
|
118
|
+
this.objects.get(existingRef[api.TOKEN_REF]).interfaces =
|
|
117
119
|
obj[IFACES_SYMBOL] =
|
|
118
120
|
existingRef[api.TOKEN_INTERFACES] =
|
|
119
121
|
interfaces =
|
|
@@ -123,7 +125,7 @@ class ObjectTable {
|
|
|
123
125
|
}
|
|
124
126
|
interfaces = this.removeRedundant(interfaces, fqn);
|
|
125
127
|
const objid = this.makeId(fqn);
|
|
126
|
-
this.objects
|
|
128
|
+
this.objects.set(objid, { instance: obj, fqn, interfaces });
|
|
127
129
|
tagObject(obj, objid, interfaces);
|
|
128
130
|
return { [api.TOKEN_REF]: objid, [api.TOKEN_INTERFACES]: interfaces };
|
|
129
131
|
}
|
|
@@ -131,11 +133,12 @@ class ObjectTable {
|
|
|
131
133
|
* Find the object and registered type for the given ObjRef
|
|
132
134
|
*/
|
|
133
135
|
findObject(objref) {
|
|
136
|
+
var _a;
|
|
134
137
|
if (typeof objref !== 'object' || !(api.TOKEN_REF in objref)) {
|
|
135
138
|
throw new Error(`Malformed object reference: ${JSON.stringify(objref)}`);
|
|
136
139
|
}
|
|
137
140
|
const objid = objref[api.TOKEN_REF];
|
|
138
|
-
const obj = this.objects
|
|
141
|
+
const obj = this.objects.get(objid);
|
|
139
142
|
if (!obj) {
|
|
140
143
|
throw new Error(`Object ${objid} not found`);
|
|
141
144
|
}
|
|
@@ -150,7 +153,7 @@ class ObjectTable {
|
|
|
150
153
|
return {
|
|
151
154
|
...obj,
|
|
152
155
|
interfaces: [
|
|
153
|
-
...(obj.interfaces
|
|
156
|
+
...((_a = obj.interfaces) !== null && _a !== void 0 ? _a : []),
|
|
154
157
|
// We append at the end so "registered" interface information has
|
|
155
158
|
// precedence over client-declared ones.
|
|
156
159
|
...additionalInterfaces,
|
|
@@ -162,12 +165,13 @@ class ObjectTable {
|
|
|
162
165
|
/**
|
|
163
166
|
* Delete the registration with the given objref
|
|
164
167
|
*/
|
|
165
|
-
deleteObject(
|
|
166
|
-
this.
|
|
167
|
-
|
|
168
|
+
deleteObject({ [api.TOKEN_REF]: objid }) {
|
|
169
|
+
if (!this.objects.delete(objid)) {
|
|
170
|
+
throw new Error(`Object ${objid} not found`);
|
|
171
|
+
}
|
|
168
172
|
}
|
|
169
173
|
get count() {
|
|
170
|
-
return
|
|
174
|
+
return this.objects.size;
|
|
171
175
|
}
|
|
172
176
|
makeId(fqn) {
|
|
173
177
|
return `${fqn}@${this.nextid++}`;
|
package/lib/recording.js
CHANGED
|
@@ -39,7 +39,7 @@ function recordInteraction(kernel, inputOutputLogPath) {
|
|
|
39
39
|
try {
|
|
40
40
|
const ret = old.value.apply(this, args);
|
|
41
41
|
// if this is an async function, wait for the promised value.
|
|
42
|
-
if (typeof ret
|
|
42
|
+
if (typeof (ret === null || ret === void 0 ? void 0 : ret.then) === 'function') {
|
|
43
43
|
return new Promise((ok, fail) => {
|
|
44
44
|
return ret
|
|
45
45
|
.then((value) => {
|
package/lib/serialization.d.ts
CHANGED
|
@@ -68,7 +68,6 @@ export interface SerializerHost {
|
|
|
68
68
|
readonly objects: ObjectTable;
|
|
69
69
|
debug(...args: any[]): void;
|
|
70
70
|
lookupType(fqn: string): spec.Type;
|
|
71
|
-
recurse(x: any, type: OptionalValueOrVoid): any;
|
|
72
71
|
findSymbol(fqn: spec.FQN): any;
|
|
73
72
|
}
|
|
74
73
|
interface Serializer {
|
|
@@ -88,5 +87,14 @@ export interface TypeSerialization {
|
|
|
88
87
|
* There can be multiple, because the type can be a type union.
|
|
89
88
|
*/
|
|
90
89
|
export declare function serializationType(typeRef: OptionalValueOrVoid, lookup: TypeLookup): TypeSerialization[];
|
|
90
|
+
export declare function process(host: SerializerHost, serde: keyof Serializer, value: unknown, type: OptionalValueOrVoid, context: string): any;
|
|
91
|
+
export declare class SerializationError extends Error {
|
|
92
|
+
readonly value: unknown;
|
|
93
|
+
readonly causes: readonly any[];
|
|
94
|
+
readonly name: string;
|
|
95
|
+
constructor(message: string, value: unknown, causes?: readonly any[], { renderValue }?: {
|
|
96
|
+
renderValue?: boolean;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
91
99
|
export {};
|
|
92
100
|
//# sourceMappingURL=serialization.d.ts.map
|