dyna-record 0.1.2 → 0.1.4
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 +14 -3
- package/dist/src/DynaRecord.d.ts +15 -0
- package/dist/src/DynaRecord.d.ts.map +1 -1
- package/dist/src/DynaRecord.js +26 -0
- package/dist/src/decorators/attributes/EnumAttribute.d.ts +32 -0
- package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/EnumAttribute.js +44 -0
- package/dist/src/decorators/attributes/index.d.ts +1 -0
- package/dist/src/decorators/attributes/index.d.ts.map +1 -1
- package/dist/src/decorators/attributes/index.js +3 -1
- package/dist/src/decorators/attributes/serializers.d.ts +1 -1
- package/dist/src/metadata/EntityMetadata.d.ts +12 -6
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +27 -13
- package/dist/src/metadata/TableMetadata.d.ts +18 -0
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +25 -0
- package/dist/src/metadata/types.d.ts +4 -2
- package/dist/src/metadata/types.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.d.ts +3 -1
- package/dist/src/operations/Create/Create.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.js +7 -4
- package/dist/src/operations/FindById/types.d.ts +2 -2
- package/dist/src/operations/FindById/types.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.d.ts +4 -2
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +7 -3
- package/dist/src/operations/Update/types.d.ts +4 -0
- package/dist/src/operations/Update/types.d.ts.map +1 -1
- package/dist/src/operations/types.d.ts +7 -2
- package/dist/src/operations/types.d.ts.map +1 -1
- package/dist/src/relationships/BelongsToLink.d.ts +2 -1
- package/dist/src/relationships/BelongsToLink.d.ts.map +1 -1
- package/dist/src/utils.d.ts +6 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[API Documentation](https://dyna-record.com/)
|
|
4
4
|
|
|
5
|
-
Dyna-Record is a strongly typed ORM (Object-Relational Mapping) tool designed for modeling and interacting with data stored in DynamoDB in a structured and type-safe manner. It simplifies the process of defining data models (entities), performing CRUD operations, and handling complex queries. To support relational data, dyna-record implements a flavor of the [single-table design pattern](https://aws.amazon.com/blogs/compute/creating-a-single-table-design-with-amazon-dynamodb/) and the [adjacency list design pattern](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html). All operations are [ACID compliant transactions\*](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis.html)\.
|
|
5
|
+
Dyna-Record is a strongly typed ORM (Object-Relational Mapping) tool designed for modeling and interacting with data stored in DynamoDB in a structured and type-safe manner. It simplifies the process of defining data models (entities), performing CRUD operations, and handling complex queries. To support relational data, dyna-record implements a flavor of the [single-table design pattern](https://aws.amazon.com/blogs/compute/creating-a-single-table-design-with-amazon-dynamodb/) and the [adjacency list design pattern](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html). All operations are [ACID compliant transactions\*](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis.html)\. To enforce data integrity beyond the type system, schema validation is performed at runtime.
|
|
6
6
|
|
|
7
7
|
Note: ACID compliant according to DynamoDB [limitations](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis.html)
|
|
8
8
|
|
|
@@ -142,6 +142,7 @@ Use the attribute decorators below to define attributes on a model. The decorato
|
|
|
142
142
|
- [@NumberAttribute](https://dyna-record.com/functions/NumberAttribute.html)
|
|
143
143
|
- [@BooleanAttribute](https://dyna-record.com/functions/BooleanAttribute.html)
|
|
144
144
|
- [@DateAttribute](https://dyna-record.com/functions/DateAttribute.html)
|
|
145
|
+
- [@EnumAttribute](https://dyna-record.com/functions/EnumAttribute.html)
|
|
145
146
|
|
|
146
147
|
- The [alias](https://dyna-record.com/interfaces/AttributeOptions.html#alias) option allows you to specify the attribute name as it appears in the DynamoDB table, different from your class property name.
|
|
147
148
|
- Set nullable attributes as optional for optimal type safety
|
|
@@ -310,7 +311,7 @@ class Student extends OtherTable {
|
|
|
310
311
|
|
|
311
312
|
The create method is used to insert a new record into a DynamoDB table. This method automatically handles key generation (using UUIDs), timestamps for [createdAt](https://dyna-record.com/classes/default.html#createdAt) and [updatedAt](https://dyna-record.com/classes/default.html#updatedAt) fields, and the management of relationships between entities. It leverages AWS SDK's [TransactWriteCommand](https://www.google.com/search?q=aws+transact+write+command&oq=aws+transact+write+command&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQRRg7MgYIAhBFGDvSAQgzMjAzajBqN6gCALACAA&sourceid=chrome&ie=UTF-8) for transactional integrity, ensuring either complete success or rollback in case of any failure. The method handles conditional checks to ensure data integrity and consistency during creation. If a foreignKey is set on create, dyna-record will de-normalize the data required in order to support the relationship
|
|
312
313
|
|
|
313
|
-
To use the create method, call it on the model class you wish to create a new record for. Pass the properties of the new record as an object argument to the method.
|
|
314
|
+
To use the create method, call it on the model class you wish to create a new record for. Pass the properties of the new record as an object argument to the method. Only attributes defined on the model can be configured, and will be enforced via types and runtime schema validation.
|
|
314
315
|
|
|
315
316
|
#### Basic Usage
|
|
316
317
|
|
|
@@ -469,7 +470,7 @@ const result = await Customer.query(
|
|
|
469
470
|
|
|
470
471
|
[Docs](https://dyna-record.com/classes/default.html#update)
|
|
471
472
|
|
|
472
|
-
The update method enables modifications to existing items in a DynamoDB table. It supports updating simple attributes, handling nullable fields, and managing relationships between entities, including updating and removing foreign keys.
|
|
473
|
+
The update method enables modifications to existing items in a DynamoDB table. It supports updating simple attributes, handling nullable fields, and managing relationships between entities, including updating and removing foreign keys. Only attributes defined on the model can be updated, and will be enforced via types and runtime schema validation.
|
|
473
474
|
|
|
474
475
|
#### Updating simple attributes
|
|
475
476
|
|
|
@@ -513,6 +514,16 @@ await Pet.update("123", {
|
|
|
513
514
|
});
|
|
514
515
|
```
|
|
515
516
|
|
|
517
|
+
#### Instance Method
|
|
518
|
+
|
|
519
|
+
There is an instance `update` method that has the same rules above, but returns the full updated instance.
|
|
520
|
+
|
|
521
|
+
```typescript
|
|
522
|
+
const updatedInstance = await petInstance.update({
|
|
523
|
+
ownerId: null
|
|
524
|
+
});
|
|
525
|
+
```
|
|
526
|
+
|
|
516
527
|
### Delete
|
|
517
528
|
|
|
518
529
|
[Docs](https://dyna-record.com/classes/default.html#delete)
|
package/dist/src/DynaRecord.d.ts
CHANGED
|
@@ -188,6 +188,21 @@ declare abstract class DynaRecord implements DynaRecordBase {
|
|
|
188
188
|
* ```
|
|
189
189
|
*/
|
|
190
190
|
static update<T extends DynaRecord>(this: EntityClass<T>, id: string, attributes: UpdateOptions<T>): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Same as the static `update` method but on an instance. Returns the full updated instance
|
|
193
|
+
*
|
|
194
|
+
*
|
|
195
|
+
* @example Updating an entity.
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const updatedInstance = await instance.update({ email: "newemail@example.com", profileId: 789 });
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @example Removing a nullable entities attributes
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const updatedInstance = await instance.update({ email: "newemail@example.com", someKey: null });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
update<T extends this>(attributes: UpdateOptions<T>): Promise<T>;
|
|
191
206
|
/**
|
|
192
207
|
* Delete an entity by ID
|
|
193
208
|
* - Delete all BelongsToLinks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynaRecord.d.ts","sourceRoot":"","sources":["../../src/DynaRecord.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,IAAI,mBAAmB,EAAE,MAAM,eAAe,CAAC;A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AAE,WAAW,CAAC,CAAC,CAAC,EACpB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;;;;;;OASG;WACW,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;CAIpD;AAED,eAAe,UAAU,CAAC"}
|
package/dist/src/DynaRecord.js
CHANGED
|
@@ -60,6 +60,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
60
60
|
const metadata_1 = __importStar(require("./metadata"));
|
|
61
61
|
const decorators_1 = require("./decorators");
|
|
62
62
|
const operations_1 = require("./operations");
|
|
63
|
+
const utils_1 = require("./utils");
|
|
63
64
|
/**
|
|
64
65
|
* Serves as an abstract base class for entities in the ORM system. It defines standard fields such as `id`, `type`, `createdAt`, and `updatedAt`, and provides static methods for CRUD operations and queries. This class encapsulates common behaviors and properties that all entities share, leveraging decorators for attribute metadata and supporting operations like finding, creating, updating, and deleting entities.
|
|
65
66
|
*
|
|
@@ -183,6 +184,31 @@ let DynaRecord = (() => {
|
|
|
183
184
|
const op = new operations_1.Update(this);
|
|
184
185
|
await op.run(id, attributes);
|
|
185
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Same as the static `update` method but on an instance. Returns the full updated instance
|
|
189
|
+
*
|
|
190
|
+
*
|
|
191
|
+
* @example Updating an entity.
|
|
192
|
+
* ```typescript
|
|
193
|
+
* const updatedInstance = await instance.update({ email: "newemail@example.com", profileId: 789 });
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @example Removing a nullable entities attributes
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const updatedInstance = await instance.update({ email: "newemail@example.com", someKey: null });
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
async update(attributes) {
|
|
202
|
+
const InstanceClass = this.constructor;
|
|
203
|
+
const op = new operations_1.Update(InstanceClass);
|
|
204
|
+
const updatedAttributes = await op.run(this.id, attributes);
|
|
205
|
+
const clone = structuredClone(this);
|
|
206
|
+
// Update the current instance with new attributes
|
|
207
|
+
Object.assign(clone, updatedAttributes);
|
|
208
|
+
const updatedInstance = Object.fromEntries(Object.entries(clone).filter(([_, value]) => value !== null));
|
|
209
|
+
// Return the updated instance, which is of type `this`
|
|
210
|
+
return (0, utils_1.createInstance)(InstanceClass, updatedInstance);
|
|
211
|
+
}
|
|
186
212
|
/**
|
|
187
213
|
* Delete an entity by ID
|
|
188
214
|
* - Delete all BelongsToLinks
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type DynaRecord from "../../DynaRecord";
|
|
2
|
+
import type { AttributeDecoratorContext, AttributeOptions } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Extends {@link AttributeOptions} but requires that the allowed values are set on `values`
|
|
5
|
+
*/
|
|
6
|
+
export interface EnumAttributeOptions extends AttributeOptions {
|
|
7
|
+
values: [string, ...string[]];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A decorator for marking class fields as enum attributes within the context of a single-table design entity. Only the types specified in `values` are allowed via both the type system and runtime schema checks.
|
|
11
|
+
*
|
|
12
|
+
* This enforces a union type of the specified fields listed in `values`
|
|
13
|
+
*
|
|
14
|
+
* @template T The entity the decorator is applied to.
|
|
15
|
+
* @template K The type of the attribute, restricted to the values listed in `values` prop of EnumAttributeOptions
|
|
16
|
+
* @param props An optional object of {@link EnumAttributeOptions}, including the allowed values, configuration options such as metadata attributes and additional property characteristics.
|
|
17
|
+
* @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 enum values.
|
|
18
|
+
*
|
|
19
|
+
* Usage example:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* class Product extends BaseEntity {
|
|
22
|
+
* @EnumAttribute({ alias: 'SomeField', values: ["val-1", "val-2"] })
|
|
23
|
+
* public someField: "val-1" | "val-2"; // Attribute representing the union/enum types specified in `values`. In this case the only allowed values are "val-1" and "val-2"
|
|
24
|
+
*
|
|
25
|
+
* @EnumAttribute({ alias: 'MyNullableField', nullable: true, values: ["val-1", "val-2"] })
|
|
26
|
+
* public myNullableField?: "val-1" | "val-2"; // Set to Optional for nullable attributes
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function EnumAttribute<T extends DynaRecord, const K extends P["values"][number], const P extends EnumAttributeOptions>(props: P): (_value: undefined, context: AttributeDecoratorContext<T, K, P>) => void;
|
|
31
|
+
export default EnumAttribute;
|
|
32
|
+
//# sourceMappingURL=EnumAttribute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnumAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/EnumAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAG5D,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,aAAa,CACpB,CAAC,SAAS,UAAU,EACpB,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EACnC,KAAK,CAAC,CAAC,SAAS,oBAAoB,EACpC,KAAK,EAAE,CAAC,YAEE,SAAS,WACR,0BAA0B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAe9C;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 zod_1 = require("zod");
|
|
7
|
+
const metadata_1 = __importDefault(require("../../metadata"));
|
|
8
|
+
/**
|
|
9
|
+
* A decorator for marking class fields as enum attributes within the context of a single-table design entity. Only the types specified in `values` are allowed via both the type system and runtime schema checks.
|
|
10
|
+
*
|
|
11
|
+
* This enforces a union type of the specified fields listed in `values`
|
|
12
|
+
*
|
|
13
|
+
* @template T The entity the decorator is applied to.
|
|
14
|
+
* @template K The type of the attribute, restricted to the values listed in `values` prop of EnumAttributeOptions
|
|
15
|
+
* @param props An optional object of {@link EnumAttributeOptions}, including the allowed values, configuration options such as metadata attributes and additional property characteristics.
|
|
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 enum values.
|
|
17
|
+
*
|
|
18
|
+
* Usage example:
|
|
19
|
+
* ```typescript
|
|
20
|
+
* class Product extends BaseEntity {
|
|
21
|
+
* @EnumAttribute({ alias: 'SomeField', values: ["val-1", "val-2"] })
|
|
22
|
+
* public someField: "val-1" | "val-2"; // Attribute representing the union/enum types specified in `values`. In this case the only allowed values are "val-1" and "val-2"
|
|
23
|
+
*
|
|
24
|
+
* @EnumAttribute({ alias: 'MyNullableField', nullable: true, values: ["val-1", "val-2"] })
|
|
25
|
+
* public myNullableField?: "val-1" | "val-2"; // Set to Optional for nullable attributes
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function EnumAttribute(props) {
|
|
30
|
+
return function (_value, context) {
|
|
31
|
+
if (context.kind === "field") {
|
|
32
|
+
context.addInitializer(function () {
|
|
33
|
+
const entity = Object.getPrototypeOf(this);
|
|
34
|
+
metadata_1.default.addEntityAttribute(entity.constructor.name, {
|
|
35
|
+
attributeName: context.name.toString(),
|
|
36
|
+
nullable: props?.nullable,
|
|
37
|
+
type: zod_1.z.enum(props.values),
|
|
38
|
+
...props
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.default = EnumAttribute;
|
|
@@ -5,5 +5,6 @@ export { default as DateAttribute } from "./DateAttribute";
|
|
|
5
5
|
export { default as StringAttribute } from "./StringAttribute";
|
|
6
6
|
export { default as BooleanAttribute } from "./BooleanAttribute";
|
|
7
7
|
export { default as NumberAttribute } from "./NumberAttribute";
|
|
8
|
+
export { default as EnumAttribute } from "./EnumAttribute";
|
|
8
9
|
export * from "./serializers";
|
|
9
10
|
//# 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,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"}
|
|
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,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,cAAc,eAAe,CAAC"}
|
|
@@ -17,7 +17,7 @@ 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.NumberAttribute = exports.BooleanAttribute = exports.StringAttribute = exports.DateAttribute = exports.ForeignKeyAttribute = exports.SortKeyAttribute = exports.PartitionKeyAttribute = void 0;
|
|
20
|
+
exports.EnumAttribute = exports.NumberAttribute = exports.BooleanAttribute = exports.StringAttribute = exports.DateAttribute = exports.ForeignKeyAttribute = exports.SortKeyAttribute = exports.PartitionKeyAttribute = void 0;
|
|
21
21
|
var PartitionKeyAttribute_1 = require("./PartitionKeyAttribute");
|
|
22
22
|
Object.defineProperty(exports, "PartitionKeyAttribute", { enumerable: true, get: function () { return __importDefault(PartitionKeyAttribute_1).default; } });
|
|
23
23
|
var SortKeyAttribute_1 = require("./SortKeyAttribute");
|
|
@@ -32,4 +32,6 @@ var BooleanAttribute_1 = require("./BooleanAttribute");
|
|
|
32
32
|
Object.defineProperty(exports, "BooleanAttribute", { enumerable: true, get: function () { return __importDefault(BooleanAttribute_1).default; } });
|
|
33
33
|
var NumberAttribute_1 = require("./NumberAttribute");
|
|
34
34
|
Object.defineProperty(exports, "NumberAttribute", { enumerable: true, get: function () { return __importDefault(NumberAttribute_1).default; } });
|
|
35
|
+
var EnumAttribute_1 = require("./EnumAttribute");
|
|
36
|
+
Object.defineProperty(exports, "EnumAttribute", { enumerable: true, get: function () { return __importDefault(EnumAttribute_1).default; } });
|
|
35
37
|
__exportStar(require("./serializers"), exports);
|
|
@@ -7,7 +7,7 @@ import type { NativeScalarAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
export declare const dateSerializer: {
|
|
10
|
-
toEntityAttribute: (val: NativeScalarAttributeValue) => number | bigint | boolean |
|
|
10
|
+
toEntityAttribute: (val: NativeScalarAttributeValue) => number | bigint | boolean | import("@aws-sdk/util-dynamodb").NumberValue | ArrayBuffer | Blob | DataView | Date | null | undefined;
|
|
11
11
|
toTableAttribute: (val?: Date) => string | undefined;
|
|
12
12
|
};
|
|
13
13
|
//# sourceMappingURL=serializers.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AttributeMetadata, type AttributeMetadataStorage, type RelationshipMetadataStorage } from ".";
|
|
2
2
|
import type DynaRecord from "../DynaRecord";
|
|
3
|
+
import { type EntityDefinedAttributes } from "../operations";
|
|
3
4
|
type EntityClass = new (...args: any) => DynaRecord;
|
|
4
5
|
/**
|
|
5
6
|
* Represents metadata for an entity within the ORM system, encapsulating information about the entity's attributes, relationships, and its associated database table.
|
|
@@ -39,20 +40,25 @@ declare class EntityMetadata {
|
|
|
39
40
|
*/
|
|
40
41
|
addAttribute(attrMeta: AttributeMetadata): void;
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
+
* Parse raw entity defined attributes (not reserved/relationship attributes) from input and ensure they are entity defined attributes.
|
|
44
|
+
* Any reserved attributes such as primary key, sort key, id, type ,createdAt, updatedAt etc will be omitted.
|
|
45
|
+
* If any attributes do not match their schema, a ValidationError is thrown
|
|
43
46
|
* @param attributes
|
|
44
47
|
*/
|
|
45
|
-
|
|
48
|
+
parseRawEntityDefinedAttributes(attributes: EntityDefinedAttributes<DynaRecord>): EntityDefinedAttributes<DynaRecord>;
|
|
46
49
|
/**
|
|
47
|
-
*
|
|
50
|
+
* Partial parse raw entity defined attributes (not reserved/relationship attributes) from input and ensure they are entity defined attributes.
|
|
51
|
+
* This is similar to `parseRawEntityDefinedAttributes` but will do a partial validation, only validating the entity defined attributes that are present and not rejected if fields are missing.
|
|
52
|
+
* Any reserved attributes such as primary key, sort key, id, type ,createdAt, updatedAt etc will be omitted.
|
|
53
|
+
* If any attributes do not match their schema, a ValidationError is thrown
|
|
48
54
|
* @param attributes
|
|
49
55
|
*/
|
|
50
|
-
|
|
56
|
+
parseRawEntityDefinedAttributesPartial(attributes: Partial<EntityDefinedAttributes<DynaRecord>>): Partial<EntityDefinedAttributes<DynaRecord>>;
|
|
51
57
|
/**
|
|
52
|
-
*
|
|
58
|
+
* Build validation errors with the cause
|
|
53
59
|
* @param error
|
|
54
60
|
*/
|
|
55
|
-
private
|
|
61
|
+
private buildValidationError;
|
|
56
62
|
}
|
|
57
63
|
export default EntityMetadata;
|
|
58
64
|
//# sourceMappingURL=EntityMetadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAE5C,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAG7D,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;;;;;OAKG;IACI,+BAA+B,CACpC,UAAU,EAAE,uBAAuB,CAAC,UAAU,CAAC,GAC9C,uBAAuB,CAAC,UAAU,CAAC;IAatC;;;;;;OAMG;IACI,sCAAsC,CAC3C,UAAU,EAAE,OAAO,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC,GACvD,OAAO,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC;IAgB/C;;;OAGG;IACH,OAAO,CAAC,oBAAoB;CAK7B;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const zod_1 = require("zod");
|
|
4
7
|
const errors_1 = require("../errors");
|
|
8
|
+
const _1 = __importDefault(require("."));
|
|
5
9
|
/**
|
|
6
10
|
* Represents metadata for an entity within the ORM system, encapsulating information about the entity's attributes, relationships, and its associated database table.
|
|
7
11
|
*
|
|
@@ -61,42 +65,52 @@ class EntityMetadata {
|
|
|
61
65
|
this.#zodAttributes[attrMeta.name] = attrMeta.type;
|
|
62
66
|
}
|
|
63
67
|
/**
|
|
64
|
-
*
|
|
68
|
+
* Parse raw entity defined attributes (not reserved/relationship attributes) from input and ensure they are entity defined attributes.
|
|
69
|
+
* Any reserved attributes such as primary key, sort key, id, type ,createdAt, updatedAt etc will be omitted.
|
|
70
|
+
* If any attributes do not match their schema, a ValidationError is thrown
|
|
65
71
|
* @param attributes
|
|
66
72
|
*/
|
|
67
|
-
|
|
73
|
+
parseRawEntityDefinedAttributes(attributes) {
|
|
68
74
|
if (this.#schema === undefined) {
|
|
69
|
-
|
|
75
|
+
const tableMeta = _1.default.getTable(this.tableClassName);
|
|
76
|
+
this.#schema = zod_1.z.object(this.#zodAttributes).omit(tableMeta.reservedKeys);
|
|
70
77
|
}
|
|
71
78
|
try {
|
|
72
|
-
this.#schema.parse(attributes);
|
|
79
|
+
return this.#schema.parse(attributes);
|
|
73
80
|
}
|
|
74
81
|
catch (error) {
|
|
75
|
-
this.
|
|
82
|
+
throw this.buildValidationError(error);
|
|
76
83
|
}
|
|
77
84
|
}
|
|
78
85
|
/**
|
|
79
|
-
*
|
|
86
|
+
* Partial parse raw entity defined attributes (not reserved/relationship attributes) from input and ensure they are entity defined attributes.
|
|
87
|
+
* This is similar to `parseRawEntityDefinedAttributes` but will do a partial validation, only validating the entity defined attributes that are present and not rejected if fields are missing.
|
|
88
|
+
* Any reserved attributes such as primary key, sort key, id, type ,createdAt, updatedAt etc will be omitted.
|
|
89
|
+
* If any attributes do not match their schema, a ValidationError is thrown
|
|
80
90
|
* @param attributes
|
|
81
91
|
*/
|
|
82
|
-
|
|
92
|
+
parseRawEntityDefinedAttributesPartial(attributes) {
|
|
83
93
|
if (this.#schemaPartial === undefined) {
|
|
84
|
-
|
|
94
|
+
const tableMeta = _1.default.getTable(this.tableClassName);
|
|
95
|
+
this.#schemaPartial = zod_1.z
|
|
96
|
+
.object(this.#zodAttributes)
|
|
97
|
+
.omit(tableMeta.reservedKeys)
|
|
98
|
+
.partial();
|
|
85
99
|
}
|
|
86
100
|
try {
|
|
87
|
-
this.#schemaPartial.parse(attributes);
|
|
101
|
+
return this.#schemaPartial.parse(attributes);
|
|
88
102
|
}
|
|
89
103
|
catch (error) {
|
|
90
|
-
this.
|
|
104
|
+
throw this.buildValidationError(error);
|
|
91
105
|
}
|
|
92
106
|
}
|
|
93
107
|
/**
|
|
94
|
-
*
|
|
108
|
+
* Build validation errors with the cause
|
|
95
109
|
* @param error
|
|
96
110
|
*/
|
|
97
|
-
|
|
111
|
+
buildValidationError(error) {
|
|
98
112
|
const errorOptions = error instanceof zod_1.ZodError ? { cause: error.issues } : undefined;
|
|
99
|
-
|
|
113
|
+
return new errors_1.ValidationError("Validation errors", errorOptions);
|
|
100
114
|
}
|
|
101
115
|
}
|
|
102
116
|
exports.default = EntityMetadata;
|
|
@@ -31,6 +31,24 @@ declare class TableMetadata {
|
|
|
31
31
|
readonly defaultTableAttributes: Record<string, AttributeMetadata>;
|
|
32
32
|
partitionKeyAttribute: AttributeMetadata;
|
|
33
33
|
sortKeyAttribute: AttributeMetadata;
|
|
34
|
+
/**
|
|
35
|
+
* Represents the keys that should be excluded from schema validation.
|
|
36
|
+
* These keys are reserved by dyna-record and should be managed internally.
|
|
37
|
+
*
|
|
38
|
+
* While dyna-record employs type guards to prevent the setting of these keys,
|
|
39
|
+
* this ensures additional runtime validation.
|
|
40
|
+
*
|
|
41
|
+
* The reserved keys include:
|
|
42
|
+
* - pk
|
|
43
|
+
* - sk
|
|
44
|
+
* - id
|
|
45
|
+
* - type
|
|
46
|
+
* - createdAt
|
|
47
|
+
* - updatedAt
|
|
48
|
+
* - foreignKey
|
|
49
|
+
* - foreignEntityType
|
|
50
|
+
*/
|
|
51
|
+
reservedKeys: Record<string, true>;
|
|
34
52
|
constructor(options: TableMetadataOptions);
|
|
35
53
|
/**
|
|
36
54
|
* Creates default attribute metadata. Use {@link tableDefaultFields} unless consuming table decorator specifies overrides
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/TableMetadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAA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iBAAiB,CAAC,CAAC;IACnE,qBAAqB,EAAE,iBAAiB,CAAC;IACzC,gBAAgB,EAAE,iBAAiB,CAAC;IAE3C;;;;;;;;;;;;;;;;OAgBG;IACI,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAE9B,OAAO,EAAE,oBAAoB;IA8BzC;;;;OAIG;IACH,OAAO,CAAC,8BAA8B;IAgCtC;;;OAGG;IACI,wBAAwB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;IAO5E;;;OAGG;IACI,mBAAmB,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;CAMxE;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -37,6 +37,24 @@ class TableMetadata {
|
|
|
37
37
|
defaultTableAttributes;
|
|
38
38
|
partitionKeyAttribute;
|
|
39
39
|
sortKeyAttribute;
|
|
40
|
+
/**
|
|
41
|
+
* Represents the keys that should be excluded from schema validation.
|
|
42
|
+
* These keys are reserved by dyna-record and should be managed internally.
|
|
43
|
+
*
|
|
44
|
+
* While dyna-record employs type guards to prevent the setting of these keys,
|
|
45
|
+
* this ensures additional runtime validation.
|
|
46
|
+
*
|
|
47
|
+
* The reserved keys include:
|
|
48
|
+
* - pk
|
|
49
|
+
* - sk
|
|
50
|
+
* - id
|
|
51
|
+
* - type
|
|
52
|
+
* - createdAt
|
|
53
|
+
* - updatedAt
|
|
54
|
+
* - foreignKey
|
|
55
|
+
* - foreignEntityType
|
|
56
|
+
*/
|
|
57
|
+
reservedKeys;
|
|
40
58
|
constructor(options) {
|
|
41
59
|
const defaultAttrMeta = this.buildDefaultAttributesMetadata(options);
|
|
42
60
|
this.name = options.name;
|
|
@@ -58,6 +76,9 @@ class TableMetadata {
|
|
|
58
76
|
serializers: { toEntityAttribute: () => "", toTableAttribute: () => "" },
|
|
59
77
|
type: zod_1.z.string()
|
|
60
78
|
};
|
|
79
|
+
const defaultAttrNames = Object.keys(this.defaultAttributes);
|
|
80
|
+
// Set the default keys as reserved keys, the user defined primary and sort key are set later
|
|
81
|
+
this.reservedKeys = Object.fromEntries(defaultAttrNames.map(key => [key, true]));
|
|
61
82
|
}
|
|
62
83
|
/**
|
|
63
84
|
* Creates default attribute metadata. Use {@link tableDefaultFields} unless consuming table decorator specifies overrides
|
|
@@ -91,6 +112,8 @@ class TableMetadata {
|
|
|
91
112
|
addPartitionKeyAttribute(options) {
|
|
92
113
|
const opts = { ...options, nullable: false };
|
|
93
114
|
this.partitionKeyAttribute = new _1.AttributeMetadata(opts);
|
|
115
|
+
// Set the user defined primary key as reserved key so that its managed by dyna-record
|
|
116
|
+
this.reservedKeys[options.attributeName] = true;
|
|
94
117
|
}
|
|
95
118
|
/**
|
|
96
119
|
* Adds the sort key attribute to Table metadata storage
|
|
@@ -99,6 +122,8 @@ class TableMetadata {
|
|
|
99
122
|
addSortKeyAttribute(options) {
|
|
100
123
|
const opts = { ...options, nullable: false };
|
|
101
124
|
this.sortKeyAttribute = new _1.AttributeMetadata(opts);
|
|
125
|
+
// Set the user defined primary key as reserved key so that its managed by dyna-record
|
|
126
|
+
this.reservedKeys[options.attributeName] = true;
|
|
102
127
|
}
|
|
103
128
|
}
|
|
104
129
|
exports.default = TableMetadata;
|
|
@@ -35,9 +35,11 @@ export type JoinTableMetadataStorage = Record<string, JoinTableMetadata[]>;
|
|
|
35
35
|
*/
|
|
36
36
|
export type DefaultDateFields = "createdAt" | "updatedAt";
|
|
37
37
|
/**
|
|
38
|
-
* Specifies the default fields used in entities, including fields from `DynaRecord` or `BelongsToLink`.
|
|
38
|
+
* Specifies the default fields used in entities, including fields from `DynaRecord` or `BelongsToLink`. Instance methods are excluded
|
|
39
39
|
*/
|
|
40
|
-
export type DefaultFields =
|
|
40
|
+
export type DefaultFields = {
|
|
41
|
+
[K in keyof DynaRecord]: DynaRecord[K] extends (...args: any[]) => any ? never : K;
|
|
42
|
+
}[keyof DynaRecord] | keyof BelongsToLink;
|
|
41
43
|
/**
|
|
42
44
|
* Defines the structure for default fields within a table, mapping field names to their `AttributeMetadata` aliases.
|
|
43
45
|
*/
|
|
@@ -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;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,
|
|
1
|
+
{"version":3,"file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G,GAClE,KAAK,GACL,CAAC;CACN,CAAC,MAAM,UAAU,CAAC,GACnB,MAAM,aAAa,CAAC;AAExB;;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"}
|
|
@@ -8,6 +8,8 @@ import { type EntityAttributes } from "../types";
|
|
|
8
8
|
*
|
|
9
9
|
* It encapsulates the logic required to translate entity attributes to a format suitable for DynamoDB, execute the creation transaction, and manage any relationships defined by the entity, such as "BelongsTo" or "HasMany" links.
|
|
10
10
|
*
|
|
11
|
+
* Only attributes defined on the model can be configured, and will be enforced via types and runtime schema validation.
|
|
12
|
+
*
|
|
11
13
|
* @template T - The type of the entity being created, extending `DynaRecord`.
|
|
12
14
|
*/
|
|
13
15
|
declare class Create<T extends DynaRecord> extends OperationBase<T> {
|
|
@@ -24,7 +26,7 @@ declare class Create<T extends DynaRecord> extends OperationBase<T> {
|
|
|
24
26
|
* @param attributes
|
|
25
27
|
* @returns
|
|
26
28
|
*/
|
|
27
|
-
private
|
|
29
|
+
private buildReservedAttributes;
|
|
28
30
|
/**
|
|
29
31
|
* Build the transaction for the parent entity Create item request
|
|
30
32
|
* @param tableItem
|
|
@@ -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,
|
|
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,EAEL,KAAK,gBAAgB,EACtB,MAAM,UAAU,CAAC;AAGlB;;;;;;;;GAQG;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;IAiB5E;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAsB/B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAW/B;;;OAGG;YACW,6BAA6B;CAU5C;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -14,6 +14,8 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
14
14
|
*
|
|
15
15
|
* It encapsulates the logic required to translate entity attributes to a format suitable for DynamoDB, execute the creation transaction, and manage any relationships defined by the entity, such as "BelongsTo" or "HasMany" links.
|
|
16
16
|
*
|
|
17
|
+
* Only attributes defined on the model can be configured, and will be enforced via types and runtime schema validation.
|
|
18
|
+
*
|
|
17
19
|
* @template T - The type of the entity being created, extending `DynaRecord`.
|
|
18
20
|
*/
|
|
19
21
|
class Create extends OperationBase_1.default {
|
|
@@ -28,9 +30,10 @@ class Create extends OperationBase_1.default {
|
|
|
28
30
|
* @returns
|
|
29
31
|
*/
|
|
30
32
|
async run(attributes) {
|
|
31
|
-
const entityData = this.buildEntityData(attributes);
|
|
32
33
|
const entityMeta = metadata_1.default.getEntity(this.EntityClass.name);
|
|
33
|
-
entityMeta.
|
|
34
|
+
const entityAttrs = entityMeta.parseRawEntityDefinedAttributes(attributes);
|
|
35
|
+
const reservedAttrs = this.buildReservedAttributes();
|
|
36
|
+
const entityData = { ...reservedAttrs, ...entityAttrs };
|
|
34
37
|
const tableItem = (0, utils_1.entityToTableItem)(this.EntityClass, entityData);
|
|
35
38
|
this.buildPutItemTransaction(tableItem);
|
|
36
39
|
await this.buildRelationshipTransactions(entityData);
|
|
@@ -42,7 +45,7 @@ class Create extends OperationBase_1.default {
|
|
|
42
45
|
* @param attributes
|
|
43
46
|
* @returns
|
|
44
47
|
*/
|
|
45
|
-
|
|
48
|
+
buildReservedAttributes() {
|
|
46
49
|
const id = (0, uuid_1.v4)();
|
|
47
50
|
const createdAt = new Date();
|
|
48
51
|
const pk = this.tableMetadata.partitionKeyAttribute.name;
|
|
@@ -57,7 +60,7 @@ class Create extends OperationBase_1.default {
|
|
|
57
60
|
createdAt,
|
|
58
61
|
updatedAt: createdAt
|
|
59
62
|
};
|
|
60
|
-
return { ...keys, ...
|
|
63
|
+
return { ...keys, ...defaultAttrs };
|
|
61
64
|
}
|
|
62
65
|
/**
|
|
63
66
|
* Build the transaction for the parent entity Create item request
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { QueryItems } from "../../dynamo-utils";
|
|
2
2
|
import type DynaRecord from "../../DynaRecord";
|
|
3
|
-
import type { EntityAttributes, RelationshipAttributeNames } from "../types";
|
|
3
|
+
import type { EntityAttributes, FunctionFields, RelationshipAttributeNames } from "../types";
|
|
4
4
|
import type { BelongsToLinkDynamoItem } from "../../types";
|
|
5
5
|
/**
|
|
6
6
|
* Defines options for the `FindById` operation, allowing specification of additional associations to include in the query result.
|
|
@@ -52,6 +52,6 @@ type EntityKeysWithIncludedAssociations<T extends DynaRecord, P extends keyof T>
|
|
|
52
52
|
* @template T - The type of the main entity, extending `DynaRecord`.
|
|
53
53
|
* @template Opts - The options for the `FindById` operation, specifying included associations.
|
|
54
54
|
*/
|
|
55
|
-
export type FindByIdIncludesRes<T extends DynaRecord, Opts extends FindByIdOptions<T>> = EntityKeysWithIncludedAssociations<T, keyof EntityAttributes<T> | IncludedKeys<T, Opts>>;
|
|
55
|
+
export type FindByIdIncludesRes<T extends DynaRecord, Opts extends FindByIdOptions<T>> = EntityKeysWithIncludedAssociations<T, keyof EntityAttributes<T> | IncludedKeys<T, Opts> | FunctionFields<T>>;
|
|
56
56
|
export {};
|
|
57
57
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,UAA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AC,CAAC,CAAC,SAAS,UAAU,GAC7B,gBAAgB,CAAC,CAAC,CAAC,GACnB,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,EAAE,GACvB,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GACrC,CAAC,CAAC,CAAC,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,CAC7B,CAAC,SAAS,UAAU,EACpB,IAAI,SAAS,eAAe,CAAC,CAAC,CAAC,IAC7B,kCAAkC,CACpC,CAAC,EACD,MAAM,gBAAgB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CACtE,CAAC"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type DynaRecord from "../../DynaRecord";
|
|
2
2
|
import OperationBase from "../OperationBase";
|
|
3
|
-
import type { UpdateOptions } from "./types";
|
|
3
|
+
import type { UpdatedAttributes, UpdateOptions } from "./types";
|
|
4
4
|
import type { EntityClass } from "../../types";
|
|
5
5
|
/**
|
|
6
6
|
* 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
|
|
7
7
|
*
|
|
8
8
|
* The `Update` operation supports updating entity attributes and ensures consistency in relationships, especially for "BelongsTo" relationships. It handles the complexity of managing foreign keys and associated "BelongsToLink" records, including creating new links for updated relationships and removing outdated links when necessary.
|
|
9
9
|
*
|
|
10
|
+
* Only attributes defined on the model can be configured, and will be enforced via types and runtime schema validation.
|
|
11
|
+
*
|
|
10
12
|
* @template T - The type of the entity being updated, extending `DynaRecord`.
|
|
11
13
|
*/
|
|
12
14
|
declare class Update<T extends DynaRecord> extends OperationBase<T> {
|
|
@@ -17,7 +19,7 @@ declare class Update<T extends DynaRecord> extends OperationBase<T> {
|
|
|
17
19
|
* @param id The id of the entity being updated
|
|
18
20
|
* @param attributes Attributes on the model to update.
|
|
19
21
|
*/
|
|
20
|
-
run(id: string, attributes: UpdateOptions<T>): Promise<
|
|
22
|
+
run(id: string, attributes: UpdateOptions<T>): Promise<UpdatedAttributes<T>>;
|
|
21
23
|
/**
|
|
22
24
|
* Build the transaction to update the entity
|
|
23
25
|
* @param id The id of the entity being updated
|
|
@@ -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;
|
|
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,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C;;;;;;;;GAQG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAK7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;OAIG;IACU,GAAG,CACd,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAahC;;;;OAIG;IACH,OAAO,CAAC,0BAA0B;IAoClC;;;;;;OAMG;YACW,6BAA6B;IAsB3C;;;;;OAKG;IACH,OAAO,CAAC,sCAAsC;IAyB9C;;OAEG;YACW,SAAS;CAOxB;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -13,6 +13,8 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
13
13
|
*
|
|
14
14
|
* The `Update` operation supports updating entity attributes and ensures consistency in relationships, especially for "BelongsTo" relationships. It handles the complexity of managing foreign keys and associated "BelongsToLink" records, including creating new links for updated relationships and removing outdated links when necessary.
|
|
15
15
|
*
|
|
16
|
+
* Only attributes defined on the model can be configured, and will be enforced via types and runtime schema validation.
|
|
17
|
+
*
|
|
16
18
|
* @template T - The type of the entity being updated, extending `DynaRecord`.
|
|
17
19
|
*/
|
|
18
20
|
class Update extends OperationBase_1.default {
|
|
@@ -29,10 +31,11 @@ class Update extends OperationBase_1.default {
|
|
|
29
31
|
*/
|
|
30
32
|
async run(id, attributes) {
|
|
31
33
|
const entityMeta = metadata_1.default.getEntity(this.EntityClass.name);
|
|
32
|
-
entityMeta.
|
|
33
|
-
this.buildUpdateItemTransaction(id,
|
|
34
|
-
await this.buildRelationshipTransactions(id,
|
|
34
|
+
const entityAttrs = entityMeta.parseRawEntityDefinedAttributesPartial(attributes);
|
|
35
|
+
const updatedAttrs = this.buildUpdateItemTransaction(id, entityAttrs);
|
|
36
|
+
await this.buildRelationshipTransactions(id, entityAttrs);
|
|
35
37
|
await this.#transactionBuilder.executeTransaction();
|
|
38
|
+
return updatedAttrs;
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
41
|
* Build the transaction to update the entity
|
|
@@ -60,6 +63,7 @@ class Update extends OperationBase_1.default {
|
|
|
60
63
|
ConditionExpression: `attribute_exists(${this.partitionKeyAlias})`, // Only update the item if it exists
|
|
61
64
|
...expression
|
|
62
65
|
}, `${this.EntityClass.name} with ID '${id}' does not exist`);
|
|
66
|
+
return updatedAttrs;
|
|
63
67
|
}
|
|
64
68
|
/**
|
|
65
69
|
* Builds the transactions to persist relationships
|
|
@@ -28,5 +28,9 @@ type AllowNullForNullable<T> = {
|
|
|
28
28
|
* })
|
|
29
29
|
*/
|
|
30
30
|
export type UpdateOptions<T extends DynaRecord> = Partial<AllowNullForNullable<EntityDefinedAttributes<T>>>;
|
|
31
|
+
/**
|
|
32
|
+
* Attributes of an entity that were updated. Including the auto generated updatedAt date
|
|
33
|
+
*/
|
|
34
|
+
export type UpdatedAttributes<T extends DynaRecord> = Pick<Partial<T>, "updatedAt">;
|
|
31
35
|
export {};
|
|
32
36
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Update/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;GAKG;AACH,KAAK,kBAAkB,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACnD,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX;;;;;GAKG;AACH,KAAK,oBAAoB,CAAC,CAAC,IAAI;KAC5B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;CACrE,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI,OAAO,CACvD,oBAAoB,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CACjD,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Update/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;GAKG;AACH,KAAK,kBAAkB,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACnD,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX;;;;;GAKG;AACH,KAAK,oBAAoB,CAAC,CAAC,IAAI;KAC5B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;CACrE,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI,OAAO,CACvD,oBAAoB,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,UAAU,IAAI,IAAI,CACxD,OAAO,CAAC,CAAC,CAAC,EACV,WAAW,CACZ,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type DynaRecord from "../DynaRecord";
|
|
2
|
+
import { type DefaultFields } from "../metadata";
|
|
2
3
|
import type { ForeignKey, NullableForeignKey, Optional, PartitionKey, SortKey } from "../types";
|
|
3
4
|
/**
|
|
4
5
|
* Represents the type of the partition key attribute for a given entity. It identifies the specific property of the entity that is marked as the partition key, which uniquely identifies each instance of the entity in the database.
|
|
@@ -25,7 +26,7 @@ export type SortKeyAttribute<T> = {
|
|
|
25
26
|
* @returns The names of the function properties as strings if any exist; otherwise, the result is `never`.
|
|
26
27
|
*/
|
|
27
28
|
export type FunctionFields<T> = {
|
|
28
|
-
[K in keyof T]: T[K] extends
|
|
29
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
|
|
29
30
|
}[keyof T];
|
|
30
31
|
/**
|
|
31
32
|
* Allow ForeignKey attributes to be passes to the create method by using their inferred primitive type
|
|
@@ -46,7 +47,11 @@ export type RelationshipAttributeNames<T> = {
|
|
|
46
47
|
/**
|
|
47
48
|
* Entity attributes excluding relationship attributes
|
|
48
49
|
*/
|
|
49
|
-
export type EntityAttributes<T extends DynaRecord> = Omit<T, RelationshipAttributeNames<T>>;
|
|
50
|
+
export type EntityAttributes<T extends DynaRecord> = Omit<T, RelationshipAttributeNames<T> | FunctionFields<T>>;
|
|
51
|
+
/**
|
|
52
|
+
* Entity attributes for default fields
|
|
53
|
+
*/
|
|
54
|
+
export type EntityAttributeDefaultFields = Pick<DynaRecord, Extract<keyof DynaRecord, DefaultFields>>;
|
|
50
55
|
/**
|
|
51
56
|
* Attributes that are defined on the Entity using the attribute decorators. This excludes:
|
|
52
57
|
* - relationship attributes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/operations/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,YAAY,EACZ,OAAO,EACR,MAAM,UAAU,CAAC;AAElB;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAAI;KACpC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,GAAG,CAAC,GAAG,KAAK;CACtD,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;KAC/B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,GAAG,CAAC,GAAG,KAAK;CACjD,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX;;;;;GAKG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/operations/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,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ACV,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,UAAU,IAAI,IAAI,CACvD,CAAC,EACD,0BAA0B,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAC7C,UAAU,EACV,OAAO,CAAC,MAAM,UAAU,EAAE,aAAa,CAAC,CACzC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,uBAAuB,CAAC,CAAC,SAAS,UAAU,IAAI,IAAI,CAC9D,iBAAiB,CAAC,CAAC,CAAC,EAClB,MAAM,UAAU,GAChB,0BAA0B,CAAC,CAAC,CAAC,GAC7B,cAAc,CAAC,CAAC,CAAC,GACjB,qBAAqB,CAAC,CAAC,CAAC,GACxB,gBAAgB,CAAC,CAAC,CAAC,CACtB,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type DynaRecord from "../DynaRecord";
|
|
2
2
|
import type { ForeignKey } from "../types";
|
|
3
|
+
import type { EntityAttributes } from "../operations";
|
|
3
4
|
/**
|
|
4
5
|
* Extends `DynaRecord` with properties specific to "BelongsTo" relationships, such as `foreignEntityType` and `foreignKey`.
|
|
5
6
|
*/
|
|
6
|
-
interface BelongsToLinkProps extends DynaRecord {
|
|
7
|
+
interface BelongsToLinkProps extends EntityAttributes<DynaRecord> {
|
|
7
8
|
foreignEntityType: string;
|
|
8
9
|
foreignKey: string;
|
|
9
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BelongsToLink.d.ts","sourceRoot":"","sources":["../../../src/relationships/BelongsToLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"BelongsToLink.d.ts","sourceRoot":"","sources":["../../../src/relationships/BelongsToLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;GAEG;AACH,UAAU,kBAAmB,SAAQ,gBAAgB,CAAC,UAAU,CAAC;IAC/D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,cAAM,aAAc,YAAW,kBAAkB;IAC/C;;OAEG;IACH,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B;;OAEG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,SAAgB,iBAAiB,EAAE,MAAM,CAAC;IAC1C;;OAEG;IACH,SAAgB,UAAU,EAAE,UAAU,CAAC;IACvC;;OAEG;IACH,SAAgB,SAAS,EAAE,IAAI,CAAC;IAChC;;OAEG;IACH,SAAgB,SAAS,EAAE,IAAI,CAAC;gBAEpB,IAAI,CAAC,EAAE,aAAa;IAMhC;;;;;OAKG;WACW,KAAK,CACjB,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,GACjB,kBAAkB;CAYtB;AAED,eAAe,aAAa,CAAC"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type DynaRecord from "./DynaRecord";
|
|
|
2
2
|
import type { DynamoTableItem, BelongsToLinkDynamoItem } from "./types";
|
|
3
3
|
import { type TableMetadata } from "./metadata";
|
|
4
4
|
import { BelongsToLink } from "./relationships";
|
|
5
|
+
import { type EntityAttributes } from "./operations";
|
|
5
6
|
/**
|
|
6
7
|
* Convert an entity to its aliased table item fields to for dynamo interactions
|
|
7
8
|
* @param entityClassName
|
|
@@ -16,6 +17,10 @@ export declare const entityToTableItem: <T extends DynaRecord>(EntityClass: new
|
|
|
16
17
|
* @returns
|
|
17
18
|
*/
|
|
18
19
|
export declare const tableItemToEntity: <T extends DynaRecord>(EntityClass: new () => T, tableItem: DynamoTableItem) => T;
|
|
20
|
+
/**
|
|
21
|
+
* Create an instance of a dyna record class
|
|
22
|
+
*/
|
|
23
|
+
export declare const createInstance: <T extends DynaRecord>(EntityClass: new () => T, attributes: EntityAttributes<T>) => T;
|
|
19
24
|
/**
|
|
20
25
|
* Serialize a dynamo table item response to a BelongsToLink
|
|
21
26
|
* @param tableMeta - Table metadata
|
|
@@ -85,5 +90,5 @@ export declare const isString: (value: any) => value is string;
|
|
|
85
90
|
* let entity = { id: "123" };
|
|
86
91
|
* safeAssign(entity, "name", "Jane Doe");
|
|
87
92
|
*/
|
|
88
|
-
export declare const safeAssign: <TObject extends DynaRecord
|
|
93
|
+
export declare const safeAssign: <TObject extends EntityAttributes<DynaRecord>, TKey extends keyof TObject, TValue>(object: TObject, key: TKey, value: TValue) => void;
|
|
89
94
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AACxE,OAAiB,EAEf,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AACxE,OAAiB,EAEf,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,+DAEhB,QAAQ,UAAU,CAAC,KAC9B,eAmBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,8DAEjB,eAAe,MAwB3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,wFAa1B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,cACxB,aAAa,aACb,uBAAuB,KACjC,aA2BF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,WAChB,UAAU,OACb,MAAM,4BAGZ,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,cAChB,QAAQ,UAAU,CAAC,OACtB,GAAG,mBAGT,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAC/B,eAAe,aACT,aAAa,mCAGzB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,wBAAyB,MAAM,UAIrD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,UAAW,GAAG,yBAMvC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,UAAW,GAAG,oBAElC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,mIAQpB,IAEF,CAAC"}
|
package/dist/src/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
-
exports.safeAssign = exports.isString = exports.isPropertyKey = exports.chunkArray = exports.isBelongsToLinkDynamoItem = exports.isKeyOfObject = exports.isKeyOfEntity = exports.tableItemToBelongsToLink = exports.tableItemToEntity = exports.entityToTableItem = void 0;
|
|
6
|
+
exports.safeAssign = exports.isString = exports.isPropertyKey = exports.chunkArray = exports.isBelongsToLinkDynamoItem = exports.isKeyOfObject = exports.isKeyOfEntity = exports.tableItemToBelongsToLink = exports.createInstance = exports.tableItemToEntity = exports.entityToTableItem = void 0;
|
|
7
7
|
const metadata_1 = __importDefault(require("./metadata"));
|
|
8
8
|
const relationships_1 = require("./relationships");
|
|
9
9
|
/**
|
|
@@ -51,6 +51,19 @@ const tableItemToEntity = (EntityClass, tableItem) => {
|
|
|
51
51
|
return entity;
|
|
52
52
|
};
|
|
53
53
|
exports.tableItemToEntity = tableItemToEntity;
|
|
54
|
+
/**
|
|
55
|
+
* Create an instance of a dyna record class
|
|
56
|
+
*/
|
|
57
|
+
const createInstance = (EntityClass, attributes) => {
|
|
58
|
+
const entity = new EntityClass();
|
|
59
|
+
Object.entries(attributes).forEach(([attrName, val]) => {
|
|
60
|
+
if ((0, exports.isKeyOfEntity)(entity, attrName)) {
|
|
61
|
+
(0, exports.safeAssign)(entity, attrName, val);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return entity;
|
|
65
|
+
};
|
|
66
|
+
exports.createInstance = createInstance;
|
|
54
67
|
/**
|
|
55
68
|
* Serialize a dynamo table item response to a BelongsToLink
|
|
56
69
|
* @param tableMeta - Table metadata
|