@bgord/bun 0.23.2 → 0.23.4

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 (36) hide show
  1. package/dist/cache-file.service.d.ts +9 -0
  2. package/dist/cache-file.service.d.ts.map +1 -0
  3. package/dist/cache-file.service.js +27 -0
  4. package/dist/cache-file.service.js.map +1 -0
  5. package/dist/file-hash-noop.adapter.d.ts +1 -0
  6. package/dist/file-hash-noop.adapter.d.ts.map +1 -1
  7. package/dist/file-hash-noop.adapter.js +6 -1
  8. package/dist/file-hash-noop.adapter.js.map +1 -1
  9. package/dist/file-hash-sha256-bun.adapter.d.ts +1 -0
  10. package/dist/file-hash-sha256-bun.adapter.d.ts.map +1 -1
  11. package/dist/file-hash-sha256-bun.adapter.js +2 -0
  12. package/dist/file-hash-sha256-bun.adapter.js.map +1 -1
  13. package/dist/file-hash.port.d.ts +1 -0
  14. package/dist/file-hash.port.d.ts.map +1 -1
  15. package/dist/i18n.service.d.ts +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/remote-file-storage-noop.adapter.d.ts.map +1 -1
  21. package/dist/remote-file-storage-noop.adapter.js +1 -0
  22. package/dist/remote-file-storage-noop.adapter.js.map +1 -1
  23. package/dist/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +5 -5
  25. package/readme.md +1 -1
  26. package/src/cache-file.service.ts +36 -0
  27. package/src/file-hash-noop.adapter.ts +6 -1
  28. package/src/file-hash-sha256-bun.adapter.ts +2 -0
  29. package/src/file-hash.port.ts +6 -1
  30. package/src/index.ts +1 -1
  31. package/src/remote-file-storage-noop.adapter.ts +1 -0
  32. package/dist/cache-static-files.middleware.d.ts +0 -9
  33. package/dist/cache-static-files.middleware.d.ts.map +0 -1
  34. package/dist/cache-static-files.middleware.js +0 -25
  35. package/dist/cache-static-files.middleware.js.map +0 -1
  36. package/src/cache-static-files.middleware.ts +0 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/bun",
3
- "version": "0.23.2",
3
+ "version": "0.23.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": "Bartosz Gordon",
@@ -34,12 +34,12 @@
34
34
  "only-allow": "1.2.1",
35
35
  "shellcheck": "4.1.0",
36
36
  "typescript": "5.9.2",
37
- "zod": "4.1.3"
37
+ "zod": "4.1.5"
38
38
  },
39
39
  "dependencies": {
40
40
  "@axiomhq/winston": "1.3.1",
41
- "@bgord/tools": "0.12.18",
42
- "@hono/ua-blocker": "0.1.8",
41
+ "@bgord/tools": "0.12.20",
42
+ "@hono/ua-blocker": "0.1.9",
43
43
  "better-auth": "1.3.7",
44
44
  "check-disk-space": "3.4.0",
45
45
  "croner": "9.1.0",
@@ -55,6 +55,6 @@
55
55
  "yazl": "3.3.1"
56
56
  },
57
57
  "peerDependencies": {
58
- "zod": "4.1.3"
58
+ "zod": "4.1.5"
59
59
  }
60
60
  }
package/readme.md CHANGED
@@ -29,9 +29,9 @@ src/
29
29
  ├── better-auth-logger.service.ts
30
30
  ├── bots.vo.ts
31
31
  ├── build-info-repository.service.ts
32
+ ├── cache-file.service.ts
32
33
  ├── cache-resolver.service.ts
33
34
  ├── cache-response.middleware.ts
34
- ├── cache-static-files.middleware.ts
35
35
  ├── client-from-hono.adapter.ts
36
36
  ├── client.vo.ts
37
37
  ├── command-envelope.ts
