@absolutejs/sync 1.11.0 → 1.12.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.
@@ -1136,7 +1136,7 @@ var wrap = (source) => `
1136
1136
  const userFn = (${source});
1137
1137
  if (typeof userFn !== 'function') {
1138
1138
  throw new Error(
1139
- 'sandboxedHandler must evaluate to (args, ctx, actions) => result; got ' +
1139
+ 'sandboxedHandler must evaluate to (args, ctx, actions, unsafeHost) => result; got ' +
1140
1140
  typeof userFn
1141
1141
  );
1142
1142
  }
@@ -1148,12 +1148,24 @@ var wrap = (source) => `
1148
1148
  now: () => __dispatch(__callId, 'now'),
1149
1149
  fetch: (url, init) => __dispatch(__callId, 'fetch', url, init)
1150
1150
  };
1151
- return userFn(args, ctx, actions);
1151
+ // Escape hatch \u2014 host fns the mutation explicitly opted in to.
1152
+ // The Proxy means every property access is a host call; the
1153
+ // engine throws if the property name isn't declared in the
1154
+ // mutation's sandbox.unsafeHost map.
1155
+ const unsafeHost = new Proxy({}, {
1156
+ get: (_target, fnName) => {
1157
+ if (typeof fnName !== 'string') return undefined;
1158
+ return (...callArgs) =>
1159
+ __dispatch(__callId, 'unsafeHost', fnName, callArgs);
1160
+ }
1161
+ });
1162
+ return userFn(args, ctx, actions, unsafeHost);
1152
1163
  }
1153
1164
  `;
1154
1165
  var compile = async (source, config, bridgeFetch) => {
1155
1166
  const { Reference, createIsolatedRunner, resolveIsolatePolicy } = await loadIsolatedJsc();
1156
1167
  const callMap = new Map;
1168
+ const unsafeHost = config.unsafeHost;
1157
1169
  const dispatch = new Reference((callId, op, ...rest) => {
1158
1170
  const a = callMap.get(callId);
1159
1171
  if (a === undefined) {
@@ -1172,6 +1184,14 @@ var compile = async (source, config, bridgeFetch) => {
1172
1184
  return a.now();
1173
1185
  case "fetch":
1174
1186
  return runBridgeFetch(bridgeFetch, rest[0], rest[1]);
1187
+ case "unsafeHost": {
1188
+ const fnName = rest[0];
1189
+ const callArgs = rest[1] ?? [];
1190
+ if (unsafeHost === undefined || typeof unsafeHost[fnName] !== "function") {
1191
+ 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.`);
1192
+ }
1193
+ return unsafeHost[fnName](...callArgs);
1194
+ }
1175
1195
  default:
1176
1196
  throw new Error(`unknown sandbox action op: ${String(op)}`);
1177
1197
  }
@@ -3140,5 +3160,5 @@ export {
3140
3160
  CdcConsumerSlowError
3141
3161
  };
3142
3162
 
3143
- //# debugId=C14BF50A13D2477E64756E2164756E21
3163
+ //# debugId=5C3B639DC6FB356064756E2164756E21
3144
3164
  //# sourceMappingURL=index.js.map