Comparing version 3.6.0-dev.20230219 to 3.6.0-dev.20230225
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -67,2 +44,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var path_1 = __importDefault(require("path")); | ||
var FileRetriever_1 = require("./FileRetriever"); | ||
var ArgumentParser; | ||
@@ -77,3 +55,2 @@ (function (ArgumentParser) { | ||
return __generator(this, function (_a) { | ||
var _b, _c; | ||
switch (_a.label) { | ||
@@ -95,6 +72,6 @@ case 0: | ||
}; | ||
return [4, (_b = path_1.default.join(pack.directory, "node_modules", "commander"), Promise.resolve().then(function () { return __importStar(require(_b)); }))]; | ||
return [4, FileRetriever_1.FileRetriever.require(path_1.default.join("node_modules", "commander"))(pack.directory)]; | ||
case 1: | ||
command = (_a.sent()).program; | ||
return [4, (_c = path_1.default.join(pack.directory, "node_modules", "inquirer"), Promise.resolve().then(function () { return __importStar(require(_c)); }))]; | ||
return [4, FileRetriever_1.FileRetriever.require(path_1.default.join("node_modules", "inquirer"))(pack.directory)]; | ||
case 2: | ||
@@ -101,0 +78,0 @@ prompt = (_a.sent()).createPromptModule; |
@@ -46,2 +46,3 @@ "use strict"; | ||
var CommandExecutor_1 = require("./CommandExecutor"); | ||
var FileRetriever_1 = require("./FileRetriever"); | ||
var PackageManager = (function () { | ||
@@ -65,3 +66,3 @@ function PackageManager(directory, data) { | ||
switch (_c.label) { | ||
case 0: return [4, find(process.cwd())]; | ||
case 0: return [4, FileRetriever_1.FileRetriever.directory("package.json")(process.cwd())]; | ||
case 1: | ||
@@ -99,3 +100,3 @@ location = _c.sent(); | ||
if (!!(container === null || container === void 0 ? void 0 : container[props.modulo]) && | ||
fs_1.default.existsSync(path_1.default.join(this.directory, "node_modules", props.modulo))) | ||
FileRetriever_1.FileRetriever.file(path_1.default.join("node_modules", props.modulo))(this.directory) !== null) | ||
return false; | ||
@@ -128,17 +129,2 @@ var middle = this.manager === "yarn" | ||
exports.PackageManager = PackageManager; | ||
function find(directory, depth) { | ||
if (directory === void 0) { directory = process.cwd(); } | ||
if (depth === void 0) { depth = 0; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var location; | ||
return __generator(this, function (_a) { | ||
location = path_1.default.join(directory, "package.json"); | ||
if (fs_1.default.existsSync(location)) | ||
return [2, directory]; | ||
else if (depth > 1) | ||
return [2, null]; | ||
return [2, find(path_1.default.join(directory, ".."), depth + 1)]; | ||
}); | ||
}); | ||
} | ||
//# sourceMappingURL=PackageManager.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -68,2 +45,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var path_1 = __importDefault(require("path")); | ||
var FileRetriever_1 = require("./FileRetriever"); | ||
var PluginConfigurator; | ||
@@ -120,5 +98,4 @@ (function (PluginConfigurator) { | ||
return __generator(this, function (_c) { | ||
var _d; | ||
switch (_c.label) { | ||
case 0: return [4, (_d = path_1.default.join(pack.directory, "node_modules", "comment-json"), Promise.resolve().then(function () { return __importStar(require(_d)); }))]; | ||
case 0: return [4, FileRetriever_1.FileRetriever.require(path_1.default.join("node_modules", "comment-json"))(pack.directory)]; | ||
case 1: | ||
@@ -125,0 +102,0 @@ Comment = _c.sent(); |
@@ -42,3 +42,3 @@ #!/usr/bin/env node | ||
var TypiaSetupWizard_1 = require("./TypiaSetupWizard"); | ||
var USAGE = "Wrong command has been detected. Use like below:\n\n npx typia setup \\\n --compiler (ttypescript|ts-patch) \\\n --manager (npm|pnpm|yarn) \\\n --project {tsconfig.json file path}\n\n - npx typia setup\n - npx typia setup --compiler ts-patch\n - npx typia setup --manager pnpm\n - npx typia setup --project tsconfig.test.json\n\n npx typia generate \n --input {directory} \\\n --output {directory}\n\n --npx typia setup --input src/templates --output src/functinoal\n"; | ||
var USAGE = "Wrong command has been detected. Use like below:\n\n npx typia setup \\\n --compiler (ttypescript|ts-patch) \\\n --manager (npm|pnpm|yarn) \\\n --project {tsconfig.json file path}\n\n - npx typia setup\n - npx typia setup --compiler ts-patch\n - npx typia setup --manager pnpm\n - npx typia setup --project tsconfig.test.json\n\n npx typia generate \n --input {directory} \\\n --output {directory}\n\n --npx typia generate --input src/templates --output src/functinoal\n"; | ||
function halt(desc) { | ||
@@ -45,0 +45,0 @@ console.error(desc); |
@@ -44,3 +44,3 @@ "use strict"; | ||
var fs_1 = __importDefault(require("fs")); | ||
var TypiaGenerator_1 = require("../generate/TypiaGenerator"); | ||
var TypiaFileFactory_1 = require("../factories/TypiaFileFactory"); | ||
var ArgumentParser_1 = require("./setup/ArgumentParser"); | ||
@@ -66,3 +66,3 @@ var PackageManager_1 = require("./setup/PackageManager"); | ||
options = _a.sent(); | ||
return [4, TypiaGenerator_1.TypiaGenerator.generate(options)]; | ||
return [4, TypiaFileFactory_1.TypiaFileFactory.generate(options)]; | ||
case 3: | ||
@@ -80,4 +80,4 @@ _a.sent(); | ||
return __generator(this, function (_a) { | ||
command.option("--input <path>", "input directory"); | ||
command.option("--output <directory>", "output directory"); | ||
command.option("--input [path]", "input directory"); | ||
command.option("--output [directory]", "output directory"); | ||
command.option("--project [project]", "tsconfig.json file location"); | ||
@@ -84,0 +84,0 @@ questioned = { value: false }; |
@@ -43,3 +43,4 @@ "use strict"; | ||
function getFullName(checker, type, symbol) { | ||
symbol || (symbol = type.aliasSymbol || type.getSymbol()); | ||
var _a; | ||
symbol !== null && symbol !== void 0 ? symbol : (symbol = (_a = type.aliasSymbol) !== null && _a !== void 0 ? _a : type.getSymbol()); | ||
if (symbol === undefined) | ||
@@ -46,0 +47,0 @@ return checker.typeToString(type); |
export interface IRandomGenerator { | ||
boolean(): boolean; | ||
int(minimum?: number, maximum?: number): number; | ||
integer(minimum?: number, maximum?: number): number; | ||
number(minimum?: number, maximum?: number): number; | ||
@@ -8,9 +8,9 @@ bigint(minimum?: bigint, maximum?: bigint): bigint; | ||
array<T>(closure: (index: number) => T, count?: number): T[]; | ||
uuid?(): string; | ||
email?(): string; | ||
url?(): string; | ||
ipv4?(): string; | ||
ipv6?(): string; | ||
pattern?(regex: RegExp): string; | ||
date?(): string; | ||
uuid(): string; | ||
email(): string; | ||
url(): string; | ||
ipv4(): string; | ||
ipv6(): string; | ||
pattern(regex: RegExp): string; | ||
date(): string; | ||
} |
@@ -663,3 +663,3 @@ import { IJsonApplication } from "./schemas/IJsonApplication"; | ||
*/ | ||
export declare function random(generator?: IRandomGenerator): never; | ||
export declare function random(generator?: Partial<IRandomGenerator>): never; | ||
/** | ||
@@ -676,3 +676,3 @@ * Generate random data. | ||
* @template T Type of data to generate | ||
* generator Random data generator | ||
* @param generator Random data generator | ||
* @return Randomly generated data | ||
@@ -682,3 +682,3 @@ * | ||
*/ | ||
export declare function random<T>(generator?: IRandomGenerator): Primitive<T>; | ||
export declare function random<T>(generator?: Partial<IRandomGenerator>): Primitive<T>; | ||
/** | ||
@@ -1215,3 +1215,3 @@ * Clone a data. | ||
* @danger You have to specify the generic argument `T` | ||
* generator Random data generator | ||
* @param generator Random data generator | ||
* @return Nothing until specifying the generic argument `T` | ||
@@ -1222,3 +1222,3 @@ * @throws compile error | ||
*/ | ||
export declare function createRandom(generator?: IRandomGenerator): never; | ||
export declare function createRandom(generator?: Partial<IRandomGenerator>): never; | ||
/** | ||
@@ -1228,3 +1228,3 @@ * Creates a resuable {@link random} function. | ||
* @template T Type of the input value | ||
* generator Random data generator | ||
* @param generator Random data generator | ||
* @returns A reusable `random` function | ||
@@ -1234,3 +1234,3 @@ * | ||
*/ | ||
export declare function createRandom<T>(generator?: IRandomGenerator): () => Primitive<T>; | ||
export declare function createRandom<T>(generator?: Partial<IRandomGenerator>): () => Primitive<T>; | ||
/** | ||
@@ -1237,0 +1237,0 @@ * Creates a reusable {@link clone} function. |
@@ -33,3 +33,3 @@ /** | ||
type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false; | ||
type _Primitive<Instance> = _ValueOf<Instance> extends object ? Instance extends object ? Instance extends IJsonable<infer Raw> ? _ValueOf<Raw> extends object ? Raw extends object ? _PrimitiveObject<Raw> : never : _ValueOf<Raw> : _PrimitiveObject<Instance> : never : _ValueOf<Instance>; | ||
type _Primitive<Instance> = _ValueOf<Instance> extends object ? Instance extends object ? Instance extends _Native ? {} : Instance extends IJsonable<infer Raw> ? _ValueOf<Raw> extends object ? Raw extends object ? _PrimitiveObject<Raw> : never : _ValueOf<Raw> : _PrimitiveObject<Instance> : never : _ValueOf<Instance>; | ||
type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T> ? _Primitive<T>[] : { | ||
@@ -39,2 +39,3 @@ [P in keyof Instance]: Instance[P] extends Function ? never : _Primitive<Instance[P]>; | ||
type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true ? boolean : _IsValueOf<Instance, Number> extends true ? number : _IsValueOf<Instance, String> extends true ? string : Instance; | ||
type _Native = Set<any> | Map<any, any> | WeakSet<any> | WeakMap<any, any> | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | BigUint64Array | Int8Array | Int16Array | Int32Array | BigInt64Array | Float32Array | Float64Array | ArrayBuffer | SharedArrayBuffer | DataView; | ||
type _IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object ? Object extends IValueOf<infer Primitive> ? Instance extends Primitive ? false : true : false : false; | ||
@@ -41,0 +42,0 @@ interface IValueOf<T> { |
@@ -28,8 +28,5 @@ "use strict"; | ||
return function (type) { | ||
var _a, _b; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("any")), | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.Primitive", [ | ||
(_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), | ||
]), undefined, typescript_1.default.factory.createBlock([ | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.Primitive<".concat(TypeFactory_1.TypeFactory.getFullName(project.checker, type), ">")), undefined, typescript_1.default.factory.createBlock([ | ||
StatementFactory_1.StatementFactory.constant("assert", AssertProgrammer_1.AssertProgrammer.generate(project, modulo)(type)), | ||
@@ -39,3 +36,3 @@ StatementFactory_1.StatementFactory.constant("clone", CloneProgrammer_1.CloneProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: false }) }), modulo)(type)), | ||
StatementFactory_1.StatementFactory.constant("output", typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("clone"), undefined, [typescript_1.default.factory.createIdentifier("input")])), | ||
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createAsExpression(typescript_1.default.factory.createIdentifier("output"), (_b = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _b !== void 0 ? _b : TypeFactory_1.TypeFactory.keyword("any"))), | ||
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createIdentifier("output")), | ||
])); | ||
@@ -42,0 +39,0 @@ }; |
@@ -27,8 +27,5 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("string")), | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.Primitive", [ | ||
(_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), | ||
]), undefined, typescript_1.default.factory.createBlock([ | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.Primitive<".concat(TypeFactory_1.TypeFactory.getFullName(project.checker, type), ">")), undefined, typescript_1.default.factory.createBlock([ | ||
StatementFactory_1.StatementFactory.constant("assert", AssertProgrammer_1.AssertProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: false }) }), modulo)(type)), | ||
@@ -35,0 +32,0 @@ typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createIdentifier("input"), typescript_1.default.SyntaxKind.EqualsToken, typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("JSON.parse"), undefined, [typescript_1.default.factory.createIdentifier("input")]))), |
@@ -45,3 +45,2 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
var importer = new FunctionImporeter_1.FunctionImporter(); | ||
@@ -61,3 +60,3 @@ var program = CheckerProgrammer_1.CheckerProgrammer.generate(project, { | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("any")), | ||
], undefined, undefined, typescript_1.default.factory.createBlock(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), [ | ||
], typescript_1.default.factory.createTypeReferenceNode(TypeFactory_1.TypeFactory.getFullName(project.checker, type)), undefined, typescript_1.default.factory.createBlock(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), [ | ||
typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createCallExpression(program, undefined, [ | ||
@@ -68,3 +67,3 @@ typescript_1.default.factory.createIdentifier("input"), | ||
])), | ||
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createAsExpression(typescript_1.default.factory.createIdentifier("input"), (_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"))), | ||
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createIdentifier("input")), | ||
], false), true)); | ||
@@ -82,4 +81,4 @@ }; | ||
var path = explore.postfix | ||
? "path + ".concat(explore.postfix) | ||
: "path"; | ||
? "_path + ".concat(explore.postfix) | ||
: "_path"; | ||
return function (logic) { return function (input, binaries, expected) { | ||
@@ -93,3 +92,3 @@ return logic === "and" | ||
? typescript_1.default.factory.createTrue() | ||
: typescript_1.default.factory.createIdentifier("exceptionable"))(typescript_1.default.factory.createIdentifier(path), expected, input)); | ||
: typescript_1.default.factory.createIdentifier("_exceptionable"))(typescript_1.default.factory.createIdentifier(path), expected, input)); | ||
}) | ||
@@ -104,3 +103,3 @@ .reduce(typescript_1.default.factory.createLogicalAnd) | ||
? typescript_1.default.factory.createTrue() | ||
: typescript_1.default.factory.createIdentifier("exceptionable"))(typescript_1.default.factory.createIdentifier(path), expected, input), | ||
: typescript_1.default.factory.createIdentifier("_exceptionable"))(typescript_1.default.factory.createIdentifier(path), expected, input), | ||
}); | ||
@@ -124,6 +123,6 @@ } | ||
superfluous: function (value) { | ||
return create_guard_call(importer)()(typescript_1.default.factory.createAdd(typescript_1.default.factory.createIdentifier("path"), typescript_1.default.factory.createCallExpression(importer.use("join"), undefined, [typescript_1.default.factory.createIdentifier("key")])), "undefined", value); | ||
return create_guard_call(importer)()(typescript_1.default.factory.createAdd(typescript_1.default.factory.createIdentifier("_path"), typescript_1.default.factory.createCallExpression(importer.use("join"), undefined, [typescript_1.default.factory.createIdentifier("key")])), "undefined", value); | ||
}, | ||
halt: function (expr) { | ||
return typescript_1.default.factory.createLogicalOr(typescript_1.default.factory.createStrictEquality(typescript_1.default.factory.createFalse(), typescript_1.default.factory.createIdentifier("exceptionable")), expr); | ||
return typescript_1.default.factory.createLogicalOr(typescript_1.default.factory.createStrictEquality(typescript_1.default.factory.createFalse(), typescript_1.default.factory.createIdentifier("_exceptionable")), expr); | ||
}, | ||
@@ -141,3 +140,5 @@ })(importer); | ||
? typescript_1.default.factory.createTrue() | ||
: typescript_1.default.factory.createIdentifier("exceptionable"))(typescript_1.default.factory.createIdentifier((explore === null || explore === void 0 ? void 0 : explore.postfix) ? "path + ".concat(explore.postfix) : "path"), expected, value); | ||
: typescript_1.default.factory.createIdentifier("_exceptionable"))(typescript_1.default.factory.createIdentifier((explore === null || explore === void 0 ? void 0 : explore.postfix) | ||
? "_path + ".concat(explore.postfix) | ||
: "_path"), expected, value); | ||
}, | ||
@@ -149,3 +150,3 @@ full: equals | ||
? typescript_1.default.factory.createTrue() | ||
: typescript_1.default.factory.createIdentifier("exceptionable"))(typescript_1.default.factory.createIdentifier("path"), expected, input)); | ||
: typescript_1.default.factory.createIdentifier("_exceptionable"))(typescript_1.default.factory.createIdentifier("_path"), expected, input)); | ||
}; }, | ||
@@ -158,3 +159,3 @@ }); }; | ||
return typescript_1.default.factory.createCallExpression(importer.use("guard"), undefined, [ | ||
exceptionable || typescript_1.default.factory.createIdentifier("exceptionable"), | ||
exceptionable !== null && exceptionable !== void 0 ? exceptionable : typescript_1.default.factory.createIdentifier("_exceptionable"), | ||
typescript_1.default.factory.createObjectLiteralExpression([ | ||
@@ -161,0 +162,0 @@ typescript_1.default.factory.createPropertyAssignment("path", path), |
@@ -28,6 +28,5 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("any")), | ||
], (_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), undefined, typescript_1.default.factory.createBlock([ | ||
], typescript_1.default.factory.createTypeReferenceNode(TypeFactory_1.TypeFactory.getFullName(project.checker, type)), undefined, typescript_1.default.factory.createBlock([ | ||
StatementFactory_1.StatementFactory.constant("assert", AssertProgrammer_1.AssertProgrammer.generate(project, modulo)(type)), | ||
@@ -34,0 +33,0 @@ StatementFactory_1.StatementFactory.constant("prune", PruneProgrammer_1.PruneProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: false }) }), modulo)(type)), |
@@ -28,5 +28,4 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", (_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any")), | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("any")), | ||
], TypeFactory_1.TypeFactory.keyword("string"), undefined, typescript_1.default.factory.createBlock([ | ||
@@ -33,0 +32,0 @@ StatementFactory_1.StatementFactory.constant("assert", AssertProgrammer_1.AssertProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: true }) }), modulo)(type)), |
@@ -46,3 +46,3 @@ import ts from "typescript"; | ||
} | ||
function generate(project: IProject, config: IConfig, importer: FunctionImporter, addition?: () => ts.Statement[]): (type: ts.Type) => ts.ArrowFunction; | ||
function generate(project: IProject, config: IConfig, importer: FunctionImporter, addition?: () => ts.Statement[]): (type: ts.Type, typeNode?: ts.TypeNode | undefined) => ts.ArrowFunction; | ||
const generate_functors: (project: IProject, config: IConfig, importer: FunctionImporter) => (collection: MetadataCollection) => ts.VariableStatement[]; | ||
@@ -52,3 +52,3 @@ const generate_unioners: (project: IProject, config: IConfig, importer: FunctionImporter) => (collection: MetadataCollection) => ts.VariableStatement[]; | ||
function decode_tuple(project: IProject, config: IConfig, importer: FunctionImporter, checkLength: boolean): (input: ts.Expression, tuple: Array<Metadata>, explore: IExplore, tagList: IMetadataTag[]) => ts.Expression; | ||
function decode_object(config: IConfig): (input: ts.Expression, obj: MetadataObject, explore: IExplore) => ts.CallExpression; | ||
const decode_object: (config: IConfig) => (importer: FunctionImporter) => (input: ts.Expression, obj: MetadataObject, explore: IExplore) => ts.CallExpression; | ||
} |
@@ -85,3 +85,3 @@ "use strict"; | ||
CheckerProgrammer.generate_unioners = function (project, config, importer) { | ||
return FeatureProgrammer_1.FeatureProgrammer.generate_unioners(CONFIG(project, __assign(__assign({}, config), { numeric: false }), importer)); | ||
return FeatureProgrammer_1.FeatureProgrammer.generate_unioners(CONFIG(project, __assign(__assign({}, config), { numeric: false }), importer))(importer); | ||
}; | ||
@@ -93,3 +93,3 @@ function CONFIG(project, config, importer) { | ||
output: function (type) { | ||
return typescript_1.default.factory.createTypePredicateNode(undefined, "input", project.checker.typeToTypeNode(type, undefined, undefined)); | ||
return typescript_1.default.factory.createTypePredicateNode(undefined, "input", typescript_1.default.factory.createTypeReferenceNode(TypeFactory_1.TypeFactory.getFullName(project.checker, type))); | ||
}, | ||
@@ -113,7 +113,7 @@ }, | ||
checker: config.decoder || decode(project, config, importer), | ||
decoder: decode_object(config), | ||
decoder: CheckerProgrammer.decode_object(config)(importer), | ||
joiner: config.joiner.object, | ||
unionizer: config.equals | ||
? (0, decode_union_object_1.decode_union_object)(decode_object(config))(function (input, obj, explore) { | ||
return decode_object(config)(input, obj, __assign(__assign({}, explore), { tracable: true })); | ||
? (0, decode_union_object_1.decode_union_object)(CheckerProgrammer.decode_object(config)(importer))(function (input, obj, explore) { | ||
return CheckerProgrammer.decode_object(config)(importer)(input, obj, __assign(__assign({}, explore), { tracable: true })); | ||
})(config.joiner.is || (function (expr) { return expr; }))(function (value, expected) { | ||
@@ -124,3 +124,3 @@ return typescript_1.default.factory.createReturnStatement(config.joiner.failure(value, expected)); | ||
return config.combiner(explore)("or")(input, targets.map(function (obj) { return ({ | ||
expression: decode_object(config)(input, obj, explore), | ||
expression: CheckerProgrammer.decode_object(config)(importer)(input, obj, explore), | ||
combined: true, | ||
@@ -135,2 +135,3 @@ }); }), "(".concat(targets.map(function (t) { return t.name; }).join(" | "), ")")); | ||
full: config.joiner.full, | ||
type: TypeFactory_1.TypeFactory.keyword("boolean"), | ||
}, | ||
@@ -140,3 +141,3 @@ }; | ||
output.generator = { | ||
unioners: FeatureProgrammer_1.FeatureProgrammer.generate_unioners(CONFIG(project, __assign(__assign({}, config), { numeric: false }), importer)), | ||
unioners: FeatureProgrammer_1.FeatureProgrammer.generate_unioners(CONFIG(project, __assign(__assign({}, config), { numeric: false }), importer))(importer), | ||
}; | ||
@@ -312,3 +313,3 @@ return output; | ||
.map(function (obj) { return "Resolve<".concat(obj.name, ">"); }) | ||
.join(" | "))(explore_objects(config)(input, meta, __assign(__assign({}, explore), { from: "object" }))); | ||
.join(" | "))(explore_objects(config)(importer)(input, meta, __assign(__assign({}, explore), { from: "object" }))); | ||
if (instances.length) { | ||
@@ -407,4 +408,4 @@ var transformer = function (merger) { | ||
} | ||
function decode_object(config) { | ||
var func = FeatureProgrammer_1.FeatureProgrammer.decode_object(config); | ||
CheckerProgrammer.decode_object = function (config) { return function (importer) { | ||
var func = FeatureProgrammer_1.FeatureProgrammer.decode_object(config)(importer); | ||
return function (input, obj, explore) { | ||
@@ -414,4 +415,3 @@ obj.validated = true; | ||
}; | ||
} | ||
CheckerProgrammer.decode_object = decode_object; | ||
}; }; | ||
var explore_sets = function (project, config, importer) { | ||
@@ -505,10 +505,10 @@ return UnionExplorer_1.UnionExplorer.set({ | ||
}; | ||
var explore_objects = function (config) { | ||
var objector = decode_object(config); | ||
var explore_objects = function (config) { return function (importer) { | ||
var objector = CheckerProgrammer.decode_object(config)(importer); | ||
return function (input, meta, explore) { | ||
if (meta.objects.length === 1) | ||
return objector(input, meta.objects[0], explore); | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("".concat(config.unioners).concat(meta.union_index)), undefined, FeatureProgrammer_1.FeatureProgrammer.get_object_arguments(config)(explore)(input)); | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier(importer.useLocal("".concat(config.unioners).concat(meta.union_index))), undefined, FeatureProgrammer_1.FeatureProgrammer.get_object_arguments(config)(explore)(input)); | ||
}; | ||
}; | ||
}; }; | ||
})(CheckerProgrammer = exports.CheckerProgrammer || (exports.CheckerProgrammer = {})); | ||
@@ -515,0 +515,0 @@ var create_add = function (binaries) { |
import ts from "typescript"; | ||
import { IProject } from "../transformers/IProject"; | ||
export declare namespace CloneProgrammer { | ||
function generate(project: IProject, modulo: ts.LeftHandSideExpression): (type: ts.Type) => ts.ArrowFunction; | ||
function generate(project: IProject, modulo: ts.LeftHandSideExpression): (type: ts.Type, typeNode?: ts.TypeNode | undefined) => ts.ArrowFunction; | ||
} |
@@ -74,3 +74,7 @@ "use strict"; | ||
var isUnioners = IsProgrammer_1.IsProgrammer.generate_unioners(project, importer)(collection); | ||
return __spreadArray(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), __read(isFunctors), false), __read(isUnioners), false); | ||
return __spreadArray(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), __read(isFunctors.filter(function (_, i) { | ||
return importer.hasLocal("$io".concat(i)); | ||
})), false), __read(isUnioners.filter(function (_, i) { | ||
return importer.hasLocal("$iu".concat(i)); | ||
})), false); | ||
}); | ||
@@ -147,3 +151,9 @@ } | ||
is: function () { return ExpressionFactory_1.ExpressionFactory.isInstanceOf(input, native); }, | ||
value: function () { return typescript_1.default.factory.createIdentifier("{}"); }, | ||
value: function () { | ||
return native === "Boolean" || | ||
native === "Number" || | ||
native === "String" | ||
? typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.join(input, "valueOf"), undefined, undefined) | ||
: typescript_1.default.factory.createIdentifier("{}"); | ||
}, | ||
}); | ||
@@ -174,3 +184,3 @@ }; | ||
value: function () { | ||
return explore_objects(input, meta, __assign(__assign({}, explore), { from: "object" })); | ||
return explore_objects(importer)(input, meta, __assign(__assign({}, explore), { from: "object" })); | ||
}, | ||
@@ -192,3 +202,3 @@ }); | ||
} | ||
return last; | ||
return typescript_1.default.factory.createAsExpression(last, TypeFactory_1.TypeFactory.keyword("any")); | ||
}; | ||
@@ -227,3 +237,3 @@ }; | ||
}; | ||
var decode_object = function () { | ||
var decode_object = function (importer) { | ||
return FeatureProgrammer_1.FeatureProgrammer.decode_object({ | ||
@@ -233,3 +243,3 @@ trace: false, | ||
functors: FUNCTORS, | ||
}); | ||
})(importer); | ||
}; | ||
@@ -247,6 +257,8 @@ var explore_arrays = function (project, importer) { | ||
}; | ||
var explore_objects = function (input, meta, explore) { | ||
if (meta.objects.length === 1) | ||
return decode_object()(input, meta.objects[0], explore); | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("".concat(UNIONERS).concat(meta.union_index)), undefined, [input]); | ||
var explore_objects = function (importer) { | ||
return function (input, meta, explore) { | ||
if (meta.objects.length === 1) | ||
return decode_object(importer)(input, meta.objects[0], explore); | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("".concat(UNIONERS).concat(meta.union_index)), undefined, [input]); | ||
}; | ||
}; | ||
@@ -258,10 +270,6 @@ var FUNCTORS = "$co"; | ||
input: function (type) { | ||
var _a; | ||
return (_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"); | ||
return typescript_1.default.factory.createTypeReferenceNode(TypeFactory_1.TypeFactory.getFullName(project.checker, type)); | ||
}, | ||
output: function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createTypeReferenceNode("typia.Primitive", [ | ||
(_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), | ||
]); | ||
return typescript_1.default.factory.createTypeReferenceNode("typia.Primitive<".concat(TypeFactory_1.TypeFactory.getFullName(project.checker, type), ">")); | ||
}, | ||
@@ -279,5 +287,5 @@ }, | ||
checker: IsProgrammer_1.IsProgrammer.decode(project, importer), | ||
decoder: decode_object(), | ||
decoder: decode_object(importer), | ||
joiner: CloneJoiner_1.CloneJoiner.object, | ||
unionizer: (0, decode_union_object_1.decode_union_object)(IsProgrammer_1.IsProgrammer.decode_object(importer))(decode_object())(function (exp) { return exp; })(function (value, expected) { | ||
unionizer: (0, decode_union_object_1.decode_union_object)(IsProgrammer_1.IsProgrammer.decode_object(importer))(decode_object(importer))(function (exp) { return exp; })(function (value, expected) { | ||
return create_throw_error(importer, value, expected); | ||
@@ -284,0 +292,0 @@ }), |
@@ -47,4 +47,4 @@ import ts from "typescript"; | ||
interface ITypes { | ||
input: (type: ts.Type) => ts.TypeNode; | ||
output: (type: ts.Type) => ts.TypeNode; | ||
input: (type: ts.Type, node?: ts.TypeNode) => ts.TypeNode; | ||
output: (type: ts.Type, node?: ts.TypeNode) => ts.TypeNode; | ||
} | ||
@@ -121,2 +121,6 @@ interface IObjector { | ||
full?: (condition: ts.Expression) => (input: ts.Expression, expected: string, explore: IExplore) => ts.Expression; | ||
/** | ||
* Return type. | ||
*/ | ||
type?: ts.TypeNode; | ||
} | ||
@@ -155,8 +159,8 @@ interface IGenerator { | ||
*/ | ||
const generate: (project: IProject, config: IConfig, importer: FunctionImporter, addition: (collection: MetadataCollection) => ts.Statement[] | undefined) => (type: ts.Type) => ts.ArrowFunction; | ||
const generate: (project: IProject, config: IConfig, importer: FunctionImporter, addition: (collection: MetadataCollection) => ts.Statement[] | undefined) => (type: ts.Type, typeNode?: ts.TypeNode) => ts.ArrowFunction; | ||
const generate_functors: (config: IConfig) => (importer: FunctionImporter) => (collection: MetadataCollection) => ts.VariableStatement[]; | ||
const generate_unioners: (config: IConfig) => (collection: MetadataCollection) => ts.VariableStatement[]; | ||
const generate_unioners: (config: IConfig) => (importer: FunctionImporter) => (collection: MetadataCollection) => ts.VariableStatement[]; | ||
function decode_array(config: Pick<IConfig, "trace" | "path" | "decoder">, importer: FunctionImporter, combiner: (input: ts.Expression, arrow: ts.ArrowFunction, tags: IMetadataTag[]) => ts.Expression): (input: ts.Expression, meta: Metadata, explore: IExplore, tags: IMetadataTag[]) => ts.Expression; | ||
const decode_object: (config: Pick<IConfig, "trace" | "path" | "functors">) => (input: ts.Expression, obj: MetadataObject, explore: IExplore) => ts.CallExpression; | ||
const decode_object: (config: Pick<IConfig, "trace" | "path" | "functors">) => (importer: FunctionImporter) => (input: ts.Expression, obj: MetadataObject, explore: IExplore) => ts.CallExpression; | ||
const get_object_arguments: (config: Pick<IConfig, "path" | "trace">) => (explore: FeatureProgrammer.IExplore) => (input: ts.Expression) => ts.Expression[]; | ||
} |
@@ -42,5 +42,5 @@ "use strict"; | ||
FeatureProgrammer.generate = function (project, config, importer, addition) { | ||
return function (type) { | ||
var _a, _b; | ||
var _c = __read(config.initializer(project, type), 2), collection = _c[0], meta = _c[1]; | ||
return function (type, typeNode) { | ||
var _a, _b, _c, _d; | ||
var _e = __read(config.initializer(project, type), 2), collection = _e[0], meta = _e[1]; | ||
var output = config.decoder(ValueFactory_1.ValueFactory.INPUT(), meta, { | ||
@@ -52,10 +52,10 @@ tracable: config.path || config.trace, | ||
}, []); | ||
var functors = ((_a = config.generator) === null || _a === void 0 ? void 0 : _a.functors) !== undefined | ||
? config.generator.functors(collection) | ||
: FeatureProgrammer.generate_functors(config)(importer)(collection); | ||
var unioners = ((_b = config.generator) === null || _b === void 0 ? void 0 : _b.unioners) !== undefined | ||
? config.generator.unioners(collection) | ||
: FeatureProgrammer.generate_unioners(config)(collection); | ||
var functors = ((_b = (_a = config.generator) === null || _a === void 0 ? void 0 : _a.functors) !== null && _b !== void 0 ? _b : FeatureProgrammer.generate_functors(config)(importer))(collection); | ||
var unioners = ((_d = (_c = config.generator) === null || _c === void 0 ? void 0 : _c.unioners) !== null && _d !== void 0 ? _d : FeatureProgrammer.generate_unioners(config)(importer))(collection); | ||
var added = addition(collection); | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, PARAMETERS(config)(config.types.input(type))(ValueFactory_1.ValueFactory.INPUT()), config.types.output(type), undefined, typescript_1.default.factory.createBlock(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((added || [])), false), __read(functors), false), __read(unioners), false), __read((typescript_1.default.isBlock(output) | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, PARAMETERS(config)(config.types.input(type, typeNode))(ValueFactory_1.ValueFactory.INPUT()), config.types.output(type, typeNode), undefined, typescript_1.default.factory.createBlock(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((added || [])), false), __read(functors.filter(function (_, i) { | ||
return importer.hasLocal("".concat(config.functors).concat(i)); | ||
})), false), __read(unioners.filter(function (_, i) { | ||
return importer.hasLocal("".concat(config.unioners).concat(i)); | ||
})), false), __read((typescript_1.default.isBlock(output) | ||
? output.statements | ||
@@ -76,13 +76,18 @@ : [typescript_1.default.factory.createReturnStatement(output)])), false), true)); | ||
}; | ||
FeatureProgrammer.generate_unioners = function (config) { return function (collection) { | ||
return collection | ||
.unions() | ||
.map(function (union, i) { | ||
return StatementFactory_1.StatementFactory.constant("".concat(config.unioners).concat(i), generate_union(config)(union)); | ||
}); | ||
}; }; | ||
FeatureProgrammer.generate_unioners = function (config) { | ||
return function (importer) { | ||
return function (collection) { | ||
return collection | ||
.unions() | ||
.map(function (union, i) { | ||
return StatementFactory_1.StatementFactory.constant(importer.useLocal("".concat(config.unioners).concat(i)), generate_union(config)(union)); | ||
}); | ||
}; | ||
}; | ||
}; | ||
var generate_object = function (config) { | ||
return function (importer) { | ||
return function (obj) { | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, PARAMETERS(config)(TypeFactory_1.TypeFactory.keyword("any"))(ValueFactory_1.ValueFactory.INPUT()), undefined, undefined, config.objector.joiner(typescript_1.default.factory.createIdentifier("input"), (0, feature_object_entries_1.feature_object_entries)(config)(importer)(obj)(typescript_1.default.factory.createIdentifier("input")), obj)); | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, PARAMETERS(config)(TypeFactory_1.TypeFactory.keyword("any"))(ValueFactory_1.ValueFactory.INPUT()), (_a = config.objector.type) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), undefined, config.objector.joiner(typescript_1.default.factory.createIdentifier("input"), (0, feature_object_entries_1.feature_object_entries)(config)(importer)(obj)(typescript_1.default.factory.createIdentifier("input")), obj)); | ||
}; | ||
@@ -95,3 +100,3 @@ }; | ||
return function (meta) { | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, PARAMETERS(config)(TypeFactory_1.TypeFactory.keyword("any"))(ValueFactory_1.ValueFactory.INPUT()), undefined, undefined, explorer(input, meta, { | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, PARAMETERS(config)(TypeFactory_1.TypeFactory.keyword("any"))(ValueFactory_1.ValueFactory.INPUT()), TypeFactory_1.TypeFactory.keyword("any"), undefined, explorer(input, meta, { | ||
tracable: config.path || config.trace, | ||
@@ -108,3 +113,3 @@ source: "object", | ||
? [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("index" + rand, TypeFactory_1.TypeFactory.keyword("number")), | ||
IdentifierFactory_1.IdentifierFactory.parameter("_index" + rand, TypeFactory_1.TypeFactory.keyword("number")), | ||
] | ||
@@ -127,4 +132,6 @@ : []; | ||
FeatureProgrammer.decode_object = function (config) { | ||
return function (input, obj, explore) { | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("".concat(config.functors).concat(obj.index)), undefined, FeatureProgrammer.get_object_arguments(config)(explore)(input)); | ||
return function (importer) { | ||
return function (input, obj, explore) { | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier(importer.useLocal("".concat(config.functors).concat(obj.index))), undefined, FeatureProgrammer.get_object_arguments(config)(explore)(input)); | ||
}; | ||
}; | ||
@@ -139,6 +146,6 @@ }; | ||
typescript_1.default.factory.createIdentifier(explore.postfix | ||
? "path + ".concat(explore.postfix) | ||
: "path"), | ||
? "_path + ".concat(explore.postfix) | ||
: "_path"), | ||
explore.source === "object" | ||
? typescript_1.default.factory.createIdentifier("".concat(explore.tracable, " && exceptionable")) | ||
? typescript_1.default.factory.createIdentifier("".concat(explore.tracable, " && _exceptionable")) | ||
: explore.tracable | ||
@@ -151,8 +158,8 @@ ? typescript_1.default.factory.createTrue() | ||
typescript_1.default.factory.createIdentifier(explore.postfix | ||
? "path + ".concat(explore.postfix) | ||
: "path"), | ||
? "_path + ".concat(explore.postfix) | ||
: "_path"), | ||
] | ||
: [ | ||
explore.source === "object" | ||
? typescript_1.default.factory.createIdentifier("".concat(explore.tracable, " && exceptionable")) | ||
? typescript_1.default.factory.createIdentifier("".concat(explore.tracable, " && _exceptionable")) | ||
: explore.tracable | ||
@@ -168,4 +175,4 @@ ? typescript_1.default.factory.createTrue() | ||
var tail = start !== null | ||
? "\"[\" + (".concat(start, " + index").concat(rand, ") + \"]\"") | ||
: "\"[\" + index".concat(rand, " + \"]\""); | ||
? "\"[\" + (".concat(start, " + _index").concat(rand, ") + \"]\"") | ||
: "\"[\" + _index".concat(rand, " + \"]\""); | ||
if (prev === "") | ||
@@ -181,5 +188,5 @@ return tail; | ||
if (props.path) | ||
tail.push(IdentifierFactory_1.IdentifierFactory.parameter("path", TypeFactory_1.TypeFactory.keyword("string"))); | ||
tail.push(IdentifierFactory_1.IdentifierFactory.parameter("_path", TypeFactory_1.TypeFactory.keyword("string"))); | ||
if (props.trace) | ||
tail.push(IdentifierFactory_1.IdentifierFactory.parameter("exceptionable", TypeFactory_1.TypeFactory.keyword("boolean"))); | ||
tail.push(IdentifierFactory_1.IdentifierFactory.parameter("_exceptionable", TypeFactory_1.TypeFactory.keyword("boolean"), typescript_1.default.factory.createTrue())); | ||
return function (input) { return __spreadArray([ | ||
@@ -186,0 +193,0 @@ IdentifierFactory_1.IdentifierFactory.parameter(input, type) |
@@ -34,2 +34,3 @@ "use strict"; | ||
var StatementFactory_1 = require("../../factories/StatementFactory"); | ||
var TypeFactory_1 = require("../../factories/TypeFactory"); | ||
var Escaper_1 = require("../../utils/Escaper"); | ||
@@ -62,3 +63,3 @@ var metadata_to_pattern_1 = require("../internal/metadata_to_pattern"); | ||
return typescript_1.default.factory.createBlock([ | ||
StatementFactory_1.StatementFactory.constant("output", literal), | ||
StatementFactory_1.StatementFactory.constant("output", typescript_1.default.factory.createAsExpression(literal, TypeFactory_1.TypeFactory.keyword("any"))), | ||
typescript_1.default.factory.createForOfStatement(undefined, typescript_1.default.factory.createVariableDeclarationList([ | ||
@@ -74,5 +75,5 @@ typescript_1.default.factory.createVariableDeclaration(typescript_1.default.factory.createArrayBindingPattern([ | ||
CloneJoiner.tuple = function (children, rest) { | ||
if (rest === null) | ||
return typescript_1.default.factory.createArrayLiteralExpression(children, true); | ||
return typescript_1.default.factory.createArrayLiteralExpression(__spreadArray(__spreadArray([], __read(children), false), [typescript_1.default.factory.createSpreadElement(rest)], false), true); | ||
return typescript_1.default.factory.createAsExpression(typescript_1.default.factory.createArrayLiteralExpression(rest === null | ||
? children | ||
: __spreadArray(__spreadArray([], __read(children), false), [typescript_1.default.factory.createSpreadElement(rest)], false), true), TypeFactory_1.TypeFactory.keyword("any")); | ||
}; | ||
@@ -79,0 +80,0 @@ CloneJoiner.array = function (input, arrow) { |
import ts from "typescript"; | ||
export declare class FunctionImporter { | ||
private readonly used_; | ||
private readonly local_; | ||
private sequence_; | ||
empty(): boolean; | ||
use(name: string): ts.Identifier; | ||
useLocal(name: string): string; | ||
hasLocal(name: string): boolean; | ||
declare(modulo: ts.LeftHandSideExpression): ts.Statement[]; | ||
increment(): number; | ||
trace(): void; | ||
} |
@@ -39,2 +39,3 @@ "use strict"; | ||
this.used_ = new Set(); | ||
this.local_ = new Set(); | ||
this.sequence_ = 0; | ||
@@ -49,2 +50,9 @@ } | ||
}; | ||
FunctionImporter.prototype.useLocal = function (name) { | ||
this.local_.add(name); | ||
return name; | ||
}; | ||
FunctionImporter.prototype.hasLocal = function (name) { | ||
return this.local_.has(name); | ||
}; | ||
FunctionImporter.prototype.declare = function (modulo) { | ||
@@ -58,2 +66,6 @@ return __spreadArray([], __read(this.used_), false).map(function (name) { | ||
}; | ||
FunctionImporter.prototype.trace = function () { | ||
console.log.apply(console, __spreadArray([], __read(this.used_), false)); | ||
console.log.apply(console, __spreadArray([], __read(this.local_), false)); | ||
}; | ||
return FunctionImporter; | ||
@@ -60,0 +72,0 @@ }()); |
@@ -7,5 +7,5 @@ import ts from "typescript"; | ||
type Decoder = (meta: Metadata, tags: IMetadataTag[]) => ts.Expression; | ||
const array: (decoder: Decoder) => (item: Metadata, tags: IMetadataTag[]) => ts.CallExpression; | ||
const array: (coalesce: (method: string) => ts.Expression) => (decoder: Decoder) => (item: Metadata, tags: IMetadataTag[]) => ts.CallExpression; | ||
const tuple: (decoder: Decoder) => (items: Metadata[], tags: IMetadataTag[]) => ts.ArrayLiteralExpression; | ||
const object: (decoder: Decoder) => (obj: MetadataObject) => ts.ConciseBody; | ||
const object: (coalesce: (method: string) => ts.Expression) => (decoder: Decoder) => (obj: MetadataObject) => ts.ConciseBody; | ||
} |
@@ -34,2 +34,3 @@ "use strict"; | ||
var StatementFactory_1 = require("../../factories/StatementFactory"); | ||
var TypeFactory_1 = require("../../factories/TypeFactory"); | ||
var Escaper_1 = require("../../utils/Escaper"); | ||
@@ -39,57 +40,67 @@ var RandomRanger_1 = require("./RandomRanger"); | ||
(function (RandomJoiner) { | ||
RandomJoiner.array = function (decoder) { return function (item, tags) { | ||
var tail = RandomRanger_1.RandomRanger.length({ | ||
minimum: 0, | ||
maximum: 3, | ||
gap: 3, | ||
})({ | ||
fixed: "items", | ||
minimum: "minItems", | ||
maximum: "maxItems", | ||
})(tags); | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("generator.array"), undefined, __spreadArray([ | ||
typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, undefined, decoder(item, tags)) | ||
], __read((tail ? [tail] : [])), false)); | ||
}; }; | ||
RandomJoiner.array = function (coalesce) { | ||
return function (decoder) { | ||
return function (item, tags) { | ||
var tail = RandomRanger_1.RandomRanger.length(coalesce)({ | ||
minimum: 0, | ||
maximum: 3, | ||
gap: 3, | ||
})({ | ||
fixed: "items", | ||
minimum: "minItems", | ||
maximum: "maxItems", | ||
})(tags); | ||
return typescript_1.default.factory.createCallExpression(coalesce("array"), undefined, __spreadArray([ | ||
typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, undefined, decoder(item, tags)) | ||
], __read((tail ? [tail] : [])), false)); | ||
}; | ||
}; | ||
}; | ||
RandomJoiner.tuple = function (decoder) { return function (items, tags) { | ||
return typescript_1.default.factory.createArrayLiteralExpression(items.map(function (i) { var _a; return decoder((_a = i.rest) !== null && _a !== void 0 ? _a : i, tags); }), true); | ||
}; }; | ||
RandomJoiner.object = function (decoder) { | ||
return function (obj) { | ||
if (obj.properties.length === 0) | ||
return typescript_1.default.factory.createIdentifier("{}"); | ||
var regular = obj.properties.filter(function (p) { return p.key.isSoleLiteral(); }); | ||
var dynamic = obj.properties.filter(function (p) { return !p.key.isSoleLiteral(); }); | ||
var literal = typescript_1.default.factory.createObjectLiteralExpression(regular.map(function (p) { | ||
var str = p.key.getSoleLiteral(); | ||
return typescript_1.default.factory.createPropertyAssignment(Escaper_1.Escaper.variable(str) | ||
? str | ||
: typescript_1.default.factory.createStringLiteral(str), decoder(p.value, p.tags)); | ||
}), true); | ||
if (dynamic.length === 0) | ||
return literal; | ||
var properties = dynamic.map(function (p) { | ||
return typescript_1.default.factory.createExpressionStatement(dynamicProperty(decoder)(p)); | ||
}); | ||
return typescript_1.default.factory.createBlock(__spreadArray(__spreadArray([ | ||
StatementFactory_1.StatementFactory.constant("output", literal) | ||
], __read((obj.recursive | ||
? [ | ||
typescript_1.default.factory.createIfStatement(typescript_1.default.factory.createGreaterThanEquals(typescript_1.default.factory.createNumericLiteral(5), typescript_1.default.factory.createIdentifier("depth")), typescript_1.default.factory.createBlock(properties, true)), | ||
] | ||
: properties)), false), [ | ||
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createIdentifier("output")), | ||
], false), true); | ||
RandomJoiner.object = function (coalesce) { | ||
return function (decoder) { | ||
return function (obj) { | ||
if (obj.properties.length === 0) | ||
return typescript_1.default.factory.createIdentifier("{}"); | ||
var regular = obj.properties.filter(function (p) { return p.key.isSoleLiteral(); }); | ||
var dynamic = obj.properties.filter(function (p) { return !p.key.isSoleLiteral(); }); | ||
var literal = typescript_1.default.factory.createObjectLiteralExpression(regular.map(function (p) { | ||
var str = p.key.getSoleLiteral(); | ||
return typescript_1.default.factory.createPropertyAssignment(Escaper_1.Escaper.variable(str) | ||
? str | ||
: typescript_1.default.factory.createStringLiteral(str), decoder(p.value, p.tags)); | ||
}), true); | ||
if (dynamic.length === 0) | ||
return literal; | ||
var properties = dynamic.map(function (p) { | ||
return typescript_1.default.factory.createExpressionStatement(dynamicProperty(coalesce)(decoder)(p)); | ||
}); | ||
return typescript_1.default.factory.createBlock(__spreadArray(__spreadArray([ | ||
StatementFactory_1.StatementFactory.constant("output", typescript_1.default.factory.createAsExpression(literal, TypeFactory_1.TypeFactory.keyword("any"))) | ||
], __read((obj.recursive | ||
? [ | ||
typescript_1.default.factory.createIfStatement(typescript_1.default.factory.createGreaterThanEquals(typescript_1.default.factory.createNumericLiteral(5), typescript_1.default.factory.createIdentifier("_depth")), typescript_1.default.factory.createBlock(properties, true)), | ||
] | ||
: properties)), false), [ | ||
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createIdentifier("output")), | ||
], false), true); | ||
}; | ||
}; | ||
}; | ||
var dynamicProperty = function (decoder) { return function (p) { | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("generator.array"), undefined, [ | ||
typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, undefined, typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createElementAccessExpression(typescript_1.default.factory.createIdentifier("output"), decoder(p.key, [])), typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsToken), decoder(p.value, p.tags))), | ||
typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("generator.integer"), undefined, [ | ||
typescript_1.default.factory.createNumericLiteral(0), | ||
typescript_1.default.factory.createNumericLiteral(3), | ||
]), | ||
]); | ||
}; }; | ||
var dynamicProperty = function (coalesce) { | ||
return function (decoder) { | ||
return function (p) { | ||
return typescript_1.default.factory.createCallExpression(coalesce("array"), undefined, [ | ||
typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, undefined, typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createElementAccessExpression(typescript_1.default.factory.createIdentifier("output"), decoder(p.key, [])), typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsToken), decoder(p.value, p.tags))), | ||
typescript_1.default.factory.createCallExpression(coalesce("integer"), undefined, [ | ||
typescript_1.default.factory.createNumericLiteral(0), | ||
typescript_1.default.factory.createNumericLiteral(3), | ||
]), | ||
]); | ||
}; | ||
}; | ||
}; | ||
})(RandomJoiner = exports.RandomJoiner || (exports.RandomJoiner = {})); | ||
//# sourceMappingURL=RandomJoiner.js.map |
@@ -9,3 +9,3 @@ import ts from "typescript"; | ||
} | ||
const length: (defs: IDefaults) => (acc: length.IAccessors) => (tags: IMetadataTag[]) => ts.NumericLiteral | ts.CallExpression | undefined; | ||
const length: (coalesce: (method: string) => ts.Expression) => (defs: IDefaults) => (acc: length.IAccessors) => (tags: IMetadataTag[]) => ts.NumericLiteral | ts.CallExpression | undefined; | ||
namespace length { | ||
@@ -12,0 +12,0 @@ interface IAccessors { |
@@ -10,23 +10,25 @@ "use strict"; | ||
(function (RandomRanger) { | ||
RandomRanger.length = function (defs) { | ||
return function (acc) { | ||
return function (tags) { | ||
var _a, _b; | ||
var props = { | ||
fixed: getter(tags)(acc.fixed), | ||
minimum: getter(tags)(acc.minimum), | ||
maximum: getter(tags)(acc.maximum), | ||
RandomRanger.length = function (coalesce) { | ||
return function (defs) { | ||
return function (acc) { | ||
return function (tags) { | ||
var _a, _b; | ||
var props = { | ||
fixed: getter(tags)(acc.fixed), | ||
minimum: getter(tags)(acc.minimum), | ||
maximum: getter(tags)(acc.maximum), | ||
}; | ||
if (props.fixed !== undefined) | ||
return typescript_1.default.factory.createNumericLiteral(props.fixed); | ||
else if (props.minimum === undefined && props.maximum === undefined) | ||
return undefined; | ||
(_a = props.minimum) !== null && _a !== void 0 ? _a : (props.minimum = defs.minimum); | ||
(_b = props.maximum) !== null && _b !== void 0 ? _b : (props.maximum = defs.maximum); | ||
if (props.maximum <= props.minimum) | ||
props.maximum += defs.gap; | ||
return typescript_1.default.factory.createCallExpression(coalesce("integer"), undefined, [ | ||
typescript_1.default.factory.createNumericLiteral(props.minimum), | ||
typescript_1.default.factory.createNumericLiteral(props.maximum), | ||
]); | ||
}; | ||
if (props.fixed !== undefined) | ||
return typescript_1.default.factory.createNumericLiteral(props.fixed); | ||
else if (props.minimum === undefined && props.maximum === undefined) | ||
return undefined; | ||
(_a = props.minimum) !== null && _a !== void 0 ? _a : (props.minimum = defs.minimum); | ||
(_b = props.maximum) !== null && _b !== void 0 ? _b : (props.maximum = defs.maximum); | ||
if (props.maximum <= props.minimum) | ||
props.maximum += defs.gap; | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("generator.integer"), undefined, [ | ||
typescript_1.default.factory.createNumericLiteral(props.minimum), | ||
typescript_1.default.factory.createNumericLiteral(props.maximum), | ||
]); | ||
}; | ||
@@ -33,0 +35,0 @@ }; |
@@ -54,4 +54,8 @@ "use strict"; | ||
return typescript_1.default.factory.createArrayLiteralExpression([ | ||
typescript_1.default.factory.createArrowFunction(undefined, undefined, [IdentifierFactory_1.IdentifierFactory.parameter("top")], undefined, undefined, props.checker(typescript_1.default.factory.createIdentifier("top"), meta, __assign(__assign({}, explore), { tracable: false, postfix: "\"[0]\"" }), tags, input)), | ||
typescript_1.default.factory.createArrowFunction(undefined, undefined, [IdentifierFactory_1.IdentifierFactory.parameter("top")], undefined, undefined, props.decoder(typescript_1.default.factory.createIdentifier("top"), meta, __assign(__assign({}, explore), { tracable: true }), tags)), | ||
typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("top", TypeFactory_1.TypeFactory.keyword("any")), | ||
], undefined, undefined, props.checker(typescript_1.default.factory.createIdentifier("top"), meta, __assign(__assign({}, explore), { tracable: false, postfix: "\"[0]\"" }), tags, input)), | ||
typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("top", TypeFactory_1.TypeFactory.keyword("any")), | ||
], undefined, undefined, props.decoder(typescript_1.default.factory.createIdentifier("top"), meta, __assign(__assign({}, explore), { tracable: true }), tags)), | ||
]); | ||
@@ -58,0 +62,0 @@ }))); |
@@ -33,3 +33,3 @@ "use strict"; | ||
typescript_1.default.factory.createBindingElement(undefined, undefined, "value"), | ||
])), | ||
]), typescript_1.default.factory.createTypeReferenceNode("[string, any]")), | ||
], undefined, undefined, typescript_1.default.factory.createBlock(statements)), | ||
@@ -36,0 +36,0 @@ ]); |
@@ -28,9 +28,6 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("any")), | ||
], typescript_1.default.factory.createUnionTypeNode([ | ||
typescript_1.default.factory.createTypeReferenceNode("typia.Primitive", [ | ||
(_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), | ||
]), | ||
typescript_1.default.factory.createTypeReferenceNode("typia.Primitive<".concat(TypeFactory_1.TypeFactory.getFullName(project.checker, type), ">")), | ||
typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNull()), | ||
@@ -37,0 +34,0 @@ ]), undefined, typescript_1.default.factory.createBlock([ |
@@ -27,8 +27,5 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("any")), | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.Primitive", [ | ||
(_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), | ||
]), undefined, typescript_1.default.factory.createBlock([ | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.Primitive<".concat(TypeFactory_1.TypeFactory.getFullName(project.checker, type), ">")), undefined, typescript_1.default.factory.createBlock([ | ||
StatementFactory_1.StatementFactory.constant("is", IsProgrammer_1.IsProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: false }) }), modulo)(type)), | ||
@@ -35,0 +32,0 @@ typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createIdentifier("input"), typescript_1.default.SyntaxKind.EqualsToken, typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("JSON.parse"), undefined, [typescript_1.default.factory.createIdentifier("input")]))), |
@@ -16,3 +16,3 @@ import ts from "typescript"; | ||
} | ||
function generate(project: IProject, modulo: ts.LeftHandSideExpression, equals?: boolean): (type: ts.Type) => ts.ArrowFunction; | ||
function generate(project: IProject, modulo: ts.LeftHandSideExpression, equals?: boolean): (type: ts.Type, typeNode?: ts.TypeNode | undefined) => ts.ArrowFunction; | ||
const generate_functors: (project: IProject, importer: FunctionImporter) => (collection: import("../factories/MetadataCollection").MetadataCollection) => ts.VariableStatement[]; | ||
@@ -19,0 +19,0 @@ const generate_unioners: (project: IProject, importer: FunctionImporter) => (collection: import("../factories/MetadataCollection").MetadataCollection) => ts.VariableStatement[]; |
@@ -109,3 +109,3 @@ "use strict"; | ||
IsProgrammer.decode_object = function (importer) { | ||
return CheckerProgrammer_1.CheckerProgrammer.decode_object(IsProgrammer.CONFIG()(importer)); | ||
return CheckerProgrammer_1.CheckerProgrammer.decode_object(IsProgrammer.CONFIG()(importer))(importer); | ||
}; | ||
@@ -112,0 +112,0 @@ function decode_to_json(input, checkNull) { |
@@ -28,6 +28,5 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("any")), | ||
], typescript_1.default.factory.createTypePredicateNode(undefined, "input", (_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any")), undefined, typescript_1.default.factory.createBlock([ | ||
], typescript_1.default.factory.createTypePredicateNode(undefined, "input", typescript_1.default.factory.createTypeReferenceNode(TypeFactory_1.TypeFactory.getFullName(project.checker, type))), undefined, typescript_1.default.factory.createBlock([ | ||
StatementFactory_1.StatementFactory.constant("is", IsProgrammer_1.IsProgrammer.generate(project, modulo)(type)), | ||
@@ -34,0 +33,0 @@ StatementFactory_1.StatementFactory.constant("prune", PruneProgrammer_1.PruneProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: false }) }), modulo)(type)), |
@@ -28,5 +28,4 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", (_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any")), | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", typescript_1.default.factory.createTypeReferenceNode(TypeFactory_1.TypeFactory.getFullName(project.checker, type))), | ||
], typescript_1.default.factory.createUnionTypeNode([ | ||
@@ -33,0 +32,0 @@ TypeFactory_1.TypeFactory.keyword("string"), |
import ts from "typescript"; | ||
import { IProject } from "../transformers/IProject"; | ||
export declare namespace PruneProgrammer { | ||
function generate(project: IProject, modulo: ts.LeftHandSideExpression): (type: ts.Type) => ts.ArrowFunction; | ||
function generate(project: IProject, modulo: ts.LeftHandSideExpression): (type: ts.Type, typeNode?: ts.TypeNode | undefined) => ts.ArrowFunction; | ||
} |
@@ -74,3 +74,7 @@ "use strict"; | ||
var isUnioners = IsProgrammer_1.IsProgrammer.generate_unioners(project, importer)(collection); | ||
return __spreadArray(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), __read(isFunctors), false), __read(isUnioners), false); | ||
return __spreadArray(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), __read(isFunctors.filter(function (_, i) { | ||
return importer.hasLocal("$io".concat(i)); | ||
})), false), __read(isUnioners.filter(function (_, i) { | ||
return importer.hasLocal("$iu".concat(i)); | ||
})), false); | ||
}); | ||
@@ -167,3 +171,3 @@ } | ||
value: function () { | ||
return explore_objects(input, meta, __assign(__assign({}, explore), { from: "object" })); | ||
return explore_objects(importer)(input, meta, __assign(__assign({}, explore), { from: "object" })); | ||
}, | ||
@@ -213,3 +217,3 @@ }); | ||
}; | ||
var decode_object = function () { | ||
var decode_object = function (importer) { | ||
return FeatureProgrammer_1.FeatureProgrammer.decode_object({ | ||
@@ -219,3 +223,3 @@ trace: false, | ||
functors: FUNCTORS, | ||
}); | ||
})(importer); | ||
}; | ||
@@ -233,6 +237,8 @@ var explore_arrays = function (project, importer) { | ||
}; | ||
var explore_objects = function (input, meta, explore) { | ||
if (meta.objects.length === 1) | ||
return decode_object()(input, meta.objects[0], explore); | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("".concat(UNIONERS).concat(meta.union_index)), undefined, [input]); | ||
var explore_objects = function (importer) { | ||
return function (input, meta, explore) { | ||
if (meta.objects.length === 1) | ||
return decode_object(importer)(input, meta.objects[0], explore); | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("".concat(UNIONERS).concat(meta.union_index)), undefined, [input]); | ||
}; | ||
}; | ||
@@ -250,4 +256,3 @@ var filter = function (meta) { | ||
input: function (type) { | ||
var _a; | ||
return (_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"); | ||
return typescript_1.default.factory.createTypeReferenceNode(TypeFactory_1.TypeFactory.getFullName(project.checker, type)); | ||
}, | ||
@@ -266,5 +271,5 @@ output: function () { return TypeFactory_1.TypeFactory.keyword("void"); }, | ||
checker: IsProgrammer_1.IsProgrammer.decode(project, importer), | ||
decoder: decode_object(), | ||
decoder: decode_object(importer), | ||
joiner: PruneJoiner_1.PruneJoiner.object, | ||
unionizer: (0, decode_union_object_1.decode_union_object)(IsProgrammer_1.IsProgrammer.decode_object(importer))(decode_object())(function (exp) { return exp; })(function (value, expected) { | ||
unionizer: (0, decode_union_object_1.decode_union_object)(IsProgrammer_1.IsProgrammer.decode_object(importer))(decode_object(importer))(function (exp) { return exp; })(function (value, expected) { | ||
return create_throw_error(importer, value, expected); | ||
@@ -271,0 +276,0 @@ }), |
@@ -70,4 +70,4 @@ "use strict"; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("generator", typescript_1.default.factory.createTypeReferenceNode("typia.IRandomGenerator"), IdentifierFactory_1.IdentifierFactory.join(typescript_1.default.factory.createParenthesizedExpression(typescript_1.default.factory.createAsExpression(modulo, TypeFactory_1.TypeFactory.keyword("any"))), "generator")), | ||
], undefined, undefined, typescript_1.default.factory.createBlock(__spreadArray(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), __read(functors), false), [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("generator", typescript_1.default.factory.createTypeReferenceNode("Partial<typia.IRandomGenerator>"), IdentifierFactory_1.IdentifierFactory.join(typescript_1.default.factory.createParenthesizedExpression(typescript_1.default.factory.createAsExpression(modulo, TypeFactory_1.TypeFactory.keyword("any"))), "generator")), | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.Primitive<".concat(TypeFactory_1.TypeFactory.getFullName(project.checker, type), ">")), undefined, typescript_1.default.factory.createBlock(__spreadArray(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), __read(functors), false), [ | ||
typescript_1.default.factory.createReturnStatement(output), | ||
@@ -81,5 +81,5 @@ ], false), true)); | ||
return StatementFactory_1.StatementFactory.constant(FUNCTOR(i), typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("recursive", undefined, typescript_1.default.factory.createIdentifier(String(obj.recursive))), | ||
IdentifierFactory_1.IdentifierFactory.parameter("depth", undefined, typescript_1.default.factory.createNumericLiteral(0)), | ||
], undefined, undefined, RandomJoiner_1.RandomJoiner.object(decode(importer)({ | ||
IdentifierFactory_1.IdentifierFactory.parameter("_recursive", TypeFactory_1.TypeFactory.keyword("boolean"), typescript_1.default.factory.createIdentifier(String(obj.recursive))), | ||
IdentifierFactory_1.IdentifierFactory.parameter("_depth", TypeFactory_1.TypeFactory.keyword("number"), typescript_1.default.factory.createNumericLiteral(0)), | ||
], TypeFactory_1.TypeFactory.keyword("any"), undefined, RandomJoiner_1.RandomJoiner.object(COALESCE(importer))(decode(importer)({ | ||
recursive: obj.recursive, | ||
@@ -143,9 +143,9 @@ object: true, | ||
if (atomic === "boolean") | ||
expressions.push(decode_boolean()); | ||
expressions.push(decode_boolean(importer)); | ||
else if (atomic === "number") | ||
expressions.push(decode_number(tags)); | ||
expressions.push(decode_number(importer)(tags)); | ||
else if (atomic === "string") | ||
expressions.push(decode_string(importer)(tags)); | ||
else if (atomic === "bigint") | ||
expressions.push(decode_bigint(tags)); | ||
expressions.push(decode_bigint(importer)(tags)); | ||
} | ||
@@ -178,5 +178,5 @@ } | ||
var a = _v.value; | ||
var array = RandomJoiner_1.RandomJoiner.array(decode(importer)(explore))(a, tags); | ||
var array = RandomJoiner_1.RandomJoiner.array(COALESCE(importer))(decode(importer)(explore))(a, tags); | ||
expressions.push(explore.recursive && a.objects.length | ||
? typescript_1.default.factory.createConditionalExpression(typescript_1.default.factory.createLogicalAnd(typescript_1.default.factory.createIdentifier("recursive"), typescript_1.default.factory.createLessThan(typescript_1.default.factory.createNumericLiteral(5), typescript_1.default.factory.createIdentifier("depth"))), undefined, typescript_1.default.factory.createIdentifier("[]"), undefined, array) | ||
? typescript_1.default.factory.createConditionalExpression(typescript_1.default.factory.createLogicalAnd(typescript_1.default.factory.createIdentifier("_recursive"), typescript_1.default.factory.createLessThan(typescript_1.default.factory.createNumericLiteral(5), typescript_1.default.factory.createIdentifier("_depth"))), undefined, typescript_1.default.factory.createIdentifier("[]"), undefined, array) | ||
: array); | ||
@@ -199,4 +199,4 @@ } | ||
? typescript_1.default.factory.createTrue() | ||
: typescript_1.default.factory.createIdentifier("recursive"), | ||
typescript_1.default.factory.createConditionalExpression(typescript_1.default.factory.createIdentifier("recursive"), undefined, typescript_1.default.factory.createAdd(typescript_1.default.factory.createNumericLiteral(1), typescript_1.default.factory.createIdentifier("depth")), undefined, typescript_1.default.factory.createIdentifier("depth")), | ||
: typescript_1.default.factory.createIdentifier("_recursive"), | ||
typescript_1.default.factory.createConditionalExpression(typescript_1.default.factory.createIdentifier("_recursive"), undefined, typescript_1.default.factory.createAdd(typescript_1.default.factory.createNumericLiteral(1), typescript_1.default.factory.createIdentifier("_depth")), undefined, typescript_1.default.factory.createIdentifier("_depth")), | ||
] | ||
@@ -217,5 +217,5 @@ : undefined)); | ||
if (native === "Boolean") | ||
expressions.push(decode_boolean()); | ||
expressions.push(decode_boolean(importer)); | ||
else if (native === "Number") | ||
expressions.push(decode_number(tags)); | ||
expressions.push(decode_number(importer)(tags)); | ||
else if (native === "String") | ||
@@ -246,4 +246,4 @@ expressions.push(decode_string(importer)(tags)); | ||
}; | ||
var decode_boolean = function () { | ||
return typescript_1.default.factory.createLessThan(typescript_1.default.factory.createNumericLiteral(0.5), typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("Math.random"), undefined, undefined)); | ||
var decode_boolean = function (importer) { | ||
return typescript_1.default.factory.createCallExpression(COALESCE(importer)("boolean"), undefined, undefined); | ||
}; | ||
@@ -266,44 +266,50 @@ var decode_atomic = function (value) { | ||
}; | ||
var decode_number = function (tags) { | ||
var type = tags.find(function (t) { return t.kind === "type" && t.value === "uint"; }) | ||
? "int" | ||
: tags.find(function (t) { return t.kind === "type" && t.value === "int"; }) | ||
? "uint" | ||
: "double"; | ||
return RandomRanger_1.RandomRanger.number({ | ||
type: type, | ||
transform: function (value) { return typescript_1.default.factory.createNumericLiteral(value); }, | ||
setter: function (args) { | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier(type === "double" && | ||
tags.every(function (t) { | ||
return t.kind !== "multipleOf" && | ||
t.kind !== "step"; | ||
}) | ||
? "generator.number" | ||
: "generator.integer"), undefined, args.map(function (val) { return typescript_1.default.factory.createNumericLiteral(val); })); | ||
}, | ||
})({ | ||
minimum: 0, | ||
maximum: 100, | ||
gap: 10, | ||
})(tags); | ||
var decode_number = function (importer) { | ||
return function (tags) { | ||
var type = tags.find(function (t) { return t.kind === "type" && t.value === "uint"; }) | ||
? "int" | ||
: tags.find(function (t) { return t.kind === "type" && t.value === "int"; }) | ||
? "uint" | ||
: "double"; | ||
return RandomRanger_1.RandomRanger.number({ | ||
type: type, | ||
transform: function (value) { return typescript_1.default.factory.createNumericLiteral(value); }, | ||
setter: function (args) { | ||
return typescript_1.default.factory.createCallExpression(type === "double" && | ||
tags.every(function (t) { | ||
return t.kind !== "multipleOf" && | ||
t.kind !== "step"; | ||
}) | ||
? COALESCE(importer)("number") | ||
: COALESCE(importer)("integer"), undefined, args.map(function (val) { return typescript_1.default.factory.createNumericLiteral(val); })); | ||
}, | ||
})({ | ||
minimum: 0, | ||
maximum: 100, | ||
gap: 10, | ||
})(tags); | ||
}; | ||
}; | ||
var decode_bigint = function (tags) { | ||
return RandomRanger_1.RandomRanger.number({ | ||
type: tags.find(function (t) { return t.kind === "type" && t.value === "uint"; }) | ||
? "uint" | ||
: "int", | ||
transform: function (value) { | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("BigInt"), undefined, [typescript_1.default.factory.createStringLiteral(value.toString())]); | ||
}, | ||
setter: function (args) { | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("generator.bigint"), undefined, args.map(function (value) { | ||
var decode_bigint = function (importer) { | ||
return function (tags) { | ||
return RandomRanger_1.RandomRanger.number({ | ||
type: tags.find(function (t) { return t.kind === "type" && t.value === "uint"; }) | ||
? "uint" | ||
: "int", | ||
transform: function (value) { | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("BigInt"), undefined, [typescript_1.default.factory.createStringLiteral(value.toString())]); | ||
})); | ||
}, | ||
})({ | ||
minimum: 0, | ||
maximum: 100, | ||
gap: 10, | ||
})(tags); | ||
}, | ||
setter: function (args) { | ||
return typescript_1.default.factory.createCallExpression(COALESCE(importer)("bigint"), undefined, args.map(function (value) { | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("BigInt"), undefined, [ | ||
typescript_1.default.factory.createStringLiteral(value.toString()), | ||
]); | ||
})); | ||
}, | ||
})({ | ||
minimum: 0, | ||
maximum: 100, | ||
gap: 10, | ||
})(tags); | ||
}; | ||
}; | ||
@@ -330,3 +336,3 @@ var decode_string = function (importer) { | ||
} | ||
var tail = RandomRanger_1.RandomRanger.length({ | ||
var tail = RandomRanger_1.RandomRanger.length(COALESCE(importer))({ | ||
minimum: 5, | ||
@@ -340,3 +346,3 @@ maximum: 25, | ||
})(tags); | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("generator.string"), undefined, tail ? [tail] : undefined); | ||
return typescript_1.default.factory.createCallExpression(COALESCE(importer)("string"), undefined, tail ? [tail] : undefined); | ||
}; | ||
@@ -343,0 +349,0 @@ }; |
import ts from "typescript"; | ||
import { IProject } from "../transformers/IProject"; | ||
export declare namespace StringifyProgrammer { | ||
function generate(project: IProject, modulo: ts.LeftHandSideExpression): (type: ts.Type) => ts.ArrowFunction; | ||
function generate(project: IProject, modulo: ts.LeftHandSideExpression): (type: ts.Type, typeNode?: ts.TypeNode | undefined) => ts.ArrowFunction; | ||
} |
@@ -81,3 +81,7 @@ "use strict"; | ||
var isUnioners = IsProgrammer_1.IsProgrammer.generate_unioners(project, importer)(collection); | ||
return __spreadArray(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), __read(isFunctors), false), __read(isUnioners), false); | ||
return __spreadArray(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), __read(isFunctors.filter(function (_, i) { | ||
return importer.hasLocal("$io".concat(i)); | ||
})), false), __read(isUnioners.filter(function (_, i) { | ||
return importer.hasLocal("$iu".concat(i)); | ||
})), false); | ||
}); | ||
@@ -348,3 +352,3 @@ } | ||
})() | ||
: explore_objects(input, meta, __assign(__assign({}, explore), { from: "object" })); | ||
: explore_objects(importer)(input, meta, __assign(__assign({}, explore), { from: "object" })); | ||
}, | ||
@@ -365,3 +369,3 @@ }); | ||
}; | ||
var decode_object = function () { | ||
var decode_object = function (importer) { | ||
return FeatureProgrammer_1.FeatureProgrammer.decode_object({ | ||
@@ -371,3 +375,3 @@ trace: false, | ||
functors: FUNCTORS, | ||
}); | ||
})(importer); | ||
}; | ||
@@ -449,6 +453,8 @@ var decode_tuple = function (project, importer) { | ||
}; | ||
var explore_objects = function (input, meta, explore) { | ||
if (meta.objects.length === 1) | ||
return decode_object()(input, meta.objects[0], explore); | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("".concat(UNIONERS).concat(meta.union_index)), undefined, [input]); | ||
var explore_objects = function (importer) { | ||
return function (input, meta, explore) { | ||
if (meta.objects.length === 1) | ||
return decode_object(importer)(input, meta.objects[0], explore); | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("".concat(UNIONERS).concat(meta.union_index)), undefined, [input]); | ||
}; | ||
}; | ||
@@ -490,4 +496,3 @@ function wrap_required(input, meta, explore) { | ||
input: function (type) { | ||
var _a; | ||
return (_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"); | ||
return typescript_1.default.factory.createTypeReferenceNode(TypeFactory_1.TypeFactory.getFullName(project.checker, type)); | ||
}, | ||
@@ -519,5 +524,5 @@ output: function () { return TypeFactory_1.TypeFactory.keyword("string"); }, | ||
checker: IsProgrammer_1.IsProgrammer.decode(project, importer), | ||
decoder: decode_object(), | ||
decoder: decode_object(importer), | ||
joiner: StringifyJoinder_1.StringifyJoiner.object(importer), | ||
unionizer: (0, decode_union_object_1.decode_union_object)(IsProgrammer_1.IsProgrammer.decode_object(importer))(decode_object())(function (exp) { return exp; })(function (value, expected) { | ||
unionizer: (0, decode_union_object_1.decode_union_object)(IsProgrammer_1.IsProgrammer.decode_object(importer))(decode_object(importer))(function (exp) { return exp; })(function (value, expected) { | ||
return create_throw_error(importer, value, expected); | ||
@@ -524,0 +529,0 @@ }), |
@@ -28,10 +28,5 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("any")), | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.IValidation", [ | ||
typescript_1.default.factory.createTypeReferenceNode("typia.Primitive", [ | ||
(_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), | ||
]), | ||
]), undefined, typescript_1.default.factory.createBlock([ | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.IValidation<typia.Primitive<".concat(TypeFactory_1.TypeFactory.getFullName(project.checker, type), ">>")), undefined, typescript_1.default.factory.createBlock([ | ||
StatementFactory_1.StatementFactory.constant("validate", ValidateProgrammer_1.ValidateProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: true }) }), modulo)(type)), | ||
@@ -38,0 +33,0 @@ StatementFactory_1.StatementFactory.constant("clone", CloneProgrammer_1.CloneProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: false }) }), modulo)(type)), |
@@ -27,10 +27,5 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("string")), | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.IValidation", [ | ||
typescript_1.default.factory.createTypeReferenceNode("typia.Primitive", [ | ||
(_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), | ||
]), | ||
]), undefined, typescript_1.default.factory.createBlock([ | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.IValidation<typia.Primitive<".concat(TypeFactory_1.TypeFactory.getFullName(project.checker, type), ">>")), undefined, typescript_1.default.factory.createBlock([ | ||
StatementFactory_1.StatementFactory.constant("validate", ValidateProgrammer_1.ValidateProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: false }) }), modulo)(type)), | ||
@@ -37,0 +32,0 @@ typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createIdentifier("input"), typescript_1.default.SyntaxKind.EqualsToken, typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("JSON.parse"), undefined, [typescript_1.default.factory.createIdentifier("input")]))), |
@@ -47,3 +47,2 @@ "use strict"; | ||
return function (type) { | ||
var _a, _b; | ||
var importer = new FunctionImporeter_1.FunctionImporter(); | ||
@@ -63,5 +62,3 @@ var program = CheckerProgrammer_1.CheckerProgrammer.generate(project, { | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("any")), | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.IValidation", [ | ||
(_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), | ||
]), undefined, typescript_1.default.factory.createBlock(__spreadArray(__spreadArray([ | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.IValidation<".concat(TypeFactory_1.TypeFactory.getFullName(project.checker, type), ">")), undefined, typescript_1.default.factory.createBlock(__spreadArray(__spreadArray([ | ||
StatementFactory_1.StatementFactory.constant("errors", typescript_1.default.factory.createAsExpression(typescript_1.default.factory.createArrayLiteralExpression([]), typescript_1.default.factory.createArrayTypeNode(TypeFactory_1.TypeFactory.keyword("any")))), | ||
@@ -76,5 +73,3 @@ StatementFactory_1.StatementFactory.constant("$report", typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.join(typescript_1.default.factory.createParenthesizedExpression(typescript_1.default.factory.createAsExpression(modulo, TypeFactory_1.TypeFactory.keyword("any"))), "report"), [], [typescript_1.default.factory.createIdentifier("errors")])) | ||
StatementFactory_1.StatementFactory.constant("success", typescript_1.default.factory.createStrictEquality(typescript_1.default.factory.createNumericLiteral(0), typescript_1.default.factory.createIdentifier("errors.length"))), | ||
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createAsExpression(create_output(), typescript_1.default.factory.createTypeReferenceNode("typia.IValidation", [ | ||
(_b = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _b !== void 0 ? _b : TypeFactory_1.TypeFactory.keyword("any"), | ||
]))), | ||
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createAsExpression(create_output(), TypeFactory_1.TypeFactory.keyword("any"))), | ||
], false), true)); | ||
@@ -93,4 +88,4 @@ }; | ||
var path = explore.postfix | ||
? "path + ".concat(explore.postfix) | ||
: "path"; | ||
? "_path + ".concat(explore.postfix) | ||
: "_path"; | ||
return function (logic) { return function (input, binaries, expected) { | ||
@@ -104,3 +99,3 @@ return logic === "and" | ||
? typescript_1.default.factory.createTrue() | ||
: typescript_1.default.factory.createIdentifier("exceptionable"))(typescript_1.default.factory.createIdentifier(path), expected, input)); | ||
: typescript_1.default.factory.createIdentifier("_exceptionable"))(typescript_1.default.factory.createIdentifier(path), expected, input)); | ||
}) | ||
@@ -112,3 +107,3 @@ .reduce(typescript_1.default.factory.createLogicalAnd) | ||
? typescript_1.default.factory.createTrue() | ||
: typescript_1.default.factory.createIdentifier("exceptionable"))(typescript_1.default.factory.createIdentifier(path), expected, input)); | ||
: typescript_1.default.factory.createIdentifier("_exceptionable"))(typescript_1.default.factory.createIdentifier(path), expected, input)); | ||
}; }; | ||
@@ -126,6 +121,6 @@ }; | ||
superfluous: function (value) { | ||
return create_report_call()(typescript_1.default.factory.createAdd(typescript_1.default.factory.createIdentifier("path"), typescript_1.default.factory.createCallExpression(importer.use("join"), undefined, [typescript_1.default.factory.createIdentifier("key")])), "undefined", value); | ||
return create_report_call()(typescript_1.default.factory.createAdd(typescript_1.default.factory.createIdentifier("_path"), typescript_1.default.factory.createCallExpression(importer.use("join"), undefined, [typescript_1.default.factory.createIdentifier("key")])), "undefined", value); | ||
}, | ||
halt: function (expr) { | ||
return typescript_1.default.factory.createLogicalOr(typescript_1.default.factory.createStrictEquality(typescript_1.default.factory.createFalse(), typescript_1.default.factory.createIdentifier("exceptionable")), expr); | ||
return typescript_1.default.factory.createLogicalOr(typescript_1.default.factory.createStrictEquality(typescript_1.default.factory.createFalse(), typescript_1.default.factory.createIdentifier("_exceptionable")), expr); | ||
}, | ||
@@ -143,3 +138,3 @@ })(importer); | ||
? typescript_1.default.factory.createTrue() | ||
: typescript_1.default.factory.createIdentifier("exceptionable"))(typescript_1.default.factory.createIdentifier((explore === null || explore === void 0 ? void 0 : explore.postfix) ? "path + ".concat(explore.postfix) : "path"), expected, value); | ||
: typescript_1.default.factory.createIdentifier("_exceptionable"))(typescript_1.default.factory.createIdentifier((explore === null || explore === void 0 ? void 0 : explore.postfix) ? "_path + ".concat(explore.postfix) : "_path"), expected, value); | ||
}, | ||
@@ -161,3 +156,3 @@ tuple: function (binaries) { | ||
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier("$report"), undefined, [ | ||
exceptionable || typescript_1.default.factory.createIdentifier("exceptionable"), | ||
exceptionable !== null && exceptionable !== void 0 ? exceptionable : typescript_1.default.factory.createIdentifier("_exceptionable"), | ||
typescript_1.default.factory.createObjectLiteralExpression([ | ||
@@ -164,0 +159,0 @@ typescript_1.default.factory.createPropertyAssignment("path", path), |
@@ -28,8 +28,5 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", TypeFactory_1.TypeFactory.keyword("any")), | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.IValidation", [ | ||
(_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any"), | ||
]), undefined, typescript_1.default.factory.createBlock([ | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.IValidation<".concat(TypeFactory_1.TypeFactory.getFullName(project.checker, type), ">")), undefined, typescript_1.default.factory.createBlock([ | ||
StatementFactory_1.StatementFactory.constant("validate", ValidateProgrammer_1.ValidateProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: true }) }), modulo)(type)), | ||
@@ -36,0 +33,0 @@ StatementFactory_1.StatementFactory.constant("prune", PruneProgrammer_1.PruneProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: false }) }), modulo)(type)), |
@@ -28,8 +28,5 @@ "use strict"; | ||
return function (type) { | ||
var _a; | ||
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", (_a = project.checker.typeToTypeNode(type, undefined, undefined)) !== null && _a !== void 0 ? _a : TypeFactory_1.TypeFactory.keyword("any")), | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.IValidation", [ | ||
TypeFactory_1.TypeFactory.keyword("string"), | ||
]), undefined, typescript_1.default.factory.createBlock([ | ||
IdentifierFactory_1.IdentifierFactory.parameter("input", typescript_1.default.factory.createTypeReferenceNode(TypeFactory_1.TypeFactory.getFullName(project.checker, type))), | ||
], typescript_1.default.factory.createTypeReferenceNode("typia.IValidation<string>"), undefined, typescript_1.default.factory.createBlock([ | ||
StatementFactory_1.StatementFactory.constant("validate", ValidateProgrammer_1.ValidateProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: true }) }), modulo)(type)), | ||
@@ -36,0 +33,0 @@ StatementFactory_1.StatementFactory.constant("stringify", StringifyProgrammer_1.StringifyProgrammer.generate(__assign(__assign({}, project), { options: __assign(__assign({}, project.options), { functional: false, numeric: false }) }), modulo)(type)), |
{ | ||
"name": "typia", | ||
"version": "3.6.0-dev.20230219", | ||
"version": "3.6.0-dev.20230225", | ||
"description": "Superfast runtime validators with only one line", | ||
@@ -113,3 +113,3 @@ "main": "lib/index.js", | ||
"ttypescript": "^1.5.15", | ||
"typescript": "^4.9.4", | ||
"typescript": "^4.9.5", | ||
"typescript-transform-paths": "^3.4.6", | ||
@@ -116,0 +116,0 @@ "uuid": "^8.3.2", |
@@ -57,3 +57,3 @@ # Typia | ||
[![Backers](https://opencollective.com/typia/backers.svg?width=1000)](https://opencollective.com/typia) | ||
[![Backers](https://opencollective.com/typia/backers.svg?avatarHeight=75&width=600))](https://opencollective.com/typia) | ||
@@ -317,2 +317,2 @@ | ||
); | ||
``` | ||
``` |
@@ -5,2 +5,3 @@ import type CommanderModule from "commander"; | ||
import { FileRetriever } from "./FileRetriever"; | ||
import { PackageManager } from "./PackageManager"; | ||
@@ -50,9 +51,10 @@ | ||
// LOAD INSTALLED MODULES | ||
const { program: command }: typeof CommanderModule = await import( | ||
path.join(pack.directory, "node_modules", "commander") | ||
); | ||
const { program: command }: typeof CommanderModule = | ||
await FileRetriever.require( | ||
path.join("node_modules", "commander"), | ||
)(pack.directory); | ||
const { createPromptModule: prompt }: typeof InquirerModule = | ||
await import( | ||
path.join(pack.directory, "node_modules", "inquirer") | ||
); | ||
await FileRetriever.require( | ||
path.join("node_modules", "inquirer"), | ||
)(pack.directory); | ||
@@ -59,0 +61,0 @@ // TAKE OPTIONS |
@@ -0,0 +0,0 @@ import cp from "child_process"; |
@@ -5,2 +5,3 @@ import fs from "fs"; | ||
import { CommandExecutor } from "./CommandExecutor"; | ||
import { FileRetriever } from "./FileRetriever"; | ||
@@ -14,3 +15,5 @@ export class PackageManager { | ||
public static async mount(): Promise<PackageManager> { | ||
const location: string | null = await find(process.cwd()); | ||
const location: string | null = await FileRetriever.directory( | ||
"package.json", | ||
)(process.cwd()); | ||
if (location === null) | ||
@@ -48,5 +51,5 @@ throw new Error(`Unable to find "package.json" file`); | ||
!!container?.[props.modulo] && | ||
fs.existsSync( | ||
path.join(this.directory, "node_modules", props.modulo), | ||
) | ||
FileRetriever.file(path.join("node_modules", props.modulo))( | ||
this.directory, | ||
) !== null | ||
) | ||
@@ -93,11 +96,1 @@ return false; | ||
} | ||
async function find( | ||
directory: string = process.cwd(), | ||
depth: number = 0, | ||
): Promise<string | null> { | ||
const location: string = path.join(directory, "package.json"); | ||
if (fs.existsSync(location)) return directory; | ||
else if (depth > 1) return null; | ||
return find(path.join(directory, ".."), depth + 1); | ||
} |
@@ -6,2 +6,3 @@ import type Comment from "comment-json"; | ||
import { TypiaSetupWizard } from "../TypiaSetupWizard"; | ||
import { FileRetriever } from "./FileRetriever"; | ||
import { PackageManager } from "./PackageManager"; | ||
@@ -46,5 +47,6 @@ | ||
// GET COMPILER-OPTIONS | ||
const Comment: typeof import("comment-json") = await import( | ||
path.join(pack.directory, "node_modules", "comment-json") | ||
); | ||
const Comment: typeof import("comment-json") = | ||
await FileRetriever.require( | ||
path.join("node_modules", "comment-json"), | ||
)(pack.directory); | ||
@@ -51,0 +53,0 @@ const config: Comment.CommentObject = Comment.parse( |
@@ -21,3 +21,3 @@ #!/usr/bin/env node | ||
--npx typia setup --input src/templates --output src/functinoal | ||
--npx typia generate --input src/templates --output src/functinoal | ||
`; | ||
@@ -24,0 +24,0 @@ |
import fs from "fs"; | ||
import { TypiaGenerator } from "../generate/TypiaGenerator"; | ||
import { TypiaFileFactory } from "../factories/TypiaFileFactory"; | ||
import { ArgumentParser } from "./setup/ArgumentParser"; | ||
@@ -18,3 +19,3 @@ import { PackageManager } from "./setup/PackageManager"; | ||
); | ||
await TypiaGenerator.generate(options); | ||
await TypiaFileFactory.generate(options); | ||
} | ||
@@ -29,4 +30,4 @@ | ||
// PREPARE ASSETS | ||
command.option("--input <path>", "input directory"); | ||
command.option("--output <directory>", "output directory"); | ||
command.option("--input [path]", "input directory"); | ||
command.option("--output [directory]", "output directory"); | ||
command.option("--project [project]", "tsconfig.json file location"); | ||
@@ -33,0 +34,0 @@ |
@@ -0,0 +0,0 @@ import fs from "fs"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../../metadata/Metadata"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -58,3 +58,3 @@ import ts from "typescript"; | ||
// PRIMITIVE | ||
symbol ||= type.aliasSymbol || type.getSymbol(); | ||
symbol ??= type.aliasSymbol ?? type.getSymbol(); | ||
if (symbol === undefined) return checker.typeToString(type); | ||
@@ -61,0 +61,0 @@ |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
export function $any(val: any): any { | ||
return val !== undefined ? JSON.parse(JSON.stringify(val)) : undefined; | ||
} |
@@ -0,0 +0,0 @@ import { TypeGuardError } from "../TypeGuardError"; |
@@ -0,0 +0,0 @@ import { TypeGuardError } from "../TypeGuardError"; |
@@ -0,0 +0,0 @@ export function $is_between( |
@@ -0,0 +0,0 @@ export function $is_email(str: string): boolean { |
@@ -0,0 +0,0 @@ export function $is_ipv4(str: string): boolean { |
@@ -0,0 +0,0 @@ export function $is_ipv6(str: string): boolean { |
@@ -0,0 +0,0 @@ export function $is_url(str: string): boolean { |
@@ -0,0 +0,0 @@ export function $is_uuid(str: string): boolean { |
@@ -0,0 +0,0 @@ export function $join(str: string): string { |
@@ -0,0 +0,0 @@ import { TypeGuardError } from "../TypeGuardError"; |
@@ -0,0 +0,0 @@ import { IValidation } from "../IValidation"; |
export function $rest(str: string): string { | ||
return str.length === 2 ? "" : "," + str.substring(1, str.length - 1); | ||
} |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ import { RandomGenerator } from "../utils/RandomGenerator"; |
@@ -0,0 +0,0 @@ import * as typia from "./module"; |
export interface IRandomGenerator { | ||
boolean(): boolean; | ||
int(minimum?: number, maximum?: number): number; | ||
integer(minimum?: number, maximum?: number): number; | ||
number(minimum?: number, maximum?: number): number; | ||
@@ -9,9 +9,9 @@ bigint(minimum?: bigint, maximum?: bigint): bigint; | ||
uuid?(): string; | ||
email?(): string; | ||
url?(): string; | ||
ipv4?(): string; | ||
ipv6?(): string; | ||
pattern?(regex: RegExp): string; | ||
date?(): string; | ||
uuid(): string; | ||
email(): string; | ||
url(): string; | ||
ipv4(): string; | ||
ipv6(): string; | ||
pattern(regex: RegExp): string; | ||
date(): string; | ||
} |
@@ -0,0 +0,0 @@ export type IValidation<T = unknown> = |
@@ -0,0 +0,0 @@ export interface IJsDocTagInfo { |
@@ -0,0 +0,0 @@ import { Atomic } from "../typings/Atomic"; |
@@ -0,0 +0,0 @@ import { IMetadata } from "./IMetadata"; |
@@ -0,0 +0,0 @@ import { Atomic } from "../typings/Atomic"; |
@@ -0,0 +0,0 @@ import { IMetadata } from "./IMetadata"; |
@@ -0,0 +0,0 @@ import { IJsDocTagInfo } from "./IJsDocTagInfo"; |
@@ -0,0 +0,0 @@ import { IJsDocTagInfo } from "./IJsDocTagInfo"; |
@@ -0,0 +0,0 @@ export type IMetadataTag = |
@@ -0,0 +0,0 @@ import { Atomic } from "../typings/Atomic"; |
import { IMetadataConstant } from "./IMetadataConstant"; | ||
export import MetadataConstant = IMetadataConstant; |
@@ -0,0 +0,0 @@ import { ClassProperties } from "../typings/ClassProperties"; |
@@ -0,0 +0,0 @@ import { ClassProperties } from "../typings/ClassProperties"; |
@@ -39,3 +39,5 @@ /** | ||
? Instance extends object | ||
? Instance extends IJsonable<infer Raw> | ||
? Instance extends _Native | ||
? {} | ||
: Instance extends IJsonable<infer Raw> | ||
? _ValueOf<Raw> extends object | ||
@@ -66,2 +68,22 @@ ? Raw extends object | ||
type _Native = | ||
| Set<any> | ||
| Map<any, any> | ||
| WeakSet<any> | ||
| WeakMap<any, any> | ||
| Uint8Array | ||
| Uint8ClampedArray | ||
| Uint16Array | ||
| Uint32Array | ||
| BigUint64Array | ||
| Int8Array | ||
| Int16Array | ||
| Int32Array | ||
| BigInt64Array | ||
| Float32Array | ||
| Float64Array | ||
| ArrayBuffer | ||
| SharedArrayBuffer | ||
| DataView; | ||
type _IsValueOf< | ||
@@ -68,0 +90,0 @@ Instance, |
@@ -0,0 +0,0 @@ import { Metadata } from "../metadata/Metadata"; |
@@ -25,9 +25,8 @@ import ts from "typescript"; | ||
], | ||
ts.factory.createTypeReferenceNode("typia.Primitive", [ | ||
project.checker.typeToTypeNode( | ||
ts.factory.createTypeReferenceNode( | ||
`typia.Primitive<${TypeFactory.getFullName( | ||
project.checker, | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
]), | ||
)}>`, | ||
), | ||
undefined, | ||
@@ -69,10 +68,3 @@ ts.factory.createBlock([ | ||
ts.factory.createReturnStatement( | ||
ts.factory.createAsExpression( | ||
ts.factory.createIdentifier("output"), | ||
project.checker.typeToTypeNode( | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
), | ||
ts.factory.createIdentifier("output"), | ||
), | ||
@@ -79,0 +71,0 @@ ]), |
@@ -24,9 +24,8 @@ import ts from "typescript"; | ||
], | ||
ts.factory.createTypeReferenceNode("typia.Primitive", [ | ||
project.checker.typeToTypeNode( | ||
ts.factory.createTypeReferenceNode( | ||
`typia.Primitive<${TypeFactory.getFullName( | ||
project.checker, | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
]), | ||
)}>`, | ||
), | ||
undefined, | ||
@@ -33,0 +32,0 @@ ts.factory.createBlock([ |
@@ -49,4 +49,6 @@ import ts from "typescript"; | ||
], | ||
ts.factory.createTypeReferenceNode( | ||
TypeFactory.getFullName(project.checker, type), | ||
), | ||
undefined, | ||
undefined, | ||
ts.factory.createBlock( | ||
@@ -67,10 +69,3 @@ [ | ||
ts.factory.createReturnStatement( | ||
ts.factory.createAsExpression( | ||
ts.factory.createIdentifier("input"), | ||
project.checker.typeToTypeNode( | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
), | ||
ts.factory.createIdentifier(`input`), | ||
), | ||
@@ -94,4 +89,4 @@ ], | ||
const path: string = explore.postfix | ||
? `path + ${explore.postfix}` | ||
: "path"; | ||
? `_path + ${explore.postfix}` | ||
: "_path"; | ||
return (logic) => (input, binaries, expected) => | ||
@@ -109,3 +104,3 @@ logic === "and" | ||
: ts.factory.createIdentifier( | ||
"exceptionable", | ||
"_exceptionable", | ||
), | ||
@@ -131,3 +126,3 @@ )( | ||
: ts.factory.createIdentifier( | ||
"exceptionable", | ||
"_exceptionable", | ||
), | ||
@@ -145,15 +140,2 @@ )( | ||
})(); | ||
// ts.factory.createLogicalOr( | ||
// binaries | ||
// .map((binary) => binary.expression) | ||
// .reduce(ts.factory.createLogicalOr), | ||
// create_guard_call(importer)( | ||
// explore.source === "top" | ||
// ? ts.factory.createTrue() | ||
// : ts.factory.createIdentifier( | ||
// "exceptionable", | ||
// ), | ||
// )(ts.factory.createIdentifier(path), expected, input), | ||
// ); | ||
}; | ||
@@ -171,3 +153,3 @@ | ||
ts.factory.createAdd( | ||
ts.factory.createIdentifier("path"), | ||
ts.factory.createIdentifier("_path"), | ||
ts.factory.createCallExpression( | ||
@@ -186,3 +168,3 @@ importer.use("join"), | ||
ts.factory.createFalse(), | ||
ts.factory.createIdentifier("exceptionable"), | ||
ts.factory.createIdentifier("_exceptionable"), | ||
), | ||
@@ -207,6 +189,8 @@ expr, | ||
? ts.factory.createTrue() | ||
: ts.factory.createIdentifier("exceptionable"), | ||
: ts.factory.createIdentifier("_exceptionable"), | ||
)( | ||
ts.factory.createIdentifier( | ||
explore?.postfix ? `path + ${explore.postfix}` : "path", | ||
explore?.postfix | ||
? `_path + ${explore.postfix}` | ||
: "_path", | ||
), | ||
@@ -225,6 +209,6 @@ expected, | ||
: ts.factory.createIdentifier( | ||
"exceptionable", | ||
"_exceptionable", | ||
), | ||
)( | ||
ts.factory.createIdentifier("path"), | ||
ts.factory.createIdentifier("_path"), | ||
expected, | ||
@@ -245,3 +229,3 @@ input, | ||
ts.factory.createCallExpression(importer.use("guard"), undefined, [ | ||
exceptionable || ts.factory.createIdentifier("exceptionable"), | ||
exceptionable ?? ts.factory.createIdentifier("_exceptionable"), | ||
ts.factory.createObjectLiteralExpression( | ||
@@ -248,0 +232,0 @@ [ |
@@ -25,4 +25,5 @@ import ts from "typescript"; | ||
], | ||
project.checker.typeToTypeNode(type, undefined, undefined) ?? | ||
TypeFactory.keyword("any"), | ||
ts.factory.createTypeReferenceNode( | ||
TypeFactory.getFullName(project.checker, type), | ||
), | ||
undefined, | ||
@@ -29,0 +30,0 @@ ts.factory.createBlock([ |
@@ -22,7 +22,3 @@ import ts from "typescript"; | ||
"input", | ||
project.checker.typeToTypeNode( | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
TypeFactory.keyword("any"), | ||
), | ||
@@ -29,0 +25,0 @@ ], |
@@ -121,3 +121,3 @@ import ts from "typescript"; | ||
CONFIG(project, { ...config, numeric: false }, importer), | ||
); | ||
)(importer); | ||
@@ -136,6 +136,4 @@ function CONFIG( | ||
"input", | ||
project.checker.typeToTypeNode( | ||
type, | ||
undefined, | ||
undefined, | ||
ts.factory.createTypeReferenceNode( | ||
TypeFactory.getFullName(project.checker, type), | ||
), | ||
@@ -164,8 +162,8 @@ ), | ||
checker: config.decoder || decode(project, config, importer), | ||
decoder: decode_object(config), | ||
decoder: decode_object(config)(importer), | ||
joiner: config.joiner.object, | ||
unionizer: config.equals | ||
? decode_union_object(decode_object(config))( | ||
? decode_union_object(decode_object(config)(importer))( | ||
(input, obj, explore) => | ||
decode_object(config)(input, obj, { | ||
decode_object(config)(importer)(input, obj, { | ||
...explore, | ||
@@ -184,3 +182,3 @@ tracable: true, | ||
targets.map((obj) => ({ | ||
expression: decode_object(config)( | ||
expression: decode_object(config)(importer)( | ||
input, | ||
@@ -201,2 +199,3 @@ obj, | ||
full: config.joiner.full, | ||
type: TypeFactory.keyword("boolean"), | ||
}, | ||
@@ -208,3 +207,3 @@ }; | ||
CONFIG(project, { ...config, numeric: false }, importer), | ||
), | ||
)(importer), | ||
}; | ||
@@ -499,3 +498,3 @@ return output; | ||
)( | ||
explore_objects(config)(input, meta, { | ||
explore_objects(config)(importer)(input, meta, { | ||
...explore, | ||
@@ -695,13 +694,14 @@ from: "object", | ||
export function decode_object(config: IConfig) { | ||
const func = FeatureProgrammer.decode_object(config); | ||
return function ( | ||
input: ts.Expression, | ||
obj: MetadataObject, | ||
explore: IExplore, | ||
) { | ||
obj.validated = true; | ||
return func(input, obj, explore); | ||
export const decode_object = | ||
(config: IConfig) => (importer: FunctionImporter) => { | ||
const func = FeatureProgrammer.decode_object(config)(importer); | ||
return function ( | ||
input: ts.Expression, | ||
obj: MetadataObject, | ||
explore: IExplore, | ||
) { | ||
obj.validated = true; | ||
return func(input, obj, explore); | ||
}; | ||
}; | ||
} | ||
@@ -858,18 +858,27 @@ const explore_sets = ( | ||
const explore_objects = (config: IConfig) => { | ||
const objector = decode_object(config); | ||
const explore_objects = | ||
(config: IConfig) => (importer: FunctionImporter) => { | ||
const objector = decode_object(config)(importer); | ||
return (input: ts.Expression, meta: Metadata, explore: IExplore) => { | ||
if (meta.objects.length === 1) | ||
return objector(input, meta.objects[0]!, explore); | ||
return ( | ||
input: ts.Expression, | ||
meta: Metadata, | ||
explore: IExplore, | ||
) => { | ||
if (meta.objects.length === 1) | ||
return objector(input, meta.objects[0]!, explore); | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier( | ||
`${config.unioners}${meta.union_index!}`, | ||
), | ||
undefined, | ||
FeatureProgrammer.get_object_arguments(config)(explore)(input), | ||
); | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier( | ||
importer.useLocal( | ||
`${config.unioners}${meta.union_index!}`, | ||
), | ||
), | ||
undefined, | ||
FeatureProgrammer.get_object_arguments(config)(explore)( | ||
input, | ||
), | ||
); | ||
}; | ||
}; | ||
}; | ||
} | ||
@@ -876,0 +885,0 @@ |
@@ -42,4 +42,8 @@ import ts from "typescript"; | ||
...importer.declare(modulo), | ||
...isFunctors, | ||
...isUnioners, | ||
...isFunctors.filter((_, i) => | ||
importer.hasLocal(`$io${i}`), | ||
), | ||
...isUnioners.filter((_, i) => | ||
importer.hasLocal(`$iu${i}`), | ||
), | ||
]; | ||
@@ -148,3 +152,12 @@ }, | ||
is: () => ExpressionFactory.isInstanceOf(input, native), | ||
value: () => ts.factory.createIdentifier("{}"), | ||
value: () => | ||
native === "Boolean" || | ||
native === "Number" || | ||
native === "String" | ||
? ts.factory.createCallExpression( | ||
IdentifierFactory.join(input, "valueOf"), | ||
undefined, | ||
undefined, | ||
) | ||
: ts.factory.createIdentifier("{}"), | ||
}); | ||
@@ -162,3 +175,3 @@ | ||
value: () => | ||
explore_objects(input, meta, { | ||
explore_objects(importer)(input, meta, { | ||
...explore, | ||
@@ -179,3 +192,6 @@ from: "object", | ||
); | ||
return last; | ||
return ts.factory.createAsExpression( | ||
last, | ||
TypeFactory.keyword("any"), | ||
); | ||
}; | ||
@@ -254,3 +270,3 @@ | ||
const decode_object = () => | ||
const decode_object = (importer: FunctionImporter) => | ||
FeatureProgrammer.decode_object({ | ||
@@ -260,3 +276,3 @@ trace: false, | ||
functors: FUNCTORS, | ||
}); | ||
})(importer); | ||
@@ -273,16 +289,22 @@ const explore_arrays = (project: IProject, importer: FunctionImporter) => | ||
const explore_objects = ( | ||
input: ts.Expression, | ||
meta: Metadata, | ||
explore: FeatureProgrammer.IExplore, | ||
) => { | ||
if (meta.objects.length === 1) | ||
return decode_object()(input, meta.objects[0]!, explore); | ||
const explore_objects = | ||
(importer: FunctionImporter) => | ||
( | ||
input: ts.Expression, | ||
meta: Metadata, | ||
explore: FeatureProgrammer.IExplore, | ||
) => { | ||
if (meta.objects.length === 1) | ||
return decode_object(importer)( | ||
input, | ||
meta.objects[0]!, | ||
explore, | ||
); | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier(`${UNIONERS}${meta.union_index!}`), | ||
undefined, | ||
[input], | ||
); | ||
}; | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier(`${UNIONERS}${meta.union_index!}`), | ||
undefined, | ||
[input], | ||
); | ||
}; | ||
@@ -301,12 +323,12 @@ /* ----------------------------------------------------------- | ||
input: (type) => | ||
project.checker.typeToTypeNode(type, undefined, undefined) ?? | ||
TypeFactory.keyword("any"), | ||
ts.factory.createTypeReferenceNode( | ||
TypeFactory.getFullName(project.checker, type), | ||
), | ||
output: (type) => | ||
ts.factory.createTypeReferenceNode("typia.Primitive", [ | ||
project.checker.typeToTypeNode( | ||
ts.factory.createTypeReferenceNode( | ||
`typia.Primitive<${TypeFactory.getFullName( | ||
project.checker, | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
]), | ||
)}>`, | ||
), | ||
}, | ||
@@ -327,6 +349,6 @@ functors: FUNCTORS, | ||
checker: IsProgrammer.decode(project, importer), | ||
decoder: decode_object(), | ||
decoder: decode_object(importer), | ||
joiner: CloneJoiner.object, | ||
unionizer: decode_union_object(IsProgrammer.decode_object(importer))( | ||
decode_object(), | ||
decode_object(importer), | ||
)((exp) => exp)((value, expected) => | ||
@@ -333,0 +355,0 @@ create_throw_error(importer, value, expected), |
@@ -73,4 +73,4 @@ import ts from "typescript"; | ||
export interface ITypes { | ||
input: (type: ts.Type) => ts.TypeNode; | ||
output: (type: ts.Type) => ts.TypeNode; | ||
input: (type: ts.Type, node?: ts.TypeNode) => ts.TypeNode; | ||
output: (type: ts.Type, node?: ts.TypeNode) => ts.TypeNode; | ||
} | ||
@@ -169,2 +169,7 @@ | ||
) => ts.Expression; | ||
/** | ||
* Return type. | ||
*/ | ||
type?: ts.TypeNode; | ||
} | ||
@@ -227,3 +232,3 @@ export interface IGenerator { | ||
) => | ||
(type: ts.Type) => { | ||
(type: ts.Type, typeNode?: ts.TypeNode) => { | ||
const [collection, meta] = config.initializer(project, type); | ||
@@ -245,10 +250,10 @@ | ||
// RETURNS THE OPTIMAL ARROW FUNCTION | ||
const functors: ts.VariableStatement[] = | ||
config.generator?.functors !== undefined | ||
? config.generator.functors(collection) | ||
: generate_functors(config)(importer)(collection); | ||
const unioners: ts.VariableStatement[] = | ||
config.generator?.unioners !== undefined | ||
? config.generator.unioners(collection) | ||
: generate_unioners(config)(collection); | ||
const functors: ts.VariableStatement[] = ( | ||
config.generator?.functors ?? | ||
generate_functors(config)(importer) | ||
)(collection); | ||
const unioners: ts.VariableStatement[] = ( | ||
config.generator?.unioners ?? | ||
generate_unioners(config)(importer) | ||
)(collection); | ||
const added: ts.Statement[] | undefined = addition(collection); | ||
@@ -259,6 +264,6 @@ | ||
undefined, | ||
PARAMETERS(config)(config.types.input(type))( | ||
PARAMETERS(config)(config.types.input(type, typeNode))( | ||
ValueFactory.INPUT(), | ||
), | ||
config.types.output(type), | ||
config.types.output(type, typeNode), | ||
undefined, | ||
@@ -268,4 +273,8 @@ ts.factory.createBlock( | ||
...(added || []), | ||
...functors, | ||
...unioners, | ||
...functors.filter((_, i) => | ||
importer.hasLocal(`${config.functors}${i}`), | ||
), | ||
...unioners.filter((_, i) => | ||
importer.hasLocal(`${config.unioners}${i}`), | ||
), | ||
...(ts.isBlock(output) | ||
@@ -294,3 +303,5 @@ ? output.statements | ||
export const generate_unioners = | ||
(config: IConfig) => (collection: MetadataCollection) => | ||
(config: IConfig) => | ||
(importer: FunctionImporter) => | ||
(collection: MetadataCollection) => | ||
collection | ||
@@ -300,3 +311,3 @@ .unions() | ||
StatementFactory.constant( | ||
`${config.unioners}${i}`, | ||
importer.useLocal(`${config.unioners}${i}`), | ||
generate_union(config)(union), | ||
@@ -316,4 +327,4 @@ ), | ||
), | ||
config.objector.type ?? TypeFactory.keyword("any"), | ||
undefined, | ||
undefined, | ||
config.objector.joiner( | ||
@@ -339,4 +350,4 @@ ts.factory.createIdentifier("input"), | ||
), | ||
TypeFactory.keyword("any"), | ||
undefined, | ||
undefined, | ||
explorer( | ||
@@ -373,3 +384,3 @@ input, | ||
IdentifierFactory.parameter( | ||
"index" + rand, | ||
"_index" + rand, | ||
TypeFactory.keyword("number"), | ||
@@ -418,5 +429,8 @@ ), | ||
(config: Pick<IConfig, "trace" | "path" | "functors">) => | ||
(importer: FunctionImporter) => | ||
(input: ts.Expression, obj: MetadataObject, explore: IExplore) => | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier(`${config.functors}${obj.index}`), | ||
ts.factory.createIdentifier( | ||
importer.useLocal(`${config.functors}${obj.index}`), | ||
), | ||
undefined, | ||
@@ -436,8 +450,8 @@ get_object_arguments(config)(explore)(input), | ||
explore.postfix | ||
? `path + ${explore.postfix}` | ||
: "path", | ||
? `_path + ${explore.postfix}` | ||
: "_path", | ||
), | ||
explore.source === "object" | ||
? ts.factory.createIdentifier( | ||
`${explore.tracable} && exceptionable`, | ||
`${explore.tracable} && _exceptionable`, | ||
) | ||
@@ -452,4 +466,4 @@ : explore.tracable | ||
explore.postfix | ||
? `path + ${explore.postfix}` | ||
: "path", | ||
? `_path + ${explore.postfix}` | ||
: "_path", | ||
), | ||
@@ -460,3 +474,3 @@ ] | ||
? ts.factory.createIdentifier( | ||
`${explore.tracable} && exceptionable`, | ||
`${explore.tracable} && _exceptionable`, | ||
) | ||
@@ -475,4 +489,4 @@ : explore.tracable | ||
start !== null | ||
? `"[" + (${start} + index${rand}) + "]"` | ||
: `"[" + index${rand} + "]"`; | ||
? `"[" + (${start} + _index${rand}) + "]"` | ||
: `"[" + _index${rand} + "]"`; | ||
if (prev === "") return tail; | ||
@@ -483,2 +497,3 @@ else if (prev[prev.length - 1] === `"`) | ||
}; | ||
const PARAMETERS = | ||
@@ -491,3 +506,3 @@ (props: Pick<CheckerProgrammer.IConfig, "path" | "trace">) => | ||
IdentifierFactory.parameter( | ||
"path", | ||
"_path", | ||
TypeFactory.keyword("string"), | ||
@@ -499,7 +514,7 @@ ), | ||
IdentifierFactory.parameter( | ||
"exceptionable", | ||
"_exceptionable", | ||
TypeFactory.keyword("boolean"), | ||
ts.factory.createTrue(), | ||
), | ||
); | ||
return (input: ts.Identifier) => [ | ||
@@ -506,0 +521,0 @@ IdentifierFactory.parameter(input, type), |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
import ts from "typescript"; | ||
import { StatementFactory } from "../../factories/StatementFactory"; | ||
import { TypeFactory } from "../../factories/TypeFactory"; | ||
@@ -68,3 +69,9 @@ import { MetadataObject } from "../../metadata/MetadataObject"; | ||
return ts.factory.createBlock([ | ||
StatementFactory.constant("output", literal), | ||
StatementFactory.constant( | ||
"output", | ||
ts.factory.createAsExpression( | ||
literal, | ||
TypeFactory.keyword("any"), | ||
), | ||
), | ||
ts.factory.createForOfStatement( | ||
@@ -111,7 +118,10 @@ undefined, | ||
): ts.Expression => { | ||
if (rest === null) | ||
return ts.factory.createArrayLiteralExpression(children, true); | ||
return ts.factory.createArrayLiteralExpression( | ||
[...children, ts.factory.createSpreadElement(rest)], | ||
true, | ||
return ts.factory.createAsExpression( | ||
ts.factory.createArrayLiteralExpression( | ||
rest === null | ||
? children | ||
: [...children, ts.factory.createSpreadElement(rest)], | ||
true, | ||
), | ||
TypeFactory.keyword("any"), | ||
); | ||
@@ -118,0 +128,0 @@ }; |
@@ -9,2 +9,3 @@ import ts from "typescript"; | ||
private readonly used_: Set<string> = new Set(); | ||
private readonly local_: Set<string> = new Set(); | ||
private sequence_: number = 0; | ||
@@ -21,2 +22,11 @@ | ||
public useLocal(name: string): string { | ||
this.local_.add(name); | ||
return name; | ||
} | ||
public hasLocal(name: string): boolean { | ||
return this.local_.has(name); | ||
} | ||
public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] { | ||
@@ -42,2 +52,7 @@ return [...this.used_].map((name) => | ||
} | ||
public trace(): void { | ||
console.log(...this.used_); | ||
console.log(...this.local_); | ||
} | ||
} |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import { ITransformOptions } from "../../transformers/ITransformOptions"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
import ts from "typescript"; | ||
import { StatementFactory } from "../../factories/StatementFactory"; | ||
import { TypeFactory } from "../../factories/TypeFactory"; | ||
@@ -21,4 +22,6 @@ import { IMetadataTag } from "../../metadata/IMetadataTag"; | ||
export const array = | ||
(decoder: Decoder) => (item: Metadata, tags: IMetadataTag[]) => { | ||
const tail = RandomRanger.length({ | ||
(coalesce: (method: string) => ts.Expression) => | ||
(decoder: Decoder) => | ||
(item: Metadata, tags: IMetadataTag[]) => { | ||
const tail = RandomRanger.length(coalesce)({ | ||
minimum: 0, | ||
@@ -33,3 +36,3 @@ maximum: 3, | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("generator.array"), | ||
coalesce("array"), | ||
undefined, | ||
@@ -58,2 +61,3 @@ [ | ||
export const object = | ||
(coalesce: (method: string) => ts.Expression) => | ||
(decoder: Decoder) => | ||
@@ -88,3 +92,3 @@ (obj: MetadataObject): ts.ConciseBody => { | ||
ts.factory.createExpressionStatement( | ||
dynamicProperty(decoder)(p), | ||
dynamicProperty(coalesce)(decoder)(p), | ||
), | ||
@@ -94,3 +98,9 @@ ); | ||
[ | ||
StatementFactory.constant("output", literal), | ||
StatementFactory.constant( | ||
"output", | ||
ts.factory.createAsExpression( | ||
literal, | ||
TypeFactory.keyword("any"), | ||
), | ||
), | ||
...(obj.recursive | ||
@@ -101,3 +111,3 @@ ? [ | ||
ts.factory.createNumericLiteral(5), | ||
ts.factory.createIdentifier("depth"), | ||
ts.factory.createIdentifier("_depth"), | ||
), | ||
@@ -116,7 +126,7 @@ ts.factory.createBlock(properties, true), | ||
const dynamicProperty = (decoder: Decoder) => (p: MetadataProperty) => | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("generator.array"), | ||
undefined, | ||
[ | ||
const dynamicProperty = | ||
(coalesce: (method: string) => ts.Expression) => | ||
(decoder: Decoder) => | ||
(p: MetadataProperty) => | ||
ts.factory.createCallExpression(coalesce("array"), undefined, [ | ||
ts.factory.createArrowFunction( | ||
@@ -138,3 +148,3 @@ undefined, | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("generator.integer"), | ||
coalesce("integer"), | ||
undefined, | ||
@@ -146,4 +156,3 @@ [ | ||
), | ||
], | ||
); | ||
]); | ||
} |
@@ -13,2 +13,3 @@ import ts from "typescript"; | ||
export const length = | ||
(coalesce: (method: string) => ts.Expression) => | ||
(defs: IDefaults) => | ||
@@ -33,3 +34,3 @@ (acc: length.IAccessors) => | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("generator.integer"), | ||
coalesce("integer"), | ||
undefined, | ||
@@ -36,0 +37,0 @@ [ |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
@@ -0,0 +0,0 @@ import { IJsonSchema } from "../../module"; |
@@ -0,0 +0,0 @@ import { MetadataConstant } from "../../metadata/MetadataConstant"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
@@ -0,0 +0,0 @@ import { IJsonSchema } from "../../schemas/IJsonSchema"; |
@@ -0,0 +0,0 @@ import { IJsonComponents } from "../../schemas/IJsonComponents"; |
@@ -0,0 +0,0 @@ import { IJsonSchema } from "../../module"; |
@@ -0,0 +0,0 @@ import { CommentFactory } from "../../factories/CommentFactory"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -44,3 +44,8 @@ import ts from "typescript"; | ||
undefined, | ||
[IdentifierFactory.parameter("top")], | ||
[ | ||
IdentifierFactory.parameter( | ||
"top", | ||
TypeFactory.keyword("any"), | ||
), | ||
], | ||
undefined, | ||
@@ -63,3 +68,8 @@ undefined, | ||
undefined, | ||
[IdentifierFactory.parameter("top")], | ||
[ | ||
IdentifierFactory.parameter( | ||
"top", | ||
TypeFactory.keyword("any"), | ||
), | ||
], | ||
undefined, | ||
@@ -66,0 +76,0 @@ undefined, |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -59,2 +59,3 @@ import ts from "typescript"; | ||
]), | ||
ts.factory.createTypeReferenceNode("[string, any]"), | ||
), | ||
@@ -61,0 +62,0 @@ ], |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import { Metadata } from "../../metadata/Metadata"; |
@@ -26,9 +26,8 @@ import ts from "typescript"; | ||
ts.factory.createUnionTypeNode([ | ||
ts.factory.createTypeReferenceNode("typia.Primitive", [ | ||
project.checker.typeToTypeNode( | ||
ts.factory.createTypeReferenceNode( | ||
`typia.Primitive<${TypeFactory.getFullName( | ||
project.checker, | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
]), | ||
)}>`, | ||
), | ||
ts.factory.createLiteralTypeNode(ts.factory.createNull()), | ||
@@ -35,0 +34,0 @@ ]), |
@@ -24,9 +24,8 @@ import ts from "typescript"; | ||
], | ||
ts.factory.createTypeReferenceNode("typia.Primitive", [ | ||
project.checker.typeToTypeNode( | ||
ts.factory.createTypeReferenceNode( | ||
`typia.Primitive<${TypeFactory.getFullName( | ||
project.checker, | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
]), | ||
)}>`, | ||
), | ||
undefined, | ||
@@ -33,0 +32,0 @@ ts.factory.createBlock([ |
@@ -176,3 +176,3 @@ import ts from "typescript"; | ||
export const decode_object = (importer: FunctionImporter) => | ||
CheckerProgrammer.decode_object(CONFIG()(importer)); | ||
CheckerProgrammer.decode_object(CONFIG()(importer))(importer); | ||
@@ -179,0 +179,0 @@ export function decode_to_json( |
@@ -28,7 +28,5 @@ import ts from "typescript"; | ||
"input", | ||
project.checker.typeToTypeNode( | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
ts.factory.createTypeReferenceNode( | ||
TypeFactory.getFullName(project.checker, type), | ||
), | ||
), | ||
@@ -35,0 +33,0 @@ undefined, |
@@ -22,7 +22,5 @@ import ts from "typescript"; | ||
"input", | ||
project.checker.typeToTypeNode( | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
ts.factory.createTypeReferenceNode( | ||
TypeFactory.getFullName(project.checker, type), | ||
), | ||
), | ||
@@ -29,0 +27,0 @@ ], |
@@ -42,4 +42,8 @@ import ts from "typescript"; | ||
...importer.declare(modulo), | ||
...isFunctors, | ||
...isUnioners, | ||
...isFunctors.filter((_, i) => | ||
importer.hasLocal(`$io${i}`), | ||
), | ||
...isUnioners.filter((_, i) => | ||
importer.hasLocal(`$iu${i}`), | ||
), | ||
]; | ||
@@ -141,3 +145,3 @@ }, | ||
value: () => | ||
explore_objects(input, meta, { | ||
explore_objects(importer)(input, meta, { | ||
...explore, | ||
@@ -218,3 +222,3 @@ from: "object", | ||
const decode_object = () => | ||
const decode_object = (importer: FunctionImporter) => | ||
FeatureProgrammer.decode_object({ | ||
@@ -224,3 +228,3 @@ trace: false, | ||
functors: FUNCTORS, | ||
}); | ||
})(importer); | ||
@@ -237,16 +241,22 @@ const explore_arrays = (project: IProject, importer: FunctionImporter) => | ||
const explore_objects = ( | ||
input: ts.Expression, | ||
meta: Metadata, | ||
explore: FeatureProgrammer.IExplore, | ||
) => { | ||
if (meta.objects.length === 1) | ||
return decode_object()(input, meta.objects[0]!, explore); | ||
const explore_objects = | ||
(importer: FunctionImporter) => | ||
( | ||
input: ts.Expression, | ||
meta: Metadata, | ||
explore: FeatureProgrammer.IExplore, | ||
) => { | ||
if (meta.objects.length === 1) | ||
return decode_object(importer)( | ||
input, | ||
meta.objects[0]!, | ||
explore, | ||
); | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier(`${UNIONERS}${meta.union_index!}`), | ||
undefined, | ||
[input], | ||
); | ||
}; | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier(`${UNIONERS}${meta.union_index!}`), | ||
undefined, | ||
[input], | ||
); | ||
}; | ||
@@ -271,4 +281,5 @@ const filter = (meta: Metadata): boolean => | ||
input: (type) => | ||
project.checker.typeToTypeNode(type, undefined, undefined) ?? | ||
TypeFactory.keyword("any"), | ||
ts.factory.createTypeReferenceNode( | ||
TypeFactory.getFullName(project.checker, type), | ||
), | ||
output: () => TypeFactory.keyword("void"), | ||
@@ -290,6 +301,6 @@ }, | ||
checker: IsProgrammer.decode(project, importer), | ||
decoder: decode_object(), | ||
decoder: decode_object(importer), | ||
joiner: PruneJoiner.object, | ||
unionizer: decode_union_object(IsProgrammer.decode_object(importer))( | ||
decode_object(), | ||
decode_object(importer), | ||
)((exp) => exp)((value, expected) => | ||
@@ -296,0 +307,0 @@ create_throw_error(importer, value, expected), |
@@ -54,3 +54,3 @@ import ts from "typescript"; | ||
ts.factory.createTypeReferenceNode( | ||
"typia.IRandomGenerator", | ||
"Partial<typia.IRandomGenerator>", | ||
), | ||
@@ -68,4 +68,9 @@ IdentifierFactory.join( | ||
], | ||
ts.factory.createTypeReferenceNode( | ||
`typia.Primitive<${TypeFactory.getFullName( | ||
project.checker, | ||
type, | ||
)}>`, | ||
), | ||
undefined, | ||
undefined, | ||
ts.factory.createBlock( | ||
@@ -93,4 +98,4 @@ [ | ||
IdentifierFactory.parameter( | ||
"recursive", | ||
undefined, | ||
"_recursive", | ||
TypeFactory.keyword("boolean"), | ||
ts.factory.createIdentifier( | ||
@@ -101,10 +106,10 @@ String(obj.recursive), | ||
IdentifierFactory.parameter( | ||
"depth", | ||
undefined, | ||
"_depth", | ||
TypeFactory.keyword("number"), | ||
ts.factory.createNumericLiteral(0), | ||
), | ||
], | ||
TypeFactory.keyword("any"), | ||
undefined, | ||
undefined, | ||
RandomJoiner.object( | ||
RandomJoiner.object(COALESCE(importer))( | ||
decode(importer)({ | ||
@@ -147,9 +152,10 @@ recursive: obj.recursive, | ||
for (const atomic of meta.atomics) | ||
if (atomic === "boolean") expressions.push(decode_boolean()); | ||
if (atomic === "boolean") | ||
expressions.push(decode_boolean(importer)); | ||
else if (atomic === "number") | ||
expressions.push(decode_number(tags)); | ||
expressions.push(decode_number(importer)(tags)); | ||
else if (atomic === "string") | ||
expressions.push(decode_string(importer)(tags)); | ||
else if (atomic === "bigint") | ||
expressions.push(decode_bigint(tags)); | ||
expressions.push(decode_bigint(importer)(tags)); | ||
@@ -166,6 +172,5 @@ // INSTANCE TYPES | ||
for (const a of meta.arrays) { | ||
const array = RandomJoiner.array(decode(importer)(explore))( | ||
a, | ||
tags, | ||
); | ||
const array = RandomJoiner.array(COALESCE(importer))( | ||
decode(importer)(explore), | ||
)(a, tags); | ||
expressions.push( | ||
@@ -175,6 +180,6 @@ explore.recursive && a.objects.length | ||
ts.factory.createLogicalAnd( | ||
ts.factory.createIdentifier("recursive"), | ||
ts.factory.createIdentifier("_recursive"), | ||
ts.factory.createLessThan( | ||
ts.factory.createNumericLiteral(5), | ||
ts.factory.createIdentifier("depth"), | ||
ts.factory.createIdentifier("_depth"), | ||
), | ||
@@ -200,13 +205,13 @@ ), | ||
: ts.factory.createIdentifier( | ||
"recursive", | ||
"_recursive", | ||
), | ||
ts.factory.createConditionalExpression( | ||
ts.factory.createIdentifier("recursive"), | ||
ts.factory.createIdentifier("_recursive"), | ||
undefined, | ||
ts.factory.createAdd( | ||
ts.factory.createNumericLiteral(1), | ||
ts.factory.createIdentifier("depth"), | ||
ts.factory.createIdentifier("_depth"), | ||
), | ||
undefined, | ||
ts.factory.createIdentifier("depth"), | ||
ts.factory.createIdentifier("_depth"), | ||
), | ||
@@ -218,5 +223,6 @@ ] | ||
for (const native of meta.natives) | ||
if (native === "Boolean") expressions.push(decode_boolean()); | ||
if (native === "Boolean") | ||
expressions.push(decode_boolean(importer)); | ||
else if (native === "Number") | ||
expressions.push(decode_number(tags)); | ||
expressions.push(decode_number(importer)(tags)); | ||
else if (native === "String") | ||
@@ -255,10 +261,7 @@ expressions.push(decode_string(importer)(tags)); | ||
const decode_boolean = () => | ||
ts.factory.createLessThan( | ||
ts.factory.createNumericLiteral(0.5), | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("Math.random"), | ||
undefined, | ||
undefined, | ||
), | ||
const decode_boolean = (importer: FunctionImporter) => | ||
ts.factory.createCallExpression( | ||
COALESCE(importer)("boolean"), | ||
undefined, | ||
undefined, | ||
); | ||
@@ -283,14 +286,17 @@ | ||
const decode_number = (tags: IMetadataTag[]): ts.Expression => { | ||
const type = tags.find((t) => t.kind === "type" && t.value === "uint") | ||
? "int" | ||
: tags.find((t) => t.kind === "type" && t.value === "int") | ||
? "uint" | ||
: "double"; | ||
return RandomRanger.number({ | ||
type, | ||
transform: (value) => ts.factory.createNumericLiteral(value), | ||
setter: (args) => | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier( | ||
const decode_number = | ||
(importer: FunctionImporter) => | ||
(tags: IMetadataTag[]): ts.Expression => { | ||
const type = tags.find( | ||
(t) => t.kind === "type" && t.value === "uint", | ||
) | ||
? "int" | ||
: tags.find((t) => t.kind === "type" && t.value === "int") | ||
? "uint" | ||
: "double"; | ||
return RandomRanger.number({ | ||
type, | ||
transform: (value) => ts.factory.createNumericLiteral(value), | ||
setter: (args) => | ||
ts.factory.createCallExpression( | ||
type === "double" && | ||
@@ -302,43 +308,48 @@ tags.every( | ||
) | ||
? "generator.number" | ||
: "generator.integer", | ||
? COALESCE(importer)("number") | ||
: COALESCE(importer)("integer"), | ||
undefined, | ||
args.map((val) => ts.factory.createNumericLiteral(val)), | ||
), | ||
undefined, | ||
args.map((val) => ts.factory.createNumericLiteral(val)), | ||
), | ||
})({ | ||
minimum: 0, | ||
maximum: 100, | ||
gap: 10, | ||
})(tags); | ||
}; | ||
})({ | ||
minimum: 0, | ||
maximum: 100, | ||
gap: 10, | ||
})(tags); | ||
}; | ||
const decode_bigint = (tags: IMetadataTag[]): ts.Expression => | ||
RandomRanger.number({ | ||
type: tags.find((t) => t.kind === "type" && t.value === "uint") | ||
? "uint" | ||
: "int", | ||
transform: (value) => | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("BigInt"), | ||
undefined, | ||
[ts.factory.createStringLiteral(value.toString())], | ||
), | ||
setter: (args) => | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("generator.bigint"), | ||
undefined, | ||
args.map((value) => | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("BigInt"), | ||
undefined, | ||
[ts.factory.createStringLiteral(value.toString())], | ||
const decode_bigint = | ||
(importer: FunctionImporter) => | ||
(tags: IMetadataTag[]): ts.Expression => | ||
RandomRanger.number({ | ||
type: tags.find((t) => t.kind === "type" && t.value === "uint") | ||
? "uint" | ||
: "int", | ||
transform: (value) => | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("BigInt"), | ||
undefined, | ||
[ts.factory.createStringLiteral(value.toString())], | ||
), | ||
setter: (args) => | ||
ts.factory.createCallExpression( | ||
COALESCE(importer)("bigint"), | ||
undefined, | ||
args.map((value) => | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("BigInt"), | ||
undefined, | ||
[ | ||
ts.factory.createStringLiteral( | ||
value.toString(), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
})({ | ||
minimum: 0, | ||
maximum: 100, | ||
gap: 10, | ||
})(tags); | ||
})({ | ||
minimum: 0, | ||
maximum: 100, | ||
gap: 10, | ||
})(tags); | ||
@@ -365,3 +376,3 @@ const decode_string = | ||
const tail = RandomRanger.length({ | ||
const tail = RandomRanger.length(COALESCE(importer))({ | ||
minimum: 5, | ||
@@ -376,3 +387,3 @@ maximum: 25, | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier("generator.string"), | ||
COALESCE(importer)("string"), | ||
undefined, | ||
@@ -379,0 +390,0 @@ tail ? [tail] : undefined, |
@@ -58,4 +58,8 @@ import ts from "typescript"; | ||
...importer.declare(modulo), | ||
...isFunctors, | ||
...isUnioners, | ||
...isFunctors.filter((_, i) => | ||
importer.hasLocal(`$io${i}`), | ||
), | ||
...isUnioners.filter((_, i) => | ||
importer.hasLocal(`$iu${i}`), | ||
), | ||
]; | ||
@@ -385,3 +389,3 @@ }, | ||
})() | ||
: explore_objects(input, meta, { | ||
: explore_objects(importer)(input, meta, { | ||
...explore, | ||
@@ -436,3 +440,3 @@ from: "object", | ||
const decode_object = () => | ||
const decode_object = (importer: FunctionImporter) => | ||
FeatureProgrammer.decode_object({ | ||
@@ -442,3 +446,3 @@ trace: false, | ||
functors: FUNCTORS, | ||
}); | ||
})(importer); | ||
@@ -598,16 +602,22 @@ const decode_tuple = | ||
const explore_objects = ( | ||
input: ts.Expression, | ||
meta: Metadata, | ||
explore: FeatureProgrammer.IExplore, | ||
) => { | ||
if (meta.objects.length === 1) | ||
return decode_object()(input, meta.objects[0]!, explore); | ||
const explore_objects = | ||
(importer: FunctionImporter) => | ||
( | ||
input: ts.Expression, | ||
meta: Metadata, | ||
explore: FeatureProgrammer.IExplore, | ||
) => { | ||
if (meta.objects.length === 1) | ||
return decode_object(importer)( | ||
input, | ||
meta.objects[0]!, | ||
explore, | ||
); | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier(`${UNIONERS}${meta.union_index!}`), | ||
undefined, | ||
[input], | ||
); | ||
}; | ||
return ts.factory.createCallExpression( | ||
ts.factory.createIdentifier(`${UNIONERS}${meta.union_index!}`), | ||
undefined, | ||
[input], | ||
); | ||
}; | ||
@@ -707,4 +717,5 @@ /* ----------------------------------------------------------- | ||
input: (type) => | ||
project.checker.typeToTypeNode(type, undefined, undefined) ?? | ||
TypeFactory.keyword("any"), | ||
ts.factory.createTypeReferenceNode( | ||
TypeFactory.getFullName(project.checker, type), | ||
), | ||
output: () => TypeFactory.keyword("string"), | ||
@@ -747,6 +758,6 @@ }, | ||
checker: IsProgrammer.decode(project, importer), | ||
decoder: decode_object(), | ||
decoder: decode_object(importer), | ||
joiner: StringifyJoiner.object(importer), | ||
unionizer: decode_union_object(IsProgrammer.decode_object(importer))( | ||
decode_object(), | ||
decode_object(importer), | ||
)((exp) => exp)((value, expected) => | ||
@@ -753,0 +764,0 @@ create_throw_error(importer, value, expected), |
@@ -25,11 +25,8 @@ import ts from "typescript"; | ||
], | ||
ts.factory.createTypeReferenceNode("typia.IValidation", [ | ||
ts.factory.createTypeReferenceNode("typia.Primitive", [ | ||
project.checker.typeToTypeNode( | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
]), | ||
]), | ||
ts.factory.createTypeReferenceNode( | ||
`typia.IValidation<typia.Primitive<${TypeFactory.getFullName( | ||
project.checker, | ||
type, | ||
)}>>`, | ||
), | ||
undefined, | ||
@@ -36,0 +33,0 @@ ts.factory.createBlock([ |
@@ -24,11 +24,8 @@ import ts from "typescript"; | ||
], | ||
ts.factory.createTypeReferenceNode("typia.IValidation", [ | ||
ts.factory.createTypeReferenceNode("typia.Primitive", [ | ||
project.checker.typeToTypeNode( | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
]), | ||
]), | ||
ts.factory.createTypeReferenceNode( | ||
`typia.IValidation<typia.Primitive<${TypeFactory.getFullName( | ||
project.checker, | ||
type, | ||
)}>>`, | ||
), | ||
undefined, | ||
@@ -35,0 +32,0 @@ ts.factory.createBlock([ |
@@ -50,9 +50,8 @@ import ts from "typescript"; | ||
], | ||
ts.factory.createTypeReferenceNode("typia.IValidation", [ | ||
project.checker.typeToTypeNode( | ||
ts.factory.createTypeReferenceNode( | ||
`typia.IValidation<${TypeFactory.getFullName( | ||
project.checker, | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
]), | ||
)}>`, | ||
), | ||
undefined, | ||
@@ -108,12 +107,3 @@ ts.factory.createBlock( | ||
create_output(), | ||
ts.factory.createTypeReferenceNode( | ||
"typia.IValidation", | ||
[ | ||
project.checker.typeToTypeNode( | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
], | ||
), | ||
TypeFactory.keyword("any"), | ||
), | ||
@@ -139,4 +129,4 @@ ), | ||
const path: string = explore.postfix | ||
? `path + ${explore.postfix}` | ||
: "path"; | ||
? `_path + ${explore.postfix}` | ||
: "_path"; | ||
return (logic) => (input, binaries, expected) => | ||
@@ -154,3 +144,3 @@ logic === "and" | ||
: ts.factory.createIdentifier( | ||
"exceptionable", | ||
"_exceptionable", | ||
), | ||
@@ -172,3 +162,3 @@ )( | ||
? ts.factory.createTrue() | ||
: ts.factory.createIdentifier("exceptionable"), | ||
: ts.factory.createIdentifier("_exceptionable"), | ||
)(ts.factory.createIdentifier(path), expected, input), | ||
@@ -188,3 +178,3 @@ ); | ||
ts.factory.createAdd( | ||
ts.factory.createIdentifier("path"), | ||
ts.factory.createIdentifier("_path"), | ||
ts.factory.createCallExpression( | ||
@@ -203,3 +193,3 @@ importer.use("join"), | ||
ts.factory.createFalse(), | ||
ts.factory.createIdentifier("exceptionable"), | ||
ts.factory.createIdentifier("_exceptionable"), | ||
), | ||
@@ -226,6 +216,6 @@ expr, | ||
? ts.factory.createTrue() | ||
: ts.factory.createIdentifier("exceptionable"), | ||
: ts.factory.createIdentifier("_exceptionable"), | ||
)( | ||
ts.factory.createIdentifier( | ||
explore?.postfix ? `path + ${explore.postfix}` : "path", | ||
explore?.postfix ? `_path + ${explore.postfix}` : "_path", | ||
), | ||
@@ -272,3 +262,3 @@ expected, | ||
[ | ||
exceptionable || ts.factory.createIdentifier("exceptionable"), | ||
exceptionable ?? ts.factory.createIdentifier("_exceptionable"), | ||
ts.factory.createObjectLiteralExpression( | ||
@@ -275,0 +265,0 @@ [ |
@@ -25,9 +25,8 @@ import ts from "typescript"; | ||
], | ||
ts.factory.createTypeReferenceNode("typia.IValidation", [ | ||
project.checker.typeToTypeNode( | ||
ts.factory.createTypeReferenceNode( | ||
`typia.IValidation<${TypeFactory.getFullName( | ||
project.checker, | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
]), | ||
)}>`, | ||
), | ||
undefined, | ||
@@ -34,0 +33,0 @@ ts.factory.createBlock([ |
@@ -22,12 +22,8 @@ import ts from "typescript"; | ||
"input", | ||
project.checker.typeToTypeNode( | ||
type, | ||
undefined, | ||
undefined, | ||
) ?? TypeFactory.keyword("any"), | ||
ts.factory.createTypeReferenceNode( | ||
TypeFactory.getFullName(project.checker, type), | ||
), | ||
), | ||
], | ||
ts.factory.createTypeReferenceNode("typia.IValidation", [ | ||
TypeFactory.keyword("string"), | ||
]), | ||
ts.factory.createTypeReferenceNode("typia.IValidation<string>"), | ||
undefined, | ||
@@ -34,0 +30,0 @@ ts.factory.createBlock([ |
@@ -0,0 +0,0 @@ import { IJsonComponents } from "./IJsonComponents"; |
@@ -0,0 +0,0 @@ import { IJsDocTagInfo } from "../metadata/IJsDocTagInfo"; |
@@ -0,0 +0,0 @@ import { IJsDocTagInfo } from "../metadata/IJsDocTagInfo"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import path from "path"; |
@@ -0,0 +0,0 @@ // import path from "path"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ export interface ITransformOptions { |
@@ -0,0 +0,0 @@ import ts from "typescript"; |
@@ -0,0 +0,0 @@ export class TypeGuardError extends Error { |
@@ -0,0 +0,0 @@ export namespace Atomic { |
@@ -0,0 +0,0 @@ import { OmitNever } from "./OmitNever"; |
import { SpecialFields } from "./SpecialFields"; | ||
export type OmitNever<T extends object> = Omit<T, SpecialFields<T, never>>; |
export type SpecialFields<Instance extends object, Target> = { | ||
[P in keyof Instance]: Instance[P] extends Target ? P : never; | ||
}[keyof Instance & string]; |
@@ -0,0 +0,0 @@ import { ClassProperties } from "./ClassProperties"; |
@@ -0,0 +0,0 @@ export namespace ArrayUtil { |
@@ -0,0 +0,0 @@ export namespace Escaper { |
@@ -0,0 +0,0 @@ export namespace MapUtil { |
@@ -0,0 +0,0 @@ export namespace PatternUtil { |
@@ -0,0 +0,0 @@ import RandExp from "randexp"; |
@@ -0,0 +0,0 @@ export class Singleton<T, Args extends any[] = []> { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
1696237
799
30126
317
7