@@ -0,0 +1,36 @@
1
+ import type { FileHashResult } from "./file-hash.port";
2
+
3
+ type CacheFileOverridesType = Record<string, string>;
4
+
5
+ interface CacheFileHandler {
6
+ notModified(options: FileHashResult, overrides?: CacheFileOverridesType): Response;
7
+ fresh(options: FileHashResult, overrides?: CacheFileOverridesType): Headers;
8
+ }
9
+
10
+ export const CacheFileMustRevalidate: CacheFileHandler = {
11
+ notModified(options: FileHashResult, overrides: CacheFileOverridesType = {}) {
12
+ return new Response(null, {
13
+ status: 304,
14
+ headers: new Headers({
15
+ ETag: options.etag,
16
+ "Cache-Control": "private, max-age=0, must-revalidate",
17
+ "Last-Modified": new Date(options.lastModified).toUTCString(),
18
+ Vary: "Authorization, Cookie",
19
+ ...overrides,
20
+ }),
21
+ });
22
+ },
23
+
24
+ fresh(options: FileHashResult, overrides: CacheFileOverridesType = {}) {
25
+ return new Headers({
26
+ "Content-Type": options.mime.raw,
27
+ "Cache-Control": "private, max-age=0, must-revalidate",
28
+ ETag: options.etag,
29
+ "Content-Length": options.size.toBytes().toString(),
30
+ "Last-Modified": new Date(options.lastModified).toUTCString(),
31
+ "Accept-Ranges": "bytes",
32
+ Vary: "Authorization, Cookie",
33
+ ...overrides,
34
+ });
35
+ },
36
+ };
@@ -3,6 +3,11 @@ import type { FileHashPort } from "./file-hash.port";
3
3
 
4
4
  export class FileHashNoopAdapter implements FileHashPort {
5
5
  async hash(_path: tools.FilePathAbsolute | tools.FilePathRelative) {
6
- return { etag: "noop", size: tools.Size.fromBytes(0), lastModified: tools.Timestamp.parse(1000) };
6
+ return {
7
+ etag: "noop",
8
+ size: tools.Size.fromBytes(10),
9
+ lastModified: tools.Timestamp.parse(1000),
10
+ mime: new tools.Mime("text/plain"),
11
+ };
7
12
  }
8
13
  }
@@ -4,6 +4,7 @@ import type { FileHashPort } from "./file-hash.port";
4
4
  export class FileHashSha256BunAdapter implements FileHashPort {
5
5
  async hash(path: tools.FilePathAbsolute | tools.FilePathRelative) {
6
6
  const file = Bun.file(path.get());
7
+ const extension = path.getFilename().getExtension();
7
8
 
8
9
  const arrayBuffer = await file.arrayBuffer();
9
10
  const digest = await crypto.subtle.digest("SHA-256", arrayBuffer);
@@ -13,6 +14,7 @@ export class FileHashSha256BunAdapter implements FileHashPort {
13
14
  etag,
14
15
  size: tools.Size.fromBytes(arrayBuffer.byteLength),
15
16
  lastModified: tools.Timestamp.parse(file.lastModified),
17
+ mime: tools.Mime.fromExtension(extension),
16
18
  };
17
19
  }
18
20
  }
@@ -1,6 +1,11 @@
1
1
  import type * as tools from "@bgord/tools";
2
2
 
3
- export type FileHashResult = { etag: string; size: tools.Size; lastModified: tools.TimestampType };
3
+ export type FileHashResult = {
4
+ etag: string;
5
+ size: tools.Size;
6
+ lastModified: tools.TimestampType;
7
+ mime: tools.Mime;
8
+ };
4
9
 
5
10
  export interface FileHashPort {
6
11
  hash(path: tools.FilePathAbsolute | tools.FilePathRelative): Promise<FileHashResult>;
package/src/index.ts CHANGED
@@ -3,9 +3,9 @@ export * from "./api-version.middleware";
3
3
  export * from "./basic-auth.service";
4
4
  export * from "./better-auth-logger.service";
5
5
  export * from "./build-info-repository.service";
6
+ export * from "./cache-file.service";
6
7
  export * from "./cache-resolver.service";
7
8
  export * from "./cache-response.middleware";
8
- export * from "./cache-static-files.middleware";
9
9
  export * from "./client.vo";
10
10
  export * from "./client-from-hono.adapter";
11
11
  export * from "./command.types";
@@ -29,6 +29,7 @@ export class RemoteFileStorageNoopAdapter implements RemoteFileStoragePort {
29
29
  etag: "noop",
30
30
  size: tools.Size.fromBytes(10),
31
31
  lastModified: tools.Timestamp.parse(Date.now()),
32
+ mime: new tools.Mime("text/plain"),
32
33
  };
33
34
  }
34
35
 
