Skip to content

Commit 204ecf1

Browse files
authored
[core-util] Create @azure/core-util (Azure#14062)
To avoid having to export random helpers from `@azure/core-rest-pipeline`, this new package is being created to house them instead. This will also allow us to share utilities between HTTP and AMQP stacks. See Azure#14049 for some of the motivation.
1 parent 5e2b957 commit 204ecf1

File tree

20 files changed

+544
-59
lines changed

20 files changed

+544
-59
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 110 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dataplane.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
"name": "core-tracing",
7373
"path": "sdk/core/core-tracing"
7474
},
75+
{
76+
"name": "core-util",
77+
"path": "sdk/core/core-util"
78+
},
7579
{
7680
"name": "core-xml",
7781
"path": "sdk/core/core-xml"

rush.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@
447447
"projectFolder": "sdk/core/core-tracing",
448448
"versionPolicyName": "core"
449449
},
450+
{
451+
"packageName": "@azure/core-util",
452+
"projectFolder": "sdk/core/core-util",
453+
"versionPolicyName": "core"
454+
},
450455
{
451456
"packageName": "@azure/core-xml",
452457
"projectFolder": "sdk/core/core-xml",

sdk/core/core-util/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release History
2+
3+
## 1.0.0-beta.1 (Unreleased)
4+
5+
- First release of package. This package is intended to provide various shared utility functions for client SDK packages.

sdk/core/core-util/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Microsoft
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

sdk/core/core-util/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Azure Core Util client library for JavaScript (Experimental)
2+
3+
This library is intended to provide various shared utility functions for client SDK packages.
4+
5+
## Getting started
6+
7+
### Requirements
8+
9+
- [Node.js](https://nodejs.org) version > 8.x
10+
11+
### Installation
12+
13+
This package is primarily used in authoring client SDKs and not meant to be consumed directly by end users.
14+
15+
## Key concepts
16+
17+
Utility methods provided by this library should be stateless.
18+
19+
## Examples
20+
21+
Examples can be found in the `samples` folder.
22+
23+
## Next steps
24+
25+
Look at usage in dependent client SDKs.
26+
27+
## Troubleshooting
28+
29+
If you run into issues while using this library, please feel free to [file an issue](https://github.com/Azure/azure-sdk-for-js/issues/new).
30+
31+
## Contributing
32+
33+
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test the code.
34+
35+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcore%2Fcore-util%2FREADME.png)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"mainEntryPointFilePath": "types/latest/src/index.d.ts",
4+
"docModel": {
5+
"enabled": true
6+
},
7+
"apiReport": {
8+
"enabled": true,
9+
"reportFolder": "./review"
10+
},
11+
"dtsRollup": {
12+
"enabled": true,
13+
"untrimmedFilePath": "",
14+
"publicTrimmedFilePath": "./types/latest/core-util.d.ts"
15+
},
16+
"messages": {
17+
"tsdocMessageReporting": {
18+
"default": {
19+
"logLevel": "none"
20+
}
21+
},
22+
"extractorMessageReporting": {
23+
"ae-missing-release-tag": {
24+
"logLevel": "none"
25+
},
26+
"ae-unresolved-link": {
27+
"logLevel": "none"
28+
}
29+
}
30+
}
31+
}

sdk/core/core-util/karma.conf.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// https://github.com/karma-runner/karma-chrome-launcher
2+
process.env.CHROME_BIN = require("puppeteer").executablePath();
3+
4+
module.exports = function(config) {
5+
config.set({
6+
// base path that will be used to resolve all patterns (eg. files, exclude)
7+
basePath: "./",
8+
9+
// frameworks to use
10+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
11+
frameworks: ["mocha"],
12+
13+
plugins: [
14+
"karma-mocha",
15+
"karma-mocha-reporter",
16+
"karma-chrome-launcher",
17+
"karma-edge-launcher",
18+
"karma-firefox-launcher",
19+
"karma-ie-launcher",
20+
"karma-env-preprocessor",
21+
"karma-coverage",
22+
"karma-sourcemap-loader",
23+
"karma-junit-reporter"
24+
],
25+
26+
// list of files / patterns to load in the browser
27+
files: [
28+
// Uncomment the cdn link below for the polyfill service to support IE11 missing features
29+
// Promise,String.prototype.startsWith,String.prototype.endsWith,String.prototype.repeat,String.prototype.includes,Array.prototype.includes,Object.keys
30+
// "https://cdn.polyfill.io/v2/polyfill.js?features=Symbol,Promise,String.prototype.startsWith,String.prototype.endsWith,String.prototype.repeat,String.prototype.includes,Array.prototype.includes,Object.keys|always",
31+
"dist-test/index.browser.js"
32+
],
33+
34+
// list of files / patterns to exclude
35+
exclude: [],
36+
37+
// preprocess matching files before serving them to the browser
38+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
39+
preprocessors: {
40+
"**/*.js": ["sourcemap", "env"],
41+
// IMPORTANT: COMMENT following line if you want to debug in your browsers!!
42+
// Preprocess source file to calculate code coverage, however this will make source file unreadable
43+
"test-browser/index.js": ["coverage"]
44+
},
45+
46+
// inject following environment values into browser testing with window.__env__
47+
// environment values MUST be exported or set with same console running "karma start"
48+
// https://www.npmjs.com/package/karma-env-preprocessor
49+
// EXAMPLE: envPreprocessor: ["ACCOUNT_NAME", "ACCOUNT_SAS"],
50+
51+
// test results reporter to use
52+
// possible values: 'dots', 'progress'
53+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
54+
reporters: ["mocha", "coverage", "junit"],
55+
56+
coverageReporter: {
57+
// specify a common output directory
58+
dir: "coverage-browser/",
59+
reporters: [
60+
{ type: "json", subdir: ".", file: "coverage.json" },
61+
{ type: "lcovonly", subdir: ".", file: "lcov.info" },
62+
{ type: "html", subdir: "html" },
63+
{ type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" }
64+
]
65+
},
66+
67+
junitReporter: {
68+
outputDir: "", // results will be saved as $outputDir/$browserName.xml
69+
outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile
70+
suite: "", // suite will become the package name attribute in xml testsuite element
71+
useBrowserName: false, // add browser name to report and classes names
72+
nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
73+
classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
74+
properties: {} // key value pair of properties to add to the <properties> section of the report
75+
},
76+
77+
// web server port
78+
port: 9876,
79+
80+
// enable / disable colors in the output (reporters and logs)
81+
colors: true,
82+
83+
// level of logging
84+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
85+
logLevel: config.LOG_INFO,
86+
87+
// enable / disable watching file and executing tests whenever any file changes
88+
autoWatch: false,
89+
90+
// start these browsers
91+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
92+
// 'ChromeHeadless', 'Chrome', 'Firefox', 'Edge', 'IE'
93+
browsers: ["ChromeHeadless"],
94+
95+
// Continuous Integration mode
96+
// if true, Karma captures browsers, runs the tests and exits
97+
singleRun: true,
98+
99+
// Concurrency level
100+
// how many browser should be started simultaneous
101+
concurrency: 1,
102+
103+
browserNoActivityTimeout: 600000,
104+
browserDisconnectTimeout: 10000,
105+
browserDisconnectTolerance: 3,
106+
107+
client: {
108+
mocha: {
109+
// change Karma's debug.html to the mocha web reporter
110+
reporter: "html",
111+
timeout: "600000"
112+
}
113+
}
114+
});
115+
};

sdk/core/core-util/package.json

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
"name": "@azure/core-util",
3+
"version": "1.0.0-beta.1",
4+
"description": "Core library for shared utility methods",
5+
"sdk-type": "client",
6+
"main": "dist/index.js",
7+
"module": "dist-esm/src/index.js",
8+
"browser": {
9+
"./dist-esm/src/isNode.js": "./dist-esm/src/isNode.browser.js"
10+
},
11+
"types": "types/latest/core-util.d.ts",
12+
"typesVersions": {
13+
"<3.6": {
14+
"types/latest/*": [
15+
"types/3.1/*"
16+
]
17+
}
18+
},
19+
"scripts": {
20+
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
21+
"build:samples": "echo Skipped.",
22+
"build:test": "echo Just call build instead",
23+
"build:ts": "tsc -p .",
24+
"build:types": "downlevel-dts types/latest/ types/3.1/",
25+
"build": "npm run build:ts && rollup -c 2>&1 && api-extractor run --local && npm run build:types",
26+
"check-format": "prettier --list-different \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
27+
"clean": "rimraf dist dist-* types *.tgz *.log",
28+
"execute:samples": "echo skipped",
29+
"extract-api": "npm run build:ts && api-extractor run --local",
30+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
31+
"integration-test:browser": "echo skipped",
32+
"integration-test:node": "echo skipped",
33+
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
34+
"lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
35+
"lint": "eslint package.json api-extractor.json src test --ext .ts",
36+
"pack": "npm pack 2>&1",
37+
"prebuild": "npm run clean",
38+
"test:browser": "npm run build:test:browser && npm run unit-test:browser && npm run integration-test:browser",
39+
"test:node": "npm run build:test:node && npm run unit-test:node && npm run integration-test:node",
40+
"test": "npm run unit-test:node && npm run build && npm run unit-test:browser && npm run integration-test:node && npm run integration-test:browser",
41+
"unit-test:browser": "karma start --single-run",
42+
"unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"",
43+
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
44+
"docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src"
45+
},
46+
"files": [
47+
"dist/",
48+
"dist-esm/src/",
49+
"types/latest/core-util.d.ts",
50+
"types/3.1/core-util.d.ts",
51+
"README.md",
52+
"LICENSE"
53+
],
54+
"repository": "github:Azure/azure-sdk-for-js",
55+
"keywords": [
56+
"azure",
57+
"cloud"
58+
],
59+
"author": "Microsoft Corporation",
60+
"license": "MIT",
61+
"bugs": {
62+
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
63+
},
64+
"engines": {
65+
"node": ">=8.0.0"
66+
},
67+
"homepage": "https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-util/",
68+
"sideEffects": false,
69+
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
70+
"dependencies": {
71+
"tslib": "^2.0.0"
72+
},
73+
"devDependencies": {
74+
"@azure/dev-tool": "^1.0.0",
75+
"@microsoft/api-extractor": "7.7.11",
76+
"@rollup/plugin-commonjs": "11.0.2",
77+
"@rollup/plugin-json": "^4.0.0",
78+
"@rollup/plugin-multi-entry": "^3.0.0",
79+
"@rollup/plugin-node-resolve": "^8.0.0",
80+
"@rollup/plugin-replace": "^2.2.0",
81+
"@types/chai": "^4.1.6",
82+
"@types/mocha": "^7.0.2",
83+
"@types/node": "^8.0.0",
84+
"@types/sinon": "^9.0.4",
85+
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
86+
"chai": "^4.2.0",
87+
"downlevel-dts": "~0.4.0",
88+
"cross-env": "^7.0.2",
89+
"eslint": "^7.15.0",
90+
"inherits": "^2.0.3",
91+
"karma": "^5.1.0",
92+
"karma-chrome-launcher": "^3.0.0",
93+
"karma-coverage": "^2.0.0",
94+
"karma-edge-launcher": "^0.4.2",
95+
"karma-env-preprocessor": "^0.1.1",
96+
"karma-firefox-launcher": "^1.1.0",
97+
"karma-ie-launcher": "^1.0.0",
98+
"karma-junit-reporter": "^2.0.1",
99+
"karma-mocha": "^2.0.1",
100+
"karma-mocha-reporter": "^2.2.5",
101+
"karma-sourcemap-loader": "^0.3.8",
102+
"mocha": "^7.1.1",
103+
"mocha-junit-reporter": "^1.18.0",
104+
"prettier": "^1.16.4",
105+
"rimraf": "^3.0.0",
106+
"rollup": "^1.16.3",
107+
"rollup-plugin-sourcemaps": "^0.4.2",
108+
"rollup-plugin-terser": "^5.1.1",
109+
"rollup-plugin-visualizer": "^4.0.4",
110+
"sinon": "^9.0.2",
111+
"typescript": "4.1.2",
112+
"util": "^0.12.1",
113+
"typedoc": "0.15.2"
114+
}
115+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## API Report File for "@azure/core-util"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
// @public
8+
export function delay(timeInMs: number): Promise<void>;
9+
10+
// @public
11+
export const isNode: boolean;
12+
13+
14+
// (No @packageDocumentation comment for this package)
15+
16+
```

0 commit comments

Comments
 (0)