Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"sdk/synapse/synapse-artifacts/review/*.md",
"sdk/synapse/synapse-managed-private-endpoints/review/*.md",
"sdk/synapse/synapse-monitoring/review/*.md",
"sdk/synapse/synapse-spark/review/*.md",
"sdk/synapse/synapse-spark/review/*.md"
],
"words": [
"adfs",
Expand All @@ -53,6 +53,7 @@
"devdeps",
"DTDL",
"dtmi",
"dtmis",
"eastus",
"ECONNRESET",
"Eloqua",
Expand Down
6 changes: 6 additions & 0 deletions sdk/digitaltwins/dtdl-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 1.0.0-beta.2 (2022-02-23)

### Bugs Fixed

- Fix integration issues with @azure/iot-modelsrepository.

## 1.0.0-beta.1 (2022-02-01)

### Features Added
Expand Down
36 changes: 15 additions & 21 deletions sdk/digitaltwins/dtdl-parser/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Azure Model Parser client library for JavaScript

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

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.

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

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).

### Further examples

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.

## Key concepts

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

### Parse a DTDL Model

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:

```javascript
import * as fs from "fs";
import { createParser, ModelParsingOption } from "@azure/dtdl-parser";
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:

```js
// example.js
async function main() {
const rawDtdlDigest: string = fs.readFileSync(
"./samples-dev/InterfaceContentsEmbeddedV2.json",
"utf-8"
);
const client = new ModelsRepositoryClient();
const dtmi = "dtmi:com:example:TemperatureController;1";
const models = await client.getModels(dtmi);

const modelParser = createParser(ModelParsingOption.PermitAnyTopLevelElement);
modelParser.options = ModelParsingOption.PermitAnyTopLevelElement;
const modelDict = await modelParser.parse([rawDtdlDigest]);
console.log(modelDict);
Object.entries(modelDict).forEach(([key, value]) => {
console.log(key);
console.log(typeof value);
Object.entries(models).forEach(([key, value]) => {
console.log(`dtmi: ${key}`);
const modelDict = await modelParser.parse([value]);
Object.entries(modelDict).forEach(([key2, value2]) => {
console.log(key2);
});
});
}

main().catch((err) => {
console.error("The sample encountered an error:", err);
console.error("The sample encountered an error:", err);
});

```

## Troubleshooting
Expand Down
5 changes: 3 additions & 2 deletions sdk/digitaltwins/dtdl-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/dtdl-parser",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Digital Twins Model Parser client library with typescript type definitions for node.js and browser.",
"sdk-type": "client",
"main": "dist/index.js",
Expand Down Expand Up @@ -66,7 +66,8 @@
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
"dependencies": {
"@azure/logger": "^1.0.0",
"tslib": "^2.2.0"
"tslib": "^2.2.0",
"@azure/iot-modelsrepository": "^1.0.0-beta.1"
},
"devDependencies": {
"@azure/core-util": "^1.0.0-beta.1",
Expand Down
7 changes: 3 additions & 4 deletions sdk/digitaltwins/dtdl-parser/review/dtdl-parser.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

```ts

import { ModelsRepositoryClient } from '@azure/iot-modelsrepository';

// @public (undocumented)
export interface ArrayInfo extends ComplexSchemaInfo {
// (undocumented)
Expand Down Expand Up @@ -95,9 +97,6 @@ export interface DoubleInfo extends NumericSchemaInfo {
entityKind: "double";
}

// @public (undocumented)
export type DtmiResolver = (identifiers: string[]) => Promise<string[] | null>;

// @public (undocumented)
export interface DurationInfo extends TemporalSchemaInfo {
// (undocumented)
Expand Down Expand Up @@ -274,7 +273,7 @@ export type ModelDict = {
// @public (undocumented)
export interface ModelParser {
// (undocumented)
dtmiResolver?: DtmiResolver;
getModels?: ModelsRepositoryClient["getModels"];
// (undocumented)
getSupplementalTypeCollection(): SupplementalTypeCollection;
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ languages:
- javascript
products:
- azure
urlFragment: digital-twins-parser-javascript
urlFragment: dtdl-parser-javascript-beta
---

# Azure Digital Twins Model Parser client library samples for JavaScript
# Azure Digital Twins Model Parser client library samples for JavaScript (Beta)

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

Expand Down Expand Up @@ -53,7 +53,7 @@ npx cross-env node parser_demo.js

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

[parser_demo]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/digitaltwins/dtdl-parser/samples/v1/javascript/parser_demo.js
[parser_demo]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/digitaltwins/dtdl-parser/samples/v1-beta/javascript/parser_demo.js
[apiref]: https://docs.microsoft.com/javascript/api/
[freesub]: https://azure.microsoft.com/free/
[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/dtdl-parser/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
{
"name": "azure-digital-twins-parser-samples-js",
"name": "azure-dtdl-parser-samples-js-beta",
"private": true,
"version": "1.0.0",
"description": "Azure Digital Twins Model Parser client library samples for JavaScript",
"description": "Azure Digital Twins Model Parser client library samples for JavaScript (Beta)",
"engines": {
"node": ">=12.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Azure/azure-sdk-for-js.git",
"directory": "sdk/digitaltwins/digital-twins-parser"
"directory": "sdk/digitaltwins/dtdl-parser"
},
"keywords": [
"azure",
"cloud",
"typescript"
"typescript",
"DTDL",
"IoT",
"Digital Twins"
],
"author": "Microsoft Corporation",
"license": "MIT",
"bugs": {
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/digital-twins-parser",
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/dtdl-parser",
"dependencies": {
"@azure/dtdl-parser": "next",
"dotenv": "latest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@
*/

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

async function main() {
const rawDtdlDigest = fs.readFileSync(
"samples/typescript/parser/InterfaceContentsEmbeddedV2.json",
"utf-8"
);
const modelParser = new ModelParser();
const rawDtdlDigest = fs.readFileSync("./samples-dev/InterfaceContentsEmbeddedV2.json", "utf-8");
const modelParser = createParser(ModelParsingOption.PermitAnyTopLevelElement);
modelParser.options = ModelParsingOption.PermitAnyTopLevelElement;
const modelDict = await modelParser.parseAsync([rawDtdlDigest]);
const modelDict = await modelParser.parse([rawDtdlDigest]);
console.log(modelDict);
Object.entries(modelDict).forEach(([key, value]) => {
console.log(key);
console.log(typeof value);
});
}

main().catch((err) => {
console.error("The sample encountered an error:", err);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ languages:
- typescript
products:
- azure
urlFragment: digital-twins-parser-typescript
urlFragment: dtdl-parser-typescript-beta
---

# Azure Digital Twins Model Parser client library samples for TypeScript
# Azure Digital Twins Model Parser client library samples for TypeScript (Beta)

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

Expand Down Expand Up @@ -65,7 +65,7 @@ npx cross-env node dist/parser_demo.js

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

[parser_demo]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/digitaltwins/dtdl-parser/samples/v1/typescript/src/parser_demo.ts
[parser_demo]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/digitaltwins/dtdl-parser/samples/v1-beta/typescript/src/parser_demo.ts
[apiref]: https://docs.microsoft.com/javascript/api/
[freesub]: https://azure.microsoft.com/free/
[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/dtdl-parser/README.md
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "azure-digital-twins-parser-samples-ts",
"name": "azure-dtdl-parser-samples-ts-beta",
"private": true,
"version": "1.0.0",
"description": "Azure Digital Twins Model Parser client library samples for TypeScript",
"description": "Azure Digital Twins Model Parser client library samples for TypeScript (Beta)",
"engines": {
"node": ">=12.0.0"
},
Expand All @@ -13,25 +13,29 @@
"repository": {
"type": "git",
"url": "git+https://github.com/Azure/azure-sdk-for-js.git",
"directory": "sdk/digitaltwins/digital-twins-parser"
"directory": "sdk/digitaltwins/dtdl-parser"
},
"keywords": [
"azure",
"cloud",
"typescript"
"typescript",
"DTDL",
"IoT",
"Digital Twins"
],
"author": "Microsoft Corporation",
"license": "MIT",
"bugs": {
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/digital-twins-parser",
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/dtdl-parser",
"dependencies": {
"@azure/dtdl-parser": "next",
"dotenv": "latest"
},
"devDependencies": {
"typescript": "~4.2.0",
"@types/node": "^12.0.0",
"typescript": "~4.4.0",
"rimraf": "latest"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-unused-vars
*/

/**
* @summary Demonstrates the use of a ModelParser to validate a PnP model.
*/

import * as fs from "fs";
import { createParser, ModelParsingOption } from "@azure/dtdl-parser";

async function main() {
const rawDtdlDigest: string = fs.readFileSync(
"./samples-dev/InterfaceContentsEmbeddedV2.json",
"utf-8"
);
const modelParser = createParser(ModelParsingOption.PermitAnyTopLevelElement);
modelParser.options = ModelParsingOption.PermitAnyTopLevelElement;
const modelDict = await modelParser.parse([rawDtdlDigest]);
console.log(modelDict);
Object.entries(modelDict).forEach(([key, value]) => {
console.log(key);
console.log(typeof value);
});
}

main().catch((err) => {
console.error("The sample encountered an error:", err);
});

This file was deleted.

1 change: 0 additions & 1 deletion sdk/digitaltwins/dtdl-parser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export {
ValueConstraint,
TraversalStatus,
ModelParsingOption,
DtmiResolver,
ParsingError,
LanguageStringType
} from "./parser";
Expand Down
6 changes: 3 additions & 3 deletions sdk/digitaltwins/dtdl-parser/src/parser/modelParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
/* eslint-disable no-unused-vars */
/* eslint-disable sort-imports */

import { DtmiResolver, ModelParsingOption } from "./internal";
import { SupplementalTypeCollection, ModelDict } from "./internal";
import { ModelsRepositoryClient } from "@azure/iot-modelsrepository";
import { SupplementalTypeCollection, ModelDict, ModelParsingOption } from "./internal";
export interface ModelParser {
dtmiResolver?: DtmiResolver;
getModels?: ModelsRepositoryClient["getModels"];
options: ModelParsingOption;
maxDtdlVersion?: number;
parse(jsonTexts: string[]): Promise<ModelDict>;
Expand Down
Loading