@bgord/bun 1.2.8 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/bun",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": "Bartosz Gordon",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@axiomhq/winston": "1.3.1",
40
- "@bgord/tools": "1.1.13",
40
+ "@bgord/tools": "1.1.16",
41
41
  "@hono/ua-blocker": "0.1.20",
42
42
  "better-auth": "1.4.5",
43
43
  "croner": "9.1.0",
@@ -5,7 +5,8 @@ export const EncryptionKeyError = {
5
5
  InvalidHex: "encryption.key.invalid.hex",
6
6
  } as const;
7
7
 
8
- const CHARS_WHITELIST = /^[0-9a-fA-F]{64}$/;
8
+ // 64 hex chars allowed
9
+ const CHARS_WHITELIST = /^[a-fA-F0-9]{64}$/;
9
10
 
10
11
  export const EncryptionKey = z
11
12
  .string(EncryptionKeyError.Type)
@@ -1,5 +1,7 @@
1
+ import type * as tools from "@bgord/tools";
2
+
1
3
  export type EventStoreLike<E extends { name: string }> = {
2
4
  save(events: E[]): Promise<unknown>;
3
5
 
4
- saveAfter(events: E[], delay: { ms: number }): Promise<unknown>;
6
+ saveAfter(events: E[], offset: tools.Duration): Promise<unknown>;
5
7
  };
@@ -4,11 +4,12 @@ import { ZipFile } from "yazl";
4
4
  import { FileDraft } from "./file-draft.service";
5
5
 
6
6
  export class FileDraftZip extends FileDraft {
7
- private readonly parts: FileDraft[];
8
-
9
- constructor(config: { filename: tools.Filename; parts: FileDraft[] }) {
10
- super({ filename: config.filename, mime: tools.MIMES.text });
11
- this.parts = config.parts;
7
+ constructor(
8
+ basename: tools.BasenameType,
9
+ private readonly parts: FileDraft[],
10
+ ) {
11
+ super(basename, tools.MIMES.zip);
12
+ this.parts = parts;
12
13
  }
13
14
 
14
15
  // @ts-expect-error
@@ -17,7 +18,7 @@ export class FileDraftZip extends FileDraft {
17
18
  const chunks: Buffer[] = [];
18
19
 
19
20
  for (const part of this.parts) {
20
- zip.addReadStream((await part.create()) as Readable, part.config.filename.get());
21
+ zip.addReadStream((await part.create()) as Readable, part.filename.get());
21
22
  }
22
23
  zip.end();
23
24
 
@@ -1,15 +1,19 @@
1
1
  import type { ReadableStream } from "node:stream/web";
2
- import type * as tools from "@bgord/tools";
2
+ import * as tools from "@bgord/tools";
3
3
 
4
4
  export type DraftBody = BodyInit | NodeJS.ReadableStream | ReadableStream;
5
5
 
6
6
  export abstract class FileDraft {
7
- constructor(readonly config: { filename: tools.Filename; mime: tools.Mime }) {}
7
+ readonly filename: tools.Filename;
8
+
9
+ constructor(basename: tools.BasenameType, mime: tools.Mime) {
10
+ this.filename = tools.Filename.fromPartsSafe(basename, mime.toExtension());
11
+ }
8
12
 
9
13
  getHeaders(): Headers {
10
14
  return new Headers({
11
- "Content-Type": this.config.mime.toString(),
12
- "Content-Disposition": `attachment; filename="${this.config.filename.get()}"`,
15
+ "Content-Type": this.filename.getMime().toString(),
16
+ "Content-Disposition": `attachment; filename="${this.filename.get()}"`,
13
17
  });
14
18
  }
15
19
 
@@ -24,6 +28,6 @@ export abstract class FileDraft {
24
28
  async toAttachment() {
25
29
  const body = await this.create();
26
30
 
27
- return { filename: this.config.filename, content: body, contentType: this.config.mime.toString() };
31
+ return { filename: this.filename, content: body, contentType: this.filename.getMime().toString() };
28
32
  }
29
33
  }