@cloudsnorkel/cdk-github-runners 0.10.3 → 0.10.5

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 (52) hide show
  1. package/.gitattributes +1 -1
  2. package/.jsii +69 -30
  3. package/API.md +42 -7
  4. package/SETUP_GITHUB.md +16 -12
  5. package/TESTING.md +61 -0
  6. package/assets/{delete-runner.lambda → delete-failed-runner.lambda}/index.js +2031 -518
  7. package/assets/idle-runner-repear.lambda/index.js +2052 -522
  8. package/assets/image-builders/aws-image-builder/versioner.lambda/index.js +1 -1
  9. package/assets/setup.lambda/index.html +1 -1
  10. package/assets/setup.lambda/index.js +577 -159
  11. package/assets/status.lambda/index.js +1652 -473
  12. package/assets/token-retriever.lambda/index.js +2025 -521
  13. package/lib/access.d.ts +4 -2
  14. package/lib/access.js +7 -5
  15. package/lib/delete-failed-runner-function.d.ts +13 -0
  16. package/lib/delete-failed-runner-function.js +23 -0
  17. package/lib/delete-failed-runner.lambda.js +51 -0
  18. package/lib/idle-runner-repear.lambda.js +43 -10
  19. package/lib/image-builders/api.js +1 -1
  20. package/lib/image-builders/aws-image-builder/builder.js +1 -1
  21. package/lib/image-builders/aws-image-builder/deprecated/ami.js +1 -1
  22. package/lib/image-builders/aws-image-builder/deprecated/container.js +1 -1
  23. package/lib/image-builders/aws-image-builder/deprecated/linux-components.js +1 -1
  24. package/lib/image-builders/aws-image-builder/deprecated/windows-components.js +1 -1
  25. package/lib/image-builders/codebuild-deprecated.js +1 -1
  26. package/lib/image-builders/components.js +1 -1
  27. package/lib/image-builders/static.js +1 -1
  28. package/lib/lambda-github.d.ts +8 -4
  29. package/lib/lambda-github.js +23 -2
  30. package/lib/lambda-helpers.d.ts +5 -1
  31. package/lib/lambda-helpers.js +1 -1
  32. package/lib/providers/codebuild.js +2 -2
  33. package/lib/providers/common.d.ts +2 -0
  34. package/lib/providers/common.js +4 -4
  35. package/lib/providers/ec2.js +2 -2
  36. package/lib/providers/ecs.d.ts +1 -1
  37. package/lib/providers/ecs.js +14 -5
  38. package/lib/providers/fargate.js +2 -2
  39. package/lib/providers/lambda.js +2 -2
  40. package/lib/runner.d.ts +1 -1
  41. package/lib/runner.js +26 -25
  42. package/lib/secrets.d.ts +2 -2
  43. package/lib/secrets.js +2 -2
  44. package/lib/setup.lambda.js +2 -2
  45. package/lib/status.lambda.js +4 -4
  46. package/lib/token-retriever.lambda.js +2 -2
  47. package/lib/webhook.js +2 -2
  48. package/package.json +14 -14
  49. package/lib/delete-runner-function.d.ts +0 -13
  50. package/lib/delete-runner-function.js +0 -23
  51. package/lib/delete-runner.lambda.js +0 -41
  52. /package/lib/{delete-runner.lambda.d.ts → delete-failed-runner.lambda.d.ts} +0 -0
@@ -24,6 +24,24 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
25
  mod
26
26
  ));
27
+ var __accessCheck = (obj, member, msg) => {
28
+ if (!member.has(obj))
29
+ throw TypeError("Cannot " + msg);
30
+ };
31
+ var __privateGet = (obj, member, getter) => {
32
+ __accessCheck(obj, member, "read from private field");
33
+ return getter ? getter.call(obj) : member.get(obj);
34
+ };
35
+ var __privateAdd = (obj, member, value) => {
36
+ if (member.has(obj))
37
+ throw TypeError("Cannot add the same private member more than once");
38
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
39
+ };
40
+ var __privateSet = (obj, member, value, setter) => {
41
+ __accessCheck(obj, member, "write to private field");
42
+ setter ? setter.call(obj, value) : member.set(obj, value);
43
+ return value;
44
+ };
27
45
 
28
46
  // node_modules/universal-user-agent/dist-node/index.js
