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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make project schema properties optional #133

Merged
merged 5 commits into from
Aug 23, 2023
Merged

Conversation

sethvincent
Copy link
Contributor

This removes name and defaultPresets from the required array of the project jsonschemas.

There's one type error that I've ts-ignored that I'm not sure how to deal with. See the comment below.

@@ -21,24 +21,25 @@ type ConvertFunction<TSchemaName extends SchemaName> = (
>
) => CurrentProtoTypes[TSchemaName]

/* @ts-ignore TODO: resolve "not assignable to type 'ConvertFunction<"project">" */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

full output of the error:

error TS2322: 

Type '(mapeoDoc: Omit<{ schemaName: "project"; name?: string | undefined; defaultPresets?: { point?: string[] | undefined; area?: string[] | undefined; vertex?: string[] | undefined; line?: string[] | undefined; relation?: string[] | undefined; } | undefined; ... 4 more ...; links: string[]; }, "versionId">) => { ...; }'
is not assignable to type 'ConvertFunction<"project">'.

Call signature return types '{ defaultPresets: { point: Buffer[]; area: Buffer[]; vertex: Buffer[]; line: Buffer[]; relation: Buffer[]; }; name?: string | undefined; docId: string; links: string[]; createdAt: string; updatedAt: string; schemaName: "project"; common: Common_1 | undefined; }'
and 'Project_2' are incompatible.

    The types of 'name' are incompatible between these types.
      Type 'string | undefined' is not assignable to type 'string'.
        Type 'undefined' is not assignable to type 'string'.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types from protobuf are quite confusing. Every field in protobuf is optional, but the decoder defaults to settings undefined fields as an empty string / false / 0, unless fields are marked optional.

Fixed this by defining name and defaultPresets as optional in the proto file.

@@ -21,24 +21,25 @@ type ConvertFunction<TSchemaName extends SchemaName> = (
>
) => CurrentProtoTypes[TSchemaName]

/* @ts-ignore TODO: resolve "not assignable to type 'ConvertFunction<"project">" */
export const convertProject: ConvertFunction<'project'> = (mapeoDoc) => {
return {
common: convertCommon(mapeoDoc),
...mapeoDoc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...mapeoDoc,
...mapeoDoc,
name: mapeoDoc.name || '',

I think that since name is now optional, we need to take that into account here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the protobuf definition to allow for optional values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right! forgot about that!

Copy link
Member

@gmaclennan gmaclennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some changes, updated the test, and a fix for the type issue. Looks good to me.

@@ -21,24 +21,25 @@ type ConvertFunction<TSchemaName extends SchemaName> = (
>
) => CurrentProtoTypes[TSchemaName]

/* @ts-ignore TODO: resolve "not assignable to type 'ConvertFunction<"project">" */
export const convertProject: ConvertFunction<'project'> = (mapeoDoc) => {
return {
common: convertCommon(mapeoDoc),
...mapeoDoc,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the protobuf definition to allow for optional values

@@ -21,24 +21,25 @@ type ConvertFunction<TSchemaName extends SchemaName> = (
>
) => CurrentProtoTypes[TSchemaName]

/* @ts-ignore TODO: resolve "not assignable to type 'ConvertFunction<"project">" */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types from protobuf are quite confusing. Every field in protobuf is optional, but the decoder defaults to settings undefined fields as an empty string / false / 0, unless fields are marked optional.

Fixed this by defining name and defaultPresets as optional in the proto file.

@gmaclennan gmaclennan merged commit 3ec04e7 into main Aug 23, 2023
@gmaclennan gmaclennan deleted the optional-project-properties branch August 23, 2023 10:21
@gmaclennan gmaclennan linked an issue Aug 23, 2023 that may be closed by this pull request
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

Successfully merging this pull request may close these issues.

Update project settings schema properties to be optional
3 participants