lakutata 2.0.11 → 2.0.13

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.
Files changed (142) hide show
  1. package/com/database.cjs +13 -3
  2. package/com/database.mjs +13 -3
  3. package/com/docker.cjs +6 -2
  4. package/com/docker.d.ts +39 -11
  5. package/com/docker.mjs +6 -2
  6. package/com/logger.cjs +2 -2
  7. package/com/logger.mjs +2 -2
  8. package/decorator/orm.cjs +21 -11
  9. package/decorator/orm.mjs +13 -3
  10. package/helper.cjs +12 -12
  11. package/helper.d.ts +559 -82
  12. package/helper.mjs +5 -5
  13. package/lakutata.cjs +2 -2
  14. package/lakutata.mjs +2 -2
  15. package/orm.cjs +13 -3
  16. package/orm.mjs +39 -29
  17. package/package.json +2 -4
  18. package/src/components/Database.cjs +17 -7
  19. package/src/components/Database.mjs +13 -3
  20. package/src/components/Logger.cjs +2 -2
  21. package/src/components/Logger.mjs +2 -2
  22. package/src/components/docker/ConnectionOptionsBuilder.cjs +6 -2
  23. package/src/components/docker/ConnectionOptionsBuilder.mjs +6 -2
  24. package/src/components/docker/Docker.cjs +10 -3
  25. package/src/components/docker/Docker.mjs +10 -3
  26. package/src/components/docker/lib/DockerContainer.cjs +10 -6
  27. package/src/components/docker/lib/DockerContainer.mjs +6 -2
  28. package/src/components/docker/lib/DockerContainerTTY.cjs +6 -2
  29. package/src/components/docker/lib/DockerContainerTTY.mjs +6 -2
  30. package/src/components/docker/options/container/ContainerSettingOptions.cjs +4 -0
  31. package/src/components/docker/options/container/ContainerSettingOptions.mjs +4 -0
  32. package/src/decorators/orm/AfterInsert.cjs +13 -3
  33. package/src/decorators/orm/AfterInsert.mjs +17 -7
  34. package/src/decorators/orm/AfterLoad.cjs +17 -7
  35. package/src/decorators/orm/AfterLoad.mjs +13 -3
  36. package/src/decorators/orm/AfterRecover.cjs +17 -7
  37. package/src/decorators/orm/AfterRecover.mjs +17 -7
  38. package/src/decorators/orm/AfterRemove.cjs +17 -7
  39. package/src/decorators/orm/AfterRemove.mjs +22 -12
  40. package/src/decorators/orm/AfterSoftRemove.cjs +13 -3
  41. package/src/decorators/orm/AfterSoftRemove.mjs +24 -14
  42. package/src/decorators/orm/AfterUpdate.cjs +13 -3
  43. package/src/decorators/orm/AfterUpdate.mjs +22 -12
  44. package/src/decorators/orm/BeforeInsert.cjs +17 -7
  45. package/src/decorators/orm/BeforeInsert.mjs +17 -7
  46. package/src/decorators/orm/BeforeRecover.cjs +17 -7
  47. package/src/decorators/orm/BeforeRecover.mjs +22 -12
  48. package/src/decorators/orm/BeforeRemove.cjs +17 -7
  49. package/src/decorators/orm/BeforeRemove.mjs +17 -7
  50. package/src/decorators/orm/BeforeSoftRemove.cjs +17 -7
  51. package/src/decorators/orm/BeforeSoftRemove.mjs +23 -13
  52. package/src/decorators/orm/BeforeUpdate.cjs +17 -7
  53. package/src/decorators/orm/BeforeUpdate.mjs +22 -12
  54. package/src/decorators/orm/Check.cjs +18 -8
  55. package/src/decorators/orm/Check.mjs +13 -3
  56. package/src/decorators/orm/ChildEntity.cjs +13 -3
  57. package/src/decorators/orm/ChildEntity.mjs +13 -3
  58. package/src/decorators/orm/Column.cjs +29 -19
  59. package/src/decorators/orm/Column.mjs +23 -13
  60. package/src/decorators/orm/CreateDateColumn.cjs +19 -9
  61. package/src/decorators/orm/CreateDateColumn.mjs +24 -14
  62. package/src/decorators/orm/DeleteDateColumn.cjs +19 -9
  63. package/src/decorators/orm/DeleteDateColumn.mjs +23 -13
  64. package/src/decorators/orm/Entity.cjs +26 -16
  65. package/src/decorators/orm/Entity.mjs +32 -22
  66. package/src/decorators/orm/EventSubscriber.cjs +13 -3
  67. package/src/decorators/orm/EventSubscriber.mjs +18 -8
  68. package/src/decorators/orm/Exclusion.cjs +21 -11
  69. package/src/decorators/orm/Exclusion.mjs +21 -11
  70. package/src/decorators/orm/Generated.cjs +13 -3
  71. package/src/decorators/orm/Generated.mjs +13 -3
  72. package/src/decorators/orm/Index.cjs +22 -12
  73. package/src/decorators/orm/Index.mjs +27 -17
  74. package/src/decorators/orm/JoinColumn.cjs +19 -9
  75. package/src/decorators/orm/JoinColumn.mjs +27 -17
  76. package/src/decorators/orm/JoinTable.cjs +13 -3
  77. package/src/decorators/orm/JoinTable.mjs +29 -19
  78. package/src/decorators/orm/ManyToMany.cjs +25 -15
  79. package/src/decorators/orm/ManyToMany.mjs +26 -16
  80. package/src/decorators/orm/ManyToOne.cjs +25 -15
  81. package/src/decorators/orm/ManyToOne.mjs +26 -16
  82. package/src/decorators/orm/ObjectIdColumn.cjs +13 -3
  83. package/src/decorators/orm/ObjectIdColumn.mjs +26 -16
  84. package/src/decorators/orm/OneToMany.cjs +21 -11
  85. package/src/decorators/orm/OneToMany.mjs +22 -12
  86. package/src/decorators/orm/OneToOne.cjs +16 -6
  87. package/src/decorators/orm/OneToOne.mjs +36 -26
  88. package/src/decorators/orm/PrimaryColumn.cjs +22 -12
  89. package/src/decorators/orm/PrimaryColumn.mjs +24 -14
  90. package/src/decorators/orm/PrimaryGeneratedColumn.cjs +32 -22
  91. package/src/decorators/orm/PrimaryGeneratedColumn.mjs +18 -8
  92. package/src/decorators/orm/RelationId.cjs +19 -9
  93. package/src/decorators/orm/RelationId.mjs +18 -8
  94. package/src/decorators/orm/TableInheritance.cjs +17 -7
  95. package/src/decorators/orm/TableInheritance.mjs +26 -16
  96. package/src/decorators/orm/Tree.cjs +13 -3
  97. package/src/decorators/orm/Tree.mjs +26 -16
  98. package/src/decorators/orm/TreeChildren.cjs +15 -5
  99. package/src/decorators/orm/TreeChildren.mjs +18 -8
  100. package/src/decorators/orm/TreeLevelColumn.cjs +13 -3
  101. package/src/decorators/orm/TreeLevelColumn.mjs +20 -10
  102. package/src/decorators/orm/TreeParent.cjs +19 -9
  103. package/src/decorators/orm/TreeParent.mjs +13 -3
  104. package/src/decorators/orm/Unique.cjs +29 -19
  105. package/src/decorators/orm/Unique.mjs +30 -20
  106. package/src/decorators/orm/UpdateDateColumn.cjs +19 -9
  107. package/src/decorators/orm/UpdateDateColumn.mjs +25 -15
  108. package/src/decorators/orm/VersionColumn.cjs +13 -3
  109. package/src/decorators/orm/VersionColumn.mjs +26 -16
  110. package/src/decorators/orm/ViewColumn.cjs +13 -3
  111. package/src/decorators/orm/ViewColumn.mjs +26 -16
  112. package/src/decorators/orm/ViewEntity.cjs +27 -17
  113. package/src/decorators/orm/ViewEntity.mjs +19 -9
  114. package/src/decorators/orm/VirtualColumn.cjs +18 -8
  115. package/src/decorators/orm/VirtualColumn.mjs +30 -20
  116. package/src/lib/base/internal/PatternManager.cjs +2 -2
  117. package/src/lib/base/internal/PatternManager.mjs +2 -2
  118. package/src/lib/core/Application.cjs +2 -2
  119. package/src/lib/core/Application.mjs +2 -2
  120. package/src/lib/helpers/Glob.cjs +1220 -1149
  121. package/src/lib/helpers/Glob.mjs +769 -700
  122. package/src/lib/helpers/IsXML.cjs +863 -801
  123. package/src/lib/helpers/IsXML.mjs +862 -800
  124. package/src/lib/ioc/ListModules.cjs +967 -909
  125. package/src/lib/ioc/ListModules.mjs +849 -791
  126. package/src/lib/validation/VLD.cjs +20 -10
  127. package/src/lib/validation/VLD.mjs +20 -10
  128. package/vendor/Package.1.cjs +170 -129
  129. package/vendor/Package.1.mjs +169 -128
  130. package/vendor/Package.13.cjs +0 -2
  131. package/vendor/Package.13.mjs +0 -2
  132. package/vendor/Package.14.cjs +8748 -8652
  133. package/vendor/Package.14.mjs +8665 -8581
  134. package/vendor/Package.16.cjs +36855 -15590
  135. package/vendor/Package.16.mjs +36893 -15633
  136. package/vendor/Package.2.cjs +2442 -2440
  137. package/vendor/Package.2.mjs +444 -442
  138. package/vendor/Package.4.cjs +325 -319
  139. package/vendor/Package.4.mjs +326 -320
  140. package/vendor/Package.7.cjs +299 -299
  141. package/vendor/Package.7.mjs +299 -299
  142. package/vendor/TypeDef.5.d.ts +6 -0
