typia 13.2.0 → 13.3.0
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.
- package/lib/http.d.ts +3 -3
- package/lib/http.js.map +1 -1
- package/lib/http.mjs.map +1 -1
- package/lib/internal/_assertGuard.js +13 -3
- package/lib/internal/_assertGuard.js.map +1 -1
- package/lib/internal/_assertGuard.mjs +4 -2
- package/lib/internal/_assertGuard.mjs.map +1 -1
- package/lib/internal/_isFormatIdnHostname.js +5 -1
- package/lib/internal/_isFormatIdnHostname.js.map +1 -1
- package/lib/internal/_isFormatIdnHostname.mjs +1 -1
- package/lib/internal/_isFormatIdnHostname.mjs.map +1 -1
- package/lib/internal/_isFormatTime.js +19 -2
- package/lib/internal/_isFormatTime.js.map +1 -1
- package/lib/internal/_isFormatTime.mjs +9 -2
- package/lib/internal/_isFormatTime.mjs.map +1 -1
- package/lib/internal/_randomArray.js +37 -4
- package/lib/internal/_randomArray.js.map +1 -1
- package/lib/internal/_randomArray.mjs +16 -3
- package/lib/internal/_randomArray.mjs.map +1 -1
- package/lib/internal/_randomFormatByte.js +15 -12
- package/lib/internal/_randomFormatByte.js.map +1 -1
- package/lib/internal/_randomFormatByte.mjs +11 -10
- package/lib/internal/_randomFormatByte.mjs.map +1 -1
- package/lib/internal/_randomFormatDatetime.mjs +1 -1
- package/lib/internal/_randomFormatHostname.d.ts +2 -2
- package/lib/internal/_randomFormatHostname.js +2 -2
- package/lib/internal/_randomFormatHostname.mjs +2 -2
- package/lib/internal/_randomFormatHostname.mjs.map +1 -1
- package/lib/internal/_randomFormatIdnHostname.js +9 -10
- package/lib/internal/_randomFormatIdnHostname.js.map +1 -1
- package/lib/internal/_randomFormatIdnHostname.mjs +3 -4
- package/lib/internal/_randomFormatIdnHostname.mjs.map +1 -1
- package/lib/internal/_randomFormatRegex.js +4 -4
- package/lib/internal/_randomFormatRegex.js.map +1 -1
- package/lib/internal/_randomFormatRegex.mjs +1 -2
- package/lib/internal/_randomFormatRegex.mjs.map +1 -1
- package/lib/internal/_randomFormatTime.js +15 -10
- package/lib/internal/_randomFormatTime.js.map +1 -1
- package/lib/internal/_randomFormatTime.mjs +6 -3
- package/lib/internal/_randomFormatTime.mjs.map +1 -1
- package/lib/internal/private/__randomComposition.d.ts +8 -0
- package/lib/internal/private/__randomComposition.js +21 -1
- package/lib/internal/private/__randomComposition.js.map +1 -1
- package/lib/internal/private/__randomComposition.mjs +18 -1
- package/lib/internal/private/__randomComposition.mjs.map +1 -1
- package/lib/json.d.ts +2 -2
- package/lib/json.js.map +1 -1
- package/lib/json.mjs.map +1 -1
- package/lib/module.d.ts +28 -13
- package/lib/module.js.map +1 -1
- package/lib/module.mjs.map +1 -1
- package/lib/notations.d.ts +4 -4
- package/lib/notations.js.map +1 -1
- package/lib/notations.mjs.map +1 -1
- package/lib/plain.d.ts +3 -3
- package/lib/plain.js.map +1 -1
- package/lib/plain.mjs.map +1 -1
- package/lib/protobuf.d.ts +2 -2
- package/lib/protobuf.js.map +1 -1
- package/lib/protobuf.mjs.map +1 -1
- package/native/cmd/ttsc-typia/assert_guard_factory_contract_test.go +17 -4
- package/native/cmd/ttsc-typia/create_assert_error_factory_arity_test.go +309 -0
- package/native/cmd/ttsc-typia/local_function_named_like_typia_operation_transform_test.go +185 -0
- package/native/cmd/ttsc-typia/recursive_conditional_alias_name_transform_test.go +307 -0
- package/native/cmd/ttsc-typia/shadowed_typia_module_declaration_diagnostic_test.go +152 -0
- package/native/cmd/ttsc-typia/template_literal_type_tags_transform_test.go +1 -3
- package/native/cmd/ttsc-typia/transform_helpers_test.go +92 -26
- package/native/core/factories/FormatCheatSheet.go +2 -2
- package/native/core/factories/MetadataCommentTagFactory.go +26 -11
- package/native/core/factories/factory_utility_coverage_test.go +896 -907
- package/native/core/factories/internal/metadata/MetadataHelper.go +5 -28
- package/native/core/factories/metadata_comment_tag_factory_coverage_test.go +2 -2
- package/native/core/programmers/RandomProgrammer.go +5 -2
- package/native/core/schemas/metadata/MetadataCollection.go +47 -5
- package/native/transform/CallExpressionTransformer.go +167 -0
- package/package.json +3 -3
- package/src/http.ts +18 -4
- package/src/internal/_assertGuard.ts +13 -2
- package/src/internal/_isFormatIdnHostname.ts +5 -1
- package/src/internal/_isFormatTime.ts +19 -2
- package/src/internal/_randomArray.ts +42 -6
- package/src/internal/_randomFormatByte.ts +17 -12
- package/src/internal/_randomFormatHostname.ts +2 -2
- package/src/internal/_randomFormatIdnHostname.ts +8 -9
- package/src/internal/_randomFormatRegex.ts +4 -6
- package/src/internal/_randomFormatTime.ts +15 -10
- package/src/internal/private/__randomComposition.ts +24 -0
- package/src/json.ts +16 -4
- package/src/module.ts +56 -22
- package/src/notations.ts +16 -4
- package/src/plain.ts +12 -3
- package/src/protobuf.ts +16 -4
package/lib/plain.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plain.mjs","names":[],"sources":["../src/plain.ts"],"sourcesContent":["/* ===========================================================\n PLAIN\n - CLONE\n - PRUNE\n - CLASSIFY\n - FACTORY FUNCTIONS\n=========================================================== */\nimport {\n Classifiable,\n ClassifyResult,\n IValidation,\n Resolved,\n} from \"@typia/interface\";\n\nimport { TypeGuardError } from \"./TypeGuardError\";\nimport { NoTransformConfigurationError } from \"./transformers/NoTransformConfigurationError\";\n\n/* -----------------------------------------------------------\n CLONE\n----------------------------------------------------------- */\n/**\n * Deep clones value of type `T`.\n *\n * Creates a deep copy of the input value. Class instances with methods are\n * cloned as plain objects (methods are not copied).\n *\n * Does not validate the input. For validation, use:\n *\n * - {@link assertClone} — Throws on type mismatch\n * - {@link isClone} — Returns `null` on type mismatch\n * - {@link validateClone} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Value to clone\n * @returns Deep cloned value\n */\nexport function clone<T>(input: T): Resolved<T>;\n\n/** @internal */\nexport function clone(): never {\n NoTransformConfigurationError(\"plain.clone\");\n}\n\n/**\n * Deep clones value with assertion.\n *\n * Creates a deep copy with {@link assert} validation. Throws\n * {@link TypeGuardError} on type mismatch. Class instances with methods are\n * cloned as plain objects.\n *\n * Related functions:\n *\n * - {@link clone} — No validation\n * - {@link isClone} — Returns `null` instead of throwing\n * - {@link validateClone} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Value to clone\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Deep cloned value\n * @throws {TypeGuardError} When input doesn't conform to type `T`\n */\nexport function assertClone<T>(\n input: T,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): Resolved<T>;\n\n/** @internal */\nexport function assertClone<T>(\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): Resolved<T>;\n\n/** @internal */\nexport function assertClone(): never {\n NoTransformConfigurationError(\"plain.assertClone\");\n}\n\n/**\n * Deep clones value with type checking.\n *\n * Creates a deep copy with {@link is} validation. Returns `null` on type\n * mismatch. Class instances with methods are cloned as plain objects.\n *\n * Related functions:\n *\n * - {@link clone} — No validation\n * - {@link assertClone} — Throws instead of returning `null`\n * - {@link validateClone} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Value to clone\n * @returns Deep cloned value, or `null` if invalid\n */\nexport function isClone<T>(input: T): Resolved<T> | null;\n\n/** @internal */\nexport function isClone<T>(input: unknown): Resolved<T> | null;\n\n/** @internal */\nexport function isClone(): never {\n NoTransformConfigurationError(\"plain.isClone\");\n}\n\n/**\n * Deep clones value with validation.\n *\n * Creates a deep copy with {@link validate} validation. Returns\n * {@link IValidation.IFailure} with all errors on mismatch, or\n * {@link IValidation.ISuccess} with cloned value. Class instances with methods\n * are cloned as plain objects.\n *\n * Related functions:\n *\n * - {@link clone} — No validation\n * - {@link assertClone} — Throws on first error\n * - {@link isClone} — Returns `null` instead of error details\n *\n * @template T Type of input value\n * @param input Value to clone\n * @returns Validation result containing cloned value or errors\n */\nexport function validateClone<T>(input: T): IValidation<Resolved<T>>;\n\n/** @internal */\nexport function validateClone<T>(input: unknown): IValidation<Resolved<T>>;\n\n/** @internal */\nexport function validateClone(): never {\n NoTransformConfigurationError(\"plain.validateClone\");\n}\n\n/* -----------------------------------------------------------\n PRUNE\n----------------------------------------------------------- */\n/**\n * Removes superfluous properties from object.\n *\n * Deletes all properties not defined in type `T`, including in nested objects.\n * Mutates the input directly—removed properties cannot be recovered.\n *\n * Does not validate the input. For validation, use:\n *\n * - {@link assertPrune} — Throws on type mismatch\n * - {@link isPrune} — Returns `false` on type mismatch\n * - {@link validatePrune} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Object to prune\n */\nexport function prune<T extends object>(input: T): void;\n\n/** @internal */\nexport function prune(): never {\n NoTransformConfigurationError(\"plain.prune\");\n}\n\n/**\n * Removes superfluous properties with assertion.\n *\n * Combines {@link assert} with {@link prune}. Throws {@link TypeGuardError} on\n * type mismatch. Mutates the input directly—removed properties cannot be\n * recovered.\n *\n * Related functions:\n *\n * - {@link prune} — No validation\n * - {@link isPrune} — Returns `false` instead of throwing\n * - {@link validatePrune} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Object to assert and prune\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns The pruned input\n * @throws {TypeGuardError} When input doesn't conform to type `T`\n */\nexport function assertPrune<T>(\n input: T,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): T;\n\n/** @internal */\nexport function assertPrune<T>(\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): T;\n\n/** @internal */\nexport function assertPrune(): unknown {\n NoTransformConfigurationError(\"plain.assertPrune\");\n}\n\n/**\n * Removes superfluous properties with type checking.\n *\n * Combines {@link is} with {@link prune}. Returns `false` on type mismatch (no\n * pruning occurs). Returns `true` after successful pruning. Mutates the input\n * directly.\n *\n * Related functions:\n *\n * - {@link prune} — No validation\n * - {@link assertPrune} — Throws instead of returning `false`\n * - {@link validatePrune} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Object to check and prune\n * @returns `true` if valid and pruned, `false` if type mismatch\n */\nexport function isPrune<T>(input: T): input is T;\n\n/** @internal */\nexport function isPrune<T>(input: unknown): input is T;\n\n/** @internal */\nexport function isPrune(): never {\n NoTransformConfigurationError(\"plain.isPrune\");\n}\n\n/**\n * Removes superfluous properties with validation.\n *\n * Combines {@link validate} with {@link prune}. Returns\n * {@link IValidation.IFailure} with all errors on mismatch (no pruning occurs),\n * or {@link IValidation.ISuccess} after successful pruning. Mutates the input\n * directly.\n *\n * Related functions:\n *\n * - {@link prune} — No validation\n * - {@link assertPrune} — Throws on first error\n * - {@link isPrune} — Returns `false` instead of error details\n *\n * @template T Type of input value\n * @param input Object to validate and prune\n * @returns Validation result\n */\nexport function validatePrune<T>(input: T): IValidation<T>;\n\n/** @internal */\nexport function validatePrune<T>(input: unknown): IValidation<T>;\n\n/** @internal */\nexport function validatePrune<T>(): IValidation<T> {\n NoTransformConfigurationError(\"plain.validatePrune\");\n}\n\n/* -----------------------------------------------------------\n CLASSIFY\n----------------------------------------------------------- */\n/**\n * Reconstructs a class instance from plain data.\n *\n * Builds a real instance of class type `T` from a plain object, driven by\n * typia's compile-time type information — no decorators required (unlike\n * `class-transformer`). Each class is constructed by exactly one strategy, in\n * precedence order: a static factory `T.from(x)`, then `new T(x)` (single\n * argument), then field copy onto the prototype. Nested classes and containers\n * are reconstructed recursively, and methods come from the prototype.\n *\n * Does not validate the input. For validation, use:\n *\n * - {@link assertClassify} — Throws on type mismatch\n * - {@link validateClassify} — Returns detailed validation errors\n *\n * @template T Target class type to reconstruct\n * @param input Plain data to classify\n * @returns A real instance of type `T`\n */\nexport function classify<T>(input: Classifiable<T>): ClassifyResult<T>;\n\n/** @internal */\nexport function classify(): never {\n NoTransformConfigurationError(\"plain.classify\");\n}\n\n/**\n * Reconstructs a class instance with assertion.\n *\n * Combines {@link assert} with {@link classify}: validates the plain input\n * against type `T`, throwing {@link TypeGuardError} on mismatch, then builds a\n * real instance of `T`.\n *\n * Related functions:\n *\n * - {@link classify} — No validation\n * - {@link validateClassify} — Returns detailed validation errors\n *\n * @template T Target class type to reconstruct\n * @param input Plain data to validate and classify\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns A real instance of type `T`\n * @throws {TypeGuardError} When input doesn't conform to type `T`\n */\nexport function assertClassify<T>(\n input: Classifiable<T>,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): ClassifyResult<T>;\n\n/** @internal */\nexport function assertClassify<T>(\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): ClassifyResult<T>;\n\n/** @internal */\nexport function assertClassify(): never {\n NoTransformConfigurationError(\"plain.assertClassify\");\n}\n\n/**\n * Reconstructs a class instance with validation.\n *\n * Combines {@link validate} with {@link classify}: validates the plain input\n * against type `T`, returning {@link IValidation.IFailure} with all errors on\n * mismatch, or {@link IValidation.ISuccess} holding a real instance of `T`.\n *\n * Related functions:\n *\n * - {@link classify} — No validation\n * - {@link assertClassify} — Throws on first error\n *\n * @template T Target class type to reconstruct\n * @param input Plain data to validate and classify\n * @returns Validation result containing the instance or errors\n */\nexport function validateClassify<T>(\n input: Classifiable<T>,\n): IValidation<ClassifyResult<T>>;\n\n/** @internal */\nexport function validateClassify<T>(\n input: unknown,\n): IValidation<ClassifyResult<T>>;\n\n/** @internal */\nexport function validateClassify(): never {\n NoTransformConfigurationError(\"plain.validateClassify\");\n}\n\n/* -----------------------------------------------------------\n FACTORY FUNCTIONS\n----------------------------------------------------------- */\n/**\n * Creates reusable {@link clone} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createClone(): never;\n\n/**\n * Creates reusable {@link clone} function.\n *\n * @template T Type of input value\n * @returns Reusable clone function\n */\nexport function createClone<T>(): (input: T) => Resolved<T>;\n\n/** @internal */\nexport function createClone(): never {\n NoTransformConfigurationError(\"plain.createClone\");\n}\n\n/**\n * Creates reusable {@link assertClone} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createAssertClone(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Creates reusable {@link assertClone} function.\n *\n * @template T Type of input value\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Reusable clone function\n */\nexport function createAssertClone<T>(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): (input: unknown) => Resolved<T>;\n\n/** @internal */\nexport function createAssertClone(): never {\n NoTransformConfigurationError(\"plain.createAssertClone\");\n}\n\n/**\n * Creates reusable {@link isClone} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createIsClone(): never;\n\n/**\n * Creates reusable {@link isClone} function.\n *\n * @template T Type of input value\n * @returns Reusable clone function\n */\nexport function createIsClone<T>(): (input: unknown) => Resolved<T> | null;\n\n/** @internal */\nexport function createIsClone(): never {\n NoTransformConfigurationError(\"plain.createIsClone\");\n}\n\n/**\n * Creates reusable {@link validateClone} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createValidateClone(): never;\n\n/**\n * Creates reusable {@link validateClone} function.\n *\n * @template T Type of input value\n * @returns Reusable clone function\n */\nexport function createValidateClone<T>(): (\n input: unknown,\n) => IValidation<Resolved<T>>;\n\n/** @internal */\nexport function createValidateClone(): never {\n NoTransformConfigurationError(\"plain.createValidateClone\");\n}\n\n/**\n * Creates reusable {@link prune} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createPrune(): never;\n\n/**\n * Creates reusable {@link prune} function.\n *\n * @template T Type of input value\n * @returns Reusable prune function\n */\nexport function createPrune<T extends object>(): (input: T) => void;\n\n/** @internal */\nexport function createPrune(): never {\n NoTransformConfigurationError(\"plain.createPrune\");\n}\n\n/**\n * Creates reusable {@link assertPrune} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createAssertPrune(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Creates reusable {@link assertPrune} function.\n *\n * @template T Type of input value\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Reusable prune function\n */\nexport function createAssertPrune<T extends object>(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): (input: unknown) => T;\n\n/** @internal */\nexport function createAssertPrune(): never {\n NoTransformConfigurationError(\"plain.createAssertPrune\");\n}\n\n/**\n * Creates reusable {@link isPrune} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createIsPrune(): never;\n\n/**\n * Creates reusable {@link isPrune} function.\n *\n * @template T Type of input value\n * @returns Reusable prune function\n */\nexport function createIsPrune<T extends object>(): (\n input: unknown,\n) => input is T;\n\n/** @internal */\nexport function createIsPrune(): never {\n NoTransformConfigurationError(\"plain.createIsPrune\");\n}\n\n/**\n * Creates reusable {@link validatePrune} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createValidatePrune(): never;\n\n/**\n * Creates reusable {@link validatePrune} function.\n *\n * @template T Type of input value\n * @returns Reusable prune function\n */\nexport function createValidatePrune<T extends object>(): (\n input: unknown,\n) => IValidation<T>;\n\n/** @internal */\nexport function createValidatePrune(): never {\n NoTransformConfigurationError(\"plain.createValidatePrune\");\n}\n\n/**\n * Creates reusable {@link classify} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createClassify(): never;\n\n/**\n * Creates reusable {@link classify} function.\n *\n * @template T Target class type to reconstruct\n * @returns Reusable classify function\n */\nexport function createClassify<T>(): (\n input: Classifiable<T>,\n) => ClassifyResult<T>;\n\n/** @internal */\nexport function createClassify(): never {\n NoTransformConfigurationError(\"plain.createClassify\");\n}\n\n/**\n * Creates reusable {@link assertClassify} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createAssertClassify(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Creates reusable {@link assertClassify} function.\n *\n * @template T Target class type to reconstruct\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Reusable classify function\n */\nexport function createAssertClassify<T>(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): (input: unknown) => ClassifyResult<T>;\n\n/** @internal */\nexport function createAssertClassify(): never {\n NoTransformConfigurationError(\"plain.createAssertClassify\");\n}\n\n/**\n * Creates reusable {@link validateClassify} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createValidateClassify(): never;\n\n/**\n * Creates reusable {@link validateClassify} function.\n *\n * @template T Target class type to reconstruct\n * @returns Reusable classify function\n */\nexport function createValidateClassify<T>(): (\n input: unknown,\n) => IValidation<ClassifyResult<T>>;\n\n/** @internal */\nexport function createValidateClassify(): never {\n NoTransformConfigurationError(\"plain.createValidateClassify\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,QAAe;CAC7B,8BAA8B,aAAa;AAC7C;;AAkCA,SAAgB,cAAqB;CACnC,8BAA8B,mBAAmB;AACnD;;AAwBA,SAAgB,UAAiB;CAC/B,8BAA8B,eAAe;AAC/C;;AA0BA,SAAgB,gBAAuB;CACrC,8BAA8B,qBAAqB;AACrD;;AAuBA,SAAgB,QAAe;CAC7B,8BAA8B,aAAa;AAC7C;;AAkCA,SAAgB,cAAuB;CACrC,8BAA8B,mBAAmB;AACnD;;AAyBA,SAAgB,UAAiB;CAC/B,8BAA8B,eAAe;AAC/C;;AA0BA,SAAgB,gBAAmC;CACjD,8BAA8B,qBAAqB;AACrD;;AA2BA,SAAgB,WAAkB;CAChC,8BAA8B,gBAAgB;AAChD;;AAiCA,SAAgB,iBAAwB;CACtC,8BAA8B,sBAAsB;AACtD;;AA4BA,SAAgB,mBAA0B;CACxC,8BAA8B,wBAAwB;AACxD;;AAqBA,SAAgB,cAAqB;CACnC,8BAA8B,mBAAmB;AACnD;;AAwBA,SAAgB,oBAA2B;CACzC,8BAA8B,yBAAyB;AACzD;;AAkBA,SAAgB,gBAAuB;CACrC,8BAA8B,qBAAqB;AACrD;;AAoBA,SAAgB,sBAA6B;CAC3C,8BAA8B,2BAA2B;AAC3D;;AAkBA,SAAgB,cAAqB;CACnC,8BAA8B,mBAAmB;AACnD;;AAwBA,SAAgB,oBAA2B;CACzC,8BAA8B,yBAAyB;AACzD;;AAoBA,SAAgB,gBAAuB;CACrC,8BAA8B,qBAAqB;AACrD;;AAoBA,SAAgB,sBAA6B;CAC3C,8BAA8B,2BAA2B;AAC3D;;AAoBA,SAAgB,iBAAwB;CACtC,8BAA8B,sBAAsB;AACtD;;AAwBA,SAAgB,uBAA8B;CAC5C,8BAA8B,4BAA4B;AAC5D;;AAoBA,SAAgB,yBAAgC;CAC9C,8BAA8B,8BAA8B;AAC9D"}
|
|
1
|
+
{"version":3,"file":"plain.mjs","names":[],"sources":["../src/plain.ts"],"sourcesContent":["/* ===========================================================\n PLAIN\n - CLONE\n - PRUNE\n - CLASSIFY\n - FACTORY FUNCTIONS\n=========================================================== */\nimport {\n Classifiable,\n ClassifyResult,\n IValidation,\n Resolved,\n} from \"@typia/interface\";\n\nimport { TypeGuardError } from \"./TypeGuardError\";\nimport { NoTransformConfigurationError } from \"./transformers/NoTransformConfigurationError\";\n\n/* -----------------------------------------------------------\n CLONE\n----------------------------------------------------------- */\n/**\n * Deep clones value of type `T`.\n *\n * Creates a deep copy of the input value. Class instances with methods are\n * cloned as plain objects (methods are not copied).\n *\n * Does not validate the input. For validation, use:\n *\n * - {@link assertClone} — Throws on type mismatch\n * - {@link isClone} — Returns `null` on type mismatch\n * - {@link validateClone} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Value to clone\n * @returns Deep cloned value\n */\nexport function clone<T>(input: T): Resolved<T>;\n\n/** @internal */\nexport function clone(): never {\n NoTransformConfigurationError(\"plain.clone\");\n}\n\n/**\n * Deep clones value with assertion.\n *\n * Creates a deep copy with {@link assert} validation. Throws\n * {@link TypeGuardError} on type mismatch. Class instances with methods are\n * cloned as plain objects.\n *\n * Related functions:\n *\n * - {@link clone} — No validation\n * - {@link isClone} — Returns `null` instead of throwing\n * - {@link validateClone} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Value to clone\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Deep cloned value\n * @throws {TypeGuardError} When input doesn't conform to type `T`\n */\nexport function assertClone<T>(\n input: T,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): Resolved<T>;\n\n/** @internal */\nexport function assertClone<T>(\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): Resolved<T>;\n\n/** @internal */\nexport function assertClone(): never {\n NoTransformConfigurationError(\"plain.assertClone\");\n}\n\n/**\n * Deep clones value with type checking.\n *\n * Creates a deep copy with {@link is} validation. Returns `null` on type\n * mismatch. Class instances with methods are cloned as plain objects.\n *\n * Related functions:\n *\n * - {@link clone} — No validation\n * - {@link assertClone} — Throws instead of returning `null`\n * - {@link validateClone} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Value to clone\n * @returns Deep cloned value, or `null` if invalid\n */\nexport function isClone<T>(input: T): Resolved<T> | null;\n\n/** @internal */\nexport function isClone<T>(input: unknown): Resolved<T> | null;\n\n/** @internal */\nexport function isClone(): never {\n NoTransformConfigurationError(\"plain.isClone\");\n}\n\n/**\n * Deep clones value with validation.\n *\n * Creates a deep copy with {@link validate} validation. Returns\n * {@link IValidation.IFailure} with all errors on mismatch, or\n * {@link IValidation.ISuccess} with cloned value. Class instances with methods\n * are cloned as plain objects.\n *\n * Related functions:\n *\n * - {@link clone} — No validation\n * - {@link assertClone} — Throws on first error\n * - {@link isClone} — Returns `null` instead of error details\n *\n * @template T Type of input value\n * @param input Value to clone\n * @returns Validation result containing cloned value or errors\n */\nexport function validateClone<T>(input: T): IValidation<Resolved<T>>;\n\n/** @internal */\nexport function validateClone<T>(input: unknown): IValidation<Resolved<T>>;\n\n/** @internal */\nexport function validateClone(): never {\n NoTransformConfigurationError(\"plain.validateClone\");\n}\n\n/* -----------------------------------------------------------\n PRUNE\n----------------------------------------------------------- */\n/**\n * Removes superfluous properties from object.\n *\n * Deletes all properties not defined in type `T`, including in nested objects.\n * Mutates the input directly—removed properties cannot be recovered.\n *\n * Does not validate the input. For validation, use:\n *\n * - {@link assertPrune} — Throws on type mismatch\n * - {@link isPrune} — Returns `false` on type mismatch\n * - {@link validatePrune} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Object to prune\n */\nexport function prune<T extends object>(input: T): void;\n\n/** @internal */\nexport function prune(): never {\n NoTransformConfigurationError(\"plain.prune\");\n}\n\n/**\n * Removes superfluous properties with assertion.\n *\n * Combines {@link assert} with {@link prune}. Throws {@link TypeGuardError} on\n * type mismatch. Mutates the input directly—removed properties cannot be\n * recovered.\n *\n * Related functions:\n *\n * - {@link prune} — No validation\n * - {@link isPrune} — Returns `false` instead of throwing\n * - {@link validatePrune} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Object to assert and prune\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns The pruned input\n * @throws {TypeGuardError} When input doesn't conform to type `T`\n */\nexport function assertPrune<T>(\n input: T,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): T;\n\n/** @internal */\nexport function assertPrune<T>(\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): T;\n\n/** @internal */\nexport function assertPrune(): unknown {\n NoTransformConfigurationError(\"plain.assertPrune\");\n}\n\n/**\n * Removes superfluous properties with type checking.\n *\n * Combines {@link is} with {@link prune}. Returns `false` on type mismatch (no\n * pruning occurs). Returns `true` after successful pruning. Mutates the input\n * directly.\n *\n * Related functions:\n *\n * - {@link prune} — No validation\n * - {@link assertPrune} — Throws instead of returning `false`\n * - {@link validatePrune} — Returns detailed validation errors\n *\n * @template T Type of input value\n * @param input Object to check and prune\n * @returns `true` if valid and pruned, `false` if type mismatch\n */\nexport function isPrune<T>(input: T): input is T;\n\n/** @internal */\nexport function isPrune<T>(input: unknown): input is T;\n\n/** @internal */\nexport function isPrune(): never {\n NoTransformConfigurationError(\"plain.isPrune\");\n}\n\n/**\n * Removes superfluous properties with validation.\n *\n * Combines {@link validate} with {@link prune}. Returns\n * {@link IValidation.IFailure} with all errors on mismatch (no pruning occurs),\n * or {@link IValidation.ISuccess} after successful pruning. Mutates the input\n * directly.\n *\n * Related functions:\n *\n * - {@link prune} — No validation\n * - {@link assertPrune} — Throws on first error\n * - {@link isPrune} — Returns `false` instead of error details\n *\n * @template T Type of input value\n * @param input Object to validate and prune\n * @returns Validation result\n */\nexport function validatePrune<T>(input: T): IValidation<T>;\n\n/** @internal */\nexport function validatePrune<T>(input: unknown): IValidation<T>;\n\n/** @internal */\nexport function validatePrune<T>(): IValidation<T> {\n NoTransformConfigurationError(\"plain.validatePrune\");\n}\n\n/* -----------------------------------------------------------\n CLASSIFY\n----------------------------------------------------------- */\n/**\n * Reconstructs a class instance from plain data.\n *\n * Builds a real instance of class type `T` from a plain object, driven by\n * typia's compile-time type information — no decorators required (unlike\n * `class-transformer`). Each class is constructed by exactly one strategy, in\n * precedence order: a static factory `T.from(x)`, then `new T(x)` (single\n * argument), then field copy onto the prototype. Nested classes and containers\n * are reconstructed recursively, and methods come from the prototype.\n *\n * Does not validate the input. For validation, use:\n *\n * - {@link assertClassify} — Throws on type mismatch\n * - {@link validateClassify} — Returns detailed validation errors\n *\n * @template T Target class type to reconstruct\n * @param input Plain data to classify\n * @returns A real instance of type `T`\n */\nexport function classify<T>(input: Classifiable<T>): ClassifyResult<T>;\n\n/** @internal */\nexport function classify(): never {\n NoTransformConfigurationError(\"plain.classify\");\n}\n\n/**\n * Reconstructs a class instance with assertion.\n *\n * Combines {@link assert} with {@link classify}: validates the plain input\n * against type `T`, throwing {@link TypeGuardError} on mismatch, then builds a\n * real instance of `T`.\n *\n * Related functions:\n *\n * - {@link classify} — No validation\n * - {@link validateClassify} — Returns detailed validation errors\n *\n * @template T Target class type to reconstruct\n * @param input Plain data to validate and classify\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns A real instance of type `T`\n * @throws {TypeGuardError} When input doesn't conform to type `T`\n */\nexport function assertClassify<T>(\n input: Classifiable<T>,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): ClassifyResult<T>;\n\n/** @internal */\nexport function assertClassify<T>(\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): ClassifyResult<T>;\n\n/** @internal */\nexport function assertClassify(): never {\n NoTransformConfigurationError(\"plain.assertClassify\");\n}\n\n/**\n * Reconstructs a class instance with validation.\n *\n * Combines {@link validate} with {@link classify}: validates the plain input\n * against type `T`, returning {@link IValidation.IFailure} with all errors on\n * mismatch, or {@link IValidation.ISuccess} holding a real instance of `T`.\n *\n * Related functions:\n *\n * - {@link classify} — No validation\n * - {@link assertClassify} — Throws on first error\n *\n * @template T Target class type to reconstruct\n * @param input Plain data to validate and classify\n * @returns Validation result containing the instance or errors\n */\nexport function validateClassify<T>(\n input: Classifiable<T>,\n): IValidation<ClassifyResult<T>>;\n\n/** @internal */\nexport function validateClassify<T>(\n input: unknown,\n): IValidation<ClassifyResult<T>>;\n\n/** @internal */\nexport function validateClassify(): never {\n NoTransformConfigurationError(\"plain.validateClassify\");\n}\n\n/* -----------------------------------------------------------\n FACTORY FUNCTIONS\n----------------------------------------------------------- */\n/**\n * Creates reusable {@link clone} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createClone(): never;\n\n/**\n * Creates reusable {@link clone} function.\n *\n * @template T Type of input value\n * @returns Reusable clone function\n */\nexport function createClone<T>(): (input: T) => Resolved<T>;\n\n/** @internal */\nexport function createClone(): never {\n NoTransformConfigurationError(\"plain.createClone\");\n}\n\n/**\n * Creates reusable {@link assertClone} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createAssertClone(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Creates reusable {@link assertClone} function.\n *\n * @template T Type of input value\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Reusable clone function\n */\nexport function createAssertClone<T>(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): (\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n) => Resolved<T>;\n\n/** @internal */\nexport function createAssertClone(): never {\n NoTransformConfigurationError(\"plain.createAssertClone\");\n}\n\n/**\n * Creates reusable {@link isClone} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createIsClone(): never;\n\n/**\n * Creates reusable {@link isClone} function.\n *\n * @template T Type of input value\n * @returns Reusable clone function\n */\nexport function createIsClone<T>(): (input: unknown) => Resolved<T> | null;\n\n/** @internal */\nexport function createIsClone(): never {\n NoTransformConfigurationError(\"plain.createIsClone\");\n}\n\n/**\n * Creates reusable {@link validateClone} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createValidateClone(): never;\n\n/**\n * Creates reusable {@link validateClone} function.\n *\n * @template T Type of input value\n * @returns Reusable clone function\n */\nexport function createValidateClone<T>(): (\n input: unknown,\n) => IValidation<Resolved<T>>;\n\n/** @internal */\nexport function createValidateClone(): never {\n NoTransformConfigurationError(\"plain.createValidateClone\");\n}\n\n/**\n * Creates reusable {@link prune} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createPrune(): never;\n\n/**\n * Creates reusable {@link prune} function.\n *\n * @template T Type of input value\n * @returns Reusable prune function\n */\nexport function createPrune<T extends object>(): (input: T) => void;\n\n/** @internal */\nexport function createPrune(): never {\n NoTransformConfigurationError(\"plain.createPrune\");\n}\n\n/**\n * Creates reusable {@link assertPrune} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createAssertPrune(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Creates reusable {@link assertPrune} function.\n *\n * @template T Type of input value\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Reusable prune function\n */\nexport function createAssertPrune<T extends object>(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): (\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n) => T;\n\n/** @internal */\nexport function createAssertPrune(): never {\n NoTransformConfigurationError(\"plain.createAssertPrune\");\n}\n\n/**\n * Creates reusable {@link isPrune} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createIsPrune(): never;\n\n/**\n * Creates reusable {@link isPrune} function.\n *\n * @template T Type of input value\n * @returns Reusable prune function\n */\nexport function createIsPrune<T extends object>(): (\n input: unknown,\n) => input is T;\n\n/** @internal */\nexport function createIsPrune(): never {\n NoTransformConfigurationError(\"plain.createIsPrune\");\n}\n\n/**\n * Creates reusable {@link validatePrune} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createValidatePrune(): never;\n\n/**\n * Creates reusable {@link validatePrune} function.\n *\n * @template T Type of input value\n * @returns Reusable prune function\n */\nexport function createValidatePrune<T extends object>(): (\n input: unknown,\n) => IValidation<T>;\n\n/** @internal */\nexport function createValidatePrune(): never {\n NoTransformConfigurationError(\"plain.createValidatePrune\");\n}\n\n/**\n * Creates reusable {@link classify} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createClassify(): never;\n\n/**\n * Creates reusable {@link classify} function.\n *\n * @template T Target class type to reconstruct\n * @returns Reusable classify function\n */\nexport function createClassify<T>(): (\n input: Classifiable<T>,\n) => ClassifyResult<T>;\n\n/** @internal */\nexport function createClassify(): never {\n NoTransformConfigurationError(\"plain.createClassify\");\n}\n\n/**\n * Creates reusable {@link assertClassify} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createAssertClassify(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Creates reusable {@link assertClassify} function.\n *\n * @template T Target class type to reconstruct\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Reusable classify function\n */\nexport function createAssertClassify<T>(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): (\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n) => ClassifyResult<T>;\n\n/** @internal */\nexport function createAssertClassify(): never {\n NoTransformConfigurationError(\"plain.createAssertClassify\");\n}\n\n/**\n * Creates reusable {@link validateClassify} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createValidateClassify(): never;\n\n/**\n * Creates reusable {@link validateClassify} function.\n *\n * @template T Target class type to reconstruct\n * @returns Reusable classify function\n */\nexport function createValidateClassify<T>(): (\n input: unknown,\n) => IValidation<ClassifyResult<T>>;\n\n/** @internal */\nexport function createValidateClassify(): never {\n NoTransformConfigurationError(\"plain.createValidateClassify\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,QAAe;CAC7B,8BAA8B,aAAa;AAC7C;;AAkCA,SAAgB,cAAqB;CACnC,8BAA8B,mBAAmB;AACnD;;AAwBA,SAAgB,UAAiB;CAC/B,8BAA8B,eAAe;AAC/C;;AA0BA,SAAgB,gBAAuB;CACrC,8BAA8B,qBAAqB;AACrD;;AAuBA,SAAgB,QAAe;CAC7B,8BAA8B,aAAa;AAC7C;;AAkCA,SAAgB,cAAuB;CACrC,8BAA8B,mBAAmB;AACnD;;AAyBA,SAAgB,UAAiB;CAC/B,8BAA8B,eAAe;AAC/C;;AA0BA,SAAgB,gBAAmC;CACjD,8BAA8B,qBAAqB;AACrD;;AA2BA,SAAgB,WAAkB;CAChC,8BAA8B,gBAAgB;AAChD;;AAiCA,SAAgB,iBAAwB;CACtC,8BAA8B,sBAAsB;AACtD;;AA4BA,SAAgB,mBAA0B;CACxC,8BAA8B,wBAAwB;AACxD;;AAqBA,SAAgB,cAAqB;CACnC,8BAA8B,mBAAmB;AACnD;;AA2BA,SAAgB,oBAA2B;CACzC,8BAA8B,yBAAyB;AACzD;;AAkBA,SAAgB,gBAAuB;CACrC,8BAA8B,qBAAqB;AACrD;;AAoBA,SAAgB,sBAA6B;CAC3C,8BAA8B,2BAA2B;AAC3D;;AAkBA,SAAgB,cAAqB;CACnC,8BAA8B,mBAAmB;AACnD;;AA2BA,SAAgB,oBAA2B;CACzC,8BAA8B,yBAAyB;AACzD;;AAoBA,SAAgB,gBAAuB;CACrC,8BAA8B,qBAAqB;AACrD;;AAoBA,SAAgB,sBAA6B;CAC3C,8BAA8B,2BAA2B;AAC3D;;AAoBA,SAAgB,iBAAwB;CACtC,8BAA8B,sBAAsB;AACtD;;AA2BA,SAAgB,uBAA8B;CAC5C,8BAA8B,4BAA4B;AAC5D;;AAoBA,SAAgB,yBAAgC;CAC9C,8BAA8B,8BAA8B;AAC9D"}
|
package/lib/protobuf.d.ts
CHANGED
|
@@ -257,7 +257,7 @@ export declare function createAssertDecode(errorFactory?: undefined | ((props: T
|
|
|
257
257
|
* {@link TypeGuardError.IProps}
|
|
258
258
|
* @returns Reusable decoder function
|
|
259
259
|
*/
|
|
260
|
-
export declare function createAssertDecode<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: Uint8Array) => Resolved<T>;
|
|
260
|
+
export declare function createAssertDecode<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: Uint8Array, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)) => Resolved<T>;
|
|
261
261
|
/**
|
|
262
262
|
* Creates reusable {@link validateDecode} function.
|
|
263
263
|
*
|
|
@@ -311,7 +311,7 @@ export declare function createAssertEncode(errorFactory?: undefined | ((props: T
|
|
|
311
311
|
* {@link TypeGuardError.IProps}
|
|
312
312
|
* @returns Reusable encoder function
|
|
313
313
|
*/
|
|
314
|
-
export declare function createAssertEncode<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: T) => Uint8Array;
|
|
314
|
+
export declare function createAssertEncode<T>(errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): (input: T, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)) => Uint8Array;
|
|
315
315
|
/**
|
|
316
316
|
* Creates reusable {@link validateEncode} function.
|
|
317
317
|
*
|
package/lib/protobuf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protobuf.js","sourceRoot":"","sources":["../src/protobuf.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAGA,gGAA6F;AAiC7F,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,kBAAkB,CAAC,CAAC;AACpD,CAAC;AAkCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,iBAAiB,CAAC,CAAC;AACnD,CAAC;AAwCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,uBAAuB,CAAC,CAAC;AACzD,CAAC;AA8BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,mBAAmB,CAAC,CAAC;AACrD,CAAC;AAgCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,yBAAyB,CAAC,CAAC;AAC3D,CAAC;AA0BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,iBAAiB,CAAC,CAAC;AACnD,CAAC;AAoCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,uBAAuB,CAAC,CAAC;AACzD,CAAC;AA0BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,mBAAmB,CAAC,CAAC;AACrD,CAAC;AA4BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,yBAAyB,CAAC,CAAC;AAC3D,CAAC;AAoBD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,uBAAuB,CAAC,CAAC;AACzD,CAAC;AAiBD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,yBAAyB,CAAC,CAAC;AAC3D,CAAC;
|
|
1
|
+
{"version":3,"file":"protobuf.js","sourceRoot":"","sources":["../src/protobuf.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAGA,gGAA6F;AAiC7F,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,kBAAkB,CAAC,CAAC;AACpD,CAAC;AAkCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,iBAAiB,CAAC,CAAC;AACnD,CAAC;AAwCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,uBAAuB,CAAC,CAAC;AACzD,CAAC;AA8BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,mBAAmB,CAAC,CAAC;AACrD,CAAC;AAgCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,yBAAyB,CAAC,CAAC;AAC3D,CAAC;AA0BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,iBAAiB,CAAC,CAAC;AACnD,CAAC;AAoCD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,uBAAuB,CAAC,CAAC;AACzD,CAAC;AA0BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,mBAAmB,CAAC,CAAC;AACrD,CAAC;AA4BD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,yBAAyB,CAAC,CAAC;AAC3D,CAAC;AAoBD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,uBAAuB,CAAC,CAAC;AACzD,CAAC;AAiBD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,yBAAyB,CAAC,CAAC;AAC3D,CAAC;AA0BD,gBAAgB;AAChB;IAIE,IAAA,6DAA6B,EAAC,6BAA6B,CAAC,CAAC;AAC/D,CAAC;AAmBD,gBAAgB;AAChB;IAGE,IAAA,6DAA6B,EAAC,+BAA+B,CAAC,CAAC;AACjE,CAAC;AAiBD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,uBAAuB,CAAC,CAAC;AACzD,CAAC;AAiBD,gBAAgB;AAChB;IACE,IAAA,6DAA6B,EAAC,yBAAyB,CAAC,CAAC;AAC3D,CAAC;AA0BD,gBAAgB;AAChB;IAIE,IAAA,6DAA6B,EAAC,6BAA6B,CAAC,CAAC;AAC/D,CAAC;AAmBD,gBAAgB;AAChB;IAGE,IAAA,6DAA6B,EAAC,+BAA+B,CAAC,CAAC;AACjE,CAAC"}
|
package/lib/protobuf.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protobuf.mjs","names":[],"sources":["../src/protobuf.ts"],"sourcesContent":["import { IValidation, Resolved } from \"@typia/interface\";\n\nimport { TypeGuardError } from \"./TypeGuardError\";\nimport { NoTransformConfigurationError } from \"./transformers/NoTransformConfigurationError\";\n\n/* ===========================================================\n PROTOCOL BUFFER\n - MESSAGE\n - DECODE\n - ENCODE\n - FACTORY FUNCTIONS\n==============================================================\n SCHEMA\n----------------------------------------------------------- */\n/**\n * Generates Protocol Buffer message schema.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function message(): never;\n\n/**\n * Generates Protocol Buffer message schema for type `T`.\n *\n * Creates a `.proto` message definition string from a TypeScript type. Use for\n * sharing schemas with other languages/frameworks.\n *\n * Protocol Buffer has limited expressiveness compared to TypeScript.\n * Incompatible types cause compilation errors.\n *\n * @template T Target type\n * @returns Protocol Buffer message schema string\n * @see https://typia.io/docs/protobuf/message/#restrictions\n */\nexport function message<T>(): string;\n\n/** @internal */\nexport function message(): never {\n NoTransformConfigurationError(\"protobuf.message\");\n}\n\n/* -----------------------------------------------------------\n DECODE\n----------------------------------------------------------- */\n/**\n * Decodes Protocol Buffer binary.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function decode(input: Uint8Array): never;\n\n/**\n * Decodes Protocol Buffer binary to type `T`.\n *\n * Converts Protocol Buffer binary data to a TypeScript instance. Binary data\n * must have been encoded from a `T`-typed value—invalid data causes undefined\n * behavior or errors.\n *\n * For type safety, ensure data was encoded via:\n *\n * - {@link assertEncode} — Encodes with type assertion\n * - {@link isEncode} — Encodes with type checking\n * - {@link validateEncode} — Encodes with validation\n *\n * Note: Decoder validation ({@link assertDecode}, etc.) only checks custom tags\n * like `number & Minimum<7>`, not structural type safety.\n *\n * @template T Target type\n * @param input Protocol Buffer binary data\n * @returns Decoded value of type `T`\n */\nexport function decode<T>(input: Uint8Array): Resolved<T>;\n\n/** @internal */\nexport function decode(): never {\n NoTransformConfigurationError(\"protobuf.decode\");\n}\n\n/**\n * Decodes Protocol Buffer binary with assertion.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function assertDecode(\n input: Uint8Array,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Decodes Protocol Buffer binary with assertion (partial safety).\n *\n * Combines {@link decode} with {@link assert}. Throws {@link TypeGuardError} on\n * validation failure.\n *\n * Warning: Only validates custom tags (e.g., `number & Minimum<7>`, `string &\n * Format<\"uuid\">`), not structural type correctness. Ensure source data was\n * encoded with type-safe encoders.\n *\n * Related functions:\n *\n * - {@link decode} — No validation\n * - {@link isDecode} — Returns `null` instead of throwing\n * - {@link validateDecode} — Returns detailed validation errors\n *\n * @template T Target type\n * @param input Protocol Buffer binary data\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Decoded value of type `T`\n * @throws {TypeGuardError} When custom tag validation fails\n */\nexport function assertDecode<T>(\n input: Uint8Array,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): Resolved<T>;\n\n/** @internal */\nexport function assertDecode(): never {\n NoTransformConfigurationError(\"protobuf.assertDecode\");\n}\n\n/**\n * Decodes Protocol Buffer binary with type checking.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function isDecode(input: Uint8Array): never;\n\n/**\n * Decodes Protocol Buffer binary with type checking (partial safety).\n *\n * Combines {@link decode} with {@link is}. Returns `null` on validation failure.\n *\n * Warning: Only validates custom tags (e.g., `number & Minimum<7>`, `string &\n * Format<\"uuid\">`), not structural type correctness. Ensure source data was\n * encoded with type-safe encoders.\n *\n * Related functions:\n *\n * - {@link decode} — No validation\n * - {@link assertDecode} — Throws instead of returning `null`\n * - {@link validateDecode} — Returns detailed validation errors\n *\n * @template T Target type\n * @param input Protocol Buffer binary data\n * @returns Decoded value of type `T`, or `null` if invalid\n */\nexport function isDecode<T>(input: Uint8Array): Resolved<T> | null;\n\n/** @internal */\nexport function isDecode(): never {\n NoTransformConfigurationError(\"protobuf.isDecode\");\n}\n\n/**\n * Decodes Protocol Buffer binary with validation.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function validateDecode(input: Uint8Array): never;\n\n/**\n * Decodes Protocol Buffer binary with validation (partial safety).\n *\n * Combines {@link decode} with {@link validate}. Returns\n * {@link IValidation.IFailure} with errors on mismatch, or\n * {@link IValidation.ISuccess} with decoded value.\n *\n * Warning: Only validates custom tags (e.g., `number & Minimum<7>`, `string &\n * Format<\"uuid\">`), not structural type correctness. Ensure source data was\n * encoded with type-safe encoders.\n *\n * Related functions:\n *\n * - {@link decode} — No validation\n * - {@link assertDecode} — Throws on first error\n * - {@link isDecode} — Returns `null` instead of error details\n *\n * @template T Target type\n * @param input Protocol Buffer binary data\n * @returns Validation result containing decoded value or errors\n */\nexport function validateDecode<T>(input: Uint8Array): IValidation<Resolved<T>>;\n\n/** @internal */\nexport function validateDecode(): never {\n NoTransformConfigurationError(\"protobuf.validateDecode\");\n}\n\n/* -----------------------------------------------------------\n ENCODE\n----------------------------------------------------------- */\n/**\n * Encodes value to Protocol Buffer binary.\n *\n * Converts a TypeScript value to Protocol Buffer binary format.\n *\n * Does not validate the input. For validation, use:\n *\n * - {@link assertEncode} — Throws on type mismatch\n * - {@link isEncode} — Returns `null` on type mismatch\n * - {@link validateEncode} — Returns detailed validation errors\n *\n * Protocol Buffer has limited expressiveness compared to TypeScript.\n * Incompatible types cause compilation errors.\n *\n * @template T Type of input value\n * @param input Value to encode\n * @returns Protocol Buffer binary data\n * @see https://typia.io/docs/protobuf/message/#restrictions\n */\nexport function encode<T>(input: T): Uint8Array;\n\n/** @internal */\nexport function encode(): never {\n NoTransformConfigurationError(\"protobuf.encode\");\n}\n\n/**\n * Encodes value to Protocol Buffer binary with assertion.\n *\n * Combines {@link assert} with {@link encode}. Throws {@link TypeGuardError} on\n * type mismatch.\n *\n * Related functions:\n *\n * - {@link encode} — No validation\n * - {@link isEncode} — Returns `null` instead of throwing\n * - {@link validateEncode} — Returns detailed validation errors\n *\n * Protocol Buffer has limited expressiveness compared to TypeScript.\n * Incompatible types cause compilation errors.\n *\n * @template T Type of input value\n * @param input Value to encode\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Protocol Buffer binary data\n * @throws {TypeGuardError} When input doesn't conform to type `T`\n * @see https://typia.io/docs/protobuf/message/#restrictions\n */\nexport function assertEncode<T>(\n input: T,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): Uint8Array;\n\n/** @internal */\nexport function assertEncode<T>(\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): Uint8Array;\n\n/** @internal */\nexport function assertEncode(): never {\n NoTransformConfigurationError(\"protobuf.assertEncode\");\n}\n\n/**\n * Encodes value to Protocol Buffer binary with type checking.\n *\n * Combines {@link is} with {@link encode}. Returns `null` on type mismatch.\n *\n * Related functions:\n *\n * - {@link encode} — No validation\n * - {@link assertEncode} — Throws instead of returning `null`\n * - {@link validateEncode} — Returns detailed validation errors\n *\n * Protocol Buffer has limited expressiveness compared to TypeScript.\n * Incompatible types cause compilation errors.\n *\n * @template T Type of input value\n * @param input Value to encode\n * @returns Protocol Buffer binary data, or `null` if invalid\n * @see https://typia.io/docs/protobuf/message/#restrictions\n */\nexport function isEncode<T>(input: T): Uint8Array | null;\n\n/** @internal */\nexport function isEncode<T>(input: unknown): Uint8Array | null;\n\n/** @internal */\nexport function isEncode(): never {\n NoTransformConfigurationError(\"protobuf.isEncode\");\n}\n\n/**\n * Encodes value to Protocol Buffer binary with validation.\n *\n * Combines {@link validate} with {@link encode}. Returns\n * {@link IValidation.IFailure} with all errors on mismatch, or\n * {@link IValidation.ISuccess} with binary data.\n *\n * Related functions:\n *\n * - {@link encode} — No validation\n * - {@link assertEncode} — Throws on first error\n * - {@link isEncode} — Returns `null` instead of error details\n *\n * Protocol Buffer has limited expressiveness compared to TypeScript.\n * Incompatible types cause compilation errors.\n *\n * @template T Type of input value\n * @param input Value to encode\n * @returns Validation result containing binary data or errors\n * @see https://typia.io/docs/protobuf/message/#restrictions\n */\nexport function validateEncode<T>(input: T): IValidation<Uint8Array>;\n\n/** @internal */\nexport function validateEncode<T>(input: unknown): IValidation<Uint8Array>;\n\n/** @internal */\nexport function validateEncode(): never {\n NoTransformConfigurationError(\"protobuf.validateEncode\");\n}\n\n/* -----------------------------------------------------------\n FACTORY FUNCTIONS\n----------------------------------------------------------- */\n/**\n * Creates reusable {@link decode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createDecode(): never;\n\n/**\n * Creates reusable {@link decode} function.\n *\n * @template T Target type\n * @returns Reusable decoder function\n */\nexport function createDecode<T>(): (input: Uint8Array) => Resolved<T>;\n\n/** @internal */\nexport function createDecode<T>(): (input: Uint8Array) => Resolved<T> {\n NoTransformConfigurationError(\"protobuf.createDecode\");\n}\n\n/**\n * Creates reusable {@link isDecode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createIsDecode(): never;\n\n/**\n * Creates reusable {@link isDecode} function.\n *\n * @template T Target type\n * @returns Reusable decoder function\n */\nexport function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null;\n\n/** @internal */\nexport function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null {\n NoTransformConfigurationError(\"protobuf.createIsDecode\");\n}\n\n/**\n * Creates reusable {@link assertDecode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createAssertDecode(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Creates reusable {@link assertDecode} function.\n *\n * @template T Target type\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Reusable decoder function\n */\nexport function createAssertDecode<T>(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): (input: Uint8Array) => Resolved<T>;\n\n/** @internal */\nexport function createAssertDecode<T>(): (input: Uint8Array) => Resolved<T> {\n NoTransformConfigurationError(\"protobuf.createAssertDecode\");\n}\n\n/**\n * Creates reusable {@link validateDecode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createValidateDecode(): never;\n\n/**\n * Creates reusable {@link validateDecode} function.\n *\n * @template T Target type\n * @returns Reusable decoder function\n */\nexport function createValidateDecode<T>(): (\n input: Uint8Array,\n) => IValidation<Resolved<T>>;\n\n/** @internal */\nexport function createValidateDecode<T>(): (\n input: Uint8Array,\n) => IValidation<Resolved<T>> {\n NoTransformConfigurationError(\"protobuf.createValidateDecode\");\n}\n\n/**\n * Creates reusable {@link encode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createEncode(): never;\n\n/**\n * Creates reusable {@link encode} function.\n *\n * @template T Type of input value\n * @returns Reusable encoder function\n */\nexport function createEncode<T>(): (input: T) => Uint8Array;\n\n/** @internal */\nexport function createEncode<T>(): (input: T) => Uint8Array {\n NoTransformConfigurationError(\"protobuf.createEncode\");\n}\n\n/**\n * Creates reusable {@link isEncode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createIsEncode(): never;\n\n/**\n * Creates reusable {@link isEncode} function.\n *\n * @template T Type of input value\n * @returns Reusable encoder function\n */\nexport function createIsEncode<T>(): (input: T) => Uint8Array | null;\n\n/** @internal */\nexport function createIsEncode<T>(): (input: T) => Uint8Array | null {\n NoTransformConfigurationError(\"protobuf.createIsEncode\");\n}\n\n/**\n * Creates reusable {@link assertEncode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createAssertEncode(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Creates reusable {@link assertEncode} function.\n *\n * @template T Type of input value\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Reusable encoder function\n */\nexport function createAssertEncode<T>(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): (input: T) => Uint8Array;\n\n/** @internal */\nexport function createAssertEncode<T>(): (input: T) => Uint8Array {\n NoTransformConfigurationError(\"protobuf.createAssertEncode\");\n}\n\n/**\n * Creates reusable {@link validateEncode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createValidateEncode(): never;\n\n/**\n * Creates reusable {@link validateEncode} function.\n *\n * @template T Type of input value\n * @returns Reusable encoder function\n */\nexport function createValidateEncode<T>(): (\n input: T,\n) => IValidation<Uint8Array>;\n\n/** @internal */\nexport function createValidateEncode<T>(): (\n input: T,\n) => IValidation<Uint8Array> {\n NoTransformConfigurationError(\"protobuf.createValidateEncode\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,UAAiB;CAC/B,8BAA8B,kBAAkB;AAClD;;AAmCA,SAAgB,SAAgB;CAC9B,8BAA8B,iBAAiB;AACjD;;AAyCA,SAAgB,eAAsB;CACpC,8BAA8B,uBAAuB;AACvD;;AA+BA,SAAgB,WAAkB;CAChC,8BAA8B,mBAAmB;AACnD;;AAiCA,SAAgB,iBAAwB;CACtC,8BAA8B,yBAAyB;AACzD;;AA2BA,SAAgB,SAAgB;CAC9B,8BAA8B,iBAAiB;AACjD;;AAqCA,SAAgB,eAAsB;CACpC,8BAA8B,uBAAuB;AACvD;;AA2BA,SAAgB,WAAkB;CAChC,8BAA8B,mBAAmB;AACnD;;AA6BA,SAAgB,iBAAwB;CACtC,8BAA8B,yBAAyB;AACzD;;AAqBA,SAAgB,eAAsD;CACpE,8BAA8B,uBAAuB;AACvD;;AAkBA,SAAgB,iBAA+D;CAC7E,8BAA8B,yBAAyB;AACzD;;AAwBA,SAAgB,qBAA4D;CAC1E,8BAA8B,6BAA6B;AAC7D;;AAoBA,SAAgB,uBAEc;CAC5B,8BAA8B,+BAA+B;AAC/D;;AAkBA,SAAgB,eAA4C;CAC1D,8BAA8B,uBAAuB;AACvD;;AAkBA,SAAgB,iBAAqD;CACnE,8BAA8B,yBAAyB;AACzD;;AAwBA,SAAgB,qBAAkD;CAChE,8BAA8B,6BAA6B;AAC7D;;AAoBA,SAAgB,uBAEa;CAC3B,8BAA8B,+BAA+B;AAC/D"}
|
|
1
|
+
{"version":3,"file":"protobuf.mjs","names":[],"sources":["../src/protobuf.ts"],"sourcesContent":["import { IValidation, Resolved } from \"@typia/interface\";\n\nimport { TypeGuardError } from \"./TypeGuardError\";\nimport { NoTransformConfigurationError } from \"./transformers/NoTransformConfigurationError\";\n\n/* ===========================================================\n PROTOCOL BUFFER\n - MESSAGE\n - DECODE\n - ENCODE\n - FACTORY FUNCTIONS\n==============================================================\n SCHEMA\n----------------------------------------------------------- */\n/**\n * Generates Protocol Buffer message schema.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function message(): never;\n\n/**\n * Generates Protocol Buffer message schema for type `T`.\n *\n * Creates a `.proto` message definition string from a TypeScript type. Use for\n * sharing schemas with other languages/frameworks.\n *\n * Protocol Buffer has limited expressiveness compared to TypeScript.\n * Incompatible types cause compilation errors.\n *\n * @template T Target type\n * @returns Protocol Buffer message schema string\n * @see https://typia.io/docs/protobuf/message/#restrictions\n */\nexport function message<T>(): string;\n\n/** @internal */\nexport function message(): never {\n NoTransformConfigurationError(\"protobuf.message\");\n}\n\n/* -----------------------------------------------------------\n DECODE\n----------------------------------------------------------- */\n/**\n * Decodes Protocol Buffer binary.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function decode(input: Uint8Array): never;\n\n/**\n * Decodes Protocol Buffer binary to type `T`.\n *\n * Converts Protocol Buffer binary data to a TypeScript instance. Binary data\n * must have been encoded from a `T`-typed value—invalid data causes undefined\n * behavior or errors.\n *\n * For type safety, ensure data was encoded via:\n *\n * - {@link assertEncode} — Encodes with type assertion\n * - {@link isEncode} — Encodes with type checking\n * - {@link validateEncode} — Encodes with validation\n *\n * Note: Decoder validation ({@link assertDecode}, etc.) only checks custom tags\n * like `number & Minimum<7>`, not structural type safety.\n *\n * @template T Target type\n * @param input Protocol Buffer binary data\n * @returns Decoded value of type `T`\n */\nexport function decode<T>(input: Uint8Array): Resolved<T>;\n\n/** @internal */\nexport function decode(): never {\n NoTransformConfigurationError(\"protobuf.decode\");\n}\n\n/**\n * Decodes Protocol Buffer binary with assertion.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function assertDecode(\n input: Uint8Array,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Decodes Protocol Buffer binary with assertion (partial safety).\n *\n * Combines {@link decode} with {@link assert}. Throws {@link TypeGuardError} on\n * validation failure.\n *\n * Warning: Only validates custom tags (e.g., `number & Minimum<7>`, `string &\n * Format<\"uuid\">`), not structural type correctness. Ensure source data was\n * encoded with type-safe encoders.\n *\n * Related functions:\n *\n * - {@link decode} — No validation\n * - {@link isDecode} — Returns `null` instead of throwing\n * - {@link validateDecode} — Returns detailed validation errors\n *\n * @template T Target type\n * @param input Protocol Buffer binary data\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Decoded value of type `T`\n * @throws {TypeGuardError} When custom tag validation fails\n */\nexport function assertDecode<T>(\n input: Uint8Array,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): Resolved<T>;\n\n/** @internal */\nexport function assertDecode(): never {\n NoTransformConfigurationError(\"protobuf.assertDecode\");\n}\n\n/**\n * Decodes Protocol Buffer binary with type checking.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function isDecode(input: Uint8Array): never;\n\n/**\n * Decodes Protocol Buffer binary with type checking (partial safety).\n *\n * Combines {@link decode} with {@link is}. Returns `null` on validation failure.\n *\n * Warning: Only validates custom tags (e.g., `number & Minimum<7>`, `string &\n * Format<\"uuid\">`), not structural type correctness. Ensure source data was\n * encoded with type-safe encoders.\n *\n * Related functions:\n *\n * - {@link decode} — No validation\n * - {@link assertDecode} — Throws instead of returning `null`\n * - {@link validateDecode} — Returns detailed validation errors\n *\n * @template T Target type\n * @param input Protocol Buffer binary data\n * @returns Decoded value of type `T`, or `null` if invalid\n */\nexport function isDecode<T>(input: Uint8Array): Resolved<T> | null;\n\n/** @internal */\nexport function isDecode(): never {\n NoTransformConfigurationError(\"protobuf.isDecode\");\n}\n\n/**\n * Decodes Protocol Buffer binary with validation.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function validateDecode(input: Uint8Array): never;\n\n/**\n * Decodes Protocol Buffer binary with validation (partial safety).\n *\n * Combines {@link decode} with {@link validate}. Returns\n * {@link IValidation.IFailure} with errors on mismatch, or\n * {@link IValidation.ISuccess} with decoded value.\n *\n * Warning: Only validates custom tags (e.g., `number & Minimum<7>`, `string &\n * Format<\"uuid\">`), not structural type correctness. Ensure source data was\n * encoded with type-safe encoders.\n *\n * Related functions:\n *\n * - {@link decode} — No validation\n * - {@link assertDecode} — Throws on first error\n * - {@link isDecode} — Returns `null` instead of error details\n *\n * @template T Target type\n * @param input Protocol Buffer binary data\n * @returns Validation result containing decoded value or errors\n */\nexport function validateDecode<T>(input: Uint8Array): IValidation<Resolved<T>>;\n\n/** @internal */\nexport function validateDecode(): never {\n NoTransformConfigurationError(\"protobuf.validateDecode\");\n}\n\n/* -----------------------------------------------------------\n ENCODE\n----------------------------------------------------------- */\n/**\n * Encodes value to Protocol Buffer binary.\n *\n * Converts a TypeScript value to Protocol Buffer binary format.\n *\n * Does not validate the input. For validation, use:\n *\n * - {@link assertEncode} — Throws on type mismatch\n * - {@link isEncode} — Returns `null` on type mismatch\n * - {@link validateEncode} — Returns detailed validation errors\n *\n * Protocol Buffer has limited expressiveness compared to TypeScript.\n * Incompatible types cause compilation errors.\n *\n * @template T Type of input value\n * @param input Value to encode\n * @returns Protocol Buffer binary data\n * @see https://typia.io/docs/protobuf/message/#restrictions\n */\nexport function encode<T>(input: T): Uint8Array;\n\n/** @internal */\nexport function encode(): never {\n NoTransformConfigurationError(\"protobuf.encode\");\n}\n\n/**\n * Encodes value to Protocol Buffer binary with assertion.\n *\n * Combines {@link assert} with {@link encode}. Throws {@link TypeGuardError} on\n * type mismatch.\n *\n * Related functions:\n *\n * - {@link encode} — No validation\n * - {@link isEncode} — Returns `null` instead of throwing\n * - {@link validateEncode} — Returns detailed validation errors\n *\n * Protocol Buffer has limited expressiveness compared to TypeScript.\n * Incompatible types cause compilation errors.\n *\n * @template T Type of input value\n * @param input Value to encode\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Protocol Buffer binary data\n * @throws {TypeGuardError} When input doesn't conform to type `T`\n * @see https://typia.io/docs/protobuf/message/#restrictions\n */\nexport function assertEncode<T>(\n input: T,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): Uint8Array;\n\n/** @internal */\nexport function assertEncode<T>(\n input: unknown,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): Uint8Array;\n\n/** @internal */\nexport function assertEncode(): never {\n NoTransformConfigurationError(\"protobuf.assertEncode\");\n}\n\n/**\n * Encodes value to Protocol Buffer binary with type checking.\n *\n * Combines {@link is} with {@link encode}. Returns `null` on type mismatch.\n *\n * Related functions:\n *\n * - {@link encode} — No validation\n * - {@link assertEncode} — Throws instead of returning `null`\n * - {@link validateEncode} — Returns detailed validation errors\n *\n * Protocol Buffer has limited expressiveness compared to TypeScript.\n * Incompatible types cause compilation errors.\n *\n * @template T Type of input value\n * @param input Value to encode\n * @returns Protocol Buffer binary data, or `null` if invalid\n * @see https://typia.io/docs/protobuf/message/#restrictions\n */\nexport function isEncode<T>(input: T): Uint8Array | null;\n\n/** @internal */\nexport function isEncode<T>(input: unknown): Uint8Array | null;\n\n/** @internal */\nexport function isEncode(): never {\n NoTransformConfigurationError(\"protobuf.isEncode\");\n}\n\n/**\n * Encodes value to Protocol Buffer binary with validation.\n *\n * Combines {@link validate} with {@link encode}. Returns\n * {@link IValidation.IFailure} with all errors on mismatch, or\n * {@link IValidation.ISuccess} with binary data.\n *\n * Related functions:\n *\n * - {@link encode} — No validation\n * - {@link assertEncode} — Throws on first error\n * - {@link isEncode} — Returns `null` instead of error details\n *\n * Protocol Buffer has limited expressiveness compared to TypeScript.\n * Incompatible types cause compilation errors.\n *\n * @template T Type of input value\n * @param input Value to encode\n * @returns Validation result containing binary data or errors\n * @see https://typia.io/docs/protobuf/message/#restrictions\n */\nexport function validateEncode<T>(input: T): IValidation<Uint8Array>;\n\n/** @internal */\nexport function validateEncode<T>(input: unknown): IValidation<Uint8Array>;\n\n/** @internal */\nexport function validateEncode(): never {\n NoTransformConfigurationError(\"protobuf.validateEncode\");\n}\n\n/* -----------------------------------------------------------\n FACTORY FUNCTIONS\n----------------------------------------------------------- */\n/**\n * Creates reusable {@link decode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createDecode(): never;\n\n/**\n * Creates reusable {@link decode} function.\n *\n * @template T Target type\n * @returns Reusable decoder function\n */\nexport function createDecode<T>(): (input: Uint8Array) => Resolved<T>;\n\n/** @internal */\nexport function createDecode<T>(): (input: Uint8Array) => Resolved<T> {\n NoTransformConfigurationError(\"protobuf.createDecode\");\n}\n\n/**\n * Creates reusable {@link isDecode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createIsDecode(): never;\n\n/**\n * Creates reusable {@link isDecode} function.\n *\n * @template T Target type\n * @returns Reusable decoder function\n */\nexport function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null;\n\n/** @internal */\nexport function createIsDecode<T>(): (input: Uint8Array) => Resolved<T> | null {\n NoTransformConfigurationError(\"protobuf.createIsDecode\");\n}\n\n/**\n * Creates reusable {@link assertDecode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createAssertDecode(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Creates reusable {@link assertDecode} function.\n *\n * @template T Target type\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Reusable decoder function\n */\nexport function createAssertDecode<T>(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): (\n input: Uint8Array,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n) => Resolved<T>;\n\n/** @internal */\nexport function createAssertDecode<T>(): (\n input: Uint8Array,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n) => Resolved<T> {\n NoTransformConfigurationError(\"protobuf.createAssertDecode\");\n}\n\n/**\n * Creates reusable {@link validateDecode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createValidateDecode(): never;\n\n/**\n * Creates reusable {@link validateDecode} function.\n *\n * @template T Target type\n * @returns Reusable decoder function\n */\nexport function createValidateDecode<T>(): (\n input: Uint8Array,\n) => IValidation<Resolved<T>>;\n\n/** @internal */\nexport function createValidateDecode<T>(): (\n input: Uint8Array,\n) => IValidation<Resolved<T>> {\n NoTransformConfigurationError(\"protobuf.createValidateDecode\");\n}\n\n/**\n * Creates reusable {@link encode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createEncode(): never;\n\n/**\n * Creates reusable {@link encode} function.\n *\n * @template T Type of input value\n * @returns Reusable encoder function\n */\nexport function createEncode<T>(): (input: T) => Uint8Array;\n\n/** @internal */\nexport function createEncode<T>(): (input: T) => Uint8Array {\n NoTransformConfigurationError(\"protobuf.createEncode\");\n}\n\n/**\n * Creates reusable {@link isEncode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createIsEncode(): never;\n\n/**\n * Creates reusable {@link isEncode} function.\n *\n * @template T Type of input value\n * @returns Reusable encoder function\n */\nexport function createIsEncode<T>(): (input: T) => Uint8Array | null;\n\n/** @internal */\nexport function createIsEncode<T>(): (input: T) => Uint8Array | null {\n NoTransformConfigurationError(\"protobuf.createIsEncode\");\n}\n\n/**\n * Creates reusable {@link assertEncode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createAssertEncode(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): never;\n\n/**\n * Creates reusable {@link assertEncode} function.\n *\n * @template T Type of input value\n * @param errorFactory Custom error factory receiving\n * {@link TypeGuardError.IProps}\n * @returns Reusable encoder function\n */\nexport function createAssertEncode<T>(\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n): (\n input: T,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n) => Uint8Array;\n\n/** @internal */\nexport function createAssertEncode<T>(): (\n input: T,\n errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),\n) => Uint8Array {\n NoTransformConfigurationError(\"protobuf.createAssertEncode\");\n}\n\n/**\n * Creates reusable {@link validateEncode} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createValidateEncode(): never;\n\n/**\n * Creates reusable {@link validateEncode} function.\n *\n * @template T Type of input value\n * @returns Reusable encoder function\n */\nexport function createValidateEncode<T>(): (\n input: T,\n) => IValidation<Uint8Array>;\n\n/** @internal */\nexport function createValidateEncode<T>(): (\n input: T,\n) => IValidation<Uint8Array> {\n NoTransformConfigurationError(\"protobuf.createValidateEncode\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,UAAiB;CAC/B,8BAA8B,kBAAkB;AAClD;;AAmCA,SAAgB,SAAgB;CAC9B,8BAA8B,iBAAiB;AACjD;;AAyCA,SAAgB,eAAsB;CACpC,8BAA8B,uBAAuB;AACvD;;AA+BA,SAAgB,WAAkB;CAChC,8BAA8B,mBAAmB;AACnD;;AAiCA,SAAgB,iBAAwB;CACtC,8BAA8B,yBAAyB;AACzD;;AA2BA,SAAgB,SAAgB;CAC9B,8BAA8B,iBAAiB;AACjD;;AAqCA,SAAgB,eAAsB;CACpC,8BAA8B,uBAAuB;AACvD;;AA2BA,SAAgB,WAAkB;CAChC,8BAA8B,mBAAmB;AACnD;;AA6BA,SAAgB,iBAAwB;CACtC,8BAA8B,yBAAyB;AACzD;;AAqBA,SAAgB,eAAsD;CACpE,8BAA8B,uBAAuB;AACvD;;AAkBA,SAAgB,iBAA+D;CAC7E,8BAA8B,yBAAyB;AACzD;;AA2BA,SAAgB,qBAGC;CACf,8BAA8B,6BAA6B;AAC7D;;AAoBA,SAAgB,uBAEc;CAC5B,8BAA8B,+BAA+B;AAC/D;;AAkBA,SAAgB,eAA4C;CAC1D,8BAA8B,uBAAuB;AACvD;;AAkBA,SAAgB,iBAAqD;CACnE,8BAA8B,yBAAyB;AACzD;;AA2BA,SAAgB,qBAGA;CACd,8BAA8B,6BAA6B;AAC7D;;AAoBA,SAAgB,uBAEa;CAC3B,8BAA8B,+BAA+B;AAC/D"}
|
|
@@ -15,7 +15,9 @@ import (
|
|
|
15
15
|
//
|
|
16
16
|
// An assertion-guard factory returns the guard itself. Its successful invocation
|
|
17
17
|
// returns void while narrowing the input; it never returns another callable
|
|
18
|
-
// assertion guard.
|
|
18
|
+
// assertion guard. The guard carries the optional call-time `errorFactory` the
|
|
19
|
+
// emit really gives it, and stays assignable to the documented
|
|
20
|
+
// `AssertionGuard<T>` annotation.
|
|
19
21
|
//
|
|
20
22
|
// 1. Compile normal and equals factories with explicit and inferred types.
|
|
21
23
|
// 2. Prove successful invocations narrow and have a void return type.
|
|
@@ -108,16 +110,27 @@ export const inferredEquals = typia.createAssertGuardEquals<User>();
|
|
|
108
110
|
|
|
109
111
|
let input: unknown = { id: 1 };
|
|
110
112
|
const returned = guard(input);
|
|
111
|
-
|
|
113
|
+
|
|
114
|
+
// Narrowing is asserted inside a function body: TypeScript does not apply an
|
|
115
|
+
// assertion signature to a module-scoped binding, so the same lines at the top
|
|
116
|
+
// level leave the value unknown.
|
|
117
|
+
export const narrowing = (value: unknown): number => {
|
|
118
|
+
guard(value);
|
|
119
|
+
return value.id;
|
|
120
|
+
};
|
|
112
121
|
|
|
113
122
|
type Equal<X, Y> =
|
|
114
123
|
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
|
|
115
124
|
? true
|
|
116
125
|
: false;
|
|
117
126
|
type Assert<T extends true> = T;
|
|
127
|
+
type Guard = (
|
|
128
|
+
input: unknown,
|
|
129
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
130
|
+
) => asserts input is User;
|
|
118
131
|
export type FactoryCases = [
|
|
119
|
-
Assert<Equal<typeof inferred,
|
|
120
|
-
Assert<Equal<typeof inferredEquals,
|
|
132
|
+
Assert<Equal<typeof inferred, Guard>>,
|
|
133
|
+
Assert<Equal<typeof inferredEquals, Guard>>,
|
|
121
134
|
Assert<Equal<typeof returned, void>>,
|
|
122
135
|
];
|
|
123
136
|
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"os"
|
|
5
|
+
"os/exec"
|
|
6
|
+
"path/filepath"
|
|
7
|
+
"strings"
|
|
8
|
+
"testing"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
// TestCreateAssertErrorFactoryArity verifies that the declared arity of created
|
|
12
|
+
// assert functions agrees with the emitted one (#2328).
|
|
13
|
+
//
|
|
14
|
+
// Every `create*Assert*` factory emits `(input, errorFactory = <create-time
|
|
15
|
+
// factory>) => ...`, but the declarations returned `(input) => T`. A pointwise
|
|
16
|
+
// hand-off such as `rows.map(parseUser)` therefore type-checked while
|
|
17
|
+
// `Array#map` handed the element index to `errorFactory`. The declared surface
|
|
18
|
+
// has to name that parameter, without breaking the documented
|
|
19
|
+
// `AssertionGuard<T>` annotation or an ordinary one-parameter callback
|
|
20
|
+
// position.
|
|
21
|
+
//
|
|
22
|
+
// 1. Type-check a fixture that overrides `errorFactory` at call time on every
|
|
23
|
+
// member of the family, and that pins the `.map` hand-off as an error while
|
|
24
|
+
// the adjacent one-parameter controls still compile.
|
|
25
|
+
// 2. Transform that same fixture and require each member's emitted function to
|
|
26
|
+
// carry the parameter, with factories outside the family as the controls
|
|
27
|
+
// that must not.
|
|
28
|
+
// 3. Transform a runtime fixture, execute it, and require the call-time factory
|
|
29
|
+
// to build the error while a numeric second argument falls back to the
|
|
30
|
+
// ordinary type-guard error.
|
|
31
|
+
func TestCreateAssertErrorFactoryArity(t *testing.T) {
|
|
32
|
+
surface := compareEqualCoverProject(t, "create-assert-error-factory-", createAssertErrorFactorySurfaceSource)
|
|
33
|
+
ttscTypiaTestTypecheck(t, surface)
|
|
34
|
+
createAssertErrorFactoryAssertEmittedArity(t, compareEqualCoverTransform(t, surface))
|
|
35
|
+
|
|
36
|
+
project := compareEqualCoverProject(t, "create-assert-error-factory-runtime-", createAssertErrorFactoryRuntimeSource)
|
|
37
|
+
ttscTypiaTestTypecheck(t, project)
|
|
38
|
+
js := compareEqualCoverTransform(t, project)
|
|
39
|
+
if !strings.Contains(js, "(input, errorFactory)") {
|
|
40
|
+
t.Fatalf("emitted factory lost its errorFactory parameter:\n%s", js)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
node, err := exec.LookPath("node")
|
|
44
|
+
if err != nil {
|
|
45
|
+
t.Skip("node executable not found")
|
|
46
|
+
}
|
|
47
|
+
runtimeDir := filepath.Join(project, "runtime")
|
|
48
|
+
if err := os.MkdirAll(runtimeDir, 0o755); err != nil {
|
|
49
|
+
t.Fatalf("mkdir runtime dir: %v", err)
|
|
50
|
+
}
|
|
51
|
+
ttscTypiaTestWriteCommonRuntimeStubs(t, runtimeDir)
|
|
52
|
+
if err := os.WriteFile(filepath.Join(runtimeDir, "main.cjs"), []byte(ttscTypiaTestRewriteCommonJS(t, js)), 0o644); err != nil {
|
|
53
|
+
t.Fatalf("write runtime module: %v", err)
|
|
54
|
+
}
|
|
55
|
+
runner := filepath.Join(runtimeDir, "run.cjs")
|
|
56
|
+
if err := os.WriteFile(runner, []byte(createAssertErrorFactoryRuntimeRunner), 0o644); err != nil {
|
|
57
|
+
t.Fatalf("write runtime runner: %v", err)
|
|
58
|
+
}
|
|
59
|
+
cmd := exec.Command(node, runner)
|
|
60
|
+
cmd.Dir = runtimeDir
|
|
61
|
+
if output, err := cmd.CombinedOutput(); err != nil {
|
|
62
|
+
t.Fatalf("created assert error factory runtime cases failed: %v\n%s", err, output)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// createAssertErrorFactoryAssertEmittedArity requires each member of the family
|
|
67
|
+
// to emit the parameter its declaration now names, and each control not to.
|
|
68
|
+
//
|
|
69
|
+
// The declaration and the emit are written on opposite sides of the codebase,
|
|
70
|
+
// so a declaration test alone can over-promise: dropping `Guardian.Parameter`
|
|
71
|
+
// from one programmer would leave the type claiming a parameter the function no
|
|
72
|
+
// longer takes. The emitted body of each member is what settles it.
|
|
73
|
+
func createAssertErrorFactoryAssertEmittedArity(t *testing.T, js string) {
|
|
74
|
+
t.Helper()
|
|
75
|
+
starts := make([]int, len(createAssertErrorFactoryMembers))
|
|
76
|
+
for i, name := range createAssertErrorFactoryMembers {
|
|
77
|
+
// The CommonJS prologue lists every export on one `void 0` line, so the
|
|
78
|
+
// real assignment is the last occurrence, never the first.
|
|
79
|
+
index := strings.LastIndex(js, "exports."+name+" = ")
|
|
80
|
+
if index < 0 {
|
|
81
|
+
t.Fatalf("emit has no assignment for %s:\n%s", name, js)
|
|
82
|
+
}
|
|
83
|
+
starts[i] = index
|
|
84
|
+
}
|
|
85
|
+
for i, name := range createAssertErrorFactoryMembers {
|
|
86
|
+
end := strings.LastIndex(js, "exports."+createAssertErrorFactorySentinel+" = ")
|
|
87
|
+
if i+1 < len(createAssertErrorFactoryMembers) {
|
|
88
|
+
end = starts[i+1]
|
|
89
|
+
}
|
|
90
|
+
if starts[i] >= end {
|
|
91
|
+
t.Fatalf("emitted members are out of source order at %s", name)
|
|
92
|
+
}
|
|
93
|
+
segment := js[starts[i]:end]
|
|
94
|
+
// The returned function is the public one. Every composed member also
|
|
95
|
+
// builds a private `__assert` that takes the parameter, so matching the
|
|
96
|
+
// parameter list anywhere in the segment would keep passing after the
|
|
97
|
+
// returned arrow lost it.
|
|
98
|
+
carries := strings.Contains(segment, "return (input, errorFactory)")
|
|
99
|
+
if strings.HasPrefix(name, "m") && carries == false {
|
|
100
|
+
t.Fatalf("%s lost its errorFactory parameter:\n%s", name, segment)
|
|
101
|
+
}
|
|
102
|
+
if strings.HasPrefix(name, "n") && strings.Contains(segment, "errorFactory") {
|
|
103
|
+
t.Fatalf("%s gained an errorFactory parameter it does not declare:\n%s", name, segment)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// createAssertErrorFactoryMembers lists the emitted fixture exports in source
|
|
109
|
+
// order: `m*` is the whole family whose emitted function takes `errorFactory`,
|
|
110
|
+
// `n*` are factories that must not grow one.
|
|
111
|
+
var createAssertErrorFactoryMembers = []string{
|
|
112
|
+
"m01", "m02", "m03", "m04", "m05", "m06", "m07", "m08", "m09",
|
|
113
|
+
"m10", "m11", "m12", "m13", "m14", "m15", "m16", "m17", "m18",
|
|
114
|
+
"n01", "n02", "n03",
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const createAssertErrorFactorySentinel = "zzz"
|
|
118
|
+
|
|
119
|
+
// createAssertErrorFactorySurfaceSource is type-checked and transformed, but
|
|
120
|
+
// never executed: the http, protobuf and notation members pull runtime helpers
|
|
121
|
+
// this package stubs only for the emit it runs, so the executed fixture stays
|
|
122
|
+
// on the module family.
|
|
123
|
+
const createAssertErrorFactorySurfaceSource = `import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
124
|
+
import typia, { AssertionGuard, TypeGuardError } from "typia";
|
|
125
|
+
|
|
126
|
+
interface User {
|
|
127
|
+
id: number;
|
|
128
|
+
}
|
|
129
|
+
interface StringUser {
|
|
130
|
+
id: string;
|
|
131
|
+
}
|
|
132
|
+
interface SnakeUser {
|
|
133
|
+
user_id: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
type ErrorFactory = (props: TypeGuardError.IProps) => Error;
|
|
137
|
+
type UserGuard = (
|
|
138
|
+
input: unknown,
|
|
139
|
+
errorFactory?: undefined | ErrorFactory,
|
|
140
|
+
) => asserts input is User;
|
|
141
|
+
|
|
142
|
+
type Assert<T extends true> = T;
|
|
143
|
+
type Equal<X, Y> =
|
|
144
|
+
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
|
|
145
|
+
? true
|
|
146
|
+
: false;
|
|
147
|
+
|
|
148
|
+
const factory: ErrorFactory = (props) =>
|
|
149
|
+
Object.assign(new Error("call-time"), { path: props.path });
|
|
150
|
+
|
|
151
|
+
const assertUser = typia.createAssert<User>();
|
|
152
|
+
const assertUserEquals = typia.createAssertEquals<User>();
|
|
153
|
+
const guardUser = typia.createAssertGuard<User>();
|
|
154
|
+
const guardUserEquals = typia.createAssertGuardEquals<User>();
|
|
155
|
+
const jsonParse = typia.json.createAssertParse<User>();
|
|
156
|
+
const jsonStringify = typia.json.createAssertStringify<User>();
|
|
157
|
+
const httpFormData = typia.http.createAssertFormData<StringUser>();
|
|
158
|
+
const httpQuery = typia.http.createAssertQuery<StringUser>();
|
|
159
|
+
const httpHeaders = typia.http.createAssertHeaders<StringUser>();
|
|
160
|
+
const notationCamel = typia.notations.createAssertCamel<SnakeUser>();
|
|
161
|
+
const notationPascal = typia.notations.createAssertPascal<SnakeUser>();
|
|
162
|
+
const notationSnake = typia.notations.createAssertSnake<SnakeUser>();
|
|
163
|
+
const notationKebab = typia.notations.createAssertKebab<SnakeUser>();
|
|
164
|
+
const plainClone = typia.plain.createAssertClone<User>();
|
|
165
|
+
const plainPrune = typia.plain.createAssertPrune<User>();
|
|
166
|
+
const plainClassify = typia.plain.createAssertClassify<User>();
|
|
167
|
+
const protobufDecode = typia.protobuf.createAssertDecode<User>();
|
|
168
|
+
const protobufEncode = typia.protobuf.createAssertEncode<User>();
|
|
169
|
+
|
|
170
|
+
// typia's own declaration of the guard factories, not a local alias: the guard
|
|
171
|
+
// family is the one place where a user annotation could hide a reverted change.
|
|
172
|
+
export type GuardCases = [
|
|
173
|
+
Assert<Equal<typeof guardUser, UserGuard>>,
|
|
174
|
+
Assert<Equal<typeof guardUserEquals, UserGuard>>,
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
const annotatedGuard: UserGuard = guardUser;
|
|
178
|
+
const annotatedGuardEquals: UserGuard = guardUserEquals;
|
|
179
|
+
|
|
180
|
+
// Every call below is a compile-time assertion that the family member declares
|
|
181
|
+
// the call-time override the emit gives it.
|
|
182
|
+
export const overrides = (
|
|
183
|
+
raw: unknown,
|
|
184
|
+
text: string,
|
|
185
|
+
user: User,
|
|
186
|
+
snake: SnakeUser,
|
|
187
|
+
form: FormData,
|
|
188
|
+
headers: Record<string, string | string[] | undefined>,
|
|
189
|
+
bytes: Uint8Array,
|
|
190
|
+
): void => {
|
|
191
|
+
assertUser(raw, factory);
|
|
192
|
+
assertUserEquals(raw, factory);
|
|
193
|
+
annotatedGuard(raw, factory);
|
|
194
|
+
annotatedGuardEquals(raw, factory);
|
|
195
|
+
jsonParse(text, factory);
|
|
196
|
+
jsonStringify(user, factory);
|
|
197
|
+
httpFormData(form, factory);
|
|
198
|
+
httpQuery(text, factory);
|
|
199
|
+
httpHeaders(headers, factory);
|
|
200
|
+
notationCamel(snake, factory);
|
|
201
|
+
notationPascal(snake, factory);
|
|
202
|
+
notationSnake(snake, factory);
|
|
203
|
+
notationKebab(snake, factory);
|
|
204
|
+
plainClone(raw, factory);
|
|
205
|
+
plainPrune(raw, factory);
|
|
206
|
+
plainClassify(raw, factory);
|
|
207
|
+
protobufDecode(bytes, factory);
|
|
208
|
+
protobufEncode(user, factory);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// The narrowing contract of the guard family survives the extra parameter, and
|
|
212
|
+
// the documented one-parameter annotation still accepts the created guard.
|
|
213
|
+
export const documented: AssertionGuard<User> = typia.createAssertGuard<User>();
|
|
214
|
+
export const narrowed = (raw: unknown): number => {
|
|
215
|
+
annotatedGuard(raw);
|
|
216
|
+
return raw.id;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
declare const rows: unknown[];
|
|
220
|
+
|
|
221
|
+
// @ts-expect-error Array#map hands the element index to errorFactory.
|
|
222
|
+
export const mappedAssert = rows.map(assertUser);
|
|
223
|
+
// @ts-expect-error the guard family carries the same hazard.
|
|
224
|
+
export const mappedGuard = rows.map(guardUser);
|
|
225
|
+
|
|
226
|
+
// Adjacent one-axis controls that must keep compiling.
|
|
227
|
+
export const mappedExplicit = rows.map((row) => assertUser(row));
|
|
228
|
+
type Parser = (input: unknown) => User;
|
|
229
|
+
export const parser: Parser = assertUser;
|
|
230
|
+
declare function takesParser(parse: (input: unknown) => User): User;
|
|
231
|
+
export const parsed = takesParser(assertUser);
|
|
232
|
+
export const standard: StandardSchemaV1<User, User> = typia.createValidate<User>();
|
|
233
|
+
|
|
234
|
+
// The emitted-arity census. Order is load-bearing: the assertion slices the
|
|
235
|
+
// emit between consecutive assignments, and ` + "`zzz`" + ` closes the last one.
|
|
236
|
+
export const m01 = typia.createAssert<User>();
|
|
237
|
+
export const m02 = typia.createAssertEquals<User>();
|
|
238
|
+
export const m03 = typia.createAssertGuard<User>();
|
|
239
|
+
export const m04 = typia.createAssertGuardEquals<User>();
|
|
240
|
+
export const m05 = typia.json.createAssertParse<User>();
|
|
241
|
+
export const m06 = typia.json.createAssertStringify<User>();
|
|
242
|
+
export const m07 = typia.http.createAssertFormData<StringUser>();
|
|
243
|
+
export const m08 = typia.http.createAssertQuery<StringUser>();
|
|
244
|
+
export const m09 = typia.http.createAssertHeaders<StringUser>();
|
|
245
|
+
export const m10 = typia.notations.createAssertCamel<SnakeUser>();
|
|
246
|
+
export const m11 = typia.notations.createAssertPascal<SnakeUser>();
|
|
247
|
+
export const m12 = typia.notations.createAssertSnake<SnakeUser>();
|
|
248
|
+
export const m13 = typia.notations.createAssertKebab<SnakeUser>();
|
|
249
|
+
export const m14 = typia.plain.createAssertClone<User>();
|
|
250
|
+
export const m15 = typia.plain.createAssertPrune<User>();
|
|
251
|
+
export const m16 = typia.plain.createAssertClassify<User>();
|
|
252
|
+
export const m17 = typia.protobuf.createAssertDecode<User>();
|
|
253
|
+
export const m18 = typia.protobuf.createAssertEncode<User>();
|
|
254
|
+
export const n01 = typia.createIs<User>();
|
|
255
|
+
export const n02 = typia.json.createIsParse<User>();
|
|
256
|
+
export const n03 = typia.plain.createClone<User>();
|
|
257
|
+
export const zzz = 0;
|
|
258
|
+
`
|
|
259
|
+
|
|
260
|
+
const createAssertErrorFactoryRuntimeSource = `import typia, { TypeGuardError } from "typia";
|
|
261
|
+
|
|
262
|
+
interface User {
|
|
263
|
+
id: number;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export const assertUser = typia.createAssert<User>();
|
|
267
|
+
export const assertUserEquals = typia.createAssertEquals<User>();
|
|
268
|
+
export const withOverride = (
|
|
269
|
+
input: unknown,
|
|
270
|
+
errorFactory: (props: TypeGuardError.IProps) => Error,
|
|
271
|
+
): User => assertUser(input, errorFactory);
|
|
272
|
+
`
|
|
273
|
+
|
|
274
|
+
const createAssertErrorFactoryRuntimeRunner = `const mod = require("./main.cjs");
|
|
275
|
+
|
|
276
|
+
const expect = (label, actual, expected) => {
|
|
277
|
+
if (actual !== expected) throw new Error(label + ": expected " + expected + ", got " + actual);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const capture = (task) => {
|
|
281
|
+
try {
|
|
282
|
+
task();
|
|
283
|
+
} catch (exp) {
|
|
284
|
+
return exp;
|
|
285
|
+
}
|
|
286
|
+
throw new Error("expected the assertion to throw");
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
expect("valid input passes", 1, mod.assertUser({ id: 1 }).id);
|
|
290
|
+
|
|
291
|
+
// A pointwise hand-off fills errorFactory with the element index. Both the
|
|
292
|
+
// falsy 0 and a truthy index must reach the ordinary type-guard error.
|
|
293
|
+
for (const index of [0, 1, 2]) {
|
|
294
|
+
const error = capture(() => mod.assertUser({ id: "bad" }, index));
|
|
295
|
+
expect("index " + index + " expected", "number", error.expected);
|
|
296
|
+
expect("index " + index + " path", "$input.id", error.path);
|
|
297
|
+
expect("index " + index + " method", "typia.createAssert", error.method);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// The declared parameter is real: a callable factory still wins.
|
|
301
|
+
const custom = capture(() =>
|
|
302
|
+
mod.withOverride({ id: "bad" }, (props) => Object.assign(new Error("call-time"), props)),
|
|
303
|
+
);
|
|
304
|
+
expect("call-time factory message", "call-time", custom.message);
|
|
305
|
+
expect("call-time factory path", "$input.id", custom.path);
|
|
306
|
+
|
|
307
|
+
const equals = capture(() => mod.assertUserEquals({ id: 1, extra: true }, 4));
|
|
308
|
+
expect("equals surplus expected", "undefined", equals.expected);
|
|
309
|
+
`
|