rastack 0.0.57 → 0.0.59

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 (86) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +190 -0
  3. package/admin/index.tsx +19 -13
  4. package/admin/ui/BootScreen.tsx +201 -0
  5. package/dist/admin.js +156 -18
  6. package/dist/deploy/ci.js +2 -2
  7. package/dist/deploy/io.js +2 -2
  8. package/dist/dev/harness.d.ts +1 -1
  9. package/dist/dev/harness.js +21 -5
  10. package/dist/external/cache.d.ts +28 -0
  11. package/dist/external/cache.js +35 -0
  12. package/dist/external/envelope.d.ts +35 -0
  13. package/dist/external/envelope.js +48 -0
  14. package/dist/external/graphql.d.ts +25 -0
  15. package/dist/external/graphql.js +78 -0
  16. package/dist/external/handler.d.ts +52 -0
  17. package/dist/external/handler.js +139 -0
  18. package/dist/external/index.d.ts +19 -0
  19. package/dist/external/index.js +38 -0
  20. package/dist/external/lambda.d.ts +49 -0
  21. package/dist/external/lambda.js +86 -0
  22. package/dist/external/rest.d.ts +17 -0
  23. package/dist/external/rest.js +46 -0
  24. package/dist/external/route.d.ts +12 -0
  25. package/dist/external/route.js +33 -0
  26. package/dist/external/service.d.ts +50 -0
  27. package/dist/external/service.js +59 -0
  28. package/dist/external/types.d.ts +107 -0
  29. package/dist/external/types.js +22 -0
  30. package/dist/external/util.d.ts +16 -0
  31. package/dist/external/util.js +58 -0
  32. package/dist/rastack-dev.js +200 -4
  33. package/dist/rastack-wasm-build.d.ts +1 -1
  34. package/dist/rastack-wasm-build.js +6 -6
  35. package/dist/wasm/rastack_wasm_bg.wasm +0 -0
  36. package/external.ts +10 -0
  37. package/hooks/query/delete.ts +12 -11
  38. package/hooks/query/fetch.ts +6 -8
  39. package/hooks/query/interfaces.ts +1 -4
  40. package/hooks/query/list.ts +16 -9
  41. package/hooks/query/update.ts +8 -6
  42. package/package.json +25 -2
  43. package/scripts/copy-templates.js +1 -1
  44. package/scripts/copy-wasm.js +1 -1
  45. package/scripts/dev-install.mjs +63 -0
  46. package/src/deploy/ci.ts +2 -2
  47. package/src/deploy/io.ts +2 -2
  48. package/src/dev/harness.ts +21 -5
  49. package/src/external/cache.ts +53 -0
  50. package/src/external/envelope.ts +78 -0
  51. package/src/external/graphql.ts +98 -0
  52. package/src/external/handler.ts +207 -0
  53. package/src/external/index.ts +25 -0
  54. package/src/external/lambda.ts +108 -0
  55. package/src/external/rest.ts +60 -0
  56. package/src/external/route.ts +33 -0
  57. package/src/external/service.ts +86 -0
  58. package/src/external/types.ts +121 -0
  59. package/src/external/util.ts +57 -0
  60. package/src/rastack-dev.ts +233 -6
  61. package/src/rastack-wasm-build.ts +6 -6
  62. package/jest.config.cjs +0 -12
  63. package/test/auth.spec.ts +0 -207
  64. package/test/cache.spec.ts +0 -263
  65. package/test/cognito.spec.ts +0 -281
  66. package/test/compile.spec.ts +0 -240
  67. package/test/components.spec.ts +0 -524
  68. package/test/csv-schema.spec.ts +0 -143
  69. package/test/deploy.spec.ts +0 -571
  70. package/test/dev.spec.ts +0 -414
  71. package/test/entities.spec.ts +0 -597
  72. package/test/import.spec.ts +0 -241
  73. package/test/plugin.spec.ts +0 -315
  74. package/test/runtime-manifest.spec.ts +0 -309
  75. package/test/schema-entities.spec.ts +0 -688
  76. package/test/tokens.spec.ts +0 -302
  77. package/test/transitions.spec.ts +0 -372
  78. package/test/typed-hooks.spec.ts +0 -412
  79. package/test/update.spec.ts +0 -152
  80. package/test/validate.spec.ts +0 -319
  81. package/tsconfig.json +0 -27
  82. package/wasm/package.json +0 -4
  83. package/wasm/rastack_wasm.d.ts +0 -100
  84. package/wasm/rastack_wasm.js +0 -745
  85. package/wasm/rastack_wasm_bg.wasm +0 -0
  86. package/wasm/rastack_wasm_bg.wasm.d.ts +0 -28