29
47
  var require_dist_node = __commonJS({
@@ -7249,42 +7267,76 @@ var require_dist_node4 = __commonJS({
7249
7267
 
7250
7268
  // node_modules/@octokit/request/dist-node/index.js
7251
7269
  var require_dist_node5 = __commonJS({
7252
- "node_modules/@octokit/request/dist-node/index.js"(exports2) {
7270
+ "node_modules/@octokit/request/dist-node/index.js"(exports2, module2) {
7253
7271
  "use strict";
7254
- Object.defineProperty(exports2, "__esModule", { value: true });
7255
- function _interopDefault(ex) {
7256
- return ex && typeof ex === "object" && "default" in ex ? ex["default"] : ex;
7257
- }
7258
- var endpoint = require_dist_node2();
7259
- var universalUserAgent = require_dist_node();
7260
- var isPlainObject = require_is_plain_object();
7261
- var nodeFetch = _interopDefault(require_lib3());
7262
- var requestError = require_dist_node4();
7263
- var VERSION = "6.2.3";
7272
+ var __create2 = Object.create;
7273
+ var __defProp2 = Object.defineProperty;
7274
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
7275
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
7276
+ var __getProtoOf2 = Object.getPrototypeOf;
7277
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
7278
+ var __export = (target, all) => {
7279
+ for (var name in all)
7280
+ __defProp2(target, name, { get: all[name], enumerable: true });
7281
+ };
7282
+ var __copyProps2 = (to, from, except, desc) => {
7283
+ if (from && typeof from === "object" || typeof from === "function") {
7284
+ for (let key of __getOwnPropNames2(from))
7285
+ if (!__hasOwnProp2.call(to, key) && key !== except)
7286
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
7287
+ }
7288
+ return to;
7289
+ };
7290
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
7291
+ // If the importer is in node compatibility mode or this is not an ESM
7292
+ // file that has been converted to a CommonJS file using a Babel-
7293
+ // compatible transform (i.e. "__esModule" has not been set), then set
7294
+ // "default" to the CommonJS "module.exports" for node compatibility.
7295
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
7296
+ mod
7297
+ ));
7298
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
7299
+ var dist_src_exports = {};
7300
+ __export(dist_src_exports, {
7301
+ request: () => request
7302
+ });
7303
+ module2.exports = __toCommonJS(dist_src_exports);
7304
+ var import_endpoint = require_dist_node2();
7305
+ var import_universal_user_agent = require_dist_node();
7306
+ var VERSION = "6.2.5";
7307
+ var import_is_plain_object = require_is_plain_object();
7308
+ var import_node_fetch = __toESM2(require_lib3());
7309
+ var import_request_error = require_dist_node4();
7264
7310
  function getBufferResponse(response) {
7265
7311
  return response.arrayBuffer();
7266
7312
  }
7267
7313
  function fetchWrapper(requestOptions) {
7268
7314
  const log = requestOptions.request && requestOptions.request.log ? requestOptions.request.log : console;
7269
- if (isPlainObject.isPlainObject(requestOptions.body) || Array.isArray(requestOptions.body)) {
7315
+ if ((0, import_is_plain_object.isPlainObject)(requestOptions.body) || Array.isArray(requestOptions.body)) {
7270
7316
  requestOptions.body = JSON.stringify(requestOptions.body);
7271
7317
  }
7272
7318
  let headers = {};
7273
7319
  let status;
7274
7320
  let url;
7275
7321
  const fetch = requestOptions.request && requestOptions.request.fetch || globalThis.fetch || /* istanbul ignore next */
7276
- nodeFetch;
7277
- return fetch(requestOptions.url, Object.assign(
7278
- {
7279
- method: requestOptions.method,
7280
- body: requestOptions.body,
7281
- headers: requestOptions.headers,
7282
- redirect: requestOptions.redirect
7283
- },
7284
- // `requestOptions.request.agent` type is incompatible
7285
- // see https://github.com/octokit/types.ts/pull/264
7286
- requestOptions.request
7287
- )).then(async (response) => {
7322
+ import_node_fetch.default;
7323
+ return fetch(
7324
+ requestOptions.url,
7325
+ Object.assign(
7326
+ {
7327
+ method: requestOptions.method,
7328
+ body: requestOptions.body,
7329
+ headers: requestOptions.headers,
7330
+ redirect: requestOptions.redirect,
7331
+ // duplex must be set if request.body is ReadableStream or Async Iterables.
7332
+ // See https://fetch.spec.whatwg.org/#dom-requestinit-duplex.
7333
+ ...requestOptions.body && { duplex: "half" }
7334
+ },
7335
+ // `requestOptions.request.agent` type is incompatible
7336
+ // see https://github.com/octokit/types.ts/pull/264
7337
+ requestOptions.request
7338
+ )
7339
+ ).then(async (response) => {
7288
7340
  url = response.url;
7289
7341
  status = response.status;
7290
7342
  for (const keyAndValue of response.headers) {
@@ -7293,7 +7345,9 @@ var require_dist_node5 = __commonJS({
7293
7345
  if ("deprecation" in headers) {
7294
7346
  const matches = headers.link && headers.link.match(/<([^>]+)>; rel="deprecation"/);
7295
7347
  const deprecationLink = matches && matches.pop();
7296
- log.warn(`[@octokit/request] "${requestOptions.method} ${requestOptions.url}" is deprecated. It is scheduled to be removed on ${headers.sunset}${deprecationLink ? `. See ${deprecationLink}` : ""}`);
7348
+ log.warn(
7349
+ `[@octokit/request] "${requestOptions.method} ${requestOptions.url}" is deprecated. It is scheduled to be removed on ${headers.sunset}${deprecationLink ? `. See ${deprecationLink}` : ""}`
7350
+ );
7297
7351
  }
7298
7352
  if (status === 204 || status === 205) {
7299
7353
  return;
@@ -7302,7 +7356,7 @@ var require_dist_node5 = __commonJS({
7302
7356
  if (status < 400) {
7303
7357
  return;
7304
7358
  }
7305
- throw new requestError.RequestError(response.statusText, status, {
7359
+ throw new import_request_error.RequestError(response.statusText, status, {
7306
7360
  response: {
7307
7361
  url,
7308
7362
  status,
@@ -7313,7 +7367,7 @@ var require_dist_node5 = __commonJS({
7313
7367
  });
7314
7368
  }
7315
7369
  if (status === 304) {
7316
- throw new requestError.RequestError("Not modified", status, {
7370
+ throw new import_request_error.RequestError("Not modified", status, {
7317
7371
  response: {
7318
7372
  url,
7319
7373
  status,
@@ -7325,7 +7379,7 @@ var require_dist_node5 = __commonJS({
7325
7379
  }
7326
7380
  if (status >= 400) {
7327
7381
  const data = await getResponseData(response);
7328
- const error = new requestError.RequestError(toErrorMessage(data), status, {
7382
+ const error = new import_request_error.RequestError(toErrorMessage(data), status, {
7329
7383
  response: {
7330
7384
  url,
7331
7385
  status,
@@ -7345,11 +7399,11 @@ var require_dist_node5 = __commonJS({
7345
7399
  data
7346
7400
  };
7347
7401
  }).catch((error) => {
7348
- if (error instanceof requestError.RequestError)
7402
+ if (error instanceof import_request_error.RequestError)
7349
7403
  throw error;
7350
7404
  else if (error.name === "AbortError")
7351
7405
  throw error;
7352
- throw new requestError.RequestError(error.message, 500, {
7406
+ throw new import_request_error.RequestError(error.message, 500, {
7353
7407
  request: requestOptions
7354
7408
  });
7355
7409
  });
@@ -7383,7 +7437,9 @@ var require_dist_node5 = __commonJS({
7383
7437
  return fetchWrapper(endpoint2.parse(endpointOptions));
7384
7438
  }
7385
7439
  const request2 = (route2, parameters2) => {
7386
- return fetchWrapper(endpoint2.parse(endpoint2.merge(route2, parameters2)));
7440
+ return fetchWrapper(
7441
+ endpoint2.parse(endpoint2.merge(route2, parameters2))
7442
+ );
7387
7443
  };
7388
7444
  Object.assign(request2, {
7389
7445
  endpoint: endpoint2,
@@ -7396,12 +7452,11 @@ var require_dist_node5 = __commonJS({
7396
7452
  defaults: withDefaults.bind(null, endpoint2)
7397
7453
  });
7398
7454
  }
7399
- var request = withDefaults(endpoint.endpoint, {
7455
+ var request = withDefaults(import_endpoint.endpoint, {
7400
7456
  headers: {
7401
- "user-agent": `octokit-request.js/${VERSION} ${universalUserAgent.getUserAgent()}`
7457
+ "user-agent": `octokit-request.js/${VERSION} ${(0, import_universal_user_agent.getUserAgent)()}`
7402
7458
  }
7403
7459
  });
7404
- exports2.request = request;
7405
7460
  }
7406
7461
  });
7407
7462
 
@@ -8049,7 +8104,7 @@ var require_dist_node9 = __commonJS({
8049
8104
  endpoint.headers.authorization = "token " + token;
8050
8105
  return request2(endpoint);
8051
8106
  }
8052
- function createOAuthUserAuth({
8107
+ function createOAuthUserAuth2({
8053
8108
  clientId,
8054
8109
  clientSecret,
8055
8110
  clientType = "oauth-app",
@@ -8074,8 +8129,8 @@ var require_dist_node9 = __commonJS({
8074
8129
  hook: hook.bind(null, state)
8075
8130
  });
8076
8131
  }
8077
- createOAuthUserAuth.VERSION = VERSION;
8078
- exports2.createOAuthUserAuth = createOAuthUserAuth;
8132
+ createOAuthUserAuth2.VERSION = VERSION;
8133
+ exports2.createOAuthUserAuth = createOAuthUserAuth2;
8079
8134
  exports2.requiresBasicAuth = requiresBasicAuth;
8080
8135
  }
8081
8136
  });
@@ -9292,7 +9347,7 @@ var require_semver = __commonJS({
9292
9347
  version = version.version;
9293
9348
  }
9294
9349
  } else if (typeof version !== "string") {
9295
- throw new TypeError(`Invalid Version: ${require("util").inspect(version)}`);
9350
+ throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`);
9296
9351
  }
9297
9352
  if (version.length > MAX_LENGTH) {
9298
9353
  throw new TypeError(
@@ -12555,10 +12610,10 @@ var require_lodash = __commonJS({
12555
12610
  }();
12556
12611
  var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date2 && Date2.now !== root.Date.now && Date2.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
12557
12612
  var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : undefined2, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date2.now, nativeParseInt = context.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
12558
- var DataView = getNative(context, "DataView"), Map2 = getNative(context, "Map"), Promise2 = getNative(context, "Promise"), Set2 = getNative(context, "Set"), WeakMap = getNative(context, "WeakMap"), nativeCreate = getNative(Object2, "create");
12559
- var metaMap = WeakMap && new WeakMap();
12613
+ var DataView = getNative(context, "DataView"), Map2 = getNative(context, "Map"), Promise2 = getNative(context, "Promise"), Set2 = getNative(context, "Set"), WeakMap2 = getNative(context, "WeakMap"), nativeCreate = getNative(Object2, "create");
12614
+ var metaMap = WeakMap2 && new WeakMap2();
12560
12615
  var realNames = {};
12561
- var dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map2), promiseCtorString = toSource(Promise2), setCtorString = toSource(Set2), weakMapCtorString = toSource(WeakMap);
12616
+ var dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map2), promiseCtorString = toSource(Promise2), setCtorString = toSource(Set2), weakMapCtorString = toSource(WeakMap2);
12562
12617
  var symbolProto = Symbol2 ? Symbol2.prototype : undefined2, symbolValueOf = symbolProto ? symbolProto.valueOf : undefined2, symbolToString = symbolProto ? symbolProto.toString : undefined2;
12563
12618
  function lodash(value) {
12564
12619
  if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
@@ -14612,7 +14667,7 @@ var require_lodash = __commonJS({
14612
14667
  return result2;
14613
14668
  };
14614
14669
  var getTag = baseGetTag;
14615
- if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map2 && getTag(new Map2()) != mapTag || Promise2 && getTag(Promise2.resolve()) != promiseTag || Set2 && getTag(new Set2()) != setTag || WeakMap && getTag(new WeakMap()) != weakMapTag) {
14670
+ if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map2 && getTag(new Map2()) != mapTag || Promise2 && getTag(Promise2.resolve()) != promiseTag || Set2 && getTag(new Set2()) != setTag || WeakMap2 && getTag(new WeakMap2()) != weakMapTag) {
14616
14671
  getTag = function(value) {
14617
14672
  var result2 = baseGetTag(value), Ctor = result2 == objectTag ? value.constructor : undefined2, ctorString = Ctor ? toSource(Ctor) : "";
14618
14673
  if (ctorString) {
@@ -17596,298 +17651,1290 @@ var require_dist_node11 = __commonJS({
17596
17651
  }
17597
17652
  });
17598
17653
 
17599
- // node_modules/@octokit/auth-app/node_modules/lru-cache/index.js
17600
- var require_lru_cache2 = __commonJS({
17601
- "node_modules/@octokit/auth-app/node_modules/lru-cache/index.js"(exports2, module2) {
17654
+ // node_modules/@octokit/auth-app/node_modules/lru-cache/dist/cjs/index.js
17655
+ var require_cjs = __commonJS({
17656
+ "node_modules/@octokit/auth-app/node_modules/lru-cache/dist/cjs/index.js"(exports2) {
17602
17657
  "use strict";
17603
- var Yallist = require_yallist();
17604
- var MAX = Symbol("max");
17605
- var LENGTH = Symbol("length");
17606
- var LENGTH_CALCULATOR = Symbol("lengthCalculator");
17607
- var ALLOW_STALE = Symbol("allowStale");
17608
- var MAX_AGE = Symbol("maxAge");
17609
- var DISPOSE = Symbol("dispose");
17610
- var NO_DISPOSE_ON_SET = Symbol("noDisposeOnSet");
17611
- var LRU_LIST = Symbol("lruList");
17612
- var CACHE = Symbol("cache");
17613
- var UPDATE_AGE_ON_GET = Symbol("updateAgeOnGet");
17614
- var naiveLength = () => 1;
17615
- var LRUCache = class {
17616
- constructor(options) {
17617
- if (typeof options === "number")
17618
- options = { max: options };
17619
- if (!options)
17620
- options = {};
17621
- if (options.max && (typeof options.max !== "number" || options.max < 0))
17622
- throw new TypeError("max must be a non-negative number");
17623
- const max = this[MAX] = options.max || Infinity;
17624
- const lc = options.length || naiveLength;
17625
- this[LENGTH_CALCULATOR] = typeof lc !== "function" ? naiveLength : lc;
17626
- this[ALLOW_STALE] = options.stale || false;
17627
- if (options.maxAge && typeof options.maxAge !== "number")
17628
- throw new TypeError("maxAge must be a number");
17629
- this[MAX_AGE] = options.maxAge || 0;
17630
- this[DISPOSE] = options.dispose;
17631
- this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
17632
- this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false;
17633
- this.reset();
17634
- }
17635
- // resize the cache when the max changes.
17636
- set max(mL) {
17637
- if (typeof mL !== "number" || mL < 0)
17638
- throw new TypeError("max must be a non-negative number");
17639
- this[MAX] = mL || Infinity;
17640
- trim(this);
17641
- }
17642
- get max() {
17643
- return this[MAX];
17644
- }
17645
- set allowStale(allowStale) {
17646
- this[ALLOW_STALE] = !!allowStale;
17647
- }
17648
- get allowStale() {
17649
- return this[ALLOW_STALE];
17650
- }
17651
- set maxAge(mA) {
17652
- if (typeof mA !== "number")
17653
- throw new TypeError("maxAge must be a non-negative number");
17654
- this[MAX_AGE] = mA;
17655
- trim(this);
17658
+ Object.defineProperty(exports2, "__esModule", { value: true });
17659
+ exports2.LRUCache = void 0;
17660
+ var perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
17661
+ var warned = /* @__PURE__ */ new Set();
17662
+ var PROCESS = typeof process === "object" && !!process ? process : {};
17663
+ var emitWarning = (msg, type, code, fn) => {
17664
+ typeof PROCESS.emitWarning === "function" ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
17665
+ };
17666
+ var AC = globalThis.AbortController;
17667
+ var AS = globalThis.AbortSignal;
17668
+ var _a;
17669
+ if (typeof AC === "undefined") {
17670
+ AS = class AbortSignal {
17671
+ onabort;
17672
+ _onabort = [];
17673
+ reason;
17674
+ aborted = false;
17675
+ addEventListener(_, fn) {
17676
+ this._onabort.push(fn);
17677
+ }
17678
+ };
17679
+ AC = class AbortController {
17680
+ constructor() {
17681
+ warnACPolyfill();
17682
+ }
17683
+ signal = new AS();
17684
+ abort(reason) {
17685
+ var _a2, _b;
17686
+ if (this.signal.aborted)
17687
+ return;
17688
+ this.signal.reason = reason;
17689
+ this.signal.aborted = true;
17690
+ for (const fn of this.signal._onabort) {
17691
+ fn(reason);
17692
+ }
17693
+ (_b = (_a2 = this.signal).onabort) == null ? void 0 : _b.call(_a2, reason);
17694
+ }
17695
+ };
17696
+ let printACPolyfillWarning = ((_a = PROCESS.env) == null ? void 0 : _a.LRU_CACHE_IGNORE_AC_WARNING) !== "1";
17697
+ const warnACPolyfill = () => {
17698
+ if (!printACPolyfillWarning)
17699
+ return;
17700
+ printACPolyfillWarning = false;
17701
+ emitWarning("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", warnACPolyfill);
17702
+ };
17703
+ }
17704
+ var shouldWarn = (code) => !warned.has(code);
17705
+ var TYPE = Symbol("type");
17706
+ var isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
17707
+ var getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
17708
+ var ZeroArray = class extends Array {
17709
+ constructor(size) {
17710
+ super(size);
17711
+ this.fill(0);
17656
17712
  }
17657
- get maxAge() {
17658
- return this[MAX_AGE];
17713
+ };
17714
+ var _constructing;
17715
+ var _Stack = class {
17716
+ heap;
17717
+ length;
17718
+ static create(max) {
17719
+ const HeapCls = getUintArray(max);
17720
+ if (!HeapCls)
17721
+ return [];
17722
+ __privateSet(_Stack, _constructing, true);
17723
+ const s = new _Stack(max, HeapCls);
17724
+ __privateSet(_Stack, _constructing, false);
17725
+ return s;
17659
17726
  }
17660
- // resize the cache when the lengthCalculator changes.
17661
- set lengthCalculator(lC) {
17662
- if (typeof lC !== "function")
17663
- lC = naiveLength;
17664
- if (lC !== this[LENGTH_CALCULATOR]) {
17665
- this[LENGTH_CALCULATOR] = lC;
17666
- this[LENGTH] = 0;
17667
- this[LRU_LIST].forEach((hit) => {
17668
- hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
17669
- this[LENGTH] += hit.length;
17670
- });
17727
+ constructor(max, HeapCls) {
17728
+ if (!__privateGet(_Stack, _constructing)) {
17729
+ throw new TypeError("instantiate Stack using Stack.create(n)");
17671
17730
  }
17672
- trim(this);
17731
+ this.heap = new HeapCls(max);
17732
+ this.length = 0;
17673
17733
  }
17674
- get lengthCalculator() {
17675
- return this[LENGTH_CALCULATOR];
17734
+ push(n) {
17735
+ this.heap[this.length++] = n;
17676
17736
  }
17677
- get length() {
17678
- return this[LENGTH];
17737
+ pop() {
17738
+ return this.heap[--this.length];
17679
17739
  }
17680
- get itemCount() {
17681
- return this[LRU_LIST].length;
17740
+ };
17741
+ var Stack = _Stack;
17742
+ _constructing = new WeakMap();
17743
+ // private constructor
17744
+ __privateAdd(Stack, _constructing, false);
17745
+ var LRUCache = class {
17746
+ // properties coming in from the options of these, only max and maxSize
17747
+ // really *need* to be protected. The rest can be modified, as they just
17748
+ // set defaults for various methods.
17749
+ #max;
17750
+ #maxSize;
17751
+ #dispose;
17752
+ #disposeAfter;
17753
+ #fetchMethod;
17754
+ /**
17755
+ * {@link LRUCache.OptionsBase.ttl}
17756
+ */
17757
+ ttl;
17758
+ /**
17759
+ * {@link LRUCache.OptionsBase.ttlResolution}
17760
+ */
17761
+ ttlResolution;
17762
+ /**
17763
+ * {@link LRUCache.OptionsBase.ttlAutopurge}
17764
+ */
17765
+ ttlAutopurge;
17766
+ /**
17767
+ * {@link LRUCache.OptionsBase.updateAgeOnGet}
17768
+ */
17769
+ updateAgeOnGet;
17770
+ /**
17771
+ * {@link LRUCache.OptionsBase.updateAgeOnHas}
17772
+ */
17773
+ updateAgeOnHas;
17774
+ /**
17775
+ * {@link LRUCache.OptionsBase.allowStale}
17776
+ */
17777
+ allowStale;
17778
+ /**
17779
+ * {@link LRUCache.OptionsBase.noDisposeOnSet}
17780
+ */
17781
+ noDisposeOnSet;
17782
+ /**
17783
+ * {@link LRUCache.OptionsBase.noUpdateTTL}
17784
+ */
17785
+ noUpdateTTL;
17786
+ /**
17787
+ * {@link LRUCache.OptionsBase.maxEntrySize}
17788
+ */
17789
+ maxEntrySize;
17790
+ /**
17791
+ * {@link LRUCache.OptionsBase.sizeCalculation}
17792
+ */
17793
+ sizeCalculation;
17794
+ /**
17795
+ * {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
17796
+ */
17797
+ noDeleteOnFetchRejection;
17798
+ /**
17799
+ * {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
17800
+ */
17801
+ noDeleteOnStaleGet;
17802
+ /**
17803
+ * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
17804
+ */
17805
+ allowStaleOnFetchAbort;
17806
+ /**
17807
+ * {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
17808
+ */
17809
+ allowStaleOnFetchRejection;
17810
+ /**
17811
+ * {@link LRUCache.OptionsBase.ignoreFetchAbort}
17812
+ */
17813
+ ignoreFetchAbort;
17814
+ // computed properties
17815
+ #size;
17816
+ #calculatedSize;
17817
+ #keyMap;
17818
+ #keyList;
17819
+ #valList;
17820
+ #next;
17821
+ #prev;
17822
+ #head;
17823
+ #tail;
17824
+ #free;
17825
+ #disposed;
17826
+ #sizes;
17827
+ #starts;
17828
+ #ttls;
17829
+ #hasDispose;
17830
+ #hasFetchMethod;
17831
+ #hasDisposeAfter;
17832
+ /**
17833
+ * Do not call this method unless you need to inspect the
17834
+ * inner workings of the cache. If anything returned by this
17835
+ * object is modified in any way, strange breakage may occur.
17836
+ *
17837
+ * These fields are private for a reason!
17838
+ *
17839
+ * @internal
17840
+ */
17841
+ static unsafeExposeInternals(c) {
17842
+ return {
17843
+ // properties
17844
+ starts: c.#starts,
17845
+ ttls: c.#ttls,
17846
+ sizes: c.#sizes,
17847
+ keyMap: c.#keyMap,
17848
+ keyList: c.#keyList,
17849
+ valList: c.#valList,
17850
+ next: c.#next,
17851
+ prev: c.#prev,
17852
+ get head() {
17853
+ return c.#head;
17854
+ },
17855
+ get tail() {
17856
+ return c.#tail;
17857
+ },
17858
+ free: c.#free,
17859
+ // methods
17860
+ isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
17861
+ backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
17862
+ moveToTail: (index) => c.#moveToTail(index),
17863
+ indexes: (options) => c.#indexes(options),
17864
+ rindexes: (options) => c.#rindexes(options),
17865
+ isStale: (index) => c.#isStale(index)
17866
+ };
17682
17867
  }
17683
- rforEach(fn, thisp) {
17684
- thisp = thisp || this;
17685
- for (let walker = this[LRU_LIST].tail; walker !== null; ) {
17686
- const prev = walker.prev;
17687
- forEachStep(this, fn, walker, thisp);
17688
- walker = prev;
17689
- }
17868
+ // Protected read-only members
17869
+ /**
17870
+ * {@link LRUCache.OptionsBase.max} (read-only)
17871
+ */
17872
+ get max() {
17873
+ return this.#max;
17690
17874
  }
17691
- forEach(fn, thisp) {
17692
- thisp = thisp || this;
17693
- for (let walker = this[LRU_LIST].head; walker !== null; ) {
17694
- const next = walker.next;
17695
- forEachStep(this, fn, walker, thisp);
17696
- walker = next;
17697
- }
17875
+ /**
17876
+ * {@link LRUCache.OptionsBase.maxSize} (read-only)
17877
+ */
17878
+ get maxSize() {
17879
+ return this.#maxSize;
17698
17880
  }
17699
- keys() {
17700
- return this[LRU_LIST].toArray().map((k) => k.key);
17881
+ /**
17882
+ * The total computed size of items in the cache (read-only)
17883
+ */
17884
+ get calculatedSize() {
17885
+ return this.#calculatedSize;
17701
17886
  }
17702
- values() {
17703
- return this[LRU_LIST].toArray().map((k) => k.value);
17887
+ /**
17888
+ * The number of items stored in the cache (read-only)
17889
+ */
17890
+ get size() {
17891
+ return this.#size;
17704
17892
  }
17705
- reset() {
17706
- if (this[DISPOSE] && this[LRU_LIST] && this[LRU_LIST].length) {
17707
- this[LRU_LIST].forEach((hit) => this[DISPOSE](hit.key, hit.value));
17708
- }
17709
- this[CACHE] = /* @__PURE__ */ new Map();
17710
- this[LRU_LIST] = new Yallist();
17711
- this[LENGTH] = 0;
17893
+ /**
17894
+ * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
17895
+ */
17896
+ get fetchMethod() {
17897
+ return this.#fetchMethod;
17712
17898
  }
17713
- dump() {
17714
- return this[LRU_LIST].map((hit) => isStale(this, hit) ? false : {
17715
- k: hit.key,
17716
- v: hit.value,
17717
- e: hit.now + (hit.maxAge || 0)
17718
- }).toArray().filter((h) => h);
17899
+ /**
17900
+ * {@link LRUCache.OptionsBase.dispose} (read-only)
17901
+ */
17902
+ get dispose() {
17903
+ return this.#dispose;
17719
17904
  }
17720
- dumpLru() {
17721
- return this[LRU_LIST];
17905
+ /**
17906
+ * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
17907
+ */
17908
+ get disposeAfter() {
17909
+ return this.#disposeAfter;
17722
17910
  }
17723
- set(key, value, maxAge) {
17724
- maxAge = maxAge || this[MAX_AGE];
17725
- if (maxAge && typeof maxAge !== "number")
17726
- throw new TypeError("maxAge must be a number");
17727
- const now = maxAge ? Date.now() : 0;
17728
- const len = this[LENGTH_CALCULATOR](value, key);
17729
- if (this[CACHE].has(key)) {
17730
- if (len > this[MAX]) {
17731
- del(this, this[CACHE].get(key));
17732
- return false;
17911
+ constructor(options) {
17912
+ const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort } = options;
17913
+ if (max !== 0 && !isPosInt(max)) {
17914
+ throw new TypeError("max option must be a nonnegative integer");
17915
+ }
17916
+ const UintArray = max ? getUintArray(max) : Array;
17917
+ if (!UintArray) {
17918
+ throw new Error("invalid max value: " + max);
17919
+ }
17920
+ this.#max = max;
17921
+ this.#maxSize = maxSize;
17922
+ this.maxEntrySize = maxEntrySize || this.#maxSize;
17923
+ this.sizeCalculation = sizeCalculation;
17924
+ if (this.sizeCalculation) {
17925
+ if (!this.#maxSize && !this.maxEntrySize) {
17926
+ throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
17927
+ }
17928
+ if (typeof this.sizeCalculation !== "function") {
17929
+ throw new TypeError("sizeCalculation set to non-function");
17930
+ }
17931
+ }
17932
+ if (fetchMethod !== void 0 && typeof fetchMethod !== "function") {
17933
+ throw new TypeError("fetchMethod must be a function if specified");
17934
+ }
17935
+ this.#fetchMethod = fetchMethod;
17936
+ this.#hasFetchMethod = !!fetchMethod;
17937
+ this.#keyMap = /* @__PURE__ */ new Map();
17938
+ this.#keyList = new Array(max).fill(void 0);
17939
+ this.#valList = new Array(max).fill(void 0);
17940
+ this.#next = new UintArray(max);
17941
+ this.#prev = new UintArray(max);
17942
+ this.#head = 0;
17943
+ this.#tail = 0;
17944
+ this.#free = Stack.create(max);
17945
+ this.#size = 0;
17946
+ this.#calculatedSize = 0;
17947
+ if (typeof dispose === "function") {
17948
+ this.#dispose = dispose;
17949
+ }
17950
+ if (typeof disposeAfter === "function") {
17951
+ this.#disposeAfter = disposeAfter;
17952
+ this.#disposed = [];
17953
+ } else {
17954
+ this.#disposeAfter = void 0;
17955
+ this.#disposed = void 0;
17956
+ }
17957
+ this.#hasDispose = !!this.#dispose;
17958
+ this.#hasDisposeAfter = !!this.#disposeAfter;
17959
+ this.noDisposeOnSet = !!noDisposeOnSet;
17960
+ this.noUpdateTTL = !!noUpdateTTL;
17961
+ this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
17962
+ this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
17963
+ this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
17964
+ this.ignoreFetchAbort = !!ignoreFetchAbort;
17965
+ if (this.maxEntrySize !== 0) {
17966
+ if (this.#maxSize !== 0) {
17967
+ if (!isPosInt(this.#maxSize)) {
17968
+ throw new TypeError("maxSize must be a positive integer if specified");
17969
+ }
17733
17970
  }
17734
- const node = this[CACHE].get(key);
17735
- const item = node.value;
17736
- if (this[DISPOSE]) {
17737
- if (!this[NO_DISPOSE_ON_SET])
17738
- this[DISPOSE](key, item.value);
17971
+ if (!isPosInt(this.maxEntrySize)) {
17972
+ throw new TypeError("maxEntrySize must be a positive integer if specified");
17739
17973
  }
17740
- item.now = now;
17741
- item.maxAge = maxAge;
17742
- item.value = value;
17743
- this[LENGTH] += len - item.length;
17744
- item.length = len;
17745
- this.get(key);
17746
- trim(this);
17747
- return true;
17974
+ this.#initializeSizeTracking();
17748
17975
  }
17749
- const hit = new Entry(key, value, len, now, maxAge);
17750
- if (hit.length > this[MAX]) {
17751
- if (this[DISPOSE])
17752
- this[DISPOSE](key, value);
17753
- return false;
17976
+ this.allowStale = !!allowStale;
17977
+ this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
17978
+ this.updateAgeOnGet = !!updateAgeOnGet;
17979
+ this.updateAgeOnHas = !!updateAgeOnHas;
17980
+ this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
17981
+ this.ttlAutopurge = !!ttlAutopurge;
17982
+ this.ttl = ttl || 0;
17983
+ if (this.ttl) {
17984
+ if (!isPosInt(this.ttl)) {
17985
+ throw new TypeError("ttl must be a positive integer if specified");
17986
+ }
17987
+ this.#initializeTTLTracking();
17988
+ }
17989
+ if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
17990
+ throw new TypeError("At least one of max, maxSize, or ttl is required");
17991
+ }
17992
+ if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
17993
+ const code = "LRU_CACHE_UNBOUNDED";
17994
+ if (shouldWarn(code)) {
17995
+ warned.add(code);
17996
+ const msg = "TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.";
17997
+ emitWarning(msg, "UnboundedCacheWarning", code, LRUCache);
17998
+ }
17754
17999
  }
17755
- this[LENGTH] += hit.length;
17756
- this[LRU_LIST].unshift(hit);
17757
- this[CACHE].set(key, this[LRU_LIST].head);
17758
- trim(this);
17759
- return true;
17760
- }
17761
- has(key) {
17762
- if (!this[CACHE].has(key))
17763
- return false;
17764
- const hit = this[CACHE].get(key).value;
17765
- return !isStale(this, hit);
17766
- }
17767
- get(key) {
17768
- return get(this, key, true);
17769
- }
17770
- peek(key) {
17771
- return get(this, key, false);
17772
- }
17773
- pop() {
17774
- const node = this[LRU_LIST].tail;
17775
- if (!node)
17776
- return null;
17777
- del(this, node);
17778
- return node.value;
17779
18000
  }
17780
- del(key) {
17781
- del(this, this[CACHE].get(key));
18001
+ /**
18002
+ * Return the remaining TTL time for a given entry key
18003
+ */
18004
+ getRemainingTTL(key) {
18005
+ return this.#keyMap.has(key) ? Infinity : 0;
18006
+ }
18007
+ #initializeTTLTracking() {
18008
+ const ttls = new ZeroArray(this.#max);
18009
+ const starts = new ZeroArray(this.#max);
18010
+ this.#ttls = ttls;
18011
+ this.#starts = starts;
18012
+ this.#setItemTTL = (index, ttl, start = perf.now()) => {
18013
+ starts[index] = ttl !== 0 ? start : 0;
18014
+ ttls[index] = ttl;
18015
+ if (ttl !== 0 && this.ttlAutopurge) {
18016
+ const t = setTimeout(() => {
18017
+ if (this.#isStale(index)) {
18018
+ this.delete(this.#keyList[index]);
18019
+ }
18020
+ }, ttl + 1);
18021
+ if (t.unref) {
18022
+ t.unref();
18023
+ }
18024
+ }
18025
+ };
18026
+ this.#updateItemAge = (index) => {
18027
+ starts[index] = ttls[index] !== 0 ? perf.now() : 0;
18028
+ };
18029
+ this.#statusTTL = (status, index) => {
18030
+ if (ttls[index]) {
18031
+ const ttl = ttls[index];
18032
+ const start = starts[index];
18033
+ status.ttl = ttl;
18034
+ status.start = start;
18035
+ status.now = cachedNow || getNow();
18036
+ const age = status.now - start;
18037
+ status.remainingTTL = ttl - age;
18038
+ }
18039
+ };
18040
+ let cachedNow = 0;
18041
+ const getNow = () => {
18042
+ const n = perf.now();
18043
+ if (this.ttlResolution > 0) {
18044
+ cachedNow = n;
18045
+ const t = setTimeout(() => cachedNow = 0, this.ttlResolution);
18046
+ if (t.unref) {
18047
+ t.unref();
18048
+ }
18049
+ }
18050
+ return n;
18051
+ };
18052
+ this.getRemainingTTL = (key) => {
18053
+ const index = this.#keyMap.get(key);
18054
+ if (index === void 0) {
18055
+ return 0;
18056
+ }
18057
+ const ttl = ttls[index];
18058
+ const start = starts[index];
18059
+ if (ttl === 0 || start === 0) {
18060
+ return Infinity;
18061
+ }
18062
+ const age = (cachedNow || getNow()) - start;
18063
+ return ttl - age;
18064
+ };
18065
+ this.#isStale = (index) => {
18066
+ return ttls[index] !== 0 && starts[index] !== 0 && (cachedNow || getNow()) - starts[index] > ttls[index];
18067
+ };
17782
18068
  }
17783
- load(arr) {
17784
- this.reset();
17785
- const now = Date.now();
17786
- for (let l = arr.length - 1; l >= 0; l--) {
17787
- const hit = arr[l];
17788
- const expiresAt = hit.e || 0;
17789
- if (expiresAt === 0)
17790
- this.set(hit.k, hit.v);
17791
- else {
17792
- const maxAge = expiresAt - now;
17793
- if (maxAge > 0) {
17794
- this.set(hit.k, hit.v, maxAge);
18069
+ // conditionally set private methods related to TTL
18070
+ #updateItemAge = () => {
18071
+ };
18072
+ #statusTTL = () => {
18073
+ };
18074
+ #setItemTTL = () => {
18075
+ };
18076
+ /* c8 ignore stop */
18077
+ #isStale = () => false;
18078
+ #initializeSizeTracking() {
18079
+ const sizes = new ZeroArray(this.#max);
18080
+ this.#calculatedSize = 0;
18081
+ this.#sizes = sizes;
18082
+ this.#removeItemSize = (index) => {
18083
+ this.#calculatedSize -= sizes[index];
18084
+ sizes[index] = 0;
18085
+ };
18086
+ this.#requireSize = (k, v, size, sizeCalculation) => {
18087
+ if (this.#isBackgroundFetch(v)) {
18088
+ return 0;
18089
+ }
18090
+ if (!isPosInt(size)) {
18091
+ if (sizeCalculation) {
18092
+ if (typeof sizeCalculation !== "function") {
18093
+ throw new TypeError("sizeCalculation must be a function");
18094
+ }
18095
+ size = sizeCalculation(v, k);
18096
+ if (!isPosInt(size)) {
18097
+ throw new TypeError("sizeCalculation return invalid (expect positive integer)");
18098
+ }
18099
+ } else {
18100
+ throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
18101
+ }
18102
+ }
18103
+ return size;
18104
+ };
18105
+ this.#addItemSize = (index, size, status) => {
18106
+ sizes[index] = size;
18107
+ if (this.#maxSize) {
18108
+ const maxSize = this.#maxSize - sizes[index];
18109
+ while (this.#calculatedSize > maxSize) {
18110
+ this.#evict(true);
18111
+ }
18112
+ }
18113
+ this.#calculatedSize += sizes[index];
18114
+ if (status) {
18115
+ status.entrySize = size;
18116
+ status.totalCalculatedSize = this.#calculatedSize;
18117
+ }
18118
+ };
18119
+ }
18120
+ #removeItemSize = (_i) => {
18121
+ };
18122
+ #addItemSize = (_i, _s, _st) => {
18123
+ };
18124
+ #requireSize = (_k, _v, size, sizeCalculation) => {
18125
+ if (size || sizeCalculation) {
18126
+ throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
18127
+ }
18128
+ return 0;
18129
+ };
18130
+ *#indexes({ allowStale = this.allowStale } = {}) {
18131
+ if (this.#size) {
18132
+ for (let i = this.#tail; true; ) {
18133
+ if (!this.#isValidIndex(i)) {
18134
+ break;
18135
+ }
18136
+ if (allowStale || !this.#isStale(i)) {
18137
+ yield i;
18138
+ }
18139
+ if (i === this.#head) {
18140
+ break;
18141
+ } else {
18142
+ i = this.#prev[i];
17795
18143
  }
17796
18144
  }
17797
18145
  }
17798
18146
  }
17799
- prune() {
17800
- this[CACHE].forEach((value, key) => get(this, key, false));
18147
+ *#rindexes({ allowStale = this.allowStale } = {}) {
18148
+ if (this.#size) {
18149
+ for (let i = this.#head; true; ) {
18150
+ if (!this.#isValidIndex(i)) {
18151
+ break;
18152
+ }
18153
+ if (allowStale || !this.#isStale(i)) {
18154
+ yield i;
18155
+ }
18156
+ if (i === this.#tail) {
18157
+ break;
18158
+ } else {
18159
+ i = this.#next[i];
18160
+ }
18161
+ }
18162
+ }
17801
18163
  }
17802
- };
17803
- var get = (self2, key, doUse) => {
17804
- const node = self2[CACHE].get(key);
17805
- if (node) {
17806
- const hit = node.value;
17807
- if (isStale(self2, hit)) {
17808
- del(self2, node);
17809
- if (!self2[ALLOW_STALE])
17810
- return void 0;
18164
+ #isValidIndex(index) {
18165
+ return index !== void 0 && this.#keyMap.get(this.#keyList[index]) === index;
18166
+ }
18167
+ /**
18168
+ * Return a generator yielding `[key, value]` pairs,
18169
+ * in order from most recently used to least recently used.
18170
+ */
18171
+ *entries() {
18172
+ for (const i of this.#indexes()) {
18173
+ if (this.#valList[i] !== void 0 && this.#keyList[i] !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
18174
+ yield [this.#keyList[i], this.#valList[i]];
18175
+ }
18176
+ }
18177
+ }
18178
+ /**
18179
+ * Inverse order version of {@link LRUCache.entries}
18180
+ *
18181
+ * Return a generator yielding `[key, value]` pairs,
18182
+ * in order from least recently used to most recently used.
18183
+ */
18184
+ *rentries() {
18185
+ for (const i of this.#rindexes()) {
18186
+ if (this.#valList[i] !== void 0 && this.#keyList[i] !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
18187
+ yield [this.#keyList[i], this.#valList[i]];
18188
+ }
18189
+ }
18190
+ }
18191
+ /**
18192
+ * Return a generator yielding the keys in the cache,
18193
+ * in order from most recently used to least recently used.
18194
+ */
18195
+ *keys() {
18196
+ for (const i of this.#indexes()) {
18197
+ const k = this.#keyList[i];
18198
+ if (k !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
18199
+ yield k;
18200
+ }
18201
+ }
18202
+ }
18203
+ /**
18204
+ * Inverse order version of {@link LRUCache.keys}
18205
+ *
18206
+ * Return a generator yielding the keys in the cache,
18207
+ * in order from least recently used to most recently used.
18208
+ */
18209
+ *rkeys() {
18210
+ for (const i of this.#rindexes()) {
18211
+ const k = this.#keyList[i];
18212
+ if (k !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
18213
+ yield k;
18214
+ }
18215
+ }
18216
+ }
18217
+ /**
18218
+ * Return a generator yielding the values in the cache,
18219
+ * in order from most recently used to least recently used.
18220
+ */
18221
+ *values() {
18222
+ for (const i of this.#indexes()) {
18223
+ const v = this.#valList[i];
18224
+ if (v !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
18225
+ yield this.#valList[i];
18226
+ }
18227
+ }
18228
+ }
18229
+ /**
18230
+ * Inverse order version of {@link LRUCache.values}
18231
+ *
18232
+ * Return a generator yielding the values in the cache,
18233
+ * in order from least recently used to most recently used.
18234
+ */
18235
+ *rvalues() {
18236
+ for (const i of this.#rindexes()) {
18237
+ const v = this.#valList[i];
18238
+ if (v !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
18239
+ yield this.#valList[i];
18240
+ }
18241
+ }
18242
+ }
18243
+ /**
18244
+ * Iterating over the cache itself yields the same results as
18245
+ * {@link LRUCache.entries}
18246
+ */
18247
+ [Symbol.iterator]() {
18248
+ return this.entries();
18249
+ }
18250
+ /**
18251
+ * Find a value for which the supplied fn method returns a truthy value,
18252
+ * similar to Array.find(). fn is called as fn(value, key, cache).
18253
+ */
18254
+ find(fn, getOptions = {}) {
18255
+ for (const i of this.#indexes()) {
18256
+ const v = this.#valList[i];
18257
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
18258
+ if (value === void 0)
18259
+ continue;
18260
+ if (fn(value, this.#keyList[i], this)) {
18261
+ return this.get(this.#keyList[i], getOptions);
18262
+ }
18263
+ }
18264
+ }
18265
+ /**
18266
+ * Call the supplied function on each item in the cache, in order from
18267
+ * most recently used to least recently used. fn is called as
18268
+ * fn(value, key, cache). Does not update age or recenty of use.
18269
+ * Does not iterate over stale values.
18270
+ */
18271
+ forEach(fn, thisp = this) {
18272
+ for (const i of this.#indexes()) {
18273
+ const v = this.#valList[i];
18274
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
18275
+ if (value === void 0)
18276
+ continue;
18277
+ fn.call(thisp, value, this.#keyList[i], this);
18278
+ }
18279
+ }
18280
+ /**
18281
+ * The same as {@link LRUCache.forEach} but items are iterated over in
18282
+ * reverse order. (ie, less recently used items are iterated over first.)
18283
+ */
18284
+ rforEach(fn, thisp = this) {
18285
+ for (const i of this.#rindexes()) {
18286
+ const v = this.#valList[i];
18287
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
18288
+ if (value === void 0)
18289
+ continue;
18290
+ fn.call(thisp, value, this.#keyList[i], this);
18291
+ }
18292
+ }
18293
+ /**
18294
+ * Delete any stale entries. Returns true if anything was removed,
18295
+ * false otherwise.
18296
+ */
18297
+ purgeStale() {
18298
+ let deleted = false;
18299
+ for (const i of this.#rindexes({ allowStale: true })) {
18300
+ if (this.#isStale(i)) {
18301
+ this.delete(this.#keyList[i]);
18302
+ deleted = true;
18303
+ }
18304
+ }
18305
+ return deleted;
18306
+ }
18307
+ /**
18308
+ * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
18309
+ * passed to cache.load()
18310
+ */
18311
+ dump() {
18312
+ const arr = [];
18313
+ for (const i of this.#indexes({ allowStale: true })) {
18314
+ const key = this.#keyList[i];
18315
+ const v = this.#valList[i];
18316
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
18317
+ if (value === void 0 || key === void 0)
18318
+ continue;
18319
+ const entry = { value };
18320
+ if (this.#ttls && this.#starts) {
18321
+ entry.ttl = this.#ttls[i];
18322
+ const age = perf.now() - this.#starts[i];
18323
+ entry.start = Math.floor(Date.now() - age);
18324
+ }
18325
+ if (this.#sizes) {
18326
+ entry.size = this.#sizes[i];
18327
+ }
18328
+ arr.unshift([key, entry]);
18329
+ }
18330
+ return arr;
18331
+ }
18332
+ /**
18333
+ * Reset the cache and load in the items in entries in the order listed.
18334
+ * Note that the shape of the resulting cache may be different if the
18335
+ * same options are not used in both caches.
18336
+ */
18337
+ load(arr) {
18338
+ this.clear();
18339
+ for (const [key, entry] of arr) {
18340
+ if (entry.start) {
18341
+ const age = Date.now() - entry.start;
18342
+ entry.start = perf.now() - age;
18343
+ }
18344
+ this.set(key, entry.value, entry);
18345
+ }
18346
+ }
18347
+ /**
18348
+ * Add a value to the cache.
18349
+ *
18350
+ * Note: if `undefined` is specified as a value, this is an alias for
18351
+ * {@link LRUCache#delete}
18352
+ */
18353
+ set(k, v, setOptions = {}) {
18354
+ var _a2, _b, _c;
18355
+ if (v === void 0) {
18356
+ this.delete(k);
18357
+ return this;
18358
+ }
18359
+ const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status } = setOptions;
18360
+ let { noUpdateTTL = this.noUpdateTTL } = setOptions;
18361
+ const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
18362
+ if (this.maxEntrySize && size > this.maxEntrySize) {
18363
+ if (status) {
18364
+ status.set = "miss";
18365
+ status.maxEntrySizeExceeded = true;
18366
+ }
18367
+ this.delete(k);
18368
+ return this;
18369
+ }
18370
+ let index = this.#size === 0 ? void 0 : this.#keyMap.get(k);
18371
+ if (index === void 0) {
18372
+ index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
18373
+ this.#keyList[index] = k;
18374
+ this.#valList[index] = v;
18375
+ this.#keyMap.set(k, index);
18376
+ this.#next[this.#tail] = index;
18377
+ this.#prev[index] = this.#tail;
18378
+ this.#tail = index;
18379
+ this.#size++;
18380
+ this.#addItemSize(index, size, status);
18381
+ if (status)
18382
+ status.set = "add";
18383
+ noUpdateTTL = false;
17811
18384
  } else {
17812
- if (doUse) {
17813
- if (self2[UPDATE_AGE_ON_GET])
17814
- node.value.now = Date.now();
17815
- self2[LRU_LIST].unshiftNode(node);
18385
+ this.#moveToTail(index);
18386
+ const oldVal = this.#valList[index];
18387
+ if (v !== oldVal) {
18388
+ if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
18389
+ oldVal.__abortController.abort(new Error("replaced"));
18390
+ } else if (!noDisposeOnSet) {
18391
+ if (this.#hasDispose) {
18392
+ (_a2 = this.#dispose) == null ? void 0 : _a2.call(this, oldVal, k, "set");
18393
+ }
18394
+ if (this.#hasDisposeAfter) {
18395
+ (_b = this.#disposed) == null ? void 0 : _b.push([oldVal, k, "set"]);
18396
+ }
18397
+ }
18398
+ this.#removeItemSize(index);
18399
+ this.#addItemSize(index, size, status);
18400
+ this.#valList[index] = v;
18401
+ if (status) {
18402
+ status.set = "replace";
18403
+ const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
18404
+ if (oldValue !== void 0)
18405
+ status.oldValue = oldValue;
18406
+ }
18407
+ } else if (status) {
18408
+ status.set = "update";
17816
18409
  }
17817
18410
  }
17818
- return hit.value;
18411
+ if (ttl !== 0 && !this.#ttls) {
18412
+ this.#initializeTTLTracking();
18413
+ }
18414
+ if (this.#ttls) {
18415
+ if (!noUpdateTTL) {
18416
+ this.#setItemTTL(index, ttl, start);
18417
+ }
18418
+ if (status)
18419
+ this.#statusTTL(status, index);
18420
+ }
18421
+ if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
18422
+ const dt = this.#disposed;
18423
+ let task;
18424
+ while (task = dt == null ? void 0 : dt.shift()) {
18425
+ (_c = this.#disposeAfter) == null ? void 0 : _c.call(this, ...task);
18426
+ }
18427
+ }
18428
+ return this;
17819
18429
  }
17820
- };
17821
- var isStale = (self2, hit) => {
17822
- if (!hit || !hit.maxAge && !self2[MAX_AGE])
18430
+ /**
18431
+ * Evict the least recently used item, returning its value or
18432
+ * `undefined` if cache is empty.
18433
+ */
18434
+ pop() {
18435
+ var _a2;
18436
+ try {
18437
+ while (this.#size) {
18438
+ const val = this.#valList[this.#head];
18439
+ this.#evict(true);
18440
+ if (this.#isBackgroundFetch(val)) {
18441
+ if (val.__staleWhileFetching) {
18442
+ return val.__staleWhileFetching;
18443
+ }
18444
+ } else if (val !== void 0) {
18445
+ return val;
18446
+ }
18447
+ }
18448
+ } finally {
18449
+ if (this.#hasDisposeAfter && this.#disposed) {
18450
+ const dt = this.#disposed;
18451
+ let task;
18452
+ while (task = dt == null ? void 0 : dt.shift()) {
18453
+ (_a2 = this.#disposeAfter) == null ? void 0 : _a2.call(this, ...task);
18454
+ }
18455
+ }
18456
+ }
18457
+ }
18458
+ #evict(free) {
18459
+ var _a2, _b;
18460
+ const head = this.#head;
18461
+ const k = this.#keyList[head];
18462
+ const v = this.#valList[head];
18463
+ if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
18464
+ v.__abortController.abort(new Error("evicted"));
18465
+ } else if (this.#hasDispose || this.#hasDisposeAfter) {
18466
+ if (this.#hasDispose) {
18467
+ (_a2 = this.#dispose) == null ? void 0 : _a2.call(this, v, k, "evict");
18468
+ }
18469
+ if (this.#hasDisposeAfter) {
18470
+ (_b = this.#disposed) == null ? void 0 : _b.push([v, k, "evict"]);
18471
+ }
18472
+ }
18473
+ this.#removeItemSize(head);
18474
+ if (free) {
18475
+ this.#keyList[head] = void 0;
18476
+ this.#valList[head] = void 0;
18477
+ this.#free.push(head);
18478
+ }
18479
+ if (this.#size === 1) {
18480
+ this.#head = this.#tail = 0;
18481
+ this.#free.length = 0;
18482
+ } else {
18483
+ this.#head = this.#next[head];
18484
+ }
18485
+ this.#keyMap.delete(k);
18486
+ this.#size--;
18487
+ return head;
18488
+ }
18489
+ /**
18490
+ * Check if a key is in the cache, without updating the recency of use.
18491
+ * Will return false if the item is stale, even though it is technically
18492
+ * in the cache.
18493
+ *
18494
+ * Will not update item age unless
18495
+ * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
18496
+ */
18497
+ has(k, hasOptions = {}) {
18498
+ const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
18499
+ const index = this.#keyMap.get(k);
18500
+ if (index !== void 0) {
18501
+ const v = this.#valList[index];
18502
+ if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === void 0) {
18503
+ return false;
18504
+ }
18505
+ if (!this.#isStale(index)) {
18506
+ if (updateAgeOnHas) {
18507
+ this.#updateItemAge(index);
18508
+ }
18509
+ if (status) {
18510
+ status.has = "hit";
18511
+ this.#statusTTL(status, index);
18512
+ }
18513
+ return true;
18514
+ } else if (status) {
18515
+ status.has = "stale";
18516
+ this.#statusTTL(status, index);
18517
+ }
18518
+ } else if (status) {
18519
+ status.has = "miss";
18520
+ }
17823
18521
  return false;
17824
- const diff = Date.now() - hit.now;
17825
- return hit.maxAge ? diff > hit.maxAge : self2[MAX_AGE] && diff > self2[MAX_AGE];
17826
- };
17827
- var trim = (self2) => {
17828
- if (self2[LENGTH] > self2[MAX]) {
17829
- for (let walker = self2[LRU_LIST].tail; self2[LENGTH] > self2[MAX] && walker !== null; ) {
17830
- const prev = walker.prev;
17831
- del(self2, walker);
17832
- walker = prev;
18522
+ }
18523
+ /**
18524
+ * Like {@link LRUCache#get} but doesn't update recency or delete stale
18525
+ * items.
18526
+ *
18527
+ * Returns `undefined` if the item is stale, unless
18528
+ * {@link LRUCache.OptionsBase.allowStale} is set.
18529
+ */
18530
+ peek(k, peekOptions = {}) {
18531
+ const { allowStale = this.allowStale } = peekOptions;
18532
+ const index = this.#keyMap.get(k);
18533
+ if (index !== void 0 && (allowStale || !this.#isStale(index))) {
18534
+ const v = this.#valList[index];
18535
+ return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
18536
+ }
18537
+ }
18538
+ #backgroundFetch(k, index, options, context) {
18539
+ const v = index === void 0 ? void 0 : this.#valList[index];
18540
+ if (this.#isBackgroundFetch(v)) {
18541
+ return v;
18542
+ }
18543
+ const ac = new AC();
18544
+ const { signal } = options;
18545
+ signal == null ? void 0 : signal.addEventListener("abort", () => ac.abort(signal.reason), {
18546
+ signal: ac.signal
18547
+ });
18548
+ const fetchOpts = {
18549
+ signal: ac.signal,
18550
+ options,
18551
+ context
18552
+ };
18553
+ const cb = (v2, updateCache = false) => {
18554
+ const { aborted } = ac.signal;
18555
+ const ignoreAbort = options.ignoreFetchAbort && v2 !== void 0;
18556
+ if (options.status) {
18557
+ if (aborted && !updateCache) {
18558
+ options.status.fetchAborted = true;
18559
+ options.status.fetchError = ac.signal.reason;
18560
+ if (ignoreAbort)
18561
+ options.status.fetchAbortIgnored = true;
18562
+ } else {
18563
+ options.status.fetchResolved = true;
18564
+ }
18565
+ }
18566
+ if (aborted && !ignoreAbort && !updateCache) {
18567
+ return fetchFail(ac.signal.reason);
18568
+ }
18569
+ const bf2 = p;
18570
+ if (this.#valList[index] === p) {
18571
+ if (v2 === void 0) {
18572
+ if (bf2.__staleWhileFetching) {
18573
+ this.#valList[index] = bf2.__staleWhileFetching;
18574
+ } else {
18575
+ this.delete(k);
18576
+ }
18577
+ } else {
18578
+ if (options.status)
18579
+ options.status.fetchUpdated = true;
18580
+ this.set(k, v2, fetchOpts.options);
18581
+ }
18582
+ }
18583
+ return v2;
18584
+ };
18585
+ const eb = (er) => {
18586
+ if (options.status) {
18587
+ options.status.fetchRejected = true;
18588
+ options.status.fetchError = er;
18589
+ }
18590
+ return fetchFail(er);
18591
+ };
18592
+ const fetchFail = (er) => {
18593
+ const { aborted } = ac.signal;
18594
+ const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
18595
+ const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
18596
+ const noDelete = allowStale || options.noDeleteOnFetchRejection;
18597
+ const bf2 = p;
18598
+ if (this.#valList[index] === p) {
18599
+ const del = !noDelete || bf2.__staleWhileFetching === void 0;
18600
+ if (del) {
18601
+ this.delete(k);
18602
+ } else if (!allowStaleAborted) {
18603
+ this.#valList[index] = bf2.__staleWhileFetching;
18604
+ }
18605
+ }
18606
+ if (allowStale) {
18607
+ if (options.status && bf2.__staleWhileFetching !== void 0) {
18608
+ options.status.returnedStale = true;
18609
+ }
18610
+ return bf2.__staleWhileFetching;
18611
+ } else if (bf2.__returned === bf2) {
18612
+ throw er;
18613
+ }
18614
+ };
18615
+ const pcall = (res, rej) => {
18616
+ var _a2;
18617
+ const fmp = (_a2 = this.#fetchMethod) == null ? void 0 : _a2.call(this, k, v, fetchOpts);
18618
+ if (fmp && fmp instanceof Promise) {
18619
+ fmp.then((v2) => res(v2), rej);
18620
+ }
18621
+ ac.signal.addEventListener("abort", () => {
18622
+ if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
18623
+ res();
18624
+ if (options.allowStaleOnFetchAbort) {
18625
+ res = (v2) => cb(v2, true);
18626
+ }
18627
+ }
18628
+ });
18629
+ };
18630
+ if (options.status)
18631
+ options.status.fetchDispatched = true;
18632
+ const p = new Promise(pcall).then(cb, eb);
18633
+ const bf = Object.assign(p, {
18634
+ __abortController: ac,
18635
+ __staleWhileFetching: v,
18636
+ __returned: void 0
18637
+ });
18638
+ if (index === void 0) {
18639
+ this.set(k, bf, { ...fetchOpts.options, status: void 0 });
18640
+ index = this.#keyMap.get(k);
18641
+ } else {
18642
+ this.#valList[index] = bf;
17833
18643
  }
18644
+ return bf;
17834
18645
  }
17835
- };
17836
- var del = (self2, node) => {
17837
- if (node) {
17838
- const hit = node.value;
17839
- if (self2[DISPOSE])
17840
- self2[DISPOSE](hit.key, hit.value);
17841
- self2[LENGTH] -= hit.length;
17842
- self2[CACHE].delete(hit.key);
17843
- self2[LRU_LIST].removeNode(node);
18646
+ #isBackgroundFetch(p) {
18647
+ if (!this.#hasFetchMethod)
18648
+ return false;
18649
+ const b = p;
18650
+ return !!b && b instanceof Promise && b.hasOwnProperty("__staleWhileFetching") && b.__abortController instanceof AC;
17844
18651
  }
17845
- };
17846
- var Entry = class {
17847
- constructor(key, value, length, now, maxAge) {
17848
- this.key = key;
17849
- this.value = value;
17850
- this.length = length;
17851
- this.now = now;
17852
- this.maxAge = maxAge || 0;
18652
+ async fetch(k, fetchOptions = {}) {
18653
+ const {
18654
+ // get options
18655
+ allowStale = this.allowStale,
18656
+ updateAgeOnGet = this.updateAgeOnGet,
18657
+ noDeleteOnStaleGet = this.noDeleteOnStaleGet,
18658
+ // set options
18659
+ ttl = this.ttl,
18660
+ noDisposeOnSet = this.noDisposeOnSet,
18661
+ size = 0,
18662
+ sizeCalculation = this.sizeCalculation,
18663
+ noUpdateTTL = this.noUpdateTTL,
18664
+ // fetch exclusive options
18665
+ noDeleteOnFetchRejection = this.noDeleteOnFetchRejection,
18666
+ allowStaleOnFetchRejection = this.allowStaleOnFetchRejection,
18667
+ ignoreFetchAbort = this.ignoreFetchAbort,
18668
+ allowStaleOnFetchAbort = this.allowStaleOnFetchAbort,
18669
+ context,
18670
+ forceRefresh = false,
18671
+ status,
18672
+ signal
18673
+ } = fetchOptions;
18674
+ if (!this.#hasFetchMethod) {
18675
+ if (status)
18676
+ status.fetch = "get";
18677
+ return this.get(k, {
18678
+ allowStale,
18679
+ updateAgeOnGet,
18680
+ noDeleteOnStaleGet,
18681
+ status
18682
+ });
18683
+ }
18684
+ const options = {
18685
+ allowStale,
18686
+ updateAgeOnGet,
18687
+ noDeleteOnStaleGet,
18688
+ ttl,
18689
+ noDisposeOnSet,
18690
+ size,
18691
+ sizeCalculation,
18692
+ noUpdateTTL,
18693
+ noDeleteOnFetchRejection,
18694
+ allowStaleOnFetchRejection,
18695
+ allowStaleOnFetchAbort,
18696
+ ignoreFetchAbort,
18697
+ status,
18698
+ signal
18699
+ };
18700
+ let index = this.#keyMap.get(k);
18701
+ if (index === void 0) {
18702
+ if (status)
18703
+ status.fetch = "miss";
18704
+ const p = this.#backgroundFetch(k, index, options, context);
18705
+ return p.__returned = p;
18706
+ } else {
18707
+ const v = this.#valList[index];
18708
+ if (this.#isBackgroundFetch(v)) {
18709
+ const stale = allowStale && v.__staleWhileFetching !== void 0;
18710
+ if (status) {
18711
+ status.fetch = "inflight";
18712
+ if (stale)
18713
+ status.returnedStale = true;
18714
+ }
18715
+ return stale ? v.__staleWhileFetching : v.__returned = v;
18716
+ }
18717
+ const isStale = this.#isStale(index);
18718
+ if (!forceRefresh && !isStale) {
18719
+ if (status)
18720
+ status.fetch = "hit";
18721
+ this.#moveToTail(index);
18722
+ if (updateAgeOnGet) {
18723
+ this.#updateItemAge(index);
18724
+ }
18725
+ if (status)
18726
+ this.#statusTTL(status, index);
18727
+ return v;
18728
+ }
18729
+ const p = this.#backgroundFetch(k, index, options, context);
18730
+ const hasStale = p.__staleWhileFetching !== void 0;
18731
+ const staleVal = hasStale && allowStale;
18732
+ if (status) {
18733
+ status.fetch = isStale ? "stale" : "refresh";
18734
+ if (staleVal && isStale)
18735
+ status.returnedStale = true;
18736
+ }
18737
+ return staleVal ? p.__staleWhileFetching : p.__returned = p;
18738
+ }
17853
18739
  }
17854
- };
17855
- var forEachStep = (self2, fn, node, thisp) => {
17856
- let hit = node.value;
17857
- if (isStale(self2, hit)) {
17858
- del(self2, node);
17859
- if (!self2[ALLOW_STALE])
17860
- hit = void 0;
18740
+ /**
18741
+ * Return a value from the cache. Will update the recency of the cache
18742
+ * entry found.
18743
+ *
18744
+ * If the key is not found, get() will return `undefined`.
18745
+ */
18746
+ get(k, getOptions = {}) {
18747
+ const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
18748
+ const index = this.#keyMap.get(k);
18749
+ if (index !== void 0) {
18750
+ const value = this.#valList[index];
18751
+ const fetching = this.#isBackgroundFetch(value);
18752
+ if (status)
18753
+ this.#statusTTL(status, index);
18754
+ if (this.#isStale(index)) {
18755
+ if (status)
18756
+ status.get = "stale";
18757
+ if (!fetching) {
18758
+ if (!noDeleteOnStaleGet) {
18759
+ this.delete(k);
18760
+ }
18761
+ if (status && allowStale)
18762
+ status.returnedStale = true;
18763
+ return allowStale ? value : void 0;
18764
+ } else {
18765
+ if (status && allowStale && value.__staleWhileFetching !== void 0) {
18766
+ status.returnedStale = true;
18767
+ }
18768
+ return allowStale ? value.__staleWhileFetching : void 0;
18769
+ }
18770
+ } else {
18771
+ if (status)
18772
+ status.get = "hit";
18773
+ if (fetching) {
18774
+ return value.__staleWhileFetching;
18775
+ }
18776
+ this.#moveToTail(index);
18777
+ if (updateAgeOnGet) {
18778
+ this.#updateItemAge(index);
18779
+ }
18780
+ return value;
18781
+ }
18782
+ } else if (status) {
18783
+ status.get = "miss";
18784
+ }
18785
+ }
18786
+ #connect(p, n) {
18787
+ this.#prev[n] = p;
18788
+ this.#next[p] = n;
18789
+ }
18790
+ #moveToTail(index) {
18791
+ if (index !== this.#tail) {
18792
+ if (index === this.#head) {
18793
+ this.#head = this.#next[index];
18794
+ } else {
18795
+ this.#connect(this.#prev[index], this.#next[index]);
18796
+ }
18797
+ this.#connect(this.#tail, index);
18798
+ this.#tail = index;
18799
+ }
18800
+ }
18801
+ /**
18802
+ * Deletes a key out of the cache.
18803
+ * Returns true if the key was deleted, false otherwise.
18804
+ */
18805
+ delete(k) {
18806
+ var _a2, _b, _c, _d;
18807
+ let deleted = false;
18808
+ if (this.#size !== 0) {
18809
+ const index = this.#keyMap.get(k);
18810
+ if (index !== void 0) {
18811
+ deleted = true;
18812
+ if (this.#size === 1) {
18813
+ this.clear();
18814
+ } else {
18815
+ this.#removeItemSize(index);
18816
+ const v = this.#valList[index];
18817
+ if (this.#isBackgroundFetch(v)) {
18818
+ v.__abortController.abort(new Error("deleted"));
18819
+ } else if (this.#hasDispose || this.#hasDisposeAfter) {
18820
+ if (this.#hasDispose) {
18821
+ (_a2 = this.#dispose) == null ? void 0 : _a2.call(this, v, k, "delete");
18822
+ }
18823
+ if (this.#hasDisposeAfter) {
18824
+ (_b = this.#disposed) == null ? void 0 : _b.push([v, k, "delete"]);
18825
+ }
18826
+ }
18827
+ this.#keyMap.delete(k);
18828
+ this.#keyList[index] = void 0;
18829
+ this.#valList[index] = void 0;
18830
+ if (index === this.#tail) {
18831
+ this.#tail = this.#prev[index];
18832
+ } else if (index === this.#head) {
18833
+ this.#head = this.#next[index];
18834
+ } else {
18835
+ this.#next[this.#prev[index]] = this.#next[index];
18836
+ this.#prev[this.#next[index]] = this.#prev[index];
18837
+ }
18838
+ this.#size--;
18839
+ this.#free.push(index);
18840
+ }
18841
+ }
18842
+ }
18843
+ if (this.#hasDisposeAfter && ((_c = this.#disposed) == null ? void 0 : _c.length)) {
18844
+ const dt = this.#disposed;
18845
+ let task;
18846
+ while (task = dt == null ? void 0 : dt.shift()) {
18847
+ (_d = this.#disposeAfter) == null ? void 0 : _d.call(this, ...task);
18848
+ }
18849
+ }
18850
+ return deleted;
18851
+ }
18852
+ /**
18853
+ * Clear the cache entirely, throwing away all values.
18854
+ */
18855
+ clear() {
18856
+ var _a2, _b, _c;
18857
+ for (const index of this.#rindexes({ allowStale: true })) {
18858
+ const v = this.#valList[index];
18859
+ if (this.#isBackgroundFetch(v)) {
18860
+ v.__abortController.abort(new Error("deleted"));
18861
+ } else {
18862
+ const k = this.#keyList[index];
18863
+ if (this.#hasDispose) {
18864
+ (_a2 = this.#dispose) == null ? void 0 : _a2.call(this, v, k, "delete");
18865
+ }
18866
+ if (this.#hasDisposeAfter) {
18867
+ (_b = this.#disposed) == null ? void 0 : _b.push([v, k, "delete"]);
18868
+ }
18869
+ }
18870
+ }
18871
+ this.#keyMap.clear();
18872
+ this.#valList.fill(void 0);
18873
+ this.#keyList.fill(void 0);
18874
+ if (this.#ttls && this.#starts) {
18875
+ this.#ttls.fill(0);
18876
+ this.#starts.fill(0);
18877
+ }
18878
+ if (this.#sizes) {
18879
+ this.#sizes.fill(0);
18880
+ }
18881
+ this.#head = 0;
18882
+ this.#tail = 0;
18883
+ this.#free.length = 0;
18884
+ this.#calculatedSize = 0;
18885
+ this.#size = 0;
18886
+ if (this.#hasDisposeAfter && this.#disposed) {
18887
+ const dt = this.#disposed;
18888
+ let task;
18889
+ while (task = dt == null ? void 0 : dt.shift()) {
18890
+ (_c = this.#disposeAfter) == null ? void 0 : _c.call(this, ...task);
18891
+ }
18892
+ }
17861
18893
  }
17862
- if (hit)
17863
- fn.call(thisp, hit.value, hit.key, self2);
17864
18894
  };
17865
- module2.exports = LRUCache;
18895
+ exports2.LRUCache = LRUCache;
17866
18896
  }
17867
18897
  });
17868
18898
 
17869
18899
  // node_modules/@octokit/auth-app/dist-node/index.js
17870
18900
  var require_dist_node12 = __commonJS({
17871
- "node_modules/@octokit/auth-app/dist-node/index.js"(exports2) {
18901
+ "node_modules/@octokit/auth-app/dist-node/index.js"(exports2, module2) {
17872
18902
  "use strict";
17873
- Object.defineProperty(exports2, "__esModule", { value: true });
17874
- function _interopDefault(ex) {
17875
- return ex && typeof ex === "object" && "default" in ex ? ex["default"] : ex;
17876
- }
17877
- var universalUserAgent = require_dist_node();
17878
- var request = require_dist_node5();
17879
- var authOauthApp = require_dist_node10();
17880
- var deprecation = require_dist_node3();
17881
- var universalGithubAppJwt = require_dist_node11();
17882
- var LRU = _interopDefault(require_lru_cache2());
17883
- var authOauthUser = require_dist_node9();
18903
+ var __defProp2 = Object.defineProperty;
18904
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
18905
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
18906
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
18907
+ var __export = (target, all) => {
18908
+ for (var name in all)
18909
+ __defProp2(target, name, { get: all[name], enumerable: true });
18910
+ };
18911
+ var __copyProps2 = (to, from, except, desc) => {
18912
+ if (from && typeof from === "object" || typeof from === "function") {
18913
+ for (let key of __getOwnPropNames2(from))
18914
+ if (!__hasOwnProp2.call(to, key) && key !== except)
18915
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
18916
+ }
18917
+ return to;
18918
+ };
18919
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
18920
+ var dist_src_exports = {};
18921
+ __export(dist_src_exports, {
18922
+ createAppAuth: () => createAppAuth2,
18923
+ createOAuthUserAuth: () => import_auth_oauth_user2.createOAuthUserAuth
18924
+ });
18925
+ module2.exports = __toCommonJS(dist_src_exports);
18926
+ var import_universal_user_agent = require_dist_node();
18927
+ var import_request = require_dist_node5();
18928
+ var import_auth_oauth_app = require_dist_node10();
18929
+ var import_deprecation = require_dist_node3();
18930
+ var import_universal_github_app_jwt = require_dist_node11();
17884
18931
  async function getAppAuthentication({
17885
18932
  appId,
17886
18933
  privateKey,
17887
18934
  timeDifference
17888
18935
  }) {
17889
18936
  try {
17890
- const appAuthentication = await universalGithubAppJwt.githubAppJwt({
18937
+ const appAuthentication = await (0, import_universal_github_app_jwt.githubAppJwt)({
17891
18938
  id: +appId,
17892
18939
  privateKey,
17893
18940
  now: timeDifference && Math.floor(Date.now() / 1e3) + timeDifference
@@ -17900,18 +18947,21 @@ var require_dist_node12 = __commonJS({
17900
18947
  };
17901
18948
  } catch (error) {
17902
18949
  if (privateKey === "-----BEGIN RSA PRIVATE KEY-----") {
17903
- throw new Error("The 'privateKey` option contains only the first line '-----BEGIN RSA PRIVATE KEY-----'. If you are setting it using a `.env` file, make sure it is set on a single line with newlines replaced by '\n'");
18950
+ throw new Error(
18951
+ "The 'privateKey` option contains only the first line '-----BEGIN RSA PRIVATE KEY-----'. If you are setting it using a `.env` file, make sure it is set on a single line with newlines replaced by '\n'"
18952
+ );
17904
18953
  } else {
17905
18954
  throw error;
17906
18955
  }
17907
18956
  }
17908
18957
  }
18958
+ var import_lru_cache = require_cjs();
17909
18959
  function getCache() {
17910
- return new LRU({
18960
+ return new import_lru_cache.LRUCache({
17911
18961
  // cache max. 15000 tokens, that will use less than 10mb memory
17912
18962
  max: 15e3,
17913
18963
  // Cache for 1 minute less than GitHub expiry
17914
- maxAge: 1e3 * 60 * 59
18964
+ ttl: 1e3 * 60 * 59
17915
18965
  });
17916
18966
  }
17917
18967
  async function get(cache, options) {
@@ -17920,7 +18970,14 @@ var require_dist_node12 = __commonJS({
17920
18970
  if (!result) {
17921
18971
  return;
17922
18972
  }
17923
- const [token, createdAt, expiresAt, repositorySelection, permissionsString, singleFileName] = result.split("|");
18973
+ const [
18974
+ token,
18975
+ createdAt,
18976
+ expiresAt,
18977
+ repositorySelection,
18978
+ permissionsString,
18979
+ singleFileName
18980
+ ] = result.split("|");
17924
18981
  const permissions = options.permissions || permissionsString.split(/,/).reduce((permissions2, string) => {
17925
18982
  if (/!$/.test(string)) {
17926
18983
  permissions2[string.slice(0, -1)] = "write";
@@ -17942,8 +18999,17 @@ var require_dist_node12 = __commonJS({
17942
18999
  }
17943
19000
  async function set(cache, options, data) {
17944
19001
  const key = optionsToCacheKey(options);
17945
- const permissionsString = options.permissions ? "" : Object.keys(data.permissions).map((name) => `${name}${data.permissions[name] === "write" ? "!" : ""}`).join(",");
17946
- const value = [data.token, data.createdAt, data.expiresAt, data.repositorySelection, permissionsString, data.singleFileName].join("|");
19002
+ const permissionsString = options.permissions ? "" : Object.keys(data.permissions).map(
19003
+ (name) => `${name}${data.permissions[name] === "write" ? "!" : ""}`
19004
+ ).join(",");
19005
+ const value = [
19006
+ data.token,
19007
+ data.createdAt,
19008
+ data.expiresAt,
19009
+ data.repositorySelection,
19010
+ permissionsString,
19011
+ data.singleFileName
19012
+ ].join("|");
17947
19013
  await cache.set(key, value);
17948
19014
  }
17949
19015
  function optionsToCacheKey({
@@ -17955,7 +19021,12 @@ var require_dist_node12 = __commonJS({
17955
19021
  const permissionsString = Object.keys(permissions).sort().map((name) => permissions[name] === "read" ? name : `${name}!`).join(",");
17956
19022
  const repositoryIdsString = repositoryIds.sort().join(",");
17957
19023
  const repositoryNamesString = repositoryNames.join(",");
17958
- return [installationId, repositoryIdsString, repositoryNamesString, permissionsString].filter(Boolean).join("|");
19024
+ return [
19025
+ installationId,
19026
+ repositoryIdsString,
19027
+ repositoryNamesString,
19028
+ permissionsString
19029
+ ].filter(Boolean).join("|");
17959
19030
  }
17960
19031
  function toTokenAuthentication({
17961
19032
  installationId,
@@ -17968,45 +19039,45 @@ var require_dist_node12 = __commonJS({
17968
19039
  repositoryNames,
17969
19040
  singleFileName
17970
19041
  }) {
17971
- return Object.assign({
17972
- type: "token",
17973
- tokenType: "installation",
17974
- token,
17975
- installationId,
17976
- permissions,
17977
- createdAt,
17978
- expiresAt,
17979
- repositorySelection
17980
- }, repositoryIds ? {
17981
- repositoryIds
17982
- } : null, repositoryNames ? {
17983
- repositoryNames
17984
- } : null, singleFileName ? {
17985
- singleFileName
17986
- } : null);
19042
+ return Object.assign(
19043
+ {
19044
+ type: "token",
19045
+ tokenType: "installation",
19046
+ token,
19047
+ installationId,
19048
+ permissions,
19049
+ createdAt,
19050
+ expiresAt,
19051
+ repositorySelection
19052
+ },
19053
+ repositoryIds ? { repositoryIds } : null,
19054
+ repositoryNames ? { repositoryNames } : null,
19055
+ singleFileName ? { singleFileName } : null
19056
+ );
17987
19057
  }
17988
19058
  async function getInstallationAuthentication(state, options, customRequest) {
17989
19059
  const installationId = Number(options.installationId || state.installationId);
17990
19060
  if (!installationId) {
17991
- throw new Error("[@octokit/auth-app] installationId option is required for installation authentication.");
19061
+ throw new Error(
19062
+ "[@octokit/auth-app] installationId option is required for installation authentication."
19063
+ );
17992
19064
  }
17993
19065
  if (options.factory) {
17994
- const {
17995
- type,
17996
- factory,
17997
- oauthApp,
17998
- ...factoryAuthOptions
17999
- } = {
19066
+ const { type, factory, oauthApp, ...factoryAuthOptions } = {
18000
19067
  ...state,
18001
19068
  ...options
18002
19069
  };
18003
19070
  return factory(factoryAuthOptions);
18004
19071
  }
18005
- const optionsWithInstallationTokenFromState = Object.assign({
18006
- installationId
18007
- }, options);
19072
+ const optionsWithInstallationTokenFromState = Object.assign(
19073
+ { installationId },
19074
+ options
19075
+ );
18008
19076
  if (!options.refresh) {
18009
- const result = await get(state.cache, optionsWithInstallationTokenFromState);
19077
+ const result = await get(
19078
+ state.cache,
19079
+ optionsWithInstallationTokenFromState
19080
+ );
18010
19081
  if (result) {
18011
19082
  const {
18012
19083
  token: token2,
@@ -18032,7 +19103,7 @@ var require_dist_node12 = __commonJS({
18032
19103
  }
18033
19104
  }
18034
19105
  const appAuthentication = await getAppAuthentication(state);
18035
- const request2 = customRequest || state.request;
19106
+ const request = customRequest || state.request;
18036
19107
  const {
18037
19108
  data: {
18038
19109
  token,
@@ -18042,7 +19113,7 @@ var require_dist_node12 = __commonJS({
18042
19113
  repository_selection: repositorySelectionOptional,
18043
19114
  single_file: singleFileName
18044
19115
  }
18045
- } = await request2("POST /app/installations/{installation_id}/access_tokens", {
19116
+ } = await request("POST /app/installations/{installation_id}/access_tokens", {
18046
19117
  installation_id: installationId,
18047
19118
  repository_ids: options.repositoryIds,
18048
19119
  repositories: options.repositoryNames,
@@ -18088,13 +19159,14 @@ var require_dist_node12 = __commonJS({
18088
19159
  case "oauth":
18089
19160
  state.log.warn(
18090
19161
  // @ts-expect-error `log.warn()` expects string
18091
- new deprecation.Deprecation(`[@octokit/auth-app] {type: "oauth"} is deprecated. Use {type: "oauth-app"} instead`)
19162
+ new import_deprecation.Deprecation(
19163
+ `[@octokit/auth-app] {type: "oauth"} is deprecated. Use {type: "oauth-app"} instead`
19164
+ )
18092
19165
  );
18093
19166
  case "oauth-app":
18094
- return state.oauthApp({
18095
- type: "oauth-app"
18096
- });
19167
+ return state.oauthApp({ type: "oauth-app" });
18097
19168
  case "installation":
19169
+ authOptions;
18098
19170
  return getInstallationAuthentication(state, {
18099
19171
  ...authOptions,
18100
19172
  type: "installation"
@@ -18105,34 +19177,60 @@ var require_dist_node12 = __commonJS({
18105
19177
  throw new Error(`Invalid auth type: ${authOptions.type}`);
18106
19178
  }
18107
19179
  }
18108
- var PATHS = ["/app", "/app/hook/config", "/app/hook/deliveries", "/app/hook/deliveries/{delivery_id}", "/app/hook/deliveries/{delivery_id}/attempts", "/app/installations", "/app/installations/{installation_id}", "/app/installations/{installation_id}/access_tokens", "/app/installations/{installation_id}/suspended", "/marketplace_listing/accounts/{account_id}", "/marketplace_listing/plan", "/marketplace_listing/plans", "/marketplace_listing/plans/{plan_id}/accounts", "/marketplace_listing/stubbed/accounts/{account_id}", "/marketplace_listing/stubbed/plan", "/marketplace_listing/stubbed/plans", "/marketplace_listing/stubbed/plans/{plan_id}/accounts", "/orgs/{org}/installation", "/repos/{owner}/{repo}/installation", "/users/{username}/installation"];
19180
+ var import_auth_oauth_user = require_dist_node9();
19181
+ var PATHS = [
19182
+ "/app",
19183
+ "/app/hook/config",
19184
+ "/app/hook/deliveries",
19185
+ "/app/hook/deliveries/{delivery_id}",
19186
+ "/app/hook/deliveries/{delivery_id}/attempts",
19187
+ "/app/installations",
19188
+ "/app/installations/{installation_id}",
19189
+ "/app/installations/{installation_id}/access_tokens",
19190
+ "/app/installations/{installation_id}/suspended",
19191
+ "/marketplace_listing/accounts/{account_id}",
19192
+ "/marketplace_listing/plan",
19193
+ "/marketplace_listing/plans",
19194
+ "/marketplace_listing/plans/{plan_id}/accounts",
19195
+ "/marketplace_listing/stubbed/accounts/{account_id}",
19196
+ "/marketplace_listing/stubbed/plan",
19197
+ "/marketplace_listing/stubbed/plans",
19198
+ "/marketplace_listing/stubbed/plans/{plan_id}/accounts",
19199
+ "/orgs/{org}/installation",
19200
+ "/repos/{owner}/{repo}/installation",
19201
+ "/users/{username}/installation"
19202
+ ];
18109
19203
  function routeMatcher(paths) {
18110
- const regexes = paths.map((p) => p.split("/").map((c) => c.startsWith("{") ? "(?:.+?)" : c).join("/"));
18111
- const regex = `^(?:${regexes.map((r) => `(?:${r})`).join("|")})[^/]*$`;
19204
+ const regexes = paths.map(
19205
+ (p) => p.split("/").map((c) => c.startsWith("{") ? "(?:.+?)" : c).join("/")
19206
+ );
19207
+ const regex = `^(?:${regexes.map((r) => `(?:${r})`).join("|")})$`;
18112
19208
  return new RegExp(regex, "i");
18113
19209
  }
18114
19210
  var REGEX = routeMatcher(PATHS);
18115
19211
  function requiresAppAuth(url) {
18116
- return !!url && REGEX.test(url);
19212
+ return !!url && REGEX.test(url.split("?")[0]);
18117
19213
  }
18118
19214
  var FIVE_SECONDS_IN_MS = 5 * 1e3;
18119
19215
  function isNotTimeSkewError(error) {
18120
- return !(error.message.match(/'Expiration time' claim \('exp'\) must be a numeric value representing the future time at which the assertion expires/) || error.message.match(/'Issued at' claim \('iat'\) must be an Integer representing the time that the assertion was issued/));
19216
+ return !(error.message.match(
19217
+ /'Expiration time' claim \('exp'\) must be a numeric value representing the future time at which the assertion expires/
19218
+ ) || error.message.match(
19219
+ /'Issued at' claim \('iat'\) must be an Integer representing the time that the assertion was issued/
19220
+ ));
18121
19221
  }
18122
- async function hook(state, request2, route, parameters) {
18123
- const endpoint = request2.endpoint.merge(route, parameters);
19222
+ async function hook(state, request, route, parameters) {
19223
+ const endpoint = request.endpoint.merge(route, parameters);
18124
19224
  const url = endpoint.url;
18125
19225
  if (/\/login\/oauth\/access_token$/.test(url)) {
18126
- return request2(endpoint);
19226
+ return request(endpoint);
18127
19227
  }
18128
- if (requiresAppAuth(url.replace(request2.endpoint.DEFAULTS.baseUrl, ""))) {
18129
- const {
18130
- token: token2
18131
- } = await getAppAuthentication(state);
19228
+ if (requiresAppAuth(url.replace(request.endpoint.DEFAULTS.baseUrl, ""))) {
19229
+ const { token: token2 } = await getAppAuthentication(state);
18132
19230
  endpoint.headers.authorization = `bearer ${token2}`;
18133
19231
  let response;
18134
19232
  try {
18135
- response = await request2(endpoint);
19233
+ response = await request(endpoint);
18136
19234
  } catch (error) {
18137
19235
  if (isNotTimeSkewError(error)) {
18138
19236
  throw error;
@@ -18140,43 +19238,45 @@ var require_dist_node12 = __commonJS({
18140
19238
  if (typeof error.response.headers.date === "undefined") {
18141
19239
  throw error;
18142
19240
  }
18143
- const diff = Math.floor((Date.parse(error.response.headers.date) - Date.parse((/* @__PURE__ */ new Date()).toString())) / 1e3);
19241
+ const diff = Math.floor(
19242
+ (Date.parse(error.response.headers.date) - Date.parse((/* @__PURE__ */ new Date()).toString())) / 1e3
19243
+ );
18144
19244
  state.log.warn(error.message);
18145
- state.log.warn(`[@octokit/auth-app] GitHub API time and system time are different by ${diff} seconds. Retrying request with the difference accounted for.`);
18146
- const {
18147
- token: token3
18148
- } = await getAppAuthentication({
19245
+ state.log.warn(
19246
+ `[@octokit/auth-app] GitHub API time and system time are different by ${diff} seconds. Retrying request with the difference accounted for.`
19247
+ );
19248
+ const { token: token3 } = await getAppAuthentication({
18149
19249
  ...state,
18150
19250
  timeDifference: diff
18151
19251
  });
18152
19252
  endpoint.headers.authorization = `bearer ${token3}`;
18153
- return request2(endpoint);
19253
+ return request(endpoint);
18154
19254
  }
18155
19255
  return response;
18156
19256
  }
18157
- if (authOauthUser.requiresBasicAuth(url)) {
18158
- const authentication = await state.oauthApp({
18159
- type: "oauth-app"
18160
- });
19257
+ if ((0, import_auth_oauth_user.requiresBasicAuth)(url)) {
19258
+ const authentication = await state.oauthApp({ type: "oauth-app" });
18161
19259
  endpoint.headers.authorization = authentication.headers.authorization;
18162
- return request2(endpoint);
19260
+ return request(endpoint);
18163
19261
  }
18164
- const {
18165
- token,
18166
- createdAt
18167
- } = await getInstallationAuthentication(
19262
+ const { token, createdAt } = await getInstallationAuthentication(
18168
19263
  state,
18169
19264
  // @ts-expect-error TBD
18170
19265
  {},
18171
- request2
19266
+ request
18172
19267
  );
18173
19268
  endpoint.headers.authorization = `token ${token}`;
18174
- return sendRequestWithRetries(state, request2, endpoint, createdAt);
19269
+ return sendRequestWithRetries(
19270
+ state,
19271
+ request,
19272
+ endpoint,
19273
+ createdAt
19274
+ );
18175
19275
  }
18176
- async function sendRequestWithRetries(state, request2, options, createdAt, retries = 0) {
19276
+ async function sendRequestWithRetries(state, request, options, createdAt, retries = 0) {
18177
19277
  const timeSinceTokenCreationInMs = +/* @__PURE__ */ new Date() - +new Date(createdAt);
18178
19278
  try {
18179
- return await request2(options);
19279
+ return await request(options);
18180
19280
  } catch (error) {
18181
19281
  if (error.status !== 401) {
18182
19282
  throw error;
@@ -18189,58 +19289,64 @@ var require_dist_node12 = __commonJS({
18189
19289
  }
18190
19290
  ++retries;
18191
19291
  const awaitTime = retries * 1e3;
18192
- state.log.warn(`[@octokit/auth-app] Retrying after 401 response to account for token replication delay (retry: ${retries}, wait: ${awaitTime / 1e3}s)`);
19292
+ state.log.warn(
19293
+ `[@octokit/auth-app] Retrying after 401 response to account for token replication delay (retry: ${retries}, wait: ${awaitTime / 1e3}s)`
19294
+ );
18193
19295
  await new Promise((resolve) => setTimeout(resolve, awaitTime));
18194
- return sendRequestWithRetries(state, request2, options, createdAt, retries);
19296
+ return sendRequestWithRetries(state, request, options, createdAt, retries);
18195
19297
  }
18196
19298
  }
18197
- var VERSION = "4.0.9";
19299
+ var VERSION = "4.0.13";
19300
+ var import_auth_oauth_user2 = require_dist_node9();
18198
19301
  function createAppAuth2(options) {
18199
19302
  if (!options.appId) {
18200
19303
  throw new Error("[@octokit/auth-app] appId option is required");
18201
19304
  }
18202
19305
  if (!Number.isFinite(+options.appId)) {
18203
- throw new Error("[@octokit/auth-app] appId option must be a number or numeric string");
19306
+ throw new Error(
19307
+ "[@octokit/auth-app] appId option must be a number or numeric string"
19308
+ );
18204
19309
  }
18205
19310
  if (!options.privateKey) {
18206
19311
  throw new Error("[@octokit/auth-app] privateKey option is required");
18207
19312
  }
18208
19313
  if ("installationId" in options && !options.installationId) {
18209
- throw new Error("[@octokit/auth-app] installationId is set to a falsy value");
19314
+ throw new Error(
19315
+ "[@octokit/auth-app] installationId is set to a falsy value"
19316
+ );
18210
19317
  }
18211
- const log = Object.assign({
18212
- warn: console.warn.bind(console)
18213
- }, options.log);
18214
- const request$1 = options.request || request.request.defaults({
19318
+ const log = Object.assign(
19319
+ {
19320
+ warn: console.warn.bind(console)
19321
+ },
19322
+ options.log
19323
+ );
19324
+ const request = options.request || import_request.request.defaults({
18215
19325
  headers: {
18216
- "user-agent": `octokit-auth-app.js/${VERSION} ${universalUserAgent.getUserAgent()}`
19326
+ "user-agent": `octokit-auth-app.js/${VERSION} ${(0, import_universal_user_agent.getUserAgent)()}`
18217
19327
  }
18218
19328
  });
18219
- const state = Object.assign({
18220
- request: request$1,
18221
- cache: getCache()
18222
- }, options, options.installationId ? {
18223
- installationId: Number(options.installationId)
18224
- } : {}, {
18225
- log,
18226
- oauthApp: authOauthApp.createOAuthAppAuth({
18227
- clientType: "github-app",
18228
- clientId: options.clientId || "",
18229
- clientSecret: options.clientSecret || "",
18230
- request: request$1
18231
- })
18232
- });
19329
+ const state = Object.assign(
19330
+ {
19331
+ request,
19332
+ cache: getCache()
19333
+ },
19334
+ options,
19335
+ options.installationId ? { installationId: Number(options.installationId) } : {},
19336
+ {
19337
+ log,
19338
+ oauthApp: (0, import_auth_oauth_app.createOAuthAppAuth)({
19339
+ clientType: "github-app",
19340
+ clientId: options.clientId || "",
19341
+ clientSecret: options.clientSecret || "",
19342
+ request
19343
+ })
19344
+ }
19345
+ );
18233
19346
  return Object.assign(auth.bind(null, state), {
18234
19347
  hook: hook.bind(null, state)
18235
19348
  });
18236
19349
  }
18237
- Object.defineProperty(exports2, "createOAuthUserAuth", {
18238
- enumerable: true,
18239
- get: function() {
18240
- return authOauthUser.createOAuthUserAuth;
18241
- }
18242
- });
18243
- exports2.createAppAuth = createAppAuth2;
18244
19350
  }
18245
19351
  });
18246
19352
 
@@ -18389,12 +19495,35 @@ var require_before_after_hook = __commonJS({
18389
19495
 
18390
19496
  // node_modules/@octokit/graphql/dist-node/index.js
18391
19497
  var require_dist_node13 = __commonJS({
18392
- "node_modules/@octokit/graphql/dist-node/index.js"(exports2) {
19498
+ "node_modules/@octokit/graphql/dist-node/index.js"(exports2, module2) {
18393
19499
  "use strict";
18394
- Object.defineProperty(exports2, "__esModule", { value: true });
18395
- var request = require_dist_node5();
18396
- var universalUserAgent = require_dist_node();
18397
- var VERSION = "5.0.5";
19500
+ var __defProp2 = Object.defineProperty;
19501
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
19502
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
19503
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
19504
+ var __export = (target, all) => {
19505
+ for (var name in all)
19506
+ __defProp2(target, name, { get: all[name], enumerable: true });
19507
+ };
19508
+ var __copyProps2 = (to, from, except, desc) => {
19509
+ if (from && typeof from === "object" || typeof from === "function") {
19510
+ for (let key of __getOwnPropNames2(from))
19511
+ if (!__hasOwnProp2.call(to, key) && key !== except)
19512
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
19513
+ }
19514
+ return to;
19515
+ };
19516
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
19517
+ var dist_src_exports = {};
19518
+ __export(dist_src_exports, {
19519
+ GraphqlResponseError: () => GraphqlResponseError,
19520
+ graphql: () => graphql2,
19521
+ withCustomRequest: () => withCustomRequest
19522
+ });
19523
+ module2.exports = __toCommonJS(dist_src_exports);
19524
+ var import_request = require_dist_node5();
19525
+ var import_universal_user_agent = require_dist_node();
19526
+ var VERSION = "5.0.6";
18398
19527
  function _buildMessageForResponseErrors(data) {
18399
19528
  return `Request failed due to following response errors:
18400
19529
  ` + data.errors.map((e) => ` - ${e.message}`).join("\n");
@@ -18413,24 +19542,36 @@ var require_dist_node13 = __commonJS({
18413
19542
  }
18414
19543
  }
18415
19544
  };
18416
- var NON_VARIABLE_OPTIONS = ["method", "baseUrl", "url", "headers", "request", "query", "mediaType"];
19545
+ var NON_VARIABLE_OPTIONS = [
19546
+ "method",
19547
+ "baseUrl",
19548
+ "url",
19549
+ "headers",
19550
+ "request",
19551
+ "query",
19552
+ "mediaType"
19553
+ ];
18417
19554
  var FORBIDDEN_VARIABLE_OPTIONS = ["query", "method", "url"];
18418
19555
  var GHES_V3_SUFFIX_REGEX = /\/api\/v3\/?$/;
18419
19556
  function graphql(request2, query, options) {
18420
19557
  if (options) {
18421
19558
  if (typeof query === "string" && "query" in options) {
18422
- return Promise.reject(new Error(`[@octokit/graphql] "query" cannot be used as variable name`));
19559
+ return Promise.reject(
19560
+ new Error(`[@octokit/graphql] "query" cannot be used as variable name`)
19561
+ );
18423
19562
  }
18424
19563
  for (const key in options) {
18425
19564
  if (!FORBIDDEN_VARIABLE_OPTIONS.includes(key))
18426
19565
  continue;
18427
- return Promise.reject(new Error(`[@octokit/graphql] "${key}" cannot be used as variable name`));
19566
+ return Promise.reject(
19567
+ new Error(`[@octokit/graphql] "${key}" cannot be used as variable name`)
19568
+ );
18428
19569
  }
18429
19570
  }
18430
- const parsedOptions = typeof query === "string" ? Object.assign({
18431
- query
18432
- }, options) : query;
18433
- const requestOptions = Object.keys(parsedOptions).reduce((result, key) => {
19571
+ const parsedOptions = typeof query === "string" ? Object.assign({ query }, options) : query;
19572
+ const requestOptions = Object.keys(
19573
+ parsedOptions
19574
+ ).reduce((result, key) => {
18434
19575
  if (NON_VARIABLE_OPTIONS.includes(key)) {
18435
19576
  result[key] = parsedOptions[key];
18436
19577
  return result;
@@ -18451,7 +19592,11 @@ var require_dist_node13 = __commonJS({
18451
19592
  for (const key of Object.keys(response.headers)) {
18452
19593
  headers[key] = response.headers[key];
18453
19594
  }
18454
- throw new GraphqlResponseError(requestOptions, headers, response.data);
19595
+ throw new GraphqlResponseError(
19596
+ requestOptions,
19597
+ headers,
19598
+ response.data
19599
+ );
18455
19600
  }
18456
19601
  return response.data.data;
18457
19602
  });
@@ -18466,9 +19611,9 @@ var require_dist_node13 = __commonJS({
18466
19611
  endpoint: newRequest.endpoint
18467
19612
  });
18468
19613
  }
18469
- var graphql$1 = withDefaults(request.request, {
19614
+ var graphql2 = withDefaults(import_request.request, {
18470
19615
  headers: {
18471
- "user-agent": `octokit-graphql.js/${VERSION} ${universalUserAgent.getUserAgent()}`
19616
+ "user-agent": `octokit-graphql.js/${VERSION} ${(0, import_universal_user_agent.getUserAgent)()}`
18472
19617
  },
18473
19618
  method: "POST",
18474
19619
  url: "/graphql"
@@ -18479,9 +19624,6 @@ var require_dist_node13 = __commonJS({
18479
19624
  url: "/graphql"
18480
19625
  });
18481
19626
  }
18482
- exports2.GraphqlResponseError = GraphqlResponseError;
18483
- exports2.graphql = graphql$1;
18484
- exports2.withCustomRequest = withCustomRequest;
18485
19627
  }
18486
19628
  });
18487
19629
 
@@ -18533,20 +19675,78 @@ var require_dist_node14 = __commonJS({
18533
19675
 
18534
19676
  // node_modules/@octokit/core/dist-node/index.js
18535
19677
  var require_dist_node15 = __commonJS({
18536
- "node_modules/@octokit/core/dist-node/index.js"(exports2) {
19678
+ "node_modules/@octokit/core/dist-node/index.js"(exports2, module2) {
18537
19679
  "use strict";
18538
- Object.defineProperty(exports2, "__esModule", { value: true });
18539
- var universalUserAgent = require_dist_node();
18540
- var beforeAfterHook = require_before_after_hook();
18541
- var request = require_dist_node5();
18542
- var graphql = require_dist_node13();
18543
- var authToken = require_dist_node14();
18544
- var VERSION = "4.2.0";
19680
+ var __defProp2 = Object.defineProperty;
19681
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
19682
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
19683
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
19684
+ var __export = (target, all) => {
19685
+ for (var name in all)
19686
+ __defProp2(target, name, { get: all[name], enumerable: true });
19687
+ };
19688
+ var __copyProps2 = (to, from, except, desc) => {
19689
+ if (from && typeof from === "object" || typeof from === "function") {
19690
+ for (let key of __getOwnPropNames2(from))
19691
+ if (!__hasOwnProp2.call(to, key) && key !== except)
19692
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
19693
+ }
19694
+ return to;
19695
+ };
19696
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
19697
+ var dist_src_exports = {};
19698
+ __export(dist_src_exports, {
19699
+ Octokit: () => Octokit2
19700
+ });
19701
+ module2.exports = __toCommonJS(dist_src_exports);
19702
+ var import_universal_user_agent = require_dist_node();
19703
+ var import_before_after_hook = require_before_after_hook();
19704
+ var import_request = require_dist_node5();
19705
+ var import_graphql = require_dist_node13();
19706
+ var import_auth_token = require_dist_node14();
19707
+ var VERSION = "4.2.1";
18545
19708
  var Octokit2 = class {
19709
+ static defaults(defaults) {
19710
+ const OctokitWithDefaults = class extends this {
19711
+ constructor(...args) {
19712
+ const options = args[0] || {};
19713
+ if (typeof defaults === "function") {
19714
+ super(defaults(options));
19715
+ return;
19716
+ }
19717
+ super(
19718
+ Object.assign(
19719
+ {},
19720
+ defaults,
19721
+ options,
19722
+ options.userAgent && defaults.userAgent ? {
19723
+ userAgent: `${options.userAgent} ${defaults.userAgent}`
19724
+ } : null
19725
+ )
19726
+ );
19727
+ }
19728
+ };
19729
+ return OctokitWithDefaults;
19730
+ }
19731
+ /**
19732
+ * Attach a plugin (or many) to your Octokit instance.
19733
+ *
19734
+ * @example
19735
+ * const API = Octokit.plugin(plugin1, plugin2, plugin3, ...)
19736
+ */
19737
+ static plugin(...newPlugins) {
19738
+ var _a;
19739
+ const currentPlugins = this.plugins;
19740
+ const NewOctokit = (_a = class extends this {
19741
+ }, _a.plugins = currentPlugins.concat(
19742
+ newPlugins.filter((plugin) => !currentPlugins.includes(plugin))
19743
+ ), _a);
19744
+ return NewOctokit;
19745
+ }
18546
19746
  constructor(options = {}) {
18547
- const hook = new beforeAfterHook.Collection();
19747
+ const hook = new import_before_after_hook.Collection();
18548
19748
  const requestDefaults = {
18549
- baseUrl: request.request.endpoint.DEFAULTS.baseUrl,
19749
+ baseUrl: import_request.request.endpoint.DEFAULTS.baseUrl,
18550
19750
  headers: {},
18551
19751
  request: Object.assign({}, options.request, {
18552
19752
  // @ts-ignore internal usage only, no need to type
@@ -18557,7 +19757,10 @@ var require_dist_node15 = __commonJS({
18557
19757
  format: ""
18558
19758
  }
18559
19759
  };
18560
- requestDefaults.headers["user-agent"] = [options.userAgent, `octokit-core.js/${VERSION} ${universalUserAgent.getUserAgent()}`].filter(Boolean).join(" ");
19760
+ requestDefaults.headers["user-agent"] = [
19761
+ options.userAgent,
19762
+ `octokit-core.js/${VERSION} ${(0, import_universal_user_agent.getUserAgent)()}`
19763
+ ].filter(Boolean).join(" ");
18561
19764
  if (options.baseUrl) {
18562
19765
  requestDefaults.baseUrl = options.baseUrl;
18563
19766
  }
@@ -18567,16 +19770,19 @@ var require_dist_node15 = __commonJS({
18567
19770
  if (options.timeZone) {
18568
19771
  requestDefaults.headers["time-zone"] = options.timeZone;
18569
19772
  }
18570
- this.request = request.request.defaults(requestDefaults);
18571
- this.graphql = graphql.withCustomRequest(this.request).defaults(requestDefaults);
18572
- this.log = Object.assign({
18573
- debug: () => {
18574
- },
18575
- info: () => {
19773
+ this.request = import_request.request.defaults(requestDefaults);
19774
+ this.graphql = (0, import_graphql.withCustomRequest)(this.request).defaults(requestDefaults);
19775
+ this.log = Object.assign(
19776
+ {
19777
+ debug: () => {
19778
+ },
19779
+ info: () => {
19780
+ },
19781
+ warn: console.warn.bind(console),
19782
+ error: console.error.bind(console)
18576
19783
  },
18577
- warn: console.warn.bind(console),
18578
- error: console.error.bind(console)
18579
- }, options.log);
19784
+ options.log
19785
+ );
18580
19786
  this.hook = hook;
18581
19787
  if (!options.authStrategy) {
18582
19788
  if (!options.auth) {
@@ -18584,26 +19790,28 @@ var require_dist_node15 = __commonJS({
18584
19790
  type: "unauthenticated"
18585
19791
  });
18586
19792
  } else {
18587
- const auth = authToken.createTokenAuth(options.auth);
19793
+ const auth = (0, import_auth_token.createTokenAuth)(options.auth);
18588
19794
  hook.wrap("request", auth.hook);
18589
19795
  this.auth = auth;
18590
19796
  }
18591
19797
  } else {
18592
- const {
18593
- authStrategy,
18594
- ...otherOptions
18595
- } = options;
18596
- const auth = authStrategy(Object.assign({
18597
- request: this.request,
18598
- log: this.log,
18599
- // we pass the current octokit instance as well as its constructor options
18600
- // to allow for authentication strategies that return a new octokit instance
18601
- // that shares the same internal state as the current one. The original
18602
- // requirement for this was the "event-octokit" authentication strategy
18603
- // of https://github.com/probot/octokit-auth-probot.
18604
- octokit: this,
18605
- octokitOptions: otherOptions
18606
- }, options.auth));
19798
+ const { authStrategy, ...otherOptions } = options;
19799
+ const auth = authStrategy(
19800
+ Object.assign(
19801
+ {
19802
+ request: this.request,
19803
+ log: this.log,
19804
+ // we pass the current octokit instance as well as its constructor options
19805
+ // to allow for authentication strategies that return a new octokit instance
19806
+ // that shares the same internal state as the current one. The original
19807
+ // requirement for this was the "event-octokit" authentication strategy
19808
+ // of https://github.com/probot/octokit-auth-probot.
19809
+ octokit: this,
19810
+ octokitOptions: otherOptions
19811
+ },
19812
+ options.auth
19813
+ )
19814
+ );
18607
19815
  hook.wrap("request", auth.hook);
18608
19816
  this.auth = auth;
18609
19817
  }
@@ -18612,38 +19820,9 @@ var require_dist_node15 = __commonJS({
18612
19820
  Object.assign(this, plugin(this, options));
18613
19821
  });
18614
19822
  }
18615
- static defaults(defaults) {
18616
- const OctokitWithDefaults = class extends this {
18617
- constructor(...args) {
18618
- const options = args[0] || {};
18619
- if (typeof defaults === "function") {
18620
- super(defaults(options));
18621
- return;
18622
- }
18623
- super(Object.assign({}, defaults, options, options.userAgent && defaults.userAgent ? {
18624
- userAgent: `${options.userAgent} ${defaults.userAgent}`
18625
- } : null));
18626
- }
18627
- };
18628
- return OctokitWithDefaults;
18629
- }
18630
- /**
18631
- * Attach a plugin (or many) to your Octokit instance.
18632
- *
18633
- * @example
18634
- * const API = Octokit.plugin(plugin1, plugin2, plugin3, ...)
18635
- */
18636
- static plugin(...newPlugins) {
18637
- var _a;
18638
- const currentPlugins = this.plugins;
18639
- const NewOctokit = (_a = class extends this {
18640
- }, _a.plugins = currentPlugins.concat(newPlugins.filter((plugin) => !currentPlugins.includes(plugin))), _a);
18641
- return NewOctokit;
18642
- }
18643
19823
  };
18644
19824
  Octokit2.VERSION = VERSION;
18645
19825
  Octokit2.plugins = [];
18646
- exports2.Octokit = Octokit2;
18647
19826
  }
18648
19827
  });
18649
19828
 
@@ -18776,7 +19955,7 @@ exports.handler = async function(event) {
18776
19955
  privateKeySecretArn: process.env.GITHUB_PRIVATE_KEY_SECRET_ARN,
18777
19956
  privateKeySecretUrl: secretArnToUrl(process.env.GITHUB_PRIVATE_KEY_SECRET_ARN),
18778
19957
  app: {
18779
- id: "",
19958
+ id: -1,
18780
19959
  url: "",
18781
19960
  installations: []
18782
19961
  },
@@ -18838,7 +20017,7 @@ exports.handler = async function(event) {
18838
20017
  let baseUrl = baseUrlFromDomain(githubSecrets.domain);
18839
20018
  status.github.domain = githubSecrets.domain;
18840
20019
  if (githubSecrets.personalAuthToken) {
18841
- status.github.auth.type = "Personal Auth Token";
20020
+ status.github.auth.type = "Personal Access Token";
18842
20021
  status.github.auth.personalAuthToken = "*redacted*";
18843
20022
  let octokit;
18844
20023
  try {