@airgap/icp 0.13.15-beta.1 → 0.13.15-beta.11
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/package.json +8 -6
- package/v1/block-explorer/ICPBlockExplorer.d.ts +1 -1
- package/v1/block-explorer/ICPBlockExplorer.js +16 -49
- package/v1/block-explorer/ICPBlockExplorer.js.map +1 -1
- package/v1/index.d.ts +3 -2
- package/v1/index.js +9 -5
- package/v1/index.js.map +1 -1
- package/v1/module/ICPModule.d.ts +2 -4
- package/v1/module/ICPModule.js +53 -94
- package/v1/module/ICPModule.js.map +1 -1
- package/v1/module.js +1 -1
- package/v1/module.js.map +1 -1
- package/v1/protocol/ICPGovernance.d.ts +39 -0
- package/v1/protocol/ICPGovernance.js +1177 -0
- package/v1/protocol/ICPGovernance.js.map +1 -0
- package/v1/protocol/ICPImplementation.d.ts +30 -5
- package/v1/protocol/ICPImplementation.js +317 -252
- package/v1/protocol/ICPImplementation.js.map +1 -1
- package/v1/protocol/ICPProtocol.d.ts +60 -8
- package/v1/protocol/ICPProtocol.js +765 -320
- package/v1/protocol/ICPProtocol.js.map +1 -1
- package/v1/protocol/icrc/CkBTCProtocol.js +138 -225
- package/v1/protocol/icrc/CkBTCProtocol.js.map +1 -1
- package/v1/protocol/icrc/ICRC1Protocol.d.ts +4 -4
- package/v1/protocol/icrc/ICRC1Protocol.js +338 -553
- package/v1/protocol/icrc/ICRC1Protocol.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +48 -5
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +8 -2
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +31 -1
- package/v1/serializer/v3/serializer-companion.js +85 -144
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +22 -60
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/serializer/v3/validators/validators.js +19 -58
- package/v1/serializer/v3/validators/validators.js.map +1 -1
- package/v1/types/governance.d.ts +29 -0
- package/v1/types/governance.js +279 -210
- package/v1/types/governance.js.map +1 -1
- package/v1/types/icrc/ledger.js +22 -23
- package/v1/types/icrc/ledger.js.map +1 -1
- package/v1/types/ledger.d.ts +1 -0
- package/v1/types/ledger.js +37 -38
- package/v1/types/ledger.js.map +1 -1
- package/v1/types/management_idl.js +6 -7
- package/v1/types/management_idl.js.map +1 -1
- package/v1/types/protocol.d.ts +2 -1
- package/v1/types/transaction.d.ts +22 -3
- package/v1/types/transaction.js +38 -0
- package/v1/types/transaction.js.map +1 -1
- package/v1/utils/account.js +42 -70
- package/v1/utils/account.js.map +1 -1
- package/v1/utils/actor.js +139 -322
- package/v1/utils/actor.js.map +1 -1
- package/v1/utils/auth.js +44 -134
- package/v1/utils/auth.js.map +1 -1
- package/v1/utils/bls.js +41 -109
- package/v1/utils/bls.js.map +1 -1
- package/v1/utils/buffer.js +47 -111
- package/v1/utils/buffer.js.map +1 -1
- package/v1/utils/cbor.js +50 -85
- package/v1/utils/cbor.js.map +1 -1
- package/v1/utils/certificate.js +116 -238
- package/v1/utils/certificate.js.map +1 -1
- package/v1/utils/convert.d.ts +1 -1
- package/v1/utils/convert.js +29 -49
- package/v1/utils/convert.js.map +1 -1
- package/v1/utils/der.js +37 -35
- package/v1/utils/der.js.map +1 -1
- package/v1/utils/errors.js +10 -30
- package/v1/utils/errors.js.map +1 -1
- package/v1/utils/hdkey.js +33 -33
- package/v1/utils/hdkey.js.map +1 -1
- package/v1/utils/http.d.ts +1 -1
- package/v1/utils/http.js +202 -426
- package/v1/utils/http.js.map +1 -1
- package/v1/utils/icrc1.js +24 -41
- package/v1/utils/icrc1.js.map +1 -1
- package/v1/utils/idl.js +780 -1159
- package/v1/utils/idl.js.map +1 -1
- package/v1/utils/json.d.ts +1 -0
- package/v1/utils/json.js +19 -0
- package/v1/utils/json.js.map +1 -0
- package/v1/utils/leb128.js +29 -30
- package/v1/utils/leb128.js.map +1 -1
- package/v1/utils/polling.js +84 -234
- package/v1/utils/polling.js.map +1 -1
- package/v1/utils/principal.js +78 -126
- package/v1/utils/principal.js.map +1 -1
- package/v1/utils/secp256k1.js +68 -134
- package/v1/utils/secp256k1.js.map +1 -1
- package/v1/utils/transaction.js +7 -7
- package/v1/utils/transaction.js.map +1 -1
package/v1/utils/idl.js
CHANGED
|
@@ -1,62 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __values = (this && this.__values) || function(o) {
|
|
18
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
-
if (m) return m.call(o);
|
|
20
|
-
if (o && typeof o.length === "number") return {
|
|
21
|
-
next: function () {
|
|
22
|
-
if (o && i >= o.length) o = void 0;
|
|
23
|
-
return { value: o && o[i++], done: !o };
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
-
};
|
|
28
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
29
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30
|
-
if (!m) return o;
|
|
31
|
-
var i = m.call(o), r, ar = [], e;
|
|
32
|
-
try {
|
|
33
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
34
|
-
}
|
|
35
|
-
catch (error) { e = { error: error }; }
|
|
36
|
-
finally {
|
|
37
|
-
try {
|
|
38
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
39
|
-
}
|
|
40
|
-
finally { if (e) throw e.error; }
|
|
41
|
-
}
|
|
42
|
-
return ar;
|
|
43
|
-
};
|
|
44
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
45
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
46
|
-
if (ar || !(i in from)) {
|
|
47
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
48
|
-
ar[i] = from[i];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
52
|
-
};
|
|
53
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
3
|
exports.Vec = exports.Tuple = exports.Principal = exports.Nat64 = exports.Nat32 = exports.Nat16 = exports.Nat8 = exports.Int64 = exports.Int32 = exports.Int16 = exports.Int8 = exports.Float64 = exports.Float32 = exports.Nat = exports.Int = exports.Text = exports.Null = exports.Bool = exports.Unknown = exports.Reserved = exports.Empty = exports.decode = exports.encode = exports.ServiceClass = exports.FuncClass = exports.PrincipalClass = exports.RecClass = exports.VariantClass = exports.TupleClass = exports.RecordClass = exports.OptClass = exports.VecClass = exports.FixedNatClass = exports.FixedIntClass = exports.FloatClass = exports.NatClass = exports.IntClass = exports.TextClass = exports.ReservedClass = exports.NullClass = exports.BoolClass = exports.UnknownClass = exports.EmptyClass = exports.ConstructType = exports.PrimitiveType = exports.Type = exports.Visitor = exports.idlLabelToId = exports.iexp2 = exports.ilog2 = void 0;
|
|
55
4
|
exports.Service = exports.Func = exports.Rec = exports.Variant = exports.Record = exports.Opt = void 0;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
5
|
+
const buffer_1 = require("./buffer");
|
|
6
|
+
const leb128_1 = require("./leb128");
|
|
7
|
+
const buffer_2 = require("./buffer");
|
|
8
|
+
const principal_1 = require("./principal");
|
|
60
9
|
/**
|
|
61
10
|
* Equivalent to `Math.log2(n)` with support for `BigInt` values
|
|
62
11
|
*
|
|
@@ -64,7 +13,7 @@ var principal_1 = require("./principal");
|
|
|
64
13
|
* @returns integer
|
|
65
14
|
*/
|
|
66
15
|
function ilog2(n) {
|
|
67
|
-
|
|
16
|
+
const nBig = BigInt(n);
|
|
68
17
|
if (n <= 0) {
|
|
69
18
|
throw new RangeError('Input must be positive');
|
|
70
19
|
}
|
|
@@ -79,7 +28,7 @@ exports.ilog2 = ilog2;
|
|
|
79
28
|
* @returns bigint
|
|
80
29
|
*/
|
|
81
30
|
function iexp2(n) {
|
|
82
|
-
|
|
31
|
+
const nBig = BigInt(n);
|
|
83
32
|
if (n < 0) {
|
|
84
33
|
throw new RangeError('Input must be non-negative');
|
|
85
34
|
}
|
|
@@ -87,22 +36,11 @@ function iexp2(n) {
|
|
|
87
36
|
}
|
|
88
37
|
exports.iexp2 = iexp2;
|
|
89
38
|
function idlHash(s) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
for (var array_1 = __values(array), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
|
|
96
|
-
var c = array_1_1.value;
|
|
97
|
-
h = (h * 223 + c) % Math.pow(2, 32);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
101
|
-
finally {
|
|
102
|
-
try {
|
|
103
|
-
if (array_1_1 && !array_1_1.done && (_a = array_1.return)) _a.call(array_1);
|
|
104
|
-
}
|
|
105
|
-
finally { if (e_1) throw e_1.error; }
|
|
39
|
+
const utf8encoder = new TextEncoder();
|
|
40
|
+
const array = utf8encoder.encode(s);
|
|
41
|
+
let h = 0;
|
|
42
|
+
for (const c of array) {
|
|
43
|
+
h = (h * 223 + c) % 2 ** 32;
|
|
106
44
|
}
|
|
107
45
|
return h;
|
|
108
46
|
}
|
|
@@ -113,39 +51,39 @@ function idlHash(s) {
|
|
|
113
51
|
*/
|
|
114
52
|
function idlLabelToId(label) {
|
|
115
53
|
if (/^_\d+_$/.test(label) || /^_0x[0-9a-fA-F]+_$/.test(label)) {
|
|
116
|
-
|
|
117
|
-
if (Number.isSafeInteger(num) && num >= 0 && num <
|
|
54
|
+
const num = +label.slice(1, -1);
|
|
55
|
+
if (Number.isSafeInteger(num) && num >= 0 && num < 2 ** 32) {
|
|
118
56
|
return num;
|
|
119
57
|
}
|
|
120
58
|
}
|
|
121
59
|
return idlHash(label);
|
|
122
60
|
}
|
|
123
61
|
exports.idlLabelToId = idlLabelToId;
|
|
124
|
-
|
|
125
|
-
|
|
62
|
+
const magicNumber = 'DIDL';
|
|
63
|
+
const toReadableString_max = 400; // will not display arguments after 400chars. Makes sure 2mb blobs don't get inside the error
|
|
126
64
|
function zipWith(xs, ys, f) {
|
|
127
|
-
return xs.map(
|
|
65
|
+
return xs.map((x, i) => f(x, ys[i]));
|
|
128
66
|
}
|
|
129
67
|
/**
|
|
130
68
|
* An IDL Type Table, which precedes the data in the stream.
|
|
131
69
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
70
|
+
class TypeTable {
|
|
71
|
+
constructor() {
|
|
134
72
|
// List of types. Needs to be an array as the index needs to be stable.
|
|
135
73
|
this._typs = [];
|
|
136
74
|
this._idx = new Map();
|
|
137
75
|
}
|
|
138
|
-
|
|
76
|
+
has(obj) {
|
|
139
77
|
return this._idx.has(obj.name);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
78
|
+
}
|
|
79
|
+
add(type, buf) {
|
|
80
|
+
const idx = this._typs.length;
|
|
143
81
|
this._idx.set(type.name, idx);
|
|
144
82
|
this._typs.push(buf);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
83
|
+
}
|
|
84
|
+
merge(obj, knot) {
|
|
85
|
+
const idx = this._idx.get(obj.name);
|
|
86
|
+
const knotIdx = this._idx.get(knot);
|
|
149
87
|
if (idx === undefined) {
|
|
150
88
|
throw new Error('Missing type index for ' + obj);
|
|
151
89
|
}
|
|
@@ -156,194 +94,168 @@ var TypeTable = /** @class */ (function () {
|
|
|
156
94
|
// Delete the type.
|
|
157
95
|
this._typs.splice(knotIdx, 1);
|
|
158
96
|
this._idx.delete(knot);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
97
|
+
}
|
|
98
|
+
encode() {
|
|
99
|
+
const len = (0, leb128_1.lebEncode)(this._typs.length);
|
|
100
|
+
const buf = (0, buffer_1.concat)(...this._typs);
|
|
163
101
|
return (0, buffer_1.concat)(len, buf);
|
|
164
|
-
}
|
|
165
|
-
|
|
102
|
+
}
|
|
103
|
+
indexOf(typeName) {
|
|
166
104
|
if (!this._idx.has(typeName)) {
|
|
167
105
|
throw new Error('Missing type index for ' + typeName);
|
|
168
106
|
}
|
|
169
107
|
return (0, leb128_1.slebEncode)(this._idx.get(typeName) || 0);
|
|
170
|
-
};
|
|
171
|
-
return TypeTable;
|
|
172
|
-
}());
|
|
173
|
-
var Visitor = /** @class */ (function () {
|
|
174
|
-
function Visitor() {
|
|
175
108
|
}
|
|
176
|
-
|
|
109
|
+
}
|
|
110
|
+
class Visitor {
|
|
111
|
+
visitType(t, data) {
|
|
177
112
|
throw new Error('Not implemented');
|
|
178
|
-
}
|
|
179
|
-
|
|
113
|
+
}
|
|
114
|
+
visitPrimitive(t, data) {
|
|
180
115
|
return this.visitType(t, data);
|
|
181
|
-
}
|
|
182
|
-
|
|
116
|
+
}
|
|
117
|
+
visitEmpty(t, data) {
|
|
183
118
|
return this.visitPrimitive(t, data);
|
|
184
|
-
}
|
|
185
|
-
|
|
119
|
+
}
|
|
120
|
+
visitBool(t, data) {
|
|
186
121
|
return this.visitPrimitive(t, data);
|
|
187
|
-
}
|
|
188
|
-
|
|
122
|
+
}
|
|
123
|
+
visitNull(t, data) {
|
|
189
124
|
return this.visitPrimitive(t, data);
|
|
190
|
-
}
|
|
191
|
-
|
|
125
|
+
}
|
|
126
|
+
visitReserved(t, data) {
|
|
192
127
|
return this.visitPrimitive(t, data);
|
|
193
|
-
}
|
|
194
|
-
|
|
128
|
+
}
|
|
129
|
+
visitText(t, data) {
|
|
195
130
|
return this.visitPrimitive(t, data);
|
|
196
|
-
}
|
|
197
|
-
|
|
131
|
+
}
|
|
132
|
+
visitNumber(t, data) {
|
|
198
133
|
return this.visitPrimitive(t, data);
|
|
199
|
-
}
|
|
200
|
-
|
|
134
|
+
}
|
|
135
|
+
visitInt(t, data) {
|
|
201
136
|
return this.visitNumber(t, data);
|
|
202
|
-
}
|
|
203
|
-
|
|
137
|
+
}
|
|
138
|
+
visitNat(t, data) {
|
|
204
139
|
return this.visitNumber(t, data);
|
|
205
|
-
}
|
|
206
|
-
|
|
140
|
+
}
|
|
141
|
+
visitFloat(t, data) {
|
|
207
142
|
return this.visitPrimitive(t, data);
|
|
208
|
-
}
|
|
209
|
-
|
|
143
|
+
}
|
|
144
|
+
visitFixedInt(t, data) {
|
|
210
145
|
return this.visitNumber(t, data);
|
|
211
|
-
}
|
|
212
|
-
|
|
146
|
+
}
|
|
147
|
+
visitFixedNat(t, data) {
|
|
213
148
|
return this.visitNumber(t, data);
|
|
214
|
-
}
|
|
215
|
-
|
|
149
|
+
}
|
|
150
|
+
visitPrincipal(t, data) {
|
|
216
151
|
return this.visitPrimitive(t, data);
|
|
217
|
-
}
|
|
218
|
-
|
|
152
|
+
}
|
|
153
|
+
visitConstruct(t, data) {
|
|
219
154
|
return this.visitType(t, data);
|
|
220
|
-
}
|
|
221
|
-
|
|
155
|
+
}
|
|
156
|
+
visitVec(t, ty, data) {
|
|
222
157
|
return this.visitConstruct(t, data);
|
|
223
|
-
}
|
|
224
|
-
|
|
158
|
+
}
|
|
159
|
+
visitOpt(t, ty, data) {
|
|
225
160
|
return this.visitConstruct(t, data);
|
|
226
|
-
}
|
|
227
|
-
|
|
161
|
+
}
|
|
162
|
+
visitRecord(t, fields, data) {
|
|
228
163
|
return this.visitConstruct(t, data);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
164
|
+
}
|
|
165
|
+
visitTuple(t, components, data) {
|
|
166
|
+
const fields = components.map((ty, i) => [`_${i}_`, ty]);
|
|
232
167
|
return this.visitRecord(t, fields, data);
|
|
233
|
-
}
|
|
234
|
-
|
|
168
|
+
}
|
|
169
|
+
visitVariant(t, fields, data) {
|
|
235
170
|
return this.visitConstruct(t, data);
|
|
236
|
-
}
|
|
237
|
-
|
|
171
|
+
}
|
|
172
|
+
visitRec(t, ty, data) {
|
|
238
173
|
return this.visitConstruct(ty, data);
|
|
239
|
-
}
|
|
240
|
-
|
|
174
|
+
}
|
|
175
|
+
visitFunc(t, data) {
|
|
241
176
|
return this.visitConstruct(t, data);
|
|
242
|
-
}
|
|
243
|
-
|
|
177
|
+
}
|
|
178
|
+
visitService(t, data) {
|
|
244
179
|
return this.visitConstruct(t, data);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
}());
|
|
180
|
+
}
|
|
181
|
+
}
|
|
248
182
|
exports.Visitor = Visitor;
|
|
249
183
|
/**
|
|
250
184
|
* Represents an IDL type.
|
|
251
185
|
*/
|
|
252
|
-
|
|
253
|
-
function Type() {
|
|
254
|
-
}
|
|
186
|
+
class Type {
|
|
255
187
|
/* Display type name */
|
|
256
|
-
|
|
188
|
+
display() {
|
|
257
189
|
return this.name;
|
|
258
|
-
}
|
|
259
|
-
|
|
190
|
+
}
|
|
191
|
+
valueToString(x) {
|
|
260
192
|
return toReadableString(x);
|
|
261
|
-
}
|
|
193
|
+
}
|
|
262
194
|
/* Implement `T` in the IDL spec, only needed for non-primitive types */
|
|
263
|
-
|
|
195
|
+
buildTypeTable(typeTable) {
|
|
264
196
|
if (!typeTable.has(this)) {
|
|
265
197
|
this._buildTypeTableImpl(typeTable);
|
|
266
198
|
}
|
|
267
|
-
};
|
|
268
|
-
return Type;
|
|
269
|
-
}());
|
|
270
|
-
exports.Type = Type;
|
|
271
|
-
var PrimitiveType = /** @class */ (function (_super) {
|
|
272
|
-
__extends(PrimitiveType, _super);
|
|
273
|
-
function PrimitiveType() {
|
|
274
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
275
199
|
}
|
|
276
|
-
|
|
200
|
+
}
|
|
201
|
+
exports.Type = Type;
|
|
202
|
+
class PrimitiveType extends Type {
|
|
203
|
+
checkType(t) {
|
|
277
204
|
if (this.name !== t.name) {
|
|
278
|
-
throw new Error(
|
|
205
|
+
throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`);
|
|
279
206
|
}
|
|
280
207
|
return t;
|
|
281
|
-
}
|
|
282
|
-
|
|
208
|
+
}
|
|
209
|
+
_buildTypeTableImpl(typeTable) {
|
|
283
210
|
// No type table encoding for Primitive types.
|
|
284
211
|
return;
|
|
285
|
-
};
|
|
286
|
-
return PrimitiveType;
|
|
287
|
-
}(Type));
|
|
288
|
-
exports.PrimitiveType = PrimitiveType;
|
|
289
|
-
var ConstructType = /** @class */ (function (_super) {
|
|
290
|
-
__extends(ConstructType, _super);
|
|
291
|
-
function ConstructType() {
|
|
292
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
293
212
|
}
|
|
294
|
-
|
|
213
|
+
}
|
|
214
|
+
exports.PrimitiveType = PrimitiveType;
|
|
215
|
+
class ConstructType extends Type {
|
|
216
|
+
checkType(t) {
|
|
295
217
|
if (t instanceof RecClass) {
|
|
296
|
-
|
|
218
|
+
const ty = t.getType();
|
|
297
219
|
if (typeof ty === 'undefined') {
|
|
298
220
|
throw new Error('type mismatch with uninitialized type');
|
|
299
221
|
}
|
|
300
222
|
return ty;
|
|
301
223
|
}
|
|
302
|
-
throw new Error(
|
|
303
|
-
}
|
|
304
|
-
|
|
224
|
+
throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`);
|
|
225
|
+
}
|
|
226
|
+
encodeType(typeTable) {
|
|
305
227
|
return typeTable.indexOf(this.name);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
}(Type));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
309
230
|
exports.ConstructType = ConstructType;
|
|
310
231
|
/**
|
|
311
232
|
* Represents an IDL Empty, a type which has no inhabitants.
|
|
312
233
|
* Since no values exist for this type, it cannot be serialised or deserialised.
|
|
313
234
|
* Result types like `Result<Text, Empty>` should always succeed.
|
|
314
235
|
*/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
function EmptyClass() {
|
|
318
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
319
|
-
}
|
|
320
|
-
EmptyClass.prototype.accept = function (v, d) {
|
|
236
|
+
class EmptyClass extends PrimitiveType {
|
|
237
|
+
accept(v, d) {
|
|
321
238
|
return v.visitEmpty(this, d);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
throw new Error(
|
|
325
|
-
}
|
|
326
|
-
|
|
239
|
+
}
|
|
240
|
+
covariant(x) {
|
|
241
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
242
|
+
}
|
|
243
|
+
encodeValue() {
|
|
327
244
|
throw new Error('Empty cannot appear as a function argument');
|
|
328
|
-
}
|
|
329
|
-
|
|
245
|
+
}
|
|
246
|
+
valueToString() {
|
|
330
247
|
throw new Error('Empty cannot appear as a value');
|
|
331
|
-
}
|
|
332
|
-
|
|
248
|
+
}
|
|
249
|
+
encodeType() {
|
|
333
250
|
return (0, leb128_1.slebEncode)(-17 /* IDLTypeIds.Empty */);
|
|
334
|
-
}
|
|
335
|
-
|
|
251
|
+
}
|
|
252
|
+
decodeValue() {
|
|
336
253
|
throw new Error('Empty cannot appear as an output');
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
enumerable: false,
|
|
343
|
-
configurable: true
|
|
344
|
-
});
|
|
345
|
-
return EmptyClass;
|
|
346
|
-
}(PrimitiveType));
|
|
254
|
+
}
|
|
255
|
+
get name() {
|
|
256
|
+
return 'empty';
|
|
257
|
+
}
|
|
258
|
+
}
|
|
347
259
|
exports.EmptyClass = EmptyClass;
|
|
348
260
|
/**
|
|
349
261
|
* Represents an IDL Unknown, a placeholder type for deserialization only.
|
|
@@ -352,43 +264,39 @@ exports.EmptyClass = EmptyClass;
|
|
|
352
264
|
* A deserialized unknown will offer it's actual type by calling the `type()` function.
|
|
353
265
|
* Unknown cannot be serialized and attempting to do so will throw an error.
|
|
354
266
|
*/
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
function UnknownClass() {
|
|
358
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
359
|
-
}
|
|
360
|
-
UnknownClass.prototype.checkType = function (t) {
|
|
267
|
+
class UnknownClass extends Type {
|
|
268
|
+
checkType(t) {
|
|
361
269
|
throw new Error('Method not implemented for unknown.');
|
|
362
|
-
}
|
|
363
|
-
|
|
270
|
+
}
|
|
271
|
+
accept(v, d) {
|
|
364
272
|
throw v.visitType(this, d);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
throw new Error(
|
|
368
|
-
}
|
|
369
|
-
|
|
273
|
+
}
|
|
274
|
+
covariant(x) {
|
|
275
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
276
|
+
}
|
|
277
|
+
encodeValue() {
|
|
370
278
|
throw new Error('Unknown cannot appear as a function argument');
|
|
371
|
-
}
|
|
372
|
-
|
|
279
|
+
}
|
|
280
|
+
valueToString() {
|
|
373
281
|
throw new Error('Unknown cannot appear as a value');
|
|
374
|
-
}
|
|
375
|
-
|
|
282
|
+
}
|
|
283
|
+
encodeType() {
|
|
376
284
|
throw new Error('Unknown cannot be serialized');
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
|
|
285
|
+
}
|
|
286
|
+
decodeValue(b, t) {
|
|
287
|
+
let decodedValue = t.decodeValue(b, t);
|
|
380
288
|
if (Object(decodedValue) !== decodedValue) {
|
|
381
289
|
// decodedValue is primitive. Box it, otherwise we cannot add the type() function.
|
|
382
290
|
// The type() function is important for primitives because otherwise we cannot tell apart the
|
|
383
291
|
// different number types.
|
|
384
292
|
decodedValue = Object(decodedValue);
|
|
385
293
|
}
|
|
386
|
-
|
|
294
|
+
let typeFunc;
|
|
387
295
|
if (t instanceof RecClass) {
|
|
388
|
-
typeFunc =
|
|
296
|
+
typeFunc = () => t.getType();
|
|
389
297
|
}
|
|
390
298
|
else {
|
|
391
|
-
typeFunc =
|
|
299
|
+
typeFunc = () => t;
|
|
392
300
|
}
|
|
393
301
|
// Do not use 'decodedValue.type = typeFunc' because this would lead to an enumerable property
|
|
394
302
|
// 'type' which means it would be serialized if the value would be candid encoded again.
|
|
@@ -401,43 +309,34 @@ var UnknownClass = /** @class */ (function (_super) {
|
|
|
401
309
|
configurable: true
|
|
402
310
|
});
|
|
403
311
|
return decodedValue;
|
|
404
|
-
}
|
|
405
|
-
|
|
312
|
+
}
|
|
313
|
+
_buildTypeTableImpl() {
|
|
406
314
|
throw new Error('Unknown cannot be serialized');
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
enumerable: false,
|
|
413
|
-
configurable: true
|
|
414
|
-
});
|
|
415
|
-
return UnknownClass;
|
|
416
|
-
}(Type));
|
|
315
|
+
}
|
|
316
|
+
get name() {
|
|
317
|
+
return 'Unknown';
|
|
318
|
+
}
|
|
319
|
+
}
|
|
417
320
|
exports.UnknownClass = UnknownClass;
|
|
418
321
|
/**
|
|
419
322
|
* Represents an IDL Bool
|
|
420
323
|
*/
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
function BoolClass() {
|
|
424
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
425
|
-
}
|
|
426
|
-
BoolClass.prototype.accept = function (v, d) {
|
|
324
|
+
class BoolClass extends PrimitiveType {
|
|
325
|
+
accept(v, d) {
|
|
427
326
|
return v.visitBool(this, d);
|
|
428
|
-
}
|
|
429
|
-
|
|
327
|
+
}
|
|
328
|
+
covariant(x) {
|
|
430
329
|
if (typeof x === 'boolean')
|
|
431
330
|
return true;
|
|
432
|
-
throw new Error(
|
|
433
|
-
}
|
|
434
|
-
|
|
331
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
332
|
+
}
|
|
333
|
+
encodeValue(x) {
|
|
435
334
|
return new Uint8Array([x ? 1 : 0]);
|
|
436
|
-
}
|
|
437
|
-
|
|
335
|
+
}
|
|
336
|
+
encodeType() {
|
|
438
337
|
return (0, leb128_1.slebEncode)(-2 /* IDLTypeIds.Bool */);
|
|
439
|
-
}
|
|
440
|
-
|
|
338
|
+
}
|
|
339
|
+
decodeValue(b, t) {
|
|
441
340
|
this.checkType(t);
|
|
442
341
|
switch ((0, leb128_1.safeReadUint8)(b)) {
|
|
443
342
|
case 0:
|
|
@@ -447,239 +346,187 @@ var BoolClass = /** @class */ (function (_super) {
|
|
|
447
346
|
default:
|
|
448
347
|
throw new Error('Boolean value out of range');
|
|
449
348
|
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
enumerable: false,
|
|
456
|
-
configurable: true
|
|
457
|
-
});
|
|
458
|
-
return BoolClass;
|
|
459
|
-
}(PrimitiveType));
|
|
349
|
+
}
|
|
350
|
+
get name() {
|
|
351
|
+
return 'bool';
|
|
352
|
+
}
|
|
353
|
+
}
|
|
460
354
|
exports.BoolClass = BoolClass;
|
|
461
355
|
/**
|
|
462
356
|
* Represents an IDL Null
|
|
463
357
|
*/
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
function NullClass() {
|
|
467
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
468
|
-
}
|
|
469
|
-
NullClass.prototype.accept = function (v, d) {
|
|
358
|
+
class NullClass extends PrimitiveType {
|
|
359
|
+
accept(v, d) {
|
|
470
360
|
return v.visitNull(this, d);
|
|
471
|
-
}
|
|
472
|
-
|
|
361
|
+
}
|
|
362
|
+
covariant(x) {
|
|
473
363
|
if (x === null)
|
|
474
364
|
return true;
|
|
475
|
-
throw new Error(
|
|
476
|
-
}
|
|
477
|
-
|
|
365
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
366
|
+
}
|
|
367
|
+
encodeValue() {
|
|
478
368
|
return new ArrayBuffer(0);
|
|
479
|
-
}
|
|
480
|
-
|
|
369
|
+
}
|
|
370
|
+
encodeType() {
|
|
481
371
|
return (0, leb128_1.slebEncode)(-1 /* IDLTypeIds.Null */);
|
|
482
|
-
}
|
|
483
|
-
|
|
372
|
+
}
|
|
373
|
+
decodeValue(b, t) {
|
|
484
374
|
this.checkType(t);
|
|
485
375
|
return null;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
enumerable: false,
|
|
492
|
-
configurable: true
|
|
493
|
-
});
|
|
494
|
-
return NullClass;
|
|
495
|
-
}(PrimitiveType));
|
|
376
|
+
}
|
|
377
|
+
get name() {
|
|
378
|
+
return 'null';
|
|
379
|
+
}
|
|
380
|
+
}
|
|
496
381
|
exports.NullClass = NullClass;
|
|
497
382
|
/**
|
|
498
383
|
* Represents an IDL Reserved
|
|
499
384
|
*/
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
function ReservedClass() {
|
|
503
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
504
|
-
}
|
|
505
|
-
ReservedClass.prototype.accept = function (v, d) {
|
|
385
|
+
class ReservedClass extends PrimitiveType {
|
|
386
|
+
accept(v, d) {
|
|
506
387
|
return v.visitReserved(this, d);
|
|
507
|
-
}
|
|
508
|
-
|
|
388
|
+
}
|
|
389
|
+
covariant(x) {
|
|
509
390
|
return true;
|
|
510
|
-
}
|
|
511
|
-
|
|
391
|
+
}
|
|
392
|
+
encodeValue() {
|
|
512
393
|
return new ArrayBuffer(0);
|
|
513
|
-
}
|
|
514
|
-
|
|
394
|
+
}
|
|
395
|
+
encodeType() {
|
|
515
396
|
return (0, leb128_1.slebEncode)(-16 /* IDLTypeIds.Reserved */);
|
|
516
|
-
}
|
|
517
|
-
|
|
397
|
+
}
|
|
398
|
+
decodeValue(b, t) {
|
|
518
399
|
if (t.name !== this.name) {
|
|
519
400
|
t.decodeValue(b, t);
|
|
520
401
|
}
|
|
521
402
|
return null;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
enumerable: false,
|
|
528
|
-
configurable: true
|
|
529
|
-
});
|
|
530
|
-
return ReservedClass;
|
|
531
|
-
}(PrimitiveType));
|
|
403
|
+
}
|
|
404
|
+
get name() {
|
|
405
|
+
return 'reserved';
|
|
406
|
+
}
|
|
407
|
+
}
|
|
532
408
|
exports.ReservedClass = ReservedClass;
|
|
533
409
|
/**
|
|
534
410
|
* Represents an IDL Text
|
|
535
411
|
*/
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
function TextClass() {
|
|
539
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
540
|
-
}
|
|
541
|
-
TextClass.prototype.accept = function (v, d) {
|
|
412
|
+
class TextClass extends PrimitiveType {
|
|
413
|
+
accept(v, d) {
|
|
542
414
|
return v.visitText(this, d);
|
|
543
|
-
}
|
|
544
|
-
|
|
415
|
+
}
|
|
416
|
+
covariant(x) {
|
|
545
417
|
if (typeof x === 'string')
|
|
546
418
|
return true;
|
|
547
|
-
throw new Error(
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
419
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
420
|
+
}
|
|
421
|
+
encodeValue(x) {
|
|
422
|
+
const buf = new TextEncoder().encode(x);
|
|
423
|
+
const len = (0, leb128_1.lebEncode)(buf.byteLength);
|
|
552
424
|
return (0, buffer_1.concat)(len, buf);
|
|
553
|
-
}
|
|
554
|
-
|
|
425
|
+
}
|
|
426
|
+
encodeType() {
|
|
555
427
|
return (0, leb128_1.slebEncode)(-15 /* IDLTypeIds.Text */);
|
|
556
|
-
}
|
|
557
|
-
|
|
428
|
+
}
|
|
429
|
+
decodeValue(b, t) {
|
|
558
430
|
this.checkType(t);
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
431
|
+
const len = (0, leb128_1.lebDecode)(b);
|
|
432
|
+
const buf = (0, leb128_1.safeRead)(b, Number(len));
|
|
433
|
+
const decoder = new TextDecoder('utf8', { fatal: true });
|
|
562
434
|
return decoder.decode(buf);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
enumerable: false,
|
|
569
|
-
configurable: true
|
|
570
|
-
});
|
|
571
|
-
TextClass.prototype.valueToString = function (x) {
|
|
435
|
+
}
|
|
436
|
+
get name() {
|
|
437
|
+
return 'text';
|
|
438
|
+
}
|
|
439
|
+
valueToString(x) {
|
|
572
440
|
return '"' + x + '"';
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
}(PrimitiveType));
|
|
441
|
+
}
|
|
442
|
+
}
|
|
576
443
|
exports.TextClass = TextClass;
|
|
577
444
|
/**
|
|
578
445
|
* Represents an IDL Int
|
|
579
446
|
*/
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
function IntClass() {
|
|
583
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
584
|
-
}
|
|
585
|
-
IntClass.prototype.accept = function (v, d) {
|
|
447
|
+
class IntClass extends PrimitiveType {
|
|
448
|
+
accept(v, d) {
|
|
586
449
|
return v.visitInt(this, d);
|
|
587
|
-
}
|
|
588
|
-
|
|
450
|
+
}
|
|
451
|
+
covariant(x) {
|
|
589
452
|
// We allow encoding of JavaScript plain numbers.
|
|
590
453
|
// But we will always decode to bigint.
|
|
591
454
|
if (typeof x === 'bigint' || Number.isInteger(x))
|
|
592
455
|
return true;
|
|
593
|
-
throw new Error(
|
|
594
|
-
}
|
|
595
|
-
|
|
456
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
457
|
+
}
|
|
458
|
+
encodeValue(x) {
|
|
596
459
|
return (0, leb128_1.slebEncode)(x);
|
|
597
|
-
}
|
|
598
|
-
|
|
460
|
+
}
|
|
461
|
+
encodeType() {
|
|
599
462
|
return (0, leb128_1.slebEncode)(-4 /* IDLTypeIds.Int */);
|
|
600
|
-
}
|
|
601
|
-
|
|
463
|
+
}
|
|
464
|
+
decodeValue(b, t) {
|
|
602
465
|
this.checkType(t);
|
|
603
466
|
return (0, leb128_1.slebDecode)(b);
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
enumerable: false,
|
|
610
|
-
configurable: true
|
|
611
|
-
});
|
|
612
|
-
IntClass.prototype.valueToString = function (x) {
|
|
467
|
+
}
|
|
468
|
+
get name() {
|
|
469
|
+
return 'int';
|
|
470
|
+
}
|
|
471
|
+
valueToString(x) {
|
|
613
472
|
return x.toString();
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
}(PrimitiveType));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
617
475
|
exports.IntClass = IntClass;
|
|
618
476
|
/**
|
|
619
477
|
* Represents an IDL Nat
|
|
620
478
|
*/
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
function NatClass() {
|
|
624
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
625
|
-
}
|
|
626
|
-
NatClass.prototype.accept = function (v, d) {
|
|
479
|
+
class NatClass extends PrimitiveType {
|
|
480
|
+
accept(v, d) {
|
|
627
481
|
return v.visitNat(this, d);
|
|
628
|
-
}
|
|
629
|
-
|
|
482
|
+
}
|
|
483
|
+
covariant(x) {
|
|
630
484
|
// We allow encoding of JavaScript plain numbers.
|
|
631
485
|
// But we will always decode to bigint.
|
|
632
486
|
if ((typeof x === 'bigint' && x >= BigInt(0)) || (Number.isInteger(x) && x >= 0))
|
|
633
487
|
return true;
|
|
634
|
-
throw new Error(
|
|
635
|
-
}
|
|
636
|
-
|
|
488
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
489
|
+
}
|
|
490
|
+
encodeValue(x) {
|
|
637
491
|
return (0, leb128_1.lebEncode)(x);
|
|
638
|
-
}
|
|
639
|
-
|
|
492
|
+
}
|
|
493
|
+
encodeType() {
|
|
640
494
|
return (0, leb128_1.slebEncode)(-3 /* IDLTypeIds.Nat */);
|
|
641
|
-
}
|
|
642
|
-
|
|
495
|
+
}
|
|
496
|
+
decodeValue(b, t) {
|
|
643
497
|
this.checkType(t);
|
|
644
498
|
return (0, leb128_1.lebDecode)(b);
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
enumerable: false,
|
|
651
|
-
configurable: true
|
|
652
|
-
});
|
|
653
|
-
NatClass.prototype.valueToString = function (x) {
|
|
499
|
+
}
|
|
500
|
+
get name() {
|
|
501
|
+
return 'nat';
|
|
502
|
+
}
|
|
503
|
+
valueToString(x) {
|
|
654
504
|
return x.toString();
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
}(PrimitiveType));
|
|
505
|
+
}
|
|
506
|
+
}
|
|
658
507
|
exports.NatClass = NatClass;
|
|
659
508
|
/**
|
|
660
509
|
* Represents an IDL Float
|
|
661
510
|
*/
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
_this._bits = _bits;
|
|
511
|
+
class FloatClass extends PrimitiveType {
|
|
512
|
+
constructor(_bits) {
|
|
513
|
+
super();
|
|
514
|
+
this._bits = _bits;
|
|
667
515
|
if (_bits !== 32 && _bits !== 64) {
|
|
668
516
|
throw new Error('not a valid float type');
|
|
669
517
|
}
|
|
670
|
-
return _this;
|
|
671
518
|
}
|
|
672
|
-
|
|
519
|
+
accept(v, d) {
|
|
673
520
|
return v.visitFloat(this, d);
|
|
674
|
-
}
|
|
675
|
-
|
|
521
|
+
}
|
|
522
|
+
covariant(x) {
|
|
676
523
|
if (typeof x === 'number' || x instanceof Number)
|
|
677
524
|
return true;
|
|
678
|
-
throw new Error(
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
525
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
526
|
+
}
|
|
527
|
+
encodeValue(x) {
|
|
528
|
+
const buf = new ArrayBuffer(this._bits / 8);
|
|
529
|
+
const view = new DataView(buf);
|
|
683
530
|
if (this._bits === 32) {
|
|
684
531
|
view.setFloat32(0, x, true);
|
|
685
532
|
}
|
|
@@ -687,57 +534,50 @@ var FloatClass = /** @class */ (function (_super) {
|
|
|
687
534
|
view.setFloat64(0, x, true);
|
|
688
535
|
}
|
|
689
536
|
return buf;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
|
|
537
|
+
}
|
|
538
|
+
encodeType() {
|
|
539
|
+
const opcode = this._bits === 32 ? -13 /* IDLTypeIds.Float32 */ : -14 /* IDLTypeIds.Float64 */;
|
|
693
540
|
return (0, leb128_1.slebEncode)(opcode);
|
|
694
|
-
}
|
|
695
|
-
|
|
541
|
+
}
|
|
542
|
+
decodeValue(b, t) {
|
|
696
543
|
this.checkType(t);
|
|
697
|
-
|
|
698
|
-
|
|
544
|
+
const bytes = (0, leb128_1.safeRead)(b, this._bits / 8);
|
|
545
|
+
const view = new DataView(bytes);
|
|
699
546
|
if (this._bits === 32) {
|
|
700
547
|
return view.getFloat32(0, true);
|
|
701
548
|
}
|
|
702
549
|
else {
|
|
703
550
|
return view.getFloat64(0, true);
|
|
704
551
|
}
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
enumerable: false,
|
|
711
|
-
configurable: true
|
|
712
|
-
});
|
|
713
|
-
FloatClass.prototype.valueToString = function (x) {
|
|
552
|
+
}
|
|
553
|
+
get name() {
|
|
554
|
+
return 'float' + this._bits;
|
|
555
|
+
}
|
|
556
|
+
valueToString(x) {
|
|
714
557
|
return x.toString();
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
}(PrimitiveType));
|
|
558
|
+
}
|
|
559
|
+
}
|
|
718
560
|
exports.FloatClass = FloatClass;
|
|
719
561
|
/**
|
|
720
562
|
* Represents an IDL fixed-width Int(n)
|
|
721
563
|
*/
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
}
|
|
729
|
-
FixedIntClass.prototype.accept = function (v, d) {
|
|
564
|
+
class FixedIntClass extends PrimitiveType {
|
|
565
|
+
constructor(_bits) {
|
|
566
|
+
super();
|
|
567
|
+
this._bits = _bits;
|
|
568
|
+
}
|
|
569
|
+
accept(v, d) {
|
|
730
570
|
return v.visitFixedInt(this, d);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
571
|
+
}
|
|
572
|
+
covariant(x) {
|
|
573
|
+
const min = iexp2(this._bits - 1) * BigInt(-1);
|
|
574
|
+
const max = iexp2(this._bits - 1) - BigInt(1);
|
|
575
|
+
let ok = false;
|
|
736
576
|
if (typeof x === 'bigint') {
|
|
737
577
|
ok = x >= min && x <= max;
|
|
738
578
|
}
|
|
739
579
|
else if (Number.isInteger(x)) {
|
|
740
|
-
|
|
580
|
+
const v = BigInt(x);
|
|
741
581
|
ok = v >= min && v <= max;
|
|
742
582
|
}
|
|
743
583
|
else {
|
|
@@ -745,59 +585,52 @@ var FixedIntClass = /** @class */ (function (_super) {
|
|
|
745
585
|
}
|
|
746
586
|
if (ok)
|
|
747
587
|
return true;
|
|
748
|
-
throw new Error(
|
|
749
|
-
}
|
|
750
|
-
|
|
588
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
589
|
+
}
|
|
590
|
+
encodeValue(x) {
|
|
751
591
|
return (0, leb128_1.writeIntLE)(x, this._bits / 8);
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
|
|
592
|
+
}
|
|
593
|
+
encodeType() {
|
|
594
|
+
const offset = Math.log2(this._bits) - 3;
|
|
755
595
|
return (0, leb128_1.slebEncode)(-9 - offset);
|
|
756
|
-
}
|
|
757
|
-
|
|
596
|
+
}
|
|
597
|
+
decodeValue(b, t) {
|
|
758
598
|
this.checkType(t);
|
|
759
|
-
|
|
599
|
+
const num = (0, leb128_1.readIntLE)(b, this._bits / 8);
|
|
760
600
|
if (this._bits <= 32) {
|
|
761
601
|
return Number(num);
|
|
762
602
|
}
|
|
763
603
|
else {
|
|
764
604
|
return num;
|
|
765
605
|
}
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
enumerable: false,
|
|
772
|
-
configurable: true
|
|
773
|
-
});
|
|
774
|
-
FixedIntClass.prototype.valueToString = function (x) {
|
|
606
|
+
}
|
|
607
|
+
get name() {
|
|
608
|
+
return `int${this._bits}`;
|
|
609
|
+
}
|
|
610
|
+
valueToString(x) {
|
|
775
611
|
return x.toString();
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
}(PrimitiveType));
|
|
612
|
+
}
|
|
613
|
+
}
|
|
779
614
|
exports.FixedIntClass = FixedIntClass;
|
|
780
615
|
/**
|
|
781
616
|
* Represents an IDL fixed-width Nat(n)
|
|
782
617
|
*/
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
790
|
-
FixedNatClass.prototype.accept = function (v, d) {
|
|
618
|
+
class FixedNatClass extends PrimitiveType {
|
|
619
|
+
constructor(_bits) {
|
|
620
|
+
super();
|
|
621
|
+
this._bits = _bits;
|
|
622
|
+
}
|
|
623
|
+
accept(v, d) {
|
|
791
624
|
return v.visitFixedNat(this, d);
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
625
|
+
}
|
|
626
|
+
covariant(x) {
|
|
627
|
+
const max = iexp2(this._bits);
|
|
628
|
+
let ok = false;
|
|
796
629
|
if (typeof x === 'bigint' && x >= BigInt(0)) {
|
|
797
630
|
ok = x < max;
|
|
798
631
|
}
|
|
799
632
|
else if (Number.isInteger(x) && x >= 0) {
|
|
800
|
-
|
|
633
|
+
const v = BigInt(x);
|
|
801
634
|
ok = v < max;
|
|
802
635
|
}
|
|
803
636
|
else {
|
|
@@ -805,37 +638,32 @@ var FixedNatClass = /** @class */ (function (_super) {
|
|
|
805
638
|
}
|
|
806
639
|
if (ok)
|
|
807
640
|
return true;
|
|
808
|
-
throw new Error(
|
|
809
|
-
}
|
|
810
|
-
|
|
641
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
642
|
+
}
|
|
643
|
+
encodeValue(x) {
|
|
811
644
|
return (0, leb128_1.writeUIntLE)(x, this._bits / 8);
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
|
|
645
|
+
}
|
|
646
|
+
encodeType() {
|
|
647
|
+
const offset = Math.log2(this._bits) - 3;
|
|
815
648
|
return (0, leb128_1.slebEncode)(-5 - offset);
|
|
816
|
-
}
|
|
817
|
-
|
|
649
|
+
}
|
|
650
|
+
decodeValue(b, t) {
|
|
818
651
|
this.checkType(t);
|
|
819
|
-
|
|
652
|
+
const num = (0, leb128_1.readUIntLE)(b, this._bits / 8);
|
|
820
653
|
if (this._bits <= 32) {
|
|
821
654
|
return Number(num);
|
|
822
655
|
}
|
|
823
656
|
else {
|
|
824
657
|
return num;
|
|
825
658
|
}
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
enumerable: false,
|
|
832
|
-
configurable: true
|
|
833
|
-
});
|
|
834
|
-
FixedNatClass.prototype.valueToString = function (x) {
|
|
659
|
+
}
|
|
660
|
+
get name() {
|
|
661
|
+
return `nat${this._bits}`;
|
|
662
|
+
}
|
|
663
|
+
valueToString(x) {
|
|
835
664
|
return x.toString();
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
}(PrimitiveType));
|
|
665
|
+
}
|
|
666
|
+
}
|
|
839
667
|
exports.FixedNatClass = FixedNatClass;
|
|
840
668
|
/**
|
|
841
669
|
* Represents an IDL Array
|
|
@@ -845,82 +673,68 @@ exports.FixedNatClass = FixedNatClass;
|
|
|
845
673
|
*
|
|
846
674
|
* @param {Type} t
|
|
847
675
|
*/
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
_this._type = _type;
|
|
676
|
+
class VecClass extends ConstructType {
|
|
677
|
+
constructor(_type) {
|
|
678
|
+
super();
|
|
679
|
+
this._type = _type;
|
|
853
680
|
// If true, this vector is really a blob and we can just use memcpy.
|
|
854
681
|
//
|
|
855
682
|
// NOTE:
|
|
856
683
|
// With support of encoding/dencoding of TypedArrays, this optimization is
|
|
857
684
|
// only used when plain array of bytes are passed as encoding input in order
|
|
858
685
|
// to be backward compatible.
|
|
859
|
-
|
|
686
|
+
this._blobOptimization = false;
|
|
860
687
|
if (_type instanceof FixedNatClass && _type._bits === 8) {
|
|
861
|
-
|
|
688
|
+
this._blobOptimization = true;
|
|
862
689
|
}
|
|
863
|
-
return _this;
|
|
864
690
|
}
|
|
865
|
-
|
|
691
|
+
accept(v, d) {
|
|
866
692
|
return v.visitVec(this, this._type, d);
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
var _this = this;
|
|
693
|
+
}
|
|
694
|
+
covariant(x) {
|
|
870
695
|
// Special case for ArrayBuffer
|
|
871
|
-
|
|
696
|
+
const bits = this._type instanceof FixedNatClass ? this._type._bits : this._type instanceof FixedIntClass ? this._type._bits : 0;
|
|
872
697
|
if ((ArrayBuffer.isView(x) && bits == x.BYTES_PER_ELEMENT * 8) ||
|
|
873
698
|
(Array.isArray(x) &&
|
|
874
|
-
x.every(
|
|
699
|
+
x.every((v, idx) => {
|
|
875
700
|
try {
|
|
876
|
-
return
|
|
701
|
+
return this._type.covariant(v);
|
|
877
702
|
}
|
|
878
703
|
catch (e) {
|
|
879
|
-
throw new Error(
|
|
704
|
+
throw new Error(`Invalid ${this.display()} argument: \n\nindex ${idx} -> ${e.message}`);
|
|
880
705
|
}
|
|
881
706
|
})))
|
|
882
707
|
return true;
|
|
883
|
-
throw new Error(
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
var len = (0, leb128_1.lebEncode)(x.length);
|
|
708
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
709
|
+
}
|
|
710
|
+
encodeValue(x) {
|
|
711
|
+
const len = (0, leb128_1.lebEncode)(x.length);
|
|
888
712
|
if (this._blobOptimization) {
|
|
889
713
|
return (0, buffer_1.concat)(len, new Uint8Array(x));
|
|
890
714
|
}
|
|
891
715
|
if (ArrayBuffer.isView(x)) {
|
|
892
716
|
return (0, buffer_1.concat)(len, new Uint8Array(x.buffer));
|
|
893
717
|
}
|
|
894
|
-
|
|
718
|
+
const buf = new buffer_2.PipeArrayBuffer(new ArrayBuffer(len.byteLength + x.length), 0);
|
|
895
719
|
buf.write(len);
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
var encoded = this._type.encodeValue(d);
|
|
900
|
-
buf.write(new Uint8Array(encoded));
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
904
|
-
finally {
|
|
905
|
-
try {
|
|
906
|
-
if (x_1_1 && !x_1_1.done && (_a = x_1.return)) _a.call(x_1);
|
|
907
|
-
}
|
|
908
|
-
finally { if (e_2) throw e_2.error; }
|
|
720
|
+
for (const d of x) {
|
|
721
|
+
const encoded = this._type.encodeValue(d);
|
|
722
|
+
buf.write(new Uint8Array(encoded));
|
|
909
723
|
}
|
|
910
724
|
return buf.buffer;
|
|
911
|
-
}
|
|
912
|
-
|
|
725
|
+
}
|
|
726
|
+
_buildTypeTableImpl(typeTable) {
|
|
913
727
|
this._type.buildTypeTable(typeTable);
|
|
914
|
-
|
|
915
|
-
|
|
728
|
+
const opCode = (0, leb128_1.slebEncode)(-19 /* IDLTypeIds.Vector */);
|
|
729
|
+
const buffer = this._type.encodeType(typeTable);
|
|
916
730
|
typeTable.add(this, (0, buffer_1.concat)(opCode, buffer));
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
|
|
731
|
+
}
|
|
732
|
+
decodeValue(b, t) {
|
|
733
|
+
const vec = this.checkType(t);
|
|
920
734
|
if (!(vec instanceof VecClass)) {
|
|
921
735
|
throw new Error('Not a vector type');
|
|
922
736
|
}
|
|
923
|
-
|
|
737
|
+
const len = Number((0, leb128_1.lebDecode)(b));
|
|
924
738
|
if (this._type instanceof FixedNatClass) {
|
|
925
739
|
if (this._type._bits == 8) {
|
|
926
740
|
return new Uint8Array(b.read(len));
|
|
@@ -949,70 +763,62 @@ var VecClass = /** @class */ (function (_super) {
|
|
|
949
763
|
return new BigInt64Array(b.read(len * 8));
|
|
950
764
|
}
|
|
951
765
|
}
|
|
952
|
-
|
|
953
|
-
for (
|
|
766
|
+
const rets = [];
|
|
767
|
+
for (let i = 0; i < len; i++) {
|
|
954
768
|
rets.push(this._type.decodeValue(b, vec._type));
|
|
955
769
|
}
|
|
956
770
|
return rets;
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
return "vec ".concat(this._type.display());
|
|
967
|
-
};
|
|
968
|
-
VecClass.prototype.valueToString = function (x) {
|
|
969
|
-
var _this = this;
|
|
970
|
-
var elements = x.map(function (e) { return _this._type.valueToString(e); });
|
|
771
|
+
}
|
|
772
|
+
get name() {
|
|
773
|
+
return `vec ${this._type.name}`;
|
|
774
|
+
}
|
|
775
|
+
display() {
|
|
776
|
+
return `vec ${this._type.display()}`;
|
|
777
|
+
}
|
|
778
|
+
valueToString(x) {
|
|
779
|
+
const elements = x.map((e) => this._type.valueToString(e));
|
|
971
780
|
return 'vec {' + elements.join('; ') + '}';
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
}(ConstructType));
|
|
781
|
+
}
|
|
782
|
+
}
|
|
975
783
|
exports.VecClass = VecClass;
|
|
976
784
|
/**
|
|
977
785
|
* Represents an IDL Option
|
|
978
786
|
* @param {Type} t
|
|
979
787
|
*/
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
}
|
|
987
|
-
OptClass.prototype.accept = function (v, d) {
|
|
788
|
+
class OptClass extends ConstructType {
|
|
789
|
+
constructor(_type) {
|
|
790
|
+
super();
|
|
791
|
+
this._type = _type;
|
|
792
|
+
}
|
|
793
|
+
accept(v, d) {
|
|
988
794
|
return v.visitOpt(this, this._type, d);
|
|
989
|
-
}
|
|
990
|
-
|
|
795
|
+
}
|
|
796
|
+
covariant(x) {
|
|
991
797
|
try {
|
|
992
798
|
if (Array.isArray(x) && (x.length === 0 || (x.length === 1 && this._type.covariant(x[0]))))
|
|
993
799
|
return true;
|
|
994
800
|
}
|
|
995
801
|
catch (e) {
|
|
996
|
-
throw new Error(
|
|
802
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)} \n\n-> ${e.message}`);
|
|
997
803
|
}
|
|
998
|
-
throw new Error(
|
|
999
|
-
}
|
|
1000
|
-
|
|
804
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
805
|
+
}
|
|
806
|
+
encodeValue(x) {
|
|
1001
807
|
if (x.length === 0) {
|
|
1002
808
|
return new Uint8Array([0]);
|
|
1003
809
|
}
|
|
1004
810
|
else {
|
|
1005
811
|
return (0, buffer_1.concat)(new Uint8Array([1]), this._type.encodeValue(x[0]));
|
|
1006
812
|
}
|
|
1007
|
-
}
|
|
1008
|
-
|
|
813
|
+
}
|
|
814
|
+
_buildTypeTableImpl(typeTable) {
|
|
1009
815
|
this._type.buildTypeTable(typeTable);
|
|
1010
|
-
|
|
1011
|
-
|
|
816
|
+
const opCode = (0, leb128_1.slebEncode)(-18 /* IDLTypeIds.Opt */);
|
|
817
|
+
const buffer = this._type.encodeType(typeTable);
|
|
1012
818
|
typeTable.add(this, (0, buffer_1.concat)(opCode, buffer));
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
|
|
819
|
+
}
|
|
820
|
+
decodeValue(b, t) {
|
|
821
|
+
const opt = this.checkType(t);
|
|
1016
822
|
if (!(opt instanceof OptClass)) {
|
|
1017
823
|
throw new Error('Not an option type');
|
|
1018
824
|
}
|
|
@@ -1024,117 +830,94 @@ var OptClass = /** @class */ (function (_super) {
|
|
|
1024
830
|
default:
|
|
1025
831
|
throw new Error('Not an option value');
|
|
1026
832
|
}
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
OptClass.prototype.display = function () {
|
|
1036
|
-
return "opt ".concat(this._type.display());
|
|
1037
|
-
};
|
|
1038
|
-
OptClass.prototype.valueToString = function (x) {
|
|
833
|
+
}
|
|
834
|
+
get name() {
|
|
835
|
+
return `opt ${this._type.name}`;
|
|
836
|
+
}
|
|
837
|
+
display() {
|
|
838
|
+
return `opt ${this._type.display()}`;
|
|
839
|
+
}
|
|
840
|
+
valueToString(x) {
|
|
1039
841
|
if (x.length === 0) {
|
|
1040
842
|
return 'null';
|
|
1041
843
|
}
|
|
1042
844
|
else {
|
|
1043
|
-
return
|
|
845
|
+
return `opt ${this._type.valueToString(x[0])}`;
|
|
1044
846
|
}
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
}(ConstructType));
|
|
847
|
+
}
|
|
848
|
+
}
|
|
1048
849
|
exports.OptClass = OptClass;
|
|
1049
850
|
/**
|
|
1050
851
|
* Represents an IDL Record
|
|
1051
852
|
* @param {Object} [fields] - mapping of function name to Type
|
|
1052
853
|
*/
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
return _this;
|
|
1060
|
-
}
|
|
1061
|
-
RecordClass.prototype.accept = function (v, d) {
|
|
854
|
+
class RecordClass extends ConstructType {
|
|
855
|
+
constructor(fields = {}) {
|
|
856
|
+
super();
|
|
857
|
+
this._fields = Object.entries(fields).sort((a, b) => idlLabelToId(a[0]) - idlLabelToId(b[0]));
|
|
858
|
+
}
|
|
859
|
+
accept(v, d) {
|
|
1062
860
|
return v.visitRecord(this, this._fields, d);
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
for (
|
|
1067
|
-
|
|
1068
|
-
if (key !==
|
|
861
|
+
}
|
|
862
|
+
tryAsTuple() {
|
|
863
|
+
const res = [];
|
|
864
|
+
for (let i = 0; i < this._fields.length; i++) {
|
|
865
|
+
const [key, type] = this._fields[i];
|
|
866
|
+
if (key !== `_${i}_`) {
|
|
1069
867
|
return null;
|
|
1070
868
|
}
|
|
1071
869
|
res.push(type);
|
|
1072
870
|
}
|
|
1073
871
|
return res;
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
var _this = this;
|
|
872
|
+
}
|
|
873
|
+
covariant(x) {
|
|
1077
874
|
if (typeof x === 'object' &&
|
|
1078
|
-
this._fields.every(
|
|
1079
|
-
var _b = __read(_a, 2), k = _b[0], t = _b[1];
|
|
875
|
+
this._fields.every(([k, t]) => {
|
|
1080
876
|
// eslint-disable-next-line
|
|
1081
877
|
if (!x.hasOwnProperty(k)) {
|
|
1082
|
-
throw new Error(
|
|
878
|
+
throw new Error(`Record is missing key "${k}".`);
|
|
1083
879
|
}
|
|
1084
880
|
try {
|
|
1085
881
|
return t.covariant(x[k]);
|
|
1086
882
|
}
|
|
1087
883
|
catch (e) {
|
|
1088
|
-
throw new Error(
|
|
884
|
+
throw new Error(`Invalid ${this.display()} argument: \n\nfield ${k} -> ${e.message}`);
|
|
1089
885
|
}
|
|
1090
886
|
}))
|
|
1091
887
|
return true;
|
|
1092
|
-
throw new Error(
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
return value.buildTypeTable(T);
|
|
1109
|
-
});
|
|
1110
|
-
var opCode = (0, leb128_1.slebEncode)(-20 /* IDLTypeIds.Record */);
|
|
1111
|
-
var len = (0, leb128_1.lebEncode)(this._fields.length);
|
|
1112
|
-
var fields = this._fields.map(function (_a) {
|
|
1113
|
-
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
1114
|
-
return (0, buffer_1.concat)((0, leb128_1.lebEncode)(idlLabelToId(key)), value.encodeType(T));
|
|
1115
|
-
});
|
|
1116
|
-
T.add(this, (0, buffer_1.concat)(opCode, len, buffer_1.concat.apply(void 0, __spreadArray([], __read(fields), false))));
|
|
1117
|
-
};
|
|
1118
|
-
RecordClass.prototype.decodeValue = function (b, t) {
|
|
1119
|
-
var e_3, _a;
|
|
1120
|
-
var record = this.checkType(t);
|
|
888
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
889
|
+
}
|
|
890
|
+
encodeValue(x) {
|
|
891
|
+
const values = this._fields.map(([key]) => x[key]);
|
|
892
|
+
const bufs = zipWith(this._fields, values, ([, c], d) => c.encodeValue(d));
|
|
893
|
+
return (0, buffer_1.concat)(...bufs);
|
|
894
|
+
}
|
|
895
|
+
_buildTypeTableImpl(T) {
|
|
896
|
+
this._fields.forEach(([_, value]) => value.buildTypeTable(T));
|
|
897
|
+
const opCode = (0, leb128_1.slebEncode)(-20 /* IDLTypeIds.Record */);
|
|
898
|
+
const len = (0, leb128_1.lebEncode)(this._fields.length);
|
|
899
|
+
const fields = this._fields.map(([key, value]) => (0, buffer_1.concat)((0, leb128_1.lebEncode)(idlLabelToId(key)), value.encodeType(T)));
|
|
900
|
+
T.add(this, (0, buffer_1.concat)(opCode, len, (0, buffer_1.concat)(...fields)));
|
|
901
|
+
}
|
|
902
|
+
decodeValue(b, t) {
|
|
903
|
+
const record = this.checkType(t);
|
|
1121
904
|
if (!(record instanceof RecordClass)) {
|
|
1122
905
|
throw new Error('Not a record type');
|
|
1123
906
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
907
|
+
const x = {};
|
|
908
|
+
let expectedRecordIdx = 0;
|
|
909
|
+
let actualRecordIdx = 0;
|
|
1127
910
|
while (actualRecordIdx < record._fields.length) {
|
|
1128
|
-
|
|
911
|
+
const [hash, type] = record._fields[actualRecordIdx];
|
|
1129
912
|
if (expectedRecordIdx >= this._fields.length) {
|
|
1130
913
|
// skip unexpected left over fields present on the wire
|
|
1131
914
|
type.decodeValue(b, type);
|
|
1132
915
|
actualRecordIdx++;
|
|
1133
916
|
continue;
|
|
1134
917
|
}
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
918
|
+
const [expectKey, expectType] = this._fields[expectedRecordIdx];
|
|
919
|
+
const expectedId = idlLabelToId(this._fields[expectedRecordIdx][0]);
|
|
920
|
+
const actualId = idlLabelToId(hash);
|
|
1138
921
|
if (expectedId === actualId) {
|
|
1139
922
|
// the current field on the wire matches the expected field
|
|
1140
923
|
x[expectKey] = expectType.decodeValue(b, type);
|
|
@@ -1157,392 +940,291 @@ var RecordClass = /** @class */ (function (_super) {
|
|
|
1157
940
|
actualRecordIdx++;
|
|
1158
941
|
}
|
|
1159
942
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
// TODO this assumes null value in opt is represented as []
|
|
1166
|
-
x[expectKey] = [];
|
|
1167
|
-
}
|
|
1168
|
-
else {
|
|
1169
|
-
throw new Error('Cannot find required field ' + expectKey);
|
|
1170
|
-
}
|
|
943
|
+
// initialize left over expected optional fields
|
|
944
|
+
for (const [expectKey, expectType] of this._fields.slice(expectedRecordIdx)) {
|
|
945
|
+
if (expectType instanceof OptClass || expectType instanceof ReservedClass) {
|
|
946
|
+
// TODO this assumes null value in opt is represented as []
|
|
947
|
+
x[expectKey] = [];
|
|
1171
948
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
finally {
|
|
1175
|
-
try {
|
|
1176
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
949
|
+
else {
|
|
950
|
+
throw new Error('Cannot find required field ' + expectKey);
|
|
1177
951
|
}
|
|
1178
|
-
finally { if (e_3) throw e_3.error; }
|
|
1179
952
|
}
|
|
1180
953
|
return x;
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
return key + ':' + value.display();
|
|
1197
|
-
});
|
|
1198
|
-
return "record {".concat(fields.join('; '), "}");
|
|
1199
|
-
};
|
|
1200
|
-
RecordClass.prototype.valueToString = function (x) {
|
|
1201
|
-
var values = this._fields.map(function (_a) {
|
|
1202
|
-
var _b = __read(_a, 1), key = _b[0];
|
|
1203
|
-
return x[key];
|
|
1204
|
-
});
|
|
1205
|
-
var fields = zipWith(this._fields, values, function (_a, d) {
|
|
1206
|
-
var _b = __read(_a, 2), k = _b[0], c = _b[1];
|
|
1207
|
-
return k + '=' + c.valueToString(d);
|
|
1208
|
-
});
|
|
1209
|
-
return "record {".concat(fields.join('; '), "}");
|
|
1210
|
-
};
|
|
1211
|
-
return RecordClass;
|
|
1212
|
-
}(ConstructType));
|
|
954
|
+
}
|
|
955
|
+
get name() {
|
|
956
|
+
const fields = this._fields.map(([key, value]) => key + ':' + value.name);
|
|
957
|
+
return `record {${fields.join('; ')}}`;
|
|
958
|
+
}
|
|
959
|
+
display() {
|
|
960
|
+
const fields = this._fields.map(([key, value]) => key + ':' + value.display());
|
|
961
|
+
return `record {${fields.join('; ')}}`;
|
|
962
|
+
}
|
|
963
|
+
valueToString(x) {
|
|
964
|
+
const values = this._fields.map(([key]) => x[key]);
|
|
965
|
+
const fields = zipWith(this._fields, values, ([k, c], d) => k + '=' + c.valueToString(d));
|
|
966
|
+
return `record {${fields.join('; ')}}`;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
1213
969
|
exports.RecordClass = RecordClass;
|
|
1214
970
|
/**
|
|
1215
971
|
* Represents Tuple, a syntactic sugar for Record.
|
|
1216
972
|
* @param {Type} components
|
|
1217
973
|
*/
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
_components
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
return _this;
|
|
1227
|
-
}
|
|
1228
|
-
TupleClass.prototype.accept = function (v, d) {
|
|
974
|
+
class TupleClass extends RecordClass {
|
|
975
|
+
constructor(_components) {
|
|
976
|
+
const x = {};
|
|
977
|
+
_components.forEach((e, i) => (x['_' + i + '_'] = e));
|
|
978
|
+
super(x);
|
|
979
|
+
this._components = _components;
|
|
980
|
+
}
|
|
981
|
+
accept(v, d) {
|
|
1229
982
|
return v.visitTuple(this, this._components, d);
|
|
1230
|
-
}
|
|
1231
|
-
|
|
983
|
+
}
|
|
984
|
+
covariant(x) {
|
|
1232
985
|
// `>=` because tuples can be covariant when encoded.
|
|
1233
|
-
var _this = this;
|
|
1234
986
|
if (Array.isArray(x) &&
|
|
1235
987
|
x.length >= this._fields.length &&
|
|
1236
|
-
this._components.every(
|
|
988
|
+
this._components.every((t, i) => {
|
|
1237
989
|
try {
|
|
1238
990
|
return t.covariant(x[i]);
|
|
1239
991
|
}
|
|
1240
992
|
catch (e) {
|
|
1241
|
-
throw new Error(
|
|
993
|
+
throw new Error(`Invalid ${this.display()} argument: \n\nindex ${i} -> ${e.message}`);
|
|
1242
994
|
}
|
|
1243
995
|
}))
|
|
1244
996
|
return true;
|
|
1245
|
-
throw new Error(
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
return
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
var tuple = this.checkType(t);
|
|
997
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
998
|
+
}
|
|
999
|
+
encodeValue(x) {
|
|
1000
|
+
const bufs = zipWith(this._components, x, (c, d) => c.encodeValue(d));
|
|
1001
|
+
return (0, buffer_1.concat)(...bufs);
|
|
1002
|
+
}
|
|
1003
|
+
decodeValue(b, t) {
|
|
1004
|
+
const tuple = this.checkType(t);
|
|
1254
1005
|
if (!(tuple instanceof TupleClass)) {
|
|
1255
1006
|
throw new Error('not a tuple type');
|
|
1256
1007
|
}
|
|
1257
1008
|
if (tuple._components.length < this._components.length) {
|
|
1258
1009
|
throw new Error('tuple mismatch');
|
|
1259
1010
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
// skip value
|
|
1266
|
-
wireType.decodeValue(b, wireType);
|
|
1267
|
-
}
|
|
1268
|
-
else {
|
|
1269
|
-
res.push(this._components[i].decodeValue(b, wireType));
|
|
1270
|
-
}
|
|
1011
|
+
const res = [];
|
|
1012
|
+
for (const [i, wireType] of tuple._components.entries()) {
|
|
1013
|
+
if (i >= this._components.length) {
|
|
1014
|
+
// skip value
|
|
1015
|
+
wireType.decodeValue(b, wireType);
|
|
1271
1016
|
}
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
finally {
|
|
1275
|
-
try {
|
|
1276
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1017
|
+
else {
|
|
1018
|
+
res.push(this._components[i].decodeValue(b, wireType));
|
|
1277
1019
|
}
|
|
1278
|
-
finally { if (e_4) throw e_4.error; }
|
|
1279
1020
|
}
|
|
1280
1021
|
return res;
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
return
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
return
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
}(RecordClass));
|
|
1022
|
+
}
|
|
1023
|
+
display() {
|
|
1024
|
+
const fields = this._components.map((value) => value.display());
|
|
1025
|
+
return `record {${fields.join('; ')}}`;
|
|
1026
|
+
}
|
|
1027
|
+
valueToString(values) {
|
|
1028
|
+
const fields = zipWith(this._components, values, (c, d) => c.valueToString(d));
|
|
1029
|
+
return `record {${fields.join('; ')}}`;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1292
1032
|
exports.TupleClass = TupleClass;
|
|
1293
1033
|
/**
|
|
1294
1034
|
* Represents an IDL Variant
|
|
1295
1035
|
* @param {Object} [fields] - mapping of function name to Type
|
|
1296
1036
|
*/
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
return _this;
|
|
1304
|
-
}
|
|
1305
|
-
VariantClass.prototype.accept = function (v, d) {
|
|
1037
|
+
class VariantClass extends ConstructType {
|
|
1038
|
+
constructor(fields = {}) {
|
|
1039
|
+
super();
|
|
1040
|
+
this._fields = Object.entries(fields).sort((a, b) => idlLabelToId(a[0]) - idlLabelToId(b[0]));
|
|
1041
|
+
}
|
|
1042
|
+
accept(v, d) {
|
|
1306
1043
|
return v.visitVariant(this, this._fields, d);
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
var _this = this;
|
|
1044
|
+
}
|
|
1045
|
+
covariant(x) {
|
|
1310
1046
|
if (typeof x === 'object' &&
|
|
1311
1047
|
Object.entries(x).length === 1 &&
|
|
1312
|
-
this._fields.every(
|
|
1313
|
-
var _b = __read(_a, 2), k = _b[0], v = _b[1];
|
|
1048
|
+
this._fields.every(([k, v]) => {
|
|
1314
1049
|
try {
|
|
1315
1050
|
// eslint-disable-next-line
|
|
1316
1051
|
return !x.hasOwnProperty(k) || v.covariant(x[k]);
|
|
1317
1052
|
}
|
|
1318
1053
|
catch (e) {
|
|
1319
|
-
throw new Error(
|
|
1054
|
+
throw new Error(`Invalid ${this.display()} argument: \n\nvariant ${k} -> ${e.message}`);
|
|
1320
1055
|
}
|
|
1321
1056
|
}))
|
|
1322
1057
|
return true;
|
|
1323
|
-
throw new Error(
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
for (
|
|
1327
|
-
|
|
1058
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1059
|
+
}
|
|
1060
|
+
encodeValue(x) {
|
|
1061
|
+
for (let i = 0; i < this._fields.length; i++) {
|
|
1062
|
+
const [name, type] = this._fields[i];
|
|
1328
1063
|
// eslint-disable-next-line
|
|
1329
|
-
if (x.hasOwnProperty(
|
|
1330
|
-
|
|
1331
|
-
|
|
1064
|
+
if (x.hasOwnProperty(name)) {
|
|
1065
|
+
const idx = (0, leb128_1.lebEncode)(i);
|
|
1066
|
+
const buf = type.encodeValue(x[name]);
|
|
1332
1067
|
return (0, buffer_1.concat)(idx, buf);
|
|
1333
1068
|
}
|
|
1334
1069
|
}
|
|
1335
1070
|
throw Error('Variant has no data: ' + x);
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
this._fields.forEach(
|
|
1339
|
-
var _b = __read(_a, 2), type = _b[1];
|
|
1071
|
+
}
|
|
1072
|
+
_buildTypeTableImpl(typeTable) {
|
|
1073
|
+
this._fields.forEach(([, type]) => {
|
|
1340
1074
|
type.buildTypeTable(typeTable);
|
|
1341
1075
|
});
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
};
|
|
1350
|
-
VariantClass.prototype.decodeValue = function (b, t) {
|
|
1351
|
-
var e_5, _a, _b;
|
|
1352
|
-
var variant = this.checkType(t);
|
|
1076
|
+
const opCode = (0, leb128_1.slebEncode)(-21 /* IDLTypeIds.Variant */);
|
|
1077
|
+
const len = (0, leb128_1.lebEncode)(this._fields.length);
|
|
1078
|
+
const fields = this._fields.map(([key, value]) => (0, buffer_1.concat)((0, leb128_1.lebEncode)(idlLabelToId(key)), value.encodeType(typeTable)));
|
|
1079
|
+
typeTable.add(this, (0, buffer_1.concat)(opCode, len, ...fields));
|
|
1080
|
+
}
|
|
1081
|
+
decodeValue(b, t) {
|
|
1082
|
+
const variant = this.checkType(t);
|
|
1353
1083
|
if (!(variant instanceof VariantClass)) {
|
|
1354
1084
|
throw new Error('Not a variant type');
|
|
1355
1085
|
}
|
|
1356
|
-
|
|
1086
|
+
const idx = Number((0, leb128_1.lebDecode)(b));
|
|
1357
1087
|
if (idx >= variant._fields.length) {
|
|
1358
1088
|
throw Error('Invalid variant index: ' + idx);
|
|
1359
1089
|
}
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
var value = expectType.decodeValue(b, wireType);
|
|
1366
|
-
return _b = {}, _b[key] = value, _b;
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1371
|
-
finally {
|
|
1372
|
-
try {
|
|
1373
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1090
|
+
const [wireHash, wireType] = variant._fields[idx];
|
|
1091
|
+
for (const [key, expectType] of this._fields) {
|
|
1092
|
+
if (idlLabelToId(wireHash) === idlLabelToId(key)) {
|
|
1093
|
+
const value = expectType.decodeValue(b, wireType);
|
|
1094
|
+
return { [key]: value };
|
|
1374
1095
|
}
|
|
1375
|
-
finally { if (e_5) throw e_5.error; }
|
|
1376
1096
|
}
|
|
1377
1097
|
throw new Error('Cannot find field hash ' + wireHash);
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
VariantClass.prototype.valueToString = function (x) {
|
|
1398
|
-
var e_6, _a;
|
|
1399
|
-
try {
|
|
1400
|
-
for (var _b = __values(this._fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1401
|
-
var _d = __read(_c.value, 2), name_2 = _d[0], type = _d[1];
|
|
1402
|
-
// eslint-disable-next-line
|
|
1403
|
-
if (x.hasOwnProperty(name_2)) {
|
|
1404
|
-
var value = type.valueToString(x[name_2]);
|
|
1405
|
-
if (value === 'null') {
|
|
1406
|
-
return "variant {".concat(name_2, "}");
|
|
1407
|
-
}
|
|
1408
|
-
else {
|
|
1409
|
-
return "variant {".concat(name_2, "=").concat(value, "}");
|
|
1410
|
-
}
|
|
1098
|
+
}
|
|
1099
|
+
get name() {
|
|
1100
|
+
const fields = this._fields.map(([key, type]) => key + ':' + type.name);
|
|
1101
|
+
return `variant {${fields.join('; ')}}`;
|
|
1102
|
+
}
|
|
1103
|
+
display() {
|
|
1104
|
+
const fields = this._fields.map(([key, type]) => key + (type.name === 'null' ? '' : `:${type.display()}`));
|
|
1105
|
+
return `variant {${fields.join('; ')}}`;
|
|
1106
|
+
}
|
|
1107
|
+
valueToString(x) {
|
|
1108
|
+
for (const [name, type] of this._fields) {
|
|
1109
|
+
// eslint-disable-next-line
|
|
1110
|
+
if (x.hasOwnProperty(name)) {
|
|
1111
|
+
const value = type.valueToString(x[name]);
|
|
1112
|
+
if (value === 'null') {
|
|
1113
|
+
return `variant {${name}}`;
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
return `variant {${name}=${value}}`;
|
|
1411
1117
|
}
|
|
1412
1118
|
}
|
|
1413
1119
|
}
|
|
1414
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1415
|
-
finally {
|
|
1416
|
-
try {
|
|
1417
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1418
|
-
}
|
|
1419
|
-
finally { if (e_6) throw e_6.error; }
|
|
1420
|
-
}
|
|
1421
1120
|
throw new Error('Variant has no data: ' + x);
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
}(ConstructType));
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1425
1123
|
exports.VariantClass = VariantClass;
|
|
1426
1124
|
/**
|
|
1427
1125
|
* Represents a reference to an IDL type, used for defining recursive data
|
|
1428
1126
|
* types.
|
|
1429
1127
|
*/
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
}
|
|
1438
|
-
RecClass.prototype.accept = function (v, d) {
|
|
1128
|
+
class RecClass extends ConstructType {
|
|
1129
|
+
constructor() {
|
|
1130
|
+
super(...arguments);
|
|
1131
|
+
this._id = RecClass._counter++;
|
|
1132
|
+
this._type = undefined;
|
|
1133
|
+
}
|
|
1134
|
+
accept(v, d) {
|
|
1439
1135
|
if (!this._type) {
|
|
1440
1136
|
throw Error('Recursive type uninitialized.');
|
|
1441
1137
|
}
|
|
1442
1138
|
return v.visitRec(this, this._type, d);
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1139
|
+
}
|
|
1140
|
+
fill(t) {
|
|
1445
1141
|
this._type = t;
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1142
|
+
}
|
|
1143
|
+
getType() {
|
|
1448
1144
|
return this._type;
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1145
|
+
}
|
|
1146
|
+
covariant(x) {
|
|
1451
1147
|
if (this._type ? this._type.covariant(x) : false)
|
|
1452
1148
|
return true;
|
|
1453
|
-
throw new Error(
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1149
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1150
|
+
}
|
|
1151
|
+
encodeValue(x) {
|
|
1456
1152
|
if (!this._type) {
|
|
1457
1153
|
throw Error('Recursive type uninitialized.');
|
|
1458
1154
|
}
|
|
1459
1155
|
return this._type.encodeValue(x);
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1156
|
+
}
|
|
1157
|
+
_buildTypeTableImpl(typeTable) {
|
|
1462
1158
|
if (!this._type) {
|
|
1463
1159
|
throw Error('Recursive type uninitialized.');
|
|
1464
1160
|
}
|
|
1465
1161
|
typeTable.add(this, new Uint8Array([]));
|
|
1466
1162
|
this._type.buildTypeTable(typeTable);
|
|
1467
1163
|
typeTable.merge(this, this._type.name);
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1164
|
+
}
|
|
1165
|
+
decodeValue(b, t) {
|
|
1470
1166
|
if (!this._type) {
|
|
1471
1167
|
throw Error('Recursive type uninitialized.');
|
|
1472
1168
|
}
|
|
1473
1169
|
return this._type.decodeValue(b, t);
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
enumerable: false,
|
|
1480
|
-
configurable: true
|
|
1481
|
-
});
|
|
1482
|
-
RecClass.prototype.display = function () {
|
|
1170
|
+
}
|
|
1171
|
+
get name() {
|
|
1172
|
+
return `rec_${this._id}`;
|
|
1173
|
+
}
|
|
1174
|
+
display() {
|
|
1483
1175
|
if (!this._type) {
|
|
1484
1176
|
throw Error('Recursive type uninitialized.');
|
|
1485
1177
|
}
|
|
1486
|
-
return
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1178
|
+
return `μ${this.name}.${this._type.name}`;
|
|
1179
|
+
}
|
|
1180
|
+
valueToString(x) {
|
|
1489
1181
|
if (!this._type) {
|
|
1490
1182
|
throw Error('Recursive type uninitialized.');
|
|
1491
1183
|
}
|
|
1492
1184
|
return this._type.valueToString(x);
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1495
|
-
return RecClass;
|
|
1496
|
-
}(ConstructType));
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1497
1187
|
exports.RecClass = RecClass;
|
|
1188
|
+
RecClass._counter = 0;
|
|
1498
1189
|
function decodePrincipalId(b) {
|
|
1499
|
-
|
|
1190
|
+
const x = (0, leb128_1.safeReadUint8)(b);
|
|
1500
1191
|
if (x !== 1) {
|
|
1501
1192
|
throw new Error('Cannot decode principal');
|
|
1502
1193
|
}
|
|
1503
|
-
|
|
1194
|
+
const len = Number((0, leb128_1.lebDecode)(b));
|
|
1504
1195
|
return principal_1.Principal.fromUint8Array(new Uint8Array((0, leb128_1.safeRead)(b, len)));
|
|
1505
1196
|
}
|
|
1506
1197
|
/**
|
|
1507
1198
|
* Represents an IDL principal reference
|
|
1508
1199
|
*/
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
function PrincipalClass() {
|
|
1512
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1513
|
-
}
|
|
1514
|
-
PrincipalClass.prototype.accept = function (v, d) {
|
|
1200
|
+
class PrincipalClass extends PrimitiveType {
|
|
1201
|
+
accept(v, d) {
|
|
1515
1202
|
return v.visitPrincipal(this, d);
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1203
|
+
}
|
|
1204
|
+
covariant(x) {
|
|
1518
1205
|
if (x && x._isPrincipal)
|
|
1519
1206
|
return true;
|
|
1520
|
-
throw new Error(
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1207
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1208
|
+
}
|
|
1209
|
+
encodeValue(x) {
|
|
1210
|
+
const buf = x.toUint8Array();
|
|
1211
|
+
const len = (0, leb128_1.lebEncode)(buf.byteLength);
|
|
1525
1212
|
return (0, buffer_1.concat)(new Uint8Array([1]), len, buf);
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1213
|
+
}
|
|
1214
|
+
encodeType() {
|
|
1528
1215
|
return (0, leb128_1.slebEncode)(-24 /* IDLTypeIds.Principal */);
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1216
|
+
}
|
|
1217
|
+
decodeValue(b, t) {
|
|
1531
1218
|
this.checkType(t);
|
|
1532
1219
|
return decodePrincipalId(b);
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
PrincipalClass.prototype.valueToString = function (x) {
|
|
1542
|
-
return "".concat(this.name, " \"").concat(x.toText(), "\"");
|
|
1543
|
-
};
|
|
1544
|
-
return PrincipalClass;
|
|
1545
|
-
}(PrimitiveType));
|
|
1220
|
+
}
|
|
1221
|
+
get name() {
|
|
1222
|
+
return 'principal';
|
|
1223
|
+
}
|
|
1224
|
+
valueToString(x) {
|
|
1225
|
+
return `${this.name} "${x.toText()}"`;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1546
1228
|
exports.PrincipalClass = PrincipalClass;
|
|
1547
1229
|
/**
|
|
1548
1230
|
* Represents an IDL function reference.
|
|
@@ -1550,85 +1232,75 @@ exports.PrincipalClass = PrincipalClass;
|
|
|
1550
1232
|
* @param retTypes Return types.
|
|
1551
1233
|
* @param annotations Function annotations.
|
|
1552
1234
|
*/
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
return _this;
|
|
1562
|
-
}
|
|
1563
|
-
FuncClass.argsToString = function (types, v) {
|
|
1235
|
+
class FuncClass extends ConstructType {
|
|
1236
|
+
constructor(argTypes, retTypes, annotations = []) {
|
|
1237
|
+
super();
|
|
1238
|
+
this.argTypes = argTypes;
|
|
1239
|
+
this.retTypes = retTypes;
|
|
1240
|
+
this.annotations = annotations;
|
|
1241
|
+
}
|
|
1242
|
+
static argsToString(types, v) {
|
|
1564
1243
|
if (types.length !== v.length) {
|
|
1565
1244
|
throw new Error('arity mismatch');
|
|
1566
1245
|
}
|
|
1567
|
-
return '(' + types.map(
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1246
|
+
return '(' + types.map((t, i) => t.valueToString(v[i])).join(', ') + ')';
|
|
1247
|
+
}
|
|
1248
|
+
accept(v, d) {
|
|
1570
1249
|
return v.visitFunc(this, d);
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1250
|
+
}
|
|
1251
|
+
covariant(x) {
|
|
1573
1252
|
if (Array.isArray(x) && x.length === 2 && x[0] && x[0]._isPrincipal && typeof x[1] === 'string')
|
|
1574
1253
|
return true;
|
|
1575
|
-
throw new Error(
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
var methodLen = (0, leb128_1.lebEncode)(method.byteLength);
|
|
1254
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1255
|
+
}
|
|
1256
|
+
encodeValue([principal, methodName]) {
|
|
1257
|
+
const buf = principal.toUint8Array();
|
|
1258
|
+
const len = (0, leb128_1.lebEncode)(buf.byteLength);
|
|
1259
|
+
const canister = (0, buffer_1.concat)(new Uint8Array([1]), len, buf);
|
|
1260
|
+
const method = new TextEncoder().encode(methodName);
|
|
1261
|
+
const methodLen = (0, leb128_1.lebEncode)(method.byteLength);
|
|
1584
1262
|
return (0, buffer_1.concat)(new Uint8Array([1]), canister, methodLen, method);
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
this.
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
var anns = buffer_1.concat.apply(void 0, __spreadArray([], __read(this.annotations.map(function (a) { return _this.encodeAnnotation(a); })), false));
|
|
1263
|
+
}
|
|
1264
|
+
_buildTypeTableImpl(T) {
|
|
1265
|
+
this.argTypes.forEach((arg) => arg.buildTypeTable(T));
|
|
1266
|
+
this.retTypes.forEach((arg) => arg.buildTypeTable(T));
|
|
1267
|
+
const opCode = (0, leb128_1.slebEncode)(-22 /* IDLTypeIds.Func */);
|
|
1268
|
+
const argLen = (0, leb128_1.lebEncode)(this.argTypes.length);
|
|
1269
|
+
const args = (0, buffer_1.concat)(...this.argTypes.map((arg) => arg.encodeType(T)));
|
|
1270
|
+
const retLen = (0, leb128_1.lebEncode)(this.retTypes.length);
|
|
1271
|
+
const rets = (0, buffer_1.concat)(...this.retTypes.map((arg) => arg.encodeType(T)));
|
|
1272
|
+
const annLen = (0, leb128_1.lebEncode)(this.annotations.length);
|
|
1273
|
+
const anns = (0, buffer_1.concat)(...this.annotations.map((a) => this.encodeAnnotation(a)));
|
|
1597
1274
|
T.add(this, (0, buffer_1.concat)(opCode, argLen, args, retLen, rets, annLen, anns));
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
|
|
1275
|
+
}
|
|
1276
|
+
decodeValue(b) {
|
|
1277
|
+
const x = (0, leb128_1.safeReadUint8)(b);
|
|
1601
1278
|
if (x !== 1) {
|
|
1602
1279
|
throw new Error('Cannot decode function reference');
|
|
1603
1280
|
}
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1281
|
+
const canister = decodePrincipalId(b);
|
|
1282
|
+
const mLen = Number((0, leb128_1.lebDecode)(b));
|
|
1283
|
+
const buf = (0, leb128_1.safeRead)(b, mLen);
|
|
1284
|
+
const decoder = new TextDecoder('utf8', { fatal: true });
|
|
1285
|
+
const method = decoder.decode(buf);
|
|
1609
1286
|
return [canister, method];
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
var rets = this.retTypes.map(function (arg) { return arg.display(); }).join(', ');
|
|
1628
|
-
var annon = ' ' + this.annotations.join(' ');
|
|
1629
|
-
return "(".concat(args, ") \u2192 (").concat(rets, ")").concat(annon);
|
|
1630
|
-
};
|
|
1631
|
-
FuncClass.prototype.encodeAnnotation = function (ann) {
|
|
1287
|
+
}
|
|
1288
|
+
get name() {
|
|
1289
|
+
const args = this.argTypes.map((arg) => arg.name).join(', ');
|
|
1290
|
+
const rets = this.retTypes.map((arg) => arg.name).join(', ');
|
|
1291
|
+
const annon = ' ' + this.annotations.join(' ');
|
|
1292
|
+
return `(${args}) -> (${rets})${annon}`;
|
|
1293
|
+
}
|
|
1294
|
+
valueToString([principal, str]) {
|
|
1295
|
+
return `func "${principal.toText()}".${str}`;
|
|
1296
|
+
}
|
|
1297
|
+
display() {
|
|
1298
|
+
const args = this.argTypes.map((arg) => arg.display()).join(', ');
|
|
1299
|
+
const rets = this.retTypes.map((arg) => arg.display()).join(', ');
|
|
1300
|
+
const annon = ' ' + this.annotations.join(' ');
|
|
1301
|
+
return `(${args}) → (${rets})${annon}`;
|
|
1302
|
+
}
|
|
1303
|
+
encodeAnnotation(ann) {
|
|
1632
1304
|
if (ann === 'query') {
|
|
1633
1305
|
return new Uint8Array([1]);
|
|
1634
1306
|
}
|
|
@@ -1638,64 +1310,49 @@ var FuncClass = /** @class */ (function (_super) {
|
|
|
1638
1310
|
else {
|
|
1639
1311
|
throw new Error('Illegal function annotation');
|
|
1640
1312
|
}
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
}(ConstructType));
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1644
1315
|
exports.FuncClass = FuncClass;
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
}
|
|
1652
|
-
ServiceClass.prototype.accept = function (v, d) {
|
|
1316
|
+
class ServiceClass extends ConstructType {
|
|
1317
|
+
constructor(fields) {
|
|
1318
|
+
super();
|
|
1319
|
+
this._fields = Object.entries(fields).sort((a, b) => idlLabelToId(a[0]) - idlLabelToId(b[0]));
|
|
1320
|
+
}
|
|
1321
|
+
accept(v, d) {
|
|
1653
1322
|
return v.visitService(this, d);
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1323
|
+
}
|
|
1324
|
+
covariant(x) {
|
|
1656
1325
|
if (x && x._isPrincipal)
|
|
1657
1326
|
return true;
|
|
1658
|
-
throw new Error(
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1327
|
+
throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
|
|
1328
|
+
}
|
|
1329
|
+
encodeValue(x) {
|
|
1330
|
+
const buf = x.toUint8Array();
|
|
1331
|
+
const len = (0, leb128_1.lebEncode)(buf.length);
|
|
1663
1332
|
return (0, buffer_1.concat)(new Uint8Array([1]), len, buf);
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
this._fields.forEach(
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
var meths = this._fields.map(function (_a) {
|
|
1673
|
-
var _b = __read(_a, 2), label = _b[0], func = _b[1];
|
|
1674
|
-
var labelBuf = new TextEncoder().encode(label);
|
|
1675
|
-
var labelLen = (0, leb128_1.lebEncode)(labelBuf.length);
|
|
1333
|
+
}
|
|
1334
|
+
_buildTypeTableImpl(T) {
|
|
1335
|
+
this._fields.forEach(([_, func]) => func.buildTypeTable(T));
|
|
1336
|
+
const opCode = (0, leb128_1.slebEncode)(-23 /* IDLTypeIds.Service */);
|
|
1337
|
+
const len = (0, leb128_1.lebEncode)(this._fields.length);
|
|
1338
|
+
const meths = this._fields.map(([label, func]) => {
|
|
1339
|
+
const labelBuf = new TextEncoder().encode(label);
|
|
1340
|
+
const labelLen = (0, leb128_1.lebEncode)(labelBuf.length);
|
|
1676
1341
|
return (0, buffer_1.concat)(labelLen, labelBuf, func.encodeType(T));
|
|
1677
1342
|
});
|
|
1678
|
-
T.add(this,
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1343
|
+
T.add(this, (0, buffer_1.concat)(opCode, len, ...meths));
|
|
1344
|
+
}
|
|
1345
|
+
decodeValue(b) {
|
|
1681
1346
|
return decodePrincipalId(b);
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
enumerable: false,
|
|
1692
|
-
configurable: true
|
|
1693
|
-
});
|
|
1694
|
-
ServiceClass.prototype.valueToString = function (x) {
|
|
1695
|
-
return "service \"".concat(x.toText(), "\"");
|
|
1696
|
-
};
|
|
1697
|
-
return ServiceClass;
|
|
1698
|
-
}(ConstructType));
|
|
1347
|
+
}
|
|
1348
|
+
get name() {
|
|
1349
|
+
const fields = this._fields.map(([key, value]) => key + ':' + value.name);
|
|
1350
|
+
return `service {${fields.join('; ')}}`;
|
|
1351
|
+
}
|
|
1352
|
+
valueToString(x) {
|
|
1353
|
+
return `service "${x.toText()}"`;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1699
1356
|
exports.ServiceClass = ServiceClass;
|
|
1700
1357
|
/**
|
|
1701
1358
|
*
|
|
@@ -1703,7 +1360,7 @@ exports.ServiceClass = ServiceClass;
|
|
|
1703
1360
|
* @returns {string}
|
|
1704
1361
|
*/
|
|
1705
1362
|
function toReadableString(x) {
|
|
1706
|
-
|
|
1363
|
+
const str = JSON.stringify(x, (_key, value) => (typeof value === 'bigint' ? `BigInt(${value})` : value));
|
|
1707
1364
|
return str && str.length > toReadableString_max ? str.substring(0, toReadableString_max - 3) + '...' : str;
|
|
1708
1365
|
}
|
|
1709
1366
|
/**
|
|
@@ -1716,22 +1373,22 @@ function encode(argTypes, args) {
|
|
|
1716
1373
|
if (args.length < argTypes.length) {
|
|
1717
1374
|
throw Error('Wrong number of message arguments');
|
|
1718
1375
|
}
|
|
1719
|
-
|
|
1720
|
-
argTypes.forEach(
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1376
|
+
const typeTable = new TypeTable();
|
|
1377
|
+
argTypes.forEach((t) => t.buildTypeTable(typeTable));
|
|
1378
|
+
const magic = new TextEncoder().encode(magicNumber);
|
|
1379
|
+
const table = typeTable.encode();
|
|
1380
|
+
const len = (0, leb128_1.lebEncode)(args.length);
|
|
1381
|
+
const typs = (0, buffer_1.concat)(...argTypes.map((t) => t.encodeType(typeTable)));
|
|
1382
|
+
const vals = (0, buffer_1.concat)(...zipWith(argTypes, args, (t, x) => {
|
|
1726
1383
|
try {
|
|
1727
1384
|
t.covariant(x);
|
|
1728
1385
|
}
|
|
1729
1386
|
catch (e) {
|
|
1730
|
-
|
|
1387
|
+
const err = new Error(e.message + '\n\n');
|
|
1731
1388
|
throw err;
|
|
1732
1389
|
}
|
|
1733
1390
|
return t.encodeValue(x);
|
|
1734
|
-
}))
|
|
1391
|
+
}));
|
|
1735
1392
|
return (0, buffer_1.concat)(magic, table, len, typs, vals);
|
|
1736
1393
|
}
|
|
1737
1394
|
exports.encode = encode;
|
|
@@ -1742,34 +1399,34 @@ exports.encode = encode;
|
|
|
1742
1399
|
* @returns Value deserialised to JS type
|
|
1743
1400
|
*/
|
|
1744
1401
|
function decode(retTypes, bytes) {
|
|
1745
|
-
|
|
1402
|
+
const b = new buffer_2.PipeArrayBuffer(bytes);
|
|
1746
1403
|
if (bytes.byteLength < magicNumber.length) {
|
|
1747
1404
|
throw new Error('Message length smaller than magic number');
|
|
1748
1405
|
}
|
|
1749
|
-
|
|
1750
|
-
|
|
1406
|
+
const magicBuffer = (0, leb128_1.safeRead)(b, magicNumber.length);
|
|
1407
|
+
const magic = new TextDecoder().decode(magicBuffer);
|
|
1751
1408
|
if (magic !== magicNumber) {
|
|
1752
1409
|
throw new Error('Wrong magic number: ' + JSON.stringify(magic));
|
|
1753
1410
|
}
|
|
1754
1411
|
function readTypeTable(pipe) {
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
for (
|
|
1758
|
-
|
|
1412
|
+
const typeTable = [];
|
|
1413
|
+
const len = Number((0, leb128_1.lebDecode)(pipe));
|
|
1414
|
+
for (let i = 0; i < len; i++) {
|
|
1415
|
+
const ty = Number((0, leb128_1.slebDecode)(pipe));
|
|
1759
1416
|
switch (ty) {
|
|
1760
1417
|
case -18 /* IDLTypeIds.Opt */:
|
|
1761
1418
|
case -19 /* IDLTypeIds.Vector */: {
|
|
1762
|
-
|
|
1419
|
+
const t = Number((0, leb128_1.slebDecode)(pipe));
|
|
1763
1420
|
typeTable.push([ty, t]);
|
|
1764
1421
|
break;
|
|
1765
1422
|
}
|
|
1766
1423
|
case -20 /* IDLTypeIds.Record */:
|
|
1767
1424
|
case -21 /* IDLTypeIds.Variant */: {
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1425
|
+
const fields = [];
|
|
1426
|
+
let objectLength = Number((0, leb128_1.lebDecode)(pipe));
|
|
1427
|
+
let prevHash;
|
|
1771
1428
|
while (objectLength--) {
|
|
1772
|
-
|
|
1429
|
+
const hash = Number((0, leb128_1.lebDecode)(pipe));
|
|
1773
1430
|
if (hash >= Math.pow(2, 32)) {
|
|
1774
1431
|
throw new Error('field id out of 32-bit range');
|
|
1775
1432
|
}
|
|
@@ -1777,27 +1434,27 @@ function decode(retTypes, bytes) {
|
|
|
1777
1434
|
throw new Error('field id collision or not sorted');
|
|
1778
1435
|
}
|
|
1779
1436
|
prevHash = hash;
|
|
1780
|
-
|
|
1437
|
+
const t = Number((0, leb128_1.slebDecode)(pipe));
|
|
1781
1438
|
fields.push([hash, t]);
|
|
1782
1439
|
}
|
|
1783
1440
|
typeTable.push([ty, fields]);
|
|
1784
1441
|
break;
|
|
1785
1442
|
}
|
|
1786
1443
|
case -22 /* IDLTypeIds.Func */: {
|
|
1787
|
-
|
|
1788
|
-
|
|
1444
|
+
const args = [];
|
|
1445
|
+
let argLength = Number((0, leb128_1.lebDecode)(pipe));
|
|
1789
1446
|
while (argLength--) {
|
|
1790
1447
|
args.push(Number((0, leb128_1.slebDecode)(pipe)));
|
|
1791
1448
|
}
|
|
1792
|
-
|
|
1793
|
-
|
|
1449
|
+
const returnValues = [];
|
|
1450
|
+
let returnValuesLength = Number((0, leb128_1.lebDecode)(pipe));
|
|
1794
1451
|
while (returnValuesLength--) {
|
|
1795
1452
|
returnValues.push(Number((0, leb128_1.slebDecode)(pipe)));
|
|
1796
1453
|
}
|
|
1797
|
-
|
|
1798
|
-
|
|
1454
|
+
const annotations = [];
|
|
1455
|
+
let annotationLength = Number((0, leb128_1.lebDecode)(pipe));
|
|
1799
1456
|
while (annotationLength--) {
|
|
1800
|
-
|
|
1457
|
+
const annotation = Number((0, leb128_1.lebDecode)(pipe));
|
|
1801
1458
|
switch (annotation) {
|
|
1802
1459
|
case 1: {
|
|
1803
1460
|
annotations.push('query');
|
|
@@ -1815,12 +1472,12 @@ function decode(retTypes, bytes) {
|
|
|
1815
1472
|
break;
|
|
1816
1473
|
}
|
|
1817
1474
|
case -23 /* IDLTypeIds.Service */: {
|
|
1818
|
-
|
|
1819
|
-
|
|
1475
|
+
let servLength = Number((0, leb128_1.lebDecode)(pipe));
|
|
1476
|
+
const methods = [];
|
|
1820
1477
|
while (servLength--) {
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1478
|
+
const nameLength = Number((0, leb128_1.lebDecode)(pipe));
|
|
1479
|
+
const funcName = new TextDecoder().decode((0, leb128_1.safeRead)(pipe, nameLength));
|
|
1480
|
+
const funcType = (0, leb128_1.slebDecode)(pipe);
|
|
1824
1481
|
methods.push([funcName, funcType]);
|
|
1825
1482
|
}
|
|
1826
1483
|
typeTable.push([ty, methods]);
|
|
@@ -1830,18 +1487,18 @@ function decode(retTypes, bytes) {
|
|
|
1830
1487
|
throw new Error('Illegal op_code: ' + ty);
|
|
1831
1488
|
}
|
|
1832
1489
|
}
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
for (
|
|
1490
|
+
const rawList = [];
|
|
1491
|
+
const length = Number((0, leb128_1.lebDecode)(pipe));
|
|
1492
|
+
for (let i = 0; i < length; i++) {
|
|
1836
1493
|
rawList.push(Number((0, leb128_1.slebDecode)(pipe)));
|
|
1837
1494
|
}
|
|
1838
1495
|
return [typeTable, rawList];
|
|
1839
1496
|
}
|
|
1840
|
-
|
|
1497
|
+
const [rawTable, rawTypes] = readTypeTable(b);
|
|
1841
1498
|
if (rawTypes.length < retTypes.length) {
|
|
1842
1499
|
throw new Error('Wrong number of return values');
|
|
1843
1500
|
}
|
|
1844
|
-
|
|
1501
|
+
const table = rawTable.map((_) => Rec());
|
|
1845
1502
|
function getType(t) {
|
|
1846
1503
|
if (t < -24) {
|
|
1847
1504
|
throw new Error('future value not supported');
|
|
@@ -1894,86 +1551,55 @@ function decode(retTypes, bytes) {
|
|
|
1894
1551
|
return table[t];
|
|
1895
1552
|
}
|
|
1896
1553
|
function buildType(entry) {
|
|
1897
|
-
var e_7, _a, e_8, _b, e_9, _c;
|
|
1898
1554
|
switch (entry[0]) {
|
|
1899
1555
|
case -19 /* IDLTypeIds.Vector */: {
|
|
1900
|
-
|
|
1556
|
+
const ty = getType(entry[1]);
|
|
1901
1557
|
return Vec(ty);
|
|
1902
1558
|
}
|
|
1903
1559
|
case -18 /* IDLTypeIds.Opt */: {
|
|
1904
|
-
|
|
1560
|
+
const ty = getType(entry[1]);
|
|
1905
1561
|
return Opt(ty);
|
|
1906
1562
|
}
|
|
1907
1563
|
case -20 /* IDLTypeIds.Record */: {
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
var name_3 = "_".concat(hash, "_");
|
|
1913
|
-
fields[name_3] = getType(ty);
|
|
1914
|
-
}
|
|
1564
|
+
const fields = {};
|
|
1565
|
+
for (const [hash, ty] of entry[1]) {
|
|
1566
|
+
const name = `_${hash}_`;
|
|
1567
|
+
fields[name] = getType(ty);
|
|
1915
1568
|
}
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
try {
|
|
1919
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
1920
|
-
}
|
|
1921
|
-
finally { if (e_7) throw e_7.error; }
|
|
1922
|
-
}
|
|
1923
|
-
var record = Record(fields);
|
|
1924
|
-
var tuple = record.tryAsTuple();
|
|
1569
|
+
const record = Record(fields);
|
|
1570
|
+
const tuple = record.tryAsTuple();
|
|
1925
1571
|
if (Array.isArray(tuple)) {
|
|
1926
|
-
return Tuple
|
|
1572
|
+
return Tuple(...tuple);
|
|
1927
1573
|
}
|
|
1928
1574
|
else {
|
|
1929
1575
|
return record;
|
|
1930
1576
|
}
|
|
1931
1577
|
}
|
|
1932
1578
|
case -21 /* IDLTypeIds.Variant */: {
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
var name_4 = "_".concat(hash, "_");
|
|
1938
|
-
fields[name_4] = getType(ty);
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
1942
|
-
finally {
|
|
1943
|
-
try {
|
|
1944
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
1945
|
-
}
|
|
1946
|
-
finally { if (e_8) throw e_8.error; }
|
|
1579
|
+
const fields = {};
|
|
1580
|
+
for (const [hash, ty] of entry[1]) {
|
|
1581
|
+
const name = `_${hash}_`;
|
|
1582
|
+
fields[name] = getType(ty);
|
|
1947
1583
|
}
|
|
1948
1584
|
return Variant(fields);
|
|
1949
1585
|
}
|
|
1950
1586
|
case -22 /* IDLTypeIds.Func */: {
|
|
1951
|
-
|
|
1952
|
-
return Func(args.map(
|
|
1587
|
+
const [args, returnValues, annotations] = entry[1];
|
|
1588
|
+
return Func(args.map((t) => getType(t)), returnValues.map((t) => getType(t)), annotations);
|
|
1953
1589
|
}
|
|
1954
1590
|
case -23 /* IDLTypeIds.Service */: {
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
// unpack reference type
|
|
1963
|
-
type = type.getType();
|
|
1964
|
-
}
|
|
1965
|
-
if (!(type instanceof FuncClass)) {
|
|
1966
|
-
throw new Error('Illegal service definition: services can only contain functions');
|
|
1967
|
-
}
|
|
1968
|
-
rec[name_5] = type;
|
|
1591
|
+
const rec = {};
|
|
1592
|
+
const methods = entry[1];
|
|
1593
|
+
for (const [name, typeRef] of methods) {
|
|
1594
|
+
let type = getType(typeRef);
|
|
1595
|
+
if (type instanceof RecClass) {
|
|
1596
|
+
// unpack reference type
|
|
1597
|
+
type = type.getType();
|
|
1969
1598
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
finally {
|
|
1973
|
-
try {
|
|
1974
|
-
if (methods_1_1 && !methods_1_1.done && (_c = methods_1.return)) _c.call(methods_1);
|
|
1599
|
+
if (!(type instanceof FuncClass)) {
|
|
1600
|
+
throw new Error('Illegal service definition: services can only contain functions');
|
|
1975
1601
|
}
|
|
1976
|
-
|
|
1602
|
+
rec[name] = type;
|
|
1977
1603
|
}
|
|
1978
1604
|
return Service(rec);
|
|
1979
1605
|
}
|
|
@@ -1981,16 +1607,16 @@ function decode(retTypes, bytes) {
|
|
|
1981
1607
|
throw new Error('Illegal op_code: ' + entry[0]);
|
|
1982
1608
|
}
|
|
1983
1609
|
}
|
|
1984
|
-
rawTable.forEach(
|
|
1985
|
-
|
|
1610
|
+
rawTable.forEach((entry, i) => {
|
|
1611
|
+
const t = buildType(entry);
|
|
1986
1612
|
table[i].fill(t);
|
|
1987
1613
|
});
|
|
1988
|
-
|
|
1989
|
-
|
|
1614
|
+
const types = rawTypes.map((t) => getType(t));
|
|
1615
|
+
const output = retTypes.map((t, i) => {
|
|
1990
1616
|
return t.decodeValue(b, types[i]);
|
|
1991
1617
|
});
|
|
1992
1618
|
// skip unused values
|
|
1993
|
-
for (
|
|
1619
|
+
for (let ind = retTypes.length; ind < types.length; ind++) {
|
|
1994
1620
|
types[ind].decodeValue(b, types[ind]);
|
|
1995
1621
|
}
|
|
1996
1622
|
if (b.byteLength > 0) {
|
|
@@ -2027,11 +1653,7 @@ exports.Principal = new PrincipalClass();
|
|
|
2027
1653
|
* @param types array of any types
|
|
2028
1654
|
* @returns TupleClass from those types
|
|
2029
1655
|
*/
|
|
2030
|
-
function Tuple() {
|
|
2031
|
-
var types = [];
|
|
2032
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2033
|
-
types[_i] = arguments[_i];
|
|
2034
|
-
}
|
|
1656
|
+
function Tuple(...types) {
|
|
2035
1657
|
return new TupleClass(types);
|
|
2036
1658
|
}
|
|
2037
1659
|
exports.Tuple = Tuple;
|
|
@@ -2086,8 +1708,7 @@ exports.Rec = Rec;
|
|
|
2086
1708
|
* @param annotations array of strings, [] by default
|
|
2087
1709
|
* @returns new FuncClass
|
|
2088
1710
|
*/
|
|
2089
|
-
function Func(args, ret, annotations) {
|
|
2090
|
-
if (annotations === void 0) { annotations = []; }
|
|
1711
|
+
function Func(args, ret, annotations = []) {
|
|
2091
1712
|
return new FuncClass(args, ret, annotations);
|
|
2092
1713
|
}
|
|
2093
1714
|
exports.Func = Func;
|