Skip to content

Commit

Permalink
Merge pull request #1328 from samchon/feat/protobuf
Browse files Browse the repository at this point in the history
Prepare #1234: refactor metadata schema for `protobuf` sequencing.
  • Loading branch information
samchon authored Oct 14, 2024
2 parents de0b0c0 + b93f803 commit d40502c
Show file tree
Hide file tree
Showing 250 changed files with 4,516 additions and 2,139 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^3.0.0",
"uuid": "^9.0.1",
"typia": "../typia-7.0.0-dev.20241011.tgz"
"typia": "../typia-7.0.0-dev.20241012.tgz"
}
}
23 changes: 0 additions & 23 deletions debug/package.json

This file was deleted.

12 changes: 0 additions & 12 deletions debug/src/protobuf.ts

This file was deleted.

2 changes: 1 addition & 1 deletion errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"typescript": "^5.3.2"
},
"dependencies": {
"typia": "../typia-7.0.0-dev.20241011.tgz"
"typia": "../typia-7.0.0-dev.20241012.tgz"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "7.0.0-dev.20241011",
"version": "7.0.0-dev.20241012",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "7.0.0-dev.20241011",
"version": "7.0.0-dev.20241012",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -63,7 +63,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "7.0.0-dev.20241011"
"typia": "7.0.0-dev.20241012"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.7.0"
Expand Down
7 changes: 5 additions & 2 deletions src/factories/JsonMetadataFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ export namespace JsonMetadataFactory {
if (meta.maps.length) output.push("JSON does not support Map type.");
if (meta.sets.length) output.push("JSON does not support Set type.");
for (const native of meta.natives)
if (AtomicPredicator.native(native) === false && native !== "Date")
output.push(`JSON does not support ${native} type.`);
if (
AtomicPredicator.native(native.name) === false &&
native.name !== "Date"
)
output.push(`JSON does not support ${native.name} type.`);
return output;
};
}
34 changes: 18 additions & 16 deletions src/factories/MetadataCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import ts from "typescript";

import { IMetadataComponents } from "../schemas/metadata/IMetadataComponents";
import { Metadata } from "../schemas/metadata/Metadata";
import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
import { MetadataAliasType } from "../schemas/metadata/MetadataAliasType";
import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
import { MetadataObject } from "../schemas/metadata/MetadataObject";
import { MetadataObjectType } from "../schemas/metadata/MetadataObjectType";
import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";

import { Writable } from "../typings/Writable";
Expand All @@ -15,9 +15,9 @@ import { CommentFactory } from "./CommentFactory";
import { TypeFactory } from "./TypeFactory";

