-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tried #1251, but no way to support glob pattern in the generation mode.
- Loading branch information
Showing
28 changed files
with
375 additions
and
57 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "typia", | ||
"version": "6.10.1-dev.20240913", | ||
"version": "6.10.1-dev.20240914", | ||
"description": "Superfast runtime validators with only one line", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
|
@@ -70,6 +70,7 @@ | |
"@samchon/openapi": "^1.0.0", | ||
"commander": "^10.0.0", | ||
"comment-json": "^4.2.3", | ||
"glob": "^7.2.0", | ||
"inquirer": "^8.2.5", | ||
"package-manager-detector": "^0.2.0", | ||
"randexp": "^0.5.3" | ||
|
@@ -82,6 +83,7 @@ | |
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@trivago/prettier-plugin-sort-imports": "^4.3.0", | ||
"@types/glob": "^7.2.0", | ||
"@types/inquirer": "^8.2.5", | ||
"@types/node": "^18.15.12", | ||
"@types/ts-expose-internals": "npm:[email protected]", | ||
|
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
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,56 @@ | ||
import fs from "fs"; | ||
import glob from "glob"; | ||
import path from "path"; | ||
|
||
export namespace SourceFinder { | ||
export interface IProps { | ||
exclude?: string[]; | ||
include: string[]; | ||
filter: (location: string) => boolean; | ||
} | ||
export const find = async (props: IProps): Promise<string[]> => { | ||
const dict: Set<string> = new Set(); | ||
|
||
await emplace(props.filter)(props.include)((str) => dict.add(str)); | ||
if (props.exclude?.length) | ||
await emplace(props.filter)(props.exclude)((str) => dict.delete(str)); | ||
|
||
return [...dict]; | ||
}; | ||
|
||
const emplace = | ||
(filter: (file: string) => boolean) => | ||
(input: string[]) => | ||
async (closure: (location: string) => void): Promise<void> => { | ||
for (const pattern of input) { | ||
for (const file of await _Glob(path.resolve(pattern))) { | ||
const stats: fs.Stats = await fs.promises.stat(file); | ||
if (stats.isDirectory() === true) | ||
await iterate(filter)(closure)(file); | ||
else if (stats.isFile() && filter(file)) closure(file); | ||
} | ||
} | ||
}; | ||
|
||
const iterate = | ||
(filter: (location: string) => boolean) => | ||
(closure: (location: string) => void) => | ||
async (location: string): Promise<void> => { | ||
const directory: string[] = await fs.promises.readdir(location); | ||
for (const file of directory) { | ||
const next: string = path.resolve(`${location}/${file}`); | ||
const stats: fs.Stats = await fs.promises.stat(next); | ||
|
||
if (stats.isDirectory() === true) await iterate(filter)(closure)(next); | ||
else if (stats.isFile() && filter(next)) closure(next); | ||
} | ||
}; | ||
|
||
const _Glob = (pattern: string): Promise<string[]> => | ||
new Promise((resolve, reject) => { | ||
glob(pattern, (err, matches) => { | ||
if (err) reject(err); | ||
else resolve(matches.map((str) => path.resolve(str))); | ||
}); | ||
}); | ||
} |
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
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,2 @@ | ||
import typia from "typia"; | ||
export const equalsFile = (() => { return (input: any, _exceptionable: boolean = true): input is File => input instanceof File; })(); |
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,23 @@ | ||
import typia from "typia"; | ||
export const validateFile = (() => { const __is = (input: any): input is File => input instanceof File; let errors: any; let $report: any; return (input: any): typia.IValidation<File> => { | ||
if (false === __is(input)) { | ||
errors = []; | ||
$report = (typia.createValidate as any).report(errors); | ||
((input: any, _path: string, _exceptionable: boolean = true) => input instanceof File || $report(true, { | ||
path: _path + "", | ||
expected: "File", | ||
value: input | ||
}))(input, "$input", true); | ||
const success = 0 === errors.length; | ||
return { | ||
success, | ||
errors, | ||
data: success ? input : undefined | ||
} as any; | ||
} | ||
return { | ||
success: true, | ||
errors: [], | ||
data: input | ||
} as any; | ||
}; })(); |
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,12 @@ | ||
import typia from "typia"; | ||
export const assertFile = (() => { const $guard = (typia.createAssert as any).guard; const __is = (input: any): input is File => input instanceof File; let _errorFactory: any; return (input: any, errorFactory?: (p: import("typia").TypeGuardError.IProps) => Error): File => { | ||
if (false === __is(input)) { | ||
_errorFactory = errorFactory; | ||
((input: any, _path: string, _exceptionable: boolean = true) => input instanceof File || $guard(true, { | ||
path: _path + "", | ||
expected: "File", | ||
value: input | ||
}, _errorFactory))(input, "$input", true); | ||
} | ||
return input; | ||
}; })(); |
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,2 @@ | ||
import typia from "typia"; | ||
export const isFile = (() => { return (input: any): input is File => input instanceof File; })(); |
21 changes: 21 additions & 0 deletions
21
test-generate/generated/glob/private/private.controller.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,21 @@ | ||
import { createAssert } from "typia"; | ||
import { IPrivate } from "./private.interface"; | ||
export const isPrivate = (() => { const $guard = (createAssert as any).guard; const $io0 = (input: any): boolean => "number" === typeof input.value; const $ao0 = (input: any, _path: string, _exceptionable: boolean = true): boolean => "number" === typeof input.value || $guard(_exceptionable, { | ||
path: _path + ".value", | ||
expected: "number", | ||
value: input.value | ||
}, _errorFactory); const __is = (input: any): input is IPrivate => "object" === typeof input && null !== input && $io0(input); let _errorFactory: any; return (input: any, errorFactory?: (p: import("typia").TypeGuardError.IProps) => Error): IPrivate => { | ||
if (false === __is(input)) { | ||
_errorFactory = errorFactory; | ||
((input: any, _path: string, _exceptionable: boolean = true) => ("object" === typeof input && null !== input || $guard(true, { | ||
path: _path + "", | ||
expected: "IPrivate", | ||
value: input | ||
}, _errorFactory)) && $ao0(input, _path + "", true) || $guard(true, { | ||
path: _path + "", | ||
expected: "IPrivate", | ||
value: input | ||
}, _errorFactory))(input, "$input", true); | ||
} | ||
return input; | ||
}; })(); |
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,3 @@ | ||
export interface IPrivate { | ||
value: number; | ||
} |
21 changes: 21 additions & 0 deletions
21
test-generate/generated/glob/protected/protected.controller.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,21 @@ | ||
import { createAssert } from "typia"; | ||
import { IProtected } from "./protected.interface"; | ||
export const assertProtected = (() => { const $guard = (createAssert as any).guard; const $io0 = (input: any): boolean => "string" === typeof input.id; const $ao0 = (input: any, _path: string, _exceptionable: boolean = true): boolean => "string" === typeof input.id || $guard(_exceptionable, { | ||
path: _path + ".id", | ||
expected: "string", | ||
value: input.id | ||
}, _errorFactory); const __is = (input: any): input is IProtected => "object" === typeof input && null !== input && $io0(input); let _errorFactory: any; return (input: any, errorFactory?: (p: import("typia").TypeGuardError.IProps) => Error): IProtected => { | ||
if (false === __is(input)) { | ||
_errorFactory = errorFactory; | ||
((input: any, _path: string, _exceptionable: boolean = true) => ("object" === typeof input && null !== input || $guard(true, { | ||
path: _path + "", | ||
expected: "IProtected", | ||
value: input | ||
}, _errorFactory)) && $ao0(input, _path + "", true) || $guard(true, { | ||
path: _path + "", | ||
expected: "IProtected", | ||
value: input | ||
}, _errorFactory))(input, "$input", true); | ||
} | ||
return input; | ||
}; })(); |
3 changes: 3 additions & 0 deletions
3
test-generate/generated/glob/protected/protected.interface.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,3 @@ | ||
export interface IProtected { | ||
id: string; | ||
} |
Oops, something went wrong.