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

split URL to node/browser versions and add brower mapping to package.json #1

Merged
merged 1 commit into from
May 17, 2021
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 sdk/iot/modelsrepository/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"module": "dist-esm/src/index.js",
"browser": {
"stream": "./node_modules/stream-browserify/index.js",
"./dist-esm/src/print.js": "./dist-esm/src/print.browser.js"
"./dist-esm/src/print.js": "./dist-esm/src/print.browser.js",
"./dist-esm/src/utils/url.js": "./dist-esm/src/utils/url.browser.js"
},
"types": "types/iot-models-repository.d.ts",
"scripts": {
Expand Down
38 changes: 20 additions & 18 deletions sdk/iot/modelsrepository/src/modelsRepositoryClient.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Copyright (c) Microsoft.
// Licensed under the MIT license.

import {
GetModelsOptions,
IoTModelsRepositoryServiceClient,
import {
GetModelsOptions,
IoTModelsRepositoryServiceClient,
ModelsRepositoryClientOptions,
dependencyResolutionType,
HttpFetcher,
FilesystemFetcher,
PseudoParser,
DtmiResolver,
logger,
DTDL,
DTDL
} from "./internal";
import * as cnst from './constants';
import * as cnst from "./constants";
import { createClientPipeline, InternalClientPipelineOptions } from "@azure/core-client";
import { URL } from "url";
import * as path from "path";
import { Fetcher } from "./fetcherAbstract";
import { RestError } from "@azure/core-rest-pipeline";
import { URL } from "./utils/url";

function isLocalPath(p: string): boolean {
const myRegex = RegExp(/^(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+$/g);
Expand Down Expand Up @@ -55,7 +55,6 @@ export class ModelsRepositoryClient {
this._apiVersion = options.apiVersion || cnst.DEFAULT_API_VERSION;
}


/**
* improves the readability of the constructor.
* based on a boolean returns the proper dependency resolution setting string.
Expand All @@ -69,7 +68,7 @@ export class ModelsRepositoryClient {
}

/**
* Though currently not relevant, can specify API Version for communicating with
* Though currently not relevant, can specify API Version for communicating with
* the service.
*/
get apiVersion() {
Expand All @@ -91,7 +90,7 @@ export class ModelsRepositoryClient {
}

/**
* Because of the local / remote optionality of this client, the service client
* Because of the local / remote optionality of this client, the service client
* must be dynamically generated based on the repository location. If the provided
* repository location is a remote location, then this private method will be used
* to create the IoT Models Repository Service Client.
Expand Down Expand Up @@ -167,21 +166,24 @@ export class ModelsRepositoryClient {
* Retrieve one or more models based upon on or more provided dtmis.
* @param {string} dtmis - one dtmi represented as a string
* @param {GetModelsOptions} options - options to govern behavior of model getter.
* @returns {Promise<{ [dtmi: string]: unknown}>}
* @returns {Promise<{ [dtmi: string]: unknown}>}
*/
async getModels(dtmis: string, options?: GetModelsOptions): Promise<{ [dtmi: string]: unknown }>;
/**
/**
* Retrieve one or more models based upon on or more provided dtmis.
* @param {string[]} dtmis - dtmi strings in an array.
* @param {GetModelsOptions} options - options to govern behavior of model getter.
* @returns {Promise<{ [dtmi: string]: unknown}>}
* @returns {Promise<{ [dtmi: string]: unknown}>}
*/
async getModels(dtmis: string[], options?: GetModelsOptions): Promise<{ [dtmi: string]: unknown }>;
async getModels(
dtmis: string[],
options?: GetModelsOptions
): Promise<{ [dtmi: string]: unknown }>;
async getModels(
dtmis: string | string[],
options?: GetModelsOptions
): Promise<{ [dtmi: string]: unknown }> {
let modelMap: {[dtmi: string]: unknown};
let modelMap: { [dtmi: string]: unknown };
if (!Array.isArray(dtmis)) {
dtmis = [dtmis];
}
Expand All @@ -196,7 +198,7 @@ export class ModelsRepositoryClient {
logger.info(`Getting models w/ dependency resolution mode: enabled`);
logger.info(`Retreiving model(s): ${dtmis}...`);
const baseModelMap = await this._resolver.resolve(dtmis, false, options);
const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key])
const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key]);
logger.info(`Retreiving model dependencies for ${dtmis}...`);
modelMap = await this._pseudoParser.expand(baseModelList, false);
} else if (dependencyResolution === cnst.DEPENDENCY_MODE_TRY_FROM_EXPANDED) {
Expand All @@ -206,10 +208,10 @@ export class ModelsRepositoryClient {
modelMap = await this._resolver.resolve(dtmis, true, options);
} catch (e) {
if (e instanceof RestError) {
let baseModelMap: { [dtmi: string]: unknown; };
logger.info("Could not retrieve model(s) from expanded model DTDL - ")
let baseModelMap: { [dtmi: string]: unknown };
logger.info("Could not retrieve model(s) from expanded model DTDL - ");
baseModelMap = await this._resolver.resolve(dtmis, false, options);
const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key])
const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key]);
logger.info(`Retreiving model dependencies for ${dtmis}...`);
modelMap = await this._pseudoParser.expand(baseModelList as DTDL[], true);
} else {
Expand Down
6 changes: 6 additions & 0 deletions sdk/iot/modelsrepository/src/utils/url.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

const url = URL;

export { url as URL };
4 changes: 4 additions & 0 deletions sdk/iot/modelsrepository/src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export { URL } from "url";