@flaghoist/adapter-cloudflare-kv 0.1.1 → 0.2.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.
package/README.md CHANGED
@@ -24,6 +24,23 @@ deploy` creates the namespace and fills in its id for you. By hand it is:
24
24
  npx wrangler kv namespace create FLAGS
25
25
  ```
26
26
 
27
+ ## Sharing a namespace
28
+
29
+ By default Flaghoist writes each flag under its own key, so a flag called `checkout` is stored as
30
+ `checkout`. That keeps the namespace readable when you browse it in the Cloudflare dashboard.
31
+
32
+ If the namespace holds anything besides Flaghoist's flags, give it a prefix:
33
+
34
+ ```ts
35
+ cloudflareKV(env.FLAGS, { prefix: 'flag:' })
36
+ ```
37
+
38
+ Without one, `list()` reads every key in the namespace. Values that are not flags are skipped rather
39
+ than showing up as broken rows, so nothing breaks, but you pay a read for each one.
40
+
41
+ Changing the prefix on a running deployment hides the flags written under the old one. They are
42
+ still in KV, the adapter is just no longer looking there.
43
+
27
44
  Worth knowing: KV is eventually consistent. A flag you just changed can take a few seconds to reach
28
45
  every edge location, which is fine for flags and would not be fine for a bank balance.
29
46
 
package/dist/index.cjs CHANGED
@@ -33,7 +33,7 @@ function safeParse(raw) {
33
33
  }
34
34
  }
35
35
  function cloudflareKV(kv, options = {}) {
36
- const prefix = options.prefix ?? "flag:";
36
+ const prefix = options.prefix ?? "";
37
37
  return {
38
38
  async get(key) {
39
39
  return safeParse(await kv.get(prefix + key, { type: "text" }));
package/dist/index.d.cts CHANGED
@@ -24,11 +24,21 @@ interface KVNamespaceLike {
24
24
  }>;
25
25
  }
26
26
  interface CloudflareKVOptions {
27
- /** Key prefix used to namespace flags within the KV store. Default: `"flag:"`. */
27
+ /**
28
+ * Namespace every key Flaghoist writes, and ignore anything without it when listing.
29
+ *
30
+ * Empty by default, so a flag called `checkout` is stored under `checkout` and the namespace
31
+ * reads the way you expect when browsing it in the Cloudflare dashboard. Set this when the
32
+ * namespace holds anything besides Flaghoist's flags: without it `list()` reads every key in the
33
+ * namespace. Values that are not flags are skipped rather than surfacing as broken rows, but you
34
+ * still pay a read for each one.
35
+ *
36
+ * @example cloudflareKV(env.FLAGS, { prefix: 'flag:' })
37
+ */
28
38
  prefix?: string;
29
39
  }
30
40
  /**
31
- * A StorageAdapter backed by Cloudflare Workers KV — the default Flaghoist storage backend.
41
+ * A StorageAdapter backed by Cloudflare Workers KV, the default Flaghoist storage backend.
32
42
  * Flags are stored as JSON under a configurable key prefix, and every read is re-validated
33
43
  * through `parseFlag`, so tampered or corrupted data degrades to "flag ignored" rather than a
34
44
  * crash or a malformed evaluation.
package/dist/index.d.ts CHANGED
@@ -24,11 +24,21 @@ interface KVNamespaceLike {
24
24
  }>;
25
25
  }
26
26
  interface CloudflareKVOptions {
27
- /** Key prefix used to namespace flags within the KV store. Default: `"flag:"`. */
27
+ /**
28
+ * Namespace every key Flaghoist writes, and ignore anything without it when listing.
29
+ *
30
+ * Empty by default, so a flag called `checkout` is stored under `checkout` and the namespace
31
+ * reads the way you expect when browsing it in the Cloudflare dashboard. Set this when the
32
+ * namespace holds anything besides Flaghoist's flags: without it `list()` reads every key in the
33
+ * namespace. Values that are not flags are skipped rather than surfacing as broken rows, but you
34
+ * still pay a read for each one.
35
+ *
36
+ * @example cloudflareKV(env.FLAGS, { prefix: 'flag:' })
37
+ */
28
38
  prefix?: string;
29
39
  }
30
40
  /**
31
- * A StorageAdapter backed by Cloudflare Workers KV — the default Flaghoist storage backend.
41
+ * A StorageAdapter backed by Cloudflare Workers KV, the default Flaghoist storage backend.
32
42
  * Flags are stored as JSON under a configurable key prefix, and every read is re-validated
33
43
  * through `parseFlag`, so tampered or corrupted data degrades to "flag ignored" rather than a
34
44
  * crash or a malformed evaluation.
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ function safeParse(raw) {
9
9
  }
10
10
  }
11
11
  function cloudflareKV(kv, options = {}) {
12
- const prefix = options.prefix ?? "flag:";
12
+ const prefix = options.prefix ?? "";
13
13
  return {
14
14
  async get(key) {
15
15
  return safeParse(await kv.get(prefix + key, { type: "text" }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flaghoist/adapter-cloudflare-kv",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Cloudflare Workers KV StorageAdapter for Flaghoist — the default storage backend.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  "node": ">=20"
28
28
  },
29
29
  "dependencies": {
30
- "@flaghoist/core": "0.1.1"
30
+ "@flaghoist/core": "0.1.2"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@flaghoist/adapter-conformance": "0.0.0"