mirror of
https://github.com/actions/setup-python
synced 2025-04-08 08:19:49 +00:00
Initial pass
This commit is contained in:
96
node_modules/mem/index.d.ts
generated
vendored
Normal file
96
node_modules/mem/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
declare namespace mem {
|
||||
interface CacheStorage<KeyType extends unknown, ValueType extends unknown> {
|
||||
has(key: KeyType): boolean;
|
||||
get(key: KeyType): ValueType | undefined;
|
||||
set(key: KeyType, value: ValueType): void;
|
||||
delete(key: KeyType): void;
|
||||
clear?: () => void;
|
||||
}
|
||||
|
||||
interface Options<
|
||||
ArgumentsType extends unknown[],
|
||||
CacheKeyType extends unknown,
|
||||
ReturnType extends unknown
|
||||
> {
|
||||
/**
|
||||
Milliseconds until the cache expires.
|
||||
|
||||
@default Infinity
|
||||
*/
|
||||
readonly maxAge?: number;
|
||||
|
||||
/**
|
||||
Determines the cache key for storing the result based on the function arguments. By default, if there's only one argument and it's a [primitive](https://developer.mozilla.org/en-US/docs/Glossary/Primitive), it's used directly as a key, otherwise it's all the function arguments JSON stringified as an array.
|
||||
|
||||
You could for example change it to only cache on the first argument `x => JSON.stringify(x)`.
|
||||
*/
|
||||
readonly cacheKey?: (...arguments: ArgumentsType) => CacheKeyType;
|
||||
|
||||
/**
|
||||
Use a different cache storage. You could for example use a `WeakMap` instead or [`quick-lru`](https://github.com/sindresorhus/quick-lru) for a LRU cache.
|
||||
|
||||
@default new Map()
|
||||
*/
|
||||
readonly cache?: CacheStorage<CacheKeyType, {data: ReturnType; maxAge: number}>;
|
||||
|
||||
/**
|
||||
Cache rejected promises.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly cachePromiseRejection?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
declare const mem: {
|
||||
/**
|
||||
[Memoize](https://en.wikipedia.org/wiki/Memoization) functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input.
|
||||
|
||||
@param fn - Function to be memoized.
|
||||
|
||||
@example
|
||||
```
|
||||
import mem = require('mem');
|
||||
|
||||
let i = 0;
|
||||
const counter = () => ++i;
|
||||
const memoized = mem(counter);
|
||||
|
||||
memoized('foo');
|
||||
//=> 1
|
||||
|
||||
// Cached as it's the same arguments
|
||||
memoized('foo');
|
||||
//=> 1
|
||||
|
||||
// Not cached anymore as the arguments changed
|
||||
memoized('bar');
|
||||
//=> 2
|
||||
|
||||
memoized('bar');
|
||||
//=> 2
|
||||
```
|
||||
*/
|
||||
<
|
||||
ArgumentsType extends unknown[],
|
||||
ReturnType extends unknown,
|
||||
CacheKeyType extends unknown
|
||||
>(
|
||||
fn: (...arguments: ArgumentsType) => ReturnType,
|
||||
options?: mem.Options<ArgumentsType, CacheKeyType, ReturnType>
|
||||
): (...arguments: ArgumentsType) => ReturnType;
|
||||
|
||||
/**
|
||||
Clear all cached data of a memoized function.
|
||||
|
||||
@param fn - Memoized function.
|
||||
*/
|
||||
clear<ArgumentsType extends unknown[], ReturnType extends unknown>(
|
||||
fn: (...arguments: ArgumentsType) => ReturnType
|
||||
): void;
|
||||
|
||||
// TODO: Remove this for the next major release
|
||||
default: typeof mem;
|
||||
};
|
||||
|
||||
export = mem;
|
88
node_modules/mem/index.js
generated
vendored
Normal file
88
node_modules/mem/index.js
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
'use strict';
|
||||
const mimicFn = require('mimic-fn');
|
||||
const isPromise = require('p-is-promise');
|
||||
const mapAgeCleaner = require('map-age-cleaner');
|
||||
|
||||
const cacheStore = new WeakMap();
|
||||
|
||||
const defaultCacheKey = (...arguments_) => {
|
||||
if (arguments_.length === 0) {
|
||||
return '__defaultKey';
|
||||
}
|
||||
|
||||
if (arguments_.length === 1) {
|
||||
const [firstArgument] = arguments_;
|
||||
if (
|
||||
firstArgument === null ||
|
||||
firstArgument === undefined ||
|
||||
(typeof firstArgument !== 'function' && typeof firstArgument !== 'object')
|
||||
) {
|
||||
return firstArgument;
|
||||
}
|
||||
}
|
||||
|
||||
return JSON.stringify(arguments_);
|
||||
};
|
||||
|
||||
const mem = (fn, options) => {
|
||||
options = Object.assign({
|
||||
cacheKey: defaultCacheKey,
|
||||
cache: new Map(),
|
||||
cachePromiseRejection: false
|
||||
}, options);
|
||||
|
||||
if (typeof options.maxAge === 'number') {
|
||||
mapAgeCleaner(options.cache);
|
||||
}
|
||||
|
||||
const {cache} = options;
|
||||
options.maxAge = options.maxAge || 0;
|
||||
|
||||
const setData = (key, data) => {
|
||||
cache.set(key, {
|
||||
data,
|
||||
maxAge: Date.now() + options.maxAge
|
||||
});
|
||||
};
|
||||
|
||||
const memoized = function (...arguments_) {
|
||||
const key = options.cacheKey(...arguments_);
|
||||
|
||||
if (cache.has(key)) {
|
||||
return cache.get(key).data;
|
||||
}
|
||||
|
||||
const cacheItem = fn.call(this, ...arguments_);
|
||||
|
||||
setData(key, cacheItem);
|
||||
|
||||
if (isPromise(cacheItem) && options.cachePromiseRejection === false) {
|
||||
// Remove rejected promises from cache unless `cachePromiseRejection` is set to `true`
|
||||
cacheItem.catch(() => cache.delete(key));
|
||||
}
|
||||
|
||||
return cacheItem;
|
||||
};
|
||||
|
||||
try {
|
||||
// The below call will throw in some host environments
|
||||
// See https://github.com/sindresorhus/mimic-fn/issues/10
|
||||
mimicFn(memoized, fn);
|
||||
} catch (_) {}
|
||||
|
||||
cacheStore.set(memoized, options.cache);
|
||||
|
||||
return memoized;
|
||||
};
|
||||
|
||||
module.exports = mem;
|
||||
// TODO: Remove this for the next major release
|
||||
module.exports.default = mem;
|
||||
|
||||
module.exports.clear = fn => {
|
||||
const cache = cacheStore.get(fn);
|
||||
|
||||
if (cache && typeof cache.clear === 'function') {
|
||||
cache.clear();
|
||||
}
|
||||
};
|
9
node_modules/mem/license
generated
vendored
Normal file
9
node_modules/mem/license
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
82
node_modules/mem/package.json
generated
vendored
Normal file
82
node_modules/mem/package.json
generated
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"mem@4.3.0",
|
||||
"C:\\Users\\Administrator\\Documents\\setup-python"
|
||||
]
|
||||
],
|
||||
"_development": true,
|
||||
"_from": "mem@4.3.0",
|
||||
"_id": "mem@4.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==",
|
||||
"_location": "/mem",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "mem@4.3.0",
|
||||
"name": "mem",
|
||||
"escapedName": "mem",
|
||||
"rawSpec": "4.3.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "4.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/os-locale"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz",
|
||||
"_spec": "4.3.0",
|
||||
"_where": "C:\\Users\\Administrator\\Documents\\setup-python",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/mem/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"map-age-cleaner": "^0.1.1",
|
||||
"mimic-fn": "^2.0.0",
|
||||
"p-is-promise": "^2.0.0"
|
||||
},
|
||||
"description": "Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input",
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"delay": "^4.1.0",
|
||||
"tsd": "^0.7.1",
|
||||
"xo": "^0.24.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"homepage": "https://github.com/sindresorhus/mem#readme",
|
||||
"keywords": [
|
||||
"memoize",
|
||||
"function",
|
||||
"mem",
|
||||
"memoization",
|
||||
"cache",
|
||||
"caching",
|
||||
"optimize",
|
||||
"performance",
|
||||
"ttl",
|
||||
"expire",
|
||||
"promise"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "mem",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/mem.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"version": "4.3.0"
|
||||
}
|
167
node_modules/mem/readme.md
generated
vendored
Normal file
167
node_modules/mem/readme.md
generated
vendored
Normal file
@ -0,0 +1,167 @@
|
||||
# mem [](https://travis-ci.org/sindresorhus/mem)
|
||||
|
||||
> [Memoize](https://en.wikipedia.org/wiki/Memoization) functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input
|
||||
|
||||
Memory is automatically released when an item expires.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install mem
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const mem = require('mem');
|
||||
|
||||
let i = 0;
|
||||
const counter = () => ++i;
|
||||
const memoized = mem(counter);
|
||||
|
||||
memoized('foo');
|
||||
//=> 1
|
||||
|
||||
// Cached as it's the same arguments
|
||||
memoized('foo');
|
||||
//=> 1
|
||||
|
||||
// Not cached anymore as the arguments changed
|
||||
memoized('bar');
|
||||
//=> 2
|
||||
|
||||
memoized('bar');
|
||||
//=> 2
|
||||
```
|
||||
|
||||
##### Works fine with promise returning functions
|
||||
|
||||
```js
|
||||
const mem = require('mem');
|
||||
|
||||
let i = 0;
|
||||
const counter = async () => ++i;
|
||||
const memoized = mem(counter);
|
||||
|
||||
(async () => {
|
||||
console.log(await memoized());
|
||||
//=> 1
|
||||
|
||||
// The return value didn't increase as it's cached
|
||||
console.log(await memoized());
|
||||
//=> 1
|
||||
})();
|
||||
```
|
||||
|
||||
```js
|
||||
const mem = require('mem');
|
||||
const got = require('got');
|
||||
const delay = require('delay');
|
||||
|
||||
const memGot = mem(got, {maxAge: 1000});
|
||||
|
||||
(async () => {
|
||||
await memGot('sindresorhus.com');
|
||||
|
||||
// This call is cached
|
||||
await memGot('sindresorhus.com');
|
||||
|
||||
await delay(2000);
|
||||
|
||||
// This call is not cached as the cache has expired
|
||||
await memGot('sindresorhus.com');
|
||||
})();
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### mem(fn, [options])
|
||||
|
||||
#### fn
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Function to be memoized.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
##### maxAge
|
||||
|
||||
Type: `number`<br>
|
||||
Default: `Infinity`
|
||||
|
||||
Milliseconds until the cache expires.
|
||||
|
||||
##### cacheKey
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Determines the cache key for storing the result based on the function arguments. By default, if there's only one argument and it's a [primitive](https://developer.mozilla.org/en-US/docs/Glossary/Primitive), it's used directly as a key, otherwise it's all the function arguments JSON stringified as an array.
|
||||
|
||||
You could for example change it to only cache on the first argument `x => JSON.stringify(x)`.
|
||||
|
||||
##### cache
|
||||
|
||||
Type: `Object`<br>
|
||||
Default: `new Map()`
|
||||
|
||||
Use a different cache storage. Must implement the following methods: `.has(key)`, `.get(key)`, `.set(key, value)`, `.delete(key)`, and optionally `.clear()`. You could for example use a `WeakMap` instead or [`quick-lru`](https://github.com/sindresorhus/quick-lru) for a LRU cache.
|
||||
|
||||
##### cachePromiseRejection
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Cache rejected promises.
|
||||
|
||||
### mem.clear(fn)
|
||||
|
||||
Clear all cached data of a memoized function.
|
||||
|
||||
#### fn
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Memoized function.
|
||||
|
||||
|
||||
## Tips
|
||||
|
||||
### Cache statistics
|
||||
|
||||
If you want to know how many times your cache had a hit or a miss, you can make use of [stats-map](https://github.com/SamVerschueren/stats-map) as a replacement for the default cache.
|
||||
|
||||
#### Example
|
||||
|
||||
```js
|
||||
const mem = require('mem');
|
||||
const StatsMap = require('stats-map');
|
||||
const got = require('got');
|
||||
|
||||
const cache = new StatsMap();
|
||||
const memGot = mem(got, {cache});
|
||||
|
||||
(async () => {
|
||||
await memGot('sindresorhus.com');
|
||||
await memGot('sindresorhus.com');
|
||||
await memGot('sindresorhus.com');
|
||||
|
||||
console.log(cache.stats);
|
||||
//=> {hits: 2, misses: 1}
|
||||
})();
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [p-memoize](https://github.com/sindresorhus/p-memoize) - Memoize promise-returning & async functions
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
Reference in New Issue
Block a user