Skip to content

Releases: samchon/typia

v5.0.4

15 Sep 07:37
Compare
Choose a tag to compare

What's Changed

  • Change converter of comment tag to type tag. by @samchon in #810

Full Changelog: v5.0.3...v5.0.4

v5.0.3

10 Sep 09:05
f6c93a6
Compare
Choose a tag to compare

What's Changed

  • Close #800 - add type tags info on JSON schema, and fix special character name bug. by @samchon in #808

Full Changelog: v5.0.2...v5.0.3

v5.0.2

05 Sep 03:20
e387322
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v5.0.1...v5.0.2

v5.0.1

31 Aug 03:55
4c208c8
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v5.0.0...v5.0.1

v5.0.0

29 Aug 17:49
01f6925
Compare
Choose a tag to compare

New Features

Protocol Buffer

https://typia.io/docs/protobuf/message/

Typia v5 supports Protocol Buffer functions.

Lots of TypeScript users had requested this feature, and I've implemented.

@lemon-mint helped me a lot, and repository as-proto (of @piotr-oles) was great to reference.

Now, let's encode to protocol buffer binary data with only one line function call, as always we've done.

export namespace protobuf {
    export function message<T>(): string; // Protocol Buffer message
    export function assertDecode<T>(buffer: Buffer): T; // safe decoder
    export function assertEncode<T>(input: T): Uint8Array; // safe encoder
}

Type Tags

https://typia.io/docs/validators/tags/

Typia v5 supports new type tags for custom validation.

From now on, making custom validation logic is much easier and safer than before.

import typia, { tags } from "typia";

export const checkSomething = typia.createIs<Something>();

//----
// DEFINE CUSTOM TYPE TAGS
//----
type Dollar = tags.TagBase<{
    kind: "dollar";
    target: "string";
    value: undefined;
    validate: `$input[0] === "$" && !isNaN(Number($input.substring(1).split(",").join("")))`;
}>;

type Postfix<Value extends string> = tags.TagBase<{
    kind: "postfix";
    target: "string";
    value: Value;
    validate: `$input.endsWith("${Value}")`;
}>;

type IsEven<Value extends number | bigint> = tags.TagBase<{
    kind: "isEven";
    target: Value extends number ? "number" : "bigint";
    value: undefined;
    validate: `$input % ${Numeric<2>} === ${Numeric<0>}`;
}>;

type Numeric<Value extends number | bigint> = Value extends number
    ? Value
    : `BigInt(${Value})`;

Advances

Compile Error Reporting

https://typia.io/docs/protobuf/message/#restrictions

When user tries to call typia function with unsupported type like bigint type for JSON functions, typia had occured exception that kills TypeScript compiler, even when running tsc --watch command. It was not a critical problem, because except bigint type, functions in typia supported every TypeScript type.

However, as typia starts supporting Protocol Buffer functions in v5 update, and expression power of Protocol Buffer is extremely narrower than TypeScript type specs. User may try many types in Protocol Buffer functions, and gradually fix their TypeScript types referencing error message from typia. In that circumstance, if typia kills tsc --watch command whenever unsupported type comes, it would be a great annoying problem for users.

Therefore, I've changed typia to create compilation error instead of throwing exception. From now on, whenever you take a mistake on typia functions with unsupported types, it would be a compilation error, and would be printed on your console like below

main.ts:13:1 - error TS(typia.protobuf.message): unsupported type detected

- Something.any: any
  - does not support any type

- Something.unknown: any
  - does not support any type

- Something.closure: unknown
  - does not support functional type

- Something.dict: (Set<string> | WeakMap | WeakSet)
  - does not support Set type
  - does not support WeakSet type. Use Array type instead.
  - does not support WeakMap type. Use Map type instead.

- Something.date: Date
  - does not support Date type. Use string type instead.

- Something.classic: String
  - does not support String type. Use string type instead.

- Something.buffer: ArrayBuffer
  - does not support ArrayBuffer type. Use Uint8Array type instead.

Much more test functions

As type system of Protocol Buffer is extremely different with TypeScript (expression power of Protocol Buffer is much lower than TypeScript), I had to develop much more test programs. Especially, to support restrictions of Protocol Buffer types, I've added a new genre of test programs that simulating compilation errors that must be happened.

