@absolutejs/sync 1.7.3 → 1.7.5
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 +32 -59
- package/dist/engine/index.js.map +3 -3
- package/dist/engine/sandbox.d.ts +30 -25
- package/dist/index.js +32 -59
- package/dist/index.js.map +3 -3
- package/package.json +3 -3
package/dist/engine/index.js
CHANGED
|
@@ -1093,7 +1093,7 @@ var loadIsolatedJsc = async () => {
|
|
|
1093
1093
|
}
|
|
1094
1094
|
};
|
|
1095
1095
|
var wrap = (source) => `
|
|
1096
|
-
(
|
|
1096
|
+
function (__callId, args, ctx) {
|
|
1097
1097
|
const userFn = (${source});
|
|
1098
1098
|
if (typeof userFn !== 'function') {
|
|
1099
1099
|
throw new Error(
|
|
@@ -1102,20 +1102,26 @@ var wrap = (source) => `
|
|
|
1102
1102
|
);
|
|
1103
1103
|
}
|
|
1104
1104
|
const actions = {
|
|
1105
|
-
insert: (table, data) =>
|
|
1106
|
-
update: (table, data) =>
|
|
1107
|
-
delete: (table, row) =>
|
|
1108
|
-
change: (collection, change) =>
|
|
1105
|
+
insert: (table, data) => __dispatch(__callId, 'insert', table, data),
|
|
1106
|
+
update: (table, data) => __dispatch(__callId, 'update', table, data),
|
|
1107
|
+
delete: (table, row) => __dispatch(__callId, 'delete', table, row),
|
|
1108
|
+
change: (collection, change) => __dispatch(__callId, 'change', collection, change)
|
|
1109
1109
|
};
|
|
1110
1110
|
return userFn(args, ctx, actions);
|
|
1111
|
-
}
|
|
1111
|
+
}
|
|
1112
1112
|
`;
|
|
1113
|
-
var
|
|
1114
|
-
|
|
1115
|
-
const
|
|
1116
|
-
|
|
1113
|
+
var compile = async (source, config) => {
|
|
1114
|
+
const { createIsolate, Reference } = await loadIsolatedJsc();
|
|
1115
|
+
const isolate = await createIsolate({
|
|
1116
|
+
backend: config.backend ?? "auto",
|
|
1117
|
+
memoryLimit: config.memoryLimit ?? 32
|
|
1118
|
+
});
|
|
1119
|
+
const context = await isolate.createContext();
|
|
1120
|
+
const callMap = new Map;
|
|
1121
|
+
const dispatch = new Reference((callId, op, ...rest) => {
|
|
1122
|
+
const a = callMap.get(callId);
|
|
1117
1123
|
if (a === undefined) {
|
|
1118
|
-
throw new Error(
|
|
1124
|
+
throw new Error(`__dispatch invoked for orphan callId ${String(callId)}`);
|
|
1119
1125
|
}
|
|
1120
1126
|
switch (op) {
|
|
1121
1127
|
case "insert":
|
|
@@ -1130,27 +1136,14 @@ var installRouter = async (context, currentActions, Reference) => {
|
|
|
1130
1136
|
throw new Error(`unknown sandbox action op: ${String(op)}`);
|
|
1131
1137
|
}
|
|
1132
1138
|
});
|
|
1133
|
-
await context.setGlobal("
|
|
1134
|
-
|
|
1135
|
-
var compile = async (source, config) => {
|
|
1136
|
-
const { createIsolate, Reference } = await loadIsolatedJsc();
|
|
1137
|
-
const isolate = await createIsolate({
|
|
1138
|
-
backend: config.backend ?? "auto",
|
|
1139
|
-
memoryLimit: config.memoryLimit ?? 32
|
|
1140
|
-
});
|
|
1141
|
-
const script = await isolate.compileScript(wrap(source));
|
|
1142
|
-
const context = await isolate.createContext();
|
|
1143
|
-
const currentActions = {
|
|
1144
|
-
value: undefined
|
|
1145
|
-
};
|
|
1146
|
-
await installRouter(context, currentActions, Reference);
|
|
1139
|
+
await context.setGlobal("__dispatch", dispatch);
|
|
1140
|
+
const callable = await context.compileCallable(wrap(source));
|
|
1147
1141
|
return {
|
|
1142
|
+
callable,
|
|
1143
|
+
callMap,
|
|
1148
1144
|
context,
|
|
1149
|
-
currentActions,
|
|
1150
1145
|
isolate,
|
|
1151
|
-
|
|
1152
|
-
script,
|
|
1153
|
-
servedCalls: 0,
|
|
1146
|
+
nextCallId: 1,
|
|
1154
1147
|
timeoutMs: config.timeout ?? 5000
|
|
1155
1148
|
};
|
|
1156
1149
|
};
|
|
@@ -1166,37 +1159,17 @@ var makeSandboxedHandler = (source, config = {}) => {
|
|
|
1166
1159
|
pending = compile(source, config);
|
|
1167
1160
|
return pending;
|
|
1168
1161
|
};
|
|
1169
|
-
const recycleContextIfNeeded = async (compiled) => {
|
|
1170
|
-
if (compiled.servedCalls < DEFAULT_RECYCLE_CONTEXT_AFTER)
|
|
1171
|
-
return;
|
|
1172
|
-
const { Reference } = await loadIsolatedJsc();
|
|
1173
|
-
await compiled.context.dispose().catch(() => {});
|
|
1174
|
-
compiled.context = await compiled.isolate.createContext();
|
|
1175
|
-
await installRouter(compiled.context, compiled.currentActions, Reference);
|
|
1176
|
-
compiled.servedCalls = 0;
|
|
1177
|
-
};
|
|
1178
1162
|
return async (args, ctx, actions) => {
|
|
1179
1163
|
const compiled = await getCompiled();
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
compiled.
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
});
|
|
1190
|
-
return result;
|
|
1191
|
-
} finally {
|
|
1192
|
-
compiled.currentActions.value = undefined;
|
|
1193
|
-
compiled.servedCalls += 1;
|
|
1194
|
-
}
|
|
1195
|
-
});
|
|
1196
|
-
compiled.runQueue = turn.catch(() => {
|
|
1197
|
-
return;
|
|
1198
|
-
});
|
|
1199
|
-
return turn;
|
|
1164
|
+
const callId = compiled.nextCallId++;
|
|
1165
|
+
compiled.callMap.set(callId, actions);
|
|
1166
|
+
try {
|
|
1167
|
+
return await compiled.callable.call([callId, args, ctx], {
|
|
1168
|
+
timeout: compiled.timeoutMs
|
|
1169
|
+
});
|
|
1170
|
+
} finally {
|
|
1171
|
+
compiled.callMap.delete(callId);
|
|
1172
|
+
}
|
|
1200
1173
|
};
|
|
1201
1174
|
};
|
|
1202
1175
|
|
|
@@ -2811,5 +2784,5 @@ export {
|
|
|
2811
2784
|
CdcConsumerSlowError
|
|
2812
2785
|
};
|
|
2813
2786
|
|
|
2814
|
-
//# debugId=
|
|
2787
|
+
//# debugId=8D6F90BB348646A664756E2164756E21
|
|
2815
2788
|
//# sourceMappingURL=index.js.map
|