-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ajsttil): update TypeMetadata without xor metadata
- Loading branch information
1 parent
f3b9467
commit e05f39a
Showing
5 changed files
with
129 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,36 @@ | ||
import { JsonValue } from '@cuaklabs/json-schema-types'; | ||
import { | ||
AndTypeMetadata, | ||
AnyTypeMetadata, | ||
ArrayTypeMetadata, | ||
BooleanTypeMetadata, | ||
FloatTypeMetadata, | ||
IntegerTypeMetadata, | ||
LiteralTypeMetadata, | ||
NoneTypeMetadata, | ||
ObjectTypeMetadata, | ||
OrTypeMetadata, | ||
PropertyTypeMetadata, | ||
StringIndexSignatureType, | ||
StringTypeMetadata, | ||
TypeMedatata, | ||
TypeMetadataKind, | ||
} from './metadata/models/TypeMetadata'; | ||
|
||
export enum TypeMetadataKind { | ||
and, | ||
anyType, | ||
arrayType, | ||
booleanType, | ||
floatType, | ||
integerType, | ||
literalType, | ||
noneType, | ||
objectType, | ||
or, | ||
propertyType, | ||
stringIndexSignatureType, | ||
stringType, | ||
xor, | ||
} | ||
export type { | ||
AndTypeMetadata, | ||
AnyTypeMetadata, | ||
ArrayTypeMetadata, | ||
BooleanTypeMetadata, | ||
FloatTypeMetadata, | ||
IntegerTypeMetadata, | ||
LiteralTypeMetadata, | ||
NoneTypeMetadata, | ||
ObjectTypeMetadata, | ||
OrTypeMetadata, | ||
PropertyTypeMetadata, | ||
StringIndexSignatureType, | ||
StringTypeMetadata, | ||
TypeMedatata, | ||
}; | ||
|
||
export interface BaseTypeMetadata<TKind extends TypeMetadataKind> { | ||
id?: string; | ||
kind: TKind; | ||
} | ||
|
||
export interface OneChildTypeMetadata<TKind extends TypeMetadataKind> | ||
extends BaseTypeMetadata<TKind> { | ||
child: TypeMedatata; | ||
} | ||
|
||
export interface ManyChildrenTypeMetadata< | ||
TKind extends TypeMetadataKind, | ||
TChildren extends TypeMedatata[] = TypeMedatata[], | ||
> extends BaseTypeMetadata<TKind> { | ||
children: TChildren; | ||
} | ||
|
||
export type AndTypeMetadata = ManyChildrenTypeMetadata<TypeMetadataKind.and>; | ||
export type AnyTypeMetadata = BaseTypeMetadata<TypeMetadataKind.anyType>; | ||
export type ArrayTypeMetadata = | ||
OneChildTypeMetadata<TypeMetadataKind.arrayType>; | ||
export type BooleanTypeMetadata = | ||
BaseTypeMetadata<TypeMetadataKind.booleanType>; | ||
export type FloatTypeMetadata = BaseTypeMetadata<TypeMetadataKind.floatType>; | ||
export type IntegerTypeMetadata = | ||
BaseTypeMetadata<TypeMetadataKind.integerType>; | ||
export interface LiteralTypeMetadata | ||
extends BaseTypeMetadata<TypeMetadataKind.literalType> { | ||
literal: JsonValue; | ||
} | ||
export type NoneTypeMetadata = BaseTypeMetadata<TypeMetadataKind.noneType>; | ||
export type ObjectTypeMetadata = BaseTypeMetadata<TypeMetadataKind.objectType>; | ||
export type OrTypeMetadata = ManyChildrenTypeMetadata<TypeMetadataKind.or>; | ||
export interface PropertyTypeMetadata | ||
extends OneChildTypeMetadata<TypeMetadataKind.propertyType> { | ||
isOptional: boolean; | ||
property: string; | ||
} | ||
export type StringIndexSignatureType = | ||
OneChildTypeMetadata<TypeMetadataKind.stringIndexSignatureType>; | ||
export type StringTypeMetadata = BaseTypeMetadata<TypeMetadataKind.stringType>; | ||
export type XorTypeMetadata = ManyChildrenTypeMetadata<TypeMetadataKind.xor>; | ||
|
||
export type TypeMedatata = | ||
| AndTypeMetadata | ||
| AnyTypeMetadata | ||
| ArrayTypeMetadata | ||
| BooleanTypeMetadata | ||
| FloatTypeMetadata | ||
| IntegerTypeMetadata | ||
| LiteralTypeMetadata | ||
| NoneTypeMetadata | ||
| ObjectTypeMetadata | ||
| OrTypeMetadata | ||
| PropertyTypeMetadata | ||
| StringIndexSignatureType | ||
| StringTypeMetadata | ||
| XorTypeMetadata; | ||
export { TypeMetadataKind }; |
11 changes: 11 additions & 0 deletions
11
packages/transformers/ajsttil/src/metadata/calculations/normalize.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TypeMedatata } from '../models/TypeMetadata'; | ||
import { TypeMetadataGrammar } from '../models/TypeMetadataGrammar'; | ||
|
||
export function normalize(typeMetadata: TypeMedatata): TypeMetadataGrammar { | ||
const grammar: TypeMetadataGrammar = { | ||
productions: new Map(), | ||
root: typeMetadata, | ||
}; | ||
|
||
return grammar; | ||
} |
74 changes: 74 additions & 0 deletions
74
packages/transformers/ajsttil/src/metadata/models/TypeMetadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { JsonValue } from '@cuaklabs/json-schema-types'; | ||
|
||
export enum TypeMetadataKind { | ||
and, | ||
anyType, | ||
arrayType, | ||
booleanType, | ||
floatType, | ||
integerType, | ||
literalType, | ||
noneType, | ||
objectType, | ||
or, | ||
propertyType, | ||
stringIndexSignatureType, | ||
stringType, | ||
} | ||
|
||
export interface BaseTypeMetadata<TKind extends TypeMetadataKind> { | ||
id?: string; | ||
kind: TKind; | ||
} | ||
|
||
export interface OneChildTypeMetadata<TKind extends TypeMetadataKind> | ||
extends BaseTypeMetadata<TKind> { | ||
child: TypeMedatata; | ||
} | ||
|
||
export interface ManyChildrenTypeMetadata< | ||
TKind extends TypeMetadataKind, | ||
TChildren extends TypeMedatata[] = TypeMedatata[], | ||
> extends BaseTypeMetadata<TKind> { | ||
children: TChildren; | ||
} | ||
|
||
export type AndTypeMetadata = ManyChildrenTypeMetadata<TypeMetadataKind.and>; | ||
export type AnyTypeMetadata = BaseTypeMetadata<TypeMetadataKind.anyType>; | ||
export type ArrayTypeMetadata = | ||
OneChildTypeMetadata<TypeMetadataKind.arrayType>; | ||
export type BooleanTypeMetadata = | ||
BaseTypeMetadata<TypeMetadataKind.booleanType>; | ||
export type FloatTypeMetadata = BaseTypeMetadata<TypeMetadataKind.floatType>; | ||
export type IntegerTypeMetadata = | ||
BaseTypeMetadata<TypeMetadataKind.integerType>; | ||
export interface LiteralTypeMetadata | ||
extends BaseTypeMetadata<TypeMetadataKind.literalType> { | ||
literal: JsonValue; | ||
} | ||
export type NoneTypeMetadata = BaseTypeMetadata<TypeMetadataKind.noneType>; | ||
export type ObjectTypeMetadata = BaseTypeMetadata<TypeMetadataKind.objectType>; | ||
export type OrTypeMetadata = ManyChildrenTypeMetadata<TypeMetadataKind.or>; | ||
export interface PropertyTypeMetadata | ||
extends OneChildTypeMetadata<TypeMetadataKind.propertyType> { | ||
isOptional: boolean; | ||
property: string; | ||
} | ||
export type StringIndexSignatureType = | ||
OneChildTypeMetadata<TypeMetadataKind.stringIndexSignatureType>; | ||
export type StringTypeMetadata = BaseTypeMetadata<TypeMetadataKind.stringType>; | ||
|
||
export type TypeMedatata = | ||
| AndTypeMetadata | ||
| AnyTypeMetadata | ||
| ArrayTypeMetadata | ||
| BooleanTypeMetadata | ||
| FloatTypeMetadata | ||
| IntegerTypeMetadata | ||
| LiteralTypeMetadata | ||
| NoneTypeMetadata | ||
| ObjectTypeMetadata | ||
| OrTypeMetadata | ||
| PropertyTypeMetadata | ||
| StringIndexSignatureType | ||
| StringTypeMetadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters