Skip to content

Commit 4dafa50

Browse files
committed
improve some comments, remove unused properties from magic state shim in node API
1 parent 53e6983 commit 4dafa50

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

src/node/NodeRecipe.mjs

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ class NodeRecipe {
2424

2525

2626
/**
27-
* Validate an ingredient $ coerce to operation if necessary.
27+
* Validate an ingredient & coerce to operation if necessary.
2828
* @param {String | Function | Object} ing
29+
* @returns {Function || Object} The operation, or an object with the
30+
* operation and its arguments
31+
* @throws {TypeError} If it cannot find the operation in chef's list of operations.
2932
*/
3033
_validateIngredient(ing) {
3134
// CASE operation name given. Find operation and validate
@@ -34,14 +37,15 @@ class NodeRecipe {
3437
return sanitise(op.opName) === sanitise(ing);
3538
});
3639
if (op) {
40+
// Need to validate against case 2
3741
return this._validateIngredient(op);
3842
} else {
3943
throw new TypeError(`Couldn't find an operation with name '${ing}'.`);
4044
}
4145
// CASE operation given. Check its a chef operation and check its not flowcontrol
4246
} else if (typeof ing === "function") {
4347
if (ing.flowControl) {
44-
throw new TypeError(`flowControl operations like ${ing.opName} are not currently allowed in recipes for chef.bake`);
48+
throw new TypeError(`flowControl operations like ${ing.opName} are not currently allowed in recipes for chef.bake in the Node API`);
4549
}
4650

4751
if (operations.includes(ing)) {
@@ -63,7 +67,7 @@ class NodeRecipe {
6367

6468

6569
/**
66-
* Parse config for recipe.
70+
* Parse an opList from a recipeConfig and assign it to the recipe's opList.
6771
* @param {String | Function | String[] | Function[] | [String | Function]} recipeConfig
6872
*/
6973
_parseConfig(recipeConfig) {

src/node/api.mjs

+4-7
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,14 @@ export function _wrap(OpClass) {
194194
const {transformedInput, transformedArgs} = prepareOp(opInstance, input, args);
195195

196196
// SPECIAL CASE for Magic. Other flowControl operations will
197-
// not work because the opList is not passed through.
197+
// not work because the opList is not passed in.
198198
if (isFlowControl) {
199199
opInstance.ingValues = transformedArgs;
200200

201201
const state = {
202-
"progress": 0,
203-
"dish": ensureIsDish(transformedInput),
204-
"opList": [opInstance],
205-
"numJumps": 0,
206-
"numRegisters": 0,
207-
"forkOffset": 0
202+
progress: 0,
203+
dish: ensureIsDish(transformedInput),
204+
opList: [opInstance],
208205
};
209206

210207
const updatedState = await opInstance.run(state);

tests/node/tests/nodeApi.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,15 @@ TestRegister.addApiTests([
348348
it("chef.bake: cannot accept flowControl operations in recipe", () => {
349349
assert.throws(() => chef.bake("some input", "magic"), {
350350
name: "TypeError",
351-
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake"
351+
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
352352
});
353353
assert.throws(() => chef.bake("some input", magic), {
354354
name: "TypeError",
355-
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake"
355+
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
356356
});
357357
assert.throws(() => chef.bake("some input", ["to base 64", "magic"]), {
358358
name: "TypeError",
359-
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake"
359+
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
360360
});
361361
}),
362362

tests/node/tests/operations.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,10 @@ ExifImageHeight: 57`);
10771077

10781078
it("performs MAGIC", async () => {
10791079
const input = "WUagwsiae6mP8gNtCCLUFpCpCB26RmBDoDD8PacdAmzAzBVjkK2QstFXaKhpC6iUS7RHqXrJtFisoRSgoJ4whjm1arm864qaNq4RcfUmLHrcsAaZc5TXCYifNdgS83gDeejGX46gaiMyuBV6EskHt1scgJ88x2tNSotQDwbGY1mmCob2ARGFvCKYNqiN9ipMq1ZU1mgkdbNuGcb76aRtYWhCGUc8g93UJudhb8htsheZnwTpgqhx83SVJSZXMXUjJT2zmpC7uXWtumqokbdSi88YtkWDAc1Toouh2oH4D4ddmNKJWUDpMwmngUmK14xwmomccPQE9hM172APnSqwxdKQ172RkcAsysnmj5gGtRmVNNh2s359wr6mS2QRP";
1080-
const depth = 3;
1080+
const depth = 1;
10811081

10821082
const res = await chef.magic(input, {
1083-
depth: 3
1083+
depth,
10841084
});
10851085

10861086
// assert against the structure of the output, rather than the values.

0 commit comments

Comments
 (0)