Skip to content

Commit

Permalink
Merge pull request #47 from dsdavis4/create_return_type_fix
Browse files Browse the repository at this point in the history
Create return type fix
  • Loading branch information
dsdavis4 authored Jul 24, 2024
2 parents 93ecb32 + 19ca502 commit 9e71f25
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dyna-record",
"version": "0.0.18",
"version": "0.0.19",
"description": "Typescript Object Relational Mapper (ORM) for Dynamo",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/DynaRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ abstract class DynaRecord implements DynaRecordBase {
public static async create<T extends DynaRecord>(
this: EntityClass<T>,
attributes: CreateOptions<T>
): Promise<T> {
): Promise<ReturnType<Create<T>["run"]>> {
const op = new Create<T>(this);
return await op.run(attributes);
}
Expand Down
3 changes: 2 additions & 1 deletion src/operations/Create/Create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { entityToTableItem, tableItemToEntity } from "../../utils";
import OperationBase from "../OperationBase";
import { RelationshipTransactions } from "../utils";
import type { CreateOptions } from "./types";
import { type EntityAttributes } from "../types";

/**
* 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
Expand All @@ -27,7 +28,7 @@ class Create<T extends DynaRecord> extends OperationBase<T> {
* @param attributes
* @returns
*/
public async run(attributes: CreateOptions<T>): Promise<T> {
public async run(attributes: CreateOptions<T>): Promise<EntityAttributes<T>> {
const entityData = this.buildEntityData(attributes);

const tableItem = entityToTableItem(this.EntityClass, entityData);
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/Create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,5 +815,15 @@ describe("Create", () => {
myAttribute: null
});
});

it("relationships are not part of return value", async () => {
const res = await Order.create({
// @ts-expect-error default fields are not accepted on create, they are managed by dyna-record
createdAt: new Date()
});

// @ts-expect-error relationships are not part of return value
console.log(res.paymentMethod);
});
});
});

0 comments on commit 9e71f25

Please sign in to comment.