@@ -1,9 +0,0 @@
1
- export declare enum CacheStaticFilesStrategy {
2
- never = "never",
3
- always = "always",
4
- five_minutes = "five_minutes"
5
- }
6
- export declare class CacheStaticFiles {
7
- static handle(strategy: CacheStaticFilesStrategy): import("hono").MiddlewareHandler<any, string, {}>;
8
- }
9
- //# sourceMappingURL=cache-static-files.middleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache-static-files.middleware.d.ts","sourceRoot":"","sources":["../src/cache-static-files.middleware.ts"],"names":[],"mappings":"AAGA,oBAAY,wBAAwB;IAClC,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,YAAY,iBAAiB;CAC9B;AAED,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,wBAAwB;CAcjD"}
@@ -1,25 +0,0 @@
1
- import * as tools from "@bgord/tools";
2
- import { createMiddleware } from "hono/factory";
3
- export var CacheStaticFilesStrategy;
4
- (function (CacheStaticFilesStrategy) {
5
- CacheStaticFilesStrategy["never"] = "never";
6
- CacheStaticFilesStrategy["always"] = "always";
7
- CacheStaticFilesStrategy["five_minutes"] = "five_minutes";
8
- })(CacheStaticFilesStrategy || (CacheStaticFilesStrategy = {}));
9
- export class CacheStaticFiles {
10
- static handle(strategy) {
11
- return createMiddleware(async (c, next) => {
12
- if (strategy === CacheStaticFilesStrategy.never) {
13
- c.res.headers.set("cache-control", "private, no-cache, no-store, must-revalidate");
14
- }
15
- if (strategy === CacheStaticFilesStrategy.always) {
16
- c.res.headers.set("cache-control", `public, max-age=${tools.Time.Days(365).seconds}, immutable`);
17
- }
18
- if (strategy === CacheStaticFilesStrategy.five_minutes) {
19
- c.res.headers.set("cache-control", `public, max-age=${tools.Time.Minutes(5).seconds}`);
20
- }
21
- return next();
22
- });
23
- }
24
- }
25
- //# sourceMappingURL=cache-static-files.middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache-static-files.middleware.js","sourceRoot":"","sources":["../src/cache-static-files.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,CAAN,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAClC,2CAAe,CAAA;IACf,6CAAiB,CAAA;IACjB,yDAA6B,CAAA;AAC/B,CAAC,EAJW,wBAAwB,KAAxB,wBAAwB,QAInC;AAED,MAAM,OAAO,gBAAgB;IAC3B,MAAM,CAAC,MAAM,CAAC,QAAkC;QAC9C,OAAO,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;YACxC,IAAI,QAAQ,KAAK,wBAAwB,CAAC,KAAK,EAAE,CAAC;gBAChD,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,8CAA8C,CAAC,CAAC;YACrF,CAAC;YACD,IAAI,QAAQ,KAAK,wBAAwB,CAAC,MAAM,EAAE,CAAC;gBACjD,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,mBAAmB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,aAAa,CAAC,CAAC;YACnG,CAAC;YACD,IAAI,QAAQ,KAAK,wBAAwB,CAAC,YAAY,EAAE,CAAC;gBACvD,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,mBAAmB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACzF,CAAC;YACD,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,25 +0,0 @@
1
- import * as tools from "@bgord/tools";
2
- import { createMiddleware } from "hono/factory";
3
-
4
- export enum CacheStaticFilesStrategy {
5
- never = "never",
6
- always = "always",
7
- five_minutes = "five_minutes",
8
- }
9
-
10
- export class CacheStaticFiles {
11
- static handle(strategy: CacheStaticFilesStrategy) {
12
- return createMiddleware(async (c, next) => {
13
- if (strategy === CacheStaticFilesStrategy.never) {
14
- c.res.headers.set("cache-control", "private, no-cache, no-store, must-revalidate");
15
- }
16
- if (strategy === CacheStaticFilesStrategy.always) {
17
- c.res.headers.set("cache-control", `public, max-age=${tools.Time.Days(365).seconds}, immutable`);
18
- }
19
- if (strategy === CacheStaticFilesStrategy.five_minutes) {
20
- c.res.headers.set("cache-control", `public, max-age=${tools.Time.Minutes(5).seconds}`);
21
- }
22
- return next();
23
- });
24
- }
25
- }