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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type DynaRecord from "../../DynaRecord";
|
|
2
|
+
import type { AttributeDecoratorContext, AttributeOptions, NotForeignKey } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* A decorator for marking class fields as string attributes within the context of a single-table design entity, with a specific restriction against using foreign key types.
|
|
5
|
+
*
|
|
6
|
+
* IMPORTANT! - This decorator explicitly disallows the use of {@link ForeignKey} type to maintain clear separation between entity relationships and string attributes for improved data integrity and type safety.
|
|
7
|
+
*
|
|
8
|
+
* @template T The entity the decorator is applied to.
|
|
9
|
+
* @template K The type of the attribute, restricted to string attribute values and excluding foreign key types.
|
|
10
|
+
* @param props An optional object of {@link AttributeOptions}, including configuration options such as metadata attributes and additional property characteristics.
|
|
11
|
+
* @returns A class field decorator function that targets and initializes the class's prototype to register the attribute with the ORM's metadata system, ensuring proper handling and validation of the entity's string values.
|
|
12
|
+
*
|
|
13
|
+
* Usage example:
|
|
14
|
+
* ```typescript
|
|
15
|
+
* class Product extends BaseEntity {
|
|
16
|
+
* @StringAttribute({ alias: 'SKU' })
|
|
17
|
+
* public stockKeepingUnit: string; // Simple string attribute representing the product's SKU
|
|
18
|
+
*
|
|
19
|
+
* @StringAttribute({ alias: 'MyNullableField', nullable: true })
|
|
20
|
+
* public myField?: string; // Set to Optional
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Here, `@StringAttribute` decorates `stockKeepingUnit` of `Product` as a simple, non-foreign key attribute, facilitating its management within the ORM system.
|
|
25
|
+
*/
|
|
26
|
+
declare function StringAttribute<T extends DynaRecord, K extends string, P extends AttributeOptions>(props?: P): (_value: undefined, context: AttributeDecoratorContext<T, NotForeignKey<K>, P>) => void;
|
|
27
|
+
export default StringAttribute;
|
|
28
|
+
//# sourceMappingURL=StringAttribute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StringAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/StringAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAChB,aAAa,EACd,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,eAAe,CACtB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,0BAA0B,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,UAe7D;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -3,39 +3,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const zod_1 = require("zod");
|
|
6
7
|
const metadata_1 = __importDefault(require("../../metadata"));
|
|
7
8
|
/**
|
|
8
|
-
* A decorator for marking class fields as attributes within the context of a single-table design entity, with a specific restriction against using foreign key types.
|
|
9
|
+
* A decorator for marking class fields as string attributes within the context of a single-table design entity, with a specific restriction against using foreign key types.
|
|
9
10
|
*
|
|
10
|
-
* IMPORTANT! - This decorator explicitly disallows the use of {@link ForeignKey}
|
|
11
|
+
* IMPORTANT! - This decorator explicitly disallows the use of {@link ForeignKey} type to maintain clear separation between entity relationships and string attributes for improved data integrity and type safety.
|
|
11
12
|
*
|
|
12
13
|
* @template T The entity the decorator is applied to.
|
|
13
|
-
* @template K The type of the attribute, restricted to
|
|
14
|
+
* @template K The type of the attribute, restricted to string attribute values and excluding foreign key types.
|
|
14
15
|
* @param props An optional object of {@link AttributeOptions}, including configuration options such as metadata attributes and additional property characteristics.
|
|
15
|
-
* @returns A class field decorator function that targets and initializes the class's prototype to register the attribute with the ORM's metadata system, ensuring proper handling and validation of the entity's
|
|
16
|
+
* @returns A class field decorator function that targets and initializes the class's prototype to register the attribute with the ORM's metadata system, ensuring proper handling and validation of the entity's string values.
|
|
16
17
|
*
|
|
17
18
|
* Usage example:
|
|
18
19
|
* ```typescript
|
|
19
20
|
* class Product extends BaseEntity {
|
|
20
|
-
* @
|
|
21
|
-
* public stockKeepingUnit: string; // Simple
|
|
21
|
+
* @StringAttribute({ alias: 'SKU' })
|
|
22
|
+
* public stockKeepingUnit: string; // Simple string attribute representing the product's SKU
|
|
23
|
+
*
|
|
24
|
+
* @StringAttribute({ alias: 'MyNullableField', nullable: true })
|
|
25
|
+
* public myField?: string; // Set to Optional
|
|
22
26
|
* }
|
|
23
27
|
* ```
|
|
24
28
|
*
|
|
25
|
-
* Here, `@
|
|
29
|
+
* Here, `@StringAttribute` decorates `stockKeepingUnit` of `Product` as a simple, non-foreign key attribute, facilitating its management within the ORM system.
|
|
26
30
|
*/
|
|
27
|
-
function
|
|
31
|
+
function StringAttribute(props) {
|
|
28
32
|
return function (_value, context) {
|
|
29
33
|
if (context.kind === "field") {
|
|
30
34
|
context.addInitializer(function () {
|
|
31
35
|
const entity = Object.getPrototypeOf(this);
|
|
32
36
|
metadata_1.default.addEntityAttribute(entity.constructor.name, {
|
|
33
37
|
attributeName: context.name.toString(),
|
|
34
|
-
nullable:
|
|
38
|
+
nullable: props?.nullable,
|
|
39
|
+
type: zod_1.z.string(),
|
|
35
40
|
...props
|
|
36
41
|
});
|
|
37
42
|
});
|
|
38
43
|
}
|
|
39
44
|
};
|
|
40
45
|
}
|
|
41
|
-
exports.default =
|
|
46
|
+
exports.default = StringAttribute;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export { default as Attribute } from "./Attribute";
|
|
2
|
-
export { default as NullableAttribute } from "./NullableAttribute";
|
|
3
1
|
export { default as PartitionKeyAttribute } from "./PartitionKeyAttribute";
|
|
4
2
|
export { default as SortKeyAttribute } from "./SortKeyAttribute";
|
|
5
3
|
export { default as ForeignKeyAttribute } from "./ForeignKeyAttribute";
|
|
6
|
-
export { default as NullableForeignKeyAttribute } from "./NullableForeignKeyAttribute";
|
|
7
4
|
export { default as DateAttribute } from "./DateAttribute";
|
|
8
|
-
export { default as
|
|
5
|
+
export { default as StringAttribute } from "./StringAttribute";
|
|
6
|
+
export { default as BooleanAttribute } from "./BooleanAttribute";
|
|
7
|
+
export { default as NumberAttribute } from "./NumberAttribute";
|
|
9
8
|
export * from "./serializers";
|
|
10
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,cAAc,eAAe,CAAC"}
|
|
@@ -17,21 +17,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
21
|
-
var Attribute_1 = require("./Attribute");
|
|
22
|
-
Object.defineProperty(exports, "Attribute", { enumerable: true, get: function () { return __importDefault(Attribute_1).default; } });
|
|
23
|
-
var NullableAttribute_1 = require("./NullableAttribute");
|
|
24
|
-
Object.defineProperty(exports, "NullableAttribute", { enumerable: true, get: function () { return __importDefault(NullableAttribute_1).default; } });
|
|
20
|
+
exports.NumberAttribute = exports.BooleanAttribute = exports.StringAttribute = exports.DateAttribute = exports.ForeignKeyAttribute = exports.SortKeyAttribute = exports.PartitionKeyAttribute = void 0;
|
|
25
21
|
var PartitionKeyAttribute_1 = require("./PartitionKeyAttribute");
|
|
26
22
|
Object.defineProperty(exports, "PartitionKeyAttribute", { enumerable: true, get: function () { return __importDefault(PartitionKeyAttribute_1).default; } });
|
|
27
23
|
var SortKeyAttribute_1 = require("./SortKeyAttribute");
|
|
28
24
|
Object.defineProperty(exports, "SortKeyAttribute", { enumerable: true, get: function () { return __importDefault(SortKeyAttribute_1).default; } });
|
|
29
25
|
var ForeignKeyAttribute_1 = require("./ForeignKeyAttribute");
|
|
30
26
|
Object.defineProperty(exports, "ForeignKeyAttribute", { enumerable: true, get: function () { return __importDefault(ForeignKeyAttribute_1).default; } });
|
|
31
|
-
var NullableForeignKeyAttribute_1 = require("./NullableForeignKeyAttribute");
|
|
32
|
-
Object.defineProperty(exports, "NullableForeignKeyAttribute", { enumerable: true, get: function () { return __importDefault(NullableForeignKeyAttribute_1).default; } });
|
|
33
27
|
var DateAttribute_1 = require("./DateAttribute");
|
|
34
28
|
Object.defineProperty(exports, "DateAttribute", { enumerable: true, get: function () { return __importDefault(DateAttribute_1).default; } });
|
|
35
|
-
var
|
|
36
|
-
Object.defineProperty(exports, "
|
|
29
|
+
var StringAttribute_1 = require("./StringAttribute");
|
|
30
|
+
Object.defineProperty(exports, "StringAttribute", { enumerable: true, get: function () { return __importDefault(StringAttribute_1).default; } });
|
|
31
|
+
var BooleanAttribute_1 = require("./BooleanAttribute");
|
|
32
|
+
Object.defineProperty(exports, "BooleanAttribute", { enumerable: true, get: function () { return __importDefault(BooleanAttribute_1).default; } });
|
|
33
|
+
var NumberAttribute_1 = require("./NumberAttribute");
|
|
34
|
+
Object.defineProperty(exports, "NumberAttribute", { enumerable: true, get: function () { return __importDefault(NumberAttribute_1).default; } });
|
|
37
35
|
__exportStar(require("./serializers"), exports);
|
|
@@ -8,6 +8,6 @@ import type { NativeScalarAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const dateSerializer: {
|
|
10
10
|
toEntityAttribute: (val: NativeScalarAttributeValue) => number | bigint | boolean | Date | import("@aws-sdk/util-dynamodb").NumberValue | ArrayBuffer | Blob | DataView | null | undefined;
|
|
11
|
-
toTableAttribute: (val
|
|
11
|
+
toTableAttribute: (val?: Date) => string | undefined;
|
|
12
12
|
};
|
|
13
13
|
//# sourceMappingURL=serializers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializers.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/serializers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;6BACA,0BAA0B;
|
|
1
|
+
{"version":3,"file":"serializers.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/serializers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;6BACA,0BAA0B;6BAM1B,IAAI;CAC9B,CAAC"}
|
|
@@ -22,9 +22,18 @@ export interface AttributeOptions {
|
|
|
22
22
|
* scenarios where column names in the database differ from attribute names in the code.
|
|
23
23
|
*/
|
|
24
24
|
alias?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Whether or not the attribute is nullable. Defaults to false
|
|
27
|
+
*/
|
|
28
|
+
nullable?: boolean;
|
|
25
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Attribute options for attributes which are not nullable
|
|
32
|
+
*/
|
|
33
|
+
export type NonNullAttributeOptions = Omit<AttributeOptions, "nullable">;
|
|
26
34
|
/**
|
|
27
35
|
* Do not allow ForeignKey or NullableForeignKey types when using the Attribute decorator
|
|
28
36
|
*/
|
|
29
37
|
export type NotForeignKey<T> = T extends ForeignKey | NullableForeignKey ? never : T;
|
|
38
|
+
export type AttributeDecoratorContext<T extends DynaRecord, K, P extends AttributeOptions> = ClassFieldDecoratorContext<T, P["nullable"] extends true ? Optional<K> : K>;
|
|
30
39
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/decorators/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,UAAU,IAAI;KACxD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GACnC,CAAC,GACD,CAAC,CAAC,CAAC,CAAC,SAAS,kBAAkB,GAC7B,QAAQ,CAAC,CAAC,CAAC,GACX,KAAK;CACZ,CAAC,MAAM,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/decorators/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,UAAU,IAAI;KACxD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GACnC,CAAC,GACD,CAAC,CAAC,CAAC,CAAC,SAAS,kBAAkB,GAC7B,QAAQ,CAAC,CAAC,CAAC,GACX,KAAK;CACZ,CAAC,MAAM,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,GAAG,kBAAkB,GACpE,KAAK,GACL,CAAC,CAAC;AAEN,MAAM,MAAM,yBAAyB,CACnC,CAAC,SAAS,UAAU,EACpB,CAAC,EACD,CAAC,SAAS,gBAAgB,IACxB,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,SAAS,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC"}
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -10,4 +10,10 @@ export declare class NullConstraintViolationError extends Error {
|
|
|
10
10
|
export declare class NotFoundError extends Error {
|
|
11
11
|
readonly code = "NotFoundError";
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents an error indicating that an entities attributes are not valid
|
|
15
|
+
*/
|
|
16
|
+
export declare class ValidationError extends Error {
|
|
17
|
+
readonly code = "ValidationError";
|
|
18
|
+
}
|
|
13
19
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/src/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,SAAgB,IAAI,kCAAkC;CACvD;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAgB,IAAI,mBAAmB;CACxC"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,SAAgB,IAAI,kCAAkC;CACvD;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAgB,IAAI,mBAAmB;CACxC;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,SAAgB,IAAI,qBAAqB;CAC1C"}
|
package/dist/src/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotFoundError = exports.NullConstraintViolationError = void 0;
|
|
3
|
+
exports.ValidationError = exports.NotFoundError = exports.NullConstraintViolationError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Represents an error indicating a violation of a null constraint within the ORM system. This error is typically thrown when an operation attempts to set a non-nullable attribute to `null`, which would violate the data integrity rules of the database schema.
|
|
6
6
|
*/
|
|
@@ -15,3 +15,10 @@ class NotFoundError extends Error {
|
|
|
15
15
|
code = "NotFoundError";
|
|
16
16
|
}
|
|
17
17
|
exports.NotFoundError = NotFoundError;
|
|
18
|
+
/**
|
|
19
|
+
* Represents an error indicating that an entities attributes are not valid
|
|
20
|
+
*/
|
|
21
|
+
class ValidationError extends Error {
|
|
22
|
+
code = "ValidationError";
|
|
23
|
+
}
|
|
24
|
+
exports.ValidationError = ValidationError;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ZodType } from "zod";
|
|
1
2
|
import type { AttributeMetadataOptions, Serializers } from "./types";
|
|
2
3
|
/**
|
|
3
4
|
* Represents the metadata for an attribute of an entity, including its name, alias (if any), nullability, and serialization strategies.
|
|
@@ -8,6 +9,7 @@ import type { AttributeMetadataOptions, Serializers } from "./types";
|
|
|
8
9
|
* @property {string} alias - The name of the attribute as defined in the database table. If not provided, it defaults to the name of the attribute. This alias is used for database operations to map the attribute to its corresponding database column.
|
|
9
10
|
* @property {boolean} nullable - Indicates whether the attribute can be `null`, defining the attribute's nullability constraint within the database.
|
|
10
11
|
* @property {Serializers | undefined} serializers - Optional serialization strategies for converting the attribute between its database representation and its entity representation. This is particularly useful for custom data types not natively supported by DynamoDB.
|
|
12
|
+
* @property {ZodType} type - Zod validator to run on the attribute
|
|
11
13
|
*
|
|
12
14
|
* @param {AttributeMetadataOptions} options - Configuration options for the attribute metadata, including the attribute's name, optional alias, nullability, and serialization strategies.
|
|
13
15
|
*/
|
|
@@ -16,6 +18,7 @@ declare class AttributeMetadata {
|
|
|
16
18
|
readonly alias: string;
|
|
17
19
|
readonly nullable: boolean;
|
|
18
20
|
readonly serializers?: Serializers;
|
|
21
|
+
readonly type: ZodType;
|
|
19
22
|
constructor(options: AttributeMetadataOptions);
|
|
20
23
|
}
|
|
21
24
|
export default AttributeMetadata;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttributeMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/AttributeMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAErE
|
|
1
|
+
{"version":3,"file":"AttributeMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/AttributeMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,cAAM,iBAAiB;IACrB,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,QAAQ,EAAE,OAAO,CAAC;IAClC,SAAgB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1C,SAAgB,IAAI,EAAE,OAAO,CAAC;gBAElB,OAAO,EAAE,wBAAwB;CAY9C;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
* @property {string} alias - The name of the attribute as defined in the database table. If not provided, it defaults to the name of the attribute. This alias is used for database operations to map the attribute to its corresponding database column.
|
|
10
10
|
* @property {boolean} nullable - Indicates whether the attribute can be `null`, defining the attribute's nullability constraint within the database.
|
|
11
11
|
* @property {Serializers | undefined} serializers - Optional serialization strategies for converting the attribute between its database representation and its entity representation. This is particularly useful for custom data types not natively supported by DynamoDB.
|
|
12
|
+
* @property {ZodType} type - Zod validator to run on the attribute
|
|
12
13
|
*
|
|
13
14
|
* @param {AttributeMetadataOptions} options - Configuration options for the attribute metadata, including the attribute's name, optional alias, nullability, and serialization strategies.
|
|
14
15
|
*/
|
|
@@ -17,11 +18,18 @@ class AttributeMetadata {
|
|
|
17
18
|
alias;
|
|
18
19
|
nullable;
|
|
19
20
|
serializers;
|
|
21
|
+
type;
|
|
20
22
|
constructor(options) {
|
|
21
23
|
this.name = options.attributeName;
|
|
22
24
|
this.alias = options.alias ?? options.attributeName;
|
|
23
|
-
this.nullable = options.nullable;
|
|
25
|
+
this.nullable = options.nullable ?? false;
|
|
24
26
|
this.serializers = options.serializers;
|
|
27
|
+
if (options.nullable === true) {
|
|
28
|
+
this.type = options.type.optional().nullable();
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.type = options.type;
|
|
32
|
+
}
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
35
|
exports.default = AttributeMetadata;
|
|
@@ -14,6 +14,7 @@ type EntityClass = new (...args: any) => DynaRecord;
|
|
|
14
14
|
* @param {string} tableClassName - The name of the table class instance that maps to the database table of the entity.
|
|
15
15
|
*/
|
|
16
16
|
declare class EntityMetadata {
|
|
17
|
+
#private;
|
|
17
18
|
/**
|
|
18
19
|
* The name of the table class instance to which this entity belongs
|
|
19
20
|
*/
|
|
@@ -37,6 +38,21 @@ declare class EntityMetadata {
|
|
|
37
38
|
* @param attrMeta
|
|
38
39
|
*/
|
|
39
40
|
addAttribute(attrMeta: AttributeMetadata): void;
|
|
41
|
+
/**
|
|
42
|
+
* Validate all an entities attributes (used on create)
|
|
43
|
+
* @param attributes
|
|
44
|
+
*/
|
|
45
|
+
validateFull(attributes: DynaRecord): void;
|
|
46
|
+
/**
|
|
47
|
+
* Validate partial entities attributes (used on update)
|
|
48
|
+
* @param attributes
|
|
49
|
+
*/
|
|
50
|
+
validatePartial(attributes: Partial<DynaRecord>): void;
|
|
51
|
+
/**
|
|
52
|
+
* Throw validation errors with the cause
|
|
53
|
+
* @param error
|
|
54
|
+
*/
|
|
55
|
+
private handleValidationError;
|
|
40
56
|
}
|
|
41
57
|
export default EntityMetadata;
|
|
42
58
|
//# sourceMappingURL=EntityMetadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/EntityMetadata.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EntityMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/EntityMetadata.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EACjC,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAG5C,KAAK,WAAW,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,KAAK,UAAU,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,cAAM,cAAc;;IAClB;;OAEG;IACH,SAAgB,cAAc,EAAE,MAAM,CAAC;IACvC;;OAEG;IACH,SAAgB,UAAU,EAAE,wBAAwB,CAAC;IACrD;;OAEG;IACH,SAAgB,eAAe,EAAE,wBAAwB,CAAC;IAE1D;;OAEG;IACH,SAAgB,aAAa,EAAE,2BAA2B,CAAC;IAE3D,SAAgB,WAAW,EAAE,WAAW,CAAC;gBAiB7B,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM;IAS5D;;;OAGG;IACI,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAOtD;;;OAGG;IACI,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAYjD;;;OAGG;IACI,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI;IAY7D;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CAK9B;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const zod_1 = require("zod");
|
|
4
|
+
const errors_1 = require("../errors");
|
|
3
5
|
/**
|
|
4
6
|
* Represents metadata for an entity within the ORM system, encapsulating information about the entity's attributes, relationships, and its associated database table.
|
|
5
7
|
*
|
|
@@ -30,6 +32,18 @@ class EntityMetadata {
|
|
|
30
32
|
*/
|
|
31
33
|
relationships;
|
|
32
34
|
EntityClass;
|
|
35
|
+
/**
|
|
36
|
+
* Zod schema for runtime validation on entity attributes. Validates all attributes (used on Create)
|
|
37
|
+
*/
|
|
38
|
+
#schema;
|
|
39
|
+
/**
|
|
40
|
+
* Zod schema for runtime validation on entity attributes. Validates partial attributes (used on Update)
|
|
41
|
+
*/
|
|
42
|
+
#schemaPartial;
|
|
43
|
+
/**
|
|
44
|
+
* Object containing zod attributes. Built programmatically via decorators and used to create schemas
|
|
45
|
+
*/
|
|
46
|
+
#zodAttributes = {};
|
|
33
47
|
constructor(entityClass, tableClassName) {
|
|
34
48
|
this.EntityClass = entityClass;
|
|
35
49
|
this.tableClassName = tableClassName;
|
|
@@ -44,6 +58,45 @@ class EntityMetadata {
|
|
|
44
58
|
addAttribute(attrMeta) {
|
|
45
59
|
this.attributes[attrMeta.name] = attrMeta;
|
|
46
60
|
this.tableAttributes[attrMeta.alias] = attrMeta;
|
|
61
|
+
this.#zodAttributes[attrMeta.name] = attrMeta.type;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Validate all an entities attributes (used on create)
|
|
65
|
+
* @param attributes
|
|
66
|
+
*/
|
|
67
|
+
validateFull(attributes) {
|
|
68
|
+
if (this.#schema === undefined) {
|
|
69
|
+
this.#schema = zod_1.z.object(this.#zodAttributes);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
this.#schema.parse(attributes);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
this.handleValidationError(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Validate partial entities attributes (used on update)
|
|
80
|
+
* @param attributes
|
|
81
|
+
*/
|
|
82
|
+
validatePartial(attributes) {
|
|
83
|
+
if (this.#schemaPartial === undefined) {
|
|
84
|
+
this.#schemaPartial = zod_1.z.object(this.#zodAttributes).partial();
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
this.#schemaPartial.parse(attributes);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this.handleValidationError(error);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Throw validation errors with the cause
|
|
95
|
+
* @param error
|
|
96
|
+
*/
|
|
97
|
+
handleValidationError(error) {
|
|
98
|
+
const errorOptions = error instanceof zod_1.ZodError ? { cause: error.issues } : undefined;
|
|
99
|
+
throw new errors_1.ValidationError("Validation errors", errorOptions);
|
|
47
100
|
}
|
|
48
101
|
}
|
|
49
102
|
exports.default = EntityMetadata;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/TableMetadata.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TableMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/TableMetadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAGb,4BAA4B,EAC7B,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,gBAAgB;;;CAAiD,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CACrC,aAAa,EACb;IAAE,KAAK,EAAE,aAAa,CAAA;CAAE,CAQhB,CAAC;AAEX;;;;;;;;;;;;;GAaG;AACH,cAAM,aAAa;IACjB,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,iBAAiB,EAAE,MAAM,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;IAC5E,SAAgB,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACnE,qBAAqB,EAAE,iBAAiB,CAAC;IACzC,gBAAgB,EAAE,iBAAiB,CAAC;gBAE/B,OAAO,EAAE,oBAAoB;IAwBzC;;;;OAIG;IACH,OAAO,CAAC,8BAA8B;IAgCtC;;;OAGG;IACI,wBAAwB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;IAK5E;;;OAGG;IACI,mBAAmB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;CAIxE;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tableDefaultFields = exports.defaultTableKeys = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
4
5
|
const _1 = require(".");
|
|
5
6
|
const decorators_1 = require("../decorators");
|
|
6
7
|
exports.defaultTableKeys = { partitionKey: "PK", sortKey: "SK" };
|
|
@@ -47,13 +48,15 @@ class TableMetadata {
|
|
|
47
48
|
name: "",
|
|
48
49
|
alias: exports.defaultTableKeys.partitionKey,
|
|
49
50
|
nullable: false,
|
|
50
|
-
serializers: { toEntityAttribute: () => "", toTableAttribute: () => "" }
|
|
51
|
+
serializers: { toEntityAttribute: () => "", toTableAttribute: () => "" },
|
|
52
|
+
type: zod_1.z.string()
|
|
51
53
|
};
|
|
52
54
|
this.sortKeyAttribute = {
|
|
53
55
|
name: "",
|
|
54
56
|
alias: exports.defaultTableKeys.sortKey,
|
|
55
57
|
nullable: false,
|
|
56
|
-
serializers: { toEntityAttribute: () => "", toTableAttribute: () => "" }
|
|
58
|
+
serializers: { toEntityAttribute: () => "", toTableAttribute: () => "" },
|
|
59
|
+
type: zod_1.z.string()
|
|
57
60
|
};
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
@@ -73,7 +76,8 @@ class TableMetadata {
|
|
|
73
76
|
name: entityKey,
|
|
74
77
|
alias,
|
|
75
78
|
nullable: false,
|
|
76
|
-
serializers: isDateField ? decorators_1.dateSerializer : undefined
|
|
79
|
+
serializers: isDateField ? decorators_1.dateSerializer : undefined,
|
|
80
|
+
type: isDateField ? zod_1.z.date() : zod_1.z.unknown()
|
|
77
81
|
};
|
|
78
82
|
acc.entityDefaults[entityKey] = meta;
|
|
79
83
|
acc.tableDefaults[alias] = meta;
|
|
@@ -3,6 +3,7 @@ import type { AttributeMetadata, EntityMetadata, JoinTableMetadata, Relationship
|
|
|
3
3
|
import type DynaRecord from "../DynaRecord";
|
|
4
4
|
import type { BelongsToLink } from "../relationships";
|
|
5
5
|
import type { MakeOptional } from "../types";
|
|
6
|
+
import type { ZodType } from "zod";
|
|
6
7
|
/**
|
|
7
8
|
* Represents relationship metadata that includes a foreign key reference to another entity.
|
|
8
9
|
*/
|
|
@@ -83,8 +84,9 @@ export interface Serializers {
|
|
|
83
84
|
*/
|
|
84
85
|
export interface AttributeMetadataOptions {
|
|
85
86
|
attributeName: string;
|
|
87
|
+
type: ZodType;
|
|
86
88
|
alias?: string;
|
|
87
|
-
nullable
|
|
89
|
+
nullable?: boolean;
|
|
88
90
|
serializers?: Serializers;
|
|
89
91
|
}
|
|
90
92
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACd,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACd,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG,OAAO,CACtD,oBAAoB,EACpB;IAAE,UAAU,EAAE,MAAM,UAAU,CAAA;CAAE,CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,WAAW,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CACrC,aAAa,EACb,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,CAAC,GAAG;IAC7E,aAAa,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,YAAY,CACrD,IAAI,CAAC,wBAAwB,EAAE,UAAU,CAAC,EAC1C,OAAO,CACR,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,0BAA0B,KAAK,GAAG,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,0BAA0B,CAAC;AAEzE;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,iBAAiB,EAAE,gBAAgB,CAAC;IACpC;;OAEG;IACH,gBAAgB,EAAE,eAAe,CAAC;CACnC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB;IACvC,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAGhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAGhE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGjD;;;;;;GAMG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAG7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;OAIG;IACU,GAAG,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAgB5E;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAsBvB;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAW/B;;;OAGG;YACW,6BAA6B;CAU5C;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -8,6 +8,7 @@ const dynamo_utils_1 = require("../../dynamo-utils");
|
|
|
8
8
|
const utils_1 = require("../../utils");
|
|
9
9
|
const OperationBase_1 = __importDefault(require("../OperationBase"));
|
|
10
10
|
const utils_2 = require("../utils");
|
|
11
|
+
const metadata_1 = __importDefault(require("../../metadata"));
|
|
11
12
|
/**
|
|
12
13
|
* Represents the operation for creating a new entity in the database, including handling its attributes and any related entities' associations. It will handle de-normalizing data to support relationships
|
|
13
14
|
*
|
|
@@ -28,6 +29,8 @@ class Create extends OperationBase_1.default {
|
|
|
28
29
|
*/
|
|
29
30
|
async run(attributes) {
|
|
30
31
|
const entityData = this.buildEntityData(attributes);
|
|
32
|
+
const entityMeta = metadata_1.default.getEntity(this.EntityClass.name);
|
|
33
|
+
entityMeta.validateFull(entityData);
|
|
31
34
|
const tableItem = (0, utils_1.entityToTableItem)(this.EntityClass, entityData);
|
|
32
35
|
this.buildPutItemTransaction(tableItem);
|
|
33
36
|
await this.buildRelationshipTransactions(entityData);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Update.d.ts","sourceRoot":"","sources":["../../../../src/operations/Update/Update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAa/C,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Update.d.ts","sourceRoot":"","sources":["../../../../src/operations/Update/Update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAa/C,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C;;;;;;GAMG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAK7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;OAIG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IASzE;;;;OAIG;IACH,OAAO,CAAC,0BAA0B;IAkClC;;;;;;OAMG;YACW,6BAA6B;IAsB3C;;;;;OAKG;IACH,OAAO,CAAC,sCAAsC;IAyB9C;;OAEG;YACW,SAAS;CAOxB;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -7,6 +7,7 @@ const dynamo_utils_1 = require("../../dynamo-utils");
|
|
|
7
7
|
const utils_1 = require("../../utils");
|
|
8
8
|
const utils_2 = require("../utils");
|
|
9
9
|
const OperationBase_1 = __importDefault(require("../OperationBase"));
|
|
10
|
+
const metadata_1 = __importDefault(require("../../metadata"));
|
|
10
11
|
/**
|
|
11
12
|
* Facilitates the operation of updating an existing entity in the database, including handling updates to its attributes and managing changes to its relationships. It will de-normalize data to support relationship links
|
|
12
13
|
*
|
|
@@ -27,6 +28,8 @@ class Update extends OperationBase_1.default {
|
|
|
27
28
|
* @param attributes Attributes on the model to update.
|
|
28
29
|
*/
|
|
29
30
|
async run(id, attributes) {
|
|
31
|
+
const entityMeta = metadata_1.default.getEntity(this.EntityClass.name);
|
|
32
|
+
entityMeta.validatePartial(attributes);
|
|
30
33
|
this.buildUpdateItemTransaction(id, attributes);
|
|
31
34
|
await this.buildRelationshipTransactions(id, attributes);
|
|
32
35
|
await this.#transactionBuilder.executeTransaction();
|
|
@@ -48,7 +48,7 @@ export type RelationshipAttributeNames<T> = {
|
|
|
48
48
|
*/
|
|
49
49
|
export type EntityAttributes<T extends DynaRecord> = Omit<T, RelationshipAttributeNames<T>>;
|
|
50
50
|
/**
|
|
51
|
-
* Attributes that are defined on the Entity using the
|
|
51
|
+
* Attributes that are defined on the Entity using the attribute decorators. This excludes:
|
|
52
52
|
* - relationship attributes
|
|
53
53
|
* - partition key attribute
|
|
54
54
|
* - sort key attribute
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyna-record",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Typescript Object Relational Mapper (ORM) for Dynamo",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"@aws-sdk/client-dynamodb": "^3.502.0",
|
|
28
28
|
"@aws-sdk/lib-dynamodb": "^3.502.0",
|
|
29
29
|
"@aws-sdk/util-dynamodb": "^3.509.0",
|
|
30
|
-
"uuid": "^9.0.1"
|
|
30
|
+
"uuid": "^9.0.1",
|
|
31
|
+
"zod": "^3.23.8"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@aws-sdk/types": "^3.502.0",
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type { AttributeOptions, NotForeignKey } from "../types";
|
|
3
|
-
import { type NativeScalarAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
4
|
-
/**
|
|
5
|
-
* A decorator for marking class fields as attributes within the context of a single-table design entity, with a specific restriction against using foreign key types.
|
|
6
|
-
*
|
|
7
|
-
* IMPORTANT! - This decorator explicitly disallows the use of {@link ForeignKey} and {@link NullableForeignKey} types to maintain clear separation between entity relationships and scalar attributes for improved data integrity and type safety.
|
|
8
|
-
*
|
|
9
|
-
* @template T The entity the decorator is applied to.
|
|
10
|
-
* @template K The type of the attribute, restricted to native scalar attribute values and excluding foreign key types.
|
|
11
|
-
* @param props An optional object of {@link AttributeOptions}, including configuration options such as metadata attributes and additional property characteristics.
|
|
12
|
-
* @returns A class field decorator function that targets and initializes the class's prototype to register the attribute with the ORM's metadata system, ensuring proper handling and validation of the entity's scalar values.
|
|
13
|
-
*
|
|
14
|
-
* Usage example:
|
|
15
|
-
* ```typescript
|
|
16
|
-
* class Product extends BaseEntity {
|
|
17
|
-
* @Attribute({ alias: 'SKU' })
|
|
18
|
-
* public stockKeepingUnit: string; // Simple scalar attribute representing the product's SKU
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* Here, `@Attribute` decorates `stockKeepingUnit` of `Product` as a simple, non-foreign key attribute, facilitating its management within the ORM system.
|
|
23
|
-
*/
|
|
24
|
-
declare function Attribute<T extends DynaRecord, K extends NativeScalarAttributeValue>(props?: AttributeOptions): (_value: undefined, context: ClassFieldDecoratorContext<T, NotForeignKey<K>>) => void;
|
|
25
|
-
export default Attribute;
|
|
26
|
-
//# sourceMappingURL=Attribute.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Attribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/Attribute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,0BAA0B,EAC3E,KAAK,CAAC,EAAE,gBAAgB,YAGd,SAAS,WACR,2BAA2B,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,UAc3D;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type { Optional } from "../../types";
|
|
3
|
-
import type { AttributeOptions } from "../types";
|
|
4
|
-
/**
|
|
5
|
-
* Similar to '@Attribute' but specific to Dates since Dates are not native types to dynamo
|
|
6
|
-
*
|
|
7
|
-
* IMPORTANT - For optimal type safety mark the class field property as optional
|
|
8
|
-
*
|
|
9
|
-
* @template T The class type that the decorator is applied to, ensuring type safety and integration within specific class instances.
|
|
10
|
-
* @template K A type constraint extending `Date`, ensuring that the decorator is only applied to class fields specifically intended to represent dates.
|
|
11
|
-
* @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, indicating that the date attribute must not be empty.
|
|
12
|
-
* @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.
|
|
13
|
-
*
|
|
14
|
-
* Usage example:
|
|
15
|
-
* ```typescript
|
|
16
|
-
* class MyEntity extends MyTable {
|
|
17
|
-
* @DateNullableAttribute({ alias: 'MyField' })
|
|
18
|
-
* public myField?: Date; // Set to Optional
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* Here, `@Attribute` decorates `myField` of `MyEntity`, marking it as an entity attribute with an alias 'MyField' for ORM purposes.
|
|
23
|
-
*/
|
|
24
|
-
declare function DateNullableAttribute<T extends DynaRecord, K extends Date>(props?: AttributeOptions): (_value: undefined, context: ClassFieldDecoratorContext<T, Optional<K>>) => void;
|
|
25
|
-
export default DateNullableAttribute;
|
|
26
|
-
//# sourceMappingURL=DateNullableAttribute.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DateNullableAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/DateNullableAttribute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,qBAAqB,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,IAAI,EACjE,KAAK,CAAC,EAAE,gBAAgB,YAGd,SAAS,WACR,2BAA2B,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,UAetD;AAED,eAAe,qBAAqB,CAAC"}
|