@powfix/core-js 0.24.1 → 0.24.3

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.
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+ function _class_call_check(instance, Constructor) {
3
+ if (!(instance instanceof Constructor)) {
4
+ throw new TypeError("Cannot call a class as a function");
5
+ }
6
+ }
7
+ function _defineProperties(target, props) {
8
+ for(var i = 0; i < props.length; i++){
9
+ var descriptor = props[i];
10
+ descriptor.enumerable = descriptor.enumerable || false;
11
+ descriptor.configurable = true;
12
+ if ("value" in descriptor) descriptor.writable = true;
13
+ Object.defineProperty(target, descriptor.key, descriptor);
14
+ }
15
+ }
16
+ function _create_class(Constructor, protoProps, staticProps) {
17
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
18
+ if (staticProps) _defineProperties(Constructor, staticProps);
19
+ return Constructor;
20
+ }
21
+ var chunkJE77HYXB_cjs = require('../../chunk-JE77HYXB.cjs');
22
+ var _tasks;
23
+ var DedupedTaskManager = /*#__PURE__*/ function() {
24
+ function DedupedTaskManager() {
25
+ _class_call_check(this, DedupedTaskManager);
26
+ chunkJE77HYXB_cjs.__privateAdd(this, _tasks, /* @__PURE__ */ new Map());
27
+ }
28
+ _create_class(DedupedTaskManager, [
29
+ {
30
+ key: "run",
31
+ value: function run(key, factory, options) {
32
+ var _this = this;
33
+ if (chunkJE77HYXB_cjs.__privateGet(this, _tasks).has(key)) {
34
+ var task2 = chunkJE77HYXB_cjs.__privateGet(this, _tasks).get(key);
35
+ if (task2 != null) {
36
+ return task2;
37
+ }
38
+ }
39
+ var task = factory().finally(function() {
40
+ var ttl = options === null || options === void 0 ? void 0 : options.ttl;
41
+ if (ttl) {
42
+ setTimeout(function() {
43
+ chunkJE77HYXB_cjs.__privateGet(_this, _tasks).delete(key);
44
+ }, ttl);
45
+ } else {
46
+ chunkJE77HYXB_cjs.__privateGet(_this, _tasks).delete(key);
47
+ }
48
+ });
49
+ chunkJE77HYXB_cjs.__privateGet(this, _tasks).set(key, task);
50
+ return task;
51
+ }
52
+ },
53
+ {
54
+ key: "tasks",
55
+ get: function get() {
56
+ return chunkJE77HYXB_cjs.__privateGet(this, _tasks);
57
+ }
58
+ }
59
+ ]);
60
+ return DedupedTaskManager;
61
+ }();
62
+ _tasks = new WeakMap();
63
+ exports.DedupedTaskManager = DedupedTaskManager;
@@ -0,0 +1,6 @@
1
+ import type { DedupedTaskManagerRunOptions as RunOptions, DedupedTaskManagerTaskKey as TaskKey } from "./DedupedTaskManager.types.js";
2
+ export declare class DedupedTaskManager {
3
+ #private;
4
+ run<T>(key: TaskKey, factory: () => Promise<T>, options?: RunOptions): Promise<T>;
5
+ get tasks(): Map<TaskKey, Promise<any>>;
6
+ }
@@ -0,0 +1,63 @@
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
13
+ }
14
+ }
15
+ function _create_class(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
19
+ }
20
+ import { __privateAdd, __privateGet } from '../../chunk-AQ5VUG5P.js';
21
+ var _tasks;
22
+ var DedupedTaskManager = /*#__PURE__*/ function() {
23
+ "use strict";
24
+ function DedupedTaskManager() {
25
+ _class_call_check(this, DedupedTaskManager);
26
+ __privateAdd(this, _tasks, /* @__PURE__ */ new Map());
27
+ }
28
+ _create_class(DedupedTaskManager, [
29
+ {
30
+ key: "run",
31
+ value: function run(key, factory, options) {
32
+ var _this = this;
33
+ if (__privateGet(this, _tasks).has(key)) {
34
+ var task2 = __privateGet(this, _tasks).get(key);
35
+ if (task2 != null) {
36
+ return task2;
37
+ }
38
+ }
39
+ var task = factory().finally(function() {
40
+ var ttl = options === null || options === void 0 ? void 0 : options.ttl;
41
+ if (ttl) {
42
+ setTimeout(function() {
43
+ __privateGet(_this, _tasks).delete(key);
44
+ }, ttl);
45
+ } else {
46
+ __privateGet(_this, _tasks).delete(key);
47
+ }
48
+ });
49
+ __privateGet(this, _tasks).set(key, task);
50
+ return task;
51
+ }
52
+ },
53
+ {
54
+ key: "tasks",
55
+ get: function get() {
56
+ return __privateGet(this, _tasks);
57
+ }
58
+ }
59
+ ]);
60
+ return DedupedTaskManager;
61
+ }();
62
+ _tasks = new WeakMap();
63
+ export { DedupedTaskManager };
@@ -0,0 +1 @@
1
+ 'use strict';
@@ -0,0 +1,4 @@
1
+ export type DedupedTaskManagerTaskKey = number | string | symbol;
2
+ export type DedupedTaskManagerRunOptions = {
3
+ ttl?: number;
4
+ };
@@ -1,8 +1,8 @@
1
- import type { WatchablePromiseStatus } from "./WatchablePromise.types.js";
1
+ import type { PromiseExecutor, WatchablePromiseStatus } from "./WatchablePromise.types.js";
2
2
  export declare class WatchablePromise<T, E = Error> extends Promise<T> {
3
3
  #private;
4
4
  static from<P extends typeof WatchablePromise, T>(this: P, promise: Promise<T>): InstanceType<P>;
5
- constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void);
5
+ constructor(executor: PromiseExecutor<T>);
6
6
  get settled(): boolean;
7
7
  get status(): WatchablePromiseStatus;
8
8
  get result(): T | PromiseLike<T> | E | undefined;
@@ -1 +1,2 @@
1
+ export type PromiseExecutor<T> = (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void;
1
2
  export type WatchablePromiseStatus = 'pending' | 'fulfilled' | 'rejected';
@@ -1,5 +1,14 @@
1
1
  'use strict';
2
+ var DedupedTaskManager = require('./DedupedTaskManager');
2
3
  var WatchablePromise = require('./WatchablePromise');
4
+ Object.keys(DedupedTaskManager).forEach(function(k) {
5
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: function get() {
8
+ return DedupedTaskManager[k];
9
+ }
10
+ });
11
+ });
3
12
  Object.keys(WatchablePromise).forEach(function(k) {
4
13
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
5
14
  enumerable: true,
@@ -1,2 +1,4 @@
1
+ export * from "./DedupedTaskManager.js";
2
+ export type * from "./DedupedTaskManager.types.js";
1
3
  export * from "./WatchablePromise.js";
2
4
  export type * from "./WatchablePromise.types.js";
@@ -1 +1,2 @@
1
+ export * from './DedupedTaskManager.js';
1
2
  export * from './WatchablePromise.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powfix/core-js",
3
- "version": "0.24.1",
3
+ "version": "0.24.3",
4
4
  "description": "core package",
5
5
  "author": "Kwon Kyung-Min <powfix@gmail.com>",
6
6
  "private": false,