Skip to content

Commit 9124db3

Browse files
authored
chore(dtdl-parser): cleaning up and fixing bugs (Azure#20300)
* dtdl-parser updates * add spelling fixes * update release date
1 parent 5cd7947 commit 9124db3

File tree

20 files changed

+121
-105
lines changed

20 files changed

+121
-105
lines changed

.vscode/cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"sdk/synapse/synapse-artifacts/review/*.md",
4141
"sdk/synapse/synapse-managed-private-endpoints/review/*.md",
4242
"sdk/synapse/synapse-monitoring/review/*.md",
43-
"sdk/synapse/synapse-spark/review/*.md",
43+
"sdk/synapse/synapse-spark/review/*.md"
4444
],
4545
"words": [
4646
"adfs",
@@ -53,6 +53,7 @@
5353
"devdeps",
5454
"DTDL",
5555
"dtmi",
56+
"dtmis",
5657
"eastus",
5758
"ECONNRESET",
5859
"Eloqua",

sdk/digitaltwins/dtdl-parser/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 1.0.0-beta.2 (2022-02-23)
4+
5+
### Bugs Fixed
6+
7+
- Fix integration issues with @azure/iot-modelsrepository.
8+
39
## 1.0.0-beta.1 (2022-02-01)
410

511
### Features Added

sdk/digitaltwins/dtdl-parser/README.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Azure Model Parser client library for JavaScript
22

3-
Use this library to parse your DTDL models and validate their structure conforms to the DTDL specification.
3+
Use this library to parse your DTDL models and validate their structure conforms to the DTDL specification.
44

55
The Digital Twin Definition Language (DTDL) defines a JSON-LD based schema for creating Digital Twin models. As the DTDL specification evolves, this parser will be updated accordingly. A key characteristic of Azure Digital Twins is the ability to define your own vocabulary and build your twin graph in the self-defined terms of your business. This capability is provided through user-provided models. You can think of models as the nouns in a description of your world.
66

@@ -37,10 +37,6 @@ If you have not already written a DTDL model, you can access the full repository
3737

3838
To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling).
3939

40-
### Further examples
41-
42-
Top-level examples usually include things like creating and authenticating the main Client. If your service supports multiple means of authenticating (e.g. key-based and Azure Active Directory) you can give a separate example of each.
43-
4440
## Key concepts
4541

4642
### DTDL Parser
@@ -53,31 +49,29 @@ You can learn more about DTDL for models by reading "Learn about twin models and
5349

5450
### Parse a DTDL Model
5551

