querysub 0.167.0 → 0.168.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/package.json
CHANGED
|
@@ -1088,68 +1088,63 @@ export class PathValueProxyWatcher {
|
|
|
1088
1088
|
try {
|
|
1089
1089
|
let rawResult: Result;
|
|
1090
1090
|
const handling = watcher.options.nestedCalls;
|
|
1091
|
+
let curFunction = baseFunction;
|
|
1091
1092
|
if (handling === "inline") {
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
if (PathValueProxyWatcher.BREAK_ON_CALL.has(hash)) {
|
|
1103
|
-
const unwatch = () => removeMatches(PathValueProxyWatcher.BREAK_ON_CALL, hash);
|
|
1104
|
-
debugger;
|
|
1105
|
-
unwatch;
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
if (!watcher.options.canWrite) {
|
|
1109
|
-
throw new Error(`Cannot call a synced function in a watcher which does not have write permissions. If you want to call a function, you must also have write permissions.`);
|
|
1093
|
+
curFunction = () => inlineNestedCalls(baseFunction);
|
|
1094
|
+
}
|
|
1095
|
+
rawResult = interceptCalls({
|
|
1096
|
+
onCall(call, metadata) {
|
|
1097
|
+
if (PathValueProxyWatcher.BREAK_ON_CALL.size > 0 && !watcher.hasAnyUnsyncedAccesses()) {
|
|
1098
|
+
let hash = getPathStr2(call.ModuleId, call.FunctionId);
|
|
1099
|
+
if (PathValueProxyWatcher.BREAK_ON_CALL.has(hash)) {
|
|
1100
|
+
const unwatch = () => removeMatches(PathValueProxyWatcher.BREAK_ON_CALL, hash);
|
|
1101
|
+
debugger;
|
|
1102
|
+
unwatch;
|
|
1110
1103
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1104
|
+
}
|
|
1105
|
+
if (!watcher.options.canWrite) {
|
|
1106
|
+
throw new Error(`Cannot call a synced function in a watcher which does not have write permissions. If you want to call a function, you must also have write permissions.`);
|
|
1107
|
+
}
|
|
1108
|
+
if (handling === "throw") {
|
|
1109
|
+
// TODO: Support making inline calls, which is useful as it will check permissions. Although, it can
|
|
1110
|
+
// easily be slow, and adds a lot of complexity, so... maybe not... maybe always force the app
|
|
1111
|
+
// to do the permissions checks if they want them
|
|
1112
|
+
throw new Error(`Nested synced function calls are not allowed. Call the function directly, or use Querysub.onCommitFinished to wait for the function to finish.`);
|
|
1113
|
+
} else if (handling === "after" || handling === undefined) {
|
|
1114
|
+
|
|
1115
|
+
// We need to wait for predictions to finish, otherwise we run into situations
|
|
1116
|
+
// where we call a function which should change a parameter we want to pass
|
|
1117
|
+
// to another function, but because the first call didn't predict, the second
|
|
1118
|
+
// call gets a different values, causing all kinds of issues.
|
|
1119
|
+
if (watcher.pendingCalls.length === 0) {
|
|
1120
|
+
let waitPromise = onAllPredictionsFinished();
|
|
1121
|
+
if (waitPromise) {
|
|
1122
|
+
proxyWatcher.triggerOnPromiseFinish(waitPromise, {
|
|
1123
|
+
waitReason: "Waiting for predictions to finish",
|
|
1124
|
+
});
|
|
1129
1125
|
}
|
|
1130
|
-
|
|
1131
|
-
watcher.pendingCalls.push({ call, metadata });
|
|
1132
|
-
} else if (handling === "ignore") {
|
|
1133
|
-
} else {
|
|
1134
|
-
let unhandled: never = handling;
|
|
1135
|
-
throw new Error(`Invalid handling type ${handling}`);
|
|
1136
1126
|
}
|
|
1137
|
-
},
|
|
1138
|
-
code() {
|
|
1139
|
-
return authorityStorage.temporaryOverride(options.overrides, () =>
|
|
1140
|
-
runCodeWithDatabase(proxy, baseFunction)
|
|
1141
|
-
);
|
|
1142
|
-
},
|
|
1143
|
-
}) as Result;
|
|
1144
|
-
}
|
|
1145
1127
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1128
|
+
watcher.pendingCalls.push({ call, metadata });
|
|
1129
|
+
} else if (handling === "ignore") {
|
|
1130
|
+
} else if (handling === "inline") {
|
|
1131
|
+
throw new Error(`inlineNestedCalls should have prevented this call from being passed to us`);
|
|
1132
|
+
} else {
|
|
1133
|
+
let unhandled: never = handling;
|
|
1134
|
+
throw new Error(`Invalid handling type ${handling}`);
|
|
1135
|
+
}
|
|
1136
|
+
},
|
|
1137
|
+
code() {
|
|
1138
|
+
return authorityStorage.temporaryOverride(options.overrides, () =>
|
|
1139
|
+
runCodeWithDatabase(proxy, baseFunction)
|
|
1140
|
+
);
|
|
1141
|
+
},
|
|
1142
|
+
}) as Result;
|
|
1143
|
+
|
|
1144
|
+
// NOTE: Always deep clone. It's too confusing for a partial object to be returned. Any issues caused by
|
|
1145
|
+
// this (aka, returning the entire database), would also happen if we manually added deep clones before
|
|
1146
|
+
// we returned values (and both should be throttled at a framework level so we don't break the database).
|
|
1147
|
+
rawResult = deepCloneCborx(rawResult);
|
|
1153
1148
|
|
|
1154
1149
|
result = { result: rawResult };
|
|
1155
1150
|
watcher.consecutiveErrors = 0;
|