@cloudhal/storage 0.3.0 → 0.3.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.
@@ -4,7 +4,12 @@ export interface BlobFetcher {
4
4
  fetch(input: string): Promise<Response>;
5
5
  }
6
6
  export interface FetcherBlobStoreOptions {
7
- /** Keys `list` reports (static assets cannot be listed). Default: none. */
7
+ /**
8
+ * The keys this store holds. With it, `get`, `head` and `list` know only these keys and never
9
+ * fetch another: a static-assets binding with SPA fallback answers 200 with `index.html` for any
10
+ * missing file, which would otherwise read as a blob. Without it, every key is fetched and
11
+ * `list` reports none (static assets cannot be listed).
12
+ */
8
13
  readonly keys?: readonly string[];
9
14
  }
10
15
  /**
@@ -12,7 +12,12 @@ import {
12
12
 
13
13
 
14
14
 
15
-
15
+
16
+
17
+
18
+
19
+
20
+
16
21
 
17
22
 
18
23
 
@@ -26,15 +31,18 @@ export class FetcherBlobStore {
26
31
  #fetcher ;
27
32
  #prefix ;
28
33
  #keys ;
34
+ #known ;
29
35
 
30
36
  constructor(fetcher , prefix , options = {}) {
31
37
  this.#fetcher = fetcher;
32
38
  this.#prefix = prefix.replace(/^\/+/, "");
33
39
  this.#keys = [...(options.keys ?? [])].sort();
40
+ this.#known = options.keys ? new Set(options.keys) : undefined;
34
41
  }
35
42
 
36
43
  async #fetch(key ) {
37
44
  assertBlobKey(key);
45
+ if (this.#known && !this.#known.has(key)) return null;
38
46
  const res = await this.#fetcher.fetch(`https://assets.local/${this.#prefix}${key}`);
39
47
  if (res.status === 404) return null;
40
48
  if (!res.ok) throw new StorageError(`fetching ${key} failed with ${res.status}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudhal/storage",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Cloudhal storage interfaces (SQL driver, blob store) with Cloudflare D1/R2/Durable Object SQLite and local SQLite/filesystem adapters",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://cloudhal.dev",
@@ -49,7 +49,7 @@
49
49
  "README.md"
50
50
  ],
51
51
  "dependencies": {
52
- "@cloudhal/core-contracts": "0.3.0"
52
+ "@cloudhal/core-contracts": "0.3.1"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "better-sqlite3": "^13.0.0"