@guren/server 2.28.0 → 2.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import { a as RedisStore, i as FileStore, n as createCacheManager, o as MemoryStore, r as TaggedCache, t as CacheManager } from "../cache-BlXopnH1.js";
1
+ import { a as RedisStore, i as FileStore, n as createCacheManager, o as MemoryStore, r as TaggedCache, t as CacheManager } from "../cache-C2Im3l7t.js";
2
2
  export { CacheManager, FileStore, MemoryStore, RedisStore, TaggedCache, createCacheManager };
@@ -28,5 +28,7 @@ export declare class FileStore implements CacheStore {
28
28
  ttl(key: string): Promise<number>;
29
29
  /** Delete expired cache files; call periodically to free disk space. */
30
30
  cleanup(): Promise<number>;
31
+ private removeIfExpired;
32
+ private restore;
31
33
  getBasePath(): string;
32
34
  }
@@ -3,8 +3,8 @@ import { n as isHotReloadRuntime, t as claimHotDisposable } from "./hot-disposab
3
3
  import { t as describeDriverMap } from "./driver-map-CkQc52j-.js";
4
4
  import { createHash, randomUUID } from "node:crypto";
5
5
  import { dirname, join } from "node:path";
6
- import { mkdir, readFile, readdir, rename, rm, rmdir, unlink, writeFile } from "node:fs/promises";
7
- import { existsSync } from "node:fs";
6
+ import { copyFile, link, mkdir, readFile, readdir, rename, rm, rmdir, unlink, writeFile } from "node:fs/promises";
7
+ import { constants, existsSync } from "node:fs";
8
8
  //#region src/redis/lazy-client.ts