package/test/auth.spec.ts DELETED
@@ -1,207 +0,0 @@
1
- /**
2
- * Tests for the `rastack/auth` core — the client-side mirror of the access
3
- * rules `rastack-api-core` enforces (see `rust/rastack-api-core/tests/access.rs`
4
- * for the server side of the same matrix). The semantics here must track the
5
- * Rust `check_permission` / `enforced_owner` exactly: `can()` answers "would
6
- * the server accept this request?", so the components can limit the paths they
7
- * expose instead of surfacing 401s.
8
- */
9
-
10
- import {
11
- anonymousAuth,
12
- authFromClaims,
13
- bypassesRls,
14
- can,
15
- canActOnRow,
16
- isAdmin,
17
- ownsRow,
18
- policyFromManifest,
19
- policyFromOpenApi,
20
- trustedAuth,
21
- userAuth,
22
- type ResourcePolicy,
23
- } from "../auth/core";
24
-
25
- const rls: ResourcePolicy = {
26
- permission: "authenticated",
27
- access: { ownerField: "owner", scope: "owner", adminGroups: ["staff"] },
28
- };
29
-
30
- describe("rastack/auth — the permission gate (can)", () => {
31
- it("defaults to authenticated — secure by default, like the server", () => {
32
- expect(can(anonymousAuth(), {}, "list")).toBe(false);
33
- expect(can(anonymousAuth(), undefined, "create")).toBe(false);
34
- expect(can(userAuth("u1"), {}, "list")).toBe(true);
35
- expect(can(userAuth("u1"), undefined, "delete")).toBe(true);
36
- });
37
-
38
- it("public admits everyone, for every action", () => {
39
- const policy: ResourcePolicy = { permission: "public" };
40
- for (const action of [
41
- "list",
42
- "retrieve",
43
- "create",
44
- "update",
45
- "delete",
46
- ] as const) {
47
- expect(can(anonymousAuth(), policy, action)).toBe(true);
48
- }
49
- });
50
-
51
- it("authenticatedOrReadOnly admits anonymous reads but not writes", () => {
52
- const policy: ResourcePolicy = { permission: "authenticatedOrReadOnly" };
53
- expect(can(anonymousAuth(), policy, "list")).toBe(true);
54
- expect(can(anonymousAuth(), policy, "retrieve")).toBe(true);
55
- expect(can(anonymousAuth(), policy, "create")).toBe(false);
56
- expect(can(anonymousAuth(), policy, "update")).toBe(false);
57
- expect(can(anonymousAuth(), policy, "delete")).toBe(false);
58
- expect(can(userAuth("u1"), policy, "delete")).toBe(true);
59
- });
60
-
61
- it("row-secured resources need a subject (the server answers 401 without one)", () => {
62
- // Authenticated but subject-less — e.g. a machine token without `sub`.
63
- const noSub = { authenticated: true, groups: [] };
64
- expect(can(noSub, rls, "list")).toBe(false);
65
- expect(can(userAuth("u1"), rls, "list")).toBe(true);
66
- // A configured admin group bypasses row-level security.
67
- expect(can({ ...noSub, groups: ["staff"] }, rls, "list")).toBe(true);
68
- });
69
-
70
- it("trusted contexts (dev without auth) pass everything", () => {
71
- expect(can(trustedAuth(), rls, "delete")).toBe(true);
72
- });
73
-
74
- it("a missing identity gates nothing — the server stays the enforcer", () => {
75
- expect(can(undefined, rls, "delete")).toBe(true);
76
- expect(can(null, { permission: "authenticated" }, "create")).toBe(true);
77
- });
78
- });
79
-
80
- describe("rastack/auth — row-level security helpers", () => {
81
- const mine = { id: 1, owner: "u1" };
82
- const theirs = { id: 2, owner: "u2" };
83
-
84
- it("owners own their rows; others don't", () => {
85
- expect(ownsRow(userAuth("u1"), rls, mine)).toBe(true);
86
- expect(ownsRow(userAuth("u1"), rls, theirs)).toBe(false);
87
- });
88
-
89
- it("admin groups and trusted contexts bypass the owner filter", () => {
90
- expect(bypassesRls(userAuth("u1", ["staff"]), rls)).toBe(true);
91
- expect(ownsRow(userAuth("u1", ["staff"]), rls, theirs)).toBe(true);
92
- expect(ownsRow(trustedAuth(), rls, theirs)).toBe(true);
93
- expect(bypassesRls(userAuth("u1", ["other"]), rls)).toBe(false);
94
- });
95
-
96
- it("unsecured resources are owned by everyone", () => {
97
- expect(ownsRow(userAuth("u1"), {}, theirs)).toBe(true);
98
- });
99
-
100
- it("canActOnRow combines the gate and ownership", () => {
101
- expect(canActOnRow(userAuth("u1"), rls, "update", mine)).toBe(true);
102
- expect(canActOnRow(userAuth("u1"), rls, "update", theirs)).toBe(false);
103
- expect(canActOnRow(anonymousAuth(), rls, "update", mine)).toBe(false);
104
- });
105
- });
106
-
107
- describe("rastack/auth — group-owned datasets", () => {
108
- // A group dataset: rows belong to a team, physically partitioned per group.
109
- const grouped: ResourcePolicy = {
110
- permission: "authenticated",
111
- access: { groupField: "team", scope: "group", adminGroups: ["staff"] },
112
- };
113
- const blueRow = { id: 1, team: "blue" };
114
-
115
- it("members read; identities in no group can read (empty) but never write", () => {
116
- const dana = userAuth("dana", ["blue"]);
117
- const loner = userAuth("lonnie", []);
118
- expect(can(dana, grouped, "list")).toBe(true);
119
- expect(can(dana, grouped, "create")).toBe(true);
120
- // Reads outside any group just come back empty — but a write can never
121
- // succeed, so the UI shouldn't offer it.
122
- expect(can(loner, grouped, "list")).toBe(true);
123
- expect(can(loner, grouped, "create")).toBe(false);
124
- expect(can(loner, grouped, "delete")).toBe(false);
125
- });
126
-
127
- it("row membership mirrors the server's group guard", () => {
128
- expect(ownsRow(userAuth("dana", ["blue"]), grouped, blueRow)).toBe(true);
129
- expect(ownsRow(userAuth("erin", ["green"]), grouped, blueRow)).toBe(false);
130
- expect(
131
- canActOnRow(userAuth("erin", ["green"]), grouped, "update", blueRow),
132
- ).toBe(false);
133
- // adminGroups members act across groups.
134
- expect(ownsRow(userAuth("sam", ["staff"]), grouped, blueRow)).toBe(true);
135
- });
136
-
137
- it("owner + group guards both apply when a policy carries both", () => {
138
- const both: ResourcePolicy = {
139
- access: { ownerField: "owner", groupField: "team" },
140
- };
141
- const row = { id: 1, owner: "dana", team: "blue" };
142
- expect(ownsRow(userAuth("dana", ["blue"]), both, row)).toBe(true);
143
- expect(ownsRow(userAuth("dana", ["green"]), both, row)).toBe(false);
144
- expect(ownsRow(userAuth("erin", ["blue"]), both, row)).toBe(false);
145
- });
146
-
147
- it("isAdmin is the scope-driven admin role", () => {
148
- expect(isAdmin(userAuth("sam", ["staff"]), grouped)).toBe(true);
149
- expect(isAdmin(userAuth("dana", ["blue"]), grouped)).toBe(false);
150
- expect(isAdmin(trustedAuth(), grouped)).toBe(true);
151
- });
152
- });
153
-
154
- describe("rastack/auth — building an identity", () => {
155
- it("authFromClaims reads sub and cognito:groups from a decoded token", () => {
156
- const auth = authFromClaims({
157
- sub: "u1",
158
- "cognito:groups": ["staff", 42],
159
- email: "x@y.z",
160
- });
161
- expect(auth).toEqual({ authenticated: true, sub: "u1", groups: ["staff"] });
162
- expect(authFromClaims({}).authenticated).toBe(false);
163
- });
164
- });
165
-
166
- describe("rastack/auth — policy lookup", () => {
167
- const manifest = {
168
- resources: [
169
- { app: "airports", model: "airport", fields: [] },
170
- {
171
- app: "airports",
172
- model: "itinerary",
173
- fields: [],
174
- permission: "authenticated",
175
- access: { ownerField: "owner", scope: "owner", adminGroups: ["staff"] },
176
- },
177
- ],
178
- };
179
-
180
- it("policyFromManifest extracts permission + access", () => {
181
- expect(policyFromManifest(manifest, "airports.itinerary")).toEqual(rls);
182
- expect(
183
- policyFromManifest(manifest, { app: "airports", model: "airport" }),
184
- ).toEqual({});
185
- expect(policyFromManifest(manifest, "airports.missing")).toBeUndefined();
186
- // Accepts the JSON string form the provider may hold.
187
- expect(
188
- policyFromManifest(JSON.stringify(manifest), "airports.itinerary"),
189
- ).toEqual(rls);
190
- });
191
-
192
- it("policyFromOpenApi reads the x-rastack-permission / x-rastack-access stamps", () => {
193
- const doc = {
194
- paths: {
195
- "/api/airports/v1/itinerary/": {
196
- get: {
197
- operationId: "listItinerary",
198
- "x-rastack-permission": "authenticated",
199
- "x-rastack-access": rls.access,
200
- },
201
- },
202
- },
203
- };
204
- expect(policyFromOpenApi(doc, "airports.itinerary")).toEqual(rls);
205
- expect(policyFromOpenApi(doc, "airports.airport")).toBeUndefined();
206
- });
207
- });
@@ -1,263 +0,0 @@
1
- import {
2
- AccessRevokedError,
3
- CacheExpiredError,
4
- createEncryptedCacheStorage,
5
- generateEncryptionKey,
6
- IcebergFileCache,
7
- MemoryCacheStorage,
8
- purgeLocalData,
9
- WarehouseFileSource,
10
- } from "../cache";
11
-
12
- /**
13
- * The cache is exercised against an in-memory "object store" that counts
14
- * fetches — the observable contract is Iceberg's: the version hint is the only
15
- * file re-fetched once cached copies exist, immutable snapshot/data files are
16
- * fetched exactly once, and revoked access deletes the identity's cache.
17
- */
18
-
19
- const encoder = new TextEncoder();
20
-
21
- class FakeWarehouse implements WarehouseFileSource {
22
- files = new Map<string, Uint8Array>();
23
- fetches: string[] = [];
24
- revoked = false;
25
- offline = false;
26
-
27
- async fetchFile(key: string): Promise<Uint8Array | null> {
28
- if (this.revoked) throw new AccessRevokedError("revoked", 403);
29
- if (this.offline) throw new Error("network unreachable");
30
- this.fetches.push(key);
31
- return this.files.get(key) ?? null;
32
- }
33
-
34
- /** Commit snapshot `version` for the table with the given data files. */
35
- commit(prefix: string, version: number, dataFiles: Record<string, object[]>) {
36
- this.files.set(
37
- `${prefix}/metadata/version-hint.text`,
38
- encoder.encode(String(version)),
39
- );
40
- this.files.set(
41
- `${prefix}/metadata/v${version}.metadata.json`,
42
- encoder.encode(
43
- JSON.stringify({
44
- format: "rastack-iceberg-v1",
45
- data_files: Object.keys(dataFiles),
46
- next_int_id: 99,
47
- }),
48
- ),
49
- );
50
- for (const [rel, rows] of Object.entries(dataFiles)) {
51
- this.files.set(`${prefix}/${rel}`, encoder.encode(JSON.stringify(rows)));
52
- }
53
- }
54
- }
55
-
56
- class FakeEngine {
57
- seeded: string[] = [];
58
- async seedFile(key: string): Promise<void> {
59
- this.seeded.push(key);
60
- }
61
- }
62
-
63
- const RESOURCES = [{ app: "airports", model: "airport" }];
64
- const PREFIX = "airports.db/airport";
65
-
66
- function makeCache(source: FakeWarehouse, identity = "alice-sub") {
67
- const storage = new MemoryCacheStorage();
68
- return {
69
- storage,
70
- cache: new IcebergFileCache({ storage, source, identity }),
71
- };
72
- }
73
-
74
- describe("IcebergFileCache", () => {
75
- it("cold seed fetches the Iceberg tree and feeds it to the engine", async () => {
76
- const source = new FakeWarehouse();
77
- source.commit(PREFIX, 1, { "data/v1.json": [{ id: 1, code: "JFK" }] });
78
- const { cache } = makeCache(source);
79
- const engine = new FakeEngine();
80
-
81
- const stats = await cache.seed(engine, RESOURCES);
82
-
83
- expect(stats).toEqual({ tables: 1, fromCache: 0, fetched: 3 });
84
- expect(engine.seeded).toEqual([
85
- `${PREFIX}/metadata/version-hint.text`,
86
- `${PREFIX}/metadata/v1.metadata.json`,
87
- `${PREFIX}/data/v1.json`,
88
- ]);
89
- });
90
-
91
- it("warm seed with no new commit refetches only the version hint", async () => {
92
- const source = new FakeWarehouse();
93
- source.commit(PREFIX, 1, { "data/v1.json": [{ id: 1 }] });
94
- const { cache } = makeCache(source);
95
-
96
- await cache.seed(new FakeEngine(), RESOURCES);
97
- source.fetches = [];
98
-
99
- const stats = await cache.seed(new FakeEngine(), RESOURCES);
100
- // One small network read (the pointer); the immutable files came from cache.
101
- expect(source.fetches).toEqual([`${PREFIX}/metadata/version-hint.text`]);
102
- expect(stats).toEqual({ tables: 1, fromCache: 2, fetched: 1 });
103
- });
104
-
105
- it("a new snapshot fetches only unseen files and prunes superseded ones", async () => {
106
- const source = new FakeWarehouse();
107
- source.commit(PREFIX, 1, { "data/v1.json": [{ id: 1 }] });
108
- const { cache, storage } = makeCache(source);
109
- await cache.seed(new FakeEngine(), RESOURCES);
110
-
111
- // Update/delete rewrite a compacted snapshot: v2 supersedes v1's file.
112
- source.commit(PREFIX, 2, { "data/v2.json": [{ id: 1, name: "x" }] });
113
- source.fetches = [];
114
-
115
- const engine = new FakeEngine();
116
- await cache.seed(engine, RESOURCES);
117
-
118
- expect(source.fetches).toEqual([
119
- `${PREFIX}/metadata/version-hint.text`,
120
- `${PREFIX}/metadata/v2.metadata.json`,
121
- `${PREFIX}/data/v2.json`,
122
- ]);
123
- expect(engine.seeded).toContain(`${PREFIX}/data/v2.json`);
124
- // The superseded snapshot's files no longer occupy the device.
125
- const keys = await storage.keys("");
126
- expect(keys.some((k) => k.includes("v1.metadata.json"))).toBe(false);
127
- expect(keys.some((k) => k.includes("data/v1.json"))).toBe(false);
128
- });
129
-
130
- it("falls back to the cached pointer when offline", async () => {
131
- const source = new FakeWarehouse();
132
- source.commit(PREFIX, 1, { "data/v1.json": [{ id: 1 }] });
133
- const { cache } = makeCache(source);
134
- await cache.seed(new FakeEngine(), RESOURCES);
135
-
136
- source.offline = true;
137
- const engine = new FakeEngine();
138
- const stats = await cache.seed(engine, RESOURCES);
139
- expect(stats.tables).toBe(1);
140
- expect(stats.fetched).toBe(0);
141
- expect(engine.seeded).toHaveLength(3);
142
- });
143
-
144
- it("revoked access deletes the identity's cached data and surfaces the error", async () => {
145
- const source = new FakeWarehouse();
146
- source.commit(PREFIX, 1, { "data/v1.json": [{ id: 1 }] });
147
- const { cache, storage } = makeCache(source);
148
- await cache.seed(new FakeEngine(), RESOURCES);
149
- expect(await storage.keys("alice-sub::")).not.toHaveLength(0);
150
-
151
- source.revoked = true;
152
- await expect(cache.seed(new FakeEngine(), RESOURCES)).rejects.toThrow(
153
- AccessRevokedError,
154
- );
155
- // Nothing of alice's survives on the device.
156
- expect(await storage.keys("alice-sub::")).toHaveLength(0);
157
- });
158
-
159
- it("enforces the offline-retention bound: stale cache is deleted, not served", async () => {
160
- const source = new FakeWarehouse();
161
- source.commit(PREFIX, 1, { "data/v1.json": [{ id: 1 }] });
162
- const storage = new MemoryCacheStorage();
163
- let clock = 1_000_000;
164
- const cache = new IcebergFileCache({
165
- storage,
166
- source,
167
- identity: "alice",
168
- maxOfflineMs: 60_000,
169
- now: () => clock,
170
- });
171
- await cache.seed(new FakeEngine(), RESOURCES);
172
-
173
- // Offline but within the bound: cached data still serves.
174
- source.offline = true;
175
- clock += 30_000;
176
- expect((await cache.seed(new FakeEngine(), RESOURCES)).tables).toBe(1);
177
-
178
- // Past the bound: the cache refuses AND deletes the identity's data.
179
- clock += 60_001;
180
- await expect(cache.seed(new FakeEngine(), RESOURCES)).rejects.toThrow(
181
- CacheExpiredError,
182
- );
183
- expect(await storage.keys("alice::")).toHaveLength(0);
184
-
185
- // Back online: re-verification restores service from the source.
186
- source.offline = false;
187
- expect((await cache.seed(new FakeEngine(), RESOURCES)).tables).toBe(1);
188
- });
189
-
190
- it("namespaces isolate identities sharing one device", async () => {
191
- const source = new FakeWarehouse();
192
- source.commit(PREFIX, 1, { "data/v1.json": [{ id: 1 }] });
193
- const storage = new MemoryCacheStorage();
194
- const alice = new IcebergFileCache({ storage, source, identity: "alice" });
195
- const bob = new IcebergFileCache({ storage, source, identity: "bob" });
196
-
197
- await alice.seed(new FakeEngine(), RESOURCES);
198
- await bob.seed(new FakeEngine(), RESOURCES);
199
-
200
- await purgeLocalData({ identity: "alice", cacheStorage: storage });
201
- expect(await storage.keys("alice::")).toHaveLength(0);
202
- expect(await storage.keys("bob::")).not.toHaveLength(0);
203
- });
204
- });
205
-
206
- describe("createEncryptedCacheStorage", () => {
207
- it("round-trips values while storing only ciphertext", async () => {
208
- const inner = new MemoryCacheStorage();
209
- const key = await generateEncryptionKey();
210
- const storage = createEncryptedCacheStorage(inner, key);
211
- const plaintext = encoder.encode("sensitive row data");
212
-
213
- await storage.put("k", plaintext);
214
- expect(new Uint8Array((await storage.get("k"))!)).toEqual(plaintext);
215
-
216
- // What actually hits the device is sealed: different bytes, and a fresh
217
- // random IV means two writes of the same value differ too.
218
- const sealed1 = (await inner.get("k"))!;
219
- expect(Buffer.from(sealed1).includes(Buffer.from(plaintext))).toBe(false);
220
- await storage.put("k", plaintext);
221
- expect((await inner.get("k"))!).not.toEqual(sealed1);
222
- });
223
-
224
- it("treats undecryptable bytes as a cache miss, never as data", async () => {
225
- const inner = new MemoryCacheStorage();
226
- const storage = createEncryptedCacheStorage(inner, await generateEncryptionKey());
227
- await storage.put("k", encoder.encode("secret"));
228
-
229
- // Read back under a different key → miss.
230
- const other = createEncryptedCacheStorage(inner, await generateEncryptionKey());
231
- expect(await other.get("k")).toBeNull();
232
-
233
- // Tampered ciphertext → authenticated decryption fails → miss.
234
- const sealed = (await inner.get("k"))!;
235
- sealed[sealed.length - 1] ^= 0xff;
236
- await inner.put("k", sealed);
237
- expect(await storage.get("k")).toBeNull();
238
- });
239
-
240
- it("works end-to-end as the IcebergFileCache storage", async () => {
241
- const source = new FakeWarehouse();
242
- source.commit(PREFIX, 1, { "data/v1.json": [{ id: 1, code: "JFK" }] });
243
- const inner = new MemoryCacheStorage();
244
- const cache = new IcebergFileCache({
245
- storage: createEncryptedCacheStorage(inner, await generateEncryptionKey()),
246
- source,
247
- identity: "alice",
248
- });
249
-
250
- await cache.seed(new FakeEngine(), RESOURCES);
251
- source.fetches = [];
252
- const stats = await cache.seed(new FakeEngine(), RESOURCES);
253
- // Warm-cache behaviour is unchanged by encryption.
254
- expect(stats).toEqual({ tables: 1, fromCache: 2, fetched: 1 });
255
- // And nothing readable sits on the device.
256
- const stored = await Promise.all(
257
- (await inner.keys("alice::")).map((k) => inner.get(k)),
258
- );
259
- for (const bytes of stored) {
260
- expect(Buffer.from(bytes!).includes(Buffer.from("JFK"))).toBe(false);
261
- }
262
- });
263
- });