-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from dsdavis4/schema_validation
Schema validation
- Loading branch information
Showing
48 changed files
with
1,366 additions
and
739 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,53 @@ | ||
import { z } from "zod"; | ||
import type DynaRecord from "../../DynaRecord"; | ||
import Metadata from "../../metadata"; | ||
import type { AttributeDecoratorContext, AttributeOptions } from "../types"; | ||
|
||
/** | ||
* A decorator for marking class fields as boolean attributes within the context of a single-table design entity | ||
* | ||
* Can be set to nullable via decorator props | ||
* | ||
* @template T The class type that the decorator is applied to, ensuring type safety and integration within specific class instances. | ||
* @template K A type constraint extending `boolean`, ensuring that the decorator is only applied to class fields specifically intended to represent booleans. | ||
* @param props An {@link AttributeOptions} object providing configuration options for the attribute, such as its `alias` which allows the attribute to be referred to by an alternative name in the database context. The `nullable` property is also set to `false` by default. | ||
* @returns A class field decorator function that operates within the class field's context. It configures the field as a boolean attribute and defines how it should be serialized and deserialized to/from DynamoDB. | ||
* | ||
* Usage example: | ||
* ```typescript | ||
* class MyEntity extends MyTable { | ||
* @BooleanAttribute({ alias: 'MyField' }) | ||
* public myField: boolean; | ||
* | ||
* @BooleanAttribute({ alias: 'MyNullableField', nullable: true }) | ||
* public myField?: boolean; // Set to Optional | ||
* } | ||
* ``` | ||
* | ||
* Here, `@BooleanAttribute` decorates `myField` of `MyEntity`, marking it as an entity attribute with an alias 'MyField' for ORM purposes. | ||
*/ | ||
function BooleanAttribute< | ||
T extends DynaRecord, | ||
K extends boolean, | ||
P extends AttributeOptions | ||
>(props?: P) { | ||
return function ( | ||
_value: undefined, | ||
context: AttributeDecoratorContext<T, K, P> | ||
) { | ||
if (context.kind === "field") { | ||
context.addInitializer(function () { | ||
const entity: DynaRecord = Object.getPrototypeOf(this); | ||
|
||
Metadata.addEntityAttribute(entity.constructor.name, { | ||
attributeName: context.name.toString(), | ||
nullable: props?.nullable, | ||
type: z.boolean(), | ||
...props | ||
}); | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
export default BooleanAttribute; |
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
Oops, something went wrong.