9
9
  /**
10
10
  * The one rule for a `client` option that may be an ioredis instance or a
@@ -384,10 +384,7 @@ var FileStore = class {
384
384
  const filePath = this.getFilePath(key);
385
385
  const item = await this.readCacheFile(filePath);
386
386
  if (!item) return null;
387
- if (this.isExpired(item)) {
388
- await this.deleteCacheFile(filePath);
389
- return null;
390
- }
387
+ if (this.isExpired(item)) return null;
391
388
  return item.value;
392
389
  }
393
390
  async set(key, value, ttl) {
@@ -415,7 +412,7 @@ var FileStore = class {
415
412
  }
416
413
  async delete(key) {
417
414
  const filePath = this.getFilePath(key);
418
- return this.deleteCacheFile(filePath);
415
+ return this.locked(filePath, () => this.deleteCacheFile(filePath));
419
416
  }
420
417
  async clear() {
421
418
  if (!existsSync(this.basePath)) return;
@@ -474,10 +471,7 @@ var FileStore = class {
474
471
  const filePath = this.getFilePath(key);
475
472
  const item = await this.readCacheFile(filePath);
476
473
  if (!item) return -2;
477
- if (this.isExpired(item)) {
478
- await this.deleteCacheFile(filePath);
479
- return -2;
480
- }
474
+ if (this.isExpired(item)) return -2;
481
475
  if (item.expiresAt === null) return -1;
482
476
  return Math.max(0, Math.ceil((item.expiresAt - this.now()) / 1e3));
483
477
  }
@@ -498,11 +492,32 @@ var FileStore = class {
498
492
  if (!file.endsWith(this.extension)) continue;
499
493
  const filePath = join(subdirPath, file);
500
494
  const item = await this.readCacheFile(filePath);
501
- if (item && this.isExpired(item) && await this.deleteCacheFile(filePath)) cleaned++;
495
+ if (item && this.isExpired(item) && await this.locked(filePath, () => this.removeIfExpired(filePath))) cleaned++;
502
496
  }
503
497
  }
504
498
  return cleaned;
505
499
  }
500
+ async removeIfExpired(filePath) {
501
+ const grave = `${filePath}.${randomUUID()}.grave`;
502
+ try {
503
+ await rename(filePath, grave);
504
+ } catch {
505
+ return false;
506
+ }
507
+ const item = await this.readCacheFile(grave);
508
+ const expired = item !== null && this.isExpired(item);
509
+ if (expired || await this.restore(grave, filePath)) await unlink(grave).catch(() => void 0);
510
+ return expired;
511
+ }
512
+ async restore(grave, filePath) {
513
+ for (const put of [() => link(grave, filePath), () => copyFile(grave, filePath, constants.COPYFILE_EXCL)]) try {
514
+ await put();
515
+ return true;
516
+ } catch (error) {
517
+ if (error.code === "EEXIST") return true;
518
+ }
519
+ return false;
520
+ }
506
521
  getBasePath() {
507
522
  return this.basePath;
508
523
  }
@@ -4,7 +4,7 @@ import chalk from "chalk";
4
4
  import figlet from "figlet";
5
5
  import standard from "figlet/importable-fonts/Standard.js";
6
6
  //#region package.json
7
- var version = "2.28.0";
7
+ var version = "2.28.1";
8
8
  //#endregion
9
9
  //#region src/http/dev-banner.ts
10
10
  var dev_banner_exports = /* @__PURE__ */ __exportAll({
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import { o as AuthenticationException, r as getAuthContext, t as AUTH_CONTEXT_KE
18
18
  import { a as md5, c as sha256, d as verifyPassword, i as hmac, l as sha512, n as hash, o as needsRehash, r as hashPassword, s as secureCompare, t as check, u as verifyHmac } from "./Hash-D2DFd8xX.js";
19
19
  import { _ as verifyApiToken, a as getApiToken, c as hasBearerHeader, d as revokeAllApiTokens, f as revokeApiToken, g as tokenCanAny, h as tokenCanAll, i as createBearerTokenMiddleware, l as parseApiToken, m as tokenCan, n as MemoryApiTokenStore, o as getApiTokenOrFail, r as createApiToken, s as getUserApiTokens, t as API_TOKEN_KEY, u as readBearerToken } from "./api-token-BbgDEd6j.js";
20
20
  import { a as runInRequestScope, i as keepAlive, n as filterSensitiveData, t as Logger } from "./Logger-DWXdtLSJ.js";
21
- import { a as RedisStore, i as FileStore, n as createCacheManager, o as MemoryStore, r as TaggedCache, s as resolveLazyRedisClient, t as CacheManager } from "./cache-BlXopnH1.js";
21
+ import { a as RedisStore, i as FileStore, n as createCacheManager, o as MemoryStore, r as TaggedCache, s as resolveLazyRedisClient, t as CacheManager } from "./cache-C2Im3l7t.js";
22
22
  import { n as createRedisClient, r as RedisSessionStore } from "./client-C5Wj9P9o.js";
23
23
  import { r as isMcpEndpointEnabled } from "./endpoint-Coq0K_6I.js";
24
24
  import { n as isHotReloadRuntime, r as matchingOpenParen, t as claimHotDisposable } from "./hot-disposables-W2fH-GID.js";
@@ -3221,7 +3221,7 @@ let devBanner;
3221
3221
  */
3222
3222
  async function loadDevBanner() {
3223
3223
  if (typeof process === "undefined") return devBanner;
3224
- if (process.env.NODE_ENV !== "production") devBanner ??= await import("./dev-banner-bekDeLgL.js").then((n) => n.n);
3224
+ if (process.env.NODE_ENV !== "production") devBanner ??= await import("./dev-banner-DnaL8Ku6.js").then((n) => n.n);
3225
3225
  return devBanner;
3226
3226
  }
3227
3227
  function clearManagedViteEnv() {
@@ -2,7 +2,7 @@ import { a as trimTrailingSlashes, n as isRealPathWithin, t as isPathWithin } fr
2
2
  import { n as parseImportMap } from "../inertia-defaults-BjrcT7za.js";
3
3
  import { n as hash } from "../Hash-D2DFd8xX.js";
4
4
  import { a as getManifestCss, c as isViteProduction, d as startViteDevServer, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-wPxfAzjW.js";
5
- import { r as logDevServerBanner, t as GUREN_ASCII_ART } from "../dev-banner-bekDeLgL.js";
5
+ import { r as logDevServerBanner, t as GUREN_ASCII_ART } from "../dev-banner-DnaL8Ku6.js";
6
6
  import { createRequire } from "node:module";
7
7
  import { dirname, extname, join, resolve } from "node:path";
8
8
  import { fileURLToPath } from "node:url";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/server",
3
- "version": "2.28.0",
3
+ "version": "2.28.1",
4
4
  "description": "HTTP layer of the Guren framework, on Hono: routing, controllers, middleware, auth, sessions, queues and the AWS Lambda adapter. Applications import it through @guren/core.",
5
5
  "keywords": [
6
6
  "guren",