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

Initial creation of Azure DigitalTwins SDK #9787

Closed
wants to merge 15 commits into from
Closed

Initial creation of Azure DigitalTwins SDK #9787

wants to merge 15 commits into from

Conversation

zolvarga
Copy link
Contributor

No description provided.

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.

I'm not an expert in what this package is trying to accomplish, so apologies if I misunderstood parts of it. Most of my comments are regarding how this package doesn't quite conform to what we require of a data-plane track 2 client.


## Getting started

The complete Microsoft Azure SDK can be downloaded from the [Microsoft Azure downloads][microsoft_sdk_download] page, and it ships with support for building deployment packages, integrating with tooling, rich command line tooling, and more.
Copy link
Member

Choose a reason for hiding this comment

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

It feels a little weird to link off to downloading the SDK when we're in the GitHub for the SDK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section points to the central download page but the next section provides the npm install instructions. I think both has value.


In reply to: 447215310 [](ancestors = 447215310)

sdk/digitaltwins/digitaltwins/README.md Outdated Show resolved Hide resolved
<!-- LINKS -->

[microsoft_sdk_download]: https://azure.microsoft.com/en-us/downloads/?sdk=net
[azure_sdk_target_frameworks]: https://github.com/azure/azure-sdk-for-net#target-frameworks
Copy link
Member

Choose a reason for hiding this comment

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

link unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.


In reply to: 447216052 [](ancestors = 447216052)

[azure_sub]: https://azure.microsoft.com/free/
[source]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/digitaltwins
[package]: https://www.npmjs.com/package/@azure/digitaltwins
[adt_npm]: https://www.npmjs.com/package/@azure/digitaltwins
Copy link
Member

Choose a reason for hiding this comment

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

do we need two links for the same URL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed


In reply to: 447216356 [](ancestors = 447216356)

[npm]: https://www.npmjs.com/
[azure_portal]: https://portal.azure.com/
[azure_rest_api]: https://docs.microsoft.com/en-us/rest/api/azure/
[azure_core_library]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/core/Azure.Core
Copy link
Member

Choose a reason for hiding this comment

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

not used

Copy link
Contributor Author

@zolvarga zolvarga Jul 14, 2020

Choose a reason for hiding this comment

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

Updated usage


In reply to: 447216533 [](ancestors = 447216533)

