performance-helpers 1.0.0 → 1.0.1
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 +12 -2
- package/package.json +146 -1
- package/src/index.js +1 -0
- package/.eslintrc.cjs +0 -22
- package/.nojekyll +0 -0
- package/.prettierrc +0 -6
- package/CONTRIBUTING.md +0 -178
- package/assets/1_Caching.md +0 -4
- package/assets/2_Parallelizing.md +0 -18
- package/assets/3_Logging.md +0 -3
- package/assets/404.md +0 -3
- package/assets/4_Utils.md +0 -10
- package/assets/logo.png +0 -0
- package/assets/navigation.md +0 -10
- package/bench/README.md +0 -97
- package/bench/results.json +0 -94
- package/bench/results.md +0 -233
- package/bench/run.js +0 -2639
- package/bench/worker.js +0 -43
- package/docs/README.md +0 -38
- package/docs/docs-typedoc.json +0 -38714
- package/docs/helpers/constants/README.md +0 -34
- package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_BACKOFF_MAX_MULTIPLIER.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_COOLDOWN_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_INTERVAL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_MIN_INTERVAL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_BACKPRESSURE_QUEUE_CAPACITY.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_BACKPRESSURE_REFILL_INTERVAL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_BATCH_MAX_SIZE.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_CACHE_DEFAULT_TTL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_CACHE_MAX_POOL_SIZE.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_CACHE_MAX_WEIGHT_BYTES.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_HISTOGRAM_BUCKET_COUNT.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_HISTOGRAM_MAX_VALUE.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_MAX_CLEANUP_PER_TICK.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_QUEUE_CAPACITY.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_REAPER_MIN_INTERVAL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_REFILL_INTERVAL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_RETRY_BASE_DELAY_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_RETRY_MAX_DELAY_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_TIMEOUT_MS.md +0 -9
- package/docs/helpers/constants/variables/ENCODE_CACHE_LARGE_KEY_LENGTH.md +0 -9
- package/docs/helpers/constants/variables/MAX_DEEP_EQUAL_DEPTH.md +0 -9
- package/docs/helpers/constants/variables/MS_PER_MIN.md +0 -9
- package/docs/helpers/constants/variables/MS_PER_SEC.md +0 -9
- package/docs/helpers/constants/variables/default.md +0 -103
- package/docs/helpers/jsdoc-types/README.md +0 -33
- package/docs/helpers/jsdoc-types/interfaces/BufferDecoder.md +0 -23
- package/docs/helpers/jsdoc-types/interfaces/BufferEncoder.md +0 -23
- package/docs/helpers/jsdoc-types/interfaces/CacheNode.md +0 -43
- package/docs/helpers/jsdoc-types/interfaces/CommonPoolOptions.md +0 -31
- package/docs/helpers/jsdoc-types/interfaces/PendingResponseEntry.md +0 -51
- package/docs/helpers/jsdoc-types/interfaces/PostMessageOptions.md +0 -39
- package/docs/helpers/jsdoc-types/interfaces/PowerBatchOptions.md +0 -13
- package/docs/helpers/jsdoc-types/interfaces/PowerCacheOptions.md +0 -115
- package/docs/helpers/jsdoc-types/interfaces/PowerChunkingOptions.md +0 -31
- package/docs/helpers/jsdoc-types/interfaces/PowerCircuitOptions.md +0 -45
- package/docs/helpers/jsdoc-types/interfaces/PowerDeadlineOptions.md +0 -101
- package/docs/helpers/jsdoc-types/interfaces/PowerDeferOptions.md +0 -13
- package/docs/helpers/jsdoc-types/interfaces/PowerEventBusOptions.md +0 -19
- package/docs/helpers/jsdoc-types/interfaces/PowerLatchOptions.md +0 -23
- package/docs/helpers/jsdoc-types/interfaces/PowerLoggerOptions.md +0 -51
- package/docs/helpers/jsdoc-types/interfaces/PowerObserverOptions.md +0 -25
- package/docs/helpers/jsdoc-types/interfaces/PowerPoolOptions.md +0 -85
- package/docs/helpers/jsdoc-types/interfaces/PowerQueueOptions.md +0 -13
- package/docs/helpers/jsdoc-types/interfaces/PowerRetryOptions.md +0 -83
- package/docs/helpers/jsdoc-types/interfaces/PowerSlidingWindowOptions.md +0 -19
- package/docs/helpers/jsdoc-types/interfaces/PowerTTLMapOptions.md +0 -27
- package/docs/helpers/jsdoc-types/interfaces/PowerThrottleOptions.md +0 -31
- package/docs/helpers/jsdoc-types/interfaces/WorkerObj.md +0 -55
- package/docs/helpers/powerBackpressure/README.md +0 -17
- package/docs/helpers/powerBackpressure/classes/PowerBackpressure.md +0 -368
- package/docs/helpers/powerBatch/README.md +0 -17
- package/docs/helpers/powerBatch/classes/PowerBatch.md +0 -139
- package/docs/helpers/powerBuffer/README.md +0 -26
- package/docs/helpers/powerBuffer/functions/b2o.md +0 -25
- package/docs/helpers/powerBuffer/functions/o2b.md +0 -23
- package/docs/helpers/powerBuffer/functions/o2u8.md +0 -33
- package/docs/helpers/powerBuffer/functions/u82o.md +0 -30
- package/docs/helpers/powerBulkhead/README.md +0 -17
- package/docs/helpers/powerBulkhead/classes/PowerBulkhead.md +0 -302
- package/docs/helpers/powerCache/README.md +0 -29
- package/docs/helpers/powerCache/classes/PowerCache.md +0 -933
- package/docs/helpers/powerCache/classes/PowerMemoizer.md +0 -244
- package/docs/helpers/powerCache/classes/PowerTimedCache.md +0 -302
- package/docs/helpers/powerCache/functions/simpleArgsKey.md +0 -31
- package/docs/helpers/powerChunking/README.md +0 -17
- package/docs/helpers/powerChunking/classes/PowerChunker.md +0 -78
- package/docs/helpers/powerCircuit/README.md +0 -23
- package/docs/helpers/powerCircuit/classes/PowerCircuit.md +0 -167
- package/docs/helpers/powerDeadline/README.md +0 -23
- package/docs/helpers/powerDeadline/classes/PowerDeadline.md +0 -88
- package/docs/helpers/powerDefer/README.md +0 -17
- package/docs/helpers/powerDefer/classes/PowerDefer.md +0 -134
- package/docs/helpers/powerEventBus/README.md +0 -23
- package/docs/helpers/powerEventBus/classes/PowerEventBus.md +0 -330
- package/docs/helpers/powerHistogram/README.md +0 -17
- package/docs/helpers/powerHistogram/classes/PowerHistogram.md +0 -285
- package/docs/helpers/powerLatch/README.md +0 -17
- package/docs/helpers/powerLatch/classes/PowerLatch.md +0 -264
- package/docs/helpers/powerLogger/README.md +0 -17
- package/docs/helpers/powerLogger/classes/PowerLogger.md +0 -290
- package/docs/helpers/powerObserver/README.md +0 -23
- package/docs/helpers/powerObserver/classes/PowerObserver.md +0 -213
- package/docs/helpers/powerPermitGate/README.md +0 -11
- package/docs/helpers/powerPermitGate/classes/PowerPermitGate.md +0 -248
- package/docs/helpers/powerPool/README.md +0 -36
- package/docs/helpers/powerPool/classes/PowerPool.md +0 -973
- package/docs/helpers/powerPool/classes/PowerPoolShutdownError.md +0 -67
- package/docs/helpers/powerQueue/README.md +0 -11
- package/docs/helpers/powerQueue/classes/PowerQueue.md +0 -302
- package/docs/helpers/powerRateLimit/README.md +0 -17
- package/docs/helpers/powerRateLimit/classes/PowerRateLimit.md +0 -187
- package/docs/helpers/powerRetry/README.md +0 -23
- package/docs/helpers/powerRetry/classes/PowerRetry.md +0 -106
- package/docs/helpers/powerScheduler/README.md +0 -11
- package/docs/helpers/powerScheduler/classes/PowerScheduler.md +0 -135
- package/docs/helpers/powerSemaphore/README.md +0 -17
- package/docs/helpers/powerSemaphore/classes/PowerSemaphore.md +0 -173
- package/docs/helpers/powerSlidingWindow/README.md +0 -11
- package/docs/helpers/powerSlidingWindow/classes/PowerSlidingWindow.md +0 -83
- package/docs/helpers/powerSubscriberSet/README.md +0 -15
- package/docs/helpers/powerSubscriberSet/classes/PowerSubscriberSet.md +0 -251
- package/docs/helpers/powerSubscriberSet/functions/cleanupWeakRefs.md +0 -21
- package/docs/helpers/powerTTLMap/README.md +0 -17
- package/docs/helpers/powerTTLMap/classes/PowerTTLMap.md +0 -326
- package/docs/helpers/powerThrottle/README.md +0 -17
- package/docs/helpers/powerThrottle/classes/PowerThrottle.md +0 -216
- package/docs/index/README.md +0 -205
- package/docs/utils/errors/README.md +0 -12
- package/docs/utils/errors/functions/formatErrorObj.md +0 -30
- package/docs/utils/errors/functions/normalizeError.md +0 -50
- package/docs/utils/now/README.md +0 -19
- package/docs/utils/now/functions/measureAsync.md +0 -37
- package/docs/utils/now/functions/measureSync.md +0 -54
- package/docs/utils/now/functions/nowMs.md +0 -24
- package/guides/autoscale.md +0 -80
- package/guides/errors.md +0 -41
- package/guides/metaGuide.md +0 -440
- package/guides/now.md +0 -56
- package/guides/powerBackpressure.md +0 -110
- package/guides/powerBatch.md +0 -82
- package/guides/powerBuffer.md +0 -86
- package/guides/powerBulkhead.md +0 -61
- package/guides/powerCache.md +0 -269
- package/guides/powerChunking.md +0 -130
- package/guides/powerCircuit.md +0 -84
- package/guides/powerDeadline.md +0 -99
- package/guides/powerDefer.md +0 -56
- package/guides/powerEventBus.md +0 -89
- package/guides/powerHistogram.md +0 -71
- package/guides/powerLatch.md +0 -94
- package/guides/powerLogger.md +0 -129
- package/guides/powerObserver.md +0 -65
- package/guides/powerPermitGate.md +0 -52
- package/guides/powerPool.md +0 -321
- package/guides/powerQueue.md +0 -112
- package/guides/powerRateLimit.md +0 -37
- package/guides/powerRetry.md +0 -54
- package/guides/powerScheduler.md +0 -41
- package/guides/powerSemaphore.md +0 -65
- package/guides/powerSlidingWindow.md +0 -63
- package/guides/powerSubscriberSet.md +0 -48
- package/guides/powerTTLMap.md +0 -58
- package/guides/powerThrottle.md +0 -152
- package/index.html +0 -57
- package/results.json +0 -6692
- package/scripts/find-missing-jsdoc.js +0 -62
- package/scripts/modernize-optional-chaining.cjs +0 -36
- package/scripts/pool-debug.mjs +0 -29
- package/scripts/repro_powercache.js +0 -14
- package/scripts/static-audit-exports.cjs +0 -93
- package/scripts/static-audit-exports.json +0 -518
- package/test/powerBackpressure.test.js +0 -114
- package/test/powerBatch.branches.extra.test.js +0 -122
- package/test/powerBatch.test.js +0 -79
- package/test/powerBuffer.test.js +0 -125
- package/test/powerBulkhead.test.js +0 -210
- package/test/powerCache.branches.test.js +0 -233
- package/test/powerCache.bulk.test.js +0 -31
- package/test/powerCache.getorset.test.js +0 -110
- package/test/powerCache.hitRate.test.js +0 -35
- package/test/powerCache.inflight.test.js +0 -24
- package/test/powerCache.iterator.test.js +0 -18
- package/test/powerCache.misses.test.js +0 -52
- package/test/powerCache.more.test.js +0 -118
- package/test/powerCache.test.js +0 -37
- package/test/powerCache.timeout.test.js +0 -25
- package/test/powerCache.touch.test.js +0 -46
- package/test/powerChunking.branches.extra.test.js +0 -155
- package/test/powerChunking.errors.test.js +0 -177
- package/test/powerChunking.test.js +0 -39
- package/test/powerCircuit.observability.test.js +0 -71
- package/test/powerCircuit.test.js +0 -74
- package/test/powerDeadline.test.js +0 -140
- package/test/powerDefer.test.js +0 -55
- package/test/powerErrors.test.js +0 -32
- package/test/powerEventBus.branches.extra.test.js +0 -70
- package/test/powerEventBus.extra.test.js +0 -72
- package/test/powerEventBus.max.test.js +0 -43
- package/test/powerEventBus.more.test.js +0 -121
- package/test/powerEventBus.once_off.test.js +0 -17
- package/test/powerEventBus.test.js +0 -74
- package/test/powerEventBus.uncovered.test.js +0 -57
- package/test/powerEventBus.weak.test.js +0 -18
- package/test/powerHistogram.test.js +0 -73
- package/test/powerLatch.branches.extra.test.js +0 -115
- package/test/powerLatch.test.js +0 -57
- package/test/powerLogger.branches.test.js +0 -98
- package/test/powerLogger.formatter.name.test.js +0 -58
- package/test/powerLogger.json.test.js +0 -88
- package/test/powerLogger.output.test.js +0 -81
- package/test/powerLogger.table.debug.test.js +0 -77
- package/test/powerLogger.test.js +0 -59
- package/test/powerMemoizer.memoize.test.js +0 -100
- package/test/powerMemoizer.test.js +0 -85
- package/test/powerObserver.test.js +0 -129
- package/test/powerPermitGate.test.js +0 -66
- package/test/powerPool.autoTransfer.test.js +0 -100
- package/test/powerPool.autoscale.extra.test.js +0 -88
- package/test/powerPool.autoscale.test.js +0 -136
- package/test/powerPool.awaitDefaultTimeout.test.js +0 -52
- package/test/powerPool.awaitTimeout.test.js +0 -22
- package/test/powerPool.batch.test.js +0 -170
- package/test/powerPool.branches.extra2.test.js +0 -42
- package/test/powerPool.branches.test.js +0 -102
- package/test/powerPool.browser.messageerror.test.js +0 -45
- package/test/powerPool.correlation.test.js +0 -26
- package/test/powerPool.correlationId.test.js +0 -63
- package/test/powerPool.dispose.test.js +0 -49
- package/test/powerPool.drain.test.js +0 -57
- package/test/powerPool.events.test.js +0 -131
- package/test/powerPool.more.extra.test.js +0 -99
- package/test/powerPool.more.test.js +0 -283
- package/test/powerPool.node.messageerror.test.js +0 -46
- package/test/powerPool.postMessage.promise.test.js +0 -83
- package/test/powerPool.queueHigh.test.js +0 -55
- package/test/powerPool.queueSaturation.test.js +0 -51
- package/test/powerPool.rapidResize.test.js +0 -55
- package/test/powerPool.resize.overload.test.js +0 -65
- package/test/powerPool.resize.test.js +0 -70
- package/test/powerPool.shutdown.test.js +0 -38
- package/test/powerPool.stats.test.js +0 -40
- package/test/powerPool.stopThePress.test.js +0 -94
- package/test/powerPool.terminateShutdown.test.js +0 -22
- package/test/powerPool.test.js +0 -525
- package/test/powerPool.timers.test.js +0 -55
- package/test/powerPool.uncovered.test.js +0 -407
- package/test/powerPool.workerId.test.js +0 -47
- package/test/powerQueue.iterators.test.js +0 -67
- package/test/powerQueue.saturation.test.js +0 -18
- package/test/powerQueue.test.js +0 -48
- package/test/powerQueue.unshiftMany.test.js +0 -49
- package/test/powerRateLimit.atomic.test.js +0 -80
- package/test/powerRateLimit.extra.test.js +0 -145
- package/test/powerRateLimit.functions.test.js +0 -106
- package/test/powerRateLimit.test.js +0 -38
- package/test/powerRetry.attemptTimeout.test.js +0 -51
- package/test/powerRetry.test.js +0 -121
- package/test/powerScheduler.test.js +0 -126
- package/test/powerSemaphore.test.js +0 -108
- package/test/powerSlidingWindow.pool.test.js +0 -55
- package/test/powerSlidingWindow.test.js +0 -25
- package/test/powerSubscriberSet.test.js +0 -125
- package/test/powerTTLMap.test.js +0 -125
- package/test/powerThrottle.pool.test.js +0 -54
- package/test/powerThrottle.refill.test.js +0 -22
- package/test/powerThrottle.reserve.test.js +0 -46
- package/test/powerThrottle.test.js +0 -45
- package/test/powerTimedCache.test.js +0 -73
- package/test/umd.bundle.branches.test.js +0 -100
- package/test/umd.bundle.cache-timers.test.js +0 -48
- package/test/umd.bundle.exhaustive.test.js +0 -158
- package/test/umd.bundle.fuzz.test.js +0 -86
- package/test/umd.bundle.hasEqual.more.test.js +0 -68
- package/test/umd.bundle.hasEqual.test.js +0 -104
- package/test/umd.bundle.logger-extra.test.js +0 -48
- package/test/umd.bundle.more-coverage-2.test.js +0 -67
- package/test/umd.bundle.pool.test.js +0 -134
- package/test/umd.bundle.test.js +0 -265
- package/test/utils.measure.test.js +0 -49
- package/test/utils.now.extra.test.js +0 -30
- package/test/utils.now.more.test.js +0 -57
- package/tsconfig.json +0 -16
- package/typedoc.json +0 -25
- package/vite.config.js +0 -31
- package/vitest.config.js +0 -17
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import url from 'url';
|
|
5
|
-
|
|
6
|
-
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
7
|
-
|
|
8
|
-
function walk(dir, files = []) {
|
|
9
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
10
|
-
const full = path.join(dir, entry.name);
|
|
11
|
-
if (entry.isDirectory()) walk(full, files);
|
|
12
|
-
else if (entry.isFile() && full.endsWith('.js')) files.push(full);
|
|
13
|
-
}
|
|
14
|
-
return files;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function isReexport(line) {
|
|
18
|
-
return /\bfrom\b/.test(line) || /^\s*export\s*{/.test(line);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function isExportDecl(line) {
|
|
22
|
-
// matches export default class/function, export class, export function, export const/let/var
|
|
23
|
-
return (
|
|
24
|
-
/^\s*export\s+(?:default\s+)?(?:async\s+)?(?:class|function)\b/.test(line) ||
|
|
25
|
-
/^\s*export\s+(?:const|let|var)\s+[A-Za-z_$][\w$]*/.test(line) ||
|
|
26
|
-
/^\s*export\s+default\s*(?:\(|[A-Za-z_$])/.test(line)
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function hasJSDocBefore(lines, idx) {
|
|
31
|
-
let j = idx - 1;
|
|
32
|
-
while (j >= 0) {
|
|
33
|
-
const t = lines[j].trim();
|
|
34
|
-
if (t === '') {
|
|
35
|
-
j--;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
return t.startsWith('/**');
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const root = path.join(__dirname, '..', 'src');
|
|
44
|
-
const files = walk(root);
|
|
45
|
-
const findings = [];
|
|
46
|
-
for (const file of files) {
|
|
47
|
-
const src = fs.readFileSync(file, 'utf8');
|
|
48
|
-
const lines = src.split(/\r?\n/);
|
|
49
|
-
for (let i = 0; i < lines.length; i++) {
|
|
50
|
-
const line = lines[i];
|
|
51
|
-
if (!/\bexport\b/.test(line)) continue;
|
|
52
|
-
if (isReexport(line)) continue;
|
|
53
|
-
if (!isExportDecl(line)) continue;
|
|
54
|
-
if (!hasJSDocBefore(lines, i)) {
|
|
55
|
-
findings.push({ file: path.relative(process.cwd(), file), line: i + 1, code: line.trim() });
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
console.log(JSON.stringify(findings, null, 2));
|
|
61
|
-
if (findings.length === 0) process.exit(0);
|
|
62
|
-
process.exit(1);
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
function walk(dir, list = []) {
|
|
5
|
-
for (const e of fs.readdirSync(dir)) {
|
|
6
|
-
const p = path.join(dir, e);
|
|
7
|
-
let st;
|
|
8
|
-
try {
|
|
9
|
-
st = fs.statSync(p);
|
|
10
|
-
} catch (err) {
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
if (st.isDirectory()) walk(p, list);
|
|
14
|
-
else if (p.endsWith('.js')) list.push(p);
|
|
15
|
-
}
|
|
16
|
-
return list;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const files = walk('src');
|
|
20
|
-
|
|
21
|
-
const propRegex = /([A-Za-z_$][\w$\.]*)\s*&&\s*\1\./g;
|
|
22
|
-
const callRegex = /([A-Za-z_$][\w$\.]*)\s*&&\s*\1\s*\(/g;
|
|
23
|
-
const typeofRegex = /([A-Za-z_$][\w$\.]*)\s*&&\s*typeof\s+\1\./g;
|
|
24
|
-
|
|
25
|
-
files.forEach(f => {
|
|
26
|
-
try {
|
|
27
|
-
let s = fs.readFileSync(f, 'utf8');
|
|
28
|
-
let t = s.replace(propRegex, '$1?.').replace(callRegex, '$1?.(').replace(typeofRegex, 'typeof $1?.');
|
|
29
|
-
if (t !== s) {
|
|
30
|
-
fs.writeFileSync(f, t, 'utf8');
|
|
31
|
-
console.log('patched', f);
|
|
32
|
-
}
|
|
33
|
-
} catch (e) {
|
|
34
|
-
console.error('error processing', f, e && e.message);
|
|
35
|
-
}
|
|
36
|
-
});
|
package/scripts/pool-debug.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { PowerPool } from '../src/helpers/powerPool.js';
|
|
2
|
-
import { o2u8 } from '../src/helpers/powerBuffer.js';
|
|
3
|
-
import { Worker as NodeWorker } from 'worker_threads';
|
|
4
|
-
globalThis.Worker = NodeWorker;
|
|
5
|
-
import { performance } from 'perf_hooks';
|
|
6
|
-
|
|
7
|
-
async function run() {
|
|
8
|
-
const pool = new PowerPool('./bench/worker.js', {
|
|
9
|
-
size: 1,
|
|
10
|
-
minSize: 1,
|
|
11
|
-
maxSize: 1,
|
|
12
|
-
idleTimeout: 10000,
|
|
13
|
-
taskQueue: true,
|
|
14
|
-
workerOptions: { type: 'module' },
|
|
15
|
-
});
|
|
16
|
-
const payload = o2u8({ iterations: 1000000 });
|
|
17
|
-
const p0 = pool.postMessage(payload, [payload.buffer]);
|
|
18
|
-
console.log('after first dispatch, tasks=', pool.workers[0]?.tasks, 'queue=', pool.queue.length);
|
|
19
|
-
const payload2 = o2u8({ iterations: 1000000 });
|
|
20
|
-
const p1 = pool.postMessage(payload2, [payload2.buffer]);
|
|
21
|
-
console.log('after second dispatch, tasks=', pool.workers[0]?.tasks, 'queue=', pool.queue.length);
|
|
22
|
-
await pool.drain();
|
|
23
|
-
console.log('final tasks=', pool.workers[0]?.tasks, 'queue=', pool.queue.length);
|
|
24
|
-
pool.terminate();
|
|
25
|
-
}
|
|
26
|
-
run().catch((err) => {
|
|
27
|
-
console.error(err);
|
|
28
|
-
process.exit(1);
|
|
29
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { PowerCache } from '../src/helpers/powerCache.js';
|
|
2
|
-
|
|
3
|
-
(async () => {
|
|
4
|
-
const c = new PowerCache({ defaultTTL: 1, maxEntries: 10 });
|
|
5
|
-
c.set('a', 1, { ttl: 1 });
|
|
6
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
7
|
-
console.log('peek:', c.peek('a'));
|
|
8
|
-
console.log('map has a before has(ignoreExpiry):', c.map.has('a'));
|
|
9
|
-
console.log('has(ignoreExpiry):', c.has('a', { ignoreExpiry: true }));
|
|
10
|
-
console.log('map has a after has(ignoreExpiry):', c.map.has('a'));
|
|
11
|
-
console.log('has():', c.has('a'));
|
|
12
|
-
console.log('delete:', c.delete('a'));
|
|
13
|
-
console.log('map has a after delete:', c.map.has('a'));
|
|
14
|
-
})();
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
|
|
5
|
-
const root = process.cwd();
|
|
6
|
-
const srcHelpers = path.join(root, 'src');
|
|
7
|
-
|
|
8
|
-
function listJsFiles(dir) {
|
|
9
|
-
const out = [];
|
|
10
|
-
for (const name of fs.readdirSync(dir)) {
|
|
11
|
-
const p = path.join(dir, name);
|
|
12
|
-
const st = fs.statSync(p);
|
|
13
|
-
if (st.isDirectory()) {
|
|
14
|
-
out.push(...listJsFiles(p));
|
|
15
|
-
} else if (st.isFile() && p.endsWith('.js')) {
|
|
16
|
-
out.push(p);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return out;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function listAllJsFiles(dir) {
|
|
23
|
-
const out = [];
|
|
24
|
-
const entries = fs.readdirSync(dir);
|
|
25
|
-
for (const name of entries) {
|
|
26
|
-
const p = path.join(dir, name);
|
|
27
|
-
let st;
|
|
28
|
-
try { st = fs.statSync(p); } catch (e) { continue; }
|
|
29
|
-
if (st.isDirectory()) {
|
|
30
|
-
if (name === 'node_modules' || name === 'coverage' || name === '.git') continue;
|
|
31
|
-
out.push(...listAllJsFiles(p));
|
|
32
|
-
} else if (st.isFile() && p.endsWith('.js')) out.push(p);
|
|
33
|
-
}
|
|
34
|
-
return out;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function extractExports(content) {
|
|
38
|
-
const symbols = [];
|
|
39
|
-
const classRx = /export\s+class\s+([A-Za-z_$][A-Za-z0-9_$]*)/g;
|
|
40
|
-
const fnRx = /export\s+function\s+([A-Za-z_$][A-Za-z0-9_$]*)/g;
|
|
41
|
-
const varRx = /export\s+(?:const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)/g;
|
|
42
|
-
const defaultRx = /export\s+default\s+([A-Za-z_$][A-Za-z0-9_$]*)/g;
|
|
43
|
-
const namedRx = /export\s*\{([^}]+)\}/g;
|
|
44
|
-
|
|
45
|
-
let m;
|
|
46
|
-
while ((m = classRx.exec(content))) symbols.push(m[1]);
|
|
47
|
-
while ((m = fnRx.exec(content))) symbols.push(m[1]);
|
|
48
|
-
while ((m = varRx.exec(content))) symbols.push(m[1]);
|
|
49
|
-
while ((m = defaultRx.exec(content))) symbols.push(m[1]);
|
|
50
|
-
while ((m = namedRx.exec(content))) {
|
|
51
|
-
const list = m[1].split(',').map(s => s.trim().split(/\s+as\s+/)[0].trim()).filter(Boolean);
|
|
52
|
-
for (const s of list) symbols.push(s);
|
|
53
|
-
}
|
|
54
|
-
return Array.from(new Set(symbols));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function readFileSafe(p) {
|
|
58
|
-
try { return fs.readFileSync(p, 'utf8'); } catch (e) { return null; }
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const helperFiles = listJsFiles(srcHelpers);
|
|
62
|
-
const allJsFiles = listAllJsFiles(root);
|
|
63
|
-
|
|
64
|
-
const report = [];
|
|
65
|
-
const symbolMap = {};
|
|
66
|
-
|
|
67
|
-
for (const file of helperFiles) {
|
|
68
|
-
const content = readFileSafe(file);
|
|
69
|
-
if (!content) continue;
|
|
70
|
-
const exports = extractExports(content);
|
|
71
|
-
for (const sym of exports) {
|
|
72
|
-
if (!symbolMap[sym]) symbolMap[sym] = { def: file, refs: new Set() };
|
|
73
|
-
else symbolMap[sym].def = symbolMap[sym].def || file;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
for (const [sym, info] of Object.entries(symbolMap)) {
|
|
78
|
-
const rx = new RegExp('\\b' + sym + '\\b', 'g');
|
|
79
|
-
for (const file of allJsFiles) {
|
|
80
|
-
const c = readFileSafe(file);
|
|
81
|
-
if (!c) continue;
|
|
82
|
-
if (file === info.def) continue; // skip declaration file
|
|
83
|
-
if (rx.test(c)) info.refs.add(file);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
for (const [sym, info] of Object.entries(symbolMap)) {
|
|
88
|
-
report.push({ symbol: sym, definedIn: path.relative(root, info.def), referencedIn: Array.from(info.refs).map(f => path.relative(root, f)) });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const out = { generatedAt: new Date().toISOString(), report };
|
|
92
|
-
fs.writeFileSync(path.join('scripts','static-audit-exports.json'), JSON.stringify(out, null, 2));
|
|
93
|
-
console.log(JSON.stringify(out, null, 2));
|