typia 3.5.0-dev.20230211 → 3.5.0-dev.20230213

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +7 -0
  2. package/lib/module.d.ts +197 -4
  3. package/lib/module.js +74 -2
  4. package/lib/module.js.map +1 -1
  5. package/lib/programmers/AssertPruneProgrammer.d.ts +5 -0
  6. package/lib/programmers/AssertPruneProgrammer.js +37 -0
  7. package/lib/programmers/AssertPruneProgrammer.js.map +1 -0
  8. package/lib/programmers/CloneProgrammer.d.ts +5 -0
  9. package/lib/programmers/CloneProgrammer.js +287 -0
  10. package/lib/programmers/CloneProgrammer.js.map +1 -0
  11. package/lib/programmers/IsPruneProgrammer.d.ts +5 -0
  12. package/lib/programmers/IsPruneProgrammer.js +37 -0
  13. package/lib/programmers/IsPruneProgrammer.js.map +1 -0
  14. package/lib/programmers/PruneProgrammer.js +2 -2
  15. package/lib/programmers/PruneProgrammer.js.map +1 -1
  16. package/lib/programmers/ValidatePruneProgrammer.d.ts +5 -0
  17. package/lib/programmers/ValidatePruneProgrammer.js +37 -0
  18. package/lib/programmers/ValidatePruneProgrammer.js.map +1 -0
  19. package/lib/programmers/helpers/CloneJoiner.d.ts +8 -0
  20. package/lib/programmers/helpers/CloneJoiner.js +80 -0
  21. package/lib/programmers/helpers/CloneJoiner.js.map +1 -0
  22. package/lib/programmers/internal/feature_object_entries.d.ts +1 -1
  23. package/lib/transformers/CallExpressionTransformer.js +17 -1
  24. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  25. package/lib/transformers/features/miscellaneous/AssertPruneTransformer.d.ts +5 -0
  26. package/lib/transformers/features/miscellaneous/AssertPruneTransformer.js +23 -0
  27. package/lib/transformers/features/miscellaneous/AssertPruneTransformer.js.map +1 -0
  28. package/lib/transformers/features/miscellaneous/CloneTransformer.d.ts +5 -0
  29. package/lib/transformers/features/miscellaneous/CloneTransformer.js +34 -0
  30. package/lib/transformers/features/miscellaneous/CloneTransformer.js.map +1 -0
  31. package/lib/transformers/features/miscellaneous/CreateAssertPruneTransformer.d.ts +5 -0
  32. package/lib/transformers/features/miscellaneous/CreateAssertPruneTransformer.js +17 -0
  33. package/lib/transformers/features/miscellaneous/CreateAssertPruneTransformer.js.map +1 -0
  34. package/lib/transformers/features/miscellaneous/CreateCloneTransformer.d.ts +5 -0
  35. package/lib/transformers/features/miscellaneous/CreateCloneTransformer.js +17 -0
  36. package/lib/transformers/features/miscellaneous/CreateCloneTransformer.js.map +1 -0
  37. package/lib/transformers/features/miscellaneous/CreateIsPruneTransformer.d.ts +5 -0
  38. package/lib/transformers/features/miscellaneous/CreateIsPruneTransformer.js +17 -0
  39. package/lib/transformers/features/miscellaneous/CreateIsPruneTransformer.js.map +1 -0
  40. package/lib/transformers/features/miscellaneous/CreateValidatePruneTransformer.d.ts +5 -0
  41. package/lib/transformers/features/miscellaneous/CreateValidatePruneTransformer.js +17 -0
  42. package/lib/transformers/features/miscellaneous/CreateValidatePruneTransformer.js.map +1 -0
  43. package/lib/transformers/features/miscellaneous/IsPruneTransformer.d.ts +5 -0
  44. package/lib/transformers/features/miscellaneous/IsPruneTransformer.js +23 -0
  45. package/lib/transformers/features/miscellaneous/IsPruneTransformer.js.map +1 -0
  46. package/lib/transformers/features/miscellaneous/ValidatePruneTransformer.d.ts +5 -0
  47. package/lib/transformers/features/miscellaneous/ValidatePruneTransformer.js +23 -0
  48. package/lib/transformers/features/miscellaneous/ValidatePruneTransformer.js.map +1 -0
  49. package/package.json +1 -1
  50. package/src/module.ts +311 -5
  51. package/src/programmers/AssertPruneProgrammer.ts +59 -0
  52. package/src/programmers/CloneProgrammer.ts +357 -0
  53. package/src/programmers/IsPruneProgrammer.ts +63 -0
  54. package/src/programmers/PruneProgrammer.ts +5 -2
  55. package/src/programmers/ValidatePruneProgrammer.ts +73 -0
  56. package/src/programmers/helpers/CloneJoiner.ts +126 -0
  57. package/src/transformers/CallExpressionTransformer.ts +17 -1
  58. package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +38 -0
  59. package/src/transformers/features/miscellaneous/CloneTransformer.ts +46 -0
  60. package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +32 -0
  61. package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +31 -0
  62. package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +32 -0
  63. package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +32 -0
  64. package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +38 -0
  65. package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +38 -0
