Skip to content

Commit

Permalink
Merge pull request #765 from samchon/features/encode
Browse files Browse the repository at this point in the history
Features/encode
  • Loading branch information
samchon authored Aug 18, 2023
2 parents 7a99d20 + 4567ab3 commit 8a56c6f
Show file tree
Hide file tree
Showing 1,488 changed files with 91,866 additions and 15,253 deletions.
45 changes: 45 additions & 0 deletions build/internal/TestFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,51 @@ export namespace TestFeature {
},
},

//----
// PROTOBUF FUNCTIONS
//----
// ENCODERS
{
module: "protobuf",
method: "encode",
creatable: true,
spoilable: false,
opposite: {
name: "message",
method: "typia.protobuf.message",
},
},
{
module: "protobuf",
method: "isEncode",
creatable: true,
spoilable: true,
opposite: {
name: "message",
method: "typia.protobuf.message",
},
},
{
module: "protobuf",
method: "assertEncode",
creatable: true,
spoilable: true,
opposite: {
name: "message",
method: "typia.protobuf.message",
},
},
{
module: "protobuf",
method: "validateEncode",
creatable: true,
spoilable: true,
opposite: {
name: "message",
method: "typia.protobuf.message",
},
},

//----
// JSON FUNCTIONS
//----
Expand Down
1 change: 1 addition & 0 deletions build/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async function generate(
else if (feat.primitive && s.PRIMITIVE === false) continue;
else if (feat.strict && s.ADDABLE === false) continue;
else if (feat.method === "random" && s.RANDOM === false) continue;
else if (feat.module === "protobuf" && s.BINARABLE === false) continue;
else if (
feat.method.toLowerCase().includes("prune") &&
s.ADDABLE === false
Expand Down
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": "5.0.0-dev.20230811",
"version": "5.0.0-dev.20230819",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "5.0.0-dev.20230811",
"version": "5.0.0-dev.20230819",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -68,7 +68,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "5.0.0-dev.20230811"
"typia": "5.0.0-dev.20230819"
},
"peerDependencies": {
"typescript": ">= 4.7.4"
Expand Down
38 changes: 38 additions & 0 deletions src/factories/ExpressionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,42 @@ export namespace ExpressionFactory {
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
y,
);

export const currying =
(target: ts.Expression) => (parameters: ts.Expression[]) => {
if (parameters.length === 0)
return ts.factory.createCallExpression(
target,
undefined,
undefined,
);
let prev: ts.CallExpression = ts.factory.createCallExpression(
target,
undefined,
[parameters[0]!],
);
for (const param of parameters.slice(1))
prev = ts.factory.createCallExpression(prev, undefined, [
param,
]);
return prev;
};

export const selfCall = (body: ts.ConciseBody) =>
ts.isCallExpression(body)
? body
: ts.factory.createCallExpression(
ts.factory.createParenthesizedExpression(
ts.factory.createArrowFunction(
undefined,
undefined,
[],
undefined,
undefined,
body,
),
),
undefined,
undefined,
);
}
5 changes: 5 additions & 0 deletions src/factories/MetadataCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export class MetadataCollection {
private recursive_array_index_: number;
private recursive_tuple_index_: number;

/**
* @internal
*/
public readonly entire_: Set<Metadata> = new Set();

public constructor(
private readonly options?: Partial<MetadataCollection.IOptions>,
) {
Expand Down
4 changes: 4 additions & 0 deletions src/factories/MetadataFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export namespace MetadataFactory {
)(type, false);
iterate_metadata_collection(collection);
iterate_metadata_sort(collection)(meta);

if (options.validate)
for (const elem of collection.entire_) options.validate(elem);
collection.entire_.clear();
return meta;
};
}
Loading

0 comments on commit 8a56c6f

Please sign in to comment.