-
I'm not 100% sure I understand why the typescript typing wants all index attributes when getting/patching and also why I can't update an index attribute when getting / patching. I guess im not sure why I need toknow all my With an entity definition like this: export const UserEntity = new Entity(
{
model: {
version: "1",
entity: "User",
service: "barqco",
},
attributes: {
user_id: { type: "string", required: true },
email: { type: "string", required: false },
last_known_instagram_username: { type: "string", required: false },
insta_remote_id: {
type: "string",
required: false,
},
},
indexes: {
user: {
pk: {
field: "pk",
composite: ["user_id"],
},
sk: {
field: "sk",
composite: [],
},
},
userByInstagramUsername: {
pk: {
index: "gsi1pk-index",
field: "gsi1pk",
composite: ["last_known_instagram_username"],
},
},
userByEmail: {
pk: {
index: "gsi1pk-index",
field: "gsi1pk",
composite: ["email"],
},
},
},
},
Dynamo.Configuration
); From typescript's perspective I can not get a user unless I pass in all the gsi attributes. but i'm pretty sure I only need the user_id based on this definition. At least from a dynamodb perspective. TS Error: const existingUser = await UserEntity.get({
user_id,
}).go(); No Error (But I may not know all these attributes) const existingUser = await UserEntity.get({
user_id,
email,
last_known_instagram_username
}).go(); Similarly I get an error when only passing in user_id when trying to patch await UserEntity.patch({
user_id,
})
.set({ last_known_instagram_username, insta_remote_id })
.go(); Is there something i'm doing wrong based on the typing's understanding? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @barqco 👋 This is because the schema provided is invalid:
The typing wierdness you're seeing is due to typescript being unable to infer the primary index composite because of #1 (it can't tell which which index is the primary index) Electro will throw at startup in these cases 👍 Here is a working schema: export const UserEntity = new Entity(
{
model: {
version: "1",
entity: "User",
service: "barqco",
},
attributes: {
user_id: { type: "string", required: true },
email: { type: "string", required: false },
last_known_instagram_username: { type: "string", required: false },
insta_remote_id: {
type: "string",
required: false,
},
},
indexes: {
user: {
pk: {
field: "pk",
composite: ["user_id"],
},
sk: {
field: "sk",
composite: [],
},
},
userByInstagramUsername: {
index: "gsi1pk-index",
pk: {
field: "gsi1pk",
composite: ["last_known_instagram_username"],
},
},
userByEmail: {
index: "gsi2pk-index",
pk: {
field: "gsi2pk",
composite: ["email"],
},
},
},
}
); |
Beta Was this translation helpful? Give feedback.
Hi @barqco 👋
This is because the schema provided is invalid:
userByEmail
anduserByInstagramUsername
The typing wierdness you're seeing is due to typescript being unable to infer the primary index composite because of #1 (it can't tell which which index is the primary index)
Electro will throw at startup in these cases 👍
Here is a working schema: