Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support modular paging #1978

Closed
wants to merge 7 commits into from
Closed
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
2 changes: 1 addition & 1 deletion packages/rlc-common/src/helpers/nameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ReservedModelNames: ReservedName[] = [
{ name: "else", reservedFor: [NameType.Parameter] },
{ name: "enum", reservedFor: [NameType.Parameter] },
{ name: "error", reservedFor: [NameType.Parameter, ...Newable] },
{ name: "export", reservedFor: [NameType.Parameter] },
{ name: "export", reservedFor: [NameType.Parameter, NameType.Operation] },
{ name: "extends", reservedFor: [NameType.Parameter] },
{ name: "false", reservedFor: [NameType.Parameter] },
{ name: "finally", reservedFor: [NameType.Parameter] },
Expand Down
7 changes: 6 additions & 1 deletion packages/typespec-ts/test/commands/cadl-ranch-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const modularTsps: TypeSpecRanchConfig[] = [
},
{
outputPath: "client/structure/default",
inputPath: "client/structure/default",
inputPath: "client/structure/default"
},
{
outputPath: "client/structure/multi-client",
Expand All @@ -195,5 +195,10 @@ export const modularTsps: TypeSpecRanchConfig[] = [
{
outputPath: "client/structure/two-operation-group",
inputPath: "client/structure/two-operation-group"
},
{
outputPath: "azure/core",
inputPath: "azure/core/basic",
debug: true
}
];
26 changes: 26 additions & 0 deletions packages/typespec-ts/test/modularIntegration/azureCore.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BasicClient } from "./generated/azure/core/src/index.js";
import { assert } from "chai";

describe.only("BasicClient Classical Client", () => {
let client: BasicClient;

beforeEach(() => {
client = new BasicClient({
allowInsecureConnection: true
});
});

it("should list items with paging", async () => {
try {
const iter = client.listWithPage();
const resArray = new Array();
for await (let item of iter) {
resArray.push(item);
}
assert.strictEqual(resArray.length, 1);
} catch (err) {
console.log(err);
assert.fail(err as string);
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": ["@azure/azure-sdk"],
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"],
"rules": {
"@azure/azure-sdk/ts-modules-only-named": "warn",
"@azure/azure-sdk/ts-apiextractor-json-types": "warn",
"@azure/azure-sdk/ts-package-json-types": "warn",
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
"tsdoc/syntax": "warn"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Basic REST client library for JavaScript

Illustrates bodies templated with Azure Core

**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/azure-core-basic)

## 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/azure-core-basic` package

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

```bash
npm install @msinternal/azure-core-basic
```

### Create and authenticate a `BasicClient`

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.

Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET

## 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`:

```javascript
const { setLogLevel } = require("@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": "./types/src/index.d.ts",
"docModel": { "enabled": true },
"apiReport": { "enabled": true, "reportFolder": "./review" },
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "./types/azure-core-basic.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,97 @@
{
"name": "@msinternal/azure-core-basic",
"sdk-type": "client",
"author": "Microsoft Corporation",
"version": "1.0.0-beta.1",
"description": "Azure Core Basic Test Service",
"keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
"license": "MIT",
"type": "module",
"main": "dist/index.js",
"module": "./dist-esm/src/index.js",
"types": "./types/azure-core-basic.d.ts",
"exports": {
".": {
"types": "./types/src/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist-esm/src/index.js"
},
"./api": {
"types": "./types/src/api/index.d.ts",
"import": "./dist-esm/src/api/index.js"
},
"./models": {
"types": "./types/src/models/index.d.ts",
"import": "./dist-esm/src/models/index.js"
}
},
"repository": "github:Azure/azure-sdk-for-js",
"bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" },
"files": [
"dist/",
"dist-esm/",
"types/azure-core-basic.d.ts",
"README.md",
"LICENSE",
"review/*"
],
"engines": { "node": ">=14.0.0" },
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "echo skipped.",
"build:node": "echo skipped.",
"build:samples": "echo skipped.",
"build:test": "echo skipped.",
"build:debug": "echo skipped.",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ",
"clean": "rimraf dist dist-browser dist-esm test-dist temp types *.tgz *.log",
"execute:samples": "echo skipped",
"extract-api": "rimraf review && mkdirp ./review && api-extractor run --local",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ",
"generate:client": "echo skipped",
"integration-test:browser": "echo skipped",
"integration-test:node": "echo skipped",
"integration-test": "echo skipped",
"lint:fix": "eslint package.json api-extractor.json src --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json src --ext .ts",
"pack": "npm pack 2>&1",
"test:browser": "echo skipped",
"test:node": "echo skipped",
"test": "echo \"Error: no test specified\" && exit 1",
"unit-test": "echo skipped",
"unit-test:node": "echo skipped",
"unit-test:browser": "echo skipped",
"build": "npm run clean && tsc && rollup -c 2>&1 && npm run minify && mkdirp ./review && npm run extract-api",
"minify": "uglifyjs -c -m --comments --source-map \"content='./dist/index.js.map'\" -o ./dist/index.min.js ./dist/index.js"
},
"sideEffects": false,
"autoPublish": false,
"dependencies": {
"@azure/core-auth": "^1.3.0",
"@azure-rest/core-client": "^1.1.4",
"@azure/core-rest-pipeline": "^1.12.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.2.0",
"@azure/core-paging": "^1.5.0",
"@azure/core-util": "^1.4.0"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.31.1",
"autorest": "latest",
"@types/node": "^14.0.0",
"dotenv": "^16.0.0",
"eslint": "^8.0.0",
"mkdirp": "^2.1.2",
"prettier": "^2.5.1",
"rimraf": "^3.0.0",
"source-map-support": "^0.5.9",
"typescript": "~5.0.0",
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-multi-entry": "^6.0.0",
"@rollup/plugin-node-resolve": "^13.1.3",
"rollup": "^2.66.1",
"rollup-plugin-sourcemaps": "^0.6.3",
"uglify-js": "^3.4.9"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// 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"));
Loading
Loading