snyk 1.814.0 → 1.815.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/dist/cli/{424.index.js → 55.index.js} +266 -370
- package/dist/cli/55.index.js.map +1 -0
- package/dist/cli/917.index.js +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/thirdPartyNotice.json +2 -11
- package/package.json +2 -2
- package/dist/cli/424.index.js.map +0 -1
|
@@ -1,81 +1,46 @@
|
|
|
1
|
-
exports.id =
|
|
2
|
-
exports.ids = [
|
|
1
|
+
exports.id = 55;
|
|
2
|
+
exports.ids = [55];
|
|
3
3
|
exports.modules = {
|
|
4
4
|
|
|
5
|
-
/***/ 87448:
|
|
6
|
-
/***/ ((module) => {
|
|
7
|
-
|
|
8
|
-
count = (arr) => arr.length;
|
|
9
|
-
sum = (arr) => arr.reduce((a, b) => a + b, 0);
|
|
10
|
-
product = (arr) => arr.reduce((total, num) => total * num, 1);
|
|
11
|
-
max = (arr) => Math.max(arr);
|
|
12
|
-
min = (arr) => Math.min(arr);
|
|
13
|
-
sort = (arr) => [...arr].sort();
|
|
14
|
-
all = (arr) => (arr.length === 0 ? true : arr.every((v) => v === true));
|
|
15
|
-
any = (arr) => (arr.length === 0 ? false : arr.includes(true));
|
|
16
|
-
|
|
17
|
-
module.exports = { count, sum, product, min, sort, all, any };
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/***/ }),
|
|
21
|
-
|
|
22
|
-
/***/ 1778:
|
|
23
|
-
/***/ ((module) => {
|
|
24
|
-
|
|
25
|
-
arrayConcat = (arr1, arr2) => arr1.concat(arr2);
|
|
26
|
-
arraySlice = (arr, startIndex, stopIndex) => arr.slice(startIndex, stopIndex);
|
|
27
|
-
|
|
28
|
-
module.exports = { "array.concat": arrayConcat, "array.slice": arraySlice };
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/***/ }),
|
|
32
|
-
|
|
33
|
-
/***/ 20028:
|
|
34
|
-
/***/ ((module) => {
|
|
35
|
-
|
|
36
|
-
to_number = (x) => Number(x);
|
|
37
|
-
|
|
38
|
-
module.exports = { to_number };
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/***/ }),
|
|
42
|
-
|
|
43
5
|
/***/ 42869:
|
|
44
6
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
45
7
|
|
|
46
|
-
const
|
|
47
|
-
const aggregates = __webpack_require__(87448);
|
|
48
|
-
const arrays = __webpack_require__(1778);
|
|
8
|
+
const json = __webpack_require__(29387);
|
|
49
9
|
const strings = __webpack_require__(13043);
|
|
50
10
|
const regex = __webpack_require__(13732);
|
|
51
|
-
const
|
|
52
|
-
const conversions = __webpack_require__(20028);
|
|
11
|
+
const yaml = __webpack_require__(76050);
|
|
53
12
|
|
|
54
13
|
module.exports = {
|
|
55
|
-
...
|
|
56
|
-
...aggregates,
|
|
57
|
-
...arrays,
|
|
14
|
+
...json,
|
|
58
15
|
...strings,
|
|
59
16
|
...regex,
|
|
60
|
-
...
|
|
61
|
-
...conversions,
|
|
17
|
+
...yaml,
|
|
62
18
|
};
|
|
63
19
|
|
|
64
20
|
|
|
65
21
|
/***/ }),
|
|
66
22
|
|
|
67
|
-
/***/
|
|
23
|
+
/***/ 29387:
|
|
68
24
|
/***/ ((module) => {
|
|
69
25
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
26
|
+
function isValidJSON(str) {
|
|
27
|
+
if (typeof str !== "string") {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
JSON.parse(str);
|
|
32
|
+
return true;
|
|
33
|
+
} catch (err) {
|
|
34
|
+
if (err instanceof SyntaxError) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
77
40
|
|
|
78
|
-
module.exports = {
|
|
41
|
+
module.exports = {
|
|
42
|
+
"json.is_valid": isValidJSON,
|
|
43
|
+
};
|
|
79
44
|
|
|
80
45
|
|
|
81
46
|
/***/ }),
|
|
@@ -83,10 +48,9 @@ module.exports = { plus, minus, mul, div, rem, round, abs };
|
|
|
83
48
|
/***/ 13732:
|
|
84
49
|
/***/ ((module) => {
|
|
85
50
|
|
|
86
|
-
|
|
87
|
-
regexSplit = (pattern, s) => s.split(RegExp(pattern));
|
|
51
|
+
const regexSplit = (pattern, s) => s.split(RegExp(pattern));
|
|
88
52
|
|
|
89
|
-
module.exports = { "regex.split": regexSplit
|
|
53
|
+
module.exports = { "regex.split": regexSplit };
|
|
90
54
|
|
|
91
55
|
|
|
92
56
|
/***/ }),
|
|
@@ -94,57 +58,55 @@ module.exports = { "regex.split": regexSplit, re_match };
|
|
|
94
58
|
/***/ 13043:
|
|
95
59
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
96
60
|
|
|
97
|
-
|
|
61
|
+
const vsprintf = __webpack_require__(8975).vsprintf;
|
|
98
62
|
|
|
99
|
-
|
|
100
|
-
endswith = (s, search) => s.endsWith(search);
|
|
101
|
-
indexof = (s, search) => s.indexOf(search);
|
|
102
|
-
lower = (s) => s.toLowerCase();
|
|
103
|
-
replace = (s, searchValue, newValue) => s.replace(searchValue, newValue);
|
|
104
|
-
split = (s, delimiter) => s.split(delimiter);
|
|
105
|
-
sprintf = (s, values) => vsprintf(s, values);
|
|
106
|
-
startswith = (s, search) => s.startsWith(search);
|
|
107
|
-
substring = (s, start, length) => s.substr(start, length);
|
|
108
|
-
concat = (delimiter, arr) => arr.join(delimiter);
|
|
63
|
+
const sprintf = (s, values) => vsprintf(s, values);
|
|
109
64
|
|
|
110
|
-
module.exports = {
|
|
111
|
-
contains,
|
|
112
|
-
endswith,
|
|
113
|
-
indexof,
|
|
114
|
-
lower,
|
|
115
|
-
replace,
|
|
116
|
-
split,
|
|
117
|
-
sprintf,
|
|
118
|
-
startswith,
|
|
119
|
-
substring,
|
|
120
|
-
concat,
|
|
121
|
-
};
|
|
65
|
+
module.exports = { sprintf };
|
|
122
66
|
|
|
123
67
|
|
|
124
68
|
/***/ }),
|
|
125
69
|
|
|
126
|
-
/***/
|
|
127
|
-
/***/ ((module) => {
|
|
70
|
+
/***/ 76050:
|
|
71
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
128
72
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
73
|
+
const yaml = __webpack_require__(6792);
|
|
74
|
+
|
|
75
|
+
// see: https://eemeli.org/yaml/v1/#errors
|
|
76
|
+
const errors = new Set([
|
|
77
|
+
"YAMLReferenceError",
|
|
78
|
+
"YAMLSemanticError",
|
|
79
|
+
"YAMLSyntaxError",
|
|
80
|
+
"YAMLWarning",
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
function parse(str) {
|
|
84
|
+
if (typeof str !== "string") {
|
|
85
|
+
return { ok: false, result: undefined };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const YAML_SILENCE_WARNINGS_CACHED = global.YAML_SILENCE_WARNINGS;
|
|
89
|
+
try {
|
|
90
|
+
// see: https://eemeli.org/yaml/v1/#silencing-warnings
|
|
91
|
+
global.YAML_SILENCE_WARNINGS = true;
|
|
92
|
+
return { ok: true, result: yaml.parse(str) };
|
|
93
|
+
} catch (err) {
|
|
94
|
+
// Ignore parser errors.
|
|
95
|
+
if (err && errors.has(err.name)) {
|
|
96
|
+
return { ok: false, result: undefined };
|
|
97
|
+
}
|
|
98
|
+
throw err;
|
|
99
|
+
} finally {
|
|
100
|
+
global.YAML_SILENCE_WARNINGS = YAML_SILENCE_WARNINGS_CACHED;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
138
103
|
|
|
139
104
|
module.exports = {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
is_object,
|
|
146
|
-
is_null,
|
|
147
|
-
type_name,
|
|
105
|
+
// is_valid is expected to return nothing if input is invalid otherwise
|
|
106
|
+
// true/false for it being valid YAML.
|
|
107
|
+
"yaml.is_valid": (str) => typeof str === "string" ? parse(str).ok : undefined,
|
|
108
|
+
"yaml.marshal": (data) => yaml.stringify(data),
|
|
109
|
+
"yaml.unmarshal": (str) => parse(str).result,
|
|
148
110
|
};
|
|
149
111
|
|
|
150
112
|
|
|
@@ -157,7 +119,16 @@ module.exports = {
|
|
|
157
119
|
// Use of this source code is governed by an Apache2
|
|
158
120
|
// license that can be found in the LICENSE file.
|
|
159
121
|
const builtIns = __webpack_require__(42869);
|
|
160
|
-
const
|
|
122
|
+
const util = __webpack_require__(31669);
|
|
123
|
+
|
|
124
|
+
// NOTE: The util shim here exists for Node 10.x and can be removed
|
|
125
|
+
// when dropping support. Browsers and Node >= 11.x use the global.
|
|
126
|
+
const TextEncoder = typeof global.TextEncoder !== "undefined"
|
|
127
|
+
? global.TextEncoder
|
|
128
|
+
: util.TextEncoder;
|
|
129
|
+
const TextDecoder = typeof global.TextDecoder !== "undefined"
|
|
130
|
+
? global.TextDecoder
|
|
131
|
+
: util.TextDecoder;
|
|
161
132
|
|
|
162
133
|
/**
|
|
163
134
|
* @param {WebAssembly.Memory} mem
|
|
@@ -177,23 +148,28 @@ function stringDecoder(mem) {
|
|
|
177
148
|
* Stringifies and loads an object into OPA's Memory
|
|
178
149
|
* @param {WebAssembly.Instance} wasmInstance
|
|
179
150
|
* @param {WebAssembly.Memory} memory
|
|
180
|
-
* @param {any} value
|
|
151
|
+
* @param {any | ArrayBuffer} value data as `object`, literal primitive or ArrayBuffer (last is assumed to be a well-formed stringified JSON)
|
|
181
152
|
* @returns {number}
|
|
182
153
|
*/
|
|
183
154
|
function _loadJSON(wasmInstance, memory, value) {
|
|
184
155
|
if (value === undefined) {
|
|
185
|
-
|
|
156
|
+
return 0;
|
|
186
157
|
}
|
|
187
158
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
159
|
+
let valueBuf;
|
|
160
|
+
if (value instanceof ArrayBuffer) {
|
|
161
|
+
valueBuf = new Uint8Array(value);
|
|
162
|
+
} else {
|
|
163
|
+
const valueAsText = JSON.stringify(value);
|
|
164
|
+
valueBuf = new TextEncoder().encode(valueAsText);
|
|
194
165
|
}
|
|
195
166
|
|
|
196
|
-
const
|
|
167
|
+
const valueBufLen = valueBuf.byteLength;
|
|
168
|
+
const rawAddr = wasmInstance.exports.opa_malloc(valueBufLen);
|
|
169
|
+
const memoryBuffer = new Uint8Array(memory.buffer);
|
|
170
|
+
memoryBuffer.set(valueBuf, rawAddr);
|
|
171
|
+
|
|
172
|
+
const parsedAddr = wasmInstance.exports.opa_json_parse(rawAddr, valueBufLen);
|
|
197
173
|
|
|
198
174
|
if (parsedAddr === 0) {
|
|
199
175
|
throw "failed to parse json value";
|
|
@@ -210,16 +186,28 @@ function _loadJSON(wasmInstance, memory, value) {
|
|
|
210
186
|
*/
|
|
211
187
|
function _dumpJSON(wasmInstance, memory, addr) {
|
|
212
188
|
const rawAddr = wasmInstance.exports.opa_json_dump(addr);
|
|
189
|
+
return _dumpJSONRaw(memory, rawAddr);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Parses a JSON object from wasm instance's memory
|
|
194
|
+
* @param {WebAssembly.Memory} memory
|
|
195
|
+
* @param {number} addr
|
|
196
|
+
* @returns {object}
|
|
197
|
+
*/
|
|
198
|
+
function _dumpJSONRaw(memory, addr) {
|
|
213
199
|
const buf = new Uint8Array(memory.buffer);
|
|
214
200
|
|
|
215
|
-
let
|
|
216
|
-
let idx = rawAddr;
|
|
201
|
+
let idx = addr;
|
|
217
202
|
|
|
218
203
|
while (buf[idx] !== 0) {
|
|
219
|
-
|
|
204
|
+
idx++;
|
|
220
205
|
}
|
|
221
206
|
|
|
222
|
-
|
|
207
|
+
const utf8View = new Uint8Array(memory.buffer, addr, idx - addr);
|
|
208
|
+
const jsonAsText = new TextDecoder().decode(utf8View);
|
|
209
|
+
|
|
210
|
+
return JSON.parse(jsonAsText);
|
|
223
211
|
}
|
|
224
212
|
|
|
225
213
|
const builtinFuncs = builtIns;
|
|
@@ -232,22 +220,21 @@ const builtinFuncs = builtIns;
|
|
|
232
220
|
* @param {{ [builtinId: number]: string }} builtins
|
|
233
221
|
* @param {string} builtin_id
|
|
234
222
|
*/
|
|
235
|
-
function _builtinCall(wasmInstance, memory, builtins,
|
|
236
|
-
const builtInName = builtins[
|
|
223
|
+
function _builtinCall(wasmInstance, memory, builtins, builtinId) {
|
|
224
|
+
const builtInName = builtins[builtinId];
|
|
237
225
|
const impl = builtinFuncs[builtInName];
|
|
238
226
|
|
|
239
227
|
if (impl === undefined) {
|
|
240
228
|
throw {
|
|
241
|
-
message:
|
|
242
|
-
|
|
243
|
-
builtin_id +
|
|
229
|
+
message: "not implemented: built-in function " +
|
|
230
|
+
builtinId +
|
|
244
231
|
": " +
|
|
245
|
-
builtins[
|
|
232
|
+
builtins[builtinId],
|
|
246
233
|
};
|
|
247
234
|
}
|
|
248
235
|
|
|
249
|
-
|
|
250
|
-
|
|
236
|
+
const argArray = Array.prototype.slice.apply(arguments);
|
|
237
|
+
const args = [];
|
|
251
238
|
|
|
252
239
|
for (let i = 4; i < argArray.length; i++) {
|
|
253
240
|
const jsArg = _dumpJSON(wasmInstance, memory, argArray[i]);
|
|
@@ -265,66 +252,97 @@ function _builtinCall(wasmInstance, memory, builtins, builtin_id) {
|
|
|
265
252
|
* It will return a Promise, depending on the input type the promise
|
|
266
253
|
* resolves to both a compiled WebAssembly.Module and its first WebAssembly.Instance
|
|
267
254
|
* or to the WebAssemblyInstance.
|
|
268
|
-
* @param {BufferSource | WebAssembly.Module}
|
|
255
|
+
* @param {BufferSource | WebAssembly.Module} policyWasm
|
|
269
256
|
* @param {WebAssembly.Memory} memory
|
|
270
|
-
* @returns {Promise<WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance>}
|
|
257
|
+
* @returns {Promise<{ policy: WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance, minorVersion: number }>}
|
|
271
258
|
*/
|
|
272
|
-
async function _loadPolicy(
|
|
259
|
+
async function _loadPolicy(policyWasm, memory) {
|
|
273
260
|
const addr2string = stringDecoder(memory);
|
|
274
261
|
|
|
275
|
-
|
|
262
|
+
const env = {};
|
|
276
263
|
|
|
277
|
-
const wasm = await WebAssembly.instantiate(
|
|
264
|
+
const wasm = await WebAssembly.instantiate(policyWasm, {
|
|
278
265
|
env: {
|
|
279
|
-
memory
|
|
266
|
+
memory,
|
|
280
267
|
opa_abort: function (addr) {
|
|
281
268
|
throw addr2string(addr);
|
|
282
269
|
},
|
|
283
270
|
opa_println: function (addr) {
|
|
284
|
-
console.log(addr2string(addr))
|
|
271
|
+
console.log(addr2string(addr));
|
|
285
272
|
},
|
|
286
|
-
opa_builtin0: function (
|
|
287
|
-
return _builtinCall(env.instance, memory, env.builtins,
|
|
273
|
+
opa_builtin0: function (builtinId, _ctx) {
|
|
274
|
+
return _builtinCall(env.instance, memory, env.builtins, builtinId);
|
|
288
275
|
},
|
|
289
|
-
opa_builtin1: function (
|
|
290
|
-
return _builtinCall(
|
|
276
|
+
opa_builtin1: function (builtinId, _ctx, arg1) {
|
|
277
|
+
return _builtinCall(
|
|
278
|
+
env.instance,
|
|
279
|
+
memory,
|
|
280
|
+
env.builtins,
|
|
281
|
+
builtinId,
|
|
282
|
+
arg1,
|
|
283
|
+
);
|
|
291
284
|
},
|
|
292
|
-
opa_builtin2: function (
|
|
285
|
+
opa_builtin2: function (builtinId, _ctx, arg1, arg2) {
|
|
293
286
|
return _builtinCall(
|
|
294
287
|
env.instance,
|
|
295
288
|
memory,
|
|
296
289
|
env.builtins,
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
290
|
+
builtinId,
|
|
291
|
+
arg1,
|
|
292
|
+
arg2,
|
|
300
293
|
);
|
|
301
294
|
},
|
|
302
|
-
opa_builtin3: function (
|
|
295
|
+
opa_builtin3: function (builtinId, _ctx, arg1, arg2, arg3) {
|
|
303
296
|
return _builtinCall(
|
|
304
297
|
env.instance,
|
|
305
298
|
memory,
|
|
306
299
|
env.builtins,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
300
|
+
builtinId,
|
|
301
|
+
arg1,
|
|
302
|
+
arg2,
|
|
303
|
+
arg3,
|
|
311
304
|
);
|
|
312
305
|
},
|
|
313
|
-
opa_builtin4: function (
|
|
306
|
+
opa_builtin4: function (builtinId, _ctx, arg1, arg2, arg3, arg4) {
|
|
314
307
|
return _builtinCall(
|
|
315
308
|
env.instance,
|
|
316
309
|
memory,
|
|
317
310
|
env.builtins,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
311
|
+
builtinId,
|
|
312
|
+
arg1,
|
|
313
|
+
arg2,
|
|
314
|
+
arg3,
|
|
315
|
+
arg4,
|
|
323
316
|
);
|
|
324
317
|
},
|
|
325
318
|
},
|
|
326
319
|
});
|
|
327
320
|
|
|
321
|
+
// Note: On Node 10.x this value is a number on Node 12.x and up it is
|
|
322
|
+
// an object with numberic `value` property.
|
|
323
|
+
const abiVersionGlobal = wasm.instance.exports.opa_wasm_abi_version;
|
|
324
|
+
if (abiVersionGlobal !== undefined) {
|
|
325
|
+
const abiVersion = typeof abiVersionGlobal === "number"
|
|
326
|
+
? abiVersionGlobal
|
|
327
|
+
: abiVersionGlobal.value;
|
|
328
|
+
if (abiVersion !== 1) {
|
|
329
|
+
throw `unsupported ABI version ${abiVersion}`;
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
console.error("opa_wasm_abi_version undefined"); // logs to stderr
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const abiMinorVersionGlobal =
|
|
336
|
+
wasm.instance.exports.opa_wasm_abi_minor_version;
|
|
337
|
+
let abiMinorVersion;
|
|
338
|
+
if (abiMinorVersionGlobal !== undefined) {
|
|
339
|
+
abiMinorVersion = typeof abiMinorVersionGlobal === "number"
|
|
340
|
+
? abiMinorVersionGlobal
|
|
341
|
+
: abiMinorVersionGlobal.value;
|
|
342
|
+
} else {
|
|
343
|
+
console.error("opa_wasm_abi_minor_version undefined");
|
|
344
|
+
}
|
|
345
|
+
|
|
328
346
|
env.instance = wasm.instance ? wasm.instance : wasm;
|
|
329
347
|
|
|
330
348
|
const builtins = _dumpJSON(
|
|
@@ -336,11 +354,11 @@ async function _loadPolicy(policy_wasm, memory) {
|
|
|
336
354
|
/** @type {typeof builtIns} */
|
|
337
355
|
env.builtins = {};
|
|
338
356
|
|
|
339
|
-
for (
|
|
357
|
+
for (const key of Object.keys(builtins)) {
|
|
340
358
|
env.builtins[builtins[key]] = key;
|
|
341
359
|
}
|
|
342
360
|
|
|
343
|
-
return wasm;
|
|
361
|
+
return { policy: wasm, minorVersion: abiMinorVersion };
|
|
344
362
|
}
|
|
345
363
|
|
|
346
364
|
/**
|
|
@@ -354,7 +372,8 @@ class LoadedPolicy {
|
|
|
354
372
|
* @param {WebAssembly.WebAssemblyInstantiatedSource} policy
|
|
355
373
|
* @param {WebAssembly.Memory} memory
|
|
356
374
|
*/
|
|
357
|
-
constructor(policy, memory) {
|
|
375
|
+
constructor(policy, memory, minorVersion) {
|
|
376
|
+
this.minorVersion = minorVersion;
|
|
358
377
|
this.mem = memory;
|
|
359
378
|
|
|
360
379
|
// Depending on how the wasm was instantiated "policy" might be a
|
|
@@ -365,15 +384,76 @@ class LoadedPolicy {
|
|
|
365
384
|
this.dataAddr = _loadJSON(this.wasmInstance, this.mem, {});
|
|
366
385
|
this.baseHeapPtr = this.wasmInstance.exports.opa_heap_ptr_get();
|
|
367
386
|
this.dataHeapPtr = this.baseHeapPtr;
|
|
387
|
+
this.entrypoints = _dumpJSON(
|
|
388
|
+
this.wasmInstance,
|
|
389
|
+
this.mem,
|
|
390
|
+
this.wasmInstance.exports.entrypoints(),
|
|
391
|
+
);
|
|
368
392
|
}
|
|
369
393
|
|
|
370
394
|
/**
|
|
371
395
|
* Evaluates the loaded policy with the given input and
|
|
372
396
|
* return the result set. This should be re-used for multiple evaluations
|
|
373
397
|
* of the same policy with different inputs.
|
|
374
|
-
*
|
|
398
|
+
*
|
|
399
|
+
* To call a non-default entrypoint in your WASM specify it as the second
|
|
400
|
+
* param. A list of entrypoints can be accessed with the `this.entrypoints`
|
|
401
|
+
* property.
|
|
402
|
+
* @param {any | ArrayBuffer} input input to be evaluated in form of `object`, literal primitive or ArrayBuffer (last is assumed to be a well-formed stringified JSON)
|
|
403
|
+
* @param {number | string} entrypoint ID or name of the entrypoint to call (optional)
|
|
375
404
|
*/
|
|
376
|
-
evaluate(input) {
|
|
405
|
+
evaluate(input, entrypoint = 0) {
|
|
406
|
+
// determine entrypoint ID
|
|
407
|
+
if (typeof entrypoint === "number") {
|
|
408
|
+
// used as-is
|
|
409
|
+
} else if (typeof entrypoint === "string") {
|
|
410
|
+
if (Object.prototype.hasOwnProperty.call(this.entrypoints, entrypoint)) {
|
|
411
|
+
entrypoint = this.entrypoints[entrypoint];
|
|
412
|
+
} else {
|
|
413
|
+
throw `entrypoint ${entrypoint} is not valid in this instance`;
|
|
414
|
+
}
|
|
415
|
+
} else {
|
|
416
|
+
throw `entrypoint value is an invalid type, must be either string or number`;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// ABI 1.2 fastpath
|
|
420
|
+
if (this.minorVersion >= 2) {
|
|
421
|
+
// write input into memory, adjust heap pointer
|
|
422
|
+
let inputBuf = null;
|
|
423
|
+
let inputLen = 0;
|
|
424
|
+
let inputAddr = 0;
|
|
425
|
+
if (input) {
|
|
426
|
+
if (input instanceof ArrayBuffer) {
|
|
427
|
+
inputBuf = new Uint8Array(input);
|
|
428
|
+
} else {
|
|
429
|
+
const inputAsText = JSON.stringify(input);
|
|
430
|
+
inputBuf = new TextEncoder().encode(inputAsText);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
inputAddr = this.dataHeapPtr;
|
|
434
|
+
inputLen = inputBuf.byteLength;
|
|
435
|
+
const delta = inputAddr + inputLen - this.mem.buffer.byteLength;
|
|
436
|
+
if (delta > 0) {
|
|
437
|
+
const pages = roundup(delta);
|
|
438
|
+
this.mem.grow(pages);
|
|
439
|
+
}
|
|
440
|
+
const buf = new Uint8Array(this.mem.buffer);
|
|
441
|
+
buf.set(inputBuf, this.dataHeapPtr);
|
|
442
|
+
this.dataHeapPtr = inputAddr + inputLen;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const ret = this.wasmInstance.exports.opa_eval(
|
|
446
|
+
0,
|
|
447
|
+
entrypoint,
|
|
448
|
+
this.dataAddr,
|
|
449
|
+
inputAddr,
|
|
450
|
+
inputLen,
|
|
451
|
+
this.dataHeapPtr,
|
|
452
|
+
0,
|
|
453
|
+
);
|
|
454
|
+
return _dumpJSONRaw(this.mem, ret);
|
|
455
|
+
}
|
|
456
|
+
|
|
377
457
|
// Reset the heap pointer before each evaluation
|
|
378
458
|
this.wasmInstance.exports.opa_heap_ptr_set(this.dataHeapPtr);
|
|
379
459
|
|
|
@@ -384,6 +464,7 @@ class LoadedPolicy {
|
|
|
384
464
|
const ctxAddr = this.wasmInstance.exports.opa_eval_ctx_new();
|
|
385
465
|
this.wasmInstance.exports.opa_eval_ctx_set_input(ctxAddr, inputAddr);
|
|
386
466
|
this.wasmInstance.exports.opa_eval_ctx_set_data(ctxAddr, this.dataAddr);
|
|
467
|
+
this.wasmInstance.exports.opa_eval_ctx_set_entrypoint(ctxAddr, entrypoint);
|
|
387
468
|
|
|
388
469
|
// Actually evaluate the policy
|
|
389
470
|
this.wasmInstance.exports.eval(ctxAddr);
|
|
@@ -396,7 +477,7 @@ class LoadedPolicy {
|
|
|
396
477
|
}
|
|
397
478
|
|
|
398
479
|
/**
|
|
399
|
-
*
|
|
480
|
+
* evalBool will evaluate the policy and return a boolean answer
|
|
400
481
|
* depending on the return code from the policy evaluation.
|
|
401
482
|
* @deprecated Use `evaluate` instead.
|
|
402
483
|
* @param {object} input
|
|
@@ -408,7 +489,7 @@ class LoadedPolicy {
|
|
|
408
489
|
|
|
409
490
|
/**
|
|
410
491
|
* Loads data for use in subsequent evaluations.
|
|
411
|
-
* @param {object} data
|
|
492
|
+
* @param {object | ArrayBuffer} data data in form of `object` or ArrayBuffer (last is assumed to be a well-formed stringified JSON)
|
|
412
493
|
*/
|
|
413
494
|
setData(data) {
|
|
414
495
|
this.wasmInstance.exports.opa_heap_ptr_set(this.baseHeapPtr);
|
|
@@ -417,19 +498,35 @@ class LoadedPolicy {
|
|
|
417
498
|
}
|
|
418
499
|
}
|
|
419
500
|
|
|
501
|
+
function roundup(bytes) {
|
|
502
|
+
const pageSize = 64 * 1024;
|
|
503
|
+
return Math.ceil(bytes / pageSize);
|
|
504
|
+
}
|
|
505
|
+
|
|
420
506
|
module.exports = {
|
|
421
507
|
/**
|
|
422
508
|
* Takes in either an ArrayBuffer or WebAssembly.Module
|
|
423
509
|
* and will return a LoadedPolicy object which can be used to evaluate
|
|
424
510
|
* the policy.
|
|
511
|
+
*
|
|
512
|
+
* To set custom memory size specify number of memory pages
|
|
513
|
+
* as second param.
|
|
514
|
+
* Defaults to 5 pages (320KB).
|
|
425
515
|
* @param {BufferSource | WebAssembly.Module} regoWasm
|
|
516
|
+
* @param {number | WebAssembly.MemoryDescriptor} memoryDescriptor For backwards-compatibility, a 'number' argument is taken to be the initial memory size.
|
|
426
517
|
*/
|
|
427
|
-
async loadPolicy(regoWasm) {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
518
|
+
async loadPolicy(regoWasm, memoryDescriptor = {}) {
|
|
519
|
+
// back-compat, second arg used to be a number: 'memorySize', with default of 5
|
|
520
|
+
if (typeof memoryDescriptor === "number") {
|
|
521
|
+
memoryDescriptor = { initial: memoryDescriptor };
|
|
522
|
+
}
|
|
523
|
+
memoryDescriptor.initial = memoryDescriptor.initial || 5;
|
|
524
|
+
|
|
525
|
+
const memory = new WebAssembly.Memory(memoryDescriptor);
|
|
526
|
+
const { policy, minorVersion } = await _loadPolicy(regoWasm, memory);
|
|
527
|
+
return new LoadedPolicy(policy, memory, minorVersion);
|
|
528
|
+
},
|
|
529
|
+
};
|
|
433
530
|
|
|
434
531
|
|
|
435
532
|
/***/ }),
|
|
@@ -29412,215 +29509,14 @@ try {
|
|
|
29412
29509
|
|
|
29413
29510
|
/***/ }),
|
|
29414
29511
|
|
|
29415
|
-
/***/
|
|
29416
|
-
/***/ ((
|
|
29512
|
+
/***/ 79264:
|
|
29513
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
29417
29514
|
|
|
29418
|
-
|
|
29419
|
-
;(function(root) {
|
|
29420
|
-
|
|
29421
|
-
var stringFromCharCode = String.fromCharCode;
|
|
29422
|
-
|
|
29423
|
-
// Taken from https://mths.be/punycode
|
|
29424
|
-
function ucs2decode(string) {
|
|
29425
|
-
var output = [];
|
|
29426
|
-
var counter = 0;
|
|
29427
|
-
var length = string.length;
|
|
29428
|
-
var value;
|
|
29429
|
-
var extra;
|
|
29430
|
-
while (counter < length) {
|
|
29431
|
-
value = string.charCodeAt(counter++);
|
|
29432
|
-
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
|
|
29433
|
-
// high surrogate, and there is a next character
|
|
29434
|
-
extra = string.charCodeAt(counter++);
|
|
29435
|
-
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
|
|
29436
|
-
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
|
29437
|
-
} else {
|
|
29438
|
-
// unmatched surrogate; only append this code unit, in case the next
|
|
29439
|
-
// code unit is the high surrogate of a surrogate pair
|
|
29440
|
-
output.push(value);
|
|
29441
|
-
counter--;
|
|
29442
|
-
}
|
|
29443
|
-
} else {
|
|
29444
|
-
output.push(value);
|
|
29445
|
-
}
|
|
29446
|
-
}
|
|
29447
|
-
return output;
|
|
29448
|
-
}
|
|
29449
|
-
|
|
29450
|
-
// Taken from https://mths.be/punycode
|
|
29451
|
-
function ucs2encode(array) {
|
|
29452
|
-
var length = array.length;
|
|
29453
|
-
var index = -1;
|
|
29454
|
-
var value;
|
|
29455
|
-
var output = '';
|
|
29456
|
-
while (++index < length) {
|
|
29457
|
-
value = array[index];
|
|
29458
|
-
if (value > 0xFFFF) {
|
|
29459
|
-
value -= 0x10000;
|
|
29460
|
-
output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
|
|
29461
|
-
value = 0xDC00 | value & 0x3FF;
|
|
29462
|
-
}
|
|
29463
|
-
output += stringFromCharCode(value);
|
|
29464
|
-
}
|
|
29465
|
-
return output;
|
|
29466
|
-
}
|
|
29467
|
-
|
|
29468
|
-
function checkScalarValue(codePoint) {
|
|
29469
|
-
if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
|
|
29470
|
-
throw Error(
|
|
29471
|
-
'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
|
|
29472
|
-
' is not a scalar value'
|
|
29473
|
-
);
|
|
29474
|
-
}
|
|
29475
|
-
}
|
|
29476
|
-
/*--------------------------------------------------------------------------*/
|
|
29477
|
-
|
|
29478
|
-
function createByte(codePoint, shift) {
|
|
29479
|
-
return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
|
|
29480
|
-
}
|
|
29481
|
-
|
|
29482
|
-
function encodeCodePoint(codePoint) {
|
|
29483
|
-
if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
|
|
29484
|
-
return stringFromCharCode(codePoint);
|
|
29485
|
-
}
|
|
29486
|
-
var symbol = '';
|
|
29487
|
-
if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
|
|
29488
|
-
symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
|
|
29489
|
-
}
|
|
29490
|
-
else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
|
|
29491
|
-
checkScalarValue(codePoint);
|
|
29492
|
-
symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
|
|
29493
|
-
symbol += createByte(codePoint, 6);
|
|
29494
|
-
}
|
|
29495
|
-
else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
|
|
29496
|
-
symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
|
|
29497
|
-
symbol += createByte(codePoint, 12);
|
|
29498
|
-
symbol += createByte(codePoint, 6);
|
|
29499
|
-
}
|
|
29500
|
-
symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
|
|
29501
|
-
return symbol;
|
|
29502
|
-
}
|
|
29503
|
-
|
|
29504
|
-
function utf8encode(string) {
|
|
29505
|
-
var codePoints = ucs2decode(string);
|
|
29506
|
-
var length = codePoints.length;
|
|
29507
|
-
var index = -1;
|
|
29508
|
-
var codePoint;
|
|
29509
|
-
var byteString = '';
|
|
29510
|
-
while (++index < length) {
|
|
29511
|
-
codePoint = codePoints[index];
|
|
29512
|
-
byteString += encodeCodePoint(codePoint);
|
|
29513
|
-
}
|
|
29514
|
-
return byteString;
|
|
29515
|
-
}
|
|
29516
|
-
|
|
29517
|
-
/*--------------------------------------------------------------------------*/
|
|
29518
|
-
|
|
29519
|
-
function readContinuationByte() {
|
|
29520
|
-
if (byteIndex >= byteCount) {
|
|
29521
|
-
throw Error('Invalid byte index');
|
|
29522
|
-
}
|
|
29523
|
-
|
|
29524
|
-
var continuationByte = byteArray[byteIndex] & 0xFF;
|
|
29525
|
-
byteIndex++;
|
|
29526
|
-
|
|
29527
|
-
if ((continuationByte & 0xC0) == 0x80) {
|
|
29528
|
-
return continuationByte & 0x3F;
|
|
29529
|
-
}
|
|
29530
|
-
|
|
29531
|
-
// If we end up here, it’s not a continuation byte
|
|
29532
|
-
throw Error('Invalid continuation byte');
|
|
29533
|
-
}
|
|
29534
|
-
|
|
29535
|
-
function decodeSymbol() {
|
|
29536
|
-
var byte1;
|
|
29537
|
-
var byte2;
|
|
29538
|
-
var byte3;
|
|
29539
|
-
var byte4;
|
|
29540
|
-
var codePoint;
|
|
29541
|
-
|
|
29542
|
-
if (byteIndex > byteCount) {
|
|
29543
|
-
throw Error('Invalid byte index');
|
|
29544
|
-
}
|
|
29545
|
-
|
|
29546
|
-
if (byteIndex == byteCount) {
|
|
29547
|
-
return false;
|
|
29548
|
-
}
|
|
29549
|
-
|
|
29550
|
-
// Read first byte
|
|
29551
|
-
byte1 = byteArray[byteIndex] & 0xFF;
|
|
29552
|
-
byteIndex++;
|
|
29553
|
-
|
|
29554
|
-
// 1-byte sequence (no continuation bytes)
|
|
29555
|
-
if ((byte1 & 0x80) == 0) {
|
|
29556
|
-
return byte1;
|
|
29557
|
-
}
|
|
29558
|
-
|
|
29559
|
-
// 2-byte sequence
|
|
29560
|
-
if ((byte1 & 0xE0) == 0xC0) {
|
|
29561
|
-
byte2 = readContinuationByte();
|
|
29562
|
-
codePoint = ((byte1 & 0x1F) << 6) | byte2;
|
|
29563
|
-
if (codePoint >= 0x80) {
|
|
29564
|
-
return codePoint;
|
|
29565
|
-
} else {
|
|
29566
|
-
throw Error('Invalid continuation byte');
|
|
29567
|
-
}
|
|
29568
|
-
}
|
|
29569
|
-
|
|
29570
|
-
// 3-byte sequence (may include unpaired surrogates)
|
|
29571
|
-
if ((byte1 & 0xF0) == 0xE0) {
|
|
29572
|
-
byte2 = readContinuationByte();
|
|
29573
|
-
byte3 = readContinuationByte();
|
|
29574
|
-
codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
|
|
29575
|
-
if (codePoint >= 0x0800) {
|
|
29576
|
-
checkScalarValue(codePoint);
|
|
29577
|
-
return codePoint;
|
|
29578
|
-
} else {
|
|
29579
|
-
throw Error('Invalid continuation byte');
|
|
29580
|
-
}
|
|
29581
|
-
}
|
|
29582
|
-
|
|
29583
|
-
// 4-byte sequence
|
|
29584
|
-
if ((byte1 & 0xF8) == 0xF0) {
|
|
29585
|
-
byte2 = readContinuationByte();
|
|
29586
|
-
byte3 = readContinuationByte();
|
|
29587
|
-
byte4 = readContinuationByte();
|
|
29588
|
-
codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
|
|
29589
|
-
(byte3 << 0x06) | byte4;
|
|
29590
|
-
if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
|
|
29591
|
-
return codePoint;
|
|
29592
|
-
}
|
|
29593
|
-
}
|
|
29594
|
-
|
|
29595
|
-
throw Error('Invalid UTF-8 detected');
|
|
29596
|
-
}
|
|
29597
|
-
|
|
29598
|
-
var byteArray;
|
|
29599
|
-
var byteCount;
|
|
29600
|
-
var byteIndex;
|
|
29601
|
-
function utf8decode(byteString) {
|
|
29602
|
-
byteArray = ucs2decode(byteString);
|
|
29603
|
-
byteCount = byteArray.length;
|
|
29604
|
-
byteIndex = 0;
|
|
29605
|
-
var codePoints = [];
|
|
29606
|
-
var tmp;
|
|
29607
|
-
while ((tmp = decodeSymbol()) !== false) {
|
|
29608
|
-
codePoints.push(tmp);
|
|
29609
|
-
}
|
|
29610
|
-
return ucs2encode(codePoints);
|
|
29611
|
-
}
|
|
29612
|
-
|
|
29613
|
-
/*--------------------------------------------------------------------------*/
|
|
29614
|
-
|
|
29615
|
-
root.version = '3.0.0';
|
|
29616
|
-
root.encode = utf8encode;
|
|
29617
|
-
root.decode = utf8decode;
|
|
29618
|
-
|
|
29619
|
-
}( false ? 0 : exports));
|
|
29515
|
+
module.exports = __webpack_require__(39026);
|
|
29620
29516
|
|
|
29621
29517
|
|
|
29622
29518
|
/***/ })
|
|
29623
29519
|
|
|
29624
29520
|
};
|
|
29625
29521
|
;
|
|
29626
|
-
//# sourceMappingURL=
|
|
29522
|
+
//# sourceMappingURL=55.index.js.map
|