-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AnyType } from "../typeChecking/schemas" | ||
import { failure } from "../utils" | ||
import { AnyModel, ModelClass } from "./BaseModel" | ||
import { modelValidationTypeCheckerSymbol } from "./modelSymbols" | ||
import { isModel, isModelClass } from "./utils" | ||
|
||
/** | ||
* Returns the associated validation type for runtime checking (if any) to a model instance or | ||
* class. | ||
* | ||
* @param modelClassOrInstance Model class or instance. | ||
* @returns The associated validation type, or `undefined` if none. | ||
*/ | ||
export function getModelValidationType( | ||
modelClassOrInstance: AnyModel | ModelClass<AnyModel> | ||
): AnyType | undefined { | ||
if (isModel(modelClassOrInstance)) { | ||
return (modelClassOrInstance as any).constructor[modelValidationTypeCheckerSymbol] | ||
} else if (isModelClass(modelClassOrInstance)) { | ||
return (modelClassOrInstance as any)[modelValidationTypeCheckerSymbol] | ||
} else { | ||
throw failure(`modelClassOrInstance must be a model class or instance`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const modelDataTypeCheckerSymbol = Symbol("modelDataTypeChecker") | ||
export const modelValidationTypeCheckerSymbol = Symbol("modelValidationTypeChecker") | ||
export const modelUnwrappedClassSymbol = Symbol("modelUnwrappedClass") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters