-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dyngoose + SST doesnt work #710
Comments
I have not tested it with SST, however, I hope to use SST for my next project so I will certainly look into this. |
Thank you! :) In the meantime, I'll try to debug this |
@benhutchins do you have any hint to track where |
There is no default dyngoose/src/decorator/primary-key.ts Line 3 in ed6e7cd
setPrimaryKey on the Scehma class. The Schema class eventually calls definePrimaryKeyProperty when constructing and assigns an instance of the Query.PrimaryKey object to the Table based on whatever property is used on the Table , some people call it pk or similar instead of primarKey . It is actually constructed and assigned onto the Table when the @Dyngoose.$Table() decorator gets calls, which happens after all the decorator on the properties are processed. See dyngoose/src/decorator/table.ts Line 16 in ed6e7cd
The Line 43 in ed6e7cd
Table .
Your DocumentClient creation in your example code is actually incorrect, you don't need to have the code below at all. @Dyngoose.$DocumentClient()
// i setted the value of this prop because you can't `put` items, because `documentClient` is undefined
static readonly documentClient: Dyngoose.DocumentClient<LogModel> =
new Dyngoose.DocumentClient(LogModel); // the actual object here will be overridden by the decorator, so instantiating the `new Dyngoose.DocumentClient` isn't necessary However, if you want to define a custom property for the document client you just need to do: @Dyngoose.$DocumentClient()
public static readonly documentClient: Dyngoose.DocumentClient<LogModel> And the decorator will assign the property for you. |
Excellent, thank you for the explanation! I think that the problem is when Model used import type { PostLogSchema } from "@/schemas/postLog.schema";
import * as Dyngoose from "dyngoose";
import { Resource } from "sst";
@Dyngoose.$Table({ name: Resource.log.name })
export class LogModel extends Dyngoose.Table {
@Dyngoose.Attribute.String()
public id: string;
@Dyngoose.$PrimaryKey("id")
static readonly primaryKey: Dyngoose.Query.PrimaryKey<LogModel, string>
} Code executed export async function getLogById(logId: string): Promise<LogModel> {
return await LogModel.primaryKey.get({ id: logId });
} Output
Tried logging the properties on |
SST uses an ES modules, since Dyngoose doesn't have I am sure this is where the issue is arising from. Hypothetically, you can import commonjs from an es module, but I've seen issues here before. Many projects today provide a different main export for cjs vs mjs. I imagine that is what Dyngoose needs to be updated with, since it uses TypeScript, the actual code changes to the typescript files shouldn't be dramatic but might need to define two separate tsconfigs and update the build process to build both. I'll see if I can get some time this week to take a look into this. |
Thank you! I'll try to fix this too. |
Breaking Change: this changes the import paths for Dyngoose Fixes #710
I'm not finished, however, I have a work in progress PR available #711 for review which adds esm support for Dyngoose. I will be performing more testing and will try to avoid a breaking change if possible (currently it is). |
Hello! I have a problem when using Dyngoose with SST. When using SST:
Model looks like this:
The text was updated successfully, but these errors were encountered: