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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# TestService REST client library for JavaScript



**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**

Key links:

- [Package (NPM)](https://www.npmjs.com/package/@msinternal/test)

## Getting started

### Currently supported environments

- LTS versions of Node.js

### Prerequisites

- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.

### Install the `@msinternal/test` package

Install the TestService REST client REST client library for JavaScript with `npm`:

```bash
npm install @msinternal/test
```

### Create and authenticate a `TestServiceClient`

To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
provide an instance of the desired credential type obtained from the
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.

To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)

After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
can be used to authenticate the client.

## Troubleshooting

### Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:

```ts
import { setLogLevel } from "@azure/logger";

setLogLevel("info");
```

For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "dist/esm/index.d.ts",
"docModel": { "enabled": true },
"apiReport": { "enabled": true, "reportFolder": "./review" },
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "dist/test.d.ts"
},
"messages": {
"tsdocMessageReporting": { "default": { "logLevel": "none" } },
"extractorMessageReporting": {
"ae-missing-release-tag": { "logLevel": "none" },
"ae-unresolved-link": { "logLevel": "none" }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default azsdkEslint.config([
{
rules: {
"@azure/azure-sdk/ts-modules-only-named": "warn",
"@azure/azure-sdk/ts-package-json-types": "warn",
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
"@azure/azure-sdk/ts-package-json-files-required": "off",
"@azure/azure-sdk/ts-package-json-main-is-cjs": "off",
"tsdoc/syntax": "warn"
}
}
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@msinternal/test",
"version": "1.0.0-beta.1",
"description": "A generated SDK for TestServiceClient.",
"engines": {
"node": ">=20.0.0"
},
"sideEffects": false,
"autoPublish": false,
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
},
"dialects": ["esm", "commonjs"],
"esmDialects": ["browser", "react-native"],
"selfLink": false
},
"type": "module",
"browser": "./dist/browser/index.js",
"react-native": "./dist/react-native/index.js",
"keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
"author": "Microsoft Corporation",
"license": "MIT",
"files": ["dist/", "!dist/**/*.d.*ts.map", "README.md", "LICENSE"],
"dependencies": {
"@azure-rest/core-client": "^2.3.1",
"@azure/core-auth": "^1.6.0",
"@azure/core-rest-pipeline": "^1.5.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.6.2"
},
"devDependencies": {
"dotenv": "^16.0.0",
"@types/node": "^20.0.0",
"eslint": "^9.9.0",
"typescript": "~5.8.2",
"tshy": "^2.0.0",
"@microsoft/api-extractor": "^7.40.3",
"rimraf": "^5.0.5",
"mkdirp": "^3.0.1"
},
"scripts": {
"clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log",
"extract-api": "rimraf review && mkdirp ./review && api-extractor run --local",
"pack": "npm pack 2>&1",
"lint": "eslint package.json api-extractor.json src",
"lint:fix": "eslint package.json api-extractor.json src --fix --fix-type [problem,suggestion]",
"build": "npm run clean && tshy && npm run extract-api"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import nodeResolve from "@rollup/plugin-node-resolve";
import cjs from "@rollup/plugin-commonjs";
import sourcemaps from "rollup-plugin-sourcemaps";
import multiEntry from "@rollup/plugin-multi-entry";
import json from "@rollup/plugin-json";

import nodeBuiltins from "builtin-modules";

// #region Warning Handler

/**
* A function that can determine whether a rollup warning should be ignored. If
* the function returns `true`, then the warning will not be displayed.
*/

function ignoreNiseSinonEval(warning) {
return (
warning.code === "EVAL" &&
warning.id &&
(warning.id.includes("node_modules/nise") || warning.id.includes("node_modules/sinon")) === true
);
}

function ignoreChaiCircularDependency(warning) {
return (
warning.code === "CIRCULAR_DEPENDENCY" &&
warning.importer &&
warning.importer.includes("node_modules/chai") === true
);
}

const warningInhibitors = [ignoreChaiCircularDependency, ignoreNiseSinonEval];

/**
* Construct a warning handler for the shared rollup configuration
* that ignores certain warnings that are not relevant to testing.
*/
function makeOnWarnForTesting() {
return (warning, warn) => {
// If every inhibitor returns false (i.e. no inhibitors), then show the warning
if (warningInhibitors.every((inhib) => !inhib(warning))) {
warn(warning);
}
};
}

// #endregion

function makeBrowserTestConfig() {
const config = {
input: {
include: ["dist-esm/test/**/*.spec.js"],
exclude: ["dist-esm/test/**/node/**"],
},
output: {
file: `dist-test/index.browser.js`,
format: "umd",
sourcemap: true,
},
preserveSymlinks: false,
plugins: [
multiEntry({ exports: false }),
nodeResolve({
mainFields: ["module", "browser"],
}),
cjs(),
json(),
sourcemaps(),
//viz({ filename: "dist-test/browser-stats.html", sourcemap: true })
],
onwarn: makeOnWarnForTesting(),
// Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0,
// rollup started respecting the "sideEffects" field in package.json. Since
// our package.json sets "sideEffects=false", this also applies to test
// code, which causes all tests to be removed by tree-shaking.
treeshake: false,
};

return config;
}

const defaultConfigurationOptions = {
disableBrowserBundle: false,
};

export function makeConfig(pkg, options) {
options = {
...defaultConfigurationOptions,
...(options || {}),
};

const baseConfig = {
// Use the package's module field if it has one
input: pkg["module"] || "dist-esm/src/index.js",
external: [
...nodeBuiltins,
...Object.keys(pkg.dependencies),
...Object.keys(pkg.devDependencies),
],
output: { file: "dist/index.js", format: "cjs", sourcemap: true },
preserveSymlinks: false,
plugins: [sourcemaps(), nodeResolve()],
};

const config = [baseConfig];

if (!options.disableBrowserBundle) {
config.push(makeBrowserTestConfig());
}

return config;
}

export default makeConfig(require("./package.json"));
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import type { GlobalModelGetPetSettingsParameters } from "./parameters.js";
import type { GlobalModelGetPetSettings200Response } from "./responses.js";
import type { Client, StreamableMethod } from "@azure-rest/core-client";

/** Contains operations for GlobalModel operations */
export interface GlobalModelOperations {
getPetSettings(
options?: GlobalModelGetPetSettingsParameters,
): StreamableMethod<GlobalModelGetPetSettings200Response>;
}

export interface GetPetSettings {
get(
options?: GlobalModelGetPetSettingsParameters,
): StreamableMethod<GlobalModelGetPetSettings200Response>;
}

export interface Routes {
/** Resource for '/' has methods for the following verbs: get */
(path: "/"): GetPetSettings;
}

export type TestServiceClient = Client & {
path: Routes;
globalModel: GlobalModelOperations;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import TestServiceClient from "./testServiceClient.js";

export * from "./testServiceClient.js";
export * from "./parameters.js";
export * from "./responses.js";
export * from "./clientDefinitions.js";
export * from "./outputModels.js";

export default TestServiceClient;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { createClientLogger } from "@azure/logger";
export const logger = createClientLogger("test");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export interface PetSettingsOutput {
petList?: { cat?: Array<CatDefOutput> };
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typespec:

model DefaultPets {
    catList?: CatDef[] = #[#{ catType: "American Shorthair" }];
}

model PetSettings {
    petList?: {
        cat?: DefaultPets.catList;
    };
}

model CatDef {
    catType: string;
}

interface Global {
    getPetSettings(): PetSettings;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import type { RequestParameters } from "@azure-rest/core-client";

export type GlobalModelGetPetSettingsParameters = RequestParameters;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import type { HttpResponse } from "@azure-rest/core-client";
import type { PetSettingsOutput } from "./outputModels.js";

/** The request has succeeded. */
export interface GlobalModelGetPetSettings200Response extends HttpResponse {
status: "200";
body: PetSettingsOutput;
}
Loading
Loading