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

Invocation Flow Improvements (Fixes Encoding Problems) #1000

Merged
merged 4 commits into from
Jun 30, 2022

Conversation

dOrgJelli
Copy link
Contributor

@dOrgJelli dOrgJelli commented Jun 30, 2022

After seeing the problems described in this PR #947 it occurred to me that the way we have implemented noDecode is incorrect and incomplete.

It does not cover all possible encoding cases:
image

In order to make the above possible, we need to add the concept of an invoker and an invocable. This will allow us to have different options / return values:

export interface InvokerOptions extends InvokeOptions {
  encodeResult?: boolean;
}

export interface Invoker {
  invoke(
    options: InvokerOptions
  ): Promise<InvokeResult>;
}

export interface InvocableResult extends InvokeResult {
  encoded: boolean;
}

export interface Invocable {
  invoke(
    options: InvokeOptions,
    invoker: Invoker
  ): Promise<InvocableResult>;
}

A rough outline of the client implementation:

class Client implements Invoker {
  invoke(options) {
    wrapper = loadWrapper() // plugin, wasm

    result = wrapper.invoke()

    if (result.error) {
      return { error: result.error };
    }
  
    if (result.encoded && !options.encode) {
      return { data: decode(result.data) };
    } else if (!result.encoded && options.encode) {
      return { data: encode(result.data) };
    } else {
      return { data: result.data };
    }
  }
}

@dOrgJelli dOrgJelli merged commit 60b8e45 into prealpha-dev Jun 30, 2022
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.

1 participant