@absolutejs/sync 1.11.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine/index.js +25 -4
- package/dist/engine/index.js.map +4 -4
- package/dist/engine/sandbox.d.ts +46 -0
- package/dist/index.js +29 -6
- package/dist/index.js.map +6 -6
- package/dist/testing.js +23 -3
- package/dist/testing.js.map +3 -3
- package/package.json +1 -1
package/dist/testing.js
CHANGED
|
@@ -318,7 +318,7 @@ var wrap = (source) => `
|
|
|
318
318
|
const userFn = (${source});
|
|
319
319
|
if (typeof userFn !== 'function') {
|
|
320
320
|
throw new Error(
|
|
321
|
-
'sandboxedHandler must evaluate to (args, ctx, actions) => result; got ' +
|
|
321
|
+
'sandboxedHandler must evaluate to (args, ctx, actions, unsafeHost) => result; got ' +
|
|
322
322
|
typeof userFn
|
|
323
323
|
);
|
|
324
324
|
}
|
|
@@ -330,12 +330,24 @@ var wrap = (source) => `
|
|
|
330
330
|
now: () => __dispatch(__callId, 'now'),
|
|
331
331
|
fetch: (url, init) => __dispatch(__callId, 'fetch', url, init)
|
|
332
332
|
};
|
|
333
|
-
|
|
333
|
+
// Escape hatch \u2014 host fns the mutation explicitly opted in to.
|
|
334
|
+
// The Proxy means every property access is a host call; the
|
|
335
|
+
// engine throws if the property name isn't declared in the
|
|
336
|
+
// mutation's sandbox.unsafeHost map.
|
|
337
|
+
const unsafeHost = new Proxy({}, {
|
|
338
|
+
get: (_target, fnName) => {
|
|
339
|
+
if (typeof fnName !== 'string') return undefined;
|
|
340
|
+
return (...callArgs) =>
|
|
341
|
+
__dispatch(__callId, 'unsafeHost', fnName, callArgs);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
return userFn(args, ctx, actions, unsafeHost);
|
|
334
345
|
}
|
|
335
346
|
`;
|
|
336
347
|
var compile = async (source, config, bridgeFetch) => {
|
|
337
348
|
const { Reference, createIsolatedRunner, resolveIsolatePolicy } = await loadIsolatedJsc();
|
|
338
349
|
const callMap = new Map;
|
|
350
|
+
const unsafeHost = config.unsafeHost;
|
|
339
351
|
const dispatch = new Reference((callId, op, ...rest) => {
|
|
340
352
|
const a = callMap.get(callId);
|
|
341
353
|
if (a === undefined) {
|
|
@@ -354,6 +366,14 @@ var compile = async (source, config, bridgeFetch) => {
|
|
|
354
366
|
return a.now();
|
|
355
367
|
case "fetch":
|
|
356
368
|
return runBridgeFetch(bridgeFetch, rest[0], rest[1]);
|
|
369
|
+
case "unsafeHost": {
|
|
370
|
+
const fnName = rest[0];
|
|
371
|
+
const callArgs = rest[1] ?? [];
|
|
372
|
+
if (unsafeHost === undefined || typeof unsafeHost[fnName] !== "function") {
|
|
373
|
+
throw new Error(`sandboxedHandler called unsafeHost.${fnName}() but it was not declared in the mutation's sandbox.unsafeHost config. Declare it (and only the host fns you intend to expose) to opt in to the escape hatch.`);
|
|
374
|
+
}
|
|
375
|
+
return unsafeHost[fnName](...callArgs);
|
|
376
|
+
}
|
|
357
377
|
default:
|
|
358
378
|
throw new Error(`unknown sandbox action op: ${String(op)}`);
|
|
359
379
|
}
|
|
@@ -1983,5 +2003,5 @@ export {
|
|
|
1983
2003
|
createTestEngine
|
|
1984
2004
|
};
|
|
1985
2005
|
|
|
1986
|
-
//# debugId=
|
|
2006
|
+
//# debugId=E33DC349D71B8BBE64756E2164756E21
|
|
1987
2007
|
//# sourceMappingURL=testing.js.map
|