export class MetadataCollection {
private objects_: Map<ts.Type, MetadataObject>;
private object_unions_: Map<string, MetadataObject[]>;
private aliases_: Map<ts.Type, MetadataAlias>;
private objects_: Map<ts.Type, MetadataObjectType>;
private object_unions_: Map<string, MetadataObjectType[]>;
private aliases_: Map<ts.Type, MetadataAliasType>;
private arrays_: Map<ts.Type, MetadataArrayType>;
private tuples_: Map<ts.Type, MetadataTupleType>;

Expand Down Expand Up @@ -58,15 +58,15 @@ export class MetadataCollection {
/* -----------------------------------------------------------
ACCESSORS
----------------------------------------------------------- */
public aliases(): MetadataAlias[] {
public aliases(): MetadataAliasType[] {
return [...this.aliases_.values()];
}

public objects(): MetadataObject[] {
public objects(): MetadataObjectType[] {
return [...this.objects_.values()];
}

public unions(): MetadataObject[][] {
public unions(): MetadataObjectType[][] {
return [...this.object_unions_.values()];
}

Expand Down Expand Up @@ -106,8 +106,10 @@ export class MetadataCollection {
* @internal
*/
public getUnionIndex(meta: Metadata): number {
const key: string = meta.objects.map((obj) => obj.name).join(" | ");
MapUtil.take(this.object_unions_, key, () => meta.objects);
const key: string = meta.objects.map((obj) => obj.type.name).join(" | ");
MapUtil.take(this.object_unions_, key, () =>
meta.objects.map((o) => o.type),
);
return [...this.object_unions_.keys()].indexOf(key);
}

Expand All @@ -117,12 +119,12 @@ export class MetadataCollection {
public emplace(
checker: ts.TypeChecker,
type: ts.Type,
): [MetadataObject, boolean] {
): [MetadataObjectType, boolean] {
const oldbie = this.objects_.get(type);
if (oldbie !== undefined) return [oldbie, false];

const $id: string = this.getName(checker, type);
const obj: MetadataObject = MetadataObject.create({
const obj: MetadataObjectType = MetadataObjectType.create({
name: $id,
properties: [],
description:
Expand All @@ -144,12 +146,12 @@ export class MetadataCollection {
checker: ts.TypeChecker,
type: ts.Type,
symbol: ts.Symbol,
): [MetadataAlias, boolean, (meta: Metadata) => void] {
): [MetadataAliasType, boolean, (meta: Metadata) => void] {
const oldbie = this.aliases_.get(type);
if (oldbie !== undefined) return [oldbie, false, () => {}];

const $id: string = this.getName(checker, type);
const alias: MetadataAlias = MetadataAlias.create({
const alias: MetadataAliasType = MetadataAliasType.create({
name: $id,
value: null!,
description: CommentFactory.description(symbol) ?? null,
Expand Down Expand Up @@ -202,14 +204,14 @@ export class MetadataCollection {
/**
* @internal
*/
public setObjectRecursive(obj: MetadataObject, recursive: boolean): void {
public setObjectRecursive(obj: MetadataObjectType, recursive: boolean): void {
Writable(obj).recursive = recursive;
}

/**
* @internal
*/
public setAliasRecursive(alias: MetadataAlias, recursive: boolean): void {
public setAliasRecursive(alias: MetadataAliasType, recursive: boolean): void {
Writable(alias).recursive = recursive;
}

Expand Down
28 changes: 17 additions & 11 deletions src/factories/MetadataFactory.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import ts from "typescript";

import { Metadata } from "../schemas/metadata/Metadata";
import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
import { MetadataAliasType } from "../schemas/metadata/MetadataAliasType";
import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
import { MetadataConstant } from "../schemas/metadata/MetadataConstant";
import { MetadataFunction } from "../schemas/metadata/MetadataFunction";
import { MetadataObject } from "../schemas/metadata/MetadataObject";
import { MetadataObjectType } from "../schemas/metadata/MetadataObjectType";
import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
import { explore_metadata } from "./internal/metadata/explore_metadata";
import { iterate_metadata_collection } from "./internal/metadata/iterate_metadata_collection";
Expand Down Expand Up @@ -36,9 +37,9 @@ export namespace MetadataFactory {
}
export interface IExplore {
top: boolean;
object: MetadataObject | null;
object: MetadataObjectType | null;
property: string | object | null;
nested: null | MetadataAlias | MetadataArrayType | MetadataTupleType;
nested: null | MetadataAliasType | MetadataArrayType | MetadataTupleType;
parameter: string | null;
output: boolean;
escaped: boolean;
Expand Down Expand Up @@ -185,7 +186,7 @@ export namespace MetadataFactory {
for (const alias of props.metadata.aliases)
validateAlias({
...props,
alias,
alias: alias.type,
});
for (const array of props.metadata.arrays)
validateArray({
Expand All @@ -200,7 +201,7 @@ export namespace MetadataFactory {
for (const object of props.metadata.objects)
validateObject({
...props,
object,
object: object.type,
});
for (const func of props.metadata.functions)
validateFunction({
Expand All @@ -210,7 +211,7 @@ export namespace MetadataFactory {
for (const set of props.metadata.sets)
validateMeta({
...props,
metadata: set,
metadata: set.value,
});
for (const map of props.metadata.maps) {
validateMeta({
Expand Down Expand Up @@ -238,7 +239,7 @@ export namespace MetadataFactory {
transformer?: ts.TransformationContext;
options: IOptions;
visitor: IValidationVisitor;
alias: MetadataAlias;
alias: MetadataAliasType;
explore: IExplore;
}) => {
if (props.visitor.aliases.has(props.alias)) return;
Expand Down Expand Up @@ -302,7 +303,7 @@ export namespace MetadataFactory {
transformer?: ts.TransformationContext;
options: IOptions;
visitor: IValidationVisitor;
object: MetadataObject;
object: MetadataObjectType;
}) => {
if (props.visitor.objects.has(props.object)) return;
props.visitor.objects.add(props.object);
Expand All @@ -321,7 +322,12 @@ export namespace MetadataFactory {
const errors: string[] = props.options.validate(
Metadata.create({
...Metadata.initialize(),
objects: [props.object],
objects: [
MetadataObject.create({
type: props.object,
tags: [],
}),
],
}),
explore,
);
Expand Down Expand Up @@ -391,10 +397,10 @@ export namespace MetadataFactory {
interface IValidationVisitor {
functor: Validator;
errors: IError[];
objects: Set<MetadataObject>;
objects: Set<MetadataObjectType>;
arrays: Set<MetadataArrayType>;
tuples: Set<MetadataTupleType>;
aliases: Set<MetadataAlias>;
aliases: Set<MetadataAliasType>;
functions: Set<MetadataFunction>;
}
}
Loading

0 comments on commit d40502c

Please sign in to comment.