package/helper.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import './vendor/TypeDef.2.js';
3
- import { PathLike, Dirent, Stats } from 'fs';
3
+ import { PathLike } from 'fs';
4
4
  import { I as IConstructor } from './vendor/TypeDef.10.js';
5
- import { PathLike as PathLike$1 } from 'node:fs';
5
+ import { PathLike as PathLike$1, Dirent, Stats } from 'node:fs';
6
6
  import { ReadableOptions, Readable } from 'node:stream';
7
- import { win32, posix } from 'path';
8
- import { EventEmitter } from 'events';
9
- import { StringDecoder } from 'string_decoder';
7
+ import { win32, posix } from 'node:path';
8
+ import { EventEmitter } from 'node:events';
9
+ import { StringDecoder } from 'node:string_decoder';
10
10
 
11
11
  /**
12
12
  * Convert Array to Set
@@ -654,7 +654,7 @@ declare namespace Minipass {
654
654
  /**
655
655
  * Utility type to determine allowed options based on read type
656
656
  */
657
- export type Options<T> = T extends string ? EncodingOptions | ObjectModeOptions : T extends Buffer ? BufferOptions | ObjectModeOptions : SharedOptions;
657
+ export type Options<T> = ObjectModeOptions | (T extends string ? EncodingOptions : T extends Buffer ? BufferOptions : SharedOptions);
658
658
  export { };
659
659
  }
660
660
  /**
@@ -702,7 +702,7 @@ declare class Minipass<RType extends unknown = Buffer, WType extends unknown = R
702
702
  * {@link Minipass.SharedOptions.objectMode} or
703
703
  * {@link Minipass.SharedOptions.encoding}, as appropriate.
704
704
  */
705
- constructor(...args: RType extends Buffer ? [] | [Minipass.Options<RType>] : [Minipass.Options<RType>]);
705
+ constructor(...args: [Minipass.ObjectModeOptions] | (RType extends Buffer ? [] | [Minipass.Options<RType>] : [Minipass.Options<RType>]));
706
706
  /**
707
707
  * The amount of data stored in the buffer waiting to be read.
708
708
  *
@@ -1037,8 +1037,18 @@ declare namespace LRUCache {
1037
1037
  /**
1038
1038
  * The reason why an item was removed from the cache, passed
1039
1039
  * to the {@link Disposer} methods.
1040
+ *
1041
+ * - `evict`: The item was evicted because it is the least recently used,
1042
+ * and the cache is full.
1043
+ * - `set`: A new value was set, overwriting the old value being disposed.
1044
+ * - `delete`: The item was explicitly deleted, either by calling
1045
+ * {@link LRUCache#delete}, {@link LRUCache#clear}, or
1046
+ * {@link LRUCache#set} with an undefined value.
1047
+ * - `expire`: The item was removed due to exceeding its TTL.
1048
+ * - `fetch`: A {@link OptionsBase#fetchMethod} operation returned
1049
+ * `undefined` or was aborted, causing the item to be deleted.
1040
1050
  */
1041
- type DisposeReason = 'evict' | 'set' | 'delete';
1051
+ type DisposeReason = 'evict' | 'set' | 'delete' | 'expire' | 'fetch';
1042
1052
  /**
1043
1053
  * A method called upon item removal, passed as the
1044
1054
  * {@link OptionsBase.dispose} and/or
@@ -1064,8 +1074,14 @@ declare namespace LRUCache {
1064
1074
  context: FC;
1065
1075
  }
1066
1076
  /**
1067
- * Status object that may be passed to {@link LRUCache#fetch},
1068
- * {@link LRUCache#get}, {@link LRUCache#set}, and {@link LRUCache#has}.
1077
+ * Occasionally, it may be useful to track the internal behavior of the
1078
+ * cache, particularly for logging, debugging, or for behavior within the
1079
+ * `fetchMethod`. To do this, you can pass a `status` object to the
1080
+ * {@link LRUCache#fetch}, {@link LRUCache#get}, {@link LRUCache#set},
1081
+ * {@link LRUCache#memo}, and {@link LRUCache#has} methods.
1082
+ *
1083
+ * The `status` option should be a plain JavaScript object. The following
1084
+ * fields will be set on it appropriately, depending on the situation.
1069
1085
  */
