improve some comments, remove unused properties from magic state shim in node API
This commit is contained in:
parent
53e69835ff
commit
4dafa50799
@ -24,8 +24,11 @@ class NodeRecipe {
|
||||
|
||||
|
||||
/**
|
||||
* Validate an ingredient $ coerce to operation if necessary.
|
||||
* Validate an ingredient & coerce to operation if necessary.
|
||||
* @param {String | Function | Object} ing
|
||||
* @returns {Function || Object} The operation, or an object with the
|
||||
* operation and its arguments
|
||||
* @throws {TypeError} If it cannot find the operation in chef's list of operations.
|
||||
*/
|
||||
_validateIngredient(ing) {
|
||||
// CASE operation name given. Find operation and validate
|
||||
@ -34,6 +37,7 @@ class NodeRecipe {
|
||||
return sanitise(op.opName) === sanitise(ing);
|
||||
});
|
||||
if (op) {
|
||||
// Need to validate against case 2
|
||||
return this._validateIngredient(op);
|
||||
} else {
|
||||
throw new TypeError(`Couldn't find an operation with name '${ing}'.`);
|
||||
@ -41,7 +45,7 @@ class NodeRecipe {
|
||||
// CASE operation given. Check its a chef operation and check its not flowcontrol
|
||||
} else if (typeof ing === "function") {
|
||||
if (ing.flowControl) {
|
||||
throw new TypeError(`flowControl operations like ${ing.opName} are not currently allowed in recipes for chef.bake`);
|
||||
throw new TypeError(`flowControl operations like ${ing.opName} are not currently allowed in recipes for chef.bake in the Node API`);
|
||||
}
|
||||
|
||||
if (operations.includes(ing)) {
|
||||
@ -63,7 +67,7 @@ class NodeRecipe {
|
||||
|
||||
|
||||
/**
|
||||
* Parse config for recipe.
|
||||
* Parse an opList from a recipeConfig and assign it to the recipe's opList.
|
||||
* @param {String | Function | String[] | Function[] | [String | Function]} recipeConfig
|
||||
*/
|
||||
_parseConfig(recipeConfig) {
|
||||
|
@ -194,17 +194,14 @@ export function _wrap(OpClass) {
|
||||
const {transformedInput, transformedArgs} = prepareOp(opInstance, input, args);
|
||||
|
||||
// SPECIAL CASE for Magic. Other flowControl operations will
|
||||
// not work because the opList is not passed through.
|
||||
// not work because the opList is not passed in.
|
||||
if (isFlowControl) {
|
||||
opInstance.ingValues = transformedArgs;
|
||||
|
||||
const state = {
|
||||
"progress": 0,
|
||||
"dish": ensureIsDish(transformedInput),
|
||||
"opList": [opInstance],
|
||||
"numJumps": 0,
|
||||
"numRegisters": 0,
|
||||
"forkOffset": 0
|
||||
progress: 0,
|
||||
dish: ensureIsDish(transformedInput),
|
||||
opList: [opInstance],
|
||||
};
|
||||
|
||||
const updatedState = await opInstance.run(state);
|
||||
|
@ -348,15 +348,15 @@ TestRegister.addApiTests([
|
||||
it("chef.bake: cannot accept flowControl operations in recipe", () => {
|
||||
assert.throws(() => chef.bake("some input", "magic"), {
|
||||
name: "TypeError",
|
||||
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake"
|
||||
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
|
||||
});
|
||||
assert.throws(() => chef.bake("some input", magic), {
|
||||
name: "TypeError",
|
||||
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake"
|
||||
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
|
||||
});
|
||||
assert.throws(() => chef.bake("some input", ["to base 64", "magic"]), {
|
||||
name: "TypeError",
|
||||
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake"
|
||||
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
|
||||
});
|
||||
}),
|
||||
|
||||
|
@ -1077,10 +1077,10 @@ ExifImageHeight: 57`);
|
||||
|
||||
it("performs MAGIC", async () => {
|
||||
const input = "WUagwsiae6mP8gNtCCLUFpCpCB26RmBDoDD8PacdAmzAzBVjkK2QstFXaKhpC6iUS7RHqXrJtFisoRSgoJ4whjm1arm864qaNq4RcfUmLHrcsAaZc5TXCYifNdgS83gDeejGX46gaiMyuBV6EskHt1scgJ88x2tNSotQDwbGY1mmCob2ARGFvCKYNqiN9ipMq1ZU1mgkdbNuGcb76aRtYWhCGUc8g93UJudhb8htsheZnwTpgqhx83SVJSZXMXUjJT2zmpC7uXWtumqokbdSi88YtkWDAc1Toouh2oH4D4ddmNKJWUDpMwmngUmK14xwmomccPQE9hM172APnSqwxdKQ172RkcAsysnmj5gGtRmVNNh2s359wr6mS2QRP";
|
||||
const depth = 3;
|
||||
const depth = 1;
|
||||
|
||||
const res = await chef.magic(input, {
|
||||
depth: 3
|
||||
depth,
|
||||
});
|
||||
|
||||
// assert against the structure of the output, rather than the values.
|
||||
|
Loading…
x
Reference in New Issue
Block a user