Skip to content

Commit

Permalink
Merge pull request ryoppippi#346 from ryoppippi/feature/v07
Browse files Browse the repository at this point in the history
check compatibility to typia v0.7
  • Loading branch information
ryoppippi authored Dec 3, 2024
2 parents 6517d05 + 073d86b commit b35f970
Show file tree
Hide file tree
Showing 30 changed files with 637 additions and 399 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/bun-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"devDependencies": {
"@types/bun": "latest",
"std-env": "^3.7.0",
"typia": "^6.11.3"
"std-env": "^3.8.0",
"typia": "^7.0.1"
},
"peerDependencies": {
"ts-patch": "^3.2.1",
Expand Down
8 changes: 4 additions & 4 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
},
"devDependencies": {
"@ryoppippi/unplugin-typia": "workspace:*",
"@types/node": "^20.17.5",
"@types/node": "^20.17.9",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"ts-patch": "^3.2.1",
"tslib": "^2.8.1",
"type-fest": "^4.26.1",
"typescript": "~5.5.4",
"typia": "^6.11.3"
"type-fest": "^4.30.0",
"typescript": "~5.7.2",
"typia": "^7.0.1"
}
}
16 changes: 8 additions & 8 deletions examples/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
"devDependencies": {
"@sveltejs/adapter-auto": "^3.3.1",
"@sveltejs/adapter-static": "^3.0.6",
"@sveltejs/kit": "^2.7.3",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"shiki": "^1.22.2",
"svelte": "^5.1.9",
"svelte-check": "^3.8.6",
"@sveltejs/kit": "^2.9.0",
"@sveltejs/vite-plugin-svelte": "^5.0.1",
"shiki": "^1.24.0",
"svelte": "^5.4.0",
"svelte-check": "^4.1.0",
"ts-patch": "^3.2.1",
"tslib": "^2.8.1",
"typescript": "~5.5.4",
"typia": "^6.11.3",
"vite": "^5.4.10"
"typescript": "~5.7.2",
"typia": "^7.0.1",
"vite": "^6.0.2"
},
"type": "module",
"dependencies": {
Expand Down
10 changes: 9 additions & 1 deletion examples/sveltekit/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<script lang="ts">
import {type IMember, validate} from "./validate";
import typia, { type tags } from "typia";
const { data } = $props();
interface IMember {
id: string & tags.Format<"uuid">;
email: string & tags.Format<"email">;
age: number & tags.ExclusiveMinimum<19> & tags.Maximum<100>;
}
const validate = typia.createValidate<IMember>();
let member = $state<IMember>({
id: crypto.randomUUID(),
email: "hi@examle.com",
Expand Down
10 changes: 0 additions & 10 deletions examples/sveltekit/src/routes/validate.ts

This file was deleted.

12 changes: 6 additions & 6 deletions examples/vite-hono/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
"prepare": "ts-patch install && typia patch"
},
"dependencies": {
"hono": "^4.6.8",
"uuid": "^9.0.1"
"hono": "^4.6.12",
"uuid": "^11.0.3"
},
"devDependencies": {
"@hono/typia-validator": "^0.0.5",
"@hono/vite-cloudflare-pages": "^0.4.2",
"@hono/vite-dev-server": "^0.12.2",
"@hono/vite-dev-server": "^0.17.0",
"@ryoppippi/unplugin-typia": "workspace:*",
"ts-patch": "^3.2.1",
"typescript": "~5.5.4",
"typia": "^6.11.3",
"vite": "^5.4.10"
"typescript": "~5.7.2",
"typia": "^7.0.1",
"vite": "^6.0.2"
}
}
14 changes: 7 additions & 7 deletions examples/vite-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"uuid": "^9.0.1"
"uuid": "^11.0.3"
},
"devDependencies": {
"@ryoppippi/unplugin-typia": "workspace:*",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/uuid": "^9.0.8",
"@vitejs/plugin-react": "^4.3.3",
"@types/uuid": "^10.0.0",
"@vitejs/plugin-react": "^4.3.4",
"ts-patch": "^3.2.1",
"typescript": "~5.5.4",
"typia": "^6.11.3",
"vite": "^5.4.10",
"vite-plugin-inspect": "^0.8.7"
"typescript": "~5.7.2",
"typia": "^7.0.1",
"vite": "^6.0.2",
"vite-plugin-inspect": "^0.10.3"
}
}
10 changes: 5 additions & 5 deletions examples/webpack-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"name": "webpack-minimal",
"private": true,
"devDependencies": {
"@types/node": "^20.17.5",
"@types/node": "^20.17.9",
"@webpack-cli/generators": "^3.0.7",
"html-webpack-plugin": "^5.6.3",
"prettier": "^3.3.3",
"prettier": "^3.4.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"ts-patch": "^3.2.1",
"tsx": "^4.19.2",
"typescript": "~5.5.4",
"webpack": "^5.96.1",
"typescript": "~5.7.2",
"webpack": "^5.97.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.1.0",
"workbox-webpack-plugin": "^7.3.0"
Expand All @@ -28,6 +28,6 @@
"dependencies": {
"@ryoppippi/unplugin-typia": "workspace:*",
"cross-env": "^7.0.3",
"typia": "^6.11.3"
"typia": "^7.0.1"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"vite-vanilla",
"workerd"
],
"packageManager": "bun@1.1.33",
"packageManager": "bun@1.1.38",
"private": true
}
32 changes: 16 additions & 16 deletions packages/unplugin-typia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@
"defu": "^6.1.4",
"diff-match-patch": "^1.0.5",
"find-cache-dir": "^5.0.0",
"magic-string": "^0.30.12",
"magic-string": "^0.30.14",
"pathe": "^1.1.2",
"pkg-types": "^1.2.1",
"type-fest": "^4.26.1",
"typescript": "~5.5.4",
"typia": "^6.11.3",
"unplugin": "^1.15.0"
"type-fest": "^4.30.0",
"typescript": "~5.6.3",
"typia": "^7.0.1",
"unplugin": "^1.16.0"
},
"devDependencies": {
"@antfu/ni": "^0.22.4",
"@antfu/ni": "^0.23.1",
"@ryoppippi/eslint-config": "npm:@jsr/ryoppippi__eslint-config@^0.0.23",
"@std/collections": "npm:@jsr/std__collections@1.0.5",
"@types/bun": "^1.1.12",
"@types/bun": "^1.1.14",
"@types/diff-match-patch": "^1.0.36",
"@types/node": "^20.17.5",
"@types/node": "^20.17.9",
"@vue-macros/test-utils": "^1.7.0",
"bumpp": "^9.8.0",
"dax-sh": "^0.41.0",
"esbuild": "^0.23.1",
"eslint": "^9.13.0",
"eslint-plugin-format": "^0.1.2",
"rollup": "^4.24.3",
"bumpp": "^9.8.1",
"dax-sh": "^0.42.0",
"esbuild": "^0.24.0",
"eslint": "~9.14.0",
"eslint-plugin-format": "^0.1.3",
"rollup": "^4.28.0",
"ts-patch": "^3.2.1",
"vite": "^5.4.10",
"vitest": "^2.1.4"
"vite": "^6.0.2",
"vitest": "^2.1.8"
},
"access": "public"
}
21 changes: 2 additions & 19 deletions packages/unplugin-typia/src/bun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@ import { type ID, type Source, wrap } from './core/types.js';
/**
* Options for bun plugin
*/
export type BunOptions = {
/**
* Convert path of typia to mjs
* even though typia provides mjs, bun cannot handle it (because typia's package.json has "type": "commonjs").
* @default true
*/
forceImportTypiaMjs?: boolean;
} & Options;
export type BunOptions = Options;

