Skip to content

Commit

Permalink
Only principle functions are completed, but errors are.
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Sep 16, 2024
1 parent 425d579 commit 69e6df4
Show file tree
Hide file tree
Showing 53 changed files with 1,547 additions and 1,303 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "6.10.0",
"version": "7.0.0-dev.20240916",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
5 changes: 4 additions & 1 deletion src/factories/internal/metadata/iterate_metadata_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export const iterate_metadata_function =
);
else {
const { async }: FunctionalGeneralProgrammer.IOutput =
FunctionalGeneralProgrammer.getReturnType(checker)(declaration);
FunctionalGeneralProgrammer.getReturnType({
checker,
declaration,
});
metadata.functions.push(
MetadataFunction.create({
parameters: signature.parameters.map((p) =>
Expand Down
166 changes: 91 additions & 75 deletions src/programmers/functional/FunctionalAssertFunctionProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,84 +13,100 @@ import { FunctionalAssertParametersProgrammer } from "./FunctionalAssertParamete
import { FunctionAssertReturnProgrammer } from "./FunctionalAssertReturnProgrammer";

export namespace FunctionalAssertFunctionProgrammer {
export const write =
(project: ITypiaContext) =>
(modulo: ts.LeftHandSideExpression) =>
(equals: boolean) =>
(
expression: ts.Expression,
declaration: ts.FunctionDeclaration,
init?: ts.Expression,
): ts.CallExpression => {
const wrapper = errorFactoryWrapper(modulo)(declaration.parameters)(init);
const p = FunctionalAssertParametersProgrammer.decompose(project)(modulo)(
equals,
)(declaration.parameters, wrapper.name);
const r = FunctionAssertReturnProgrammer.decompose(project)(modulo)(
equals,
)(expression, declaration, wrapper.name);
return ExpressionFactory.selfCall(
ts.factory.createBlock(
[
wrapper.variable,
...p.functions,
...r.functions,
ts.factory.createReturnStatement(
ts.factory.createArrowFunction(
r.async
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
: undefined,
undefined,
declaration.parameters,
declaration.type,
undefined,
ts.factory.createBlock([
...p.expressions.map(ts.factory.createExpressionStatement),
ts.factory.createReturnStatement(r.value),
]),
),
),
],
true,
),
);
};
export interface IConfig {
equals: boolean;
}
export interface IProps {
context: ITypiaContext;
modulo: ts.LeftHandSideExpression;
config: IConfig;
declaration: ts.FunctionDeclaration;
expression: ts.Expression;
init?: ts.Expression | undefined;
}

export const errorFactoryWrapper =
(modulo: ts.LeftHandSideExpression) =>
(paramters: readonly ts.ParameterDeclaration[]) =>
(
init: ts.Expression | undefined,
): {
name: string;
variable: ts.VariableStatement;
} => {
const name: string = StringUtil.escapeDuplicate(
paramters.map((p) => p.name.getText()),
)("errorFactoryWrapper");
const variable: ts.VariableStatement = ts.factory.createVariableStatement(
undefined,
ts.factory.createVariableDeclarationList(
[
ts.factory.createVariableDeclaration(
name,
export const write = (props: IProps): ts.CallExpression => {
const wrapper = errorFactoryWrapper({
modulo: props.modulo,
parameters: props.declaration.parameters,
init: props.init,
});
const p = FunctionalAssertParametersProgrammer.decompose({
context: props.context,
modulo: props.modulo,
config: props.config,
parameters: props.declaration.parameters,
wrapper: wrapper.name,
});
const r = FunctionAssertReturnProgrammer.decompose({
context: props.context,
modulo: props.modulo,
config: props.config,
expression: props.expression,
declaration: props.declaration,
wrapper: wrapper.name,
});
return ExpressionFactory.selfCall(
ts.factory.createBlock(
[
wrapper.variable,
...p.functions,
...r.functions,
ts.factory.createReturnStatement(
ts.factory.createArrowFunction(
r.async
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
: undefined,
undefined,
AssertProgrammer.Guardian.type(),
init ??
ts.factory.createPropertyAccessExpression(
ts.factory.createAsExpression(
modulo,
TypeFactory.keyword("any"),
),
"errorFactory",
),
props.declaration.parameters,
props.declaration.type,
undefined,
ts.factory.createBlock([
...p.expressions.map(ts.factory.createExpressionStatement),
ts.factory.createReturnStatement(r.value),
]),
),
],
ts.NodeFlags.Const,
),
);
return { name, variable };
};
),
],
true,
),
);
};

export const errorFactoryWrapper = (props: {
modulo: ts.LeftHandSideExpression;
parameters: readonly ts.ParameterDeclaration[];
init: ts.Expression | undefined;
}): {
name: string;
variable: ts.VariableStatement;
} => {
const name: string = StringUtil.escapeDuplicate(
props.parameters.map((p) => p.name.getText()),
)("errorFactoryWrapper");
const variable: ts.VariableStatement = ts.factory.createVariableStatement(
undefined,
ts.factory.createVariableDeclarationList(
[
ts.factory.createVariableDeclaration(
name,
undefined,
AssertProgrammer.Guardian.type(),
props.init ??
ts.factory.createPropertyAccessExpression(
ts.factory.createAsExpression(
props.modulo,
TypeFactory.keyword("any"),
),
"errorFactory",
),
),
],
ts.NodeFlags.Const,
),
);
return { name, variable };
};

export const hookPath = (props: {
wrapper: string;
Expand Down
Loading

0 comments on commit 69e6df4

Please sign in to comment.