Skip to content

Commit 2eb08ca

Browse files
committed
style: 💄 fix linter issues
1 parent cca81c1 commit 2eb08ca

File tree

12 files changed

+89
-74
lines changed

12 files changed

+89
-74
lines changed

src/random/generators.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export const num = (type: NumberType): number => {
6767
const schema = type.getSchema();
6868
const {lt, lte, gt, gte} = schema;
6969
if (gt !== undefined) min = gt;
70-
if (gte !== undefined) if (gte === lte) return gte; else min = gte + 0.000000000000001;
70+
if (gte !== undefined)
71+
if (gte === lte) return gte;
72+
else min = gte + 0.000000000000001;
7173
if (lt !== undefined) max = lt;
7274
if (lte !== undefined) max = lte - 0.000000000000001;
7375
if (min >= max) return max;

src/schema/__tests__/SchemaBuilder.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ConstSchema, s} from '..';
1+
import {type ConstSchema, s} from '..';
22

33
describe('string', () => {
44
test('can create a string type', () => {

src/schema/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TypeOf} from './schema';
1+
import type {TypeOf} from './schema';
22
import {SchemaBuilder} from './SchemaBuilder';
33

44
export * from './common';

src/schema/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,4 +522,4 @@ export type Required<T extends object> = Omit<T, OptionalProps<T>>;
522522
export type Narrow<T> =
523523
| (T extends infer U ? U : never)
524524
| Extract<T, number | string | boolean | bigint | symbol | null | undefined | []>
525-
| ([T] extends [[]] ? [] : { [K in keyof T]: Narrow<T[K]> });
525+
| ([T] extends [[]] ? [] : {[K in keyof T]: Narrow<T[K]>});

src/type/TypeBuilder.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@ import type {TypeOfAlias} from '../system/types';
77

88
const {s} = schema;
99

10-
type UnionToIntersection<U> = (
11-
U extends never ? never : (arg: U) => never
12-
) extends (arg: infer I) => void
13-
? I
14-
: never;
15-
16-
type UnionToTuple<T> = UnionToIntersection<
17-
T extends never ? never : (t: T) => T
18-
> extends (_: never) => infer W
10+
type UnionToIntersection<U> = (U extends never ? never : (arg: U) => never) extends (arg: infer I) => void ? I : never;
11+
12+
type UnionToTuple<T> = UnionToIntersection<T extends never ? never : (t: T) => T> extends (_: never) => infer W
1913
? [...UnionToTuple<Exclude<T, W>>, W]
2014
: [];
2115

22-
type ObjValueTuple<T, KS extends any[] = UnionToTuple<keyof T>, R extends any[] = []> =
23-
KS extends [infer K, ...infer KT]
16+
type ObjValueTuple<T, KS extends any[] = UnionToTuple<keyof T>, R extends any[] = []> = KS extends [
17+
infer K,
18+
...infer KT,
19+
]
2420
? ObjValueTuple<T, KT, [...R, T[K & keyof T]]>
25-
: R
21+
: R;
2622

27-
type RecordToFields<O extends Record<string, Type>> = ObjValueTuple<{[K in keyof O]: classes.ObjectFieldType<K extends string ? K : never, O[K]>}>;
23+
type RecordToFields<O extends Record<string, Type>> = ObjValueTuple<{
24+
[K in keyof O]: classes.ObjectFieldType<K extends string ? K : never, O[K]>;
25+
}>;
2826

2927
export class TypeBuilder {
3028
constructor(public system?: TypeSystem) {}
@@ -79,7 +77,6 @@ export class TypeBuilder {
7977
return this.Function$(this.undef, this.undef);
8078
}
8179

82-
8380
// --------------------------------------------------------------- shorthands
8481

8582
public readonly undefined = () => this.undef;
@@ -94,7 +91,10 @@ export class TypeBuilder {
9491
public readonly literal = this.con;
9592

9693
public readonly array = <T>(type?: T, options?: schema.Optional<schema.ArraySchema>) =>
97-
this.Array<T extends Type ? T : classes.AnyType>((type ?? this.any) as T extends Type ? T : classes.AnyType, options);
94+
this.Array<T extends Type ? T : classes.AnyType>(
95+
(type ?? this.any) as T extends Type ? T : classes.AnyType,
96+
options,
97+
);
9898

9999
public readonly tuple = <F extends Type[]>(...types: F) => this.Tuple(...types);
100100

@@ -131,8 +131,7 @@ export class TypeBuilder {
131131
* Creates a type that represents a value that may be present or absent. The
132132
* value is `undefined` if absent. This is a shorthand for `t.Or(type, t.undef)`.
133133
*/
134-
public readonly maybe = <T extends Type>(type: T) =>
135-
this.Or(type, this.undef);
134+
public readonly maybe = <T extends Type>(type: T) => this.Or(type, this.undef);
136135

137136
/**
138137
* Creates a union type from a list of values. This is a shorthand for
@@ -147,9 +146,10 @@ export class TypeBuilder {
147146
* @param values The values to include in the union.
148147
* @returns A union type representing the values.
149148
*/
150-
public readonly enum = <const T extends (string | number | boolean | null)[]>(...values: T): classes.OrType<{[K in keyof T]: classes.ConstType<schema.Narrow<T[K]>>}> =>
151-
this.Or(...values.map(type => this.Const(type as any))) as any;
152-
149+
public readonly enum = <const T extends (string | number | boolean | null)[]>(
150+
...values: T
151+
): classes.OrType<{[K in keyof T]: classes.ConstType<schema.Narrow<T[K]>>}> =>
152+
this.Or(...values.map((type) => this.Const(type as any))) as any;
153153

154154
// --------------------------------------------------- base node constructors
155155

@@ -246,13 +246,21 @@ export class TypeBuilder {
246246
return type;
247247
}
248248

249-
public Function<Req extends Type, Res extends Type>(req: Req, res: Res, options?: schema.Optional<schema.FunctionSchema>) {
249+
public Function<Req extends Type, Res extends Type>(
250+
req: Req,
251+
res: Res,
252+
options?: schema.Optional<schema.FunctionSchema>,
253+
) {
250254
const fn = new classes.FunctionType<Req, Res>(req, res, options);
251255
fn.system = this.system;
252256
return fn;
253257
}
254258

255-
public Function$<Req extends Type, Res extends Type>(req: Req, res: Res, options?: schema.Optional<schema.FunctionStreamingSchema>) {
259+
public Function$<Req extends Type, Res extends Type>(
260+
req: Req,
261+
res: Res,
262+
options?: schema.Optional<schema.FunctionStreamingSchema>,
263+
) {
256264
const fn = new classes.FunctionStreamingType<Req, Res>(req, res, options);
257265
fn.system = this.system;
258266
return fn;

src/type/__tests__/SchemaOf.spec.ts

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {EMPTY} from 'rxjs';
22
import {type SchemaOf, t} from '..';
33
import type {TypeOf} from '../../schema';
4-
import * as system from '../../system';
4+
import type * as system from '../../system';
55

66
test('const', () => {
77
const type = t.Const(<const>42);
@@ -120,30 +120,22 @@ describe('fn', () => {
120120
});
121121

122122
test('string patch', () => {
123-
const StringOperationInsert = t.Tuple(t.Const(1), t.str)
124-
.options({
125-
title: 'Insert String',
126-
description: 'Inserts a string at the current position in the source string.'
127-
});
128-
const StringOperationEqual = t.Tuple(t.Const(0), t.str)
129-
.options({
130-
title: 'Equal String',
131-
description: 'Keeps the current position in the source string unchanged.'
132-
});
133-
const StringOperationDelete = t.Tuple(t.Const(-1), t.str)
134-
.options({
135-
title: 'Delete String',
136-
description: 'Deletes the current position in the source string.'
137-
});
138-
const StringPatch = t.Array(
139-
t.Or(
140-
StringOperationInsert,
141-
StringOperationEqual,
142-
StringOperationDelete
143-
)
144-
).options({
123+
const StringOperationInsert = t.Tuple(t.Const(1), t.str).options({
124+
title: 'Insert String',
125+
description: 'Inserts a string at the current position in the source string.',
126+
});
127+
const StringOperationEqual = t.Tuple(t.Const(0), t.str).options({
128+
title: 'Equal String',
129+
description: 'Keeps the current position in the source string unchanged.',
130+
});
131+
const StringOperationDelete = t.Tuple(t.Const(-1), t.str).options({
132+
title: 'Delete String',
133+
description: 'Deletes the current position in the source string.',
134+
});
135+
const StringPatch = t.Array(t.Or(StringOperationInsert, StringOperationEqual, StringOperationDelete)).options({
145136
title: 'String Patch',
146-
description: 'A list of string operations that can be applied to a source string to produce a destination string, or vice versa.'
137+
description:
138+
'A list of string operations that can be applied to a source string to produce a destination string, or vice versa.',
147139
});
148140

149141
type T = system.infer<typeof StringPatch>;
@@ -154,6 +146,6 @@ test('string patch', () => {
154146
];
155147
const v2: T = [
156148
// @ts-expect-error
157-
[2, 'Test']
149+
[2, 'Test'],
158150
];
159151
});

src/type/__tests__/TypeBuilder.spec.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,19 @@ test('can construct a realistic object', () => {
7676
});
7777

7878
test('can build type using lowercase shortcuts', () => {
79-
const MyObject = t.object({
80-
type: t.con('user'),
81-
id: t.string(),
82-
name: t.string(),
83-
age: t.number(),
84-
coordinates: t.tuple(t.number(), t.number()),
85-
verified: t.boolean(),
86-
offsets: t.array(t.number()),
87-
enum: t.enum(1, 2, 'three'),
88-
optional: t.maybe(t.string()),
89-
}).opt('description', t.string());
79+
const MyObject = t
80+
.object({
81+
type: t.con('user'),
82+
id: t.string(),
83+
name: t.string(),
84+
age: t.number(),
85+
coordinates: t.tuple(t.number(), t.number()),
86+
verified: t.boolean(),
87+
offsets: t.array(t.number()),
88+
enum: t.enum(1, 2, 'three'),
89+
optional: t.maybe(t.string()),
90+
})
91+
.opt('description', t.string());
9092
// console.log(MyObject + '');
9193
const MyObject2 = t.obj
9294
.prop('type', t.Const('user'))

src/type/classes/AbstractType.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
type CompiledCapacityEstimator,
3737
} from '../../codegen/capacity/CapacityEstimatorCodegenContext';
3838
import {generate} from '../../codegen/capacity/estimators';
39-
import {TExample} from '../../schema';
39+
import type {TExample} from '../../schema';
4040
import type {JsonValueCodec} from '@jsonjoy.com/json-pack/lib/codecs/types';
4141
import type * as jsonSchema from '../../json-schema';
4242
import type {BaseType} from '../types';
@@ -112,7 +112,11 @@ export abstract class AbstractType<S extends schema.Schema> implements BaseType<
112112
return this;
113113
}
114114

115-
public example(value: schema.TypeOf<S>, title?: TExample['title'], options?: Omit<TExample, 'value' | 'title'>): this {
115+
public example(
116+
value: schema.TypeOf<S>,
117+
title?: TExample['title'],
118+
options?: Omit<TExample, 'value' | 'title'>,
119+
): this {
116120
const examples = (this.schema.examples ??= []);
117121
const example: TExample = {...options, value};
118122
if (typeof title === 'string') example.title = title;

src/type/classes/ArrayType.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import type {json_string} from '@jsonjoy.com/util/lib/json-brand';
1717
import type * as ts from '../../typescript/types';
1818
import type {TypeExportContext} from '../../system/TypeExportContext';
1919

20-
2120
export class ArrayType<T extends Type> extends AbstractType<schema.ArraySchema<SchemaOf<T>>> {
2221
protected schema: schema.ArraySchema<any>;
2322

src/type/classes/ObjectType.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ export class ObjectType<F extends ObjectFieldType<any, any>[] = ObjectFieldType<
9494
super();
9595
}
9696

97-
private _field(field: ObjectFieldType<any, any>, options?: schema.Optional<schema.ObjectFieldSchema<any, any>>): void {
97+
private _field(
98+
field: ObjectFieldType<any, any>,
99+
options?: schema.Optional<schema.ObjectFieldSchema<any, any>>,
100+
): void {
98101
if (options) field.options(options);
99102
field.system = this.system;
100103
this.fields.push(field as any);
@@ -107,7 +110,11 @@ export class ObjectType<F extends ObjectFieldType<any, any>[] = ObjectFieldType<
107110
* @param options Optional schema options for the property.
108111
* @returns A new object type with the added property.
109112
*/
110-
public prop<K extends string, V extends Type>(key: K, value: V, options?: schema.Optional<schema.ObjectFieldSchema<K, SchemaOf<V>>>): ObjectType<[...F, ObjectFieldType<K, V>]> {
113+
public prop<K extends string, V extends Type>(
114+
key: K,
115+
value: V,
116+
options?: schema.Optional<schema.ObjectFieldSchema<K, SchemaOf<V>>>,
117+
): ObjectType<[...F, ObjectFieldType<K, V>]> {
111118
this._field(new ObjectFieldType<K, V>(key, value), options);
112119
return <any>this;
113120
}
@@ -119,7 +126,11 @@ export class ObjectType<F extends ObjectFieldType<any, any>[] = ObjectFieldType<
119126
* @param options Optional schema options for the property.
120127
* @returns A new object type with the added property.
121128
*/
122-
public opt<K extends string, V extends Type>(key: K, value: V, options?: schema.Optional<schema.ObjectFieldSchema<K, SchemaOf<V>>>): ObjectType<[...F, ObjectOptionalFieldType<K, V>]> {
129+
public opt<K extends string, V extends Type>(
130+
key: K,
131+
value: V,
132+
options?: schema.Optional<schema.ObjectFieldSchema<K, SchemaOf<V>>>,
133+
): ObjectType<[...F, ObjectOptionalFieldType<K, V>]> {
123134
this._field(new ObjectOptionalFieldType<K, V>(key, value), options);
124135
return <any>this;
125136
}

0 commit comments

Comments
 (0)