Joe's Friction Log (Archived) #1173
Replies: 7 comments 7 replies
-
While working on OpenAlex boards, I wanted to reuse the
related: |
Beta Was this translation helpful? Give feedback.
-
noticed an issue with controlling flow of the board when a node accepts both known and unknown inputs. |
Beta Was this translation helpful? Give feedback.
-
came across |
Beta Was this translation helpful? Give feedback.
-
function doSomething<T extends Record<string, I>, I>({
inputKey = "input",
outputKey = "output",
...rest
}: {
inputKey?: string;
outputKey?: string;
} & T): Record<string, I> {
// Ensure inputKey exists in the input object to prevent runtime errors
if (!(inputKey in rest)) {
throw new Error(`Input key "${inputKey}" not found in input object.`);
}
return {
[outputKey]: rest[inputKey],
};
} // Example usage:
const result = doSomething({
input: "value",
outputKey: "out",
});
console.log(result); |
Beta Was this translation helpful? Give feedback.
-
Not really friction but in writing the array and object utility nodes, I had a thought that about exporting a export function unshift<T>({
array,
elements,
}: {
array: T[];
elements: T[];
}): {
array: T[];
} {
array.unshift(...elements);
return { array };
}
export const unshiftNodeType: MonomorphicDefinition<
{
array: {
type: AdvancedBreadboardType<unknown[]>;
};
elements: {
type: AdvancedBreadboardType<unknown[]>;
};
},
{
array: {
type: AdvancedBreadboardType<unknown[]>;
};
}
> = defineNodeType({
inputs: {
array: {
type: array("unknown"),
},
elements: {
type: array("unknown"),
},
},
outputs: {
array: {
type: array("unknown"),
},
},
invoke: unshift,
}); also providing this export const unshiftCode: Lambda<
{
array: unknown[];
elements: unknown[];
},
{
array: unknown[];
}
> = code(({ array, elements }) => unshift({ array, elements })); |
Beta Was this translation helpful? Give feedback.
-
Something that occurred to me yesterday. it's not always clear when a schema is being used for the |
Beta Was this translation helpful? Give feedback.
-
Thoughts, notes and ponderings
Beta Was this translation helpful? Give feedback.
All reactions