-
Notifications
You must be signed in to change notification settings - Fork 0
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
Decorators #83
Comments
On TyRAS side it would look something like this: import * as builders from ".";
import type * as dataBE from "@ty-ras/data-backend";
import type * as data from "@ty-ras/data";
const createAppBuilder = <TStringDecoder>(): AppBuilder<TStringDecoder> => {
const builder0 = builders.startBuildingAPI();
const endpointsFor: AppEndpointSpecifierFactory<TStringDecoder> = (<
TURLData extends dataBE.RuntimeAnyURLData,
>({
url,
}:
| AppEndpointSpecifierFactoryArgsStaticURL
| AppEndpointSpecifierFactoryArgsURLParameters<
TStringDecoder,
TURLData
>) => {
const specifier:
| AppEndpointSpecifier
| AppEndpointSpecifierWithURL<TURLData> = {
endpoint() {
return (method: ClassMethodForEndpoint<any, any, any>, context) => {};
},
};
return specifier;
}) as any;
return {
endpointsFor,
};
};
interface AppBuilder<TStringDecoder> {
endpointsFor: AppEndpointSpecifierFactory<TStringDecoder>;
}
interface AppEndpointSpecifierFactory<TStringDecoder> {
(args: AppEndpointSpecifierFactoryArgsStaticURL): AppEndpointSpecifier;
<TURLData extends dataBE.RuntimeAnyURLData>(
args: AppEndpointSpecifierFactoryArgsURLParameters<
TStringDecoder,
TURLData
>,
): AppEndpointSpecifierWithURL<builders.EndpointHandlerArgsWithURL<TURLData>>;
}
interface AppEndpointSpecifierFactoryArgsStaticURL {
url: string;
// metadata: ...
}
interface AppEndpointSpecifierFactoryArgsURLParameters<
TStringDecoder,
TURLData extends dataBE.RuntimeAnyURLData,
> {
url: {
args: ReadonlyArray<string>;
spec: dataBE.URLParameterValidatorSpec<TURLData, TStringDecoder>;
};
// metadata: ...
}
interface AppEndpointSpecifier {
endpoint(args: {
state: string;
}): <This, Return>(
method: ClassMethodForEndpoint<{}, This, Return>,
context: ClassMethodDecoratorContext,
) => void;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface AppEndpointSpecifierWithURL<TURLData extends object> {
endpoint(args: {
state: string;
}): <This, Return>(
method: ClassMethodForEndpoint<{ url: TURLData }, This, Return>,
context: ClassMethodDecoratorContext,
) => void;
}
type ClassMethodForEndpoint<TArgs extends Record<string, any>, This, Return> = (
this: This,
args: { state: string } & TArgs,
) => Return; |
Some notes function endpointsFor<TClass>(
theClass: new () => TClass,
): ((
args: {...},
) => <Args extends Array<any>, Return>(
method: (this: TClass, ...args: Args) => Return,
ctx: ClassMethodDecoratorContext<TClass, typeof method>,
) => void) =>
(args) =>
(method, ctx) => {
// Use 'theClass' and "===" comparison against 'this' to find correct builder and modify it.
}; |
This is now implemented with #93 . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be great to have something like this:
However, this will not work until this TS issue has been solved: microsoft/TypeScript#4881 . Perhaps its chances of survival are now marginally better, after TS 5 introduced non-experimental support for decorators.
As such, using decorators within TyRAS does not make sense at all until the TS issue is solved (?).
Specifying types of arguments explicitly is something I am not sure will be much difference from the current way of using builders and such. However, it is maybe worth exploring after
1.0.0
is out.The text was updated successfully, but these errors were encountered: