Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/roblox-aurora/zircon
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorlias committed Feb 10, 2023
2 parents 0c32ac1 + 6c0d9e8 commit f446ef6
Show file tree
Hide file tree
Showing 10 changed files with 1,392 additions and 1,134 deletions.
11 changes: 8 additions & 3 deletions example/server/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { ExecutionAction } from "Class/ZirconConfigurationBuilder";
import { ZirconEnumBuilder } from "Class/ZirconEnumBuilder";
import { ZirconFunctionBuilder } from "Class/ZirconFunctionBuilder";
import { ZirconNamespaceBuilder } from "Class/ZirconNamespaceBuilder";
import { $print } from "rbxts-transform-debug";
import { $NODE_ENV } from "rbxts-transform-env";
import { ZirconOptionalValidator, ZirconString } from "Class/ZirconTypeValidator";
import { $package, $print } from "rbxts-transform-debug";

Log.SetLogger(
Logger.configure()
.WriteTo(Log.RobloxOutput())
.WriteTo(Zircon.Log.Console())
.EnrichWithProperty("Version", PKG_VERSION)
.EnrichWithProperty("Version", $package.version)
.Create(),
);

Expand Down Expand Up @@ -210,3 +210,8 @@ ZirconServer.Registry.RegisterFunction(
}),
[ZirconDefaultGroup.User],
);


const test = ZirconOptionalValidator(ZirconString);

test.Validate()
2,455 changes: 1,354 additions & 1,101 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@
},
"types": "out/index.d.ts",
"devDependencies": {
"@rbxts/compiler-types": "1.2.7-types.1",
"@rbxts/types": "^1.0.537",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"@rbxts/compiler-types": "2.0.4-types.0",
"@rbxts/types": "^1.0.642",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"concurrently": "^5.3.0",
"cross-env": "^7.0.3",
"eslint": "^7.11.0",
"eslint-config-prettier": "^6.13.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-roblox-ts": "0.0.24",
"prettier": "^2.1.2",
"rbxts-transform-debug": "1.0.0-ts4.4",
"rbxts-transform-env": "1.0.0-ts4.4",
"rbxts-transformer-services": "^1.0.0",
"roblox-ts": "^1.2.7",
"typescript": "=4.4.4"
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-roblox-ts": "0.0.34",
"prettier": "^2.7.1",
"rbxts-transform-debug": "~2.0.2",
"rbxts-transform-env": "~2.0.2",
"rbxts-transformer-services": "^1.0.1",
"roblox-ts": "~2.0.4",
"typescript": "~4.8.4"
},
"dependencies": {
"@rbxts/flipper": "^2.0.1",
"@rbxts/log": "0.5.0-beta.1",
"@rbxts/log": "^0.6.3",
"@rbxts/maid": "^1.0.0-ts.1",
"@rbxts/message-templates": "^0.3.2",
"@rbxts/net": "^3.0.0-alpha.0",
"@rbxts/roact": ">=1.4.0-ts >= 1.4.1-ts >= 1.4.2-ts",
"@rbxts/roact-hooks": "=0.3.0-ts.2",
"@rbxts/roact-rodux": "=0.2.2-ts.5",
"@rbxts/rodux": "=3.0.0-ts.3",
"@rbxts/rust-classes": "=0.11.0-beta.1",
"@rbxts/rust-classes": "=0.11.2",
"@rbxts/services": "^1.2.0",
"@rbxts/signal": "^1.0.3",
"@rbxts/snapdragon": "2.0.0-beta.1",
Expand Down
9 changes: 5 additions & 4 deletions src/Class/Validators/OptionalValidator.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import ZrUndefined from "@rbxts/zirconium/out/Data/Undefined";
import { StatefulZirconValidator } from "../StatefulZirconValidator";
import { InferTypeFromValidator2, ZirconValidator } from "../ZirconTypeValidator";

export class OptionalValidator<T, U = T> extends StatefulZirconValidator<T | undefined, U | undefined> {
export class OptionalValidator<T, U = T> extends StatefulZirconValidator<T | ZrUndefined, U | undefined> {
public constructor(private innerValidator: ZirconValidator<T, U>) {
super(innerValidator.Type + "?");
}

public Validate(value: unknown): value is T | undefined {
return this.innerValidator.Validate(value) || value === undefined;
public Validate(value: unknown): value is T | ZrUndefined {
return this.innerValidator.Validate(value) || value === ZrUndefined;
}

public Transform(value: T): U | undefined {
return this.innerValidator.Transform?.(value);
return value !== ZrUndefined ? this.innerValidator.Transform?.(value) : undefined;
}
}
8 changes: 4 additions & 4 deletions src/Class/ZirconTypeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ export const NativeEnumItem: ZirconValidator<ZrEnumItem> = {
ErrorMessage: (value) => `Expected enum item, got ${zirconTypeOf(value)}`,
};

export interface ZirconOptionalValidator<T, U = T> extends ZirconValidator<T | undefined, U | undefined> {}
export interface ZirconOptionalValidator<T, U = T> extends ZirconValidator<T | ZrUndefined, U | undefined> {}
export function ZirconOptionalValidator<I, O>(validator: ZirconValidator<I, O>) {
return {
Type: validator.Type + "?",
Validate(value: unknown, player?: Player): value is I | undefined {
return validator.Validate(value, player) || value === undefined;
Validate(value: unknown, player?: Player): value is I | ZrUndefined {
return validator.Validate(value, player) || value === ZrUndefined;
},
Transform(value: unknown, player?: Player) {
if (validator.Validate(value, player)) {
if (validator.Transform !== undefined) {
return (validator.Transform(value, player) ?? undefined) as O | undefined;
return value !== ZrUndefined ? (validator.Transform(value, player) ?? undefined) as O : undefined;
} else {
return (value as unknown) as O | undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Components/ScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ScrollViewEvents {
CanvasPositionChanged?: (position: Vector2, view: ScrollView<never>) => void;
}

export type InferEnumNames<T> = T extends { EnumType: Enum.EnumType<infer A> } ? A["Name"] : never;
export type InferEnumNames<T> = T extends { EnumType: Enum, Name: infer A } ? A : never;
interface ScrollViewProps extends ScrollViewEvents {
Size?: UDim2;
Position?: UDim2;
Expand Down
5 changes: 2 additions & 3 deletions src/Client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { ContextActionService, Players, RunService, StarterGui, UserInputService
import ZirconClientStore from "./BuiltInConsole/Store";
import { ConsoleActionName } from "./BuiltInConsole/Store/_reducers/ConsoleReducer";
import ZirconDockedConsole, { DockedConsoleProps } from "./BuiltInConsole/UI/DockedConsole";
import { $ifEnv } from "rbxts-transform-env";
import { $dbg, $print } from "rbxts-transform-debug";
import { $dbg, $package } from "rbxts-transform-debug";
import Lazy from "../Shared/Lazy";
import { GetCommandService } from "../Services";
import Remotes, {
Expand Down Expand Up @@ -251,7 +250,7 @@ namespace ZirconClient {
context: ZirconContext.Client,
message: {
type: ZirconNetworkMessageType.ZirconStandardOutputMessage,
message: `Loaded Zircon v${PKG_VERSION}`,
message: `Loaded Zircon v${$package.version}`,
level: ZirconLogLevel.Debug,
time: DateTime.now().UnixTimestamp,
tag: "INIT",
Expand Down
1 change: 0 additions & 1 deletion src/Services/RegistryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Players } from "@rbxts/services";
import ZrScriptContext from "@rbxts/zirconium/out/Runtime/ScriptContext";
import { toArray } from "../Shared/Collections";
import ZirconUserGroup, { ZirconPermissions } from "../Server/Class/ZirconGroup";
import { $ifEnv } from "rbxts-transform-env";
import ZrPlayerScriptContext from "@rbxts/zirconium/out/Runtime/PlayerScriptContext";
import { ZirconFunction } from "Class/ZirconFunction";
import { ZirconNamespace } from "Class/ZirconNamespace";
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/Collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function setsEqual<TValue>(
return true;
}

export function last<TValue>(collection: Array<TValue>, amount: number): Array<TValue> {
export function last<TValue extends defined>(collection: Array<TValue>, amount: number): Array<TValue> {
const amountCalculated = math.min(amount, collection.size());
const newArray = new Array<TValue>(amountCalculated);
for (let start = collection.size() - amountCalculated; start < collection.size(); start++) {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"strict": true,
"target": "ESNext",
"typeRoots": ["node_modules/@rbxts"],
"moduleDetection": "force",

// configurable
"rootDir": "src",
Expand Down

0 comments on commit f446ef6

Please sign in to comment.