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

Move common type guards into core-util #22872

Merged
merged 14 commits into from
Aug 12, 2022

Conversation

dgetu
Copy link
Member

@dgetu dgetu commented Aug 10, 2022

A few type guards had duplicate identical definitions in multiple packages. This change moves the common functions to core-util.

Fixes #21734

dgetu added 2 commits August 10, 2022 21:46
A few type guards had duplicate definitions in multiple packages. This change moves the common functions to `core-util`.

Fixes Azure#21734
@ghost ghost added Service Bus Storage Storage Service (Queues, Blobs, Files) AgriFood Remote Rendering dev-tool Issues related to the Azure SDK for JS dev-tool eslint plugin labels Aug 10, 2022
@azure-sdk
Copy link
Collaborator

azure-sdk commented Aug 10, 2022

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-core-util

Copy link
Member

@joheredi joheredi left a comment

Choose a reason for hiding this comment

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

Thanks for taking this work @dgetu! The PR is looking great! The only thing I am not too sure about and would love to see removed from the PR, are the changes under /common.

Other than that it would be really cool if you can write a few unit tests for the typeguards in core-util. You can take a look at these tests to see how they are setup in core-util

@@ -0,0 +1,10 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about these changes under common/*. Is it possible to remove these changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Copy link
Member

Choose a reason for hiding this comment

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

This looks like the rush change feature that we don't use (but the CADL team does, which is the only reason I know about it.)

@@ -63,6 +63,8 @@
"sideEffects": false,
"dependencies": {
"@azure/abort-controller": "^1.0.0",
"@azure/core-util": "^1.0.1",
"@azure/dev-tool": "^1.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this dev-tool dependency?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@joheredi
Copy link
Member

It may be good to add a Changelog.md entry in @azure/core-util with these changes

Copy link
Member

@deyaaeldeen deyaaeldeen left a comment

Choose a reason for hiding this comment

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

Looks great! Always in favor of deleting duplicate code 😄

I left one minor comment.

@@ -68,7 +68,7 @@
"@azure/core-http": "^2.0.0",
"@azure/core-rest-pipeline": "^1.1.0",
"@azure/core-auth": "^1.3.2",
"@azure/core-util": "^1.0.0",
"@azure/core-util": "^1.0.1",
Copy link
Member

Choose a reason for hiding this comment

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

Is this change necessary?

Copy link
Member

Choose a reason for hiding this comment

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

I think it may be because core-util 1.0.0 doesn't have the new functions so code using it will break if 1.0.0 is installed which meets the ^

Copy link
Member

Choose a reason for hiding this comment

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

Yeah but I don't see the recorder using any of the new stuff.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a few unnecessary dependency bumps and missed this one when I reverted them. Fixed!

Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

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

Great stuff! I'm happy to get these consolidated

@xirzec
Copy link
Member

xirzec commented Aug 11, 2022

Seeing some odd build failures in storage-blob due to the changes to storage-internal-avro:

image

Not sure at all how what changes in the files which looks like just whitespace could have affected this, but since it doesn't appear that there are any core-util related changes to that code, maybe we just revert them?

@joheredi
Copy link
Member

Seeing some odd build failures in storage-blob due to the changes to storage-internal-avro:

image

Not sure at all how what changes in the files which looks like just whitespace could have affected this, but since it doesn't appear that there are any core-util related changes to that code, maybe we just revert them?

Yeah lets remove changes in common and storage. I guess a quick git checkout upstream/main -- sdk/storage and git checkout upstream/main -- common/tools should be enough

dgetu added 6 commits August 11, 2022 21:39
objectHasProperty fails at runtime when it is passed a null or undefined value. This change causes these inputs to instead return false
Copy link
Member

@joheredi joheredi left a comment

Choose a reason for hiding this comment

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

Looks awesome :) Thanks for the great tests

@dgetu dgetu changed the title Move common type guards to core-util Move common type guards into core-util Aug 12, 2022
Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

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

Love the tests!

import { isDefined, isObjectWithProperties, objectHasProperty } from "../../src/index";
import { assert } from "chai";

describe("Type guards", function () {
Copy link
Member

Choose a reason for hiding this comment

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

❤️

@dgetu dgetu merged commit f6c54e1 into Azure:main Aug 12, 2022
@mikeharder
Copy link
Member

@dgetu: Should the definitions of isDefined() outside of core-util be deleted now?

https://github.com/Azure/azure-sdk-for-js/search?l=TypeScript&q=%22function+isdefined%22

I'm not sure about monitor-query and notification-hubs, but I'm pretty sure the copy under test-utils can be deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AgriFood App Configuration Azure.ApplicationModel.Configuration Azure.Core Azure.Identity Communication dev-tool Issues related to the Azure SDK for JS dev-tool eslint plugin Event Hubs KeyVault Remote Rendering Service Bus Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move typeguard utilities into core-util
6 participants