@azure/iot-modelsrepository 1.0.0-alpha.20250618.1 → 1.0.0-alpha.20250718.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/browser/dtmiResolver.js +1 -0
  2. package/dist/browser/dtmiResolver.js.map +1 -1
  3. package/dist/browser/fetcherHTTP.js +4 -3
  4. package/dist/browser/fetcherHTTP.js.map +1 -1
  5. package/dist/browser/modelsRepositoryClient.js +15 -7
  6. package/dist/browser/modelsRepositoryClient.js.map +1 -1
  7. package/dist/browser/modelsRepositoryServiceClient.js +6 -1
  8. package/dist/browser/modelsRepositoryServiceClient.js.map +1 -1
  9. package/dist/browser/psuedoParser.js +1 -0
  10. package/dist/browser/psuedoParser.js.map +1 -1
  11. package/dist/commonjs/dtmiResolver.js +1 -0
  12. package/dist/commonjs/dtmiResolver.js.map +1 -1
  13. package/dist/commonjs/fetcherFilesystem.js +4 -3
  14. package/dist/commonjs/fetcherFilesystem.js.map +1 -1
  15. package/dist/commonjs/fetcherHTTP.js +4 -3
  16. package/dist/commonjs/fetcherHTTP.js.map +1 -1
  17. package/dist/commonjs/modelsRepositoryClient.js +15 -7
  18. package/dist/commonjs/modelsRepositoryClient.js.map +1 -1
  19. package/dist/commonjs/modelsRepositoryServiceClient.js +6 -1
  20. package/dist/commonjs/modelsRepositoryServiceClient.js.map +1 -1
  21. package/dist/commonjs/psuedoParser.js +1 -0
  22. package/dist/commonjs/psuedoParser.js.map +1 -1
  23. package/dist/commonjs/tsdoc-metadata.json +11 -11
  24. package/dist/esm/dtmiResolver.js +1 -0
  25. package/dist/esm/dtmiResolver.js.map +1 -1
  26. package/dist/esm/fetcherFilesystem.js +3 -2
  27. package/dist/esm/fetcherFilesystem.js.map +1 -1
  28. package/dist/esm/fetcherHTTP.js +4 -3
  29. package/dist/esm/fetcherHTTP.js.map +1 -1
  30. package/dist/esm/modelsRepositoryClient.js +15 -7
  31. package/dist/esm/modelsRepositoryClient.js.map +1 -1
  32. package/dist/esm/modelsRepositoryServiceClient.js +6 -1
  33. package/dist/esm/modelsRepositoryServiceClient.js.map +1 -1
  34. package/dist/esm/psuedoParser.js +1 -0
  35. package/dist/esm/psuedoParser.js.map +1 -1
  36. package/dist/react-native/dtmiResolver.js +1 -0
  37. package/dist/react-native/dtmiResolver.js.map +1 -1
  38. package/dist/react-native/fetcherFilesystem.js +3 -2
  39. package/dist/react-native/fetcherFilesystem.js.map +1 -1
  40. package/dist/react-native/fetcherHTTP.js +4 -3
  41. package/dist/react-native/fetcherHTTP.js.map +1 -1
  42. package/dist/react-native/modelsRepositoryClient.js +15 -7
  43. package/dist/react-native/modelsRepositoryClient.js.map +1 -1
  44. package/dist/react-native/modelsRepositoryServiceClient.js +6 -1
  45. package/dist/react-native/modelsRepositoryServiceClient.js.map +1 -1
  46. package/dist/react-native/psuedoParser.js +1 -0
  47. package/dist/react-native/psuedoParser.js.map +1 -1
  48. package/package.json +2 -2
@@ -13,6 +13,7 @@ import { logger } from "./logger.js";
13
13
  * @internal
14
14
  */
15
15
  export class DtmiResolver {
16
+ _fetcher;
16
17
  constructor(fetcher) {
17
18
  this._fetcher = fetcher;
18
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dtmiResolver.js","sourceRoot":"","sources":["../../src/dtmiResolver.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IAEvB,YAAY,OAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CACX,KAAe,EACf,aAAsB,EACtB,OAA0B;QAE1B,MAAM,QAAQ,GAA6B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AC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions } from \"@azure/core-client\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\nimport { convertDtmiToPath } from \"./dtmiConventions.js\";\nimport { ModelError } from \"./exceptions.js\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport { logger } from \"./logger.js\";\n\n/**\n * DtmiResolver handles reformatting the DTMIs to paths and passing options\n * down to the configured fetcher. It is almost like a middle man between the\n * user-facing API and the PsuedoParser (which identifies if there are sub-dependencies\n * to resolve), and the configured fetcher, which will go out to the endpoint,\n * either in the filesystem or through a URI, and actually get the model we want.\n *\n * @internal\n */\nexport class DtmiResolver {\n private _fetcher: Fetcher;\n constructor(fetcher: Fetcher) {\n this._fetcher = fetcher;\n }\n\n async resolve(\n dtmis: string[],\n expandedModel: boolean,\n options?: OperationOptions,\n ): Promise<{ [dtmi: string]: DTDL }> {\n const modelMap: { [dtmi: string]: DTDL } = {};\n const dtdlPromises = dtmis.map(async (dtmi) => {\n const dtdlPath = convertDtmiToPath(dtmi, expandedModel);\n logger.info(`Model ${dtmi} located in repository at ${dtdlPath}`);\n const dtdl = await this._fetcher.fetch(dtdlPath, options);\n if (expandedModel) {\n if (Array.isArray(dtdl)) {\n const modelIds: string[] = (dtdl as DTDL[]).map((model: DTDL) => model[\"@id\"]);\n if (!modelIds.includes(dtmi)) {\n throw new ModelError(\n `DTMI mismatch on expanded DTDL - Request: ${dtmi}, Response: ${modelIds}`,\n );\n }\n for (const model of dtdl) {\n modelMap[model[\"@id\"]] = model;\n }\n } else {\n throw new ModelError(\"Expanded format should always return an array of models.\");\n }\n } else {\n const model = dtdl as DTDL;\n if (model[\"@id\"] !== dtmi) {\n throw new ModelError(`DTMI mismatch - Request: ${dtmi}, Response ${model[\"@id\"]}`);\n }\n\n modelMap[`${dtmi}`] = model;\n }\n });\n\n await Promise.all(dtdlPromises);\n return modelMap;\n }\n}\n"]}
1
+ {"version":3,"file":"dtmiResolver.js","sourceRoot":"","sources":["../../src/dtmiResolver.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IACf,QAAQ,CAAU;IAC1B,YAAY,OAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CACX,KAAe,EACf,aAAsB,EACtB,OAA0B;QAE1B,MAAM,QAAQ,GAA6B,EAAE,CAAC;QAC9C,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC5C,MAAM,QAAQ,GAAG,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;YACxD,MAAM,CAAC,IAAI,CAAC,SAAS,IAAI,6BAA6B,QAAQ,EAAE,CAAC,CAAC;YAClE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC1D,IAAI,aAAa,EAAE,CAAC;gBAClB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxB,MAAM,QAAQ,GAAc,IAAe,CAAC,GAAG,CAAC,CAAC,KAAW,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;oBAC/E,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;wBAC7B,MAAM,IAAI,UAAU,CAClB,6CAA6C,IAAI,eAAe,QAAQ,EAAE,CAC3E,CAAC;oBACJ,CAAC;oBACD,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;wBACzB,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC;oBACjC,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,UAAU,CAAC,0DAA0D,CAAC,CAAC;gBACnF,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,GAAG,IAAY,CAAC;gBAC3B,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;oBAC1B,MAAM,IAAI,UAAU,CAAC,4BAA4B,IAAI,cAAc,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACrF,CAAC;gBAED,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC;YAC9B,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions } from \"@azure/core-client\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\nimport { convertDtmiToPath } from \"./dtmiConventions.js\";\nimport { ModelError } from \"./exceptions.js\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport { logger } from \"./logger.js\";\n\n/**\n * DtmiResolver handles reformatting the DTMIs to paths and passing options\n * down to the configured fetcher. It is almost like a middle man between the\n * user-facing API and the PsuedoParser (which identifies if there are sub-dependencies\n * to resolve), and the configured fetcher, which will go out to the endpoint,\n * either in the filesystem or through a URI, and actually get the model we want.\n *\n * @internal\n */\nexport class DtmiResolver {\n private _fetcher: Fetcher;\n constructor(fetcher: Fetcher) {\n this._fetcher = fetcher;\n }\n\n async resolve(\n dtmis: string[],\n expandedModel: boolean,\n options?: OperationOptions,\n ): Promise<{ [dtmi: string]: DTDL }> {\n const modelMap: { [dtmi: string]: DTDL } = {};\n const dtdlPromises = dtmis.map(async (dtmi) => {\n const dtdlPath = convertDtmiToPath(dtmi, expandedModel);\n logger.info(`Model ${dtmi} located in repository at ${dtdlPath}`);\n const dtdl = await this._fetcher.fetch(dtdlPath, options);\n if (expandedModel) {\n if (Array.isArray(dtdl)) {\n const modelIds: string[] = (dtdl as DTDL[]).map((model: DTDL) => model[\"@id\"]);\n if (!modelIds.includes(dtmi)) {\n throw new ModelError(\n `DTMI mismatch on expanded DTDL - Request: ${dtmi}, Response: ${modelIds}`,\n );\n }\n for (const model of dtdl) {\n modelMap[model[\"@id\"]] = model;\n }\n } else {\n throw new ModelError(\"Expanded format should always return an array of models.\");\n }\n } else {\n const model = dtdl as DTDL;\n if (model[\"@id\"] !== dtmi) {\n throw new ModelError(`DTMI mismatch - Request: ${dtmi}, Response ${model[\"@id\"]}`);\n }\n\n modelMap[`${dtmi}`] = model;\n }\n });\n\n await Promise.all(dtdlPromises);\n return modelMap;\n }\n}\n"]}
@@ -9,25 +9,26 @@ import { logger } from "./logger.js";
9
9
  * @internal
10
10
  */