As a result of such development, LOC of test programs are reaching to 1,400,000. It was a hard time for me, but of that, I believe that users of typia can use it with more confidence. From now on, my slogan is "The word best validator library ensured by 1.4M LOC test codes.". You typia users, as almost all types of TypeScript are rigorously verified with a test program, just use it with confidence.

random() function

https://typia.io/docs/random/

Until v4 version, typia.random<T>() function could not generate bigint or Uint8Array type, because it had been designed for JSON data, especially for RestAPI backend environments (I'd used it for mockup simulator generator - https://nestia.io/docs/sdk/simulator/). By the way, as v5 version starts supporting Protocol Buffer features, I've also advanced typia.random<T>() function.

Therefore, return type of typia.random<T>() function has been changed from Primitive<T> type to Resolved<T> to support bigint and Uint8Array types. Also, as v5 version of typia supports advanced custom validation feature, typia.random<T>() function also changed its custom random data generation interface to be much efficient.

Breaking Changes

Namespace refactoring

// RUNTIME VALIDATORS
export function is<T>(input: unknown): input is T; // returns boolean
export function assert<T>(input: unknown): T; // throws TypeGuardError
export function validate<T>(input: unknown): IValidation<T>; // detailed

// JSON FUNCTIONS
export namespace json {
    export function application<T>(): IJsonApplication; // JSON schema
    export function assertParse<T>(input: string): T; // type safe parser
    export function assertStringify<T>(input: T): string; // safe and faster
}

// PROTOCOL BUFFER
export namespace protobuf {
    export function message<T>(): string; // Protocol Buffer message
    export function assertDecode<T>(buffer: Buffer): T; // safe decoder
    export function assertEncode<T>(input: T): Uint8Array; // safe encoder
}

// RANDOM GENERATOR
export function random<T>(g?: Partial<IRandomGenerator>): T;

As typia has started supporting Protocol Buffer, and planning to support much more binary related protocols like CBOR and MessagePack (#514), I've wrapped JSON related functions into a json namespace. Also, Protocol Buffer functions are capsuled into the protobuf namespace.

I'm sorry for users about such critical changes, but I believe you can easily adjust to it. Also, such namespace wrapping would make typia much efficient especially for extensionability in future.

Shrink of Comment Tags

https://typia.io/docs/validators/tags/#comment-tags

Until v4 version, comment tags could be adjusted to a element (value) type of Array and Map.

However, since v5 version, comment tags only be applied to the target type.


What's Changed

New Contributors

Full Changelog: v4.3.3...v5.0.0

v4.3.3

25 Aug 18:19
bbb353f
Compare
Choose a tag to compare

What's Changed

Full Changelog: v4.3.2...v4.3.3

v4.3.2

21 Aug 03:00
bcca37c
Compare
Choose a tag to compare

From v4.3 update, below type comment tags being supported.

Also, in the bigint case, it can use @type uint64 comment tag for unsigned bigint restriction.

For reference, such type comment tags are designed to prepare the next v5 update, Protocol Buffer supporting.

  • @type {string}
    • int / int32: -2^31 <= x <= 2^31 - 1
    • uint / uint32: 0 <= x <= 2^32 - 1
    • uint64: 0 <= x <= 2^64 - 1
    • int64: -2^63 <= x <= 2^63 - 1
    • float: -1.175494351e38 <= x <= 3.4028235e38

What's Changed

Full Changelog: v4.2.3...v4.3.2

v4.2.3

14 Aug 18:35
ef88a0b
Compare
Choose a tag to compare

What's Changed

Full Changelog: v4.2.2...v4.2.3

v4.2.2

13 Aug 14:04
5489d2e
Compare
Choose a tag to compare

What's Changed

Full Changelog: v4.2.1...v4.2.2

v4.2.1

08 Aug 13:16
dce2551
Compare
Choose a tag to compare

When typia.stringify<T>() be used for an object type which has template typed key containing a number type, and exponential log being used in the template key type, typia could not write the property because regex pattern for numeric value of typia had not supported the exponential log value.

This is an extremely rare case, but fixed for extensionality.

export interface ISomething {
    [key: `value_${number}`]: boolean | string | number;
}

const something: ISomething = {
    "5.175933557310941e-7": -0.170261004873707,
};
typia.stringify(something);

What's Changed

  • Enhance #744 - silent setup and enhanced documentation. by @samchon in #748
  • Fix number pattern of stringify to support exponential log value by @samchon in #749
  • Benchmark on Surface Pro 6 by @samchon in #750

Full Changelog: v4.2.0...v4.2.1