56-
To parse a sample DTDL model, either start with one you have already written or use one located in the public DTDL database (referenced above). Once you have installed the package via `npm`, create a TypeScript sample:
57-
58-
```javascript
59-
import * as fs from "fs";
60-
import { createParser, ModelParsingOption } from "@azure/dtdl-parser";
52+
To parse a sample DTDL model, either start with one you have already written or use one located in the public DTDL database. Let's grab a sample model from the models repository:
6153

54+
```js
55+
// example.js
6256
async function main() {
63-
const rawDtdlDigest: string = fs.readFileSync(
64-
"./samples-dev/InterfaceContentsEmbeddedV2.json",
65-
"utf-8"
66-
);
57+
const client = new ModelsRepositoryClient();
58+
const dtmi = "dtmi:com:example:TemperatureController;1";
59+
const models = await client.getModels(dtmi);
60+
6761
const modelParser = createParser(ModelParsingOption.PermitAnyTopLevelElement);
6862
modelParser.options = ModelParsingOption.PermitAnyTopLevelElement;
69-
const modelDict = await modelParser.parse([rawDtdlDigest]);
70-
console.log(modelDict);
71-
Object.entries(modelDict).forEach(([key, value]) => {
72-
console.log(key);
73-
console.log(typeof value);
63+
Object.entries(models).forEach(([key, value]) => {
64+
console.log(`dtmi: ${key}`);
65+
const modelDict = await modelParser.parse([value]);
66+
Object.entries(modelDict).forEach(([key2, value2]) => {
67+
console.log(key2);
68+
});
7469
});
7570
}
7671

7772
main().catch((err) => {
78-
console.error("The sample encountered an error:", err);
73+
console.error("The sample encountered an error:", err);
7974
});
80-
8175
```
8276

8377
## Troubleshooting

sdk/digitaltwins/dtdl-parser/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/dtdl-parser",
3-
"version": "1.0.0-beta.1",
3+
"version": "1.0.0-beta.2",
44
"description": "Digital Twins Model Parser client library with typescript type definitions for node.js and browser.",
55
"sdk-type": "client",
66
"main": "dist/index.js",
@@ -66,7 +66,8 @@
6666
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
6767
"dependencies": {
6868
"@azure/logger": "^1.0.0",
69-
"tslib": "^2.2.0"
69+
"tslib": "^2.2.0",
70+
"@azure/iot-modelsrepository": "^1.0.0-beta.1"
7071
},
7172
"devDependencies": {
7273
"@azure/core-util": "^1.0.0-beta.1",

sdk/digitaltwins/dtdl-parser/review/dtdl-parser.api.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
```ts
66

7+
import { ModelsRepositoryClient } from '@azure/iot-modelsrepository';
8+
79
// @public (undocumented)
810
export interface ArrayInfo extends ComplexSchemaInfo {
911
// (undocumented)
@@ -95,9 +97,6 @@ export interface DoubleInfo extends NumericSchemaInfo {
9597
entityKind: "double";
9698
}
9799

98-
// @public (undocumented)
99-
export type DtmiResolver = (identifiers: string[]) => Promise<string[] | null>;
100-
101100
// @public (undocumented)
102101
export interface DurationInfo extends TemporalSchemaInfo {
103102
// (undocumented)
@@ -274,7 +273,7 @@ export type ModelDict = {
274273
// @public (undocumented)
275274
export interface ModelParser {
276275
// (undocumented)
277-
dtmiResolver?: DtmiResolver;
276+
getModels?: ModelsRepositoryClient["getModels"];
278277
// (undocumented)
279278
getSupplementalTypeCollection(): SupplementalTypeCollection;
280279
// (undocumented)

sdk/digitaltwins/dtdl-parser/samples/v1/javascript/README.md renamed to sdk/digitaltwins/dtdl-parser/samples/v1-beta/javascript/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ languages:
44
- javascript
55
products:
66
- azure
7-
urlFragment: digital-twins-parser-javascript
7+
urlFragment: dtdl-parser-javascript-beta
88
---
99

10-
# Azure Digital Twins Model Parser client library samples for JavaScript
10+
# Azure Digital Twins Model Parser client library samples for JavaScript (Beta)
1111

1212
These sample programs show how to use the JavaScript client libraries for Azure Digital Twins Model Parser in some common scenarios.
1313

@@ -53,7 +53,7 @@ npx cross-env node parser_demo.js
5353

5454
Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients.
5555

56-
[parser_demo]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/digitaltwins/dtdl-parser/samples/v1/javascript/parser_demo.js
56+
[parser_demo]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/digitaltwins/dtdl-parser/samples/v1-beta/javascript/parser_demo.js
5757
[apiref]: https://docs.microsoft.com/javascript/api/
5858
[freesub]: https://azure.microsoft.com/free/
5959
[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/dtdl-parser/README.md

sdk/digitaltwins/dtdl-parser/samples/v1/javascript/package.json renamed to sdk/digitaltwins/dtdl-parser/samples/v1-beta/javascript/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
{
2-
"name": "azure-digital-twins-parser-samples-js",
2+
"name": "azure-dtdl-parser-samples-js-beta",
33
"private": true,
44
"version": "1.0.0",
5-
"description": "Azure Digital Twins Model Parser client library samples for JavaScript",
5+
"description": "Azure Digital Twins Model Parser client library samples for JavaScript (Beta)",
66
"engines": {
77
"node": ">=12.0.0"
88
},
99
"repository": {
1010
"type": "git",
1111
"url": "git+https://github.com/Azure/azure-sdk-for-js.git",
12-
"directory": "sdk/digitaltwins/digital-twins-parser"
12+
"directory": "sdk/digitaltwins/dtdl-parser"
1313
},
1414
"keywords": [
1515
"azure",
1616
"cloud",
17-
"typescript"
17+
"typescript",
18+
"DTDL",
19+
"IoT",
20+
"Digital Twins"
1821
],
1922
"author": "Microsoft Corporation",
2023
"license": "MIT",
2124
"bugs": {
2225
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
2326
},
24-
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/digital-twins-parser",
27+
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/dtdl-parser",
2528
"dependencies": {
2629
"@azure/dtdl-parser": "next",
2730
"dotenv": "latest"

sdk/digitaltwins/dtdl-parser/samples/v1/javascript/parser_demo.js renamed to sdk/digitaltwins/dtdl-parser/samples/v1-beta/javascript/parser_demo.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@
88
*/
99

1010
const fs = require("fs");
11-
const { ModelParser, ModelParsingOption } = require("@azure/dtdl-parser");
11+
const { createParser, ModelParsingOption } = require("@azure/dtdl-parser");
1212

1313
async function main() {
14-
const rawDtdlDigest = fs.readFileSync(
15-
"samples/typescript/parser/InterfaceContentsEmbeddedV2.json",
16-
"utf-8"
17-
);
18-
const modelParser = new ModelParser();
14+
const rawDtdlDigest = fs.readFileSync("./samples-dev/InterfaceContentsEmbeddedV2.json", "utf-8");
15+
const modelParser = createParser(ModelParsingOption.PermitAnyTopLevelElement);
1916
modelParser.options = ModelParsingOption.PermitAnyTopLevelElement;
20-
const modelDict = await modelParser.parseAsync([rawDtdlDigest]);
17+
const modelDict = await modelParser.parse([rawDtdlDigest]);
2118
console.log(modelDict);
2219
Object.entries(modelDict).forEach(([key, value]) => {
2320
console.log(key);
2421
console.log(typeof value);
2522
});
2623
}
24+
2725
main().catch((err) => {
2826
console.error("The sample encountered an error:", err);
2927
});

sdk/digitaltwins/dtdl-parser/samples/v1/typescript/README.md renamed to sdk/digitaltwins/dtdl-parser/samples/v1-beta/typescript/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ languages:
44
- typescript
55
products:
66
- azure
7-
urlFragment: digital-twins-parser-typescript
7+
urlFragment: dtdl-parser-typescript-beta
88
---
99

10-
# Azure Digital Twins Model Parser client library samples for TypeScript
10+
# Azure Digital Twins Model Parser client library samples for TypeScript (Beta)
1111

1212
These sample programs show how to use the TypeScript client libraries for Azure Digital Twins Model Parser in some common scenarios.
1313

@@ -65,7 +65,7 @@ npx cross-env node dist/parser_demo.js
6565

6666
Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients.
6767

68-
[parser_demo]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/digitaltwins/dtdl-parser/samples/v1/typescript/src/parser_demo.ts
68+
[parser_demo]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/digitaltwins/dtdl-parser/samples/v1-beta/typescript/src/parser_demo.ts
6969
[apiref]: https://docs.microsoft.com/javascript/api/
7070
[freesub]: https://azure.microsoft.com/free/
7171
[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/dtdl-parser/README.md

0 commit comments

Comments
 (0)