summaryrefslogtreecommitdiff
path: root/includes/external/addressbook/node_modules/p-cancelable
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-04-06 22:18:28 +0200
committerRaindropsSys <contact@minteck.org>2023-04-06 22:18:28 +0200
commit83354b2b88218090988dd6e526b0a2505b57e0f1 (patch)
treee3c73c38a122a78bb7e66fbb99056407edd9d4b9 /includes/external/addressbook/node_modules/p-cancelable
parent47b8f2299a483024c4a6a8876af825a010954caa (diff)
downloadpluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.gz
pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.bz2
pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.zip
Updated 5 files and added 1110 files (automated)
Diffstat (limited to 'includes/external/addressbook/node_modules/p-cancelable')
-rw-r--r--includes/external/addressbook/node_modules/p-cancelable/index.d.ts168
-rw-r--r--includes/external/addressbook/node_modules/p-cancelable/index.js110
-rw-r--r--includes/external/addressbook/node_modules/p-cancelable/license9
-rw-r--r--includes/external/addressbook/node_modules/p-cancelable/package.json50
-rw-r--r--includes/external/addressbook/node_modules/p-cancelable/readme.md152
5 files changed, 489 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/p-cancelable/index.d.ts b/includes/external/addressbook/node_modules/p-cancelable/index.d.ts
new file mode 100644
index 0000000..f19d3b0
--- /dev/null
+++ b/includes/external/addressbook/node_modules/p-cancelable/index.d.ts
@@ -0,0 +1,168 @@
+/**
+The rejection reason when `.cancel()` is called.
+
+It includes a `.isCanceled` property for convenience.
+*/
+export class CancelError extends Error {
+ readonly name: 'CancelError';
+ readonly isCanceled: true;
+
+ constructor(reason?: string);
+}
+
+/**
+Accepts a function that is called when the promise is canceled.
+
+You're not required to call this function. You can call this function multiple times to add multiple cancel handlers.
+*/
+export interface OnCancelFunction {
+ shouldReject: boolean;
+ (cancelHandler: () => void): void;
+}
+
+export default class PCancelable<ValueType> extends Promise<ValueType> {
+ /**
+ Whether the promise is canceled.
+ */
+ readonly isCanceled: boolean;
+
+ /**
+ Cancel the promise and optionally provide a reason.
+
+ The cancellation is synchronous. Calling it after the promise has settled or multiple times does nothing.
+
+ @param reason - The cancellation reason to reject the promise with.
+ */
+ cancel: (reason?: string) => void;
+
+ /**
+ Create a promise that can be canceled.
+
+ Can be constructed in the same was as a [`Promise` constructor](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise), but with an appended `onCancel` parameter in `executor`. `PCancelable` is a subclass of `Promise`.
+
+ Cancelling will reject the promise with `CancelError`. To avoid that, set `onCancel.shouldReject` to `false`.
+
+ @example
+ ```
+ import PCancelable from 'p-cancelable';
+
+ const cancelablePromise = new PCancelable((resolve, reject, onCancel) => {
+ const job = new Job();
+
+ onCancel.shouldReject = false;
+ onCancel(() => {
+ job.stop();
+ });
+
+ job.on('finish', resolve);
+ });
+
+ cancelablePromise.cancel(); // Doesn't throw an error
+ ```
+ */
+ constructor(
+ executor: (
+ resolve: (value?: ValueType | PromiseLike<ValueType>) => void,
+ reject: (reason?: unknown) => void,
+ onCancel: OnCancelFunction
+ ) => void
+ );
+
+ /**
+ Convenience method to make your promise-returning or async function cancelable.
+
+ @param fn - A promise-returning function. The function you specify will have `onCancel` appended to its parameters.
+
+ @example
+ ```
+ import PCancelable from 'p-cancelable';
+
+ const fn = PCancelable.fn((input, onCancel) => {
+ const job = new Job();
+
+ onCancel(() => {
+ job.cleanup();
+ });
+
+ return job.start(); //=> Promise
+ });
+
+ const cancelablePromise = fn('input'); //=> PCancelable
+
+ // …
+
+ cancelablePromise.cancel();
+ ```
+ */
+ static fn<ReturnType>(
+ userFn: (onCancel: OnCancelFunction) => PromiseLike<ReturnType>
+ ): () => PCancelable<ReturnType>;
+ static fn<Agument1Type, ReturnType>(
+ userFn: (
+ argument1: Agument1Type,
+ onCancel: OnCancelFunction
+ ) => PromiseLike<ReturnType>
+ ): (argument1: Agument1Type) => PCancelable<ReturnType>;
+ static fn<Agument1Type, Agument2Type, ReturnType>(
+ userFn: (
+ argument1: Agument1Type,
+ argument2: Agument2Type,
+ onCancel: OnCancelFunction
+ ) => PromiseLike<ReturnType>
+ ): (
+ argument1: Agument1Type,
+ argument2: Agument2Type
+ ) => PCancelable<ReturnType>;
+ static fn<Agument1Type, Agument2Type, Agument3Type, ReturnType>(
+ userFn: (
+ argument1: Agument1Type,
+ argument2: Agument2Type,
+ argument3: Agument3Type,
+ onCancel: OnCancelFunction
+ ) => PromiseLike<ReturnType>
+ ): (
+ argument1: Agument1Type,
+ argument2: Agument2Type,
+ argument3: Agument3Type
+ ) => PCancelable<ReturnType>;
+ static fn<Agument1Type, Agument2Type, Agument3Type, Agument4Type, ReturnType>(
+ userFn: (
+ argument1: Agument1Type,
+ argument2: Agument2Type,
+ argument3: Agument3Type,
+ argument4: Agument4Type,
+ onCancel: OnCancelFunction
+ ) => PromiseLike<ReturnType>
+ ): (
+ argument1: Agument1Type,
+ argument2: Agument2Type,
+ argument3: Agument3Type,
+ argument4: Agument4Type
+ ) => PCancelable<ReturnType>;
+ static fn<
+ Agument1Type,
+ Agument2Type,
+ Agument3Type,
+ Agument4Type,
+ Agument5Type,
+ ReturnType
+ >(
+ userFn: (
+ argument1: Agument1Type,
+ argument2: Agument2Type,
+ argument3: Agument3Type,
+ argument4: Agument4Type,
+ argument5: Agument5Type,
+ onCancel: OnCancelFunction
+ ) => PromiseLike<ReturnType>
+ ): (
+ argument1: Agument1Type,
+ argument2: Agument2Type,
+ argument3: Agument3Type,
+ argument4: Agument4Type,
+ argument5: Agument5Type
+ ) => PCancelable<ReturnType>;
+ static fn<ReturnType>(
+ userFn: (...arguments: unknown[]) => PromiseLike<ReturnType>
+ ): (...arguments: unknown[]) => PCancelable<ReturnType>;
+}
diff --git a/includes/external/addressbook/node_modules/p-cancelable/index.js b/includes/external/addressbook/node_modules/p-cancelable/index.js
new file mode 100644
index 0000000..93bb224
--- /dev/null
+++ b/includes/external/addressbook/node_modules/p-cancelable/index.js
@@ -0,0 +1,110 @@
+export class CancelError extends Error {
+ constructor(reason) {
+ super(reason || 'Promise was canceled');
+ this.name = 'CancelError';
+ }
+
+ get isCanceled() {
+ return true;
+ }
+}
+
+// TODO: Use private class fields when ESLint 8 is out.
+
+export default class PCancelable {
+ static fn(userFunction) {
+ return (...arguments_) => {
+ return new PCancelable((resolve, reject, onCancel) => {
+ arguments_.push(onCancel);
+ // eslint-disable-next-line promise/prefer-await-to-then
+ userFunction(...arguments_).then(resolve, reject);
+ });
+ };
+ }
+
+ constructor(executor) {
+ this._cancelHandlers = [];
+ this._isPending = true;
+ this._isCanceled = false;
+ this._rejectOnCancel = true;
+
+ this._promise = new Promise((resolve, reject) => {
+ this._reject = reject;
+
+ const onResolve = value => {
+ if (!this._isCanceled || !onCancel.shouldReject) {
+ this._isPending = false;
+ resolve(value);
+ }
+ };
+
+ const onReject = error => {
+ this._isPending = false;
+ reject(error);
+ };
+
+ const onCancel = handler => {
+ if (!this._isPending) {
+ throw new Error('The `onCancel` handler was attached after the promise settled.');
+ }
+
+ this._cancelHandlers.push(handler);
+ };
+
+ Object.defineProperties(onCancel, {
+ shouldReject: {
+ get: () => this._rejectOnCancel,
+ set: boolean => {
+ this._rejectOnCancel = boolean;
+ }
+ }
+ });
+
+ executor(onResolve, onReject, onCancel);
+ });
+ }
+
+ then(onFulfilled, onRejected) {
+ // eslint-disable-next-line promise/prefer-await-to-then
+ return this._promise.then(onFulfilled, onRejected);
+ }
+
+ catch(onRejected) {
+ // eslint-disable-next-line promise/prefer-await-to-then
+ return this._promise.catch(onRejected);
+ }
+
+ finally(onFinally) {
+ // eslint-disable-next-line promise/prefer-await-to-then
+ return this._promise.finally(onFinally);
+ }
+
+ cancel(reason) {
+ if (!this._isPending || this._isCanceled) {
+ return;
+ }
+
+ this._isCanceled = true;
+
+ if (this._cancelHandlers.length > 0) {
+ try {
+ for (const handler of this._cancelHandlers) {
+ handler();
+ }
+ } catch (error) {
+ this._reject(error);
+ return;
+ }
+ }
+
+ if (this._rejectOnCancel) {
+ this._reject(new CancelError(reason));
+ }
+ }
+
+ get isCanceled() {
+ return this._isCanceled;
+ }
+}
+
+Object.setPrototypeOf(PCancelable.prototype, Promise.prototype);
diff --git a/includes/external/addressbook/node_modules/p-cancelable/license b/includes/external/addressbook/node_modules/p-cancelable/license
new file mode 100644
index 0000000..fa7ceba
--- /dev/null
+++ b/includes/external/addressbook/node_modules/p-cancelable/license
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://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.
diff --git a/includes/external/addressbook/node_modules/p-cancelable/package.json b/includes/external/addressbook/node_modules/p-cancelable/package.json
new file mode 100644
index 0000000..84c16bd
--- /dev/null
+++ b/includes/external/addressbook/node_modules/p-cancelable/package.json
@@ -0,0 +1,50 @@
+{
+ "name": "p-cancelable",
+ "version": "3.0.0",
+ "description": "Create a promise that can be canceled",
+ "license": "MIT",
+ "repository": "sindresorhus/p-cancelable",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "https://sindresorhus.com"
+ },
+ "type": "module",
+ "exports": "./index.js",
+ "engines": {
+ "node": ">=12.20"
+ },
+ "scripts": {
+ "test": "xo && ava && tsd"
+ },
+ "files": [
+ "index.js",
+ "index.d.ts"
+ ],
+ "keywords": [
+ "promise",
+ "cancelable",
+ "cancel",
+ "canceled",
+ "canceling",
+ "cancellable",
+ "cancellation",
+ "abort",
+ "abortable",
+ "aborting",
+ "cleanup",
+ "task",
+ "token",
+ "async",
+ "function",
+ "await",
+ "promises",
+ "bluebird"
+ ],
+ "devDependencies": {
+ "ava": "^3.15.0",
+ "delay": "^5.0.0",
+ "tsd": "^0.16.0",
+ "xo": "^0.40.1"
+ }
+}
diff --git a/includes/external/addressbook/node_modules/p-cancelable/readme.md b/includes/external/addressbook/node_modules/p-cancelable/readme.md
new file mode 100644
index 0000000..6a096a1
--- /dev/null
+++ b/includes/external/addressbook/node_modules/p-cancelable/readme.md
@@ -0,0 +1,152 @@
+# p-cancelable
+
+> Create a promise that can be canceled
+
+Useful for animation, loading resources, long-running async computations, async iteration, etc.
+
+*If you target [Node.js 15](https://medium.com/@nodejs/node-js-v15-0-0-is-here-deb00750f278) or later, this package is [less useful](https://github.com/sindresorhus/p-cancelable/issues/27) and you should probably use [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) instead.*
+
+## Install
+
+```
+$ npm install p-cancelable
+```
+
+## Usage
+
+```js
+import PCancelable from 'p-cancelable';
+
+const cancelablePromise = new PCancelable((resolve, reject, onCancel) => {
+ const worker = new SomeLongRunningOperation();
+
+ onCancel(() => {
+ worker.close();
+ });
+
+ worker.on('finish', resolve);
+ worker.on('error', reject);
+});
+
+// Cancel the operation after 10 seconds
+setTimeout(() => {
+ cancelablePromise.cancel('Unicorn has changed its color');
+}, 10000);
+
+try {
+ console.log('Operation finished successfully:', await cancelablePromise);
+} catch (error) {
+ if (cancelablePromise.isCanceled) {
+ // Handle the cancelation here
+ console.log('Operation was canceled');
+ return;
+ }
+
+ throw error;
+}
+```
+
+## API
+
+### new PCancelable(executor)
+
+Same as the [`Promise` constructor](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise), but with an appended `onCancel` parameter in `executor`.
+
+Cancelling will reject the promise with `CancelError`. To avoid that, set `onCancel.shouldReject` to `false`.
+
+```js
+import PCancelable from 'p-cancelable';
+
+const cancelablePromise = new PCancelable((resolve, reject, onCancel) => {
+ const job = new Job();
+
+ onCancel.shouldReject = false;
+ onCancel(() => {
+ job.stop();
+ });
+
+ job.on('finish', resolve);
+});
+
+cancelablePromise.cancel(); // Doesn't throw an error
+```
+
+`PCancelable` is a subclass of `Promise`.
+
+#### onCanceled(fn)
+
+Type: `Function`
+
+Accepts a function that is called when the promise is canceled.
+
+You're not required to call this function. You can call this function multiple times to add multiple cancel handlers.
+
+### PCancelable#cancel(reason?)
+
+Type: `Function`
+
+Cancel the promise and optionally provide a reason.
+
+The cancellation is synchronous. Calling it after the promise has settled or multiple times does nothing.
+
+### PCancelable#isCanceled
+
+Type: `boolean`
+
+Whether the promise is canceled.
+
+### PCancelable.fn(fn)
+
+Convenience method to make your promise-returning or async function cancelable.
+
+The function you specify will have `onCancel` appended to its parameters.
+
+```js
+import PCancelable from 'p-cancelable';
+
+const fn = PCancelable.fn((input, onCancel) => {
+ const job = new Job();
+
+ onCancel(() => {
+ job.cleanup();
+ });
+
+ return job.start(); //=> Promise
+});
+
+const cancelablePromise = fn('input'); //=> PCancelable
+
+// …
+
+cancelablePromise.cancel();
+```
+
+### CancelError
+
+Type: `Error`
+
+Rejection reason when `.cancel()` is called.
+
+It includes a `.isCanceled` property for convenience.
+
+## FAQ
+
+### Cancelable vs. Cancellable
+
+[In American English, the verb cancel is usually inflected canceled and canceling—with one l.](http://grammarist.com/spelling/cancel/) Both a [browser API](https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable) and the [Cancelable Promises proposal](https://github.com/tc39/proposal-cancelable-promises) use this spelling.
+
+### What about the official [Cancelable Promises proposal](https://github.com/tc39/proposal-cancelable-promises)?
+
+~~It's still an early draft and I don't really like its current direction. It complicates everything and will require deep changes in the ecosystem to adapt to it. And the way you have to use cancel tokens is verbose and convoluted. I much prefer the more pragmatic and less invasive approach in this module.~~ The proposal was withdrawn.
+
+## p-cancelable for enterprise
+
+Available as part of the Tidelift Subscription.
+
+The maintainers of p-cancelable and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-p-cancelable?utm_source=npm-p-cancelable&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
+
+## Related
+
+- [p-progress](https://github.com/sindresorhus/p-progress) - Create a promise that reports progress
+- [p-lazy](https://github.com/sindresorhus/p-lazy) - Create a lazy promise that defers execution until `.then()` or `.catch()` is called
+- [More…](https://github.com/sindresorhus/promise-fun)