package/src/module.ts CHANGED
@@ -829,8 +829,8 @@ Object.assign(validateParse, validate);
829
829
  * than the native `JSON.stringify()` function. The 5x faster principle is because
830
830
  * it writes an optimized JSON conversion plan, only for the type `T`.
831
831
  *
832
- * For reference, this `typia.stringify()` does not validate the input value type. It
833
- * just believes that the input value is following the type `T`. Therefore, if you
832
+ * For reference, this `typia.stringify()` does not validate the input value type.
833
+ * It just believes that the input value is following the type `T`. Therefore, if you
834
834
  * can't ensure the input value type, it would be better to call one of below functions
835
835
  * instead.
836
836
  *
@@ -990,7 +990,7 @@ export function isStringify<T>(input: T): string | null;
990
990
  * `typia.isStringify()` is a combination function of {@link is} and
991
991
  * {@link stringify}. Therefore, it converts an input value to JSON
992
992
  * (JavaScript Object Notation) string, with type checking.
993
- *
993
+ *f
994
994
  * In such reason, when `input` value is not matched with the type `T`, it returns
995
995
  * `null` value. Otherwise, there's no problem on the `input` value, JSON string would
996
996
  * be returned.
@@ -1105,6 +1105,28 @@ export function metadata(): never {
1105
1105
  halt("metadata");
1106
1106
  }
1107
1107
 
1108
+ export function clone<T>(input: T): T;
1109
+ export function clone(): never {
1110
+ halt("clone");
1111
+ }
1112
+ export namespace clone {
1113
+ export const is_uuid = $is_uuid;
1114
+ export const is_email = $is_email;
1115
+ export const is_url = $is_url;
1116
+ export const is_ipv4 = $is_ipv4;
1117
+ export const is_ipv6 = $is_ipv6;
1118
+ export const is_between = $is_between;
1119
+
1120
+ export function throws(
1121
+ props: Pick<TypeGuardError.IProps, "expected" | "value">,
1122
+ ): void {
1123
+ throw new TypeGuardError({
1124
+ ...props,
1125
+ method: "typia.clone",
1126
+ });
1127
+ }
1128
+ }
1129
+
1108
1130
  /**
1109
1131
  * Prune, erase superfluous properties.
1110
1132
  *
@@ -1112,8 +1134,17 @@ export function metadata(): never {
1112
1134
  * objects. Note that, as every superfluous properties would be deleted, you never can
1113
1135
  * read those superfluous properties after calling this `prune()` function.
1114
1136
  *
1137
+ * For reference, this `typia.prune()` function does not validate the input value type.
1138
+ * It just believes that the input value is following the type `T`. Therefore, if you
1139
+ * can't ensure the input value type, it would better to call one of below functions
1140
+ * instead.
1141
+ *
1142
+ * - {@link assertPrune}
1143
+ * - {@link isPrune}
1144
+ * - {@link validatePrune}
1145
+ *
1115
1146
  * @template T Type of the input value
1116
- * @param input target instance to prune
1147
+ * @param input Target instance to prune
1117
1148
  *
1118
1149
  * @author Jeongho Nam - https://github.com/samchon
1119
1150
  */
