Skip to content

Commit

Permalink
[Digital Twins] Migrate @azure/digital-twins-core to core-rest-pipe…
Browse files Browse the repository at this point in the history
…line (#24416)

Migrate to coreV2 and new test recorder.
  • Loading branch information
xirzec authored Jan 11, 2023
1 parent 13791e2 commit 858a26a
Show file tree
Hide file tree
Showing 329 changed files with 52,316 additions and 36,126 deletions.
13 changes: 12 additions & 1 deletion sdk/digitaltwins/digital-twins-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# Release History

## 1.1.1 (Unreleased)
## 2.0.0 (Unreleased)

### Features Added

### Breaking Changes

- Migrated to use `@azure/core-rest-pipeline`. For more information, please refer to [the documentation](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core#core-v1-and-core-v2). As a result of this migration:
- The response types no longer contain the raw response `_response`. To access the raw response, an `onResponse` callback has to be passed in the request options bag, for example:
```ts
let rawResponse: FullOperationResponse | undefined;
await client.operationName(/* ...parameters... */, {
onResponse: (response) => (rawResponse = response),
});
```
- Client methods that previously returned `RestResponse` now return `void`. In the event the operation fails, a `RestError` will still be thrown. To access the raw HTTP response, use the `onResponse` callback described above.
- Digital Twin objects returned from operations no longer have their properties wrapped in a `body` property.

### Bugs Fixed

### Other Changes
Expand Down
14 changes: 7 additions & 7 deletions sdk/digitaltwins/digital-twins-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ const myComponent = {
{
"@type": "Property",
name: "ComponentProp1",
schema: "string"
}
]
schema: "string",
},
],
};

const models = await serviceClient.createModels([myComponent]);
Expand Down Expand Up @@ -146,7 +146,7 @@ We can get a digital twin using `getDigitalTwin` with the digital twin ID.
const digitalTwinId = "myTwin";
const twin = await serviceClient.getDigitalTwin(digitalTwinId);
console.log(`DigitalTwin's etag: ${twin.eTag}`);
console.log(`DigitalTwin: ${twin.body}`);
console.log(`DigitalTwin: ${twin}`);
```

#### Query digital twins
Expand Down Expand Up @@ -196,10 +196,10 @@ const componentPath = "Component1";
const patch = {
op: "replace",
path: "/ComponentProp1",
value: "value2"
value: "value2",
};
const updateComponentResponse = await serviceClient.updateComponent(digitalTwinId, componentPath, [
patch
patch,
]);
```

Expand All @@ -216,7 +216,7 @@ const relationship = {
$sourceId: "BuildingTwin",
$relationshipName: "has",
$targetId: "FloorTwin",
isAccessRestricted: false
isAccessRestricted: false,
};

await serviceClient.upsertRelationship(
Expand Down
26 changes: 6 additions & 20 deletions sdk/digitaltwins/digital-twins-core/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// https://github.com/karma-runner/karma-chrome-launcher
process.env.CHROME_BIN = require("puppeteer").executablePath();
require("dotenv").config();
const {
jsonRecordingFilterFunction,
isPlaybackMode,
isSoftRecordMode,
isRecordMode,
} = require("@azure-tools/test-recorder");
const { relativeRecordingsPath } = require("@azure-tools/test-recorder");

process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();

module.exports = function (config) {
config.set({
Expand All @@ -28,15 +25,13 @@ module.exports = function (config) {
"karma-coverage",
"karma-sourcemap-loader",
"karma-junit-reporter",
"karma-json-to-file-reporter",
"karma-json-preprocessor",
],

// list of files / patterns to load in the browser
files: [
"dist-test/index.browser.js",
{ pattern: "dist-test/index.browser.js.map", type: "html", included: false, served: true },
].concat(isPlaybackMode() || isSoftRecordMode() ? ["recordings/browsers/**/*.json"] : []),
],

// list of files / patterns to exclude
exclude: [],
Expand All @@ -48,7 +43,6 @@ module.exports = function (config) {
// IMPORTANT: COMMENT following line if you want to debug in your browsers!!
// Preprocess source file to calculate code coverage, however this will make source file unreadable
// "dist-test/index.browser.js": ["coverage"]
"recordings/browsers/**/*.json": ["json"],
},

// inject following environment values into browser testing with window.__env__
Expand All @@ -60,12 +54,13 @@ module.exports = function (config) {
"AZURE_CLIENT_SECRET",
"AZURE_TENANT_ID",
"TEST_MODE",
"RECORDINGS_RELATIVE_PATH",
],

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ["mocha", "coverage", "junit", "json-to-file"],
reporters: ["mocha", "coverage", "junit"],

coverageReporter: {
// specify a common output directory
Expand All @@ -88,12 +83,6 @@ module.exports = function (config) {
properties: {}, // key value pair of properties to add to the <properties> section of the report
},

jsonToFileReporter: {
// required - to save the recordings of browser tests
filter: jsonRecordingFilterFunction,
outputPath: ".",
},

// web server port
port: 9876,

Expand Down Expand Up @@ -130,9 +119,6 @@ module.exports = function (config) {
browserNoActivityTimeout: 600000,
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 3,
browserConsoleLogOptions: {
terminal: !isRecordMode(),
},

client: {
mocha: {
Expand Down
22 changes: 12 additions & 10 deletions sdk/digitaltwins/digital-twins-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/digital-twins-core",
"version": "1.1.1",
"version": "2.0.0",
"description": "An isomorphic client library for Azure Digital Twins",
"sdk-type": "client",
"author": "Microsoft Corporation",
Expand All @@ -27,17 +27,17 @@
"execute:samples": "dev-tool samples run samples-dev",
"extract-api": "tsc -p . && api-extractor run --local",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "npm run build:test:browser && cross-env TEST_MODE=live karma start --single-run",
"integration-test:node": "npm run build:test:node && nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"",
"integration-test:browser": "dev-tool run test:browser",
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/test/**/*.spec.js'",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js",
"pack": "npm pack 2>&1",
"test:node": "npm run clean && npm run build:test:node && npm run unit-test:node",
"test:browser": "npm run clean && npm run build:test:browser && npm run unit-test:browser",
"test": "npm run clean && npm run build:test && npm run unit-test",
"unit-test:browser": "karma start --single-run",
"unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"",
"unit-test:browser": "dev-tool run test:browser",
"unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'",
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
},
"files": [
Expand All @@ -64,18 +64,22 @@
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
"dependencies": {
"@azure/core-http": "^2.2.5",
"@azure/core-auth": "^1.3.0",
"@azure/core-client": "^1.7.1",
"@azure/core-rest-pipeline": "^1.8.0",
"@azure/core-paging": "^1.1.1",
"@azure/core-tracing": "^1.0.0",
"@azure/core-util": "^1.0.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.2.0"
"tslib": "^2.2.0",
"uuid": "^8.3.0"
},
"devDependencies": {
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^2.0.1",
"@azure-tools/test-credential": "^1.0.0",
"@azure-tools/test-recorder": "^1.0.0",
"@azure-tools/test-recorder": "^2.0.0",
"@microsoft/api-extractor": "^7.31.1",
"@types/chai": "^4.1.6",
"@types/mocha": "^7.0.2",
Expand All @@ -93,8 +97,6 @@
"karma-env-preprocessor": "^0.1.1",
"karma-firefox-launcher": "^1.1.0",
"karma-ie-launcher": "^1.0.0",
"karma-json-preprocessor": "^0.3.3",
"karma-json-to-file-reporter": "^1.0.1",
"karma-junit-reporter": "^2.0.1",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
Expand Down
Loading

0 comments on commit 858a26a

Please sign in to comment.