@dr.pogodin/js-utils 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,6 +46,12 @@ and used in the same way):
46
46
  — One year expressed in milliseconds.
47
47
 
48
48
  ### Types
49
+ - `Extends<Base, T extends Base>` &mdash; Validates compile-time the type **T**
50
+ extends (is assignable to) the type **Base**; returns **T** if successful.
51
+ - `Implements<Base, T extends Base & ...>` &mdash; Validates compile-time
52
+ the type **T** extends (is assignable to) the type **Base**, and also has
53
+ all (if any) optional fields defined in the **Base**; returns **T** if
54
+ the validation passes.
49
55
  - `ObjectKey` &mdash; **string** | **number** | **symbol** &mdash;
50
56
  The most generic valid type of an object key in TypeScript.
51
57
 
@@ -114,10 +114,10 @@ class Barrier extends Promise {
114
114
  then(onFulfilled, onRejected) {
115
115
  const res = super.then(onFulfilled, onRejected);
116
116
  // TODO: Revise later.
117
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
117
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/strict-void-return
118
118
  res.pResolve = this.resolve;
119
119
  // TODO: Revise later.
120
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
120
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/strict-void-return
121
121
  res.pReject = this.reject;
122
122
  return res;
123
123
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Barrier.js","names":["STATE","Barrier","Promise","pState","PENDING","constructor","executor","resolveRef","rejectRef","resolve","reject","value","RESOLVED","reason","REJECTED","pResolve","pReject","arg","resolved","rejected","settled","catch","onRejected","finally","onFinally","then","onFulfilled","res","exports","default"],"sources":["../../src/Barrier.ts"],"sourcesContent":["export type Executor<T> = ConstructorParameters<typeof Promise<T>>[0];\n\ntype Resolver<T> = Parameters<Executor<T>>[0];\ntype Rejecter = Parameters<Executor<unknown>>[1];\n\nenum STATE {\n PENDING = 'PENDING',\n REJECTED = 'REJECTED',\n RESOLVED = 'RESOLVED',\n}\n\n/**\n * Barrier is just a Promise which has resolve and reject exposed as instance\n * methods.\n *\n * It has two generic arguments T and TR which correspond to the argument of\n * the .resolve() method, and to the value resolved by the promise (barrier).\n * For a simple barrier TR equals to T, however for barriers created via .then()\n * chain, T corresponds to the argument of the original barrier, and TR to\n * the value resolved by the latest promise in the chain. Consider this:\n *\n * const b = new Barrier<string>();\n * b.resolve('result');\n * const s = await b; // `s` has `string` type, and equals \"result\".\n *\n * const b = (new Barrier<string>()).then((s) => s.length);\n * b.resolve('result'); // Chained barrier exposes .resolve() method of\n * // the first barrier in the chain, which expects\n * // `string` arugment (T), but the chained barrier\n * // resolves to `number` (TR).\n * const n = await b; // `n` has `number` type, and equals 6.\n *\n * Docs: https://dr.pogodin.studio/docs/react-utils/docs/api/classes/Barrier\n */\nexport default class Barrier<T = unknown, TR = T> extends Promise<TR> {\n private pResolve: Resolver<T>;\n\n private pReject: Rejecter;\n\n private pState = STATE.PENDING;\n\n constructor(executor?: Executor<TR>) {\n let resolveRef: Resolver<TR>;\n let rejectRef: Rejecter;\n\n super((resolve, reject) => {\n // Note: Enforcing `void` return type because of the BEWARE note below.\n resolveRef = (value: TR | PromiseLike<TR>): void => {\n resolve(value);\n this.pState = STATE.RESOLVED;\n\n // BEWARE: Don't try to return `this` here, it will easily cause\n // infinite loops in React Native, which are extremely difficult\n // to troubleshoot (I wasn't able to figure out, are they due to\n // internal Promise implementation in RN, or because of some bad\n // patterns in the host code).\n };\n\n // Note: Enforcing `void` return type because of the BEWARE note below.\n rejectRef = (reason?: unknown): void => {\n reject(reason);\n this.pState = STATE.REJECTED;\n };\n\n if (executor) executor(resolveRef, rejectRef);\n });\n\n // NOTE: We assume, the only scenario where TR is not equal T is when\n // the Barrier is constructed by a .then() call on a \"parent\" barrier,\n // and in that scenario .then() itself will replace .p_resolve by another\n // resolver immediately after this constructor returns.\n this.pResolve = resolveRef! as Resolver<T>;\n\n this.pReject = rejectRef!;\n }\n\n get resolve() {\n return (arg: Parameters<Resolver<T>>[0]): this => {\n this.pResolve(arg);\n return this;\n };\n }\n\n get reject() {\n return (arg: Parameters<Rejecter>[0]): this => {\n this.pReject(arg);\n return this;\n };\n }\n\n get resolved(): boolean {\n return this.pState === STATE.RESOLVED;\n }\n\n get rejected(): boolean {\n return this.pState === STATE.REJECTED;\n }\n\n get settled(): boolean {\n return this.pState !== STATE.PENDING;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n catch<TR1>(\n onRejected?: ((reason: unknown) => TR1 | PromiseLike<TR1>) | null,\n ): Barrier<T, TR1> {\n return super.catch(onRejected) as Barrier<T, TR1>;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n finally(onFinally?: (() => void) | null): Barrier<TR> {\n return super.finally(onFinally) as Barrier<TR>;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n then<TR1, TR2>(\n onFulfilled?: ((value: TR) => TR1 | PromiseLike<TR1>) | null,\n onRejected?: ((reason: unknown) => TR2 | PromiseLike<TR2>) | null,\n ): Barrier<T, TR1 | TR2> {\n const res = super.then(onFulfilled, onRejected) as Barrier<T, TR1 | TR2>;\n // TODO: Revise later.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n res.pResolve = this.resolve;\n // TODO: Revise later.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n res.pReject = this.reject;\n return res;\n }\n}\n"],"mappings":";;;;;;IAKKA,KAAK,0BAALA,KAAK;E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vC;EAEA,IAAIO,QAAQA,CAAA,EAAY;IACtB,OAAO,IAAI,CAAChB,MAAM,KAAKH,KAAK,CAACc,QAAQ;EACvC;EAEA,IAAIM,OAAOA,CAAA,EAAY;IACrB,OAAO,IAAI,CAACjB,MAAM,KAAKH,KAAK,CAACI,OAAO;EACtC;;EAEA;EACA;EACA;EACA;EACA;EACAiB,KAAKA,CACHC,UAAiE,EAChD;IACjB,OAAO,KAAK,CAACD,KAAK,CAACC,UAAU,CAAC;EAChC;;EAEA;EACA;EACA;EACA;EACA;EACAC,OAAOA,CAACC,SAA+B,EAAe;IACpD,OAAO,KAAK,CAACD,OAAO,CAACC,SAAS,CAAC;EACjC;;EAEA;EACA;EACA;EACA;EACA;EACAC,IAAIA,CACFC,WAA4D,EAC5DJ,UAAiE,EAC1C;IACvB,MAAMK,GAAG,GAAG,KAAK,CAACF,IAAI,CAACC,WAAW,EAAEJ,UAAU,CAA0B;IACxE;IACA;IACAK,GAAG,CAACZ,QAAQ,GAAG,IAAI,CAACN,OAAO;IAC3B;IACA;IACAkB,GAAG,CAACX,OAAO,GAAG,IAAI,CAACN,MAAM;IACzB,OAAOiB,GAAG;EACZ;AACF;AAACC,OAAA,CAAAC,OAAA,GAAA5B,OAAA","ignoreList":[]}
1
+ {"version":3,"file":"Barrier.js","names":["STATE","Barrier","Promise","pState","PENDING","constructor","executor","resolveRef","rejectRef","resolve","reject","value","RESOLVED","reason","REJECTED","pResolve","pReject","arg","resolved","rejected","settled","catch","onRejected","finally","onFinally","then","onFulfilled","res","exports","default"],"sources":["../../src/Barrier.ts"],"sourcesContent":["export type Executor<T> = ConstructorParameters<typeof Promise<T>>[0];\n\ntype Rejecter = Parameters<Executor<unknown>>[1];\ntype Resolver<T> = Parameters<Executor<T>>[0];\n\nenum STATE {\n PENDING = 'PENDING',\n REJECTED = 'REJECTED',\n RESOLVED = 'RESOLVED',\n}\n\n/**\n * Barrier is just a Promise which has resolve and reject exposed as instance\n * methods.\n *\n * It has two generic arguments T and TR which correspond to the argument of\n * the .resolve() method, and to the value resolved by the promise (barrier).\n * For a simple barrier TR equals to T, however for barriers created via .then()\n * chain, T corresponds to the argument of the original barrier, and TR to\n * the value resolved by the latest promise in the chain. Consider this:\n *\n * const b = new Barrier<string>();\n * b.resolve('result');\n * const s = await b; // `s` has `string` type, and equals \"result\".\n *\n * const b = (new Barrier<string>()).then((s) => s.length);\n * b.resolve('result'); // Chained barrier exposes .resolve() method of\n * // the first barrier in the chain, which expects\n * // `string` arugment (T), but the chained barrier\n * // resolves to `number` (TR).\n * const n = await b; // `n` has `number` type, and equals 6.\n *\n * Docs: https://dr.pogodin.studio/docs/react-utils/docs/api/classes/Barrier\n */\nexport default class Barrier<T = unknown, TR = T> extends Promise<TR> {\n private pResolve: Resolver<T>;\n\n private pReject: Rejecter;\n\n private pState = STATE.PENDING;\n\n constructor(executor?: Executor<TR>) {\n let resolveRef: Resolver<TR>;\n let rejectRef: Rejecter;\n\n super((resolve, reject) => {\n // Note: Enforcing `void` return type because of the BEWARE note below.\n resolveRef = (value: PromiseLike<TR> | TR): void => {\n resolve(value);\n this.pState = STATE.RESOLVED;\n\n // BEWARE: Don't try to return `this` here, it will easily cause\n // infinite loops in React Native, which are extremely difficult\n // to troubleshoot (I wasn't able to figure out, are they due to\n // internal Promise implementation in RN, or because of some bad\n // patterns in the host code).\n };\n\n // Note: Enforcing `void` return type because of the BEWARE note below.\n rejectRef = (reason?: unknown): void => {\n reject(reason);\n this.pState = STATE.REJECTED;\n };\n\n if (executor) executor(resolveRef, rejectRef);\n });\n\n // NOTE: We assume, the only scenario where TR is not equal T is when\n // the Barrier is constructed by a .then() call on a \"parent\" barrier,\n // and in that scenario .then() itself will replace .p_resolve by another\n // resolver immediately after this constructor returns.\n this.pResolve = resolveRef! as Resolver<T>;\n\n this.pReject = rejectRef!;\n }\n\n get resolve() {\n return (arg: Parameters<Resolver<T>>[0]): this => {\n this.pResolve(arg);\n return this;\n };\n }\n\n get reject() {\n return (arg: Parameters<Rejecter>[0]): this => {\n this.pReject(arg);\n return this;\n };\n }\n\n get resolved(): boolean {\n return this.pState === STATE.RESOLVED;\n }\n\n get rejected(): boolean {\n return this.pState === STATE.REJECTED;\n }\n\n get settled(): boolean {\n return this.pState !== STATE.PENDING;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n catch<TR1>(\n onRejected?: ((reason: unknown) => PromiseLike<TR1> | TR1) | null,\n ): Barrier<T, TR1> {\n return super.catch(onRejected) as Barrier<T, TR1>;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n finally(onFinally?: (() => void) | null): Barrier<TR> {\n return super.finally(onFinally) as Barrier<TR>;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n then<TR1, TR2>(\n onFulfilled?: ((value: TR) => PromiseLike<TR1> | TR1) | null,\n onRejected?: ((reason: unknown) => PromiseLike<TR2> | TR2) | null,\n ): Barrier<T, TR1 | TR2> {\n const res = super.then(onFulfilled, onRejected) as Barrier<T, TR1 | TR2>;\n // TODO: Revise later.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/strict-void-return\n res.pResolve = this.resolve;\n // TODO: Revise later.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/strict-void-return\n res.pReject = this.reject;\n return res;\n }\n}\n"],"mappings":";;;;;;IAKKA,KAAK,0BAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAAA,OAALA,KAAK;AAAA,EAALA,KA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KAAKH,KAAK,CAACc,QAAQ;EACvC;EAEA,IAAIM,OAAOA,CAAA,EAAY;IACrB,OAAO,IAAI,CAACjB,MAAM,KAAKH,KAAK,CAACI,OAAO;EACtC;;EAEA;EACA;EACA;EACA;EACA;EACAiB,KAAKA,CACHC,UAAiE,EAChD;IACjB,OAAO,KAAK,CAACD,KAAK,CAACC,UAAU,CAAC;EAChC;;EAEA;EACA;EACA;EACA;EACA;EACAC,OAAOA,CAACC,SAA+B,EAAe;IACpD,OAAO,KAAK,CAACD,OAAO,CAACC,SAAS,CAAC;EACjC;;EAEA;EACA;EACA;EACA;EACA;EACAC,IAAIA,CACFC,WAA4D,EAC5DJ,UAAiE,EAC1C;IACvB,MAAMK,GAAG,GAAG,KAAK,CAACF,IAAI,CAACC,WAAW,EAAEJ,UAAU,CAA0B;IACxE;IACA;IACAK,GAAG,CAACZ,QAAQ,GAAG,IAAI,CAACN,OAAO;IAC3B;IACA;IACAkB,GAAG,CAACX,OAAO,GAAG,IAAI,CAACN,MAAM;IACzB,OAAOiB,GAAG;EACZ;AACF;AAACC,OAAA,CAAAC,OAAA,GAAA5B,OAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"Cached.js","names":["addTimestamp","promise","timestamp","res","getTimestamp","e","Array","isArray","Cached","pData","pOldestTimestamp","Number","MAX_SAFE_INTEGER","data","oldestTimestamp","constructor","maxage","getter","cleanCache","deadline","Date","now","key","entry","Object","entries","setEntry","id","set","datum","getEntry","forceRefresh","cached","itemOrPromise","Promise","then","item","get","exports"],"sources":["../../src/Cached.ts"],"sourcesContent":["type CachedT<T> = [T, number];\ntype TimestampedPromise<T> = Promise<T> & { timestamp: number };\ntype EntryT<T> = CachedT<T> | TimestampedPromise<CachedT<T>>;\n\n/** Adds timestamp to the promise. */\nfunction addTimestamp<T>(\n promise: Promise<T>,\n timestamp: number,\n): TimestampedPromise<T> {\n const res = promise as TimestampedPromise<T>;\n res.timestamp = timestamp;\n return res;\n}\n\n/** Gets entry timestamp. */\nfunction getTimestamp<T>(e: EntryT<T>): number {\n return Array.isArray(e) ? e[1] : e.timestamp;\n}\n\nexport class Cached<T> {\n private pData: Record<string, EntryT<T>> = {};\n private pOldestTimestamp = Number.MAX_SAFE_INTEGER;\n\n /** For test use only. */\n get data(): Readonly<Record<string, EntryT<T>>> {\n return this.pData;\n }\n\n /** For test use only. */\n get oldestTimestamp(): number {\n return this.pOldestTimestamp;\n }\n\n constructor(\n public readonly maxage: number,\n private getter: (id: string) => T | Promise<T>,\n ) {}\n\n /** Removes stale items from the cache, and updates .oldestTimestamp. */\n private cleanCache() {\n const deadline = Date.now() - this.maxage;\n this.pOldestTimestamp = Number.MAX_SAFE_INTEGER;\n for (const [key, entry] of Object.entries(this.pData)) {\n const timestamp = getTimestamp(entry);\n if (timestamp < deadline) delete this.pData[key];\n else if (timestamp < this.pOldestTimestamp) {\n this.pOldestTimestamp = timestamp;\n }\n }\n }\n\n /**\n * Adds entry to the cache.\n * NOTE: It assumes entry's timestamp is the current moment (for the cache\n * cleaning purposes; if it is not, but it is a past timestamp, nothing bad\n * will happen, just some cleaning operation will be skipped).\n */\n private setEntry(id: string, entry: EntryT<T>) {\n this.pData[id] = entry;\n const timestamp = getTimestamp(entry);\n if (timestamp < this.pOldestTimestamp) this.pOldestTimestamp = timestamp;\n else if (this.pOldestTimestamp < timestamp - this.maxage) this.cleanCache();\n }\n\n /** Adds `datum` to the cache, and removes stale items from the cache. */\n private set(id: string, datum: T): CachedT<T> {\n const res: CachedT<T> = [datum, Date.now()];\n this.setEntry(id, res);\n return res;\n }\n\n /**\n * Retrieves envelope of the specified datum, either read from the cache,\n * or retrieved using the getter provided at construction time.\n */\n private getEntry(id: string, forceRefresh?: boolean): EntryT<T> {\n const now = Date.now();\n\n if (!forceRefresh) {\n const cached = this.pData[id];\n if (cached && getTimestamp(cached) >= now - this.maxage) return cached;\n }\n\n const itemOrPromise = this.getter(id);\n if (!(itemOrPromise instanceof Promise)) {\n return this.set(id, itemOrPromise);\n }\n\n const promise = addTimestamp(\n itemOrPromise.then((item) => this.set(id, item)),\n now,\n );\n\n this.setEntry(id, promise);\n\n return promise;\n }\n\n /** Gets item. */\n get(id: string, forceRefresh?: boolean): T | Promise<T> {\n const entry = this.getEntry(id, forceRefresh);\n return Array.isArray(entry) ? entry[0] : entry.then((e) => e[0]);\n }\n}\n"],"mappings":";;;;;;AAIA;AACA,SAASA,YAAYA,CACnBC,OAAmB,EACnBC,SAAiB,EACM;EACvB,MAAMC,GAAG,GAAGF,OAAgC;EAC5CE,GAAG,CAACD,SAAS,GAAGA,SAAS;EACzB,OAAOC,GAAG;AACZ;;AAEA;AACA,SAASC,YAAYA,CAAIC,CAAY,EAAU;EAC7C,OAAOC,KAAK,CAACC,OAAO,CAACF,CAAC,CAAC,GAAGA,CAAC,CAAC,CAAC,CAAC,GAAGA,CAAC,CAACH,SAAS;AAC9C;AAEO,MAAMM,MAAM,CAAI;EACbC,KAAK,GAA8B,CAAC,CAAC;EACrCC,gBAAgB,GAAGC,MAAM,CAACC,gBAAgB;;EAElD;EACA,IAAIC,IAAIA,CAAA,EAAwC;IAC9C,OAAO,IAAI,CAACJ,KAAK;EACnB;;EAEA;EACA,IAAIK,eAAeA,CAAA,EAAW;IAC5B,OAAO,IAAI,CAACJ,gBAAgB;EAC9B;EAEAK,WAAWA,CACOC,MAAc,EACtBC,MAAsC,EAC9C;IAAA,KAFgBD,MAAc,GAAdA,MAAc;IAAA,KACtBC,MAAsC,GAAtCA,MAAsC;EAC7C;;EAEH;EACQC,UAAUA,CAAA,EAAG;IACnB,MAAMC,QAAQ,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,GAAG,IAAI,CAACL,MAAM;IACzC,IAAI,CAACN,gBAAgB,GAAGC,MAAM,CAACC,gBAAgB;IAC/C,KAAK,MAAM,CAACU,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAAC,IAAI,CAAChB,KAAK,CAAC,EAAE;MACrD,MAAMP,S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AAChB,MAAM,CAACU,EAAE,CAAC;IACrC,IAAI,EAAEM,aAAa,YAAYC,OAAO,CAAC,EAAE;MACvC,OAAO,IAAI,CAACN,GAAG,CAACD,EAAE,EAAEM,aAAa,CAAC;IACpC;IAEA,MAAMhC,OAAO,GAAGD,YAAY,CAC1BiC,aAAa,CAACE,IAAI,CAAEC,IAAI,IAAK,IAAI,CAACR,GAAG,CAACD,EAAE,EAAES,IAAI,CAAC,CAAC,EAChDf,GACF,CAAC;IAED,IAAI,CAACK,QAAQ,CAACC,EAAE,EAAE1B,OAAO,CAAC;IAE1B,OAAOA,OAAO;EAChB;;EAEA;EACAoC,GAAGA,CAACV,EAAU,EAAEI,YAAsB,EAAkB;IACtD,MAAMR,KAAK,GAAG,IAAI,CAACO,QAAQ,CAACH,EAAE,EAAEI,YAAY,CAAC;IAC7C,OAAOzB,KAAK,CAACC,OAAO,CAACgB,KAAK,CAAC,GAAGA,KAAK,CAAC,CAAC,CAAC,GAAGA,KAAK,CAACY,IAAI,CAAE9B,CAAC,IAAKA,CAAC,CAAC,CAAC,CAAC,CAAC;EAClE;AACF;AAACiC,OAAA,CAAA9B,MAAA,GAAAA,MAAA","ignoreList":[]}
1
+ {"version":3,"file":"Cached.js","names":["addTimestamp","promise","timestamp","res","getTimestamp","e","Array","isArray","Cached","pData","pOldestTimestamp","Number","MAX_SAFE_INTEGER","data","oldestTimestamp","constructor","maxage","getter","cleanCache","deadline","Date","now","key","entry","Object","entries","setEntry","id","set","datum","getEntry","forceRefresh","cached","itemOrPromise","Promise","then","item","get","exports"],"sources":["../../src/Cached.ts"],"sourcesContent":["type CachedT<T> = [T, number];\ntype EntryT<T> = CachedT<T> | TimestampedPromise<CachedT<T>>;\ntype TimestampedPromise<T> = Promise<T> & { timestamp: number };\n\n/** Adds timestamp to the promise. */\nfunction addTimestamp<T>(\n promise: Promise<T>,\n timestamp: number,\n): TimestampedPromise<T> {\n const res = promise as TimestampedPromise<T>;\n res.timestamp = timestamp;\n return res;\n}\n\n/** Gets entry timestamp. */\nfunction getTimestamp<T>(e: EntryT<T>): number {\n return Array.isArray(e) ? e[1] : e.timestamp;\n}\n\nexport class Cached<T> {\n private pData: Record<string, EntryT<T>> = {};\n private pOldestTimestamp = Number.MAX_SAFE_INTEGER;\n\n /** For test use only. */\n get data(): Readonly<Record<string, EntryT<T>>> {\n return this.pData;\n }\n\n /** For test use only. */\n get oldestTimestamp(): number {\n return this.pOldestTimestamp;\n }\n\n constructor(\n public readonly maxage: number,\n private getter: (id: string) => Promise<T> | T,\n ) {}\n\n /** Removes stale items from the cache, and updates .oldestTimestamp. */\n private cleanCache() {\n const deadline = Date.now() - this.maxage;\n this.pOldestTimestamp = Number.MAX_SAFE_INTEGER;\n for (const [key, entry] of Object.entries(this.pData)) {\n const timestamp = getTimestamp(entry);\n if (timestamp < deadline) delete this.pData[key];\n else if (timestamp < this.pOldestTimestamp) {\n this.pOldestTimestamp = timestamp;\n }\n }\n }\n\n /**\n * Adds entry to the cache.\n * NOTE: It assumes entry's timestamp is the current moment (for the cache\n * cleaning purposes; if it is not, but it is a past timestamp, nothing bad\n * will happen, just some cleaning operation will be skipped).\n */\n private setEntry(id: string, entry: EntryT<T>) {\n this.pData[id] = entry;\n const timestamp = getTimestamp(entry);\n if (timestamp < this.pOldestTimestamp) this.pOldestTimestamp = timestamp;\n else if (this.pOldestTimestamp < timestamp - this.maxage) this.cleanCache();\n }\n\n /** Adds `datum` to the cache, and removes stale items from the cache. */\n private set(id: string, datum: T): CachedT<T> {\n const res: CachedT<T> = [datum, Date.now()];\n this.setEntry(id, res);\n return res;\n }\n\n /**\n * Retrieves envelope of the specified datum, either read from the cache,\n * or retrieved using the getter provided at construction time.\n */\n private getEntry(id: string, forceRefresh?: boolean): EntryT<T> {\n const now = Date.now();\n\n if (!forceRefresh) {\n const cached = this.pData[id];\n if (cached && getTimestamp(cached) >= now - this.maxage) return cached;\n }\n\n const itemOrPromise = this.getter(id);\n if (!(itemOrPromise instanceof Promise)) {\n return this.set(id, itemOrPromise);\n }\n\n const promise = addTimestamp(\n itemOrPromise.then((item) => this.set(id, item)),\n now,\n );\n\n this.setEntry(id, promise);\n\n return promise;\n }\n\n /** Gets item. */\n get(id: string, forceRefresh?: boolean): Promise<T> | T {\n const entry = this.getEntry(id, forceRefresh);\n return Array.isArray(entry) ? entry[0] : entry.then((e) => e[0]);\n }\n}\n"],"mappings":";;;;;;AAIA;AACA,SAASA,YAAYA,CACnBC,OAAmB,EACnBC,SAAiB,EACM;EACvB,MAAMC,GAAG,GAAGF,OAAgC;EAC5CE,GAAG,CAACD,SAAS,GAAGA,SAAS;EACzB,OAAOC,GAAG;AACZ;;AAEA;AACA,SAASC,YAAYA,CAAIC,CAAY,EAAU;EAC7C,OAAOC,KAAK,CAACC,OAAO,CAACF,CAAC,CAAC,GAAGA,CAAC,CAAC,CAAC,CAAC,GAAGA,CAAC,CAACH,SAAS;AAC9C;AAEO,MAAMM,MAAM,CAAI;EACbC,KAAK,GAA8B,CAAC,CAAC;EACrCC,gBAAgB,GAAGC,MAAM,CAACC,gBAAgB;;EAElD;EACA,IAAIC,IAAIA,CAAA,EAAwC;IAC9C,OAAO,IAAI,CAACJ,KAAK;EACnB;;EAEA;EACA,IAAIK,eAAeA,CAAA,EAAW;IAC5B,OAAO,IAAI,CAACJ,gBAAgB;EAC9B;EAEAK,WAAWA,CACOC,MAAc,EACtBC,MAAsC,EAC9C;IAAA,KAFgBD,MAAc,GAAdA,MAAc;IAAA,KACtBC,MAAsC,GAAtCA,MAAsC;EAC7C;;EAEH;EACQC,UAAUA,CAAA,EAAG;IACnB,MAAMC,QAAQ,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,GAAG,IAAI,CAACL,MAAM;IACzC,IAAI,CAACN,gBAAgB,GAAGC,MAAM,CAACC,gBAAgB;IAC/C,KAAK,MAAM,CAACU,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAAC,IAAI,CAAChB,KAAK,CAAC,EAAE;MAC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AAG,IAAI,CAAChB,MAAM,CAACU,EAAE,CAAC;IACrC,IAAI,EAAEM,aAAa,YAAYC,OAAO,CAAC,EAAE;MACvC,OAAO,IAAI,CAACN,GAAG,CAACD,EAAE,EAAEM,aAAa,CAAC;IACpC;IAEA,MAAMhC,OAAO,GAAGD,YAAY,CAC1BiC,aAAa,CAACE,IAAI,CAAEC,IAAI,IAAK,IAAI,CAACR,GAAG,CAACD,EAAE,EAAES,IAAI,CAAC,CAAC,EAChDf,GACF,CAAC;IAED,IAAI,CAACK,QAAQ,CAACC,EAAE,EAAE1B,OAAO,CAAC;IAE1B,OAAOA,OAAO;EAChB;;EAEA;EACAoC,GAAGA,CAACV,EAAU,EAAEI,YAAsB,EAAkB;IACtD,MAAMR,KAAK,GAAG,IAAI,CAACO,QAAQ,CAACH,EAAE,EAAEI,YAAY,CAAC;IAC7C,OAAOzB,KAAK,CAACC,OAAO,CAACgB,KAAK,CAAC,GAAGA,KAAK,CAAC,CAAC,CAAC,GAAGA,KAAK,CAACY,IAAI,CAAE9B,CAAC,IAAKA,CAAC,CAAC,CAAC,CAAC,CAAC;EAClE;AACF;AAACiC,OAAA,CAAA9B,MAAA,GAAAA,MAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"time.js","names":["_Barrier","_interopRequireDefault","require","SEC_MS","exports","MIN_MS","HOUR_MS","DAY_MS","YEAR_MS","Timer","Barrier","abort","pAbort","timeout","pTimeout","constructor","executor","undefined","init","Error","id","setTimeout","resolve","clearTimeout","then","onFulfilled","onRejected","res","timer","t"],"sources":["../../src/time.ts"],"sourcesContent":["import Barrier, { type Executor } from './Barrier';\n\n// This is not very elegant, but as of now TypeScript does not support type\n// arithmetic, thus we can't have constants assigned like `MIN_MS = 60 * SEC_MS`\n// and have the result type to be 60000 (number literal), it would be just\n// the generic number type.\nexport const SEC_MS = 1000;\nexport const MIN_MS = 60000; // 60 * SEC_MS\nexport const HOUR_MS = 3600000; // 60 * MIN_MS\nexport const DAY_MS = 86400000; // 24 * HOUR_MS\nexport const YEAR_MS = 31536000000; // 365 * DAY_MS\n\n// TODO: Ok, as we have ended up with a Timer class, mostly to achieve a good\n// TypeScript typing for timer() function, it makes sense to expose the class\n// from the library as well, and it should be documented later.\nexport class Timer<T> extends Barrier<void, T> {\n private pAbort: () => void;\n\n private pTimeout?: number;\n\n get abort(): () => void {\n return this.pAbort;\n }\n\n get timeout(): number | undefined {\n return this.pTimeout;\n }\n\n /**\n * Creates a new, non-initialized instance of Timer. Call .init() method\n * to actually initialize and launch the timer.\n *\n * NOTE: Although it might be tempting to accept `timeout` value as\n * a constructor's argument, it won't work well, because Timer is an\n * extension of Promise (via Barrier), and the way Promises works (in\n * particular their .then() method, which internally calls constructor()\n * with special executor) does not play along with initalization depending\n * on custom parameters done in constructor().\n *\n * @param executor\n */\n constructor(executor?: Executor<T>) {\n super(executor);\n this.pAbort = () => undefined;\n }\n\n init(timeout: number): this {\n if (this.pTimeout !== undefined) {\n throw Error('This Timer is initialized already');\n }\n this.pTimeout = timeout;\n if (timeout > 0) {\n const id = setTimeout(() => {\n void super.resolve();\n }, timeout);\n this.pAbort = () => {\n clearTimeout(id);\n };\n } else {\n void super.resolve();\n }\n return this;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Timer type extending that via\n // Barrier. Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n then<TR1, TR2>(\n onFulfilled?: ((value: T) => TR1 | PromiseLike<TR1>) | null,\n onRejected?: ((reason: unknown) => TR2 | PromiseLike<TR2>) | null,\n ): Timer<TR1 | TR2> {\n const res = super.then(onFulfilled, onRejected) as Timer<TR1 | TR2>;\n if (this.timeout !== undefined) void res.init(this.timeout);\n return res;\n }\n}\n\n/**\n * Creates a Promise, which resolves after the given timeout.\n * @param {number} timeout Timeout [ms].\n * @return {Barrier} Resolves after the timeout. It has additional\n * .abort() method attached, which cancels the pending timer resolution\n * (without resolving or rejecting the barrier).\n */\n// TODO: For async functions TS requires the return type to be the global\n// Promise, thus not allowing to return our Timer type extending that via\n// Barrier. Thus, we don't mark this method async for now, disabling the rule,\n// and we should think more about it in future.\n// eslint-disable-next-line @typescript-eslint/promise-function-async\nexport function timer(timeout: number): Timer<void> {\n const t = new Timer<void>();\n return t.init(timeout);\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA;AACA;AACA;AACA;AACO,MAAMC,MAAM,GAAAC,OAAA,CAAAD,MAAA,GAAG,IAAI;AACnB,MAAME,MAAM,GAAAD,OAAA,CAAAC,MAAA,GAAG,KAAK,CAAC,CAAC;AACtB,MAAMC,OAAO,GAAAF,OAAA,CAAAE,OAAA,GAAG,OAAO,CAAC,CAAC;AACzB,MAAMC,MAAM,GAAAH,OAAA,CAAAG,MAAA,GAAG,QAAQ,CAAC,CAAC;AACzB,MAAMC,OAAO,GAAAJ,OAAA,CAAAI,OAAA,GAAG,WAAW,CAAC,CAAC;;AAEpC;AACA;AACA;AACO,MAAMC,KAAK,SAAYC,gBAAO,CAAU;EAK7C,IAAIC,KAAKA,CAAA,EAAe;IACtB,OAAO,IAAI,CAACC,MAAM;EACpB;EAEA,IAAIC,OAAOA,CAAA,EAAuB;IAChC,OAAO,IAAI,CAACC,QAAQ;EACtB;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,QAAsB,EAAE;IAClC,KAAK,CAACA,QAAQ,CAAC;IACf,IAAI,CAACJ,MAAM,GAAG,MAAMK,SAAS;EAC/B;EAEAC,IAAIA,CAACL,OAAe,EAAQ;IAC1B,IAAI,IAAI,CAACC,QAAQ,KAAKG,SAAS,EAAE;MAC/B,MAAME,KAAK,CAAC,mCAAmC,CAAC;IAClD;IACA,IAAI,CAACL,QAAQ,GAAGD,OAAO;IACvB,IAAIA,OAAO,GAAG,CAAC,EAAE;MACf,MAAMO,EAAE,GAAGC,UAAU,CAAC,MAAM;QAC1B,KAAK,KAAK,CAACC,OAAO,CAAC,CAAC;MACtB,CAAC,EAAET,OAAO,CAAC;MACX,IAAI,CAACD,MAAM,GAAG,MAAM;QAClBW,YAAY,CAACH,EAAE,CAAC;MAClB,CAAC;IACH,CAAC,MAAM;MACL,KAAK,KAAK,CAACE,OAAO,CAAC,CAAC;IACtB;IACA,OAAO,IAAI;EACb;;EAEA;EACA;EACA;EACA;EACA;EACAE,IAAIA,CACFC,WAA2D,EAC3DC,UAAiE,EAC/C;IAClB,MAAMC,GAAG,GAAG,KAAK,CAACH,IAAI,CAACC,WAAW,EAAEC,UAAU,CAAqB;IACnE,IAAI,IAAI,CAACb,OAAO,KAAKI,SAAS,EAAE,KAAKU,GAAG,CAACT,IAAI,CAAC,IAAI,CAACL,OAAO,CAAC;IAC3D,OAAOc,GAAG;EACZ;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAAvB,OAAA,CAAAK,KAAA,GAAAA,KAAA;AACO,SAASmB,KAAKA,CAACf,OAAe,EAAe;EAClD,MAAMgB,CAAC,GAAG,IAAIpB,KAAK,CAAO,CAAC;EAC3B,OAAOoB,CAAC,CAACX,IAAI,CAACL,OAAO,CAAC;AACxB","ignoreList":[]}
1
+ {"version":3,"file":"time.js","names":["_Barrier","_interopRequireDefault","require","SEC_MS","exports","MIN_MS","HOUR_MS","DAY_MS","YEAR_MS","Timer","Barrier","abort","pAbort","timeout","pTimeout","constructor","executor","undefined","init","Error","id","setTimeout","resolve","clearTimeout","then","onFulfilled","onRejected","res","timer","t"],"sources":["../../src/time.ts"],"sourcesContent":["import Barrier, { type Executor } from './Barrier';\n\n// This is not very elegant, but as of now TypeScript does not support type\n// arithmetic, thus we can't have constants assigned like `MIN_MS = 60 * SEC_MS`\n// and have the result type to be 60000 (number literal), it would be just\n// the generic number type.\nexport const SEC_MS = 1000;\nexport const MIN_MS = 60000; // 60 * SEC_MS\nexport const HOUR_MS = 3600000; // 60 * MIN_MS\nexport const DAY_MS = 86400000; // 24 * HOUR_MS\nexport const YEAR_MS = 31536000000; // 365 * DAY_MS\n\n// TODO: Ok, as we have ended up with a Timer class, mostly to achieve a good\n// TypeScript typing for timer() function, it makes sense to expose the class\n// from the library as well, and it should be documented later.\nexport class Timer<T> extends Barrier<void, T> {\n private pAbort: () => void;\n\n private pTimeout?: number;\n\n get abort(): () => void {\n return this.pAbort;\n }\n\n get timeout(): number | undefined {\n return this.pTimeout;\n }\n\n /**\n * Creates a new, non-initialized instance of Timer. Call .init() method\n * to actually initialize and launch the timer.\n *\n * NOTE: Although it might be tempting to accept `timeout` value as\n * a constructor's argument, it won't work well, because Timer is an\n * extension of Promise (via Barrier), and the way Promises works (in\n * particular their .then() method, which internally calls constructor()\n * with special executor) does not play along with initalization depending\n * on custom parameters done in constructor().\n *\n * @param executor\n */\n constructor(executor?: Executor<T>) {\n super(executor);\n this.pAbort = () => undefined;\n }\n\n init(timeout: number): this {\n if (this.pTimeout !== undefined) {\n throw Error('This Timer is initialized already');\n }\n this.pTimeout = timeout;\n if (timeout > 0) {\n const id = setTimeout(() => {\n void super.resolve();\n }, timeout);\n this.pAbort = () => {\n clearTimeout(id);\n };\n } else {\n void super.resolve();\n }\n return this;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Timer type extending that via\n // Barrier. Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n then<TR1, TR2>(\n onFulfilled?: ((value: T) => PromiseLike<TR1> | TR1) | null,\n onRejected?: ((reason: unknown) => PromiseLike<TR2> | TR2) | null,\n ): Timer<TR1 | TR2> {\n const res = super.then(onFulfilled, onRejected) as Timer<TR1 | TR2>;\n if (this.timeout !== undefined) void res.init(this.timeout);\n return res;\n }\n}\n\n/**\n * Creates a Promise, which resolves after the given timeout.\n * @param {number} timeout Timeout [ms].\n * @return {Barrier} Resolves after the timeout. It has additional\n * .abort() method attached, which cancels the pending timer resolution\n * (without resolving or rejecting the barrier).\n */\n// TODO: For async functions TS requires the return type to be the global\n// Promise, thus not allowing to return our Timer type extending that via\n// Barrier. Thus, we don't mark this method async for now, disabling the rule,\n// and we should think more about it in future.\n// eslint-disable-next-line @typescript-eslint/promise-function-async\nexport function timer(timeout: number): Timer<void> {\n const t = new Timer<void>();\n return t.init(timeout);\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA;AACA;AACA;AACA;AACO,MAAMC,MAAM,GAAAC,OAAA,CAAAD,MAAA,GAAG,IAAI;AACnB,MAAME,MAAM,GAAAD,OAAA,CAAAC,MAAA,GAAG,KAAK,CAAC,CAAC;AACtB,MAAMC,OAAO,GAAAF,OAAA,CAAAE,OAAA,GAAG,OAAO,CAAC,CAAC;AACzB,MAAMC,MAAM,GAAAH,OAAA,CAAAG,MAAA,GAAG,QAAQ,CAAC,CAAC;AACzB,MAAMC,OAAO,GAAAJ,OAAA,CAAAI,OAAA,GAAG,WAAW,CAAC,CAAC;;AAEpC;AACA;AACA;AACO,MAAMC,KAAK,SAAYC,gBAAO,CAAU;EAK7C,IAAIC,KAAKA,CAAA,EAAe;IACtB,OAAO,IAAI,CAACC,MAAM;EACpB;EAEA,IAAIC,OAAOA,CAAA,EAAuB;IAChC,OAAO,IAAI,CAACC,QAAQ;EACtB;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,QAAsB,EAAE;IAClC,KAAK,CAACA,QAAQ,CAAC;IACf,IAAI,CAACJ,MAAM,GAAG,MAAMK,SAAS;EAC/B;EAEAC,IAAIA,CAACL,OAAe,EAAQ;IAC1B,IAAI,IAAI,CAACC,QAAQ,KAAKG,SAAS,EAAE;MAC/B,MAAME,KAAK,CAAC,mCAAmC,CAAC;IAClD;IACA,IAAI,CAACL,QAAQ,GAAGD,OAAO;IACvB,IAAIA,OAAO,GAAG,CAAC,EAAE;MACf,MAAMO,EAAE,GAAGC,UAAU,CAAC,MAAM;QAC1B,KAAK,KAAK,CAACC,OAAO,CAAC,CAAC;MACtB,CAAC,EAAET,OAAO,CAAC;MACX,IAAI,CAACD,MAAM,GAAG,MAAM;QAClBW,YAAY,CAACH,EAAE,CAAC;MAClB,CAAC;IACH,CAAC,MAAM;MACL,KAAK,KAAK,CAACE,OAAO,CAAC,CAAC;IACtB;IACA,OAAO,IAAI;EACb;;EAEA;EACA;EACA;EACA;EACA;EACAE,IAAIA,CACFC,WAA2D,EAC3DC,UAAiE,EAC/C;IAClB,MAAMC,GAAG,GAAG,KAAK,CAACH,IAAI,CAACC,WAAW,EAAEC,UAAU,CAAqB;IACnE,IAAI,IAAI,CAACb,OAAO,KAAKI,SAAS,EAAE,KAAKU,GAAG,CAACT,IAAI,CAAC,IAAI,CAACL,OAAO,CAAC;IAC3D,OAAOc,GAAG;EACZ;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAAvB,OAAA,CAAAK,KAAA,GAAAA,KAAA;AACO,SAASmB,KAAKA,CAACf,OAAe,EAAe;EAClD,MAAMgB,CAAC,GAAG,IAAIpB,KAAK,CAAO,CAAC;EAC3B,OAAOoB,CAAC,CAACX,IAAI,CAACL,OAAO,CAAC;AACxB","ignoreList":[]}
@@ -12,4 +12,18 @@ exports.assertEmptyObject = assertEmptyObject;
12
12
  function assertEmptyObject(object) {
13
13
  if (Object.keys(object).length) throw Error('The object is not empty');
14
14
  }
15
+
16
+ /**
17
+ * Validates compile-time that the type T extends Base, and returns T.
18
+ *
19
+ * BEWARE: In the case Base has some optional fields missing in T, T still
20
+ * extends Base (as "extends" means T is assignable to Base)! The Implements
21
+ * util below also checks that T has all optional fields defined in Base.
22
+ */
23
+
24
+ /**
25
+ * Validates compile-time that the type T extends (is assignable to) the type
26
+ * Base, and also that it has defined all (if any) optional fields defined in
27
+ * the Base. Returns T if the validation passes.
28
+ */
15
29
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":["assertEmptyObject","object","Object","keys","length","Error"],"sources":["../../src/types.ts"],"sourcesContent":["// Misc TypeScript-specific utilities.\n\n/** The most permissive object key type. */\nexport type ObjectKey = string | number | symbol;\n\n/** Asserts given object is empty, both compile- and run-time. */\nexport function assertEmptyObject(object: Record<ObjectKey, never>): void {\n if (Object.keys(object).length) throw Error('The object is not empty');\n}\n"],"mappings":";;;;;;AAAA;;AAEA;;AAGA;AACO,SAASA,iBAAiBA,CAACC,MAAgC,EAAQ;EACxE,IAAIC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,EAAE,MAAMC,KAAK,CAAC,yBAAyB,CAAC;AACxE","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":["assertEmptyObject","object","Object","keys","length","Error"],"sources":["../../src/types.ts"],"sourcesContent":["// Misc TypeScript-specific utilities.\n\n/** The most permissive object key type. */\nexport type ObjectKey = number | string | symbol;\n\n/** Asserts given object is empty, both compile- and run-time. */\nexport function assertEmptyObject(object: Record<ObjectKey, never>): void {\n if (Object.keys(object).length) throw Error('The object is not empty');\n}\n\n/**\n * Validates compile-time that the type T extends Base, and returns T.\n *\n * BEWARE: In the case Base has some optional fields missing in T, T still\n * extends Base (as \"extends\" means T is assignable to Base)! The Implements\n * util below also checks that T has all optional fields defined in Base.\n */\nexport type Extends<Base, T extends Base> = T;\n\n/**\n * Validates compile-time that the type T extends (is assignable to) the type\n * Base, and also that it has defined all (if any) optional fields defined in\n * the Base. Returns T if the validation passes.\n */\nexport type Implements<\n Base,\n T extends Required<T> extends Required<Base> ? Base : Required<Base>,\n> = T;\n"],"mappings":";;;;;;AAAA;;AAEA;;AAGA;AACO,SAASA,iBAAiBA,CAACC,MAAgC,EAAQ;EACxE,IAAIC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,EAAE,MAAMC,KAAK,CAAC,yBAAyB,CAAC;AACxE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -108,10 +108,10 @@ export default class Barrier extends Promise {
108
108
  then(onFulfilled, onRejected) {
109
109
  const res = super.then(onFulfilled, onRejected);
110
110
  // TODO: Revise later.
111
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
111
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/strict-void-return
112
112
  res.pResolve = this.resolve;
113
113
  // TODO: Revise later.
114
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
114
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/strict-void-return
115
115
  res.pReject = this.reject;
116
116
  return res;
117
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Barrier.js","names":["STATE","Barrier","Promise","pState","PENDING","constructor","executor","resolveRef","rejectRef","resolve","reject","value","RESOLVED","reason","REJECTED","pResolve","pReject","arg","resolved","rejected","settled","catch","onRejected","finally","onFinally","then","onFulfilled","res"],"sources":["../../src/Barrier.ts"],"sourcesContent":["export type Executor<T> = ConstructorParameters<typeof Promise<T>>[0];\n\ntype Resolver<T> = Parameters<Executor<T>>[0];\ntype Rejecter = Parameters<Executor<unknown>>[1];\n\nenum STATE {\n PENDING = 'PENDING',\n REJECTED = 'REJECTED',\n RESOLVED = 'RESOLVED',\n}\n\n/**\n * Barrier is just a Promise which has resolve and reject exposed as instance\n * methods.\n *\n * It has two generic arguments T and TR which correspond to the argument of\n * the .resolve() method, and to the value resolved by the promise (barrier).\n * For a simple barrier TR equals to T, however for barriers created via .then()\n * chain, T corresponds to the argument of the original barrier, and TR to\n * the value resolved by the latest promise in the chain. Consider this:\n *\n * const b = new Barrier<string>();\n * b.resolve('result');\n * const s = await b; // `s` has `string` type, and equals \"result\".\n *\n * const b = (new Barrier<string>()).then((s) => s.length);\n * b.resolve('result'); // Chained barrier exposes .resolve() method of\n * // the first barrier in the chain, which expects\n * // `string` arugment (T), but the chained barrier\n * // resolves to `number` (TR).\n * const n = await b; // `n` has `number` type, and equals 6.\n *\n * Docs: https://dr.pogodin.studio/docs/react-utils/docs/api/classes/Barrier\n */\nexport default class Barrier<T = unknown, TR = T> extends Promise<TR> {\n private pResolve: Resolver<T>;\n\n private pReject: Rejecter;\n\n private pState = STATE.PENDING;\n\n constructor(executor?: Executor<TR>) {\n let resolveRef: Resolver<TR>;\n let rejectRef: Rejecter;\n\n super((resolve, reject) => {\n // Note: Enforcing `void` return type because of the BEWARE note below.\n resolveRef = (value: TR | PromiseLike<TR>): void => {\n resolve(value);\n this.pState = STATE.RESOLVED;\n\n // BEWARE: Don't try to return `this` here, it will easily cause\n // infinite loops in React Native, which are extremely difficult\n // to troubleshoot (I wasn't able to figure out, are they due to\n // internal Promise implementation in RN, or because of some bad\n // patterns in the host code).\n };\n\n // Note: Enforcing `void` return type because of the BEWARE note below.\n rejectRef = (reason?: unknown): void => {\n reject(reason);\n this.pState = STATE.REJECTED;\n };\n\n if (executor) executor(resolveRef, rejectRef);\n });\n\n // NOTE: We assume, the only scenario where TR is not equal T is when\n // the Barrier is constructed by a .then() call on a \"parent\" barrier,\n // and in that scenario .then() itself will replace .p_resolve by another\n // resolver immediately after this constructor returns.\n this.pResolve = resolveRef! as Resolver<T>;\n\n this.pReject = rejectRef!;\n }\n\n get resolve() {\n return (arg: Parameters<Resolver<T>>[0]): this => {\n this.pResolve(arg);\n return this;\n };\n }\n\n get reject() {\n return (arg: Parameters<Rejecter>[0]): this => {\n this.pReject(arg);\n return this;\n };\n }\n\n get resolved(): boolean {\n return this.pState === STATE.RESOLVED;\n }\n\n get rejected(): boolean {\n return this.pState === STATE.REJECTED;\n }\n\n get settled(): boolean {\n return this.pState !== STATE.PENDING;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n catch<TR1>(\n onRejected?: ((reason: unknown) => TR1 | PromiseLike<TR1>) | null,\n ): Barrier<T, TR1> {\n return super.catch(onRejected) as Barrier<T, TR1>;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n finally(onFinally?: (() => void) | null): Barrier<TR> {\n return super.finally(onFinally) as Barrier<TR>;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n then<TR1, TR2>(\n onFulfilled?: ((value: TR) => TR1 | PromiseLike<TR1>) | null,\n onRejected?: ((reason: unknown) => TR2 | PromiseLike<TR2>) | null,\n ): Barrier<T, TR1 | TR2> {\n const res = super.then(onFulfilled, onRejected) as Barrier<T, TR1 | TR2>;\n // TODO: Revise later.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n res.pResolve = this.resolve;\n // TODO: Revise later.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n res.pReject = this.reject;\n return res;\n }\n}\n"],"mappings":"IAKKA,KAAK,0BAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAAA,OAALA,KAAK;AAAA,EAALA,KAAK;AAMV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,OAAO,SAA8BC,OAAO,CAAK;EAK5DC,MAAM,GAAGH,KAAK,CAACI,OAAO;EAE9BC,WAAWA,CAACC,QAAuB,EAAE;IACnC,IAAIC,UAAwB;IAC5B,IAAIC,SAAmB;IAEvB,KAAK,CAAC,CAACC,OAAO,EAAEC,MAAM,K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K,CAACD,OAAO,CAACC,SAAS,CAAC;EACjC;;EAEA;EACA;EACA;EACA;EACA;EACAC,IAAIA,CACFC,WAA4D,EAC5DJ,UAAiE,EAC1C;IACvB,MAAMK,GAAG,GAAG,KAAK,CAACF,IAAI,CAACC,WAAW,EAAEJ,UAAU,CAA0B;IACxE;IACA;IACAK,GAAG,CAACZ,QAAQ,GAAG,IAAI,CAACN,OAAO;IAC3B;IACA;IACAkB,GAAG,CAACX,OAAO,GAAG,IAAI,CAACN,MAAM;IACzB,OAAOiB,GAAG;EACZ;AACF","ignoreList":[]}
1
+ {"version":3,"file":"Barrier.js","names":["STATE","Barrier","Promise","pState","PENDING","constructor","executor","resolveRef","rejectRef","resolve","reject","value","RESOLVED","reason","REJECTED","pResolve","pReject","arg","resolved","rejected","settled","catch","onRejected","finally","onFinally","then","onFulfilled","res"],"sources":["../../src/Barrier.ts"],"sourcesContent":["export type Executor<T> = ConstructorParameters<typeof Promise<T>>[0];\n\ntype Rejecter = Parameters<Executor<unknown>>[1];\ntype Resolver<T> = Parameters<Executor<T>>[0];\n\nenum STATE {\n PENDING = 'PENDING',\n REJECTED = 'REJECTED',\n RESOLVED = 'RESOLVED',\n}\n\n/**\n * Barrier is just a Promise which has resolve and reject exposed as instance\n * methods.\n *\n * It has two generic arguments T and TR which correspond to the argument of\n * the .resolve() method, and to the value resolved by the promise (barrier).\n * For a simple barrier TR equals to T, however for barriers created via .then()\n * chain, T corresponds to the argument of the original barrier, and TR to\n * the value resolved by the latest promise in the chain. Consider this:\n *\n * const b = new Barrier<string>();\n * b.resolve('result');\n * const s = await b; // `s` has `string` type, and equals \"result\".\n *\n * const b = (new Barrier<string>()).then((s) => s.length);\n * b.resolve('result'); // Chained barrier exposes .resolve() method of\n * // the first barrier in the chain, which expects\n * // `string` arugment (T), but the chained barrier\n * // resolves to `number` (TR).\n * const n = await b; // `n` has `number` type, and equals 6.\n *\n * Docs: https://dr.pogodin.studio/docs/react-utils/docs/api/classes/Barrier\n */\nexport default class Barrier<T = unknown, TR = T> extends Promise<TR> {\n private pResolve: Resolver<T>;\n\n private pReject: Rejecter;\n\n private pState = STATE.PENDING;\n\n constructor(executor?: Executor<TR>) {\n let resolveRef: Resolver<TR>;\n let rejectRef: Rejecter;\n\n super((resolve, reject) => {\n // Note: Enforcing `void` return type because of the BEWARE note below.\n resolveRef = (value: PromiseLike<TR> | TR): void => {\n resolve(value);\n this.pState = STATE.RESOLVED;\n\n // BEWARE: Don't try to return `this` here, it will easily cause\n // infinite loops in React Native, which are extremely difficult\n // to troubleshoot (I wasn't able to figure out, are they due to\n // internal Promise implementation in RN, or because of some bad\n // patterns in the host code).\n };\n\n // Note: Enforcing `void` return type because of the BEWARE note below.\n rejectRef = (reason?: unknown): void => {\n reject(reason);\n this.pState = STATE.REJECTED;\n };\n\n if (executor) executor(resolveRef, rejectRef);\n });\n\n // NOTE: We assume, the only scenario where TR is not equal T is when\n // the Barrier is constructed by a .then() call on a \"parent\" barrier,\n // and in that scenario .then() itself will replace .p_resolve by another\n // resolver immediately after this constructor returns.\n this.pResolve = resolveRef! as Resolver<T>;\n\n this.pReject = rejectRef!;\n }\n\n get resolve() {\n return (arg: Parameters<Resolver<T>>[0]): this => {\n this.pResolve(arg);\n return this;\n };\n }\n\n get reject() {\n return (arg: Parameters<Rejecter>[0]): this => {\n this.pReject(arg);\n return this;\n };\n }\n\n get resolved(): boolean {\n return this.pState === STATE.RESOLVED;\n }\n\n get rejected(): boolean {\n return this.pState === STATE.REJECTED;\n }\n\n get settled(): boolean {\n return this.pState !== STATE.PENDING;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n catch<TR1>(\n onRejected?: ((reason: unknown) => PromiseLike<TR1> | TR1) | null,\n ): Barrier<T, TR1> {\n return super.catch(onRejected) as Barrier<T, TR1>;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n finally(onFinally?: (() => void) | null): Barrier<TR> {\n return super.finally(onFinally) as Barrier<TR>;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Barrier type extending it.\n // Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n then<TR1, TR2>(\n onFulfilled?: ((value: TR) => PromiseLike<TR1> | TR1) | null,\n onRejected?: ((reason: unknown) => PromiseLike<TR2> | TR2) | null,\n ): Barrier<T, TR1 | TR2> {\n const res = super.then(onFulfilled, onRejected) as Barrier<T, TR1 | TR2>;\n // TODO: Revise later.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/strict-void-return\n res.pResolve = this.resolve;\n // TODO: Revise later.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/strict-void-return\n res.pReject = this.reject;\n return res;\n }\n}\n"],"mappings":"IAKKA,KAAK,0BAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAALA,KAAK;EAAA,OAALA,KAAK;AAAA,EAALA,KAAK;AAMV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,OAAO,SAA8BC,OAAO,CAAK;EAK5DC,MAAM,GAAGH,KAAK,CAACI,OAAO;EAE9BC,WAAWA,CAACC,QAAuB,EAAE;IACnC,IAAIC,UAAwB;IAC5B,IAAIC,SAAmB;IAEvB,KAAK,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACzB;MACAH,UAAU,GAAII,KAA2B,IAAW;QAClDF,OAAO,CAACE,KAAK,CAAC;QACd,IAAI,CAACR,MAAM,GAAGH,KAAK,CAAC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C;IACvB,MAAMK,GAAG,GAAG,KAAK,CAACF,IAAI,CAACC,WAAW,EAAEJ,UAAU,CAA0B;IACxE;IACA;IACAK,GAAG,CAACZ,QAAQ,GAAG,IAAI,CAACN,OAAO;IAC3B;IACA;IACAkB,GAAG,CAACX,OAAO,GAAG,IAAI,CAACN,MAAM;IACzB,OAAOiB,GAAG;EACZ;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"Cached.js","names":["addTimestamp","promise","timestamp","res","getTimestamp","e","Array","isArray","Cached","pData","pOldestTimestamp","Number","MAX_SAFE_INTEGER","data","oldestTimestamp","constructor","maxage","getter","cleanCache","deadline","Date","now","key","entry","Object","entries","setEntry","id","set","datum","getEntry","forceRefresh","cached","itemOrPromise","Promise","then","item","get"],"sources":["../../src/Cached.ts"],"sourcesContent":["type CachedT<T> = [T, number];\ntype TimestampedPromise<T> = Promise<T> & { timestamp: number };\ntype EntryT<T> = CachedT<T> | TimestampedPromise<CachedT<T>>;\n\n/** Adds timestamp to the promise. */\nfunction addTimestamp<T>(\n promise: Promise<T>,\n timestamp: number,\n): TimestampedPromise<T> {\n const res = promise as TimestampedPromise<T>;\n res.timestamp = timestamp;\n return res;\n}\n\n/** Gets entry timestamp. */\nfunction getTimestamp<T>(e: EntryT<T>): number {\n return Array.isArray(e) ? e[1] : e.timestamp;\n}\n\nexport class Cached<T> {\n private pData: Record<string, EntryT<T>> = {};\n private pOldestTimestamp = Number.MAX_SAFE_INTEGER;\n\n /** For test use only. */\n get data(): Readonly<Record<string, EntryT<T>>> {\n return this.pData;\n }\n\n /** For test use only. */\n get oldestTimestamp(): number {\n return this.pOldestTimestamp;\n }\n\n constructor(\n public readonly maxage: number,\n private getter: (id: string) => T | Promise<T>,\n ) {}\n\n /** Removes stale items from the cache, and updates .oldestTimestamp. */\n private cleanCache() {\n const deadline = Date.now() - this.maxage;\n this.pOldestTimestamp = Number.MAX_SAFE_INTEGER;\n for (const [key, entry] of Object.entries(this.pData)) {\n const timestamp = getTimestamp(entry);\n if (timestamp < deadline) delete this.pData[key];\n else if (timestamp < this.pOldestTimestamp) {\n this.pOldestTimestamp = timestamp;\n }\n }\n }\n\n /**\n * Adds entry to the cache.\n * NOTE: It assumes entry's timestamp is the current moment (for the cache\n * cleaning purposes; if it is not, but it is a past timestamp, nothing bad\n * will happen, just some cleaning operation will be skipped).\n */\n private setEntry(id: string, entry: EntryT<T>) {\n this.pData[id] = entry;\n const timestamp = getTimestamp(entry);\n if (timestamp < this.pOldestTimestamp) this.pOldestTimestamp = timestamp;\n else if (this.pOldestTimestamp < timestamp - this.maxage) this.cleanCache();\n }\n\n /** Adds `datum` to the cache, and removes stale items from the cache. */\n private set(id: string, datum: T): CachedT<T> {\n const res: CachedT<T> = [datum, Date.now()];\n this.setEntry(id, res);\n return res;\n }\n\n /**\n * Retrieves envelope of the specified datum, either read from the cache,\n * or retrieved using the getter provided at construction time.\n */\n private getEntry(id: string, forceRefresh?: boolean): EntryT<T> {\n const now = Date.now();\n\n if (!forceRefresh) {\n const cached = this.pData[id];\n if (cached && getTimestamp(cached) >= now - this.maxage) return cached;\n }\n\n const itemOrPromise = this.getter(id);\n if (!(itemOrPromise instanceof Promise)) {\n return this.set(id, itemOrPromise);\n }\n\n const promise = addTimestamp(\n itemOrPromise.then((item) => this.set(id, item)),\n now,\n );\n\n this.setEntry(id, promise);\n\n return promise;\n }\n\n /** Gets item. */\n get(id: string, forceRefresh?: boolean): T | Promise<T> {\n const entry = this.getEntry(id, forceRefresh);\n return Array.isArray(entry) ? entry[0] : entry.then((e) => e[0]);\n }\n}\n"],"mappings":"AAIA;AACA,SAASA,YAAYA,CACnBC,OAAmB,EACnBC,SAAiB,EACM;EACvB,MAAMC,GAAG,GAAGF,OAAgC;EAC5CE,GAAG,CAACD,SAAS,GAAGA,SAAS;EACzB,OAAOC,GAAG;AACZ;;AAEA;AACA,SAASC,YAAYA,CAAIC,CAAY,EAAU;EAC7C,OAAOC,KAAK,CAACC,OAAO,CAACF,CA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ACO,QAAQ,CAACH,EAAE,EAAEI,YAAY,CAAC;IAC7C,OAAOzB,KAAK,CAACC,OAAO,CAACgB,KAAK,CAAC,GAAGA,KAAK,CAAC,CAAC,CAAC,GAAGA,KAAK,CAACY,IAAI,CAAE9B,CAAC,IAAKA,CAAC,CAAC,CAAC,CAAC,CAAC;EAClE;AACF","ignoreList":[]}
1
+ {"version":3,"file":"Cached.js","names":["addTimestamp","promise","timestamp","res","getTimestamp","e","Array","isArray","Cached","pData","pOldestTimestamp","Number","MAX_SAFE_INTEGER","data","oldestTimestamp","constructor","maxage","getter","cleanCache","deadline","Date","now","key","entry","Object","entries","setEntry","id","set","datum","getEntry","forceRefresh","cached","itemOrPromise","Promise","then","item","get"],"sources":["../../src/Cached.ts"],"sourcesContent":["type CachedT<T> = [T, number];\ntype EntryT<T> = CachedT<T> | TimestampedPromise<CachedT<T>>;\ntype TimestampedPromise<T> = Promise<T> & { timestamp: number };\n\n/** Adds timestamp to the promise. */\nfunction addTimestamp<T>(\n promise: Promise<T>,\n timestamp: number,\n): TimestampedPromise<T> {\n const res = promise as TimestampedPromise<T>;\n res.timestamp = timestamp;\n return res;\n}\n\n/** Gets entry timestamp. */\nfunction getTimestamp<T>(e: EntryT<T>): number {\n return Array.isArray(e) ? e[1] : e.timestamp;\n}\n\nexport class Cached<T> {\n private pData: Record<string, EntryT<T>> = {};\n private pOldestTimestamp = Number.MAX_SAFE_INTEGER;\n\n /** For test use only. */\n get data(): Readonly<Record<string, EntryT<T>>> {\n return this.pData;\n }\n\n /** For test use only. */\n get oldestTimestamp(): number {\n return this.pOldestTimestamp;\n }\n\n constructor(\n public readonly maxage: number,\n private getter: (id: string) => Promise<T> | T,\n ) {}\n\n /** Removes stale items from the cache, and updates .oldestTimestamp. */\n private cleanCache() {\n const deadline = Date.now() - this.maxage;\n this.pOldestTimestamp = Number.MAX_SAFE_INTEGER;\n for (const [key, entry] of Object.entries(this.pData)) {\n const timestamp = getTimestamp(entry);\n if (timestamp < deadline) delete this.pData[key];\n else if (timestamp < this.pOldestTimestamp) {\n this.pOldestTimestamp = timestamp;\n }\n }\n }\n\n /**\n * Adds entry to the cache.\n * NOTE: It assumes entry's timestamp is the current moment (for the cache\n * cleaning purposes; if it is not, but it is a past timestamp, nothing bad\n * will happen, just some cleaning operation will be skipped).\n */\n private setEntry(id: string, entry: EntryT<T>) {\n this.pData[id] = entry;\n const timestamp = getTimestamp(entry);\n if (timestamp < this.pOldestTimestamp) this.pOldestTimestamp = timestamp;\n else if (this.pOldestTimestamp < timestamp - this.maxage) this.cleanCache();\n }\n\n /** Adds `datum` to the cache, and removes stale items from the cache. */\n private set(id: string, datum: T): CachedT<T> {\n const res: CachedT<T> = [datum, Date.now()];\n this.setEntry(id, res);\n return res;\n }\n\n /**\n * Retrieves envelope of the specified datum, either read from the cache,\n * or retrieved using the getter provided at construction time.\n */\n private getEntry(id: string, forceRefresh?: boolean): EntryT<T> {\n const now = Date.now();\n\n if (!forceRefresh) {\n const cached = this.pData[id];\n if (cached && getTimestamp(cached) >= now - this.maxage) return cached;\n }\n\n const itemOrPromise = this.getter(id);\n if (!(itemOrPromise instanceof Promise)) {\n return this.set(id, itemOrPromise);\n }\n\n const promise = addTimestamp(\n itemOrPromise.then((item) => this.set(id, item)),\n now,\n );\n\n this.setEntry(id, promise);\n\n return promise;\n }\n\n /** Gets item. */\n get(id: string, forceRefresh?: boolean): Promise<T> | T {\n const entry = this.getEntry(id, forceRefresh);\n return Array.isArray(entry) ? entry[0] : entry.then((e) => e[0]);\n }\n}\n"],"mappings":"AAIA;AACA,SAASA,YAAYA,CACnBC,OAAmB,EACnBC,SAAiB,EACM;EACvB,MAAMC,GAAG,GAAGF,OAAgC;EAC5CE,GAAG,CAACD,SAAS,GAAGA,SAAS;EACzB,OAAOC,GAAG;AACZ;;AAEA;AACA,SAASC,YAAYA,CAAIC,CAAY,EAAU;EAC7C,OAAOC,KAAK,CAACC,OAAO,CAACF,CAAC,CAAC,GAAGA,CAAC,CAAC,CAA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AY,CAAC;IAC7C,OAAOzB,KAAK,CAACC,OAAO,CAACgB,KAAK,CAAC,GAAGA,KAAK,CAAC,CAAC,CAAC,GAAGA,KAAK,CAACY,IAAI,CAAE9B,CAAC,IAAKA,CAAC,CAAC,CAAC,CAAC,CAAC;EAClE;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"time.js","names":["Barrier","SEC_MS","MIN_MS","HOUR_MS","DAY_MS","YEAR_MS","Timer","abort","pAbort","timeout","pTimeout","constructor","executor","undefined","init","Error","id","setTimeout","resolve","clearTimeout","then","onFulfilled","onRejected","res","timer","t"],"sources":["../../src/time.ts"],"sourcesContent":["import Barrier, { type Executor } from './Barrier';\n\n// This is not very elegant, but as of now TypeScript does not support type\n// arithmetic, thus we can't have constants assigned like `MIN_MS = 60 * SEC_MS`\n// and have the result type to be 60000 (number literal), it would be just\n// the generic number type.\nexport const SEC_MS = 1000;\nexport const MIN_MS = 60000; // 60 * SEC_MS\nexport const HOUR_MS = 3600000; // 60 * MIN_MS\nexport const DAY_MS = 86400000; // 24 * HOUR_MS\nexport const YEAR_MS = 31536000000; // 365 * DAY_MS\n\n// TODO: Ok, as we have ended up with a Timer class, mostly to achieve a good\n// TypeScript typing for timer() function, it makes sense to expose the class\n// from the library as well, and it should be documented later.\nexport class Timer<T> extends Barrier<void, T> {\n private pAbort: () => void;\n\n private pTimeout?: number;\n\n get abort(): () => void {\n return this.pAbort;\n }\n\n get timeout(): number | undefined {\n return this.pTimeout;\n }\n\n /**\n * Creates a new, non-initialized instance of Timer. Call .init() method\n * to actually initialize and launch the timer.\n *\n * NOTE: Although it might be tempting to accept `timeout` value as\n * a constructor's argument, it won't work well, because Timer is an\n * extension of Promise (via Barrier), and the way Promises works (in\n * particular their .then() method, which internally calls constructor()\n * with special executor) does not play along with initalization depending\n * on custom parameters done in constructor().\n *\n * @param executor\n */\n constructor(executor?: Executor<T>) {\n super(executor);\n this.pAbort = () => undefined;\n }\n\n init(timeout: number): this {\n if (this.pTimeout !== undefined) {\n throw Error('This Timer is initialized already');\n }\n this.pTimeout = timeout;\n if (timeout > 0) {\n const id = setTimeout(() => {\n void super.resolve();\n }, timeout);\n this.pAbort = () => {\n clearTimeout(id);\n };\n } else {\n void super.resolve();\n }\n return this;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Timer type extending that via\n // Barrier. Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n then<TR1, TR2>(\n onFulfilled?: ((value: T) => TR1 | PromiseLike<TR1>) | null,\n onRejected?: ((reason: unknown) => TR2 | PromiseLike<TR2>) | null,\n ): Timer<TR1 | TR2> {\n const res = super.then(onFulfilled, onRejected) as Timer<TR1 | TR2>;\n if (this.timeout !== undefined) void res.init(this.timeout);\n return res;\n }\n}\n\n/**\n * Creates a Promise, which resolves after the given timeout.\n * @param {number} timeout Timeout [ms].\n * @return {Barrier} Resolves after the timeout. It has additional\n * .abort() method attached, which cancels the pending timer resolution\n * (without resolving or rejecting the barrier).\n */\n// TODO: For async functions TS requires the return type to be the global\n// Promise, thus not allowing to return our Timer type extending that via\n// Barrier. Thus, we don't mark this method async for now, disabling the rule,\n// and we should think more about it in future.\n// eslint-disable-next-line @typescript-eslint/promise-function-async\nexport function timer(timeout: number): Timer<void> {\n const t = new Timer<void>();\n return t.init(timeout);\n}\n"],"mappings":"OAAOA,OAAO,sBAEd;AACA;AACA;AACA;AACA,OAAO,MAAMC,MAAM,GAAG,IAAI;AAC1B,OAAO,MAAMC,MAAM,GAAG,KAAK,CAAC,CAAC;AAC7B,OAAO,MAAMC,OAAO,GAAG,OAAO,CAAC,CAAC;AAChC,OAAO,MAAMC,MAAM,GAAG,QAAQ,CAAC,CAAC;AAChC,OAAO,MAAMC,OAAO,GAAG,WAAW,CAAC,CAAC;;AAEpC;AACA;AACA;AACA,OAAO,MAAMC,KAAK,SAAYN,OAAO,CAAU;EAK7C,IAAIO,KAAKA,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,OAAOmB,CAAC,CAACX,IAAI,CAACL,OAAO,CAAC;AACxB","ignoreList":[]}
1
+ {"version":3,"file":"time.js","names":["Barrier","SEC_MS","MIN_MS","HOUR_MS","DAY_MS","YEAR_MS","Timer","abort","pAbort","timeout","pTimeout","constructor","executor","undefined","init","Error","id","setTimeout","resolve","clearTimeout","then","onFulfilled","onRejected","res","timer","t"],"sources":["../../src/time.ts"],"sourcesContent":["import Barrier, { type Executor } from './Barrier';\n\n// This is not very elegant, but as of now TypeScript does not support type\n// arithmetic, thus we can't have constants assigned like `MIN_MS = 60 * SEC_MS`\n// and have the result type to be 60000 (number literal), it would be just\n// the generic number type.\nexport const SEC_MS = 1000;\nexport const MIN_MS = 60000; // 60 * SEC_MS\nexport const HOUR_MS = 3600000; // 60 * MIN_MS\nexport const DAY_MS = 86400000; // 24 * HOUR_MS\nexport const YEAR_MS = 31536000000; // 365 * DAY_MS\n\n// TODO: Ok, as we have ended up with a Timer class, mostly to achieve a good\n// TypeScript typing for timer() function, it makes sense to expose the class\n// from the library as well, and it should be documented later.\nexport class Timer<T> extends Barrier<void, T> {\n private pAbort: () => void;\n\n private pTimeout?: number;\n\n get abort(): () => void {\n return this.pAbort;\n }\n\n get timeout(): number | undefined {\n return this.pTimeout;\n }\n\n /**\n * Creates a new, non-initialized instance of Timer. Call .init() method\n * to actually initialize and launch the timer.\n *\n * NOTE: Although it might be tempting to accept `timeout` value as\n * a constructor's argument, it won't work well, because Timer is an\n * extension of Promise (via Barrier), and the way Promises works (in\n * particular their .then() method, which internally calls constructor()\n * with special executor) does not play along with initalization depending\n * on custom parameters done in constructor().\n *\n * @param executor\n */\n constructor(executor?: Executor<T>) {\n super(executor);\n this.pAbort = () => undefined;\n }\n\n init(timeout: number): this {\n if (this.pTimeout !== undefined) {\n throw Error('This Timer is initialized already');\n }\n this.pTimeout = timeout;\n if (timeout > 0) {\n const id = setTimeout(() => {\n void super.resolve();\n }, timeout);\n this.pAbort = () => {\n clearTimeout(id);\n };\n } else {\n void super.resolve();\n }\n return this;\n }\n\n // TODO: For async functions TS requires the return type to be the global\n // Promise, thus not allowing to return our Timer type extending that via\n // Barrier. Thus, we don't mark this method async for now, disabling the rule,\n // and we should think more about it in future.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n then<TR1, TR2>(\n onFulfilled?: ((value: T) => PromiseLike<TR1> | TR1) | null,\n onRejected?: ((reason: unknown) => PromiseLike<TR2> | TR2) | null,\n ): Timer<TR1 | TR2> {\n const res = super.then(onFulfilled, onRejected) as Timer<TR1 | TR2>;\n if (this.timeout !== undefined) void res.init(this.timeout);\n return res;\n }\n}\n\n/**\n * Creates a Promise, which resolves after the given timeout.\n * @param {number} timeout Timeout [ms].\n * @return {Barrier} Resolves after the timeout. It has additional\n * .abort() method attached, which cancels the pending timer resolution\n * (without resolving or rejecting the barrier).\n */\n// TODO: For async functions TS requires the return type to be the global\n// Promise, thus not allowing to return our Timer type extending that via\n// Barrier. Thus, we don't mark this method async for now, disabling the rule,\n// and we should think more about it in future.\n// eslint-disable-next-line @typescript-eslint/promise-function-async\nexport function timer(timeout: number): Timer<void> {\n const t = new Timer<void>();\n return t.init(timeout);\n}\n"],"mappings":"OAAOA,OAAO,sBAEd;AACA;AACA;AACA;AACA,OAAO,MAAMC,MAAM,GAAG,IAAI;AAC1B,OAAO,MAAMC,MAAM,GAAG,KAAK,CAAC,CAAC;AAC7B,OAAO,MAAMC,OAAO,GAAG,OAAO,CAAC,CAAC;AAChC,OAAO,MAAMC,MAAM,GAAG,QAAQ,CAAC,CAAC;AAChC,OAAO,MAAMC,OAAO,GAAG,WAAW,CAAC,CAAC;;AAEpC;AACA;AACA;AACA,OAAO,MAAMC,KAAK,SAAYN,OAAO,CAAU;EAK7C,IAAIO,KAAKA,CAAA,EAAe;IACtB,OAAO,IAAI,CAACC,MAAM;EACpB;EAEA,IAAIC,OAAOA,CAAA,EAAuB;IAChC,OAAO,IAAI,CAACC,QAAQ;EACtB;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,QAAsB,EAAE;IAClC,KAAK,CAACA,QAAQ,CAAC;IACf,IAAI,CAACJ,MAAM,GAAG,MAAMK,SAAS;EAC/B;EAEAC,IAAIA,CAACL,OAAe,EAAQ;IAC1B,IAAI,IAAI,CAACC,QAAQ,KAAKG,SAAS,EAAE;MAC/B,MAAME,KAAK,CAAC,mCAAmC,CAAC;IAClD;IACA,IAAI,CAACL,QAAQ,GAAGD,OAAO;IACvB,IAAIA,OAAO,GAAG,CAAC,EAAE;MACf,MAAMO,EAAE,GAAGC,UAAU,CAAC,MAAM;QAC1B,KAAK,KAAK,CAACC,OAAO,CAAC,CAAC;MACtB,CAAC,EAAET,OAAO,CAAC;MACX,IAAI,CAACD,MAAM,GAAG,MAAM;QAClBW,YAAY,CAACH,EAAE,CAAC;MAClB,CAAC;IACH,CAAC,MAAM;MACL,KAAK,KAAK,CAACE,OAAO,CAAC,CAAC;IACtB;IACA,OAAO,IAAI;EACb;;EAEA;EACA;EACA;EACA;EACA;EACAE,IAAIA,CACFC,WAA2D,EAC3DC,UAAiE,EAC/C;IAClB,MAAMC,GAAG,GAAG,KAAK,CAACH,IAAI,CAACC,WAAW,EAAEC,UAAU,CAAqB;IACnE,IAAI,IAAI,CAACb,OAAO,KAAKI,SAAS,EAAE,KAAKU,GAAG,CAACT,IAAI,CAAC,IAAI,CAACL,OAAO,CAAC;IAC3D,OAAOc,GAAG;EACZ;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,KAAKA,CAACf,OAAe,EAAe;EAClD,MAAMgB,CAAC,GAAG,IAAInB,KAAK,CAAO,CAAC;EAC3B,OAAOmB,CAAC,CAACX,IAAI,CAACL,OAAO,CAAC;AACxB","ignoreList":[]}
@@ -6,4 +6,18 @@
6
6
  export function assertEmptyObject(object) {
7
7
  if (Object.keys(object).length) throw Error('The object is not empty');
8
8
  }
9
+
10
+ /**
11
+ * Validates compile-time that the type T extends Base, and returns T.
12
+ *
13
+ * BEWARE: In the case Base has some optional fields missing in T, T still
14
+ * extends Base (as "extends" means T is assignable to Base)! The Implements
15
+ * util below also checks that T has all optional fields defined in Base.
16
+ */
17
+
18
+ /**
19
+ * Validates compile-time that the type T extends (is assignable to) the type
20
+ * Base, and also that it has defined all (if any) optional fields defined in
21
+ * the Base. Returns T if the validation passes.
22
+ */
9
23
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":["assertEmptyObject","object","Object","keys","length","Error"],"sources":["../../src/types.ts"],"sourcesContent":["// Misc TypeScript-specific utilities.\n\n/** The most permissive object key type. */\nexport type ObjectKey = string | number | symbol;\n\n/** Asserts given object is empty, both compile- and run-time. */\nexport function assertEmptyObject(object: Record<ObjectKey, never>): void {\n if (Object.keys(object).length) throw Error('The object is not empty');\n}\n"],"mappings":"AAAA;;AAEA;;AAGA;AACA,OAAO,SAASA,iBAAiBA,CAACC,MAAgC,EAAQ;EACxE,IAAIC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,EAAE,MAAMC,KAAK,CAAC,yBAAyB,CAAC;AACxE","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":["assertEmptyObject","object","Object","keys","length","Error"],"sources":["../../src/types.ts"],"sourcesContent":["// Misc TypeScript-specific utilities.\n\n/** The most permissive object key type. */\nexport type ObjectKey = number | string | symbol;\n\n/** Asserts given object is empty, both compile- and run-time. */\nexport function assertEmptyObject(object: Record<ObjectKey, never>): void {\n if (Object.keys(object).length) throw Error('The object is not empty');\n}\n\n/**\n * Validates compile-time that the type T extends Base, and returns T.\n *\n * BEWARE: In the case Base has some optional fields missing in T, T still\n * extends Base (as \"extends\" means T is assignable to Base)! The Implements\n * util below also checks that T has all optional fields defined in Base.\n */\nexport type Extends<Base, T extends Base> = T;\n\n/**\n * Validates compile-time that the type T extends (is assignable to) the type\n * Base, and also that it has defined all (if any) optional fields defined in\n * the Base. Returns T if the validation passes.\n */\nexport type Implements<\n Base,\n T extends Required<T> extends Required<Base> ? Base : Required<Base>,\n> = T;\n"],"mappings":"AAAA;;AAEA;;AAGA;AACA,OAAO,SAASA,iBAAiBA,CAACC,MAAgC,EAAQ;EACxE,IAAIC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,EAAE,MAAMC,KAAK,CAAC,yBAAyB,CAAC;AACxE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  export type Executor<T> = ConstructorParameters<typeof Promise<T>>[0];
2
- type Resolver<T> = Parameters<Executor<T>>[0];
3
2
  type Rejecter = Parameters<Executor<unknown>>[1];
3
+ type Resolver<T> = Parameters<Executor<T>>[0];
4
4
  /**
5
5
  * Barrier is just a Promise which has resolve and reject exposed as instance
6
6
  * methods.
@@ -34,8 +34,8 @@ export default class Barrier<T = unknown, TR = T> extends Promise<TR> {
34
34
  get resolved(): boolean;
35
35
  get rejected(): boolean;
36
36
  get settled(): boolean;
37
- catch<TR1>(onRejected?: ((reason: unknown) => TR1 | PromiseLike<TR1>) | null): Barrier<T, TR1>;
37
+ catch<TR1>(onRejected?: ((reason: unknown) => PromiseLike<TR1> | TR1) | null): Barrier<T, TR1>;
38
38
  finally(onFinally?: (() => void) | null): Barrier<TR>;
39
- then<TR1, TR2>(onFulfilled?: ((value: TR) => TR1 | PromiseLike<TR1>) | null, onRejected?: ((reason: unknown) => TR2 | PromiseLike<TR2>) | null): Barrier<T, TR1 | TR2>;
39
+ then<TR1, TR2>(onFulfilled?: ((value: TR) => PromiseLike<TR1> | TR1) | null, onRejected?: ((reason: unknown) => PromiseLike<TR2> | TR2) | null): Barrier<T, TR1 | TR2>;
40
40
  }
41
41
  export {};
@@ -1,8 +1,8 @@
1
1
  type CachedT<T> = [T, number];
2
+ type EntryT<T> = CachedT<T> | TimestampedPromise<CachedT<T>>;
2
3
  type TimestampedPromise<T> = Promise<T> & {
3
4
  timestamp: number;
4
5
  };
5
- type EntryT<T> = CachedT<T> | TimestampedPromise<CachedT<T>>;
6
6
  export declare class Cached<T> {
7
7
  readonly maxage: number;
8
8
  private getter;
@@ -12,7 +12,7 @@ export declare class Cached<T> {
12
12
  get data(): Readonly<Record<string, EntryT<T>>>;
13
13
  /** For test use only. */
14
14
  get oldestTimestamp(): number;
15
- constructor(maxage: number, getter: (id: string) => T | Promise<T>);
15
+ constructor(maxage: number, getter: (id: string) => Promise<T> | T);
16
16
  /** Removes stale items from the cache, and updates .oldestTimestamp. */
17
17
  private cleanCache;
18
18
  /**
@@ -30,6 +30,6 @@ export declare class Cached<T> {
30
30
  */
31
31
  private getEntry;
32
32
  /** Gets item. */
33
- get(id: string, forceRefresh?: boolean): T | Promise<T>;
33
+ get(id: string, forceRefresh?: boolean): Promise<T> | T;
34
34
  }
35
35
  export {};
@@ -24,7 +24,7 @@ export declare class Timer<T> extends Barrier<void, T> {
24
24
  */
25
25
  constructor(executor?: Executor<T>);
26
26
  init(timeout: number): this;
27
- then<TR1, TR2>(onFulfilled?: ((value: T) => TR1 | PromiseLike<TR1>) | null, onRejected?: ((reason: unknown) => TR2 | PromiseLike<TR2>) | null): Timer<TR1 | TR2>;
27
+ then<TR1, TR2>(onFulfilled?: ((value: T) => PromiseLike<TR1> | TR1) | null, onRejected?: ((reason: unknown) => PromiseLike<TR2> | TR2) | null): Timer<TR1 | TR2>;
28
28
  }
29
29
  /**
30
30
  * Creates a Promise, which resolves after the given timeout.
@@ -1,4 +1,18 @@
1
1
  /** The most permissive object key type. */
2
- export type ObjectKey = string | number | symbol;
2
+ export type ObjectKey = number | string | symbol;
3
3
  /** Asserts given object is empty, both compile- and run-time. */
4
4
  export declare function assertEmptyObject(object: Record<ObjectKey, never>): void;
5
+ /**
6
+ * Validates compile-time that the type T extends Base, and returns T.
7
+ *
8
+ * BEWARE: In the case Base has some optional fields missing in T, T still
9
+ * extends Base (as "extends" means T is assignable to Base)! The Implements
10
+ * util below also checks that T has all optional fields defined in Base.
11
+ */
12
+ export type Extends<Base, T extends Base> = T;
13
+ /**
14
+ * Validates compile-time that the type T extends (is assignable to) the type
15
+ * Base, and also that it has defined all (if any) optional fields defined in
16
+ * the Base. Returns T if the validation passes.
17
+ */
18
+ export type Implements<Base, T extends Required<T> extends Required<Base> ? Base : Required<Base>> = T;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@dr.pogodin/js-utils",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Collection of JavaScript (TypeScript) utilities.",
5
5
  "main": "./build/module/index.js",
6
6
  "module": "./build/module/index.js",
7
7
  "types": "./build/types/index.d.ts",
8
8
  "exports": {
9
- "require": "./build/common/index.js",
10
9
  "types": "./build/types/index.d.ts",
10
+ "require": "./build/common/index.js",
11
11
  "default": "./build/module/index.js"
12
12
  },
13
13
  "scripts": {
@@ -18,9 +18,9 @@
18
18
  "jest": "npm run jest:types && npm run jest:logic",
19
19
  "jest:logic": "jest --config jest.config.js --no-cache",
20
20
  "jest:types": "tstyche",
21
- "lint": "eslint",
21
+ "lint": "eslint --cache",
22
22
  "test": "npm run lint && npm run typecheck && npm run jest",
23
- "typecheck": "tsc && tsc --project __tests__/tsconfig.json"
23
+ "typecheck": "tsc"
24
24
  },
25
25
  "repository": {
26
26
  "type": "git",
@@ -38,23 +38,23 @@
38
38
  },
39
39
  "homepage": "https://github.com/birdofpreyru/js-utils#readme",
40
40
  "devDependencies": {
41
- "@babel/cli": "^7.28.3",
42
- "@babel/core": "^7.28.5",
43
- "@babel/plugin-transform-runtime": "^7.28.5",
44
- "@babel/preset-env": "^7.28.5",
41
+ "@babel/cli": "^7.28.6",
42
+ "@babel/core": "^7.29.0",
43
+ "@babel/plugin-transform-runtime": "^7.29.0",
44
+ "@babel/preset-env": "^7.29.0",
45
45
  "@babel/preset-typescript": "^7.28.5",
46
- "@dr.pogodin/eslint-configs": "^0.1.1",
47
- "@tsconfig/recommended": "^1.0.10",
46
+ "@dr.pogodin/eslint-configs": "^0.2.7",
47
+ "@tsconfig/recommended": "^1.0.13",
48
48
  "@types/jest": "^30.0.0",
49
49
  "babel-jest": "^30.2.0",
50
50
  "babel-plugin-add-import-extension": "^1.6.0",
51
51
  "jest": "^30.2.0",
52
52
  "mockdate": "^3.0.5",
53
- "rimraf": "^6.0.1",
54
- "tstyche": "^5.0.0",
53
+ "rimraf": "^6.1.3",
54
+ "tstyche": "^6.2.0",
55
55
  "typescript": "^5.9.3"
56
56
  },
57
57
  "dependencies": {
58
- "@babel/runtime": "^7.28.4"
58
+ "@babel/runtime": "^7.28.6"
59
59
  }
60
60
  }
package/tsconfig.json CHANGED
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "extends": "@tsconfig/recommended",
3
- "include": ["src"],
4
3
  "compilerOptions": {
5
4
  "module": "Preserve",
6
5
  "noEmit": true,