@@ -1137,7 +1168,6 @@ export namespace prune {
1137
1168
  export const is_ipv6 = $is_ipv6;
1138
1169
  export const is_between = $is_between;
1139
1170
 
1140
- export const rest = $rest;
1141
1171
  export function throws(
1142
1172
  props: Pick<TypeGuardError.IProps, "expected" | "value">,
1143
1173
  ): void {
@@ -1148,6 +1178,180 @@ export namespace prune {
1148
1178
  }
1149
1179
  }
1150
1180
 
1181
+ /**
1182
+ * Prune, erase superfluous properties, with type assertion.
1183
+ *
1184
+ * `typia.assertPrune()` is a combination function of {@link assert} and {@link prune}.
1185
+ * Therefore, it removes every superfluous properties from the `input` object including
1186
+ * nested objects, with type assertion.
1187
+ *
1188
+ * In such reason, when `input` value is not matched with the type `T`, it throws an
1189
+ * {@link TypeGuardError}. Otherwise, there's no problem on the `input` value, its
1190
+ * every superfluous properties would be removed, including nested objects.
1191
+ *
1192
+ * @template T Type of the input value
1193
+ * @param input Target instance to assert and prune
1194
+ *
1195
+ * @author Jeongho Nam - https://github.com/samchon
1196
+ */
1197
+ export function assertPrune<T>(input: T): T;
1198
+
1199
+ /**
1200
+ * Prune, erase superfluous properties, with type assertion.
1201
+ *
1202
+ * `typia.assertPrune()` is a combination function of {@link assert} and {@link prune}.
1203
+ * Therefore, it removes every superfluous properties from the `input` object including
1204
+ * nested objects, with type assertion.
1205
+ *
1206
+ * In such reason, when `input` value is not matched with the type `T`, it throws an
1207
+ * {@link TypeGuardError}. Otherwise, there's no problem on the `input` value, its
1208
+ * every superfluous properties would be removed, including nested objects.
1209
+ *
1210
+ * @template T Type of the input value
1211
+ * @param input Target instance to assert and prune
1212
+ *
1213
+ * @author Jeongho Nam - https://github.com/samchon
1214
+ */
1215
+ export function assertPrune<T>(input: unknown): T;
1216
+
1217
+ /**
1218
+ * @internal
1219
+ */
1220
+ export function assertPrune<T>(): unknown {
1221
+ halt("assertPrune");
1222
+ }
1223
+
1224
+ /**
1225
+ * @internal
1226
+ */
1227
+ export namespace assertPrune {
1228
+ export const is_uuid = $is_uuid;
1229
+ export const is_email = $is_email;
1230
+ export const is_url = $is_url;
1231
+ export const is_ipv4 = $is_ipv4;
1232
+ export const is_ipv6 = $is_ipv6;
1233
+ export const is_between = $is_between;
1234
+
1235
+ export const join = $join;
1236
+ export const every = $every;
1237
+ export const guard = $guard("typia.assertPrune");
1238
+ }
1239
+
1240
+ /**
1241
+ * Prune, erase superfluous properties, with type checking.
1242
+ *
1243
+ * `typia.assertPrune()` is a combination function of {@link is} and {@link prune}.
1244
+ * Therefore, it removes every superfluous properties from the `input` object including
1245
+ * nested objects, with type checking.
1246
+ *
1247
+ * In such reason, when `input` value is not matched with the type `T`, it returns
1248
+ * `false` value. Otherwise, there's no problem on the `input` value, it returns
1249
+ * `true` after removing every superfluous properties, including nested objects.
1250
+ *
1251
+ * @template T Type of the input value
1252
+ * @param input Target instance to check and prune
1253
+ * @returns Whether the parametric value is following the type `T` or not
1254
+ *
1255
+ * @author Jeongho Nam - https://github.com/samchon
1256
+ */
1257
+ export function isPrune<T>(input: T): input is T;
1258
+
1259
+ /**
1260
+ * Prune, erase superfluous properties, with type checking.
1261
+ *
1262
+ * `typia.assertPrune()` is a combination function of {@link is} and {@link prune}.
1263
+ * Therefore, it removes every superfluous properties from the `input` object including
1264
+ * nested objects, with type checking.
1265
+ *
1266
+ * In such reason, when `input` value is not matched with the type `T`, it returns
1267
+ * `false` value. Otherwise, there's no problem on the `input` value, it returns
1268
+ * `true` after removing every superfluous properties, including nested objects.
1269
+ *
1270
+ * @template T Type of the input value
1271
+ * @param input Target instance to check and prune
1272
+ * @returns Whether the parametric value is following the type `T` or not
1273
+ *
1274
+ * @author Jeongho Nam - https://github.com/samchon
1275
+ */
1276
+ export function isPrune<T>(input: unknown): input is T;
1277
+
1278
+ /**
1279
+ * @internal
1280
+ */
1281
+ export function isPrune(): never {
1282
+ halt("isPrune");
1283
+ }
1284
+
1285
+ /**
1286
+ * @internal
1287
+ */
1288
+ export namespace isPrune {
1289
+ export const is_uuid = $is_uuid;
1290
+ export const is_email = $is_email;
1291
+ export const is_url = $is_url;
1292
+ export const is_ipv4 = $is_ipv4;
1293
+ export const is_ipv6 = $is_ipv6;
1294
+ export const is_between = $is_between;
1295
+
1296
+ export function throws(
1297
+ props: Pick<TypeGuardError.IProps, "expected" | "value">,
1298
+ ): void {
1299
+ throw new TypeGuardError({
1300
+ ...props,
1301
+ method: "typia.prune",
1302
+ });
1303
+ }
1304
+ }
1305
+
1306
+ /**
1307
+ * Prune, erase superfluous properties, with type validation.
1308
+ *
1309
+ * `typia.validatePrune()` is a combination function of {@link validate} and {@link prune}.
1310
+ * Therefore, it removes every superfluous properties from the `input` object including
1311
+ * nested objects, with type validation.
1312
+ *
1313
+ * In such reason, when `input` value is not matched with the type `T`, it returns
1314
+ * {@link IValidation.IFailure} value with detailed error reasons. Otherwise, there's
1315
+ * no problem on the `input` value, it returns {@link IValidation.ISucess} value after
1316
+ * removing every superfluous properties, including nested objects.
1317
+ *
1318
+ * @template T Type of the input value
1319
+ * @param input Target instance to validate and prune
1320
+ * @returns Validation result
1321
+ *
1322
+ * @author Jeongho Nam - https://github.com/samchon
1323
+ */
1324
+ export function validatePrune<T>(input: T): IValidation<T>;
1325
+
1326
+ /**
1327
+ * Prune, erase superfluous properties, with type validation.
1328
+ *
1329
+ * `typia.validatePrune()` is a combination function of {@link validate} and {@link prune}.
1330
+ * Therefore, it removes every superfluous properties from the `input` object including
1331
+ * nested objects, with type validation.
1332
+ *
1333
+ * In such reason, when `input` value is not matched with the type `T`, it returns
1334
+ * {@link IValidation.IFailure} value with detailed error reasons. Otherwise, there's
1335
+ * no problem on the `input` value, it returns {@link IValidation.ISucess} value after
1336
+ * removing every superfluous properties, including nested objects.
1337
+ *
1338
+ * @template T Type of the input value
1339
+ * @param input Target instance to validate and prune
1340
+ * @returns Validation result
1341
+ *
1342
+ * @author Jeongho Nam - https://github.com/samchon
1343
+ */
1344
+ export function validatePrune<T>(input: unknown): IValidation<T>;
1345
+
1346
+ /**
1347
+ * @internal
1348
+ */
1349
+ export function validatePrune<T>(): IValidation<T> {
1350
+ halt("validatePrune");
1351
+ }
1352
+ Object.assign(validatePrune, prune);
1353
+ Object.assign(validatePrune, validate);
1354
+
1151
1355
  /* ===========================================================
1152
1356
  FACTORY FUNCTIONS
1153
1357
  - BASIC VALIDATORS
@@ -1582,6 +1786,17 @@ Object.assign(createValidateStringify, validateStringify);
1582
1786
  /* -----------------------------------------------------------
1583
1787
  MISCELLANEOUS
1584
1788
  ----------------------------------------------------------- */
1789
+ export function createClone(): never;
1790
+ export function createClone<T>(): (input: T) => T;
1791
+
1792
+ /**
1793
+ * @internal
1794
+ */
1795
+ export function createClone(): never {
1796
+ halt("createClone");
1797
+ }
1798
+ Object.assign(createClone, clone);
1799
+
1585
1800
  /**
1586
1801
  * Creates a reusable {@link prune} function.
1587
1802
  *
@@ -1611,6 +1826,97 @@ export function createPrune<T extends object>(): (input: T) => void {
1611
1826
  }
1612
1827
  Object.assign(createPrune, prune);
1613
1828
 
1829
+ /**
1830
+ * Creates a reusable {@link isPrune} function.
1831
+ *
1832
+ * @danger You have to specify the generic argument `T`
1833
+ * @return Nothing until specifying the generic argument `T`
1834
+ * @throws compile error
1835
+ *
1836
+ * @author Jeongho Nam - https://github.com/samchon
1837
+ */
1838
+ export function createAssertPrune(): never;
1839
+
1840
+ /**
1841
+ * Creates a resuable {@link isPrune} function.
1842
+ *
1843
+ * @template T Type of the input value
1844
+ * @returns A reusable `isPrune` function
1845
+ *
1846
+ * @author Jeongho Nam - https://github.com/samchon
1847
+ */
1848
+ export function createAssertPrune<T extends object>(): (input: T) => T;
1849
+
1850
+ /**
1851
+ * @internal
1852
+ */
1853
+ export function createAssertPrune<T extends object>(): (input: T) => T {
1854
+ halt("createAssertPrune");
1855
+ }
1856
+ Object.assign(createAssertPrune, assertPrune);
1857
+
1858
+ /**
1859
+ * Creates a reusable {@link isPrune} function.
1860
+ *
1861
+ * @danger You have to specify the generic argument `T`
1862
+ * @return Nothing until specifying the generic argument `T`
1863
+ * @throws compile error
1864
+ *
1865
+ * @author Jeongho Nam - https://github.com/samchon
1866
+ */
1867
+ export function createIsPrune(): never;
1868
+
1869
+ /**
1870
+ * Creates a resuable {@link isPrune} function.
1871
+ *
1872
+ * @template T Type of the input value
1873
+ * @returns A reusable `isPrune` function
1874
+ *
1875
+ * @author Jeongho Nam - https://github.com/samchon
1876
+ */
1877
+ export function createIsPrune<T extends object>(): (input: T) => input is T;
1878
+
1879
+ /**
1880
+ * @internal
1881
+ */
1882
+ export function createIsPrune<T extends object>(): (input: T) => input is T {
1883
+ halt("createIsPrune");
1884
+ }
1885
+ Object.assign(createIsPrune, isPrune);
1886
+
1887
+ /**
1888
+ * Creates a reusable {@link validatePrune} function.
1889
+ *
1890
+ * @danger You have to specify the generic argument `T`
1891
+ * @return Nothing until specifying the generic argument `T`
1892
+ * @throws compile error
1893
+ *
1894
+ * @author Jeongho Nam - https://github.com/samchon
1895
+ */
1896
+ export function createValidatePrune(): never;
1897
+
1898
+ /**
1899
+ * Creates a resuable {@link validatePrune} function.
1900
+ *
1901
+ * @template T Type of the input value
1902
+ * @returns A reusable `validatePrune` function
1903
+ *
1904
+ * @author Jeongho Nam - https://github.com/samchon
1905
+ */
1906
+ export function createValidatePrune<T extends object>(): (
1907
+ input: T,
1908
+ ) => IValidation<T>;
1909
+
1910
+ /**
1911
+ * @internal
1912
+ */
1913
+ export function createValidatePrune<T extends object>(): (
1914
+ input: T,
1915
+ ) => IValidation<T> {
1916
+ halt("createValidatePrune");
1917
+ }
1918
+ Object.assign(createValidatePrune, validatePrune);
1919
+
1614
1920
  /**
1615
1921
  * @internal
1616
1922
  */
@@ -0,0 +1,59 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../factories/StatementFactory";
5
+
6
+ import { IProject } from "../transformers/IProject";
7
+
8
+ import { AssertProgrammer } from "./AssertProgrammer";
9
+ import { PruneProgrammer } from "./PruneProgrammer";
10
+
11
+ export namespace AssertPruneProgrammer {
12
+ export const generate =
13
+ (project: IProject, modulo: ts.LeftHandSideExpression) =>
14
+ (type: ts.Type) =>
15
+ ts.factory.createArrowFunction(
16
+ undefined,
17
+ undefined,
18
+ [IdentifierFactory.parameter("input")],
19
+ undefined,
20
+ undefined,
21
+ ts.factory.createBlock([
22
+ StatementFactory.constant(
23
+ "assert",
24
+ AssertProgrammer.generate(project, modulo)(type),
25
+ ),
26
+ StatementFactory.constant(
27
+ "prune",
28
+ PruneProgrammer.generate(
29
+ {
30
+ ...project,
31
+ options: {
32
+ ...project.options,
33
+ functional: false,
34
+ numeric: false,
35
+ },
36
+ },
37
+ modulo,
38
+ )(type),
39
+ ),
40
+ ts.factory.createExpressionStatement(
41
+ ts.factory.createCallExpression(
42
+ ts.factory.createIdentifier("assert"),
43
+ undefined,
44
+ [ts.factory.createIdentifier("input")],
45
+ ),
46
+ ),
47
+ ts.factory.createExpressionStatement(
48
+ ts.factory.createCallExpression(
49
+ ts.factory.createIdentifier("prune"),
50
+ undefined,
51
+ [ts.factory.createIdentifier("input")],
52
+ ),
53
+ ),
54
+ ts.factory.createReturnStatement(
55
+ ts.factory.createIdentifier("input"),
56
+ ),
57
+ ]),
58
+ );
59
+ }