Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorlias committed Oct 12, 2021
1 parent c146b80 commit 2f87117
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 29 deletions.
8 changes: 4 additions & 4 deletions example/server/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ExistingEnum = ZirconServer.Registry.RegisterEnum(new ZirconEnumBuilder("t

ZirconServer.Registry.RegisterFunction(
new ZirconFunctionBuilder("kill")
.AddArguments("player?")
.AddArgument("player?")
.AddDescription("testing lol")
.Bind((context, player) => {
const target = player ?? context.GetExecutor();
Expand All @@ -42,7 +42,7 @@ ZirconServer.Registry.RegisterFunction(
);

ZirconServer.Registry.RegisterFunction(
new ZirconFunctionBuilder("test_enum").AddArguments(TestEnum).Bind((context, value) => {
new ZirconFunctionBuilder("test_enum").AddArgument(TestEnum).Bind((context, value) => {
value.Match({
Value2: () => {
Log.Info("Got given enum item 2 (member)");
Expand All @@ -64,15 +64,15 @@ ZirconServer.Registry.RegisterFunction(
);

ZirconServer.Registry.RegisterFunction(
new ZirconFunctionBuilder("test_enum2").AddArguments(ExistingEnum.GetMemberType()).Bind((context, value) => {
new ZirconFunctionBuilder("test_enum2").AddArgument(ExistingEnum.GetMemberType()).Bind((context, value) => {
Log.Info("Got {NumberValue} ({StringValue})", ExistingEnumType[value.GetName()], value.GetName());
}),
[ZirconServer.Registry.User],
);

ZirconServer.Registry.RegisterFunction(
new ZirconFunctionBuilder("print_message")
.AddArguments("string")
.AddArgument("string")
.Bind((context, message) => Log.Info("Zircon says {Message} from {Player}", message, context.GetExecutor())),
[ZirconServer.Registry.User],
);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rbxts/zircon",
"version": "0.20.0-beta.0",
"version": "0.12.0-beta.0",
"description": "",
"main": "out/init.lua",
"scripts": {
Expand Down Expand Up @@ -34,7 +34,7 @@
"rbxts-transform-debug": "1.0.0-rc.1",
"rbxts-transform-env": "1.0.0-rc.0",
"rbxts-transformer-services": "^1.0.0",
"roblox-ts": "^1.1.1",
"roblox-ts": "^1.2.3",
"typescript": "=4.3.5"
},
"dependencies": {
Expand Down
18 changes: 1 addition & 17 deletions src/Class/ZirconFunctionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@ export class ZirconFunctionBuilder<V extends ZirconValidator<unknown, unknown>[]

public constructor(private name: string) {}

/**
* Adds these arguments to this function
* @param args The arguments
* @returns
*/
public AddArguments<TValidation extends Validator[]>(...args: TValidation) {
if (this.hasVaradic) {
throw `Cannot add argument past varadic argument`;
}

for (const argValidator of args) {
this.AddArgument(argValidator);
}
return (this as unknown) as ZirconFunctionBuilder<[...V, ...InferValidators<TValidation>]>;
}

/**
* Adds an argnument to this zircon function
* @param argValidator The argument type/validator
Expand All @@ -60,7 +44,7 @@ export class ZirconFunctionBuilder<V extends ZirconValidator<unknown, unknown>[]

return (this as unknown) as Omit<
ZirconFunctionBuilder<[...V, ...InferValidator<TValidation>[]]>,
"AddArguments" | "AddVaradicArgument"
"AddVaradicArgument"
>;
}

Expand Down
8 changes: 2 additions & 6 deletions src/Class/ZirconTypeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ export type BuiltInValidators = typeof BuiltInValidators;
export type Validator = keyof typeof BuiltInValidators | ZirconValidator<any, any> | ZirconEnum<any>;

export type InferValidators<T extends ReadonlyArray<Validator>> = {
readonly // eslint-disable-next-line @typescript-eslint/ban-ts-comment
/** @ts-ignore Because otherwise we can't get this working. */
[P in keyof T]: InferValidator<T[P]>;
readonly [P in keyof T]: T[P] extends Validator ? InferValidator<T[P]> : never;
};

// export type InferArguments<T extends ReadonlyArray<Validator>> = {
Expand All @@ -136,9 +134,7 @@ export type IWantToStabMyselfWithAFuckingFork<T> = T extends keyof BuiltInValida
export type InferArguments<T extends readonly ZirconValidator<any, any>[]> = T extends []
? [...(readonly (ZrValue | ZrUndefined)[])]
: {
readonly // eslint-disable-next-line @typescript-eslint/ban-ts-comment
/** @ts-ignore */
[P in keyof T]: InferTypeFromValidator2<T[P]>;
readonly [P in keyof T]: T[P] extends ZirconValidator<any, any> ? InferTypeFromValidator2<T[P]> : never;
};

export type InferValidator<T extends Validator> = T extends keyof BuiltInValidators
Expand Down

0 comments on commit 2f87117

Please sign in to comment.