Skip to content

Fix Cosmos Samples#18623

Merged
witemple-msft merged 11 commits intoAzure:mainfrom
sajeetharan:fix_cosmos_samples
Nov 16, 2021
Merged

Fix Cosmos Samples#18623
witemple-msft merged 11 commits intoAzure:mainfrom
sajeetharan:fix_cosmos_samples

Conversation

@sajeetharan
Copy link
Copy Markdown
Member

Fix issue #17930

  • Update ../../dist-sem to @azure/cosmos
  • Migrate samples to V2
  • Enable strict mode on samples
  • SDK update

Note : We need to publish the SDK as the samples uses some of the exports which are not in live yet. SasTokenAuth.ts

@azure-sdk
Copy link
Copy Markdown
Collaborator

API changes have been detected in @azure/cosmos. You can review API changes here

Copy link
Copy Markdown
Member

@simorenoh simorenoh left a comment

Choose a reason for hiding this comment

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

Just had a couple questions, but it looks great! Good to have this fixed!

"@azure/cosmos": "latest",
"dotenv": "latest",
"@azure/identity": "^2.0.1",
"@azure/identity": "^1.1.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why are we lowering this version?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The sample tool automatically picks the version of @azure/identity that @azure/cosmos uses for its own samples. We can just manually undo this change or upgrade @azure/cosmos to identity v2.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@azure/cosmos Upgraded to identity v2

"@azure/cosmos": "latest",
"dotenv": "latest",
"@azure/identity": "^2.0.1",
"@azure/identity": "^1.1.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same question as other package.json

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@azure/cosmos Upgraded to identity v2

Comment thread sdk/cosmosdb/cosmos/test/internal/session.spec.ts Outdated
import { SasTokenPermissionKind } from "../../../dist-esm/common";
import { createAuthorizationSasToken } from "../../../dist-esm/utils/SasToken";
import { SasTokenProperties } from "../../../dist-esm/client/SasToken/SasTokenProperties";
import { SasTokenProperties,SasTokenPermissionKind,createAuthorizationSasToken } from "@azure/cosmos";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

since all the imports are from @azure/cosmos and so is the CosmosClient then why not have them in the same import statement?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I recommend running the "organize imports" source action in VSCode. It will combine and sort imports.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

since these are tests , i have changed it to import from the src

Copy link
Copy Markdown
Member

@witemple-msft witemple-msft left a comment

Choose a reason for hiding this comment

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

The samples themselves already look a lot better. There are several things I noticed looking through that we need to address first, and two high-level comments:

  1. Files in the /samples folder at the root of the repo are deleted in this PR. You'll need to check them back out from the main branch to restore that directory.
  2. There are a lot of uses of ?. which is good syntax but won't work in Node 12. I've shown an example of some patterns that you can use instead in the comments, but in a lot of cases you're working with an object that it would be an error of some kind if it were undefined, so if you notice you're doing x?.y a lot, and you really expect x to have a value, you can instead wrap the whole thing in an if:
if (x !== undefined) {
  // Body here
} else {
  // print an error message
} 

Comment thread sdk/cosmosdb/cosmos/package.json Outdated
Comment thread sdk/cosmosdb/cosmos/review/cosmos.api.md
}

// @public (undocumented)
export function getUserAgent(suffix?: string): string;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Function has no documentation comment. Are you certain this should be public?

}

// @public (undocumented)
export enum SasTokenPermissionKind {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All undocumented.

Comment thread sdk/cosmosdb/cosmos/samples-dev/AlterQueryThroughput.ts Outdated
Comment thread sdk/cosmosdb/cosmos/samples-dev/ItemManagement.ts Outdated
Comment thread sdk/cosmosdb/cosmos/samples-dev/ServerSideScripts.ts Outdated
Comment thread sdk/cosmosdb/cosmos/test/internal/unit/sasToken.spec.ts Outdated
Comment thread sdk/cosmosdb/cosmos/test/internal/unit/platform.spec.ts Outdated
Comment thread sdk/cosmosdb/cosmos/samples/v3/javascript/Shared/handleError.js
xirzec
xirzec previously requested changes Nov 10, 2021
Copy link
Copy Markdown
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.

I'm confused about the changes outside of the cosmos folder

Comment thread samples/Bundling/parcel/js/index.js
Copy link
Copy Markdown
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.

Thanks for fixing the deletion issue! 👍

@xirzec xirzec dismissed their stale review November 15, 2021 19:04

issue addressed

@check-enforcer
Copy link
Copy Markdown

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

What if I am onboarding a new service?

Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run js - [service] - ci

@witemple-msft
Copy link
Copy Markdown
Member

/azp run js - cosmosdb - ci

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines failed to run 1 pipeline(s).

@witemple-msft
Copy link
Copy Markdown
Member

/azp run js - cosmosdb - ci

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@azure-sdk
Copy link
Copy Markdown
Collaborator

API changes have been detected in @azure/cosmos. You can review API changes here

@witemple-msft
Copy link
Copy Markdown
Member

witemple-msft commented Nov 16, 2021

@sajeetharan I made a few changes.

  • Moved assets/Data/Families.json to samples-dev/Data/Families.json and changed the way it is imported (the usage pattern that was there previously wouldn't work with the JavaScript layout, only TypeScript). I changed the sample configuration in package.json as well, and added json files to the includes in the tsconfig.json.
  • Rewrote all x?.y in samples-dev to some form of x && x.y.
  • Ran experimental generator. It passes fine with the above changes. The new generator uses a newer version of our code formatter, so it inserts commas in a few places where the old one doesn't.

@witemple-msft
Copy link
Copy Markdown
Member

/azp run js - cosmosdb - tests

@azure-pipelines
Copy link
Copy Markdown

No pipelines are associated with this pull request.

Copy link
Copy Markdown
Member

@witemple-msft witemple-msft left a comment

Choose a reason for hiding this comment

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

Thank you, @sajeetharan for your hard work on this.

"composite": false,
"noEmit": true,
"strict": true
"strict": false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder why this change was needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants