@tstdl/base 0.90.60 → 0.90.61

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/function/log.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { Logger } from '../logger/logger.js';
2
2
  export type WrapLogOptions = {
3
3
  fnName?: string;
4
+ logResult?: boolean;
4
5
  logger?: Logger;
5
6
  trace?: boolean;
6
7
  };
7
- export declare function wrapLog(fn: Function, { fnName, logger, trace }?: WrapLogOptions): Function;
8
+ export declare function wrapLog(fn: Function, { fnName, logResult, logger, trace }?: WrapLogOptions): Function;
package/function/log.js CHANGED
@@ -1,23 +1,28 @@
1
1
  /* eslint-disable @typescript-eslint/ban-types */
2
2
  import { isArray, isPrimitive, isString } from '../utils/type-guards.js';
3
3
  import { typeOf } from '../utils/type-of.js';
4
- export function wrapLog(fn, { fnName = fn.name, logger, trace = false } = {}) {
4
+ export function wrapLog(fn, { fnName = fn.name, logResult = true, logger, trace = false } = {}) {
5
5
  const log = logger?.trace.bind(logger) ?? console.log.bind(console); // eslint-disable-line no-console
6
6
  const wrapped = {
7
7
  [fnName](...args) {
8
- const argString = args.map((arg) => stringifyArg(arg)).join(', ');
8
+ const argString = args.map((arg) => stringifyValue(arg)).join(', ');
9
9
  log(`[call: ${fnName}(${argString})]`);
10
10
  if (trace) {
11
11
  console.trace();
12
12
  }
13
- return Reflect.apply(fn, this, args);
13
+ const result = Reflect.apply(fn, this, args);
14
+ if (logResult) {
15
+ const resultString = stringifyValue(result);
16
+ log(`[return: ${fnName} => ${resultString}]`);
17
+ }
18
+ return result;
14
19
  }
15
20
  };
16
21
  return wrapped[fnName];
17
22
  }
18
- function stringifyArg(arg, depth = 1) {
23
+ function stringifyValue(arg, depth = 1) {
19
24
  if (isArray(arg) && (depth > 0)) {
20
- const argString = arg.map((innerArg) => stringifyArg(innerArg, depth - 1)).join(', ');
25
+ const argString = arg.map((innerArg) => stringifyValue(innerArg, depth - 1)).join(', ');
21
26
  return `[${argString}]`;
22
27
  }
23
28
  return isPrimitive(arg) ? isString(arg) ? `"${arg}"` : String(arg) : typeOf(arg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.90.60",
3
+ "version": "0.90.61",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -109,7 +109,7 @@
109
109
  "luxon": "^3.4",
110
110
  "reflect-metadata": "^0.2",
111
111
  "rxjs": "^7.8",
112
- "type-fest": "4.12"
112
+ "type-fest": "4.14"
113
113
  },
114
114
  "devDependencies": {
115
115
  "@mxssfd/typedoc-theme": "1.1",
@@ -130,7 +130,7 @@
130
130
  "typedoc": "0.25",
131
131
  "typedoc-plugin-missing-exports": "2.2",
132
132
  "typescript": "5.4",
133
- "typescript-eslint": "7.2"
133
+ "typescript-eslint": "7.3"
134
134
  },
135
135
  "peerDependencies": {
136
136
  "@elastic/elasticsearch": "^8.12",
@@ -148,9 +148,9 @@
148
148
  "mongodb": "^6.5",
149
149
  "nodemailer": "^6.9",
150
150
  "playwright": "^1.42",
151
- "preact": "^10.19",
151
+ "preact": "^10.20",
152
152
  "preact-render-to-string": "^6.4",
153
- "undici": "^6.9",
153
+ "undici": "^6.10",
154
154
  "urlpattern-polyfill": "^10.0"
155
155
  },
156
156
  "peerDependenciesMeta": {
@@ -1,2 +1,2 @@
1
- import type { Signal } from './api.js';
1
+ import { type Signal } from './api.js';
2
2
  export declare function defer<T>(signalFactory: () => Signal<T>): Signal<T>;
@@ -21,19 +21,14 @@ export declare abstract class EffectScheduler {
21
21
  * It is an error to attempt to execute any effects synchronously during a scheduling operation.
22
22
  */
23
23
  abstract scheduleEffect(e: SchedulableEffect): void;
24
- }
25
- /**
26
- * Interface to an `EffectScheduler` capable of running scheduled effects synchronously.
27
- */
28
- export interface FlushableEffectRunner {
29
24
  /**
30
25
  * Run any scheduled effects.
31
26
  */
32
- flush(): void;
27
+ abstract flush(): void;
33
28
  }
34
- export declare class TstdlEffectScheduler implements EffectScheduler, FlushableEffectRunner {
29
+ export declare class TstdlEffectScheduler implements EffectScheduler {
35
30
  private readonly queue;
36
- private pendingFlush;
31
+ private hasPendingFlush;
37
32
  scheduleEffect(effect: SchedulableEffect): void;
38
33
  flush(): void;
39
34
  }
@@ -15,13 +15,16 @@ export class EffectScheduler {
15
15
  }
16
16
  export class TstdlEffectScheduler {
17
17
  queue = new Set();
18
- pendingFlush = false;
18
+ hasPendingFlush = false;
19
19
  scheduleEffect(effect) {
20
+ if (this.queue.has(effect)) {
21
+ return;
22
+ }
20
23
  this.queue.add(effect);
21
- if (!this.pendingFlush) {
22
- this.pendingFlush = true;
24
+ if (!this.hasPendingFlush) {
25
+ this.hasPendingFlush = true;
23
26
  queueMicrotask(() => {
24
- this.pendingFlush = false;
27
+ this.hasPendingFlush = false;
25
28
  this.flush();
26
29
  });
27
30
  }
@@ -44,7 +44,7 @@ export interface WritableSignal<T> extends Signal<T> {
44
44
  update(updateFn: (value: T) => T): void;
45
45
  /**
46
46
  * Returns a readonly version of this signal. Readonly signals can be accessed to read their value
47
- * but can't be changed using set, update or mutate methods. The readonly signals do _not_ have
47
+ * but can't be changed using set or update methods. The readonly signals do _not_ have
48
48
  * any built-in mechanism that would prevent deep-mutation of their value.
49
49
  */
50
50
  asReadonly(): Signal<T>;