Skip to content

Commit e466a23

Browse files
Copilotstreamich
andcommitted
Rename Type classes to 3-letter abbreviations
Co-authored-by: streamich <[email protected]>
1 parent 2ec76b9 commit e466a23

36 files changed

+226
-226
lines changed

src/codegen/capacity/estimators.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ export const bin = (ctx: CapacityEstimatorCodegenContext, value: JsExpression):
5959
};
6060

6161
export const const_ = (ctx: CapacityEstimatorCodegenContext, value: JsExpression, type: Type): void => {
62-
const constType = type as any; // ConstType
62+
const constType = type as any; // ConType
6363
ctx.inc(maxEncodingCapacity(constType.value()));
6464
};
6565

6666
export const arr = (ctx: CapacityEstimatorCodegenContext, value: JsExpression, type: Type): void => {
6767
const codegen = ctx.codegen;
6868
ctx.inc(MaxEncodingOverhead.Array);
6969
const rLen = codegen.var(`${value.use()}.length`);
70-
const arrayType = type as any; // ArrayType
70+
const arrayType = type as any; // ArrType
7171
const elementType = arrayType.type;
7272
codegen.js(`size += ${MaxEncodingOverhead.ArrayElement} * ${rLen}`);
7373
const fn = elementType.compileCapacityEstimator({
@@ -90,7 +90,7 @@ export const arr = (ctx: CapacityEstimatorCodegenContext, value: JsExpression, t
9090
export const tup = (ctx: CapacityEstimatorCodegenContext, value: JsExpression, type: Type): void => {
9191
const codegen = ctx.codegen;
9292
const r = codegen.var(value.use());
93-
const tupleType = type as any; // TupleType
93+
const tupleType = type as any; // TupType
9494
const types = tupleType.types;
9595
const overhead = MaxEncodingOverhead.Array + MaxEncodingOverhead.ArrayElement * types.length;
9696
ctx.inc(overhead);
@@ -113,7 +113,7 @@ export const obj = (
113113
): void => {
114114
const codegen = ctx.codegen;
115115
const r = codegen.var(value.use());
116-
const objectType = type as any; // ObjectType
116+
const objectType = type as any; // ObjType
117117
const encodeUnknownFields = !!objectType.schema.encodeUnknownFields;
118118
if (encodeUnknownFields) {
119119
codegen.js(`size += maxEncodingCapacity(${r});`);

src/json-schema/converter.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import type {AbstractType} from '../type/classes/AbstractType';
1+
import type {AbsType} from '../type/classes/AbsType';
22
import type {AnyType} from '../type/classes/AnyType';
3-
import type {ArrayType} from '../type/classes/ArrayType';
4-
import type {BinaryType} from '../type/classes/BinaryType';
5-
import type {BooleanType} from '../type/classes/BooleanType';
6-
import type {ConstType} from '../type/classes/ConstType';
3+
import type {ArrType} from '../type/classes/ArrType';
4+
import type {BinType} from '../type/classes/BinType';
5+
import type {BoolType} from '../type/classes/BoolType';
6+
import type {ConType} from '../type/classes/ConType';
77
import type {MapType} from '../type/classes/MapType';
8-
import type {NumberType} from '../type/classes/NumberType';
9-
import type {ObjectType} from '../type/classes/ObjectType';
8+
import type {NumType} from '../type/classes/NumType';
9+
import type {ObjType} from '../type/classes/ObjType';
1010
import type {OrType} from '../type/classes/OrType';
1111
import type {RefType} from '../type/classes/RefType';
12-
import type {StringType} from '../type/classes/StringType';
13-
import type {TupleType} from '../type/classes/TupleType';
12+
import type {StrType} from '../type/classes/StrType';
13+
import type {TupType} from '../type/classes/TupType';
1414
import type {TypeExportContext} from '../system/TypeExportContext';
1515
import type * as schema from '../schema';
1616
import type {
@@ -30,9 +30,9 @@ import type {
3030

3131
/**
3232
* Extracts the base JSON Schema properties that are common to all types.
33-
* This replaces the logic from AbstractType.toJsonSchema().
33+
* This replaces the logic from AbsType.toJsonSchema().
3434
*/
35-
function getBaseJsonSchema(type: AbstractType<any>, ctx?: TypeExportContext): JsonSchemaGenericKeywords {
35+
function getBaseJsonSchema(type: AbsType<any>, ctx?: TypeExportContext): JsonSchemaGenericKeywords {
3636
const typeSchema = type.getSchema();
3737
const jsonSchema: JsonSchemaGenericKeywords = {};
3838

@@ -49,34 +49,34 @@ function getBaseJsonSchema(type: AbstractType<any>, ctx?: TypeExportContext): Js
4949
* Main router function that converts a type to JSON Schema using a switch statement.
5050
* This replaces the individual toJsonSchema() methods on each type class.
5151
*/
52-
export function typeToJsonSchema(type: AbstractType<any>, ctx?: TypeExportContext): JsonSchemaNode {
52+
export function typeToJsonSchema(type: AbsType<any>, ctx?: TypeExportContext): JsonSchemaNode {
5353
const typeName = type.getTypeName();
5454

5555
switch (typeName) {
5656
case 'any':
5757
return anyToJsonSchema(type as AnyType, ctx);
5858
case 'arr':
59-
return arrayToJsonSchema(type as ArrayType<any>, ctx);
59+
return arrayToJsonSchema(type as ArrType<any>, ctx);
6060
case 'bin':
61-
return binaryToJsonSchema(type as BinaryType<any>, ctx);
61+
return binaryToJsonSchema(type as BinType<any>, ctx);
6262
case 'bool':
63-
return booleanToJsonSchema(type as BooleanType, ctx);
63+
return booleanToJsonSchema(type as BoolType, ctx);
6464
case 'con':
65-
return constToJsonSchema(type as ConstType<any>, ctx);
65+
return constToJsonSchema(type as ConType<any>, ctx);
6666
case 'map':
6767
return mapToJsonSchema(type as MapType<any>, ctx);
6868
case 'num':
69-
return numberToJsonSchema(type as NumberType, ctx);
69+
return numberToJsonSchema(type as NumType, ctx);
7070
case 'obj':
71-
return objectToJsonSchema(type as ObjectType<any>, ctx);
71+
return objectToJsonSchema(type as ObjType<any>, ctx);
7272
case 'or':
7373
return orToJsonSchema(type as OrType<any>, ctx);
7474
case 'ref':
7575
return refToJsonSchema(type as RefType<any>, ctx);
7676
case 'str':
77-
return stringToJsonSchema(type as StringType, ctx);
77+
return stringToJsonSchema(type as StrType, ctx);
7878
case 'tup':
79-
return tupleToJsonSchema(type as TupleType<any>, ctx);
79+
return tupleToJsonSchema(type as TupType<any>, ctx);
8080
default:
8181
// Fallback to base implementation for unknown types
8282
return getBaseJsonSchema(type, ctx);
@@ -97,7 +97,7 @@ function anyToJsonSchema(type: AnyType, ctx?: TypeExportContext): JsonSchemaAny
9797
return result;
9898
}
9999

100-
function arrayToJsonSchema(type: ArrayType<any>, ctx?: TypeExportContext): JsonSchemaArray {
100+
function arrayToJsonSchema(type: ArrType<any>, ctx?: TypeExportContext): JsonSchemaArray {
101101
const schema = type.getSchema();
102102
const baseSchema = getBaseJsonSchema(type, ctx);
103103
const result: JsonSchemaArray = {
@@ -114,7 +114,7 @@ function arrayToJsonSchema(type: ArrayType<any>, ctx?: TypeExportContext): JsonS
114114
return result;
115115
}
116116

117-
function binaryToJsonSchema(type: BinaryType<any>, ctx?: TypeExportContext): JsonSchemaBinary {
117+
function binaryToJsonSchema(type: BinType<any>, ctx?: TypeExportContext): JsonSchemaBinary {
118118
const baseSchema = getBaseJsonSchema(type, ctx);
119119
const result: JsonSchemaBinary = {
120120
type: 'binary' as any,
@@ -126,7 +126,7 @@ function binaryToJsonSchema(type: BinaryType<any>, ctx?: TypeExportContext): Jso
126126
return result;
127127
}
128128

129-
function booleanToJsonSchema(type: BooleanType, ctx?: TypeExportContext): JsonSchemaBoolean {
129+
function booleanToJsonSchema(type: BoolType, ctx?: TypeExportContext): JsonSchemaBoolean {
130130
const baseSchema = getBaseJsonSchema(type, ctx);
131131
const result: JsonSchemaBoolean = {
132132
type: 'boolean',
@@ -138,7 +138,7 @@ function booleanToJsonSchema(type: BooleanType, ctx?: TypeExportContext): JsonSc
138138
return result;
139139
}
140140

141-
function constToJsonSchema(type: ConstType<any>, ctx?: TypeExportContext): JsonSchemaNode {
141+
function constToJsonSchema(type: ConType<any>, ctx?: TypeExportContext): JsonSchemaNode {
142142
const schema = type.getSchema();
143143
const baseSchema = getBaseJsonSchema(type, ctx);
144144
const value = schema.value;
@@ -214,7 +214,7 @@ function mapToJsonSchema(type: MapType<any>, ctx?: TypeExportContext): JsonSchem
214214
return result;
215215
}
216216

217-
function numberToJsonSchema(type: NumberType, ctx?: TypeExportContext): JsonSchemaNumber {
217+
function numberToJsonSchema(type: NumType, ctx?: TypeExportContext): JsonSchemaNumber {
218218
const schema = type.getSchema();
219219
const baseSchema = getBaseJsonSchema(type, ctx);
220220
const result: JsonSchemaNumber = {
@@ -238,7 +238,7 @@ function numberToJsonSchema(type: NumberType, ctx?: TypeExportContext): JsonSche
238238
return result;
239239
}
240240

241-
function objectToJsonSchema(type: ObjectType<any>, ctx?: TypeExportContext): JsonSchemaObject {
241+
function objectToJsonSchema(type: ObjType<any>, ctx?: TypeExportContext): JsonSchemaObject {
242242
const schema = type.getSchema();
243243
const baseSchema = getBaseJsonSchema(type, ctx);
244244
const result: JsonSchemaObject = {
@@ -294,7 +294,7 @@ function refToJsonSchema(type: RefType<any>, ctx?: TypeExportContext): JsonSchem
294294
return result;
295295
}
296296

297-
function stringToJsonSchema(type: StringType, ctx?: TypeExportContext): JsonSchemaString {
297+
function stringToJsonSchema(type: StrType, ctx?: TypeExportContext): JsonSchemaString {
298298
const schema = type.getSchema();
299299
const baseSchema = getBaseJsonSchema(type, ctx);
300300
const result: JsonSchemaString = {
@@ -323,7 +323,7 @@ function stringToJsonSchema(type: StringType, ctx?: TypeExportContext): JsonSche
323323
return result;
324324
}
325325

326-
function tupleToJsonSchema(type: TupleType<any>, ctx?: TypeExportContext): JsonSchemaArray {
326+
function tupleToJsonSchema(type: TupType<any>, ctx?: TypeExportContext): JsonSchemaArray {
327327
const baseSchema = getBaseJsonSchema(type, ctx);
328328
const types = (type as any).types;
329329
const result: JsonSchemaArray = {

src/random/__tests__/random.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ describe('random generators', () => {
240240

241241
test('handles edge cases and constraints', () => {
242242
// Empty array constraint
243-
const emptyArrayType = t.Array(t.String(), {max: 0});
244-
const emptyArray = emptyArrayType.random();
243+
const emptyArrType = t.Array(t.String(), {max: 0});
244+
const emptyArray = emptyArrType.random();
245245
expect(emptyArray).toEqual([]);
246-
emptyArrayType.validate(emptyArray);
246+
emptyArrType.validate(emptyArray);
247247

248248
// Single item array constraint
249249
const singleItemType = t.Array(t.Number(), {min: 1, max: 1});

src/random/generator.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
import type {AbstractType} from '../type/classes/AbstractType';
1+
import type {AbsType} from '../type/classes/AbsType';
22
import type {AnyType} from '../type/classes/AnyType';
3-
import type {ArrayType} from '../type/classes/ArrayType';
4-
import type {BinaryType} from '../type/classes/BinaryType';
5-
import type {BooleanType} from '../type/classes/BooleanType';
6-
import type {ConstType} from '../type/classes/ConstType';
7-
import type {FunctionType} from '../type/classes/FunctionType';
3+
import type {ArrType} from '../type/classes/ArrType';
4+
import type {BinType} from '../type/classes/BinType';
5+
import type {BoolType} from '../type/classes/BoolType';
6+
import type {ConType} from '../type/classes/ConType';
7+
import type {FunType} from '../type/classes/FunType';
88
import type {MapType} from '../type/classes/MapType';
9-
import type {NumberType} from '../type/classes/NumberType';
10-
import type {ObjectType} from '../type/classes/ObjectType';
9+
import type {NumType} from '../type/classes/NumType';
10+
import type {ObjType} from '../type/classes/ObjType';
1111
import type {OrType} from '../type/classes/OrType';
1212
import type {RefType} from '../type/classes/RefType';
13-
import type {StringType} from '../type/classes/StringType';
14-
import type {TupleType} from '../type/classes/TupleType';
13+
import type {StrType} from '../type/classes/StrType';
14+
import type {TupType} from '../type/classes/TupType';
1515

1616
import * as gen from './generators';
1717

1818
/**
1919
* Main router function that dispatches to the correct random generator based on the type's kind.
2020
* This replaces the individual random() methods in each type class.
2121
*/
22-
export function random(type: AbstractType<any>): unknown {
22+
export function random(type: AbsType<any>): unknown {
2323
const kind = type.getTypeName();
2424

2525
switch (kind) {
2626
case 'any':
2727
return gen.any(type as AnyType);
2828
case 'arr':
29-
return gen.arr(type as ArrayType<any>);
29+
return gen.arr(type as ArrType<any>);
3030
case 'bin':
31-
return gen.bin(type as BinaryType<any>);
31+
return gen.bin(type as BinType<any>);
3232
case 'bool':
33-
return gen.bool(type as BooleanType);
33+
return gen.bool(type as BoolType);
3434
case 'con':
35-
return gen.const_(type as ConstType);
35+
return gen.const_(type as ConType);
3636
case 'fn':
3737
case 'fn$':
38-
return gen.fn(type as FunctionType<any, any>);
38+
return gen.fn(type as FunType<any, any>);
3939
case 'map':
4040
return gen.map(type as MapType<any>);
4141
case 'num':
42-
return gen.num(type as NumberType);
42+
return gen.num(type as NumType);
4343
case 'obj':
44-
return gen.obj(type as ObjectType<any>);
44+
return gen.obj(type as ObjType<any>);
4545
case 'or':
4646
return gen.or(type as OrType<any>);
4747
case 'ref':
4848
return gen.ref(type as RefType<any>);
4949
case 'str':
50-
return gen.str(type as StringType);
50+
return gen.str(type as StrType);
5151
case 'tup':
52-
return gen.tup(type as TupleType<any>);
52+
return gen.tup(type as TupType<any>);
5353
default:
5454
// Fallback to generic random JSON for unknown types
5555
return gen.any(type as AnyType);

src/random/generators.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import {RandomJson} from '@jsonjoy.com/util/lib/json-random';
22
import {cloneBinary} from '@jsonjoy.com/util/lib/json-clone';
33
import type {AnyType} from '../type/classes/AnyType';
4-
import type {ArrayType} from '../type/classes/ArrayType';
5-
import type {BinaryType} from '../type/classes/BinaryType';
6-
import type {BooleanType} from '../type/classes/BooleanType';
7-
import type {ConstType} from '../type/classes/ConstType';
8-
import type {FunctionType} from '../type/classes/FunctionType';
4+
import type {ArrType} from '../type/classes/ArrType';
5+
import type {BinType} from '../type/classes/BinType';
6+
import type {BoolType} from '../type/classes/BoolType';
7+
import type {ConType} from '../type/classes/ConType';
8+
import type {FunType} from '../type/classes/FunType';
99
import type {MapType} from '../type/classes/MapType';
10-
import type {NumberType} from '../type/classes/NumberType';
11-
import type {ObjectType} from '../type/classes/ObjectType';
10+
import type {NumType} from '../type/classes/NumType';
11+
import type {ObjType} from '../type/classes/ObjType';
1212
import type {OrType} from '../type/classes/OrType';
1313
import type {RefType} from '../type/classes/RefType';
14-
import type {StringType} from '../type/classes/StringType';
15-
import type {TupleType} from '../type/classes/TupleType';
14+
import type {StrType} from '../type/classes/StrType';
15+
import type {TupType} from '../type/classes/TupType';
1616

1717
export const any = (type: AnyType): unknown => {
1818
return RandomJson.generate({nodeCount: 5});
1919
};
2020

21-
export const arr = (type: ArrayType<any>): unknown[] => {
21+
export const arr = (type: ArrType<any>): unknown[] => {
2222
let length = Math.round(Math.random() * 10);
2323
const schema = type.getSchema();
2424
const {min, max} = schema;
@@ -31,22 +31,22 @@ export const arr = (type: ArrayType<any>): unknown[] => {
3131
return result;
3232
};
3333

34-
export const bin = (type: BinaryType<any>): Uint8Array => {
34+
export const bin = (type: BinType<any>): Uint8Array => {
3535
const octets = RandomJson.genString()
3636
.split('')
3737
.map((c) => c.charCodeAt(0));
3838
return new Uint8Array(octets);
3939
};
4040

41-
export const bool = (type: BooleanType): boolean => {
41+
export const bool = (type: BoolType): boolean => {
4242
return RandomJson.genBoolean();
4343
};
4444

45-
export const const_ = (type: ConstType): unknown => {
45+
export const const_ = (type: ConType): unknown => {
4646
return cloneBinary(type.getSchema().value);
4747
};
4848

49-
export const fn = (type: FunctionType<any, any>): unknown => {
49+
export const fn = (type: FunType<any, any>): unknown => {
5050
return async () => type.res.random();
5151
};
5252

@@ -59,7 +59,7 @@ export const map = (type: MapType<any>): Record<string, unknown> => {
5959
return res;
6060
};
6161

62-
export const num = (type: NumberType): number => {
62+
export const num = (type: NumType): number => {
6363
let num = Math.random();
6464
let min = Number.MIN_SAFE_INTEGER;
6565
let max = Number.MAX_SAFE_INTEGER;
@@ -117,7 +117,7 @@ export const num = (type: NumberType): number => {
117117
return num;
118118
};
119119

120-
export const obj = (type: ObjectType<any>): Record<string, unknown> => {
120+
export const obj = (type: ObjType<any>): Record<string, unknown> => {
121121
const schema = type.getSchema();
122122
const obj: Record<string, unknown> = schema.unknownFields ? <Record<string, unknown>>RandomJson.genObject() : {};
123123
// Use runtime check to avoid circular import with ObjectOptionalFieldType
@@ -140,7 +140,7 @@ export const ref = (type: RefType<any>): unknown => {
140140
return alias.type.random();
141141
};
142142

143-
export const str = (type: StringType): string => {
143+
export const str = (type: StrType): string => {
144144
let length = Math.round(Math.random() * 10);
145145
const schema = type.getSchema();
146146
const {min, max} = schema;
@@ -149,6 +149,6 @@ export const str = (type: StringType): string => {
149149
return RandomJson.genString(length);
150150
};
151151

152-
export const tup = (type: TupleType<any>): unknown[] => {
152+
export const tup = (type: TupType<any>): unknown[] => {
153153
return (type as any).types.map((subType: any) => subType.random());
154154
};

src/random/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import type {AbstractType} from '../type/classes/AbstractType';
1+
import type {AbsType} from '../type/classes/AbsType';
22

3-
export type RandomGeneratorFunction = (type: AbstractType<any>) => unknown;
3+
export type RandomGeneratorFunction = (type: AbsType<any>) => unknown;

src/system/TypeAlias.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {printTree} from 'tree-dump/lib/printTree';
2-
import {ObjectType} from '../type/classes';
2+
import {ObjType} from '../type/classes';
33
import {toText} from '../typescript/toText';
44
import type {JsonSchemaGenericKeywords, JsonSchemaValueNode} from '../json-schema';
55
import {typeToJsonSchema} from '../json-schema';
@@ -30,7 +30,7 @@ export class TypeAlias<K extends string, T extends Type> implements Printable {
3030

3131
public toTypeScriptAst(): ts.TsInterfaceDeclaration | ts.TsTypeAliasDeclaration {
3232
const type = this.type;
33-
if (type instanceof ObjectType) {
33+
if (type instanceof ObjType) {
3434
const ast = this.type.toTypeScriptAst() as ts.TsTypeLiteral;
3535
const node: ts.TsInterfaceDeclaration = {
3636
node: 'InterfaceDeclaration',

0 commit comments

Comments
 (0)