refactor(promise-kit): split up into multiple src files
MODIFY
packages/promise-kit/index.js
packages/promise-kit/index.js
import { memoRace } from './src/memo-race.js';
+export * from './src/is-promise.js';
+// eslint-disable-next-line import/export
+export * from './src/types.js';
+
/** @type {PromiseConstructor} */
const BestPipelinablePromise = globalThis.HandledPromise || Promise;
-/**
- * @template T
- * @typedef {Object} PromiseKit A reified Promise
- * @property {(value: ERef<T>) => void} resolve
- * @property {(reason: any) => void} reject
- * @property {Promise<T>} promise
- */
-
-/**
- * PromiseRecord is deprecated in favor of PromiseKit.
- *
- * @template T
- * @typedef {PromiseKit<T>} PromiseRecord
- */
-
-/**
- * @template T
- * @typedef {T | PromiseLike<T>} ERef
- * A reference of some kind for to an object of type T. It may be a direct
- * reference to a local T. It may be a local presence for a remote T. It may
- * be a promise for a local or remote T. Or it may even be a thenable
- * (a promise-like non-promise with a "then" method) for a T.
- */
-
/**
* Needed to prevent type errors where functions are detected to be undefined.
*/
@@ -43,10 +23,10 @@ const NOOP_INITIALIZER = harden(() => {});
* and rejecting it.
*
* @template T
- * @returns {PromiseKit<T>}
+ * @returns {import('./src/types.js').PromiseKit<T>}
*/
export function makePromiseKit() {
- /** @type {(value: ERef<T>) => void} */
+ /** @type {(value: import('./src/types.js').ERef<T>) => void} */
let resolve = NOOP_INITIALIZER;
/** @type {(reason: unknown) => void} */
let reject = NOOP_INITIALIZER;
@@ -61,17 +41,6 @@ export function makePromiseKit() {
}
harden(makePromiseKit);
-/**
- * Determine if the argument is a Promise.
- *
- * @param {any} maybePromise The value to examine
- * @returns {maybePromise is Promise} Whether it is a promise
- */
-export function isPromise(maybePromise) {
- return Promise.resolve(maybePromise) === maybePromise;
-}
-harden(isPromise);
-
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.

ADD
packages/promise-kit/src/is-promise.js
+// @ts-check
+
+/**
+ * Determine if the argument is a Promise.
+ *
+ * @param {unknown} maybePromise The value to examine
+ * @returns {maybePromise is Promise} Whether it is a promise
+ */
+export function isPromise(maybePromise) {
+ return Promise.resolve(maybePromise) === maybePromise;
+}
+harden(isPromise);

MODIFY
packages/promise-kit/src/memo-race.js
packages/promise-kit/src/memo-race.js
@@ -34,7 +34,7 @@ const isObject = value => Object(value) === value;
/**
* @template [T=any]
* @typedef {object} Deferred
- * @property {(value?: import("../index.js").ERef<T> ) => void} resolve
+ * @property {(value?: import("./types.js").ERef<T> ) => void} resolve
* @property {(err?: any ) => void} reject
*/

ADD
packages/promise-kit/src/types.js
+/**
+ * @template T
+ * @typedef {object} PromiseKit A reified Promise
+ * @property {(value: ERef<T>) => void} resolve
+ * @property {(reason: any) => void} reject
+ * @property {Promise<T>} promise
+ */
+
+/**
+ * PromiseRecord is deprecated in favor of PromiseKit.
+ *
+ * @template T
+ * @typedef {PromiseKit<T>} PromiseRecord
+ */
+
+/**
+ * @template T
+ * @typedef {T | PromiseLike<T>} ERef
+ * A reference of some kind for to an object of type T. It may be a direct
+ * reference to a local T. It may be a local presence for a remote T. It may
+ * be a promise for a local or remote T. Or it may even be a thenable
+ * (a promise-like non-promise with a "then" method) for a T.
+ */
+
+export {};

refactor(promise-kit): split up into multiple src files