11
11
  export class HttpFetcher {
12
+ _client;
13
+ _baseURL;
12
14
  // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
13
15
  constructor(baseURL, client) {
14
16
  this._client = client;
15
17
  this._baseURL = baseURL;
16
18
  }
17
19
  async fetch(path, options) {
18
- var _a, _b;
19
20
  logger.info(`Fetching ${path} from remote endpoint`);
20
21
  if (!options) {
21
22
  options = {};
22
23
  }
23
24
  const myURL = this._baseURL + "/" + path;
24
25
  const requestMethod = "GET";
25
- const requestHeader = createHttpHeaders((_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.customHeaders);
26
+ const requestHeader = createHttpHeaders(options.requestOptions?.customHeaders);
26
27
  const requestOptions = {
27
28
  url: myURL,
28
29
  method: requestMethod,
29
30
  headers: requestHeader,
30
- timeout: (_b = options.requestOptions) === null || _b === void 0 ? void 0 : _b.timeout,
31
+ timeout: options.requestOptions?.timeout,
31
32
  abortSignal: options.abortSignal,
32
33
  tracingOptions: options.tracingOptions,
33
34
  allowInsecureConnection: true,
@@ -1 +1 @@
1
- {"version":3,"file":"fetcherHTTP.js","sourceRoot":"","sources":["../../src/fetcherHTTP.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IAItB,wEAAwE;IACxE,YAAY,OAAe,EAAE,MAAqB;QAChD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY,EAAE,OAA0B;;QAClD,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,uBAAuB,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,GAAG,GAAG,GAAG,IAAI,CAAC;QACzC,MAAM,aAAa,GAAgB,KAAK,CAAC;QACzC,MAAM,aAAa,GAAgB,iBAAiB,CAAC,MAAA,OAAO,CAAC,cAAc,0CAAE,aAAa,CAAC,CAAC;QAC5F,MAAM,cAAc,GAAG;YACrB,GAAG,EAAE,KAAK;YACV,MAAM,EAAE,aAAa;YACrB,OAAO,EAAE,aAAa;YACtB,OAAO,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,OAAO;YACxC,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,uBAAuB,EAAE,IAAI;SAC9B,CAAC;QACF,MAAM,OAAO,GAAoB,qBAAqB,CAAC,cAAc,CAAC,CAAC;QACvE,MAAM,GAAG,GAAqB,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAEtE,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YAC1C,MAAM,YAAY,GAAG,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;YAC1C,MAAM,UAAU,GAAkB,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAC3D,OAAO,UAAU,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,SAAS,CAAC,+CAA+C,EAAE;gBACnE,IAAI,EAAE,kBAAkB;gBACxB,UAAU,EAAE,GAAG,CAAC,MAAM;gBACtB,QAAQ,EAAE,GAAG;gBACb,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions, ServiceClient } from \"@azure/core-client\";\nimport type {\n HttpHeaders,\n HttpMethods,\n PipelineRequest,\n PipelineResponse,\n} from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest, RestError } from \"@azure/core-rest-pipeline\";\nimport { logger } from \"./logger.js\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\n\n/**\n * The HTTP Fetcher implements the Fetcher interface to\n * retrieve models through HTTP calls.\n *\n * @internal\n */\nexport class HttpFetcher implements Fetcher {\n private _client: ServiceClient;\n private _baseURL: string;\n\n // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters\n constructor(baseURL: string, client: ServiceClient) {\n this._client = client;\n this._baseURL = baseURL;\n }\n\n async fetch(path: string, options?: OperationOptions): Promise<DTDL | DTDL[]> {\n logger.info(`Fetching ${path} from remote endpoint`);\n if (!options) {\n options = {};\n }\n const myURL = this._baseURL + \"/\" + path;\n const requestMethod: HttpMethods = \"GET\";\n const requestHeader: HttpHeaders = createHttpHeaders(options.requestOptions?.customHeaders);\n const requestOptions = {\n url: myURL,\n method: requestMethod,\n headers: requestHeader,\n timeout: options.requestOptions?.timeout,\n abortSignal: options.abortSignal,\n tracingOptions: options.tracingOptions,\n allowInsecureConnection: true,\n };\n const request: PipelineRequest = createPipelineRequest(requestOptions);\n const res: PipelineResponse = await this._client.sendRequest(request);\n\n if (res.status >= 200 && res.status < 400) {\n const dtdlAsString = res.bodyAsText || \"\";\n const parsedDtdl: DTDL | DTDL[] = JSON.parse(dtdlAsString);\n return parsedDtdl;\n } else {\n throw new RestError(\"Error on HTTP Request in remote model fetcher\", {\n code: \"ResourceNotFound\",\n statusCode: res.status,\n response: res,\n request: request,\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"fetcherHTTP.js","sourceRoot":"","sources":["../../src/fetcherHTTP.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACd,OAAO,CAAgB;IACvB,QAAQ,CAAS;IAEzB,wEAAwE;IACxE,YAAY,OAAe,EAAE,MAAqB;QAChD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY,EAAE,OAA0B;QAClD,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,uBAAuB,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,GAAG,GAAG,GAAG,IAAI,CAAC;QACzC,MAAM,aAAa,GAAgB,KAAK,CAAC;QACzC,MAAM,aAAa,GAAgB,iBAAiB,CAAC,OAAO,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;QAC5F,MAAM,cAAc,GAAG;YACrB,GAAG,EAAE,KAAK;YACV,MAAM,EAAE,aAAa;YACrB,OAAO,EAAE,aAAa;YACtB,OAAO,EAAE,OAAO,CAAC,cAAc,EAAE,OAAO;YACxC,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,uBAAuB,EAAE,IAAI;SAC9B,CAAC;QACF,MAAM,OAAO,GAAoB,qBAAqB,CAAC,cAAc,CAAC,CAAC;QACvE,MAAM,GAAG,GAAqB,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAEtE,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YAC1C,MAAM,YAAY,GAAG,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;YAC1C,MAAM,UAAU,GAAkB,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAC3D,OAAO,UAAU,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,SAAS,CAAC,+CAA+C,EAAE;gBACnE,IAAI,EAAE,kBAAkB;gBACxB,UAAU,EAAE,GAAG,CAAC,MAAM;gBACtB,QAAQ,EAAE,GAAG;gBACb,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions, ServiceClient } from \"@azure/core-client\";\nimport type {\n HttpHeaders,\n HttpMethods,\n PipelineRequest,\n PipelineResponse,\n} from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest, RestError } from \"@azure/core-rest-pipeline\";\nimport { logger } from \"./logger.js\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\n\n/**\n * The HTTP Fetcher implements the Fetcher interface to\n * retrieve models through HTTP calls.\n *\n * @internal\n */\nexport class HttpFetcher implements Fetcher {\n private _client: ServiceClient;\n private _baseURL: string;\n\n // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters\n constructor(baseURL: string, client: ServiceClient) {\n this._client = client;\n this._baseURL = baseURL;\n }\n\n async fetch(path: string, options?: OperationOptions): Promise<DTDL | DTDL[]> {\n logger.info(`Fetching ${path} from remote endpoint`);\n if (!options) {\n options = {};\n }\n const myURL = this._baseURL + \"/\" + path;\n const requestMethod: HttpMethods = \"GET\";\n const requestHeader: HttpHeaders = createHttpHeaders(options.requestOptions?.customHeaders);\n const requestOptions = {\n url: myURL,\n method: requestMethod,\n headers: requestHeader,\n timeout: options.requestOptions?.timeout,\n abortSignal: options.abortSignal,\n tracingOptions: options.tracingOptions,\n allowInsecureConnection: true,\n };\n const request: PipelineRequest = createPipelineRequest(requestOptions);\n const res: PipelineResponse = await this._client.sendRequest(request);\n\n if (res.status >= 200 && res.status < 400) {\n const dtdlAsString = res.bodyAsText || \"\";\n const parsedDtdl: DTDL | DTDL[] = JSON.parse(dtdlAsString);\n return parsedDtdl;\n } else {\n throw new RestError(\"Error on HTTP Request in remote model fetcher\", {\n code: \"ResourceNotFound\",\n statusCode: res.status,\n response: res,\n request: request,\n });\n }\n }\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- import { __rest } from "tslib";
4
3
  import { DEFAULT_API_VERSION, DEFAULT_REPOSITORY_LOCATION, DEFAULT_USER_AGENT, DEPENDENCY_MODE_DISABLED, DEPENDENCY_MODE_ENABLED, DEPENDENCY_MODE_TRY_FROM_EXPANDED, } from "./utils/constants.js";
5
4
  import { createClientPipeline } from "@azure/core-client";
6
5
  import { isLocalPath, normalize } from "./utils/path.js";
@@ -14,6 +13,12 @@ import { HttpFetcher } from "./fetcherHTTP.js";
14
13
  * Initializes a new instance of the IoT Models Repository Client.
15
14
  */
16
15
  export class ModelsRepositoryClient {
16
+ _repositoryLocation;
17
+ _dependencyResolution;
18
+ _apiVersion;
19
+ _fetcher;
20
+ _resolver;
21
+ _pseudoParser;
17
22
  /**
18
23
  * The ModelsRepositoryClient constructor
19
24
  * @param options - The models repository client options that govern the behavior of the client.
@@ -69,7 +74,7 @@ export class ModelsRepositoryClient {
69
74
  * to create the IoT Models Repository Service Client.
70
75
  */
71
76
  _createClient(options) {
72
- const pipelineOptions = __rest(options, []);
77
+ const { ...pipelineOptions } = options;
73
78
  if (!pipelineOptions.userAgentOptions) {
74
79
  pipelineOptions.userAgentOptions = {};
75
80
  }
@@ -79,11 +84,14 @@ export class ModelsRepositoryClient {
79
84
  else {
80
85
  pipelineOptions.userAgentOptions.userAgentPrefix = DEFAULT_USER_AGENT;
81
86
  }
82
- const internalPipelineOptions = Object.assign(Object.assign({}, pipelineOptions), {
83
- loggingOptions: {
84
- logger: logger.info,
87
+ const internalPipelineOptions = {
88
+ ...pipelineOptions,
89
+ ...{
90
+ loggingOptions: {
91
+ logger: logger.info,
92
+ },
85
93
  },
86
- });
94
+ };
87
95
  const pipeline = createClientPipeline(internalPipelineOptions);
88
96
  const client = new IoTModelsRepositoryServiceClient(this._repositoryLocation, { pipeline });
89
97
  return client;
@@ -133,7 +141,7 @@ export class ModelsRepositoryClient {
133
141
  if (!Array.isArray(dtmis)) {
134
142
  dtmis = [dtmis];
135
143
  }
136
- const dependencyResolution = (options === null || options === void 0 ? void 0 : options.dependencyResolution) || this._dependencyResolution;
144
+ const dependencyResolution = options?.dependencyResolution || this._dependencyResolution;
137
145
  if (dependencyResolution === DEPENDENCY_MODE_DISABLED) {
138
146
  logger.info("Getting models w/ dependency resolution mode: disabled");
139
147
  logger.info(`Retreiving model(s): ${dtmis}...`);
@@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C;oBACN,MAAM,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,SAAS,CAAC,uCAAuC,oBAAoB,EAAE,CAAC,CAAC;QACjF,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n DEFAULT_API_VERSION,\n DEFAULT_REPOSITORY_LOCATION,\n DEFAULT_USER_AGENT,\n DEPENDENCY_MODE_DISABLED,\n DEPENDENCY_MODE_ENABLED,\n DEPENDENCY_MODE_TRY_FROM_EXPANDED,\n} from \"./utils/constants.js\";\nimport type { InternalClientPipelineOptions } from \"@azure/core-client\";\nimport { createClientPipeline } from \"@azure/core-client\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport { isLocalPath, normalize } from \"./utils/path.js\";\nimport { FilesystemFetcher } from \"./fetcherFilesystem.js\";\nimport type { dependencyResolutionType } from \"./dependencyResolutionType.js\";\nimport { DtmiResolver } from \"./dtmiResolver.js\";\nimport { PseudoParser } from \"./psuedoParser.js\";\nimport type { ModelsRepositoryClientOptions } from \"./interfaces/modelsRepositoryClientOptions.js\";\nimport { logger } from \"./logger.js\";\nimport { IoTModelsRepositoryServiceClient } from \"./modelsRepositoryServiceClient.js\";\nimport { HttpFetcher } from \"./fetcherHTTP.js\";\nimport type { GetModelsOptions } from \"./interfaces/getModelsOptions.js\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\n\n/**\n * Initializes a new instance of the IoT Models Repository Client.\n */\nexport class ModelsRepositoryClient {\n private _repositoryLocation: string;\n private _dependencyResolution: dependencyResolutionType;\n private _apiVersion: string;\n private _fetcher: Fetcher;\n private _resolver: DtmiResolver;\n private _pseudoParser: PseudoParser;\n\n /**\n * The ModelsRepositoryClient constructor\n * @param options - The models repository client options that govern the behavior of the client.\n */\n constructor(options: ModelsRepositoryClientOptions = {}) {\n this._repositoryLocation = options.repositoryLocation || DEFAULT_REPOSITORY_LOCATION;\n logger.info(`Client configured for repository location ${this._repositoryLocation}`);\n this._dependencyResolution =\n options.dependencyResolution ||\n this._checkDefaultDependencyResolution(!!options.repositoryLocation);\n logger.info(`Client configured for dependency mode: ${this._dependencyResolution}`);\n this._fetcher = this._createFetcher(this._repositoryLocation, options);\n this._resolver = new DtmiResolver(this._fetcher);\n this._pseudoParser = new PseudoParser(this._resolver);\n\n // Store api version here (for now). Currently doesn't do anything\n this._apiVersion = options.apiVersion || DEFAULT_API_VERSION;\n }\n\n /**\n * improves the readability of the constructor.\n * based on a boolean returns the proper dependency resolution setting string.\n */\n private _checkDefaultDependencyResolution(customRepository: boolean): dependencyResolutionType {\n if (customRepository) {\n return \"enabled\";\n } else {\n return \"tryFromExpanded\";\n }\n }\n\n /**\n * Though currently not relevant, can specify API Version for communicating with\n * the service.\n */\n get apiVersion(): string {\n return this._apiVersion;\n }\n\n /**\n * Configured repository location for this instance. Will be used as the endpoint to get the models from.\n */\n get repositoryLocation(): string {\n return this._repositoryLocation;\n }\n\n /**\n * Configured type of dependency resolution for this instance. Dictates how the client deals with model dependencies.\n */\n get dependencyResolution(): dependencyResolutionType {\n return this._dependencyResolution;\n }\n\n /**\n * Because of the local / remote optionality of this client, the service client\n * must be dynamically generated based on the repository location. If the provided\n * repository location is a remote location, then this private method will be used\n * to create the IoT Models Repository Service Client.\n */\n private _createClient(options: ModelsRepositoryClientOptions): IoTModelsRepositoryServiceClient {\n const { ...pipelineOptions } = options;\n\n if (!pipelineOptions.userAgentOptions) {\n pipelineOptions.userAgentOptions = {};\n }\n if (pipelineOptions.userAgentOptions.userAgentPrefix) {\n pipelineOptions.userAgentOptions.userAgentPrefix = `${pipelineOptions.userAgentOptions.userAgentPrefix} ${DEFAULT_USER_AGENT}`;\n } else {\n pipelineOptions.userAgentOptions.userAgentPrefix = DEFAULT_USER_AGENT;\n }\n\n const internalPipelineOptions: InternalClientPipelineOptions = {\n ...pipelineOptions,\n ...{\n loggingOptions: {\n logger: logger.info,\n },\n },\n };\n\n const pipeline = createClientPipeline(internalPipelineOptions);\n const client = new IoTModelsRepositoryServiceClient(this._repositoryLocation, { pipeline });\n return client;\n }\n\n /**\n * The fetcher is an abstraction necessary since this client can communicate with remote or local\n * Model Repositories based on the provided location. It will analyze the provided location based\n * on that create either an HTTP Fetcher, which uses the IoT Models Repository Service Client,\n * or a Filesystem Fetcher.\n */\n private _createFetcher(location: string, options: ModelsRepositoryClientOptions): Fetcher {\n let locationURL;\n let fetcher;\n if (isLocalPath(location)) {\n // POSIX Filesystem Path or Windows Filesystem Path\n logger.info(`Repository location identified as filesystem path - using FilesystemFetcher`);\n fetcher = new FilesystemFetcher(normalize(location));\n } else {\n locationURL = new URL(location);\n const prot = locationURL.protocol;\n if (prot.includes(\"http\") || prot.includes(\"https\")) {\n logger.info(`Repository location identified as HTTP/HTTPS endpoint - using HttpFetcher`);\n const client = this._createClient(options);\n fetcher = new HttpFetcher(location, client);\n } else if (prot.includes(\"file\")) {\n // filesystem URI\n logger.info(\"Repository Location identified as filesystem URI - using FilesystemFetcher\");\n fetcher = new FilesystemFetcher(location);\n } else if (prot === \"\" && location.search(/\\.[a-zA-Z]{2,63}$/)) {\n // Web URL with protocol unspecified - default to HTTPS\n logger.info(\n \"Repository Location identified as remote endpoint without protocol specified - using HttpFetcher\",\n );\n const fLocation = \"https://\" + location;\n const client = this._createClient(options);\n fetcher = new HttpFetcher(fLocation, client);\n } else {\n throw new EvalError(`Unable to identify location: ${location}`);\n }\n }\n\n return fetcher;\n }\n\n /**\n * Retrieve one or more models based upon on or more provided dtmis.\n * @param dtmis - one dtmi represented as a string\n * @param options - options to govern behavior of model getter.\n */\n async getModels(dtmis: string, options?: GetModelsOptions): Promise<{ [dtmi: string]: unknown }>;\n /**\n * Retrieve one or more models based upon on or more provided dtmis.\n * @param dtmis - dtmi strings in an array.\n * @param options - options to govern behavior of model getter.\n */\n async getModels(\n dtmis: string[],\n options?: GetModelsOptions,\n ): Promise<{ [dtmi: string]: unknown }>;\n async getModels(\n dtmis: string | string[],\n options?: GetModelsOptions,\n ): Promise<{ [dtmi: string]: unknown }> {\n let modelMap: { [dtmi: string]: unknown };\n if (!Array.isArray(dtmis)) {\n dtmis = [dtmis];\n }\n\n const dependencyResolution = options?.dependencyResolution || this._dependencyResolution;\n\n if (dependencyResolution === DEPENDENCY_MODE_DISABLED) {\n logger.info(\"Getting models w/ dependency resolution mode: disabled\");\n logger.info(`Retreiving model(s): ${dtmis}...`);\n modelMap = await this._resolver.resolve(dtmis, false, options);\n } else if (dependencyResolution === DEPENDENCY_MODE_ENABLED) {\n logger.info(`Getting models w/ dependency resolution mode: enabled`);\n logger.info(`Retreiving model(s): ${dtmis}...`);\n const baseModelMap = await this._resolver.resolve(dtmis, false, options);\n const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key]);\n logger.info(`Retreiving model dependencies for ${dtmis}...`);\n modelMap = await this._pseudoParser.expand(baseModelList, false);\n } else if (dependencyResolution === DEPENDENCY_MODE_TRY_FROM_EXPANDED) {\n logger.info(`Getting models w/ dependency resolution mode: tryFromExpanded`);\n try {\n logger.info(`Retreiving expanded model(s): ${dtmis}...`);\n modelMap = await this._resolver.resolve(dtmis, true, options);\n } catch (e: any) {\n if (e.name === \"RestError\" && e.code === \"ResouceNotFound\") {\n logger.info(\"Could not retrieve model(s) from expanded model DTDL - \");\n const baseModelMap: { [dtmi: string]: unknown } = await this._resolver.resolve(\n dtmis,\n false,\n options,\n );\n const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key]);\n logger.info(`Retreiving model dependencies for ${dtmis}...`);\n modelMap = await this._pseudoParser.expand(baseModelList as DTDL[], true);\n } else {\n throw e;\n }\n }\n } else {\n throw EvalError(`Invalid dependency resolution mode: ${dependencyResolution}`);\n }\n\n return modelMap;\n }\n}\n"]}
1
+ {"version":3,"file":"modelsRepositoryClient.js","sourceRoot":"","sources":["../../src/modelsRepositoryClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;A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N,MAAM,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,SAAS,CAAC,uCAAuC,oBAAoB,EAAE,CAAC,CAAC;QACjF,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n DEFAULT_API_VERSION,\n DEFAULT_REPOSITORY_LOCATION,\n DEFAULT_USER_AGENT,\n DEPENDENCY_MODE_DISABLED,\n DEPENDENCY_MODE_ENABLED,\n DEPENDENCY_MODE_TRY_FROM_EXPANDED,\n} from \"./utils/constants.js\";\nimport type { InternalClientPipelineOptions } from \"@azure/core-client\";\nimport { createClientPipeline } from \"@azure/core-client\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport { isLocalPath, normalize } from \"./utils/path.js\";\nimport { FilesystemFetcher } from \"./fetcherFilesystem.js\";\nimport type { dependencyResolutionType } from \"./dependencyResolutionType.js\";\nimport { DtmiResolver } from \"./dtmiResolver.js\";\nimport { PseudoParser } from \"./psuedoParser.js\";\nimport type { ModelsRepositoryClientOptions } from \"./interfaces/modelsRepositoryClientOptions.js\";\nimport { logger } from \"./logger.js\";\nimport { IoTModelsRepositoryServiceClient } from \"./modelsRepositoryServiceClient.js\";\nimport { HttpFetcher } from \"./fetcherHTTP.js\";\nimport type { GetModelsOptions } from \"./interfaces/getModelsOptions.js\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\n\n/**\n * Initializes a new instance of the IoT Models Repository Client.\n */\nexport class ModelsRepositoryClient {\n private _repositoryLocation: string;\n private _dependencyResolution: dependencyResolutionType;\n private _apiVersion: string;\n private _fetcher: Fetcher;\n private _resolver: DtmiResolver;\n private _pseudoParser: PseudoParser;\n\n /**\n * The ModelsRepositoryClient constructor\n * @param options - The models repository client options that govern the behavior of the client.\n */\n constructor(options: ModelsRepositoryClientOptions = {}) {\n this._repositoryLocation = options.repositoryLocation || DEFAULT_REPOSITORY_LOCATION;\n logger.info(`Client configured for repository location ${this._repositoryLocation}`);\n this._dependencyResolution =\n options.dependencyResolution ||\n this._checkDefaultDependencyResolution(!!options.repositoryLocation);\n logger.info(`Client configured for dependency mode: ${this._dependencyResolution}`);\n this._fetcher = this._createFetcher(this._repositoryLocation, options);\n this._resolver = new DtmiResolver(this._fetcher);\n this._pseudoParser = new PseudoParser(this._resolver);\n\n // Store api version here (for now). Currently doesn't do anything\n this._apiVersion = options.apiVersion || DEFAULT_API_VERSION;\n }\n\n /**\n * improves the readability of the constructor.\n * based on a boolean returns the proper dependency resolution setting string.\n */\n private _checkDefaultDependencyResolution(customRepository: boolean): dependencyResolutionType {\n if (customRepository) {\n return \"enabled\";\n } else {\n return \"tryFromExpanded\";\n }\n }\n\n /**\n * Though currently not relevant, can specify API Version for communicating with\n * the service.\n */\n get apiVersion(): string {\n return this._apiVersion;\n }\n\n /**\n * Configured repository location for this instance. Will be used as the endpoint to get the models from.\n */\n get repositoryLocation(): string {\n return this._repositoryLocation;\n }\n\n /**\n * Configured type of dependency resolution for this instance. Dictates how the client deals with model dependencies.\n */\n get dependencyResolution(): dependencyResolutionType {\n return this._dependencyResolution;\n }\n\n /**\n * Because of the local / remote optionality of this client, the service client\n * must be dynamically generated based on the repository location. If the provided\n * repository location is a remote location, then this private method will be used\n * to create the IoT Models Repository Service Client.\n */\n private _createClient(options: ModelsRepositoryClientOptions): IoTModelsRepositoryServiceClient {\n const { ...pipelineOptions } = options;\n\n if (!pipelineOptions.userAgentOptions) {\n pipelineOptions.userAgentOptions = {};\n }\n if (pipelineOptions.userAgentOptions.userAgentPrefix) {\n pipelineOptions.userAgentOptions.userAgentPrefix = `${pipelineOptions.userAgentOptions.userAgentPrefix} ${DEFAULT_USER_AGENT}`;\n } else {\n pipelineOptions.userAgentOptions.userAgentPrefix = DEFAULT_USER_AGENT;\n }\n\n const internalPipelineOptions: InternalClientPipelineOptions = {\n ...pipelineOptions,\n ...{\n loggingOptions: {\n logger: logger.info,\n },\n },\n };\n\n const pipeline = createClientPipeline(internalPipelineOptions);\n const client = new IoTModelsRepositoryServiceClient(this._repositoryLocation, { pipeline });\n return client;\n }\n\n /**\n * The fetcher is an abstraction necessary since this client can communicate with remote or local\n * Model Repositories based on the provided location. It will analyze the provided location based\n * on that create either an HTTP Fetcher, which uses the IoT Models Repository Service Client,\n * or a Filesystem Fetcher.\n */\n private _createFetcher(location: string, options: ModelsRepositoryClientOptions): Fetcher {\n let locationURL;\n let fetcher;\n if (isLocalPath(location)) {\n // POSIX Filesystem Path or Windows Filesystem Path\n logger.info(`Repository location identified as filesystem path - using FilesystemFetcher`);\n fetcher = new FilesystemFetcher(normalize(location));\n } else {\n locationURL = new URL(location);\n const prot = locationURL.protocol;\n if (prot.includes(\"http\") || prot.includes(\"https\")) {\n logger.info(`Repository location identified as HTTP/HTTPS endpoint - using HttpFetcher`);\n const client = this._createClient(options);\n fetcher = new HttpFetcher(location, client);\n } else if (prot.includes(\"file\")) {\n // filesystem URI\n logger.info(\"Repository Location identified as filesystem URI - using FilesystemFetcher\");\n fetcher = new FilesystemFetcher(location);\n } else if (prot === \"\" && location.search(/\\.[a-zA-Z]{2,63}$/)) {\n // Web URL with protocol unspecified - default to HTTPS\n logger.info(\n \"Repository Location identified as remote endpoint without protocol specified - using HttpFetcher\",\n );\n const fLocation = \"https://\" + location;\n const client = this._createClient(options);\n fetcher = new HttpFetcher(fLocation, client);\n } else {\n throw new EvalError(`Unable to identify location: ${location}`);\n }\n }\n\n return fetcher;\n }\n\n /**\n * Retrieve one or more models based upon on or more provided dtmis.\n * @param dtmis - one dtmi represented as a string\n * @param options - options to govern behavior of model getter.\n */\n async getModels(dtmis: string, options?: GetModelsOptions): Promise<{ [dtmi: string]: unknown }>;\n /**\n * Retrieve one or more models based upon on or more provided dtmis.\n * @param dtmis - dtmi strings in an array.\n * @param options - options to govern behavior of model getter.\n */\n async getModels(\n dtmis: string[],\n options?: GetModelsOptions,\n ): Promise<{ [dtmi: string]: unknown }>;\n async getModels(\n dtmis: string | string[],\n options?: GetModelsOptions,\n ): Promise<{ [dtmi: string]: unknown }> {\n let modelMap: { [dtmi: string]: unknown };\n if (!Array.isArray(dtmis)) {\n dtmis = [dtmis];\n }\n\n const dependencyResolution = options?.dependencyResolution || this._dependencyResolution;\n\n if (dependencyResolution === DEPENDENCY_MODE_DISABLED) {\n logger.info(\"Getting models w/ dependency resolution mode: disabled\");\n logger.info(`Retreiving model(s): ${dtmis}...`);\n modelMap = await this._resolver.resolve(dtmis, false, options);\n } else if (dependencyResolution === DEPENDENCY_MODE_ENABLED) {\n logger.info(`Getting models w/ dependency resolution mode: enabled`);\n logger.info(`Retreiving model(s): ${dtmis}...`);\n const baseModelMap = await this._resolver.resolve(dtmis, false, options);\n const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key]);\n logger.info(`Retreiving model dependencies for ${dtmis}...`);\n modelMap = await this._pseudoParser.expand(baseModelList, false);\n } else if (dependencyResolution === DEPENDENCY_MODE_TRY_FROM_EXPANDED) {\n logger.info(`Getting models w/ dependency resolution mode: tryFromExpanded`);\n try {\n logger.info(`Retreiving expanded model(s): ${dtmis}...`);\n modelMap = await this._resolver.resolve(dtmis, true, options);\n } catch (e: any) {\n if (e.name === \"RestError\" && e.code === \"ResouceNotFound\") {\n logger.info(\"Could not retrieve model(s) from expanded model DTDL - \");\n const baseModelMap: { [dtmi: string]: unknown } = await this._resolver.resolve(\n dtmis,\n false,\n options,\n );\n const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key]);\n logger.info(`Retreiving model dependencies for ${dtmis}...`);\n modelMap = await this._pseudoParser.expand(baseModelList as DTDL[], true);\n } else {\n throw e;\n }\n }\n } else {\n throw EvalError(`Invalid dependency resolution mode: ${dependencyResolution}`);\n }\n\n return modelMap;\n }\n}\n"]}
@@ -6,6 +6,8 @@ import { DEFAULT_API_VERSION } from "./utils/constants.js";
6
6
  * @internal
7
7
  */
8
8
  export class IoTModelsRepositoryServiceClient extends ServiceClient {
9
+ url;
10
+ version;
9
11
  /**
10
12
  * Initializes a new instance of the IoTModelsRepositoryServiceClient class.
11
13
  *
@@ -17,7 +19,10 @@ export class IoTModelsRepositoryServiceClient extends ServiceClient {
17
19
  baseUri: `${url}`,
18
20
  requestContentType: "application/json; charset=utf-8",
19
21
  };
20
- const optionsWithDefaults = Object.assign(Object.assign({}, defaults), options);
22
+ const optionsWithDefaults = {
23
+ ...defaults,
24
+ ...options,
25
+ };
21
26
  super(optionsWithDefaults);
22
27
  this.url = url;
23
28
  this.version = options.version || DEFAULT_API_VERSION;
@@ -1 +1 @@
1
- {"version":3,"file":"modelsRepositoryServiceClient.js","sourceRoot":"","sources":["../../src/modelsRepositoryServiceClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAS3D;;GAEG;AACH,MAAM,OAAO,gCAAiC,SAAQ,aAAa;IAIjE;;;;;OAKG;IACH,YAAY,GAAW,EAAE,UAAmD,EAAE;QAC5E,MAAM,QAAQ,GAA4C;YACxD,OAAO,EAAE,GAAG,GAAG,EAAE;YACjB,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,mBAAmB,mCACpB,QAAQ,GACR,OAAO,CACX,CAAC;QAEF,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAE3B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,mBAAmB,CAAC;IACxD,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ServiceClientOptions } from \"@azure/core-client\";\nimport { ServiceClient } from \"@azure/core-client\";\nimport { DEFAULT_API_VERSION } from \"./utils/constants.js\";\n\ninterface IoTModelsRepositoryServiceClientOptions extends ServiceClientOptions {\n // API Version to be used during HTTP Calls.\n version?: string;\n // Endpoint that will be base of URLs for HTTP calls.\n endpoint?: string;\n}\n\n/**\n * @internal\n */\nexport class IoTModelsRepositoryServiceClient extends ServiceClient {\n url: string;\n version: string;\n\n /**\n * Initializes a new instance of the IoTModelsRepositoryServiceClient class.\n *\n * @param url - The URL of the service account or table that is the target of the desired operation.\n * @param options - The parameter options\n */\n constructor(url: string, options: IoTModelsRepositoryServiceClientOptions = {}) {\n const defaults: IoTModelsRepositoryServiceClientOptions = {\n baseUri: `${url}`,\n requestContentType: \"application/json; charset=utf-8\",\n };\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n };\n\n super(optionsWithDefaults);\n\n this.url = url;\n this.version = options.version || DEFAULT_API_VERSION;\n }\n}\n"]}
1
+ {"version":3,"file":"modelsRepositoryServiceClient.js","sourceRoot":"","sources":["../../src/modelsRepositoryServiceClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAS3D;;GAEG;AACH,MAAM,OAAO,gCAAiC,SAAQ,aAAa;IACjE,GAAG,CAAS;IACZ,OAAO,CAAS;IAEhB;;;;;OAKG;IACH,YAAY,GAAW,EAAE,UAAmD,EAAE;QAC5E,MAAM,QAAQ,GAA4C;YACxD,OAAO,EAAE,GAAG,GAAG,EAAE;YACjB,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,mBAAmB,GAAG;YAC1B,GAAG,QAAQ;YACX,GAAG,OAAO;SACX,CAAC;QAEF,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAE3B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,mBAAmB,CAAC;IACxD,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ServiceClientOptions } from \"@azure/core-client\";\nimport { ServiceClient } from \"@azure/core-client\";\nimport { DEFAULT_API_VERSION } from \"./utils/constants.js\";\n\ninterface IoTModelsRepositoryServiceClientOptions extends ServiceClientOptions {\n // API Version to be used during HTTP Calls.\n version?: string;\n // Endpoint that will be base of URLs for HTTP calls.\n endpoint?: string;\n}\n\n/**\n * @internal\n */\nexport class IoTModelsRepositoryServiceClient extends ServiceClient {\n url: string;\n version: string;\n\n /**\n * Initializes a new instance of the IoTModelsRepositoryServiceClient class.\n *\n * @param url - The URL of the service account or table that is the target of the desired operation.\n * @param options - The parameter options\n */\n constructor(url: string, options: IoTModelsRepositoryServiceClientOptions = {}) {\n const defaults: IoTModelsRepositoryServiceClientOptions = {\n baseUri: `${url}`,\n requestContentType: \"application/json; charset=utf-8\",\n };\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n };\n\n super(optionsWithDefaults);\n\n this.url = url;\n this.version = options.version || DEFAULT_API_VERSION;\n }\n}\n"]}
@@ -14,6 +14,7 @@ import { RestError } from "@azure/core-rest-pipeline";
14
14
  * @internal
15
15
  */
16
16
  export class PseudoParser {
17
+ _resolver;
17
18
  // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
18
19
  constructor(resolver) {
19
20
  this._resolver = resolver;
@@ -1 +1 @@
1
- {"version":3,"file":"psuedoParser.js","sourceRoot":"","sources":["../../src/psuedoParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,YAAY;IAGvB,wEAAwE;IACxE,YAAY,QAAsB;QAChC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,eAAwB;QACnD,MAAM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ACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAChC,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;gBACtC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACnC,CAAC;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBACxC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;oBAChC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;wBAChC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBAC7B,CAAC;yBAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;wBACvC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;oBACzD,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;QACvD,OAAO,YAAY,CAAC;IACtB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { DTDL } from \"./psuedoDtdl.js\";\nimport { logger } from \"./logger.js\";\nimport type { DtmiResolver } from \"./dtmiResolver.js\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\n\n/**\n * The PsuedoParser is an interesting implementation. Essentially, this\n * codebase works in tandem with a Digital Twins Parser, which simultaneously\n * defines the DTDL structure and validates models match the correct DTDL format.\n * In lieu of using that Parser as a dependency (for a complex network of reasons),\n * we implement this class, which kind of parses. Because it uses the resovler too,\n * we can, during psuedo-parsing, identify any times we should resolve a dependency,\n * and then resolve the dependencies until the dependency tree is fully resolved.\n *\n * @internal\n */\nexport class PseudoParser {\n private _resolver: DtmiResolver;\n\n // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters\n constructor(resolver: DtmiResolver) {\n this._resolver = resolver;\n }\n\n async expand(models: DTDL[], tryFromExpanded: boolean): Promise<{ [dtmi: string]: DTDL }> {\n const expandedMap: { [dtmi: string]: DTDL } = {};\n for (let i = 0; i < models.length; i++) {\n const model: DTDL = models[i];\n if (model[\"@id\"] !== undefined) {\n expandedMap[model[\"@id\"]] = model;\n } else {\n throw Error(`model ${model} does not contain @id member`);\n }\n await this._expand(model, expandedMap, tryFromExpanded);\n }\n return expandedMap;\n }\n\n private async _expand(\n model: DTDL,\n modelMap: { [dtmi: string]: DTDL },\n tryFromExpanded: boolean,\n ): Promise<void> {\n logger.info(`Expanding model: ${model[\"@id\"]}`);\n const dependencies = this._getModelDependencies(model);\n const dependenciesToResolve = dependencies.filter((dependency: string) => {\n return !(dependency in modelMap);\n });\n if (dependenciesToResolve.length !== 0) {\n logger.info(`Outstanding dependencies found: ${dependenciesToResolve}`);\n let resolvedDependenciesMap: { [s: string]: unknown };\n try {\n resolvedDependenciesMap = await this._resolver.resolve(\n dependenciesToResolve,\n tryFromExpanded,\n );\n } catch (e: any) {\n if (e instanceof RestError) {\n resolvedDependenciesMap = await this._resolver.resolve(dependenciesToResolve, false);\n } else {\n throw e;\n }\n }\n Object.keys(resolvedDependenciesMap).forEach((key) => {\n modelMap[key] = resolvedDependenciesMap[key] as DTDL;\n });\n const promiseList: Promise<void>[] = [];\n Object.values(resolvedDependenciesMap).forEach((dependencyModel) => {\n promiseList.push(this._expand(dependencyModel as DTDL, modelMap, tryFromExpanded));\n });\n await Promise.all(promiseList);\n }\n }\n\n private _getModelDependencies(model: DTDL): string[] {\n const dependencies = [];\n\n if (model.contents !== undefined) {\n const contents = model.contents;\n contents.forEach((element) => {\n if (\n element[\"@type\"] &&\n typeof element[\"@type\"] === \"string\" &&\n element[\"@type\"] === \"Component\"\n ) {\n if (element.schema && typeof element.schema === \"string\") {\n dependencies.push(element.schema);\n }\n }\n });\n }\n\n if (model.extends !== undefined) {\n if (typeof model.extends === \"string\") {\n dependencies.push(model.extends);\n } else if (Array.isArray(model.extends)) {\n model.extends.forEach((element) => {\n if (typeof element === \"string\") {\n dependencies.push(element);\n } else if (typeof element === \"object\") {\n dependencies.push(this._getModelDependencies(element));\n }\n });\n }\n }\n\n const noDuplicates = Array.from(new Set(dependencies));\n return noDuplicates;\n }\n}\n"]}
1
+ {"version":3,"file":"psuedoParser.js","sourceRoot":"","sources":["../../src/psuedoParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,YAAY;IACf,SAAS,CAAe;IAEhC,wEAAwE;IACxE,YAAY,QAAsB;QAChC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,eAAwB;QACnD,MAAM,WAAW,GAA6B,EAAE,CAAC;QACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,MAAM,KAAK,GAAS,MAAM,CAAC,CAAC,CAAC,CAAC;YAC9B,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC/B,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,CAAC,SAAS,KAAK,8BAA8B,CAAC,CAAC;YAC5D,CAAC;YACD,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAA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C,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;oBACzD,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;QACvD,OAAO,YAAY,CAAC;IACtB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { DTDL } from \"./psuedoDtdl.js\";\nimport { logger } from \"./logger.js\";\nimport type { DtmiResolver } from \"./dtmiResolver.js\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\n\n/**\n * The PsuedoParser is an interesting implementation. Essentially, this\n * codebase works in tandem with a Digital Twins Parser, which simultaneously\n * defines the DTDL structure and validates models match the correct DTDL format.\n * In lieu of using that Parser as a dependency (for a complex network of reasons),\n * we implement this class, which kind of parses. Because it uses the resovler too,\n * we can, during psuedo-parsing, identify any times we should resolve a dependency,\n * and then resolve the dependencies until the dependency tree is fully resolved.\n *\n * @internal\n */\nexport class PseudoParser {\n private _resolver: DtmiResolver;\n\n // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters\n constructor(resolver: DtmiResolver) {\n this._resolver = resolver;\n }\n\n async expand(models: DTDL[], tryFromExpanded: boolean): Promise<{ [dtmi: string]: DTDL }> {\n const expandedMap: { [dtmi: string]: DTDL } = {};\n for (let i = 0; i < models.length; i++) {\n const model: DTDL = models[i];\n if (model[\"@id\"] !== undefined) {\n expandedMap[model[\"@id\"]] = model;\n } else {\n throw Error(`model ${model} does not contain @id member`);\n }\n await this._expand(model, expandedMap, tryFromExpanded);\n }\n return expandedMap;\n }\n\n private async _expand(\n model: DTDL,\n modelMap: { [dtmi: string]: DTDL },\n tryFromExpanded: boolean,\n ): Promise<void> {\n logger.info(`Expanding model: ${model[\"@id\"]}`);\n const dependencies = this._getModelDependencies(model);\n const dependenciesToResolve = dependencies.filter((dependency: string) => {\n return !(dependency in modelMap);\n });\n if (dependenciesToResolve.length !== 0) {\n logger.info(`Outstanding dependencies found: ${dependenciesToResolve}`);\n let resolvedDependenciesMap: { [s: string]: unknown };\n try {\n resolvedDependenciesMap = await this._resolver.resolve(\n dependenciesToResolve,\n tryFromExpanded,\n );\n } catch (e: any) {\n if (e instanceof RestError) {\n resolvedDependenciesMap = await this._resolver.resolve(dependenciesToResolve, false);\n } else {\n throw e;\n }\n }\n Object.keys(resolvedDependenciesMap).forEach((key) => {\n modelMap[key] = resolvedDependenciesMap[key] as DTDL;\n });\n const promiseList: Promise<void>[] = [];\n Object.values(resolvedDependenciesMap).forEach((dependencyModel) => {\n promiseList.push(this._expand(dependencyModel as DTDL, modelMap, tryFromExpanded));\n });\n await Promise.all(promiseList);\n }\n }\n\n private _getModelDependencies(model: DTDL): string[] {\n const dependencies = [];\n\n if (model.contents !== undefined) {\n const contents = model.contents;\n contents.forEach((element) => {\n if (\n element[\"@type\"] &&\n typeof element[\"@type\"] === \"string\" &&\n element[\"@type\"] === \"Component\"\n ) {\n if (element.schema && typeof element.schema === \"string\") {\n dependencies.push(element.schema);\n }\n }\n });\n }\n\n if (model.extends !== undefined) {\n if (typeof model.extends === \"string\") {\n dependencies.push(model.extends);\n } else if (Array.isArray(model.extends)) {\n model.extends.forEach((element) => {\n if (typeof element === \"string\") {\n dependencies.push(element);\n } else if (typeof element === \"object\") {\n dependencies.push(this._getModelDependencies(element));\n }\n });\n }\n }\n\n const noDuplicates = Array.from(new Set(dependencies));\n return noDuplicates;\n }\n}\n"]}
@@ -16,6 +16,7 @@ const logger_js_1 = require("./logger.js");
16
16
  * @internal
17
17
  */
18
18
  class DtmiResolver {
19
+ _fetcher;
19
20
  constructor(fetcher) {
20
21
  this._fetcher = fetcher;
21
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dtmiResolver.js","sourceRoot":"","sources":["../../src/dtmiResolver.ts"],"names":[],"mappings":";AAAA,uCAAuC;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,MAAM,KAAK,GAAG,IAAY,CAAC;gBAC3B,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;oBAC1B,MAAM,IAAI,0BAAU,CAAC,4BAA4B,IAAI,cAAc,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACrF,CAAC;gBAED,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC;YAC9B,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA3CD,oCA2CC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions } from \"@azure/core-client\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\nimport { convertDtmiToPath } from \"./dtmiConventions.js\";\nimport { ModelError } from \"./exceptions.js\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport { logger } from \"./logger.js\";\n\n/**\n * DtmiResolver handles reformatting the DTMIs to paths and passing options\n * down to the configured fetcher. It is almost like a middle man between the\n * user-facing API and the PsuedoParser (which identifies if there are sub-dependencies\n * to resolve), and the configured fetcher, which will go out to the endpoint,\n * either in the filesystem or through a URI, and actually get the model we want.\n *\n * @internal\n */\nexport class DtmiResolver {\n private _fetcher: Fetcher;\n constructor(fetcher: Fetcher) {\n this._fetcher = fetcher;\n }\n\n async resolve(\n dtmis: string[],\n expandedModel: boolean,\n options?: OperationOptions,\n ): Promise<{ [dtmi: string]: DTDL }> {\n const modelMap: { [dtmi: string]: DTDL } = {};\n const dtdlPromises = dtmis.map(async (dtmi) => {\n const dtdlPath = convertDtmiToPath(dtmi, expandedModel);\n logger.info(`Model ${dtmi} located in repository at ${dtdlPath}`);\n const dtdl = await this._fetcher.fetch(dtdlPath, options);\n if (expandedModel) {\n if (Array.isArray(dtdl)) {\n const modelIds: string[] = (dtdl as DTDL[]).map((model: DTDL) => model[\"@id\"]);\n if (!modelIds.includes(dtmi)) {\n throw new ModelError(\n `DTMI mismatch on expanded DTDL - Request: ${dtmi}, Response: ${modelIds}`,\n );\n }\n for (const model of dtdl) {\n modelMap[model[\"@id\"]] = model;\n }\n } else {\n throw new ModelError(\"Expanded format should always return an array of models.\");\n }\n } else {\n const model = dtdl as DTDL;\n if (model[\"@id\"] !== dtmi) {\n throw new ModelError(`DTMI mismatch - Request: ${dtmi}, Response ${model[\"@id\"]}`);\n }\n\n modelMap[`${dtmi}`] = model;\n }\n });\n\n await Promise.all(dtdlPromises);\n return modelMap;\n }\n}\n"]}
1
+ {"version":3,"file":"dtmiResolver.js","sourceRoot":"","sources":["../../src/dtmiResolver.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC,6DAAyD;AACzD,mDAA6C;AAE7C,2CAAqC;AAErC;;;;;;;;GAQG;AACH,MAAa,YAAY;IACf,QAAQ,CAAU;IAC1B,YAAY,OAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CACX,KAAe,EACf,aAAsB,EACtB,OAA0B;QAE1B,MAAM,QAAQ,GAA6B,EAAE,CAAC;QAC9C,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC5C,MAAM,QAAQ,GAAG,IAAA,sCAAiB,EAAC,IAAI,EAAE,aAAa,CAAC,CAAC;YACxD,kBAAM,CAAC,IAAI,CAAC,SAAS,IAAI,6BAA6B,QAAQ,EAAE,CAAC,CAAC;YAClE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC1D,IAAI,aAAa,EAAE,CAAC;gBAClB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxB,MAAM,QAAQ,GAAc,IAAe,CAAC,GAAG,CAAC,CAAC,KAAW,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;oBAC/E,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;wBAC7B,MAAM,IAAI,0BAAU,CAClB,6CAA6C,IAAI,eAAe,QAAQ,EAAE,CAC3E,CAAC;oBACJ,CAAC;oBACD,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;wBACzB,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC;oBACjC,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,0BAAU,CAAC,0DAA0D,CAAC,CAAC;gBACnF,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,GAAG,IAAY,CAAC;gBAC3B,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;oBAC1B,MAAM,IAAI,0BAAU,CAAC,4BAA4B,IAAI,cAAc,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACrF,CAAC;gBAED,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC;YAC9B,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA3CD,oCA2CC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions } from \"@azure/core-client\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\nimport { convertDtmiToPath } from \"./dtmiConventions.js\";\nimport { ModelError } from \"./exceptions.js\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport { logger } from \"./logger.js\";\n\n/**\n * DtmiResolver handles reformatting the DTMIs to paths and passing options\n * down to the configured fetcher. It is almost like a middle man between the\n * user-facing API and the PsuedoParser (which identifies if there are sub-dependencies\n * to resolve), and the configured fetcher, which will go out to the endpoint,\n * either in the filesystem or through a URI, and actually get the model we want.\n *\n * @internal\n */\nexport class DtmiResolver {\n private _fetcher: Fetcher;\n constructor(fetcher: Fetcher) {\n this._fetcher = fetcher;\n }\n\n async resolve(\n dtmis: string[],\n expandedModel: boolean,\n options?: OperationOptions,\n ): Promise<{ [dtmi: string]: DTDL }> {\n const modelMap: { [dtmi: string]: DTDL } = {};\n const dtdlPromises = dtmis.map(async (dtmi) => {\n const dtdlPath = convertDtmiToPath(dtmi, expandedModel);\n logger.info(`Model ${dtmi} located in repository at ${dtdlPath}`);\n const dtdl = await this._fetcher.fetch(dtdlPath, options);\n if (expandedModel) {\n if (Array.isArray(dtdl)) {\n const modelIds: string[] = (dtdl as DTDL[]).map((model: DTDL) => model[\"@id\"]);\n if (!modelIds.includes(dtmi)) {\n throw new ModelError(\n `DTMI mismatch on expanded DTDL - Request: ${dtmi}, Response: ${modelIds}`,\n );\n }\n for (const model of dtdl) {\n modelMap[model[\"@id\"]] = model;\n }\n } else {\n throw new ModelError(\"Expanded format should always return an array of models.\");\n }\n } else {\n const model = dtdl as DTDL;\n if (model[\"@id\"] !== dtmi) {\n throw new ModelError(`DTMI mismatch - Request: ${dtmi}, Response ${model[\"@id\"]}`);\n }\n\n modelMap[`${dtmi}`] = model;\n }\n });\n\n await Promise.all(dtdlPromises);\n return modelMap;\n }\n}\n"]}
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.FilesystemFetcher = void 0;
6
6
  const tslib_1 = require("tslib");
7
7
  const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
8
- const path = tslib_1.__importStar(require("node:path"));
8
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
9
9
  const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
10
10
  const logger_js_1 = require("./logger.js");
11
11
  function readFilePromise(filePath) {
@@ -28,12 +28,13 @@ function readFilePromise(filePath) {
28
28
  * @internal
29
29
  */
30
30
  class FilesystemFetcher {
31
+ _baseFilePath;
31
32
  constructor(baseFilePath) {
32
33
  this._baseFilePath = baseFilePath;
33
34
  }
34
35
  async fetch(filePath) {
35
36
  logger_js_1.logger.info(`Fetching ${filePath} from local filesystem`);
36
- const absolutePath = path.join(this._baseFilePath, filePath);
37
+ const absolutePath = node_path_1.default.join(this._baseFilePath, filePath);
37
38
  if (absolutePath.indexOf(this._baseFilePath) !== 0) {
38
39
  throw new Error("Attempted to escape base file path");
39
40
  }
@@ -46,7 +47,7 @@ class FilesystemFetcher {
46
47
  catch (e) {
47
48
  const options = {
48
49
  code: "ResourceNotFound",
49
- statusCode: e === null || e === void 0 ? void 0 : e.status,
50
+ statusCode: e?.status,
50
51
  };
51
52
  throw new core_rest_pipeline_1.RestError("Failed to fetch from Filesystem", options);
52
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fetcherFilesystem.js","sourceRoot":"","sources":["../../src/fetcherFilesystem.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,8DAAyB;AACzB,wDAAkC;AAElC,kEAAsD;AAEtD,2CAAqC;AAGrC,SAAS,eAAe,CAAC,QAAgB;IACvC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,iBAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YAC1C,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACtB,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAa,iBAAiB;IAG5B,YAAY,YAAoB;QAC9B,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,QAAgB;QAC1B,kBAAM,CAAC,IAAI,CAAC,YAAY,QAAQ,wBAAwB,CAAC,CAAC;QAC1D,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAC7D,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,CAAC;YACH,kBAAM,CAAC,IAAI,CAAC,gBAAgB,YAAY,EAAE,CAAC,CAAC;YAC5C,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,YAAY,CAAC,CAAC;YACrD,MAAM,UAAU,GAAkB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACvD,OAAO,UAAU,CAAC;QACpB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,OAAO,GAAqB;gBAChC,IAAI,EAAE,kBAAkB;gBACxB,UAAU,EAAE,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,MAAM;aACtB,CAAC;YACF,MAAM,IAAI,8BAAS,CAAC,iCAAiC,EAAE,OAAO,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;CACF;AA3BD,8CA2BC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport type { RestErrorOptions } from \"@azure/core-rest-pipeline\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport { logger } from \"./logger.js\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\n\nfunction readFilePromise(filePath: string): Promise<string> {\n return new Promise((resolve, reject) => {\n fs.readFile(filePath, \"utf8\", (err, data) => {\n if (err !== undefined) {\n reject(err);\n } else {\n resolve(data);\n }\n return 0;\n });\n });\n}\n\n/**\n * The Filesystem Fetcher implements the generic Fetcher interface\n * so that models are fetched from a filesystem endpoint.\n *\n * @internal\n */\nexport class FilesystemFetcher implements Fetcher {\n private _baseFilePath: string;\n\n constructor(baseFilePath: string) {\n this._baseFilePath = baseFilePath;\n }\n\n async fetch(filePath: string): Promise<DTDL | DTDL[]> {\n logger.info(`Fetching ${filePath} from local filesystem`);\n const absolutePath = path.join(this._baseFilePath, filePath);\n if (absolutePath.indexOf(this._baseFilePath) !== 0) {\n throw new Error(\"Attempted to escape base file path\");\n }\n\n try {\n logger.info(`File open on ${absolutePath}`);\n const dtdlFile = await readFilePromise(absolutePath);\n const parsedDtdl: DTDL | DTDL[] = JSON.parse(dtdlFile);\n return parsedDtdl;\n } catch (e: any) {\n const options: RestErrorOptions = {\n code: \"ResourceNotFound\",\n statusCode: e?.status,\n };\n throw new RestError(\"Failed to fetch from Filesystem\", options);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"fetcherFilesystem.js","sourceRoot":"","sources":["../../src/fetcherFilesystem.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,8DAAyB;AACzB,kEAA6B;AAE7B,kEAAsD;AAEtD,2CAAqC;AAGrC,SAAS,eAAe,CAAC,QAAgB;IACvC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,iBAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YAC1C,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACtB,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAa,iBAAiB;IACpB,aAAa,CAAS;IAE9B,YAAY,YAAoB;QAC9B,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,QAAgB;QAC1B,kBAAM,CAAC,IAAI,CAAC,YAAY,QAAQ,wBAAwB,CAAC,CAAC;QAC1D,MAAM,YAAY,GAAG,mBAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAC7D,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,CAAC;YACH,kBAAM,CAAC,IAAI,CAAC,gBAAgB,YAAY,EAAE,CAAC,CAAC;YAC5C,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,YAAY,CAAC,CAAC;YACrD,MAAM,UAAU,GAAkB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACvD,OAAO,UAAU,CAAC;QACpB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,OAAO,GAAqB;gBAChC,IAAI,EAAE,kBAAkB;gBACxB,UAAU,EAAE,CAAC,EAAE,MAAM;aACtB,CAAC;YACF,MAAM,IAAI,8BAAS,CAAC,iCAAiC,EAAE,OAAO,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;CACF;AA3BD,8CA2BC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { RestErrorOptions } from \"@azure/core-rest-pipeline\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport { logger } from \"./logger.js\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\n\nfunction readFilePromise(filePath: string): Promise<string> {\n return new Promise((resolve, reject) => {\n fs.readFile(filePath, \"utf8\", (err, data) => {\n if (err !== undefined) {\n reject(err);\n } else {\n resolve(data);\n }\n return 0;\n });\n });\n}\n\n/**\n * The Filesystem Fetcher implements the generic Fetcher interface\n * so that models are fetched from a filesystem endpoint.\n *\n * @internal\n */\nexport class FilesystemFetcher implements Fetcher {\n private _baseFilePath: string;\n\n constructor(baseFilePath: string) {\n this._baseFilePath = baseFilePath;\n }\n\n async fetch(filePath: string): Promise<DTDL | DTDL[]> {\n logger.info(`Fetching ${filePath} from local filesystem`);\n const absolutePath = path.join(this._baseFilePath, filePath);\n if (absolutePath.indexOf(this._baseFilePath) !== 0) {\n throw new Error(\"Attempted to escape base file path\");\n }\n\n try {\n logger.info(`File open on ${absolutePath}`);\n const dtdlFile = await readFilePromise(absolutePath);\n const parsedDtdl: DTDL | DTDL[] = JSON.parse(dtdlFile);\n return parsedDtdl;\n } catch (e: any) {\n const options: RestErrorOptions = {\n code: \"ResourceNotFound\",\n statusCode: e?.status,\n };\n throw new RestError(\"Failed to fetch from Filesystem\", options);\n }\n }\n}\n"]}
@@ -12,25 +12,26 @@ const logger_js_1 = require("./logger.js");
12
12
  * @internal
13
13
  */
14
14
  class HttpFetcher {
15
+ _client;
16
+ _baseURL;
15
17
  // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
16
18
  constructor(baseURL, client) {
17
19
  this._client = client;
18
20
  this._baseURL = baseURL;
19
21
  }
20
22
  async fetch(path, options) {
21
- var _a, _b;
22
23
  logger_js_1.logger.info(`Fetching ${path} from remote endpoint`);
23
24
  if (!options) {
24
25
  options = {};
25
26
  }
26
27
  const myURL = this._baseURL + "/" + path;
27
28
  const requestMethod = "GET";
28
- const requestHeader = (0, core_rest_pipeline_1.createHttpHeaders)((_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.customHeaders);
29
+ const requestHeader = (0, core_rest_pipeline_1.createHttpHeaders)(options.requestOptions?.customHeaders);
29
30
  const requestOptions = {
30
31
  url: myURL,
31
32
  method: requestMethod,
32
33
  headers: requestHeader,
33
- timeout: (_b = options.requestOptions) === null || _b === void 0 ? void 0 : _b.timeout,
34
+ timeout: options.requestOptions?.timeout,
34
35
  abortSignal: options.abortSignal,
35
36
  tracingOptions: options.tracingOptions,
36
37
  allowInsecureConnection: true,
@@ -1 +1 @@
1
- {"version":3,"file":"fetcherHTTP.js","sourceRoot":"","sources":["../../src/fetcherHTTP.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AASlC,kEAAgG;AAChG,2CAAqC;AAIrC;;;;;GAKG;AACH,MAAa,WAAW;IAItB,wEAAwE;IACxE,YAAY,OAAe,EAAE,MAAqB;QAChD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY,EAAE,OAA0B;;QAClD,kBAAM,CAAC,IAAI,CAAC,YAAY,IAAI,uBAAuB,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,GAAG,GAAG,GAAG,IAAI,CAAC;QACzC,MAAM,aAAa,GAAgB,KAAK,CAAC;QACzC,MAAM,aAAa,GAAgB,IAAA,sCAAiB,EAAC,MAAA,OAAO,CAAC,cAAc,0CAAE,aAAa,CAAC,CAAC;QAC5F,MAAM,cAAc,GAAG;YACrB,GAAG,EAAE,KAAK;YACV,MAAM,EAAE,aAAa;YACrB,OAAO,EAAE,aAAa;YACtB,OAAO,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,OAAO;YACxC,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,uBAAuB,EAAE,IAAI;SAC9B,CAAC;QACF,MAAM,OAAO,GAAoB,IAAA,0CAAqB,EAAC,cAAc,CAAC,CAAC;QACvE,MAAM,GAAG,GAAqB,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAEtE,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YAC1C,MAAM,YAAY,GAAG,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;YAC1C,MAAM,UAAU,GAAkB,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAC3D,OAAO,UAAU,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,8BAAS,CAAC,+CAA+C,EAAE;gBACnE,IAAI,EAAE,kBAAkB;gBACxB,UAAU,EAAE,GAAG,CAAC,MAAM;gBACtB,QAAQ,EAAE,GAAG;gBACb,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AA3CD,kCA2CC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions, ServiceClient } from \"@azure/core-client\";\nimport type {\n HttpHeaders,\n HttpMethods,\n PipelineRequest,\n PipelineResponse,\n} from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest, RestError } from \"@azure/core-rest-pipeline\";\nimport { logger } from \"./logger.js\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\n\n/**\n * The HTTP Fetcher implements the Fetcher interface to\n * retrieve models through HTTP calls.\n *\n * @internal\n */\nexport class HttpFetcher implements Fetcher {\n private _client: ServiceClient;\n private _baseURL: string;\n\n // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters\n constructor(baseURL: string, client: ServiceClient) {\n this._client = client;\n this._baseURL = baseURL;\n }\n\n async fetch(path: string, options?: OperationOptions): Promise<DTDL | DTDL[]> {\n logger.info(`Fetching ${path} from remote endpoint`);\n if (!options) {\n options = {};\n }\n const myURL = this._baseURL + \"/\" + path;\n const requestMethod: HttpMethods = \"GET\";\n const requestHeader: HttpHeaders = createHttpHeaders(options.requestOptions?.customHeaders);\n const requestOptions = {\n url: myURL,\n method: requestMethod,\n headers: requestHeader,\n timeout: options.requestOptions?.timeout,\n abortSignal: options.abortSignal,\n tracingOptions: options.tracingOptions,\n allowInsecureConnection: true,\n };\n const request: PipelineRequest = createPipelineRequest(requestOptions);\n const res: PipelineResponse = await this._client.sendRequest(request);\n\n if (res.status >= 200 && res.status < 400) {\n const dtdlAsString = res.bodyAsText || \"\";\n const parsedDtdl: DTDL | DTDL[] = JSON.parse(dtdlAsString);\n return parsedDtdl;\n } else {\n throw new RestError(\"Error on HTTP Request in remote model fetcher\", {\n code: \"ResourceNotFound\",\n statusCode: res.status,\n response: res,\n request: request,\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"fetcherHTTP.js","sourceRoot":"","sources":["../../src/fetcherHTTP.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AASlC,kEAAgG;AAChG,2CAAqC;AAIrC;;;;;GAKG;AACH,MAAa,WAAW;IACd,OAAO,CAAgB;IACvB,QAAQ,CAAS;IAEzB,wEAAwE;IACxE,YAAY,OAAe,EAAE,MAAqB;QAChD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY,EAAE,OAA0B;QAClD,kBAAM,CAAC,IAAI,CAAC,YAAY,IAAI,uBAAuB,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,GAAG,GAAG,GAAG,IAAI,CAAC;QACzC,MAAM,aAAa,GAAgB,KAAK,CAAC;QACzC,MAAM,aAAa,GAAgB,IAAA,sCAAiB,EAAC,OAAO,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;QAC5F,MAAM,cAAc,GAAG;YACrB,GAAG,EAAE,KAAK;YACV,MAAM,EAAE,aAAa;YACrB,OAAO,EAAE,aAAa;YACtB,OAAO,EAAE,OAAO,CAAC,cAAc,EAAE,OAAO;YACxC,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,uBAAuB,EAAE,IAAI;SAC9B,CAAC;QACF,MAAM,OAAO,GAAoB,IAAA,0CAAqB,EAAC,cAAc,CAAC,CAAC;QACvE,MAAM,GAAG,GAAqB,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAEtE,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YAC1C,MAAM,YAAY,GAAG,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;YAC1C,MAAM,UAAU,GAAkB,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAC3D,OAAO,UAAU,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,8BAAS,CAAC,+CAA+C,EAAE;gBACnE,IAAI,EAAE,kBAAkB;gBACxB,UAAU,EAAE,GAAG,CAAC,MAAM;gBACtB,QAAQ,EAAE,GAAG;gBACb,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AA3CD,kCA2CC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions, ServiceClient } from \"@azure/core-client\";\nimport type {\n HttpHeaders,\n HttpMethods,\n PipelineRequest,\n PipelineResponse,\n} from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest, RestError } from \"@azure/core-rest-pipeline\";\nimport { logger } from \"./logger.js\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\n\n/**\n * The HTTP Fetcher implements the Fetcher interface to\n * retrieve models through HTTP calls.\n *\n * @internal\n */\nexport class HttpFetcher implements Fetcher {\n private _client: ServiceClient;\n private _baseURL: string;\n\n // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters\n constructor(baseURL: string, client: ServiceClient) {\n this._client = client;\n this._baseURL = baseURL;\n }\n\n async fetch(path: string, options?: OperationOptions): Promise<DTDL | DTDL[]> {\n logger.info(`Fetching ${path} from remote endpoint`);\n if (!options) {\n options = {};\n }\n const myURL = this._baseURL + \"/\" + path;\n const requestMethod: HttpMethods = \"GET\";\n const requestHeader: HttpHeaders = createHttpHeaders(options.requestOptions?.customHeaders);\n const requestOptions = {\n url: myURL,\n method: requestMethod,\n headers: requestHeader,\n timeout: options.requestOptions?.timeout,\n abortSignal: options.abortSignal,\n tracingOptions: options.tracingOptions,\n allowInsecureConnection: true,\n };\n const request: PipelineRequest = createPipelineRequest(requestOptions);\n const res: PipelineResponse = await this._client.sendRequest(request);\n\n if (res.status >= 200 && res.status < 400) {\n const dtdlAsString = res.bodyAsText || \"\";\n const parsedDtdl: DTDL | DTDL[] = JSON.parse(dtdlAsString);\n return parsedDtdl;\n } else {\n throw new RestError(\"Error on HTTP Request in remote model fetcher\", {\n code: \"ResourceNotFound\",\n statusCode: res.status,\n response: res,\n request: request,\n });\n }\n }\n}\n"]}
@@ -3,7 +3,6 @@
3
3
  // Licensed under the MIT License.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.ModelsRepositoryClient = void 0;
6
- const tslib_1 = require("tslib");
7
6
  const constants_js_1 = require("./utils/constants.js");
8
7
  const core_client_1 = require("@azure/core-client");
9
8
  const path_js_1 = require("./utils/path.js");
@@ -17,6 +16,12 @@ const fetcherHTTP_js_1 = require("./fetcherHTTP.js");
17
16
  * Initializes a new instance of the IoT Models Repository Client.
18
17
  */
19
18
  class ModelsRepositoryClient {
19
+ _repositoryLocation;
20
+ _dependencyResolution;
21
+ _apiVersion;
22
+ _fetcher;
23
+ _resolver;
24
+ _pseudoParser;
20
25
  /**
21
26
  * The ModelsRepositoryClient constructor
22
27
  * @param options - The models repository client options that govern the behavior of the client.
@@ -72,7 +77,7 @@ class ModelsRepositoryClient {
72
77
  * to create the IoT Models Repository Service Client.
73
78
  */
74
79
  _createClient(options) {
75
- const pipelineOptions = tslib_1.__rest(options, []);
80
+ const { ...pipelineOptions } = options;
76
81
  if (!pipelineOptions.userAgentOptions) {
77
82
  pipelineOptions.userAgentOptions = {};
78
83
  }
@@ -82,11 +87,14 @@ class ModelsRepositoryClient {
82
87
  else {
83
88
  pipelineOptions.userAgentOptions.userAgentPrefix = constants_js_1.DEFAULT_USER_AGENT;
84
89
  }
85
- const internalPipelineOptions = Object.assign(Object.assign({}, pipelineOptions), {
86
- loggingOptions: {
87
- logger: logger_js_1.logger.info,
90
+ const internalPipelineOptions = {
91
+ ...pipelineOptions,
92
+ ...{
93
+ loggingOptions: {
94
+ logger: logger_js_1.logger.info,
95
+ },
88
96
  },
89
- });
97
+ };
90
98
  const pipeline = (0, core_client_1.createClientPipeline)(internalPipelineOptions);
91
99
  const client = new modelsRepositoryServiceClient_js_1.IoTModelsRepositoryServiceClient(this._repositoryLocation, { pipeline });
92
100
  return client;
@@ -136,7 +144,7 @@ class ModelsRepositoryClient {
136
144
  if (!Array.isArray(dtmis)) {
137
145
  dtmis = [dtmis];
138
146
  }
139
- const dependencyResolution = (options === null || options === void 0 ? void 0 : options.dependencyResolution) || this._dependencyResolution;
147
+ const dependencyResolution = options?.dependencyResolution || this._dependencyResolution;
140
148
  if (dependencyResolution === constants_js_1.DEPENDENCY_MODE_DISABLED) {
141
149
  logger_js_1.logger.info("Getting models w/ dependency resolution mode: disabled");
142
150
  logger_js_1.logger.info(`Retreiving model(s): ${dtmis}...`);
@@ -1 +1 @@
1
- {"version":3,"file":"modelsRepositoryClient.js","sourceRoot":"","sources":["../../src/modelsRepositoryClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;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gBACzD,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YAChE,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;oBAC3D,kBAAM,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAC;oBACvE,MAAM,YAAY,GAAgC,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAC5E,KAAK,EACL,KAAK,EACL,OAAO,CACR,CAAC;oBACF,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;oBAChF,kBAAM,CAAC,IAAI,CAAC,qCAAqC,KAAK,KAAK,CAAC,CAAC;oBAC7D,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,aAAuB,EAAE,IAAI,CAAC,CAAC;gBAC5E,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,SAAS,CAAC,uCAAuC,oBAAoB,EAAE,CAAC,CAAC;QACjF,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AApMD,wDAoMC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n DEFAULT_API_VERSION,\n DEFAULT_REPOSITORY_LOCATION,\n DEFAULT_USER_AGENT,\n DEPENDENCY_MODE_DISABLED,\n DEPENDENCY_MODE_ENABLED,\n DEPENDENCY_MODE_TRY_FROM_EXPANDED,\n} from \"./utils/constants.js\";\nimport type { InternalClientPipelineOptions } from \"@azure/core-client\";\nimport { createClientPipeline } from \"@azure/core-client\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport { isLocalPath, normalize } from \"./utils/path.js\";\nimport { FilesystemFetcher } from \"./fetcherFilesystem.js\";\nimport type { dependencyResolutionType } from \"./dependencyResolutionType.js\";\nimport { DtmiResolver } from \"./dtmiResolver.js\";\nimport { PseudoParser } from \"./psuedoParser.js\";\nimport type { ModelsRepositoryClientOptions } from \"./interfaces/modelsRepositoryClientOptions.js\";\nimport { logger } from \"./logger.js\";\nimport { IoTModelsRepositoryServiceClient } from \"./modelsRepositoryServiceClient.js\";\nimport { HttpFetcher } from \"./fetcherHTTP.js\";\nimport type { GetModelsOptions } from \"./interfaces/getModelsOptions.js\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\n\n/**\n * Initializes a new instance of the IoT Models Repository Client.\n */\nexport class ModelsRepositoryClient {\n private _repositoryLocation: string;\n private _dependencyResolution: dependencyResolutionType;\n private _apiVersion: string;\n private _fetcher: Fetcher;\n private _resolver: DtmiResolver;\n private _pseudoParser: PseudoParser;\n\n /**\n * The ModelsRepositoryClient constructor\n * @param options - The models repository client options that govern the behavior of the client.\n */\n constructor(options: ModelsRepositoryClientOptions = {}) {\n this._repositoryLocation = options.repositoryLocation || DEFAULT_REPOSITORY_LOCATION;\n logger.info(`Client configured for repository location ${this._repositoryLocation}`);\n this._dependencyResolution =\n options.dependencyResolution ||\n this._checkDefaultDependencyResolution(!!options.repositoryLocation);\n logger.info(`Client configured for dependency mode: ${this._dependencyResolution}`);\n this._fetcher = this._createFetcher(this._repositoryLocation, options);\n this._resolver = new DtmiResolver(this._fetcher);\n this._pseudoParser = new PseudoParser(this._resolver);\n\n // Store api version here (for now). Currently doesn't do anything\n this._apiVersion = options.apiVersion || DEFAULT_API_VERSION;\n }\n\n /**\n * improves the readability of the constructor.\n * based on a boolean returns the proper dependency resolution setting string.\n */\n private _checkDefaultDependencyResolution(customRepository: boolean): dependencyResolutionType {\n if (customRepository) {\n return \"enabled\";\n } else {\n return \"tryFromExpanded\";\n }\n }\n\n /**\n * Though currently not relevant, can specify API Version for communicating with\n * the service.\n */\n get apiVersion(): string {\n return this._apiVersion;\n }\n\n /**\n * Configured repository location for this instance. Will be used as the endpoint to get the models from.\n */\n get repositoryLocation(): string {\n return this._repositoryLocation;\n }\n\n /**\n * Configured type of dependency resolution for this instance. Dictates how the client deals with model dependencies.\n */\n get dependencyResolution(): dependencyResolutionType {\n return this._dependencyResolution;\n }\n\n /**\n * Because of the local / remote optionality of this client, the service client\n * must be dynamically generated based on the repository location. If the provided\n * repository location is a remote location, then this private method will be used\n * to create the IoT Models Repository Service Client.\n */\n private _createClient(options: ModelsRepositoryClientOptions): IoTModelsRepositoryServiceClient {\n const { ...pipelineOptions } = options;\n\n if (!pipelineOptions.userAgentOptions) {\n pipelineOptions.userAgentOptions = {};\n }\n if (pipelineOptions.userAgentOptions.userAgentPrefix) {\n pipelineOptions.userAgentOptions.userAgentPrefix = `${pipelineOptions.userAgentOptions.userAgentPrefix} ${DEFAULT_USER_AGENT}`;\n } else {\n pipelineOptions.userAgentOptions.userAgentPrefix = DEFAULT_USER_AGENT;\n }\n\n const internalPipelineOptions: InternalClientPipelineOptions = {\n ...pipelineOptions,\n ...{\n loggingOptions: {\n logger: logger.info,\n },\n },\n };\n\n const pipeline = createClientPipeline(internalPipelineOptions);\n const client = new IoTModelsRepositoryServiceClient(this._repositoryLocation, { pipeline });\n return client;\n }\n\n /**\n * The fetcher is an abstraction necessary since this client can communicate with remote or local\n * Model Repositories based on the provided location. It will analyze the provided location based\n * on that create either an HTTP Fetcher, which uses the IoT Models Repository Service Client,\n * or a Filesystem Fetcher.\n */\n private _createFetcher(location: string, options: ModelsRepositoryClientOptions): Fetcher {\n let locationURL;\n let fetcher;\n if (isLocalPath(location)) {\n // POSIX Filesystem Path or Windows Filesystem Path\n logger.info(`Repository location identified as filesystem path - using FilesystemFetcher`);\n fetcher = new FilesystemFetcher(normalize(location));\n } else {\n locationURL = new URL(location);\n const prot = locationURL.protocol;\n if (prot.includes(\"http\") || prot.includes(\"https\")) {\n logger.info(`Repository location identified as HTTP/HTTPS endpoint - using HttpFetcher`);\n const client = this._createClient(options);\n fetcher = new HttpFetcher(location, client);\n } else if (prot.includes(\"file\")) {\n // filesystem URI\n logger.info(\"Repository Location identified as filesystem URI - using FilesystemFetcher\");\n fetcher = new FilesystemFetcher(location);\n } else if (prot === \"\" && location.search(/\\.[a-zA-Z]{2,63}$/)) {\n // Web URL with protocol unspecified - default to HTTPS\n logger.info(\n \"Repository Location identified as remote endpoint without protocol specified - using HttpFetcher\",\n );\n const fLocation = \"https://\" + location;\n const client = this._createClient(options);\n fetcher = new HttpFetcher(fLocation, client);\n } else {\n throw new EvalError(`Unable to identify location: ${location}`);\n }\n }\n\n return fetcher;\n }\n\n /**\n * Retrieve one or more models based upon on or more provided dtmis.\n * @param dtmis - one dtmi represented as a string\n * @param options - options to govern behavior of model getter.\n */\n async getModels(dtmis: string, options?: GetModelsOptions): Promise<{ [dtmi: string]: unknown }>;\n /**\n * Retrieve one or more models based upon on or more provided dtmis.\n * @param dtmis - dtmi strings in an array.\n * @param options - options to govern behavior of model getter.\n */\n async getModels(\n dtmis: string[],\n options?: GetModelsOptions,\n ): Promise<{ [dtmi: string]: unknown }>;\n async getModels(\n dtmis: string | string[],\n options?: GetModelsOptions,\n ): Promise<{ [dtmi: string]: unknown }> {\n let modelMap: { [dtmi: string]: unknown };\n if (!Array.isArray(dtmis)) {\n dtmis = [dtmis];\n }\n\n const dependencyResolution = options?.dependencyResolution || this._dependencyResolution;\n\n if (dependencyResolution === DEPENDENCY_MODE_DISABLED) {\n logger.info(\"Getting models w/ dependency resolution mode: disabled\");\n logger.info(`Retreiving model(s): ${dtmis}...`);\n modelMap = await this._resolver.resolve(dtmis, false, options);\n } else if (dependencyResolution === DEPENDENCY_MODE_ENABLED) {\n logger.info(`Getting models w/ dependency resolution mode: enabled`);\n logger.info(`Retreiving model(s): ${dtmis}...`);\n const baseModelMap = await this._resolver.resolve(dtmis, false, options);\n const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key]);\n logger.info(`Retreiving model dependencies for ${dtmis}...`);\n modelMap = await this._pseudoParser.expand(baseModelList, false);\n } else if (dependencyResolution === DEPENDENCY_MODE_TRY_FROM_EXPANDED) {\n logger.info(`Getting models w/ dependency resolution mode: tryFromExpanded`);\n try {\n logger.info(`Retreiving expanded model(s): ${dtmis}...`);\n modelMap = await this._resolver.resolve(dtmis, true, options);\n } catch (e: any) {\n if (e.name === \"RestError\" && e.code === \"ResouceNotFound\") {\n logger.info(\"Could not retrieve model(s) from expanded model DTDL - \");\n const baseModelMap: { [dtmi: string]: unknown } = await this._resolver.resolve(\n dtmis,\n false,\n options,\n );\n const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key]);\n logger.info(`Retreiving model dependencies for ${dtmis}...`);\n modelMap = await this._pseudoParser.expand(baseModelList as DTDL[], true);\n } else {\n throw e;\n }\n }\n } else {\n throw EvalError(`Invalid dependency resolution mode: ${dependencyResolution}`);\n }\n\n return modelMap;\n }\n}\n"]}
1
+ {"version":3,"file":"modelsRepositoryClient.js","sourceRoot":"","sources":["../../src/modelsRepositoryClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,uDAO8B;AAE9B,oDAA0D;AAE1D,6CAAyD;AACzD,iEAA2D;AAE3D,uDAAiD;AACjD,uDAAiD;AAEjD,2CAAqC;AACrC,yFAAsF;AACtF,qDAA+C;AAI/C;;GAEG;AACH,MAAa,sBAAsB;IACzB,mBAAmB,CAAS;IAC5B,qBAAqB,CAA2B;IAChD,WAAW,CAAS;IACpB,QAAQ,CAAU;IAClB,SAAS,CAAe;IACxB,aAAa,CAAe;IAEpC;;;OAGG;IACH,YAAY,UAAyC,EAAE;QACrD,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,IAAI,0CAA2B,CAAC;QACrF,kBAAM,CAAC,IAAI,CAAC,6CAA6C,IAAI,CAAC,mBAAmB,EAAE,CAAC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AK,EACL,KAAK,EACL,OAAO,CACR,CAAC;oBACF,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;oBAChF,kBAAM,CAAC,IAAI,CAAC,qCAAqC,KAAK,KAAK,CAAC,CAAC;oBAC7D,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,aAAuB,EAAE,IAAI,CAAC,CAAC;gBAC5E,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,SAAS,CAAC,uCAAuC,oBAAoB,EAAE,CAAC,CAAC;QACjF,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AApMD,wDAoMC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n DEFAULT_API_VERSION,\n DEFAULT_REPOSITORY_LOCATION,\n DEFAULT_USER_AGENT,\n DEPENDENCY_MODE_DISABLED,\n DEPENDENCY_MODE_ENABLED,\n DEPENDENCY_MODE_TRY_FROM_EXPANDED,\n} from \"./utils/constants.js\";\nimport type { InternalClientPipelineOptions } from \"@azure/core-client\";\nimport { createClientPipeline } from \"@azure/core-client\";\nimport type { Fetcher } from \"./fetcherAbstract.js\";\nimport { isLocalPath, normalize } from \"./utils/path.js\";\nimport { FilesystemFetcher } from \"./fetcherFilesystem.js\";\nimport type { dependencyResolutionType } from \"./dependencyResolutionType.js\";\nimport { DtmiResolver } from \"./dtmiResolver.js\";\nimport { PseudoParser } from \"./psuedoParser.js\";\nimport type { ModelsRepositoryClientOptions } from \"./interfaces/modelsRepositoryClientOptions.js\";\nimport { logger } from \"./logger.js\";\nimport { IoTModelsRepositoryServiceClient } from \"./modelsRepositoryServiceClient.js\";\nimport { HttpFetcher } from \"./fetcherHTTP.js\";\nimport type { GetModelsOptions } from \"./interfaces/getModelsOptions.js\";\nimport type { DTDL } from \"./psuedoDtdl.js\";\n\n/**\n * Initializes a new instance of the IoT Models Repository Client.\n */\nexport class ModelsRepositoryClient {\n private _repositoryLocation: string;\n private _dependencyResolution: dependencyResolutionType;\n private _apiVersion: string;\n private _fetcher: Fetcher;\n private _resolver: DtmiResolver;\n private _pseudoParser: PseudoParser;\n\n /**\n * The ModelsRepositoryClient constructor\n * @param options - The models repository client options that govern the behavior of the client.\n */\n constructor(options: ModelsRepositoryClientOptions = {}) {\n this._repositoryLocation = options.repositoryLocation || DEFAULT_REPOSITORY_LOCATION;\n logger.info(`Client configured for repository location ${this._repositoryLocation}`);\n this._dependencyResolution =\n options.dependencyResolution ||\n this._checkDefaultDependencyResolution(!!options.repositoryLocation);\n logger.info(`Client configured for dependency mode: ${this._dependencyResolution}`);\n this._fetcher = this._createFetcher(this._repositoryLocation, options);\n this._resolver = new DtmiResolver(this._fetcher);\n this._pseudoParser = new PseudoParser(this._resolver);\n\n // Store api version here (for now). Currently doesn't do anything\n this._apiVersion = options.apiVersion || DEFAULT_API_VERSION;\n }\n\n /**\n * improves the readability of the constructor.\n * based on a boolean returns the proper dependency resolution setting string.\n */\n private _checkDefaultDependencyResolution(customRepository: boolean): dependencyResolutionType {\n if (customRepository) {\n return \"enabled\";\n } else {\n return \"tryFromExpanded\";\n }\n }\n\n /**\n * Though currently not relevant, can specify API Version for communicating with\n * the service.\n */\n get apiVersion(): string {\n return this._apiVersion;\n }\n\n /**\n * Configured repository location for this instance. Will be used as the endpoint to get the models from.\n */\n get repositoryLocation(): string {\n return this._repositoryLocation;\n }\n\n /**\n * Configured type of dependency resolution for this instance. Dictates how the client deals with model dependencies.\n */\n get dependencyResolution(): dependencyResolutionType {\n return this._dependencyResolution;\n }\n\n /**\n * Because of the local / remote optionality of this client, the service client\n * must be dynamically generated based on the repository location. If the provided\n * repository location is a remote location, then this private method will be used\n * to create the IoT Models Repository Service Client.\n */\n private _createClient(options: ModelsRepositoryClientOptions): IoTModelsRepositoryServiceClient {\n const { ...pipelineOptions } = options;\n\n if (!pipelineOptions.userAgentOptions) {\n pipelineOptions.userAgentOptions = {};\n }\n if (pipelineOptions.userAgentOptions.userAgentPrefix) {\n pipelineOptions.userAgentOptions.userAgentPrefix = `${pipelineOptions.userAgentOptions.userAgentPrefix} ${DEFAULT_USER_AGENT}`;\n } else {\n pipelineOptions.userAgentOptions.userAgentPrefix = DEFAULT_USER_AGENT;\n }\n\n const internalPipelineOptions: InternalClientPipelineOptions = {\n ...pipelineOptions,\n ...{\n loggingOptions: {\n logger: logger.info,\n },\n },\n };\n\n const pipeline = createClientPipeline(internalPipelineOptions);\n const client = new IoTModelsRepositoryServiceClient(this._repositoryLocation, { pipeline });\n return client;\n }\n\n /**\n * The fetcher is an abstraction necessary since this client can communicate with remote or local\n * Model Repositories based on the provided location. It will analyze the provided location based\n * on that create either an HTTP Fetcher, which uses the IoT Models Repository Service Client,\n * or a Filesystem Fetcher.\n */\n private _createFetcher(location: string, options: ModelsRepositoryClientOptions): Fetcher {\n let locationURL;\n let fetcher;\n if (isLocalPath(location)) {\n // POSIX Filesystem Path or Windows Filesystem Path\n logger.info(`Repository location identified as filesystem path - using FilesystemFetcher`);\n fetcher = new FilesystemFetcher(normalize(location));\n } else {\n locationURL = new URL(location);\n const prot = locationURL.protocol;\n if (prot.includes(\"http\") || prot.includes(\"https\")) {\n logger.info(`Repository location identified as HTTP/HTTPS endpoint - using HttpFetcher`);\n const client = this._createClient(options);\n fetcher = new HttpFetcher(location, client);\n } else if (prot.includes(\"file\")) {\n // filesystem URI\n logger.info(\"Repository Location identified as filesystem URI - using FilesystemFetcher\");\n fetcher = new FilesystemFetcher(location);\n } else if (prot === \"\" && location.search(/\\.[a-zA-Z]{2,63}$/)) {\n // Web URL with protocol unspecified - default to HTTPS\n logger.info(\n \"Repository Location identified as remote endpoint without protocol specified - using HttpFetcher\",\n );\n const fLocation = \"https://\" + location;\n const client = this._createClient(options);\n fetcher = new HttpFetcher(fLocation, client);\n } else {\n throw new EvalError(`Unable to identify location: ${location}`);\n }\n }\n\n return fetcher;\n }\n\n /**\n * Retrieve one or more models based upon on or more provided dtmis.\n * @param dtmis - one dtmi represented as a string\n * @param options - options to govern behavior of model getter.\n */\n async getModels(dtmis: string, options?: GetModelsOptions): Promise<{ [dtmi: string]: unknown }>;\n /**\n * Retrieve one or more models based upon on or more provided dtmis.\n * @param dtmis - dtmi strings in an array.\n * @param options - options to govern behavior of model getter.\n */\n async getModels(\n dtmis: string[],\n options?: GetModelsOptions,\n ): Promise<{ [dtmi: string]: unknown }>;\n async getModels(\n dtmis: string | string[],\n options?: GetModelsOptions,\n ): Promise<{ [dtmi: string]: unknown }> {\n let modelMap: { [dtmi: string]: unknown };\n if (!Array.isArray(dtmis)) {\n dtmis = [dtmis];\n }\n\n const dependencyResolution = options?.dependencyResolution || this._dependencyResolution;\n\n if (dependencyResolution === DEPENDENCY_MODE_DISABLED) {\n logger.info(\"Getting models w/ dependency resolution mode: disabled\");\n logger.info(`Retreiving model(s): ${dtmis}...`);\n modelMap = await this._resolver.resolve(dtmis, false, options);\n } else if (dependencyResolution === DEPENDENCY_MODE_ENABLED) {\n logger.info(`Getting models w/ dependency resolution mode: enabled`);\n logger.info(`Retreiving model(s): ${dtmis}...`);\n const baseModelMap = await this._resolver.resolve(dtmis, false, options);\n const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key]);\n logger.info(`Retreiving model dependencies for ${dtmis}...`);\n modelMap = await this._pseudoParser.expand(baseModelList, false);\n } else if (dependencyResolution === DEPENDENCY_MODE_TRY_FROM_EXPANDED) {\n logger.info(`Getting models w/ dependency resolution mode: tryFromExpanded`);\n try {\n logger.info(`Retreiving expanded model(s): ${dtmis}...`);\n modelMap = await this._resolver.resolve(dtmis, true, options);\n } catch (e: any) {\n if (e.name === \"RestError\" && e.code === \"ResouceNotFound\") {\n logger.info(\"Could not retrieve model(s) from expanded model DTDL - \");\n const baseModelMap: { [dtmi: string]: unknown } = await this._resolver.resolve(\n dtmis,\n false,\n options,\n );\n const baseModelList = Object.keys(baseModelMap).map((key) => baseModelMap[key]);\n logger.info(`Retreiving model dependencies for ${dtmis}...`);\n modelMap = await this._pseudoParser.expand(baseModelList as DTDL[], true);\n } else {\n throw e;\n }\n }\n } else {\n throw EvalError(`Invalid dependency resolution mode: ${dependencyResolution}`);\n }\n\n return modelMap;\n }\n}\n"]}
@@ -9,6 +9,8 @@ const constants_js_1 = require("./utils/constants.js");
9
9
  * @internal
10
10
  */
11
11
  class IoTModelsRepositoryServiceClient extends core_client_1.ServiceClient {
12
+ url;
13
+ version;
12
14
  /**
13
15
  * Initializes a new instance of the IoTModelsRepositoryServiceClient class.
14
16
  *
@@ -20,7 +22,10 @@ class IoTModelsRepositoryServiceClient extends core_client_1.ServiceClient {
20
22
  baseUri: `${url}`,
21
23
  requestContentType: "application/json; charset=utf-8",
22
24
  };
23
- const optionsWithDefaults = Object.assign(Object.assign({}, defaults), options);
25
+ const optionsWithDefaults = {
26
+ ...defaults,
27
+ ...options,
28
+ };
24
29
  super(optionsWithDefaults);
25
30
  this.url = url;
26
31
  this.version = options.version || constants_js_1.DEFAULT_API_VERSION;
@@ -1 +1 @@
1
- {"version":3,"file":"modelsRepositoryServiceClient.js","sourceRoot":"","sources":["../../src/modelsRepositoryServiceClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,oDAAmD;AACnD,uDAA2D;AAS3D;;GAEG;AACH,MAAa,gCAAiC,SAAQ,2BAAa;IAIjE;;;;;OAKG;IACH,YAAY,GAAW,EAAE,UAAmD,EAAE;QAC5E,MAAM,QAAQ,GAA4C;YACxD,OAAO,EAAE,GAAG,GAAG,EAAE;YACjB,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,mBAAmB,mCACpB,QAAQ,GACR,OAAO,CACX,CAAC;QAEF,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAE3B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,kCAAmB,CAAC;IACxD,CAAC;CACF;AA1BD,4EA0BC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ServiceClientOptions } from \"@azure/core-client\";\nimport { ServiceClient } from \"@azure/core-client\";\nimport { DEFAULT_API_VERSION } from \"./utils/constants.js\";\n\ninterface IoTModelsRepositoryServiceClientOptions extends ServiceClientOptions {\n // API Version to be used during HTTP Calls.\n version?: string;\n // Endpoint that will be base of URLs for HTTP calls.\n endpoint?: string;\n}\n\n/**\n * @internal\n */\nexport class IoTModelsRepositoryServiceClient extends ServiceClient {\n url: string;\n version: string;\n\n /**\n * Initializes a new instance of the IoTModelsRepositoryServiceClient class.\n *\n * @param url - The URL of the service account or table that is the target of the desired operation.\n * @param options - The parameter options\n */\n constructor(url: string, options: IoTModelsRepositoryServiceClientOptions = {}) {\n const defaults: IoTModelsRepositoryServiceClientOptions = {\n baseUri: `${url}`,\n requestContentType: \"application/json; charset=utf-8\",\n };\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n };\n\n super(optionsWithDefaults);\n\n this.url = url;\n this.version = options.version || DEFAULT_API_VERSION;\n }\n}\n"]}
1
+ {"version":3,"file":"modelsRepositoryServiceClient.js","sourceRoot":"","sources":["../../src/modelsRepositoryServiceClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,oDAAmD;AACnD,uDAA2D;AAS3D;;GAEG;AACH,MAAa,gCAAiC,SAAQ,2BAAa;IACjE,GAAG,CAAS;IACZ,OAAO,CAAS;IAEhB;;;;;OAKG;IACH,YAAY,GAAW,EAAE,UAAmD,EAAE;QAC5E,MAAM,QAAQ,GAA4C;YACxD,OAAO,EAAE,GAAG,GAAG,EAAE;YACjB,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,mBAAmB,GAAG;YAC1B,GAAG,QAAQ;YACX,GAAG,OAAO;SACX,CAAC;QAEF,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAE3B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,kCAAmB,CAAC;IACxD,CAAC;CACF;AA1BD,4EA0BC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ServiceClientOptions } from \"@azure/core-client\";\nimport { ServiceClient } from \"@azure/core-client\";\nimport { DEFAULT_API_VERSION } from \"./utils/constants.js\";\n\ninterface IoTModelsRepositoryServiceClientOptions extends ServiceClientOptions {\n // API Version to be used during HTTP Calls.\n version?: string;\n // Endpoint that will be base of URLs for HTTP calls.\n endpoint?: string;\n}\n\n/**\n * @internal\n */\nexport class IoTModelsRepositoryServiceClient extends ServiceClient {\n url: string;\n version: string;\n\n /**\n * Initializes a new instance of the IoTModelsRepositoryServiceClient class.\n *\n * @param url - The URL of the service account or table that is the target of the desired operation.\n * @param options - The parameter options\n */\n constructor(url: string, options: IoTModelsRepositoryServiceClientOptions = {}) {\n const defaults: IoTModelsRepositoryServiceClientOptions = {\n baseUri: `${url}`,\n requestContentType: \"application/json; charset=utf-8\",\n };\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n };\n\n super(optionsWithDefaults);\n\n this.url = url;\n this.version = options.version || DEFAULT_API_VERSION;\n }\n}\n"]}
@@ -17,6 +17,7 @@ const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
17
17
  * @internal
18
18
  */
19
19
  class PseudoParser {
20
+ _resolver;
20
21
  // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
21
22
  constructor(resolver) {
22
23
  this._resolver = resolver;