1070
1086
  interface Status<V> {
1071
1087
  /**
@@ -1125,7 +1141,8 @@ declare namespace LRUCache {
1125
1141
  * various states.
1126
1142
  *
1127
1143
  * - inflight: there is another fetch() for this key which is in process
1128
- * - get: there is no fetchMethod, so {@link LRUCache#get} was called.
1144
+ * - get: there is no {@link OptionsBase.fetchMethod}, so
1145
+ * {@link LRUCache#get} was called.
1129
1146
  * - miss: the item is not in cache, and will be fetched.
1130
1147
  * - hit: the item is in the cache, and was resolved immediately.
1131
1148
  * - stale: the item is in the cache, but stale.
@@ -1234,6 +1251,67 @@ declare namespace LRUCache {
1234
1251
  interface FetchOptionsNoContext<K, V> extends FetchOptions<K, V, undefined> {
1235
1252
  context?: undefined;
1236
1253
  }
1254
+ interface MemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
1255
+ /**
1256
+ * Set to true to force a re-load of the existing data, even if it
1257
+ * is not yet stale.
1258
+ */
1259
+ forceRefresh?: boolean;
1260
+ /**
1261
+ * Context provided to the {@link OptionsBase.memoMethod} as
1262
+ * the {@link MemoizerOptions.context} param.
1263
+ *
1264
+ * If the FC type is specified as unknown (the default),
1265
+ * undefined or void, then this is optional. Otherwise, it will
1266
+ * be required.
1267
+ */
1268
+ context?: FC;
1269
+ status?: Status<V>;
1270
+ }
1271
+ /**
1272
+ * Options provided to {@link LRUCache#memo} when the FC type is something
1273
+ * other than `unknown`, `undefined`, or `void`
1274
+ */
1275
+ interface MemoOptionsWithContext<K, V, FC> extends MemoOptions<K, V, FC> {
1276
+ context: FC;
1277
+ }
1278
+ /**
1279
+ * Options provided to {@link LRUCache#memo} when the FC type is
1280
+ * `undefined` or `void`
1281
+ */
1282
+ interface MemoOptionsNoContext<K, V> extends MemoOptions<K, V, undefined> {
1283
+ context?: undefined;
1284
+ }
1285
+ /**
1286
+ * Options provided to the
1287
+ * {@link OptionsBase.memoMethod} function.
1288
+ */
1289
+ interface MemoizerOptions<K, V, FC = unknown> {
1290
+ options: MemoizerMemoOptions<K, V, FC>;
1291
+ /**
1292
+ * Object provided in the {@link MemoOptions.context} option to
1293
+ * {@link LRUCache#memo}
1294
+ */
1295
+ context: FC;
1296
+ }
1297
+ /**
1298
+ * options which override the options set in the LRUCache constructor
1299
+ * when calling {@link LRUCache#memo}.
1300
+ *
1301
+ * This is the union of {@link GetOptions} and {@link SetOptions}, plus
1302
+ * {@link MemoOptions.forceRefresh}, and
1303
+ * {@link MemoOptions.context}
1304
+ *
1305
+ * Any of these may be modified in the {@link OptionsBase.memoMethod}
1306
+ * function, but the {@link GetOptions} fields will of course have no
1307
+ * effect, as the {@link LRUCache#get} call already happened by the time
1308
+ * the memoMethod is called.
1309
+ */
1310
+ interface MemoizerMemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'> {
1311
+ status?: Status<V>;
1312
+ size?: Size;
1313
+ start?: Milliseconds;
1314
+ }
1237
1315
  /**
1238
1316
  * Options that may be passed to the {@link LRUCache#has} method.
1239
1317
  */
