@decocms/blocks-cli 7.86.0 → 7.86.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/blocks-cli",
3
- "version": "7.86.0",
3
+ "version": "7.86.1",
4
4
  "type": "module",
5
5
  "description": "Deco codegen (generate-blocks, generate-schema, generate-invoke) and Fresh-to-TanStack migration tooling",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "lint:unused": "knip"
34
34
  },
35
35
  "dependencies": {
36
- "@decocms/blocks": "7.86.0",
36
+ "@decocms/blocks": "7.86.1",
37
37
  "ts-morph": "^27.0.0",
38
38
  "tsx": "^4.22.5"
39
39
  },
@@ -8,6 +8,7 @@ import {
8
8
  LIVE_KEY,
9
9
  revisionKey,
10
10
  snapshotKey,
11
+ redirectPathHash,
11
12
  } from "@decocms/blocks/cms";
12
13
  import { splitExactRedirects } from "@decocms/blocks/sdk/redirects";
13
14
  import { createKvRestClient, type KvRestClient, kvConfigFromEnv } from "./lib/cf-kv-rest";
@@ -477,6 +478,16 @@ describe("syncRedirectsToKv", () => {
477
478
  expect(store.get(`redirect:${ID}:/old`)).toBe('{"to":"/new","status":301}');
478
479
  });
479
480
 
481
+ it("writes index:redirects:<id>, the sorted hashes of the paths, even when there are none", async () => {
482
+ const { client, store } = makeBulkClient();
483
+ await syncRedirectsToKv(client, [rule("/b", "/x"), rule("/a", "/y")], ID);
484
+ const hashes = [redirectPathHash("/a"), redirectPathHash("/b")].sort((a, b) => a - b);
485
+ expect(JSON.parse(store.get(`index:redirects:${ID}`)!)).toEqual(hashes);
486
+
487
+ await syncRedirectsToKv(client, [], ID);
488
+ expect(store.get(`index:redirects:${ID}`)).toBe("[]");
489
+ });
490
+
480
491
  it("updates a changed target in place", async () => {
481
492
  const { client, store } = makeBulkClient({
482
493
  [`redirect:${ID}:/old`]: '{"to":"/stale","status":302}',
@@ -12,7 +12,9 @@ import {
12
12
  computeRevision,
13
13
  DEPLOYMENTS_KEY,
14
14
  LIVE_KEY,
15
+ redirectIndexKey,
15
16
  redirectKey,
17
+ redirectPathHash,
16
18
  redirectPrefix,
17
19
  revisionKey,
18
20
  snapshotKey,
@@ -106,6 +108,10 @@ export async function syncRedirectsToKv(
106
108
  if (stale.length > 0) {
107
109
  await client.deleteMany(stale);
108
110
  }
111
+ // After the rules, so the index never names a path whose key isn't there yet.
112
+ // Written even when empty: that is what tells the worker to read nothing.
113
+ const hashes = [...new Set(redirects.map((r) => redirectPathHash(r.path)))].sort((a, b) => a - b);
114
+ await client.put(redirectIndexKey(id), JSON.stringify(hashes));
109
115
 
110
116
  return { written: desired.size, deleted: stale.length };
111
117
  }
@@ -160,6 +166,7 @@ export async function recordAndGcDeployment(
160
166
  }
161
167
  await client.delete(snapshotKey(entry.id));
162
168
  await client.delete(revisionKey(entry.id));
169
+ await client.delete(redirectIndexKey(entry.id));
163
170
  // The per-path redirect keys are keyed by deployment too, so they are
164
171
  // part of this snapshot and must go with it — otherwise every deploy
165
172
  // leaks tens of thousands of orphans into the namespace forever.