Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 Feature: Pass parameters as an object #728

Open
2 tasks done
dokgu opened this issue Oct 20, 2023 · 3 comments
Open
2 tasks done

馃殌 Feature: Pass parameters as an object #728

dokgu opened this issue Oct 20, 2023 · 3 comments

Comments

@dokgu
Copy link

dokgu commented Oct 20, 2023

馃敄 Feature description

Pass the parameters as an object - something like:

type CreateMembershipProps = {
  teamId: string;
  roles: string[];
  email: string | undefined;
  userId: string | undefined;
  phone: string | undefined;
  url: string | undefined;
  ...
}

That way, developers can supply the parameters in any order and it wouldn't break anything and won't have to deal with parameter order gymnastics. I believe Appwrite is written in PHP but I'm sure something like this is also possible.

馃帳 Pitch

I was upgrading my SDKs and I was looking at the breaking changes for createMembership() and it's fine that url is now optional but it's frustrating to keep having to check for the order of the parameters. For instance, on version 9.0.0, the order is

createMembership(teamId, roles, url, email, ...)

but on version 11.0.0 the order of parameters got switched all over:

createMembership(teamId, roles, email, userId, phone, url, ...)

Also, now I have to supply a bunch of undefined parameters just to get to the url towards the very end.

I didn't get any indication that something was wrong because Typescript just validates the types and email, userId, and url are all a bunch of string | undefined types so switching them around doesn't trigger any warnings from Typescript.

馃憖 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

馃彚 Have you read the Code of Conduct?

@stnguyen90
Copy link
Contributor

@dokgu, thanks for raising this issue! 馃檹馃徏 I'm going to move this to the sdk-generator repo since it would apply to the sdk-for-web too.

@stnguyen90 stnguyen90 transferred this issue from appwrite/sdk-for-node Oct 20, 2023
@datner
Copy link

datner commented May 14, 2024

the suggested type

type CreateMembershipProps = {
 // ...
  email: string | undefined;
 // ...
}
createMembership({...}) // Type-Error, `email` is missing
createMembership({..., email: undefined }) // OK

should be

type CreateMembershipProps = {
 // ...
  email?: string
 // ...
}

createMembership({...}) // OK
createMembership({..., email: undefined }) // OK

The former demands a value, either a string or an explicit undefined, the latter does not. The latter gets auto-expanded to email?: string | undefined or stays email?: string with exactOptionalPropertyTypes set to true

@datner
Copy link

datner commented May 14, 2024

I'll attach my comment from the discord verbatim:

the experience using the js (node and web) api is quite painful, there are very obvious C# (and similar) influences in the api to the aggressive detriment of the user experince.. Consider this api:

db.createRelationshipAttribute(
  "<id>",
  "<id>",
  "<id>",
  RelationshipType.OneToMany,
  false,
  "",
  "",
  RelationMutate.Cascade,
)

you can't understand anything reading this, why is the api not the more standard Options interface

db.createRelationshipAttribute({
  databaseId: "<id>",
  parentCollectionId: "<id>",
  childCollectionId: "<id>",
  type: RelationshipType.OneToMany,
  required: false,
  // parentKey?: "",
  // childKey?: "",
  onDelete: RelationMutate.Cascade,
})

or creating namespaced clients

const Parent = new Collection(parentCollection) // <- Models.Collection
Parent.createRelationAttribute({
  to: "<id>",
  type: RelationshipType.OneToMany
})

or even follow the cross-reference style of collection.$id

const Parent = new Collection(parentCollection) // <- Models.Collection
const Child = new Collection(childCollection)
Parent.addRelation(Child, {
  type: RelationshipType.OneToMany
})

This is ofc before the lack of proper types and the recommendation of hard casting results.

I know Appwrite is massive, like MASSIVE massive, both internally and externally with the plethora of sdks, but I really wish the api was more ergonomic
The dream ofc would be to take inspiration from declarative schema-based apis like from kysely or drizzle instead of the imperative approach but I'm trying to keep things realistic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants