Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SenecaBatchProcessor Functional Spec #1

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

BeAllAround
Copy link

No description provided.

@@ -1,10 +1,12 @@
type BatchProcessorOptionsFull = {
debug: boolean;
send: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add the object structure as well - helps make it a little self documenting

};
export type BatchProcessorOptions = Partial<BatchProcessorOptionsFull>;
declare function BatchProcessor(this: any, options: BatchProcessorOptionsFull): {
exports: {
process: (seneca: any, ctx: any, out: any) => any;
process: (this: any, seneca: any, ctx: any, out?: any) => Promise<any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the this here?


type BatchProcessorOptionsFull = {
debug: boolean
send: any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also add the object structures here


// console.log(out, state, ctx)

expect(state).toEqual({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this outside the message


})

describe('more complex', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test needs a better descriptive name


}

class Utility {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use classes as function containers - classes should be only for things that are instantiated

let value = (Inks as any).evaluate(msg[key], { out, ctx }, { sep: '~' })

if(null != value && Types[type]) {
let validate = Gubu(eval(type))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, avoid eval in library code, or security static analysis tools will complain

validate(value)
}

if(null != value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless there is additional logic, prefer ternaries for assignments like this

new_msg[key] = null == value ? msg[key] : value

return new_msg
}

static async workflowRun(seneca: any, msg: any, config: any, options: any, results: any) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's refactor this as a preprocessing step, so that workflow exposes a single function run without any conditional logic at runtime

the preprocessing step can then be unit tested by validating the data structure it generates

for(const message_pattern in match) {
let workflow = match[message_pattern]
// console.log(message_pattern, pattern)
if(ALL == message_pattern) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if the patrun pattern '' (empty string) can be used as an ALL match - avoids need for special case code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants