dyna-record 0.0.19 → 0.1.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/README.md +19 -39
- package/dist/src/DynaRecord.d.ts +1 -1
- package/dist/src/DynaRecord.js +3 -3
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts +28 -0
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/{NullableAttribute.js → BooleanAttribute.js} +16 -11
- package/dist/src/decorators/attributes/DateAttribute.d.ts +11 -6
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/DateAttribute.js +12 -5
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts +10 -4
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.js +10 -2
- package/dist/src/decorators/attributes/NumberAttribute.d.ts +28 -0
- package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/{DateNullableAttribute.js → NumberAttribute.js} +16 -13
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.js +3 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.js +3 -1
- package/dist/src/decorators/attributes/StringAttribute.d.ts +28 -0
- package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/{Attribute.js → StringAttribute.js} +15 -10
- package/dist/src/decorators/attributes/index.d.ts +3 -4
- package/dist/src/decorators/attributes/index.d.ts.map +1 -1
- package/dist/src/decorators/attributes/index.js +7 -9
- package/dist/src/decorators/attributes/serializers.d.ts +1 -1
- package/dist/src/decorators/attributes/serializers.d.ts.map +1 -1
- package/dist/src/decorators/attributes/serializers.js +1 -1
- package/dist/src/decorators/types.d.ts +9 -0
- package/dist/src/decorators/types.d.ts.map +1 -1
- package/dist/src/errors.d.ts +6 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +8 -1
- package/dist/src/metadata/AttributeMetadata.d.ts +3 -0
- package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -1
- package/dist/src/metadata/AttributeMetadata.js +9 -1
- package/dist/src/metadata/EntityMetadata.d.ts +16 -0
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +53 -0
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +7 -3
- package/dist/src/metadata/types.d.ts +3 -1
- package/dist/src/metadata/types.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.js +3 -0
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +3 -0
- package/dist/src/operations/types.d.ts +1 -1
- package/package.json +3 -2
- package/dist/src/decorators/attributes/Attribute.d.ts +0 -26
- package/dist/src/decorators/attributes/Attribute.d.ts.map +0 -1
- package/dist/src/decorators/attributes/DateNullableAttribute.d.ts +0 -26
- package/dist/src/decorators/attributes/DateNullableAttribute.d.ts.map +0 -1
- package/dist/src/decorators/attributes/NullableAttribute.d.ts +0 -27
- package/dist/src/decorators/attributes/NullableAttribute.d.ts.map +0 -1
- package/dist/src/decorators/attributes/NullableForeignKeyAttribute.d.ts +0 -30
- package/dist/src/decorators/attributes/NullableForeignKeyAttribute.d.ts.map +0 -1
- package/dist/src/decorators/attributes/NullableForeignKeyAttribute.js +0 -45
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import { type Optional } from "../../types";
|
|
3
|
-
import type { AttributeOptions, NotForeignKey } from "../types";
|
|
4
|
-
import { type NativeScalarAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
5
|
-
/**
|
|
6
|
-
* Similar to '@Attribute' but specific to Dates since Dates are not native types to dynamo
|
|
7
|
-
*
|
|
8
|
-
* IMPORTANT - For optimal type safety mark the class field property as optional
|
|
9
|
-
*
|
|
10
|
-
* @template T The class type that the decorator is applied to, ensuring type safety and integration within specific class instances.
|
|
11
|
-
* @template K A type constraint extending `Date`, ensuring that the decorator is only applied to class fields specifically intended to represent dates.
|
|
12
|
-
* @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 `true` by default, indicating that the date attribute can be empty.
|
|
13
|
-
* @returns A class field decorator function that operates within the class field's context. It configures the field as a date attribute and defines how it should be serialized and deserialized to/from DynamoDB.
|
|
14
|
-
*
|
|
15
|
-
* Usage example:
|
|
16
|
-
* ```typescript
|
|
17
|
-
* class MyEntity extends MyTable {
|
|
18
|
-
* @NullableAttribute({ alias: 'MyField' })
|
|
19
|
-
* public myField?: string; // Set to Optional
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* Here, `@Attribute` decorates `myField` of `MyEntity`, marking it as an entity attribute with an alias 'MyField' for ORM purposes.
|
|
24
|
-
*/
|
|
25
|
-
declare function NullableAttribute<T extends DynaRecord, K extends NativeScalarAttributeValue>(props?: AttributeOptions): (_value: undefined, context: ClassFieldDecoratorContext<T, Optional<NotForeignKey<K>>>) => void;
|
|
26
|
-
export default NullableAttribute;
|
|
27
|
-
//# sourceMappingURL=NullableAttribute.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NullableAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/NullableAttribute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,iBAAiB,CACxB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,0BAA0B,EACpC,KAAK,CAAC,EAAE,gBAAgB,YAEd,SAAS,WACR,2BAA2B,CAAC,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC,CAAC,UAcrE;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type { NullableForeignKey } from "../../types";
|
|
3
|
-
import type { AttributeOptions } from "../types";
|
|
4
|
-
/**
|
|
5
|
-
* A decorator for annotating class fields as nullable foreign keys within the context of a single-table design entity. This decorator is specifically designed for attributes that represent nullable foreign keys, facilitating the representation and management of relationships between entities.
|
|
6
|
-
*
|
|
7
|
-
* IMPORTANT - For optimal type safety mark the class field property as optional
|
|
8
|
-
*
|
|
9
|
-
* The entity can belong to its associated entity has a {@link HasOne} or {@link HasMany}
|
|
10
|
-
*
|
|
11
|
-
* @template T The entity the decorator is applied to.
|
|
12
|
-
* @param props An optional object of {@link AttributeOptions}, including configuration options such as metadata attributes.
|
|
13
|
-
* @returns A class field decorator function that targets and initializes the class's prototype to register the field with the ORM's metadata system.
|
|
14
|
-
*
|
|
15
|
-
* Usage example:
|
|
16
|
-
* ```typescript
|
|
17
|
-
* class User extends BaseEntity {
|
|
18
|
-
* @NullableForeignKeyAttribute({ alias: 'ProfileId' })
|
|
19
|
-
* public profileId?: NullableForeignKey; // Set to optional. Nullable foreign key to another entity (e.g., UserProfile)
|
|
20
|
-
*
|
|
21
|
-
* @BelongsTo(() => Profile, { foreignKey: "profileId" })
|
|
22
|
-
* public readonly profile?: Profile; // Set to optional because its linked via a NullableForeignKey
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* Here, `@NullableForeignKeyAttribute` decorates `profileId` of `User`, indicating it as a nullable foreign key.
|
|
27
|
-
*/
|
|
28
|
-
declare function NullableForeignKeyAttribute<T extends DynaRecord>(props?: AttributeOptions): (_value: undefined, context: ClassFieldDecoratorContext<T, NullableForeignKey>) => void;
|
|
29
|
-
export default NullableForeignKeyAttribute;
|
|
30
|
-
//# sourceMappingURL=NullableForeignKeyAttribute.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NullableForeignKeyAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/NullableForeignKeyAttribute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,iBAAS,2BAA2B,CAAC,CAAC,SAAS,UAAU,EACvD,KAAK,CAAC,EAAE,gBAAgB,YAGd,SAAS,WACR,2BAA2B,CAAC,EAAE,kBAAkB,CAAC,UAc7D;AAED,eAAe,2BAA2B,CAAC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const metadata_1 = __importDefault(require("../../metadata"));
|
|
7
|
-
/**
|
|
8
|
-
* A decorator for annotating class fields as nullable foreign keys within the context of a single-table design entity. This decorator is specifically designed for attributes that represent nullable foreign keys, facilitating the representation and management of relationships between entities.
|
|
9
|
-
*
|
|
10
|
-
* IMPORTANT - For optimal type safety mark the class field property as optional
|
|
11
|
-
*
|
|
12
|
-
* The entity can belong to its associated entity has a {@link HasOne} or {@link HasMany}
|
|
13
|
-
*
|
|
14
|
-
* @template T The entity the decorator is applied to.
|
|
15
|
-
* @param props An optional object of {@link AttributeOptions}, including configuration options such as metadata attributes.
|
|
16
|
-
* @returns A class field decorator function that targets and initializes the class's prototype to register the field with the ORM's metadata system.
|
|
17
|
-
*
|
|
18
|
-
* Usage example:
|
|
19
|
-
* ```typescript
|
|
20
|
-
* class User extends BaseEntity {
|
|
21
|
-
* @NullableForeignKeyAttribute({ alias: 'ProfileId' })
|
|
22
|
-
* public profileId?: NullableForeignKey; // Set to optional. Nullable foreign key to another entity (e.g., UserProfile)
|
|
23
|
-
*
|
|
24
|
-
* @BelongsTo(() => Profile, { foreignKey: "profileId" })
|
|
25
|
-
* public readonly profile?: Profile; // Set to optional because its linked via a NullableForeignKey
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* Here, `@NullableForeignKeyAttribute` decorates `profileId` of `User`, indicating it as a nullable foreign key.
|
|
30
|
-
*/
|
|
31
|
-
function NullableForeignKeyAttribute(props) {
|
|
32
|
-
return function (_value, context) {
|
|
33
|
-
if (context.kind === "field") {
|
|
34
|
-
context.addInitializer(function () {
|
|
35
|
-
const entity = Object.getPrototypeOf(this);
|
|
36
|
-
metadata_1.default.addEntityAttribute(entity.constructor.name, {
|
|
37
|
-
attributeName: context.name.toString(),
|
|
38
|
-
nullable: true,
|
|
39
|
-
...props
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
exports.default = NullableForeignKeyAttribute;
|