if (!isBun()) {
throw new Error('You must use this plugin with bun');
Expand Down Expand Up @@ -110,7 +103,7 @@ function bunTypiaPlugin(
const bunPlugin = ({
name: 'unplugin-typia',
async setup(build) {
const { forceImportTypiaMjs = true, ...options } = bunOptions ?? {};
const { ...options } = bunOptions ?? {};
const resolvedOptions = resolveOptions(options ?? {});
const { include } = resolvedOptions;

Expand Down Expand Up @@ -149,16 +142,6 @@ function bunTypiaPlugin(
return { contents: code ?? source };
});
}

/** if input is ./node_modules/typia/lib/*, convert js to mjs */
if (forceImportTypiaMjs) {
build.onLoad({ filter: /.+\/node_modules\/typia\/lib\/.*\.js$/ }, async (args) => {
const { path } = args;
const mjsPath = path.replace(/\.js$/, '.mjs');

return { contents: await Bun.file(mjsPath).text() };
});
}
},
}) as const satisfies BunPlugin;

Expand Down
6 changes: 3 additions & 3 deletions packages/unplugin-typia/src/core/typia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function transformTypia(
* @param tsconfigId - The tsconfig.json path. @default undefined
*/
async function getTsCompilerOption(cacheEnable = true, tsconfigId?: string): Promise<ts.CompilerOptions> {
const parseTsComilerOptions = async () => {
const parseTsCompilerOptions = async () => {
const readFile = (path: string) => ts.sys.readFile(path);
const id = (tsconfigId != null) ? resolve(tsconfigId) : await resolveTSConfig();

Expand All @@ -81,10 +81,10 @@ async function getTsCompilerOption(cacheEnable = true, tsconfigId?: string): Pro

/** parse tsconfig compilerOptions */
if (cacheEnable) {
compilerOptions ??= await parseTsComilerOptions();
compilerOptions ??= await parseTsCompilerOptions();
}
else {
compilerOptions = await parseTsComilerOptions();
compilerOptions = await parseTsCompilerOptions();
}

return compilerOptions;
Expand Down
78 changes: 31 additions & 47 deletions packages/unplugin-typia/tests/fixtures/__snapshots__/alias.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,67 @@
import * as __typia_transform__isFormatEmail from "typia/lib/internal/_isFormatEmail.js";
import * as __typia_transform__isFormatUuid from "typia/lib/internal/_isFormatUuid.js";
import * as __typia_transform__isTypeUint32 from "typia/lib/internal/_isTypeUint32.js";
import * as __typia_transform__randomFormatEmail from "typia/lib/internal/_randomFormatEmail.js";
import * as __typia_transform__randomFormatUuid from "typia/lib/internal/_randomFormatUuid.js";
import * as __typia_transform__randomInteger from "typia/lib/internal/_randomInteger.js";
import * as __typia_transform__validateReport from "typia/lib/internal/_validateReport.js";
import type { IMember } from '@/type.js';
import typia from 'typia';
const is = (() => { const $io0 = (input: any): boolean => "string" === typeof input.email && /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(input.email) && ("string" === typeof input.id && /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(input.id)) && ("number" === typeof input.age && (Math.floor(input.age) === input.age && 0 <= input.age && input.age <= 4294967295 && 19 < input.age && input.age <= 100)); return (input: any): input is IMember => "object" === typeof input && null !== input && $io0(input); })();
const random = (() => { const $generator = (typia.createRandom as any).generator; const $ro0 = (_recursive: boolean = false, _depth: number = 0): any => ({
email: (_generator?.customs ?? $generator.customs)?.string?.([
{
name: "Format<\"email\">",
kind: "format",
value: "email"
}
]) ?? (_generator?.email ?? $generator.email)(),
id: (_generator?.customs ?? $generator.customs)?.string?.([
{
name: "Format<\"uuid\">",
kind: "format",
value: "uuid"
}
]) ?? (_generator?.uuid ?? $generator.uuid)(),
age: (_generator?.customs ?? $generator.customs)?.number?.([
{
name: "Type<\"uint32\">",
kind: "type",
value: "uint32"
},
{
name: "ExclusiveMinimum<19>",
kind: "exclusiveMinimum",
value: 19
},
{
name: "Maximum<100>",
kind: "maximum",
value: 100
}
]) ?? (_generator?.integer ?? $generator.integer)(20, 100)
}); let _generator: any; return (generator?: Partial<typia.IRandomGenerator>): import("typia").Resolved<IMember> => {
const is = (() => { const _io0 = (input: any): boolean => "string" === typeof input.email && __typia_transform__isFormatEmail._isFormatEmail(input.email) && ("string" === typeof input.id && __typia_transform__isFormatUuid._isFormatUuid(input.id)) && ("number" === typeof input.age && (__typia_transform__isTypeUint32._isTypeUint32(input.age) && 19 < input.age && input.age <= 100)); return (input: any): input is IMember => "object" === typeof input && null !== input && _io0(input); })();
const random = (() => { const _ro0 = (_recursive: boolean = false, _depth: number = 0): any => ({
email: (_generator?.email ?? __typia_transform__randomFormatEmail._randomFormatEmail)(),
id: (_generator?.uuid ?? __typia_transform__randomFormatUuid._randomFormatUuid)(),
age: (_generator?.integer ?? __typia_transform__randomInteger._randomInteger)({
type: "integer",
exclusiveMinimum: true,
minimum: 19,
maximum: 100
})
}); let _generator: Partial<import("typia").IRandomGenerator> | undefined; return (generator?: Partial<import("typia").IRandomGenerator>): import("typia").Resolved<IMember> => {
_generator = generator;
return $ro0();
return _ro0();
}; })();
const validate = (() => { const $io0 = (input: any): boolean => "string" === typeof input.email && /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(input.email) && ("string" === typeof input.id && /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(input.id)) && ("number" === typeof input.age && (Math.floor(input.age) === input.age && 0 <= input.age && input.age <= 4294967295 && 19 < input.age && input.age <= 100)); const $vo0 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ["string" === typeof input.email && (/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(input.email) || $report(_exceptionable, {
const validate = (() => { const _io0 = (input: any): boolean => "string" === typeof input.email && __typia_transform__isFormatEmail._isFormatEmail(input.email) && ("string" === typeof input.id && __typia_transform__isFormatUuid._isFormatUuid(input.id)) && ("number" === typeof input.age && (__typia_transform__isTypeUint32._isTypeUint32(input.age) && 19 < input.age && input.age <= 100)); const _vo0 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ["string" === typeof input.email && (__typia_transform__isFormatEmail._isFormatEmail(input.email) || _report(_exceptionable, {
path: _path + ".email",
expected: "string & Format<\"email\">",
value: input.email
})) || $report(_exceptionable, {
})) || _report(_exceptionable, {
path: _path + ".email",
expected: "(string & Format<\"email\">)",
value: input.email
}), "string" === typeof input.id && (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(input.id) || $report(_exceptionable, {
}), "string" === typeof input.id && (__typia_transform__isFormatUuid._isFormatUuid(input.id) || _report(_exceptionable, {
path: _path + ".id",
expected: "string & Format<\"uuid\">",
value: input.id
})) || $report(_exceptionable, {
})) || _report(_exceptionable, {
path: _path + ".id",
expected: "(string & Format<\"uuid\">)",
value: input.id
}), "number" === typeof input.age && (Math.floor(input.age) === input.age && 0 <= input.age && input.age <= 4294967295 || $report(_exceptionable, {
}), "number" === typeof input.age && (__typia_transform__isTypeUint32._isTypeUint32(input.age) || _report(_exceptionable, {
path: _path + ".age",
expected: "number & Type<\"uint32\">",
value: input.age
})) && (19 < input.age || $report(_exceptionable, {
})) && (19 < input.age || _report(_exceptionable, {
path: _path + ".age",
expected: "number & ExclusiveMinimum<19>",
value: input.age
})) && (input.age <= 100 || $report(_exceptionable, {
})) && (input.age <= 100 || _report(_exceptionable, {
path: _path + ".age",
expected: "number & Maximum<100>",
value: input.age
})) || $report(_exceptionable, {
})) || _report(_exceptionable, {
path: _path + ".age",
expected: "(number & Type<\"uint32\"> & ExclusiveMinimum<19> & Maximum<100>)",
value: input.age
})].every((flag: boolean) => flag); const __is = (input: any): input is IMember => "object" === typeof input && null !== input && $io0(input); let errors: any; let $report: any; return (input: any): typia.IValidation<IMember> => {
})].every((flag: boolean) => flag); const __is = (input: any): input is IMember => "object" === typeof input && null !== input && _io0(input); let errors: any; let _report: any; return (input: any): import("typia").IValidation<IMember> => {
if (false === __is(input)) {
errors = [];
$report = (typia.createValidate as any).report(errors);
((input: any, _path: string, _exceptionable: boolean = true) => ("object" === typeof input && null !== input || $report(true, {
_report = (__typia_transform__validateReport._validateReport as any)(errors);
((input: any, _path: string, _exceptionable: boolean = true) => ("object" === typeof input && null !== input || _report(true, {
path: _path + "",
expected: "IMember",
value: input
})) && $vo0(input, _path + "", true) || $report(true, {
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IMember",
value: input
Expand Down
Loading

0 comments on commit b35f970

Please sign in to comment.