@@ -1276,6 +1354,10 @@ declare namespace LRUCache {
1276
1354
  * The type signature for the {@link OptionsBase.fetchMethod} option.
1277
1355
  */
1278
1356
  type Fetcher<K, V, FC = unknown> = (key: K, staleValue: V | undefined, options: FetcherOptions<K, V, FC>) => Promise<V | undefined | void> | V | undefined | void;
1357
+ /**
1358
+ * the type signature for the {@link OptionsBase.memoMethod} option.
1359
+ */
1360
+ type Memoizer<K, V, FC = unknown> = (key: K, staleValue: V | undefined, options: MemoizerOptions<K, V, FC>) => V;
1279
1361
  /**
1280
1362
  * Options which may be passed to the {@link LRUCache} constructor.
1281
1363
  *
@@ -1290,6 +1372,14 @@ declare namespace LRUCache {
1290
1372
  * (and in fact required by the type definitions here) that the cache
1291
1373
  * also set {@link OptionsBase.ttlAutopurge}, to prevent potentially
1292
1374
  * unbounded storage.
1375
+ *
1376
+ * All options are also available on the {@link LRUCache} instance, making
1377
+ * it safe to pass an LRUCache instance as the options argumemnt to
1378
+ * make another empty cache of the same type.
1379
+ *
1380
+ * Some options are marked as read-only, because changing them after
1381
+ * instantiation is not safe. Changing any of the other options will of
1382
+ * course only have an effect on subsequent method calls.
1293
1383
  */
1294
1384
  interface OptionsBase<K, V, FC> {
1295
1385
  /**
@@ -1303,20 +1393,44 @@ declare namespace LRUCache {
1303
1393
  * Note that significantly fewer items may be stored, if
1304
1394
  * {@link OptionsBase.maxSize} and/or {@link OptionsBase.ttl} are also
1305
1395
  * set.
1396
+ *
1397
+ * **It is strongly recommended to set a `max` to prevent unbounded growth
1398
+ * of the cache.**
1306
1399
  */
1307
1400
  max?: Count;
1308
1401
  /**
1309
1402
  * Max time in milliseconds for items to live in cache before they are
1310
- * considered stale. Note that stale items are NOT preemptively removed
1311
- * by default, and MAY live in the cache long after they have expired.
1403
+ * considered stale. Note that stale items are NOT preemptively removed by
1404
+ * default, and MAY live in the cache, contributing to its LRU max, long
1405
+ * after they have expired, unless {@link OptionsBase.ttlAutopurge} is
1406
+ * set.
1407
+ *
1408
+ * If set to `0` (the default value), then that means "do not track
1409
+ * TTL", not "expire immediately".
1312
1410
  *
1313
1411
  * Also, as this cache is optimized for LRU/MRU operations, some of
1314
1412
  * the staleness/TTL checks will reduce performance, as they will incur
1315
1413
  * overhead by deleting items.
1316
1414
  *
1317
- * Must be an integer number of ms. If set to 0, this indicates "no TTL"
1415
+ * This is not primarily a TTL cache, and does not make strong TTL
1416
+ * guarantees. There is no pre-emptive pruning of expired items, but you
1417
+ * _may_ set a TTL on the cache, and it will treat expired items as missing
1418
+ * when they are fetched, and delete them.
1419
+ *
1420
+ * Optional, but must be a non-negative integer in ms if specified.
1421
+ *
1422
+ * This may be overridden by passing an options object to `cache.set()`.
1423
+ *
1424
+ * At least one of `max`, `maxSize`, or `TTL` is required. This must be a
1425
+ * positive integer if set.
1426
+ *
1427
+ * Even if ttl tracking is enabled, **it is strongly recommended to set a
1428
+ * `max` to prevent unbounded growth of the cache.**
1318
1429
  *
1319
- * @default 0
1430
+ * If ttl tracking is enabled, and `max` and `maxSize` are not set,
1431
+ * and `ttlAutopurge` is not set, then a warning will be emitted
1432
+ * cautioning about the potential for unbounded memory consumption.
1433
+ * (The TypeScript definitions will also discourage this.)
1320
1434
  */
1321
1435
  ttl?: Milliseconds;
1322
1436
  /**
@@ -1336,54 +1450,95 @@ declare namespace LRUCache {
1336
1450
  ttlResolution?: Milliseconds;
1337
1451
  /**
1338
1452
  * Preemptively remove stale items from the cache.
1339
- * Note that this may significantly degrade performance,
1340
- * especially if the cache is storing a large number of items.
1341
- * It is almost always best to just leave the stale items in
1342
- * the cache, and let them fall out as new items are added.
1453
+ *
1454
+ * Note that this may *significantly* degrade performance, especially if
1455
+ * the cache is storing a large number of items. It is almost always best
1456
+ * to just leave the stale items in the cache, and let them fall out as new
1457
+ * items are added.
1343
1458
  *
1344
1459
  * Note that this means that {@link OptionsBase.allowStale} is a bit
1345
1460
  * pointless, as stale items will be deleted almost as soon as they
1346
1461
  * expire.
1347
1462
  *
1348
- * @default false
1463
+ * Use with caution!
1349
1464
  */
1350
1465
  ttlAutopurge?: boolean;
1351
1466
  /**
1352
- * Update the age of items on {@link LRUCache#get}, renewing their TTL
1467
+ * When using time-expiring entries with `ttl`, setting this to `true` will
1468
+ * make each item's age reset to 0 whenever it is retrieved from cache with
1469
+ * {@link LRUCache#get}, causing it to not expire. (It can still fall out
1470
+ * of cache based on recency of use, of course.)
1353
1471
  *
1354
1472
  * Has no effect if {@link OptionsBase.ttl} is not set.
1355
1473
  *
1356
- * @default false
1474
+ * This may be overridden by passing an options object to `cache.get()`.
1357
1475
  */
1358
1476
  updateAgeOnGet?: boolean;
1359
1477
  /**
1360
- * Update the age of items on {@link LRUCache#has}, renewing their TTL
1478
+ * When using time-expiring entries with `ttl`, setting this to `true` will
1479
+ * make each item's age reset to 0 whenever its presence in the cache is
1480
+ * checked with {@link LRUCache#has}, causing it to not expire. (It can
1481
+ * still fall out of cache based on recency of use, of course.)
1361
1482
  *
1362
1483
  * Has no effect if {@link OptionsBase.ttl} is not set.
1363
- *
1364
- * @default false
1365
1484
  */
1366
1485
  updateAgeOnHas?: boolean;
1367
1486
  /**
1368
1487
  * Allow {@link LRUCache#get} and {@link LRUCache#fetch} calls to return
1369
1488
  * stale data, if available.
1489
+ *
1490
+ * By default, if you set `ttl`, stale items will only be deleted from the
1491
+ * cache when you `get(key)`. That is, it's not preemptively pruning items,
1492
+ * unless {@link OptionsBase.ttlAutopurge} is set.
1493
+ *
1494
+ * If you set `allowStale:true`, it'll return the stale value *as well as*
1495
+ * deleting it. If you don't set this, then it'll return `undefined` when
1496
+ * you try to get a stale entry.
1497
+ *
1498
+ * Note that when a stale entry is fetched, _even if it is returned due to
1499
+ * `allowStale` being set_, it is removed from the cache immediately. You
1500
+ * can suppress this behavior by setting
1501
+ * {@link OptionsBase.noDeleteOnStaleGet}, either in the constructor, or in
1502
+ * the options provided to {@link LRUCache#get}.
1503
+ *
1504
+ * This may be overridden by passing an options object to `cache.get()`.
1505
+ * The `cache.has()` method will always return `false` for stale items.
1506
+ *
1507
+ * Only relevant if a ttl is set.
1370
1508
  */
1371
1509
  allowStale?: boolean;
1372
1510
  /**
1373
- * Function that is called on items when they are dropped from the cache.
1374
- * This can be handy if you want to close file descriptors or do other
1375
- * cleanup tasks when items are no longer accessible. Called with `key,
1376
- * value`. It's called before actually removing the item from the
1377
- * internal cache, so it is *NOT* safe to re-add them.
1378
- *
1379
- * Use {@link OptionsBase.disposeAfter} if you wish to dispose items after
1380
- * they have been full removed, when it is safe to add them back to the
1381
- * cache.
1511
+ * Function that is called on items when they are dropped from the
1512
+ * cache, as `dispose(value, key, reason)`.
1513
+ *
1514
+ * This can be handy if you want to close file descriptors or do
1515
+ * other cleanup tasks when items are no longer stored in the cache.
1516
+ *
1517
+ * **NOTE**: It is called _before_ the item has been fully removed
1518
+ * from the cache, so if you want to put it right back in, you need
1519
+ * to wait until the next tick. If you try to add it back in during
1520
+ * the `dispose()` function call, it will break things in subtle and
1521
+ * weird ways.
1522
+ *
1523
+ * Unlike several other options, this may _not_ be overridden by
1524
+ * passing an option to `set()`, for performance reasons.
1525
+ *
1526
+ * The `reason` will be one of the following strings, corresponding
1527
+ * to the reason for the item's deletion:
1528
+ *
1529
+ * - `evict` Item was evicted to make space for a new addition
1530
+ * - `set` Item was overwritten by a new value
1531
+ * - `expire` Item expired its TTL
1532
+ * - `fetch` Item was deleted due to a failed or aborted fetch, or a
1533
+ * fetchMethod returning `undefined.
1534
+ * - `delete` Item was removed by explicit `cache.delete(key)`,
1535
+ * `cache.clear()`, or `cache.set(key, undefined)`.
1382
1536
  */
1383
1537
  dispose?: Disposer<K, V>;
1384
1538
  /**
1385
1539
  * The same as {@link OptionsBase.dispose}, but called *after* the entry
1386
1540
  * is completely removed and the cache is once again in a clean state.
1541
+ *
1387
1542
  * It is safe to add an item right back into the cache at this point.
1388
1543
  * However, note that it is *very* easy to inadvertently create infinite
1389
1544
  * recursion this way.
@@ -1393,26 +1548,43 @@ declare namespace LRUCache {
1393
1548
  * Set to true to suppress calling the
1394
1549
  * {@link OptionsBase.dispose} function if the entry key is
1395
1550
  * still accessible within the cache.
1551
+ *
1396
1552
  * This may be overridden by passing an options object to
1397
1553
  * {@link LRUCache#set}.
1554
+ *
1555
+ * Only relevant if `dispose` or `disposeAfter` are set.
1398
1556
  */
1399
1557
  noDisposeOnSet?: boolean;
1400
1558
  /**
1401
- * Boolean flag to tell the cache to not update the TTL when
1402
- * setting a new value for an existing key (ie, when updating a value
1403
- * rather than inserting a new value). Note that the TTL value is
1404
- * _always_ set (if provided) when adding a new entry into the cache.
1559
+ * Boolean flag to tell the cache to not update the TTL when setting a new
1560
+ * value for an existing key (ie, when updating a value rather than
1561
+ * inserting a new value). Note that the TTL value is _always_ set (if
1562
+ * provided) when adding a new entry into the cache.
1405
1563
  *
1406
1564
  * Has no effect if a {@link OptionsBase.ttl} is not set.
1565
+ *
1566
+ * May be passed as an option to {@link LRUCache#set}.
1407
1567
  */
1408
1568
  noUpdateTTL?: boolean;
1409
1569
  /**
1410
- * If you wish to track item size, you must provide a maxSize
1411
- * note that we still will only keep up to max *actual items*,
1412
- * if max is set, so size tracking may cause fewer than max items
1413
- * to be stored. At the extreme, a single item of maxSize size
1414
- * will cause everything else in the cache to be dropped when it
1415
- * is added. Use with caution!
1570
+ * Set to a positive integer to track the sizes of items added to the
1571
+ * cache, and automatically evict items in order to stay below this size.
1572
+ * Note that this may result in fewer than `max` items being stored.
1573
+ *
1574
+ * Attempting to add an item to the cache whose calculated size is greater
1575
+ * that this amount will be a no-op. The item will not be cached, and no
1576
+ * other items will be evicted.
1577
+ *
1578
+ * Optional, must be a positive integer if provided.
1579
+ *
1580
+ * Sets `maxEntrySize` to the same value, unless a different value is
1581
+ * provided for `maxEntrySize`.
1582
+ *
1583
+ * At least one of `max`, `maxSize`, or `TTL` is required. This must be a
1584
+ * positive integer if set.
1585
+ *
1586
+ * Even if size tracking is enabled, **it is strongly recommended to set a
1587
+ * `max` to prevent unbounded growth of the cache.**
1416
1588
  *
1417
1589
  * Note also that size tracking can negatively impact performance,
1418
1590
  * though for most cases, only minimally.
@@ -1422,13 +1594,22 @@ declare namespace LRUCache {
1422
1594
  * The maximum allowed size for any single item in the cache.
1423
1595
  *
1424
1596
  * If a larger item is passed to {@link LRUCache#set} or returned by a
1425
- * {@link OptionsBase.fetchMethod}, then it will not be stored in the
1426
- * cache.
1597
+ * {@link OptionsBase.fetchMethod} or {@link OptionsBase.memoMethod}, then
1598
+ * it will not be stored in the cache.
1599
+ *
1600
+ * Attempting to add an item whose calculated size is greater than
1601
+ * this amount will not cache the item or evict any old items, but
1602
+ * WILL delete an existing value if one is already present.
1603
+ *
1604
+ * Optional, must be a positive integer if provided. Defaults to
1605
+ * the value of `maxSize` if provided.
1427
1606
  */
1428
1607
  maxEntrySize?: Size;
1429
1608
  /**
1430
1609
  * A function that returns a number indicating the item's size.
1431
1610
  *
1611
+ * Requires {@link OptionsBase.maxSize} to be set.
1612
+ *
1432
1613
  * If not provided, and {@link OptionsBase.maxSize} or
1433
1614
  * {@link OptionsBase.maxEntrySize} are set, then all
1434
1615
  * {@link LRUCache#set} calls **must** provide an explicit
@@ -1437,8 +1618,41 @@ declare namespace LRUCache {
1437
1618
  sizeCalculation?: SizeCalculator<K, V>;
1438
1619
  /**
1439
1620
  * Method that provides the implementation for {@link LRUCache#fetch}
1621
+ *
1622
+ * ```ts
1623
+ * fetchMethod(key, staleValue, { signal, options, context })
1624
+ * ```
1625
+ *
1626
+ * If `fetchMethod` is not provided, then `cache.fetch(key)` is equivalent
1627
+ * to `Promise.resolve(cache.get(key))`.
1628
+ *
1629
+ * If at any time, `signal.aborted` is set to `true`, or if the
1630
+ * `signal.onabort` method is called, or if it emits an `'abort'` event
1631
+ * which you can listen to with `addEventListener`, then that means that
1632
+ * the fetch should be abandoned. This may be passed along to async
1633
+ * functions aware of AbortController/AbortSignal behavior.
1634
+ *
1635
+ * The `fetchMethod` should **only** return `undefined` or a Promise
1636
+ * resolving to `undefined` if the AbortController signaled an `abort`
1637
+ * event. In all other cases, it should return or resolve to a value
1638
+ * suitable for adding to the cache.
1639
+ *
1640
+ * The `options` object is a union of the options that may be provided to
1641
+ * `set()` and `get()`. If they are modified, then that will result in
1642
+ * modifying the settings to `cache.set()` when the value is resolved, and
1643
+ * in the case of
1644
+ * {@link OptionsBase.noDeleteOnFetchRejection} and
1645
+ * {@link OptionsBase.allowStaleOnFetchRejection}, the handling of
1646
+ * `fetchMethod` failures.
1647
+ *
1648
+ * For example, a DNS cache may update the TTL based on the value returned
1649
+ * from a remote DNS server by changing `options.ttl` in the `fetchMethod`.
1440
1650
  */
1441
1651
  fetchMethod?: Fetcher<K, V, FC>;
1652
+ /**
1653
+ * Method that provides the implementation for {@link LRUCache#memo}
1654
+ */
1655
+ memoMethod?: Memoizer<K, V, FC>;
1442
1656
  /**
1443
1657
  * Set to true to suppress the deletion of stale data when a
1444
1658
  * {@link OptionsBase.fetchMethod} returns a rejected promise.
@@ -1450,6 +1664,18 @@ declare namespace LRUCache {
1450
1664
  *
1451
1665
  * Note that the `get` return value will still be `undefined`
1452
1666
  * unless {@link OptionsBase.allowStale} is true.
1667
+ *
1668
+ * When using time-expiring entries with `ttl`, by default stale
1669
+ * items will be removed from the cache when the key is accessed
1670
+ * with `cache.get()`.
1671
+ *
1672
+ * Setting this option will cause stale items to remain in the cache, until
1673
+ * they are explicitly deleted with `cache.delete(key)`, or retrieved with
1674
+ * `noDeleteOnStaleGet` set to `false`.
1675
+ *
1676
+ * This may be overridden by passing an options object to `cache.get()`.
1677
+ *
1678
+ * Only relevant if a ttl is used.
1453
1679
  */
1454
1680
  noDeleteOnStaleGet?: boolean;
1455
1681
  /**
@@ -1458,14 +1684,24 @@ declare namespace LRUCache {
1458
1684
  * promise.
1459
1685
  *
1460
1686
  * This differs from using {@link OptionsBase.allowStale} in that stale
1461
- * data will ONLY be returned in the case that the
1462
- * {@link LRUCache#fetch} fails, not any other times.
1687
+ * data will ONLY be returned in the case that the {@link LRUCache#fetch}
1688
+ * fails, not any other times.
1689
+ *
1690
+ * If a `fetchMethod` fails, and there is no stale value available, the
1691
+ * `fetch()` will resolve to `undefined`. Ie, all `fetchMethod` errors are
1692
+ * suppressed.
1693
+ *
1694
+ * Implies `noDeleteOnFetchRejection`.
1695
+ *
1696
+ * This may be set in calls to `fetch()`, or defaulted on the constructor,
1697
+ * or overridden by modifying the options object in the `fetchMethod`.
1463
1698
  */
1464
1699
  allowStaleOnFetchRejection?: boolean;
1465
1700
  /**
1466
1701
  * Set to true to return a stale value from the cache when the
1467
- * `AbortSignal` passed to the {@link OptionsBase.fetchMethod} dispatches an `'abort'`
1468
- * event, whether user-triggered, or due to internal cache behavior.
1702
+ * `AbortSignal` passed to the {@link OptionsBase.fetchMethod} dispatches
1703
+ * an `'abort'` event, whether user-triggered, or due to internal cache
1704
+ * behavior.
1469
1705
  *
1470
1706
  * Unless {@link OptionsBase.ignoreFetchAbort} is also set, the underlying
1471
1707
  * {@link OptionsBase.fetchMethod} will still be considered canceled, and
@@ -1501,9 +1737,9 @@ declare namespace LRUCache {
1501
1737
  * object passed to {@link OptionsBase.fetchMethod}, and still cache the
1502
1738
  * resulting resolution value, as long as it is not `undefined`.
1503
1739
  *
1504
- * When used on its own, this means aborted {@link LRUCache#fetch} calls are not
1505
- * immediately resolved or rejected when they are aborted, and instead
1506
- * take the full time to await.
1740
+ * When used on its own, this means aborted {@link LRUCache#fetch} calls
1741
+ * are not immediately resolved or rejected when they are aborted, and
1742
+ * instead take the full time to await.
1507
1743
  *
1508
1744
  * When used with {@link OptionsBase.allowStaleOnFetchAbort}, aborted
1509
1745
  * {@link LRUCache#fetch} calls will resolve immediately to their stale
@@ -1512,6 +1748,26 @@ declare namespace LRUCache {
1512
1748
  * not `undefined`, thus supporting a "return stale on timeout while
1513
1749
  * refreshing" mechanism by passing `AbortSignal.timeout(n)` as the signal.
1514
1750
  *
1751
+ * For example:
1752
+ *
1753
+ * ```ts
1754
+ * const c = new LRUCache({
1755
+ * ttl: 100,
1756
+ * ignoreFetchAbort: true,
1757
+ * allowStaleOnFetchAbort: true,
1758
+ * fetchMethod: async (key, oldValue, { signal }) => {
1759
+ * // note: do NOT pass the signal to fetch()!
1760
+ * // let's say this fetch can take a long time.
1761
+ * const res = await fetch(`https://slow-backend-server/${key}`)
1762
+ * return await res.json()
1763
+ * },
1764
+ * })
1765
+ *
1766
+ * // this will return the stale value after 100ms, while still
1767
+ * // updating in the background for next time.
1768
+ * const val = await c.fetch('key', { signal: AbortSignal.timeout(100) })
1769
+ * ```
1770
+ *
1515
1771
  * **Note**: regardless of this setting, an `abort` event _is still
1516
1772
  * emitted on the `AbortSignal` object_, so may result in invalid results
1517
1773
  * when passed to other underlying APIs that use AbortSignals.
@@ -1549,13 +1805,19 @@ declare namespace LRUCache {
1549
1805
  /**
1550
1806
  * Default export, the thing you're using this module to get.
1551
1807
  *
1552
- * All properties from the options object (with the exception of
1553
- * {@link OptionsBase.max} and {@link OptionsBase.maxSize}) are added as
1554
- * normal public members. (`max` and `maxBase` are read-only getters.)
1555
- * Changing any of these will alter the defaults for subsequent method calls,
1556
- * but is otherwise safe.
1808
+ * The `K` and `V` types define the key and value types, respectively. The
1809
+ * optional `FC` type defines the type of the `context` object passed to
1810
+ * `cache.fetch()` and `cache.memo()`.
1811
+ *
1812
+ * Keys and values **must not** be `null` or `undefined`.
1813
+ *
1814
+ * All properties from the options object (with the exception of `max`,
1815
+ * `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
1816
+ * added as normal public members. (The listed options are read-only getters.)
1817
+ *
1818
+ * Changing any of these will alter the defaults for subsequent method calls.
1557
1819
  */
1558
- declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<K, V> {
1820
+ declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
1559
1821
  #private;
1560
1822
  /**
1561
1823
  * {@link LRUCache.OptionsBase.ttl}
@@ -1638,7 +1900,7 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1638
1900
  readonly head: Index;
1639
1901
  readonly tail: Index;
1640
1902
  free: StackLike;
1641
- isBackgroundFetch: (p: any) => boolean;
1903
+ isBackgroundFetch: (p: any) => p is BackgroundFetch<V>;
1642
1904
  backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: any) => BackgroundFetch<V>;
1643
1905
  moveToTail: (index: number) => void;
1644
1906
  indexes: (options?: {
@@ -1669,6 +1931,7 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1669
1931
  * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
1670
1932
  */
1671
1933
  get fetchMethod(): LRUCache.Fetcher<K, V, FC> | undefined;
1934
+ get memoMethod(): LRUCache.Memoizer<K, V, FC> | undefined;
1672
1935
  /**
1673
1936
  * {@link LRUCache.OptionsBase.dispose} (read-only)
1674
1937
  */
@@ -1679,7 +1942,8 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1679
1942
  get disposeAfter(): LRUCache.Disposer<K, V> | undefined;
1680
1943
  constructor(options: LRUCache.Options<K, V, FC> | LRUCache<K, V, FC>);
1681
1944
  /**
1682
- * Return the remaining TTL time for a given entry key
1945
+ * Return the number of ms left in the item's TTL. If item is not in cache,
1946
+ * returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
1683
1947
  */
1684
1948
  getRemainingTTL(key: K): number;
1685
1949
  /**
@@ -1693,7 +1957,7 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1693
1957
  * Return a generator yielding `[key, value]` pairs,
1694
1958
  * in order from least recently used to most recently used.
1695
1959
  */
1696
- rentries(): Generator<(K | V | BackgroundFetch<V> | undefined)[], void, unknown>;
1960
+ rentries(): Generator<(K | V)[], void, unknown>;
1697
1961
  /**
1698
1962
  * Return a generator yielding the keys in the cache,
1699
1963
  * in order from most recently used to least recently used.
@@ -1717,27 +1981,33 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1717
1981
  * Return a generator yielding the values in the cache,
1718
1982
  * in order from least recently used to most recently used.
1719
1983
  */
1720
- rvalues(): Generator<V | BackgroundFetch<V> | undefined, void, unknown>;
1984
+ rvalues(): Generator<V | undefined, void, unknown>;
1721
1985
  /**
1722
1986
  * Iterating over the cache itself yields the same results as
1723
1987
  * {@link LRUCache.entries}
1724
1988
  */
1725
1989
  [Symbol.iterator](): Generator<[K, V], void, unknown>;
1726
1990
  /**
1727
- * A String value that is used in the creation of the default string description of an object.
1728
- * Called by the built-in method Object.prototype.toString.
1991
+ * A String value that is used in the creation of the default string
1992
+ * description of an object. Called by the built-in method
1993
+ * `Object.prototype.toString`.
1729
1994
  */
1730
1995
  [Symbol.toStringTag]: string;
1731
1996
  /**
1732
1997
  * Find a value for which the supplied fn method returns a truthy value,
1733
- * similar to Array.find(). fn is called as fn(value, key, cache).
1998
+ * similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
1734
1999
  */
1735
2000
  find(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => boolean, getOptions?: LRUCache.GetOptions<K, V, FC>): V | undefined;
1736
2001
  /**
1737
- * Call the supplied function on each item in the cache, in order from
1738
- * most recently used to least recently used. fn is called as
1739
- * fn(value, key, cache). Does not update age or recenty of use.
1740
- * Does not iterate over stale values.
2002
+ * Call the supplied function on each item in the cache, in order from most
2003
+ * recently used to least recently used.
2004
+ *
2005
+ * `fn` is called as `fn(value, key, cache)`.
2006
+ *
2007
+ * If `thisp` is provided, function will be called in the `this`-context of
2008
+ * the provided object, or the cache if no `thisp` object is provided.
2009
+ *
2010
+ * Does not update age or recenty of use, or iterate over stale values.
1741
2011
  */
1742
2012
  forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
1743
2013
  /**
@@ -1752,20 +2022,39 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1752
2022
  purgeStale(): boolean;
1753
2023
  /**
1754
2024
  * Get the extended info about a given entry, to get its value, size, and
1755
- * TTL info simultaneously. Like {@link LRUCache#dump}, but just for a
1756
- * single key. Always returns stale values, if their info is found in the
1757
- * cache, so be sure to check for expired TTLs if relevant.
2025
+ * TTL info simultaneously. Returns `undefined` if the key is not present.
2026
+ *
2027
+ * Unlike {@link LRUCache#dump}, which is designed to be portable and survive
2028
+ * serialization, the `start` value is always the current timestamp, and the
2029
+ * `ttl` is a calculated remaining time to live (negative if expired).
2030
+ *
2031
+ * Always returns stale values, if their info is found in the cache, so be
2032
+ * sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
2033
+ * if relevant.
1758
2034
  */
1759
2035
  info(key: K): LRUCache.Entry<V> | undefined;
1760
2036
  /**
1761
2037
  * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
1762
- * passed to cache.load()
2038
+ * passed to {@link LRUCache#load}.
2039
+ *
2040
+ * The `start` fields are calculated relative to a portable `Date.now()`
2041
+ * timestamp, even if `performance.now()` is available.
2042
+ *
2043
+ * Stale entries are always included in the `dump`, even if
2044
+ * {@link LRUCache.OptionsBase.allowStale} is false.
2045
+ *
2046
+ * Note: this returns an actual array, not a generator, so it can be more
2047
+ * easily passed around.
1763
2048
  */
1764
2049
  dump(): [K, LRUCache.Entry<V>][];
1765
2050
  /**
1766
2051
  * Reset the cache and load in the items in entries in the order listed.
1767
- * Note that the shape of the resulting cache may be different if the
1768
- * same options are not used in both caches.
2052
+ *
2053
+ * The shape of the resulting cache may be different if the same options are
2054
+ * not used in both caches.
2055
+ *
2056
+ * The `start` fields are assumed to be calculated relative to a portable
2057
+ * `Date.now()` timestamp, even if `performance.now()` is available.
1769
2058
  */
1770
2059
  load(arr: [K, LRUCache.Entry<V>][]): void;
1771
2060
  /**
@@ -1773,6 +2062,30 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1773
2062
  *
1774
2063
  * Note: if `undefined` is specified as a value, this is an alias for
1775
2064
  * {@link LRUCache#delete}
2065
+ *
2066
+ * Fields on the {@link LRUCache.SetOptions} options param will override
2067
+ * their corresponding values in the constructor options for the scope
2068
+ * of this single `set()` operation.
2069
+ *
2070
+ * If `start` is provided, then that will set the effective start
2071
+ * time for the TTL calculation. Note that this must be a previous
2072
+ * value of `performance.now()` if supported, or a previous value of
2073
+ * `Date.now()` if not.
2074
+ *
2075
+ * Options object may also include `size`, which will prevent
2076
+ * calling the `sizeCalculation` function and just use the specified
2077
+ * number if it is a positive integer, and `noDisposeOnSet` which
2078
+ * will prevent calling a `dispose` function in the case of
2079
+ * overwrites.
2080
+ *
2081
+ * If the `size` (or return value of `sizeCalculation`) for a given
2082
+ * entry is greater than `maxEntrySize`, then the item will not be
2083
+ * added to the cache.
2084
+ *
2085
+ * Will update the recency of the entry.
2086
+ *
2087
+ * If the value is `undefined`, then this is an alias for
2088
+ * `cache.delete(key)`. `undefined` is never stored in the cache.
1776
2089
  */
1777
2090
  set(k: K, v: V | BackgroundFetch<V> | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
1778
2091
  /**
@@ -1785,6 +2098,14 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1785
2098
  * Will return false if the item is stale, even though it is technically
1786
2099
  * in the cache.
1787
2100
  *
2101
+ * Check if a key is in the cache, without updating the recency of
2102
+ * use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
2103
+ * to `true` in either the options or the constructor.
2104
+ *
2105
+ * Will return `false` if the item is stale, even though it is technically in
2106
+ * the cache. The difference can be determined (if it matters) by using a
2107
+ * `status` argument, and inspecting the `has` field.
2108
+ *
1788
2109
  * Will not update item age unless
1789
2110
  * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
1790
2111
  */
@@ -1801,6 +2122,25 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1801
2122
  * Make an asynchronous cached fetch using the
1802
2123
  * {@link LRUCache.OptionsBase.fetchMethod} function.
1803
2124
  *
2125
+ * If the value is in the cache and not stale, then the returned
2126
+ * Promise resolves to the value.
2127
+ *
2128
+ * If not in the cache, or beyond its TTL staleness, then
2129
+ * `fetchMethod(key, staleValue, { options, signal, context })` is
2130
+ * called, and the value returned will be added to the cache once
2131
+ * resolved.
2132
+ *
2133
+ * If called with `allowStale`, and an asynchronous fetch is
2134
+ * currently in progress to reload a stale value, then the former
2135
+ * stale value will be returned.
2136
+ *
2137
+ * If called with `forceRefresh`, then the cached item will be
2138
+ * re-fetched, even if it is not stale. However, if `allowStale` is also
2139
+ * set, then the old value will still be returned. This is useful
2140
+ * in cases where you want to force a reload of a cached value. If
2141
+ * a background fetch is already in progress, then `forceRefresh`
2142
+ * has no effect.
2143
+ *
1804
2144
  * If multiple fetches for the same key are issued, then they will all be
1805
2145
  * coalesced into a single call to fetchMethod.
1806
2146
  *
@@ -1813,9 +2153,89 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1813
2153
  * This is a known (fixable) shortcoming which will be addresed on when
1814
2154
  * someone complains about it, as the fix would involve added complexity and
1815
2155
  * may not be worth the costs for this edge case.
2156
+ *
2157
+ * If {@link LRUCache.OptionsBase.fetchMethod} is not specified, then this is
2158
+ * effectively an alias for `Promise.resolve(cache.get(key))`.
2159
+ *
2160
+ * When the fetch method resolves to a value, if the fetch has not
2161
+ * been aborted due to deletion, eviction, or being overwritten,
2162
+ * then it is added to the cache using the options provided.
2163
+ *
2164
+ * If the key is evicted or deleted before the `fetchMethod`
2165
+ * resolves, then the AbortSignal passed to the `fetchMethod` will
2166
+ * receive an `abort` event, and the promise returned by `fetch()`
2167
+ * will reject with the reason for the abort.
2168
+ *
2169
+ * If a `signal` is passed to the `fetch()` call, then aborting the
2170
+ * signal will abort the fetch and cause the `fetch()` promise to
2171
+ * reject with the reason provided.
2172
+ *
2173
+ * **Setting `context`**
2174
+ *
2175
+ * If an `FC` type is set to a type other than `unknown`, `void`, or
2176
+ * `undefined` in the {@link LRUCache} constructor, then all
2177
+ * calls to `cache.fetch()` _must_ provide a `context` option. If
2178
+ * set to `undefined` or `void`, then calls to fetch _must not_
2179
+ * provide a `context` option.
2180
+ *
2181
+ * The `context` param allows you to provide arbitrary data that
2182
+ * might be relevant in the course of fetching the data. It is only
2183
+ * relevant for the course of a single `fetch()` operation, and
2184
+ * discarded afterwards.
2185
+ *
2186
+ * **Note: `fetch()` calls are inflight-unique**
2187
+ *
2188
+ * If you call `fetch()` multiple times with the same key value,
2189
+ * then every call after the first will resolve on the same
2190
+ * promise<sup>1</sup>,
2191
+ * _even if they have different settings that would otherwise change
2192
+ * the behavior of the fetch_, such as `noDeleteOnFetchRejection`
2193
+ * or `ignoreFetchAbort`.
2194
+ *
2195
+ * In most cases, this is not a problem (in fact, only fetching
2196
+ * something once is what you probably want, if you're caching in
2197
+ * the first place). If you are changing the fetch() options
2198
+ * dramatically between runs, there's a good chance that you might
2199
+ * be trying to fit divergent semantics into a single object, and
2200
+ * would be better off with multiple cache instances.
2201
+ *
2202
+ * **1**: Ie, they're not the "same Promise", but they resolve at
2203
+ * the same time, because they're both waiting on the same
2204
+ * underlying fetchMethod response.
1816
2205
  */
1817
2206
  fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
1818
2207
  fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<undefined | V>;
2208
+ /**
2209
+ * In some cases, `cache.fetch()` may resolve to `undefined`, either because
2210
+ * a {@link LRUCache.OptionsBase#fetchMethod} was not provided (turning
2211
+ * `cache.fetch(k)` into just an async wrapper around `cache.get(k)`) or
2212
+ * because `ignoreFetchAbort` was specified (either to the constructor or
2213
+ * in the {@link LRUCache.FetchOptions}). Also, the
2214
+ * {@link LRUCache.OptionsBase.fetchMethod} may return `undefined` or `void`, making
2215
+ * the test even more complicated.
2216
+ *
2217
+ * Because inferring the cases where `undefined` might be returned are so
2218
+ * cumbersome, but testing for `undefined` can also be annoying, this method
2219
+ * can be used, which will reject if `this.fetch()` resolves to undefined.
2220
+ */
2221
+ forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
2222
+ forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<V>;
2223
+ /**
2224
+ * If the key is found in the cache, then this is equivalent to
2225
+ * {@link LRUCache#get}. If not, in the cache, then calculate the value using
2226
+ * the {@link LRUCache.OptionsBase.memoMethod}, and add it to the cache.
2227
+ *
2228
+ * If an `FC` type is set to a type other than `unknown`, `void`, or
2229
+ * `undefined` in the LRUCache constructor, then all calls to `cache.memo()`
2230
+ * _must_ provide a `context` option. If set to `undefined` or `void`, then
2231
+ * calls to memo _must not_ provide a `context` option.
2232
+ *
2233
+ * The `context` param allows you to provide arbitrary data that might be
2234
+ * relevant in the course of fetching the data. It is only relevant for the
2235
+ * course of a single `memo()` operation, and discarded afterwards.
2236
+ */
2237
+ memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
2238
+ memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : never): V;
1819
2239
  /**
1820
2240
  * Return a value from the cache. Will update the recency of the cache
1821
2241
  * entry found.
@@ -1825,6 +2245,7 @@ declare class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<
1825
2245
  get(k: K, getOptions?: LRUCache.GetOptions<K, V, FC>): V | undefined;
1826
2246
  /**
1827
2247
  * Deletes a key out of the cache.
2248
+ *
1828
2249
  * Returns true if the key was deleted, false otherwise.
1829
2250
  */
1830
2251
  delete(k: K): boolean;
@@ -1973,6 +2394,11 @@ declare abstract class PathBase implements Dirent {
1973
2394
  * @internal
1974
2395
  */
1975
2396
  nocase: boolean;
2397
+ /**
2398
+ * boolean indicating that this path is the current working directory
2399
+ * of the PathScurry collection that contains it.
2400
+ */
2401
+ isCWD: boolean;
1976
2402
  /**
1977
2403
  * the string or regexp used to split paths. On posix, it is `'/'`, and on
1978
2404
  * windows it is a RegExp matching either `'/'` or `'\\'`
@@ -2002,10 +2428,16 @@ declare abstract class PathBase implements Dirent {
2002
2428
  get birthtime(): Date | undefined;
2003
2429
  /**
2004
2430
  * This property is for compatibility with the Dirent class as of
2005
- * Node v20, where Dirent['path'] refers to the path of the directory
2006
- * that was passed to readdir. So, somewhat counterintuitively, this
2007
- * property refers to the *parent* path, not the path object itself.
2008
- * For root entries, it's the path to the entry itself.
2431
+ * Node v20, where Dirent['parentPath'] refers to the path of the
2432
+ * directory that was passed to readdir. For root entries, it's the path
2433
+ * to the entry itself.
2434
+ */
2435
+ get parentPath(): string;
2436
+ /**
2437
+ * Deprecated alias for Dirent['parentPath'] Somewhat counterintuitively,
2438
+ * this property refers to the *parent* path, not the path object itself.
2439
+ *
2440
+ * @deprecated
2009
2441
  */
2010
2442
  get path(): string;
2011
2443
  /**
@@ -2435,7 +2867,7 @@ declare abstract class PathScurryBase {
2435
2867
  *
2436
2868
  * @internal
2437
2869
  */
2438
- constructor(cwd: string | URL | undefined, pathImpl: typeof win32 | typeof posix, sep: string | RegExp, { nocase, childrenCacheSize, fs, }?: PathScurryOpts);
2870
+ constructor(cwd: (URL | string) | undefined, pathImpl: typeof win32 | typeof posix, sep: string | RegExp, { nocase, childrenCacheSize, fs, }?: PathScurryOpts);
2439
2871
  /**
2440
2872
  * Get the depth of a provided path, string, or the cwd
2441
2873
  */
@@ -2929,6 +3361,7 @@ type PathScurry = PathScurryBase | InstanceType<typeof PathScurry>;
2929
3361
  interface IgnoreLike {
2930
3362
  ignored?: (p: Path) => boolean;
2931
3363
  childrenIgnored?: (p: Path) => boolean;
3364
+ add?: (ignore: string) => void;
2932
3365
  }
2933
3366
 
2934
3367
  /**
@@ -2999,7 +3432,7 @@ interface GlobOptions {
2999
3432
  */
3000
3433
  follow?: boolean;
3001
3434
  /**
3002
- * string or string[], or an object with `ignore` and `ignoreChildren`
3435
+ * string or string[], or an object with `ignored` and `childrenIgnored`
3003
3436
  * methods.
3004
3437
  *
3005
3438
  * If a string or string[] is provided, then this is treated as a glob
@@ -3172,6 +3605,50 @@ interface GlobOptions {
3172
3605
  * `'//?/C:/foo/bar'`
3173
3606
  */
3174
3607
  posix?: boolean;
3608
+ /**
3609
+ * Do not match any children of any matches. For example, the pattern
3610
+ * `**\/foo` would match `a/foo`, but not `a/foo/b/foo` in this mode.
3611
+ *
3612
+ * This is especially useful for cases like "find all `node_modules`
3613
+ * folders, but not the ones in `node_modules`".
3614
+ *
3615
+ * In order to support this, the `Ignore` implementation must support an
3616
+ * `add(pattern: string)` method. If using the default `Ignore` class, then
3617
+ * this is fine, but if this is set to `false`, and a custom `Ignore` is
3618
+ * provided that does not have an `add()` method, then it will throw an
3619
+ * error.
3620
+ *
3621
+ * **Caveat** It *only* ignores matches that would be a descendant of a
3622
+ * previous match, and only if that descendant is matched *after* the
3623
+ * ancestor is encountered. Since the file system walk happens in
3624
+ * indeterminate order, it's possible that a match will already be added
3625
+ * before its ancestor, if multiple or braced patterns are used.
3626
+ *
3627
+ * For example:
3628
+ *
3629
+ * ```ts
3630
+ * const results = await glob([
3631
+ * // likely to match first, since it's just a stat
3632
+ * 'a/b/c/d/e/f',
3633
+ *
3634
+ * // this pattern is more complicated! It must to various readdir()
3635
+ * // calls and test the results against a regular expression, and that
3636
+ * // is certainly going to take a little bit longer.
3637
+ * //
3638
+ * // So, later on, it encounters a match at 'a/b/c/d/e', but it's too
3639
+ * // late to ignore a/b/c/d/e/f, because it's already been emitted.
3640
+ * 'a/[bdf]/?/[a-z]/*',
3641
+ * ], { includeChildMatches: false })
3642
+ * ```
3643
+ *
3644
+ * It's best to only set this to `false` if you can be reasonably sure that
3645
+ * no components of the pattern will potentially match one another's file
3646
+ * system descendants, or if the occasional included child entry will not
3647
+ * cause problems.
3648
+ *
3649
+ * @default true
3650
+ */
3651
+ includeChildMatches?: boolean;
3175
3652
  }
3176
3653
  type GlobOptionsWithFileTypesTrue = GlobOptions & {
3177
3654
  withFileTypes: true;