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

Theorize how reflection would work with and without decorators #65

Open
sirisian opened this issue Feb 11, 2022 · 0 comments
Open

Theorize how reflection would work with and without decorators #65

sirisian opened this issue Feb 11, 2022 · 0 comments

Comments

@sirisian
Copy link
Owner

sirisian commented Feb 11, 2022

WIP. This isn't important to the proposal really. Just a place for me to jot down notes.

Server contract example.

@contract('contract')
class Contract {
  add(a:number, b:number):number {
    return a + b;
  }
  
  @oneWay
  updateProgress(
    @validate(v => v >=0 && v <= 1)
    progress:number
  ):void {
    /* do stuff */
  }
  
  simple(
    @validate(v => v.startsWith('a'))
    s:string
  ):string {
    return s + t;
  }

  @validate((a, b, c) => b + c < 10, 'B + C must be less than 10') // Returned error. Others are silent.
  complex(
    { 
      (a:number),
      @validate(v => v <= 10)
      (b:uint8) = 0
    }, [
      @validateRange(1, 10)
      c:uint8
    ]
  ):MyInterface {
    return foo(a, b, c);
  }
  
  foo(
    @validate(a:number => a < 5)
    @validate(a:string => a =='a')
    a:number|string = 'a'
  ):@validate(s => s.length != 0) string { // return validation
      return a.toString();
  }
}

TODO: Add actually complex cases with union types and parameter decorators. Use interfaces and such to really iron out edge cases.

const client = await RPCClient('contract');
const a = await client.add(1, 2);
client.updateProgress(0.5);
const s = await client.simple('abc');
const b = await client.complex({ a: 1.5 }, [10]);

Decorators would definitely need to be able to extract types.

TODO: Define decorators for above cases.

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

No branches or pull requests

1 participant