digitalTwinId: string,
options: DigitalTwinsListRelationshipsOptionalParams
): AsyncIterableIterator<any> {
const f = {};
Copy link
Member

Choose a reason for hiding this comment

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

what is this argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed


In reply to: 447262020 [](ancestors = 447262020)

maxItemCount: number = -1
): PagedAsyncIterableIterator<EventRoute, EventRoutesListNextResponse> {
var options: EventRoutesListOptionalParams & PageSettings = {};
if (maxItemCount != -1) {
Copy link
Member

Choose a reason for hiding this comment

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

lint: should use strict equality checks

Suggested change
if (maxItemCount != -1) {
if (maxItemCount !== -1) {

Copy link
Member

Choose a reason for hiding this comment

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

If the linter isn't running, you may have to tweak .eslintrc.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


In reply to: 447263018 [](ancestors = 447263018)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


In reply to: 447262868 [](ancestors = 447262868)

}
}

export {
Copy link
Member

Choose a reason for hiding this comment

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

typically we have a /src/index.ts that handles all top level package exports instead of the client doing this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is in the ToDo list


In reply to: 447263479 [](ancestors = 447263479)

"pack": "npm pack 2>&1",
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
"extract-api": "tsc -p . && api-extractor run --local",
"generate-pl": "autorest --typescript --typescript.azure-arm=true --use=@microsoft.azure/autorest.typescript@5.1.0 --add-credentials --model-enum-as-union --license-header=MICROSOFT_MIT_NO_VERSION --output-folder=./src/generated --input-file=swagger/digitaltwins.json"
Copy link
Member

Choose a reason for hiding this comment

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

do we need --typescript.azure-arm=true ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we do. The paginated API generation is missing if we don't specify "arm" here. (Chris Radek figured it out)


In reply to: 447264176 [](ancestors = 447264176)

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

Choose a reason for hiding this comment

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

why is the swagger being checked into this repo? I think it should live here instead: https://github.com/Azure/azure-rest-api-specs/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree and eventually it will be only in azure-rest-api-spec. But until we don't have a way to auto-generate from there, I followed the example of the digitaltwins .NET SDK and checked into this repo. (They have the swagger checked in to azure SDK folder) If you strongly against that I will remove it from here. It is not a big deal.


In reply to: 447264662 [](ancestors = 447264662)

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 auto-generate, but we simply reference the external swagger by URL in other client libraries.

Copy link
Contributor Author

@zolvarga zolvarga Jul 13, 2020

Choose a reason for hiding this comment

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

Yes, but if there is no auto-generate in the case of new version of swagger it is better to keep the original swagger what is the code generated from, is'n it?


In reply to: 453892297 [](ancestors = 453892297)

Copy link
Member

Choose a reason for hiding this comment

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

That would make sense to me, except what about generating the other language SDKs? Having the spec live in some language neutral place has the advantage of allowing all languages to reference the same spec.

For cognitive search we used that to drive changes across languages (e.g. the service team updated the swagger in one place then we regenerated all clients.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed


In reply to: 453986003 [](ancestors = 453986003)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed


In reply to: 453977418 [](ancestors = 453977418,453892297)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed


In reply to: 453758091 [](ancestors = 453758091,447264662)

@drwill-ms drwill-ms self-requested a review July 14, 2020 22:25
@zolvarga
Copy link
Contributor Author

Thanks for the comments, all of them valuable. We will discuss what is the purpose of this service in a meeting.


In reply to: 439452976 [](ancestors = 439452976)

Copy link
Member

@bterlson bterlson left a comment

Choose a reason for hiding this comment

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

Overall looking great, couple suggestions.

}

// @public
export interface DigitalTwinModelsAddOptionalParams extends coreHttp.RequestOptionsBase {
Copy link
Member

Choose a reason for hiding this comment

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

This should extend OperationOptions


// @public
export type DigitalTwinModelsAddResponse = Array<ModelData> & {
_response: coreHttp.HttpResponse & {
Copy link
Member

Choose a reason for hiding this comment

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

_response is good.


// @public
export interface DigitalTwinsAddHeaders {
eTag: string;
Copy link
Member

Choose a reason for hiding this comment

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

js prefers etag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would be a swagger change but it would effect all languages.


In reply to: 455321769 [](ancestors = 455321769)

Choose a reason for hiding this comment

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

I don't know if swagger has an "etag" type, but in the least it could be a fix to autorest code generator to use etag type if the parameter name is etag.

Copy link
Member

Choose a reason for hiding this comment

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

As a data point, currently in the data plane swagger, the etag header is spelled "ETag" (capital E and capital T). This looks consistent with the spelling in the RFC (RFC 7232) and places like Wikipedia.

};

// @public
export interface DigitalTwinModelsListOptionalParams extends coreHttp.RequestOptionsBase {
Copy link
Member

Choose a reason for hiding this comment

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

Generally replace ROB with OperationOptions.

};

// @public
export class DigitalTwinsClient {
Copy link
Member

Choose a reason for hiding this comment

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

One thing we should discuss is whether it makes sense to have separate clients for models, twins, components, and relationships.

publishComponentTelemetry(digitalTwinId: string, componentPath: string, payload: string, messageId?: string): Promise<RestResponse>;
publishTelemetry(digitalTwinId: string, payload: any, messageId?: string): Promise<RestResponse>;
queryTwins(query?: string): PagedAsyncIterableIterator<any, QueryQueryTwinsResponse>;
updateComponent(digitalTwinId: string, componentPath: string, componentPatch: any, ifMatch?: string): Promise<DigitalTwinsUpdateComponentResponse>;
Copy link
Member

Choose a reason for hiding this comment

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

componentPatch can likely be typed more precisely than any. Even object might be preferable if we can't be more specific.


// @public
export interface DigitalTwinsSendComponentTelemetryOptionalParams extends coreHttp.RequestOptionsBase {
dtTimestamp?: string;
Copy link
Member

Choose a reason for hiding this comment

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

dtTimestamp doesn't seem super descriptive to me.

Copy link
Member

Choose a reason for hiding this comment

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

We discussed: this comes from the swagger and we have a work item to improve this name for ADT GA.


In reply to: 455324864 [](ancestors = 455324864)

Choose a reason for hiding this comment

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

FWIW, in the .NET client, we called this TimeStamp for now, and will update it along with the swagger change at GA.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to the swagger changes list


In reply to: 455388544 [](ancestors = 455388544,455324864)

export type IfNoneMatch = '*';

// @public
export type IfNoneMatch1 = '*';
Copy link
Member

Choose a reason for hiding this comment

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

Duplicate declaration here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to the swagger changes list


In reply to: 455325165 [](ancestors = 455325165)

const createdTwin = await serviceClient.upsertDigitalTwin(
digitalTwinId,
newTwin,
(enableUpdate = true)
Copy link
Member

Choose a reason for hiding this comment

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

Per review: we should avoid this pattern in our code. The usual recommendation is to use option bags so you can write {enableUpdate: true}.

When that can't be used, it's accepted to use comments to name boolean params e.g. doFoo(/*forceUpdate*/ true)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


In reply to: 455407628 [](ancestors = 455407628)


### Install the package

Install the Azure Digital Twins client library for Javascript with [NPM][npm_package]:

Choose a reason for hiding this comment

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

capital S in JavaScript?

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jul 23, 2020

@zolvarga Do you mind updating the PR description with a link to Azure/azure-sdk#1499 for other reviewers stumbling on this?

@zolvarga
Copy link
Contributor Author

Closing as moved to final review

@zolvarga zolvarga closed this Aug 11, 2020
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.

6 participants