Skip to content

Commit

Permalink
Made schema constructors more readable.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwoplaza committed Dec 18, 2024
1 parent 91b2fd4 commit 0c75545
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 18 deletions.
8 changes: 5 additions & 3 deletions packages/typed-binary/src/structure/array.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValidationError } from '../error.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { Measurer } from '../io/measurer.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import type { ParseUnwrapped } from '../utilityTypes.ts';
import {
type AnySchema,
Expand Down Expand Up @@ -82,7 +82,9 @@ export class ArraySchema<TElement extends AnySchema> extends Schema<
}
}

export const arrayOf = <TSchema extends AnySchema>(
export function arrayOf<TSchema extends AnySchema>(
elementSchema: TSchema,
length: number,
) => new ArraySchema(elementSchema, length);
) {
return new ArraySchema(elementSchema, length);
}
2 changes: 1 addition & 1 deletion packages/typed-binary/src/structure/baseTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { Measurer } from '../io/measurer.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { MaxValue, Schema } from './types.ts';

////
Expand Down
6 changes: 4 additions & 2 deletions packages/typed-binary/src/structure/chars.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValidationError } from '../error.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { Measurer } from '../io/measurer.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { Schema } from './types.ts';

export class CharsSchema extends Schema<string> {
Expand Down Expand Up @@ -35,4 +35,6 @@ export class CharsSchema extends Schema<string> {
}
}

export const chars = <T extends number>(length: T) => new CharsSchema(length);
export function chars<T extends number>(length: T) {
return new CharsSchema(length);
}
2 changes: 1 addition & 1 deletion packages/typed-binary/src/structure/concat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MergeRecordUnion } from '../utilityTypes.ts';
import { type AnyObjectSchema, ObjectSchema } from './object.ts';
import type { PropertiesOf } from './types.ts';
import type { MergeRecordUnion } from '../utilityTypes.ts';

type Concat<Objs extends AnyObjectSchema[]> = ObjectSchema<
MergeRecordUnion<PropertiesOf<Objs[number]>>
Expand Down
2 changes: 1 addition & 1 deletion packages/typed-binary/src/structure/dynamicArray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { Measurer } from '../io/measurer.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import type { ParseUnwrapped } from '../utilityTypes.ts';
import {
type AnySchema,
Expand Down
2 changes: 1 addition & 1 deletion packages/typed-binary/src/structure/keyed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UnresolvedReferenceError } from '../error.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { Measurer } from '../io/measurer.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import type { ParseUnwrapped, Parsed } from '../utilityTypes.ts';
import {
type AnySchema,
Expand Down
2 changes: 1 addition & 1 deletion packages/typed-binary/src/structure/object.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { Measurer } from '../io/measurer.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import type { ParseUnwrappedRecord, Parsed } from '../utilityTypes.ts';
import {
type AnySchema,
Expand Down
2 changes: 1 addition & 1 deletion packages/typed-binary/src/structure/optional.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { Measurer } from '../io/measurer.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import type { ParseUnwrapped } from '../utilityTypes.ts';
import {
type AnySchema,
Expand Down
8 changes: 5 additions & 3 deletions packages/typed-binary/src/structure/tuple.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ValidationError } from '../error.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { Measurer } from '../io/measurer.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import type { Parsed } from '../utilityTypes.ts';
import {
type AnySchema,
Expand Down Expand Up @@ -88,6 +88,8 @@ export class TupleSchema<
}
}

export const tupleOf = <TSchema extends [AnySchema, ...AnySchema[]]>(
export function tupleOf<TSchema extends [AnySchema, ...AnySchema[]]>(
schemas: TSchema,
) => new TupleSchema(schemas);
) {
return new TupleSchema(schemas);
}
2 changes: 1 addition & 1 deletion packages/typed-binary/src/structure/typedArray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import { Measurer } from '../io/measurer.ts';
import type { IMeasurer, ISerialInput, ISerialOutput } from '../io/types.ts';
import type { Parsed } from '../utilityTypes.ts';
import { type MaxValue, Schema } from './types.ts';

Expand Down
6 changes: 3 additions & 3 deletions packages/typed-binary/src/test/unwrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { describe, expectTypeOf, it } from 'vitest';

// Importing from the public API
import type {
Unwrap,
ISchema,
IKeyedSchema,
UnwrapRecord,
ISchema,
Unwrap,
UnwrapArray,
UnwrapRecord,
} from '../index.ts';

describe('Unwrap<T>', () => {
Expand Down

0 comments on commit 0c75545

Please sign in to comment.