@fireproof/core 0.20.0-dev-preview-17 → 0.20.0-dev-preview-19

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,51 +1,51 @@
1
1
  import { Result, URI } from "@adviser/cement";
2
- import { bs, fireproof, SuperThis } from "@fireproof/core";
2
+ import { bs, fireproof } from "@fireproof/core";
3
3
 
4
4
  class TestInterceptor extends bs.PassThroughGateway {
5
5
  readonly fn = vitest.fn();
6
6
 
7
- async buildUrl(sthis: SuperThis, baseUrl: URI, key: string): Promise<Result<bs.SerdeGatewayBuildUrlReturn>> {
8
- const ret = await super.buildUrl(sthis, baseUrl, key);
7
+ async buildUrl(ctx: bs.SerdeGatewayCtx, baseUrl: URI, key: string): Promise<Result<bs.SerdeGatewayBuildUrlReturn>> {
8
+ const ret = await super.buildUrl(ctx, baseUrl, key);
9
9
  this.fn("buildUrl", ret);
10
10
  return ret;
11
11
  }
12
12
 
13
- async start(sthis: SuperThis, baseUrl: URI): Promise<Result<bs.SerdeGatewayStartReturn>> {
14
- const ret = await super.start(sthis, baseUrl);
13
+ async start(ctx: bs.SerdeGatewayCtx, baseUrl: URI): Promise<Result<bs.SerdeGatewayStartReturn>> {
14
+ const ret = await super.start(ctx, baseUrl);
15
15
  this.fn("start", ret);
16
16
  return ret;
17
17
  }
18
- async close(sthis: SuperThis, baseUrl: URI): Promise<Result<bs.SerdeGatewayCloseReturn>> {
19
- const ret = await super.close(sthis, baseUrl);
18
+ async close(ctx: bs.SerdeGatewayCtx, baseUrl: URI): Promise<Result<bs.SerdeGatewayCloseReturn>> {
19
+ const ret = await super.close(ctx, baseUrl);
20
20
  this.fn("close", ret);
21
21
  return ret;
22
22
  }
23
- async delete(sthis: SuperThis, baseUrl: URI): Promise<Result<bs.SerdeGatewayDeleteReturn>> {
24
- const ret = await super.delete(sthis, baseUrl);
23
+ async delete(ctx: bs.SerdeGatewayCtx, baseUrl: URI): Promise<Result<bs.SerdeGatewayDeleteReturn>> {
24
+ const ret = await super.delete(ctx, baseUrl);
25
25
  this.fn("delete", ret);
26
26
  return ret;
27
27
  }
28
- async destroy(sthis: SuperThis, baseUrl: URI): Promise<Result<bs.SerdeGatewayDestroyReturn>> {
29
- const ret = await super.destroy(sthis, baseUrl);
28
+ async destroy(ctx: bs.SerdeGatewayCtx, baseUrl: URI): Promise<Result<bs.SerdeGatewayDestroyReturn>> {
29
+ const ret = await super.destroy(ctx, baseUrl);
30
30
  this.fn("destroy", ret);
31
31
  return ret;
32
32
  }
33
- async put<T>(sthis: SuperThis, url: URI, body: bs.FPEnvelope<T>): Promise<Result<bs.SerdeGatewayPutReturn<T>>> {
34
- const ret = await super.put<T>(sthis, url, body);
33
+ async put<T>(ctx: bs.SerdeGatewayCtx, url: URI, body: bs.FPEnvelope<T>): Promise<Result<bs.SerdeGatewayPutReturn<T>>> {
34
+ const ret = await super.put<T>(ctx, url, body);
35
35
  this.fn("put", ret);
36
36
  return ret;
37
37
  }
38
- async get<S>(sthis: SuperThis, url: URI): Promise<Result<bs.SerdeGatewayGetReturn<S>>> {
39
- const ret = await super.get<S>(sthis, url);
38
+ async get<S>(ctx: bs.SerdeGatewayCtx, url: URI): Promise<Result<bs.SerdeGatewayGetReturn<S>>> {
39
+ const ret = await super.get<S>(ctx, url);
40
40
  this.fn("get", ret);
41
41
  return ret;
42
42
  }
43
43
  async subscribe(
44
- sthis: SuperThis,
44
+ ctx: bs.SerdeGatewayCtx,
45
45
  url: URI,
46
46
  callback: (meta: bs.FPEnvelopeMeta) => Promise<void>,
47
47
  ): Promise<Result<bs.SerdeGatewaySubscribeReturn>> {
48
- const ret = await super.subscribe(sthis, url, callback);
48
+ const ret = await super.subscribe(ctx, url, callback);
49
49
  this.fn("subscribe", ret);
50
50
  return ret;
51
51
  }
@@ -1,4 +1,4 @@
1
- import { bs, PARAM, rt } from "@fireproof/core";
1
+ import { bs, ensureSuperThis, PARAM, rt } from "@fireproof/core";
2
2
  import { runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
3
3
  import { base58btc } from "multiformats/bases/base58";
4
4
  import { mockSuperThis } from "../helpers.js";
@@ -56,7 +56,7 @@ describe("KeyBag indexdb and file", () => {
56
56
 
57
57
  let diskBag: rt.kb.KeyItem;
58
58
  let diskBag2: rt.kb.KeyItem;
59
- const provider = await kb.rt.getBag();
59
+ const provider = await kb.rt.getBagProvider();
60
60
  if (runtimeFn().isBrowser) {
61
61
  const p = provider as KeyBagProviderIndexDB;
62
62
  diskBag = await p._prepare().then((db) => db.get("bag", name));
@@ -94,7 +94,7 @@ describe("KeyedCryptoStore", () => {
94
94
  let loader: bs.Loadable;
95
95
  // let logger: Logger;
96
96
  let baseUrl: URI;
97
- const sthis = mockSuperThis();
97
+ const sthis = ensureSuperThis();
98
98
  beforeEach(async () => {
99
99
  await sthis.start();
100
100
  // logger = MockLogger().logger;
@@ -108,6 +108,7 @@ describe("KeyedCryptoStore", () => {
108
108
  }
109
109
  baseUrl = baseUrl.build().defParam(PARAM.NAME, "test").URI();
110
110
  loader = {
111
+ sthis,
111
112
  keyBag: () => rt.kb.getKeyBag(sthis, { url: kbUrl }),
112
113
  } as bs.Loadable;
113
114
  });
@@ -116,9 +117,9 @@ describe("KeyedCryptoStore", () => {
116
117
  const url = baseUrl.build().setParam(PARAM.STORE_KEY, "insecure").URI();
117
118
 
118
119
  for (const pstore of [
119
- strt.makeDataStore({ sthis, url, loader }),
120
- strt.makeMetaStore({ sthis, url, loader }),
121
- strt.makeWALStore({ sthis, url, loader }),
120
+ strt.makeDataStore({ url, loader }),
121
+ strt.makeMetaStore({ url, loader }),
122
+ strt.makeWALStore({ url, loader }),
122
123
  ]) {
123
124
  const store = await pstore;
124
125
  // await store.start();
@@ -87,7 +87,7 @@ describe("KeyBag", () => {
87
87
 
88
88
  let diskBag: rt.kb.KeyItem;
89
89
  let diskBag2: rt.kb.KeyItem;
90
- const provider = await kb.rt.getBag();
90
+ const provider = await kb.rt.getBagProvider();
91
91
  if (runtimeFn().isBrowser) {
92
92
  const p = provider as KeyBagProviderIndexDB;
93
93
  diskBag = await p._prepare().then((db) => db.get("bag", name));
@@ -152,6 +152,7 @@ describe("KeyedCryptoStore", () => {
152
152
  baseUrl = baseUrl.build().setParam(PARAM.NAME, "test").URI();
153
153
  kb = await rt.kb.getKeyBag(sthis, {});
154
154
  loader = {
155
+ sthis,
155
156
  keyBag: async () => kb,
156
157
  } as bs.Loadable;
157
158
  });
@@ -160,9 +161,9 @@ describe("KeyedCryptoStore", () => {
160
161
  const url = baseUrl.build().setParam(PARAM.STORE_KEY, "insecure").URI();
161
162
 
162
163
  for (const pstore of [
163
- strt.makeDataStore({ sthis, url, loader }),
164
- strt.makeMetaStore({ sthis, url, loader }),
165
- strt.makeWALStore({ sthis, url, loader }),
164
+ strt.makeDataStore({ url, loader }),
165
+ strt.makeMetaStore({ url, loader }),
166
+ strt.makeWALStore({ url, loader }),
166
167
  ]) {
167
168
  const store = await pstore;
168
169
  // await store.start();
@@ -177,9 +178,9 @@ describe("KeyedCryptoStore", () => {
177
178
  it("create key", async () => {
178
179
  const strt = bs.toStoreRuntime(sthis);
179
180
  for (const pstore of [
180
- strt.makeDataStore({ sthis, url: baseUrl, loader }),
181
- strt.makeMetaStore({ sthis, url: baseUrl, loader }),
182
- strt.makeWALStore({ sthis, url: baseUrl, loader }),
181
+ strt.makeDataStore({ url: baseUrl, loader }),
182
+ strt.makeMetaStore({ url: baseUrl, loader }),
183
+ strt.makeWALStore({ url: baseUrl, loader }),
183
184
  ]) {
184
185
  const store = await pstore; // await bs.ensureStart(await pstore, logger);
185
186
  const kc = await store.keyedCrypto();
@@ -195,9 +196,9 @@ describe("KeyedCryptoStore", () => {
195
196
  const url = baseUrl.build().setParam(PARAM.STORE_KEY, "@heute@").URI();
196
197
  const strt = bs.toStoreRuntime(sthis);
197
198
  for (const pstore of [
198
- strt.makeDataStore({ sthis, url, loader }),
199
- strt.makeMetaStore({ sthis, url, loader }),
200
- strt.makeWALStore({ sthis, url, loader }),
199
+ strt.makeDataStore({ url, loader }),
200
+ strt.makeMetaStore({ url, loader }),
201
+ strt.makeWALStore({ url, loader }),
201
202
  ]) {
202
203
  const store = await pstore;
203
204
  // await store.start();
@@ -220,9 +221,9 @@ describe("KeyedCryptoStore", () => {
220
221
  const strt = bs.toStoreRuntime(sthis);
221
222
  const url = baseUrl.build().setParam(PARAM.STORE_KEY, key).URI();
222
223
  for (const pstore of [
223
- strt.makeDataStore({ sthis, url, loader }),
224
- strt.makeMetaStore({ sthis, url, loader }),
225
- strt.makeWALStore({ sthis, url, loader }),
224
+ strt.makeDataStore({ url, loader }),
225
+ strt.makeMetaStore({ url, loader }),
226
+ strt.makeWALStore({ url, loader }),
226
227
  ]) {
227
228
  // for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
228
229
  const store = await pstore;
@@ -10,9 +10,10 @@ function runtime(sthis: SuperThis) {
10
10
  async function mockLoader(sthis: SuperThis, name?: string): Promise<bs.StoreFactoryItem> {
11
11
  const url = noopUrl(name);
12
12
  return {
13
- sthis,
13
+ // sthis,
14
14
  url: url,
15
15
  loader: {
16
+ sthis,
16
17
  keyBag: () => rt.kb.getKeyBag(sthis),
17
18
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
19
  handleDbMetasFromStore: (metas: DbMeta[]): Promise<void> => Promise.resolve(),
@@ -22,8 +23,9 @@ async function mockLoader(sthis: SuperThis, name?: string): Promise<bs.StoreFact
22
23
 
23
24
  describe("DataStore", function () {
24
25
  let store: bs.DataStore;
25
-
26
26
  const sthis = ensureSuperThis();
27
+ let loader: bs.StoreFactoryItem;
28
+
27
29
  afterEach(async () => {
28
30
  await store.close();
29
31
  await store.destroy();
@@ -31,7 +33,8 @@ describe("DataStore", function () {
31
33
 
32
34
  beforeEach(async () => {
33
35
  await sthis.start();
34
- store = await runtime(sthis).makeDataStore(await mockLoader(sthis));
36
+ loader = await mockLoader(sthis);
37
+ store = await runtime(sthis).makeDataStore(loader);
35
38
  await store.start();
36
39
  });
37
40
 
@@ -45,7 +48,7 @@ describe("DataStore", function () {
45
48
  bytes: new Uint8Array([55, 56, 57]),
46
49
  };
47
50
  await store.save(car);
48
- const data = (await store.realGateway.getPlain(sthis, store.url(), car.cid.toString())).Ok();
51
+ const data = (await store.realGateway.getPlain(loader, store.url(), car.cid.toString())).Ok();
49
52
  expect(sthis.txt.decode(data)).toEqual(sthis.txt.decode(car.bytes));
50
53
  });
51
54
  });
@@ -53,6 +56,7 @@ describe("DataStore", function () {
53
56
  describe("DataStore with a saved car", function () {
54
57
  let store: bs.DataStore;
55
58
  let car: bs.AnyBlock;
59
+ let loader: bs.StoreFactoryItem;
56
60
 
57
61
  const sthis = ensureSuperThis();
58
62
 
@@ -63,7 +67,8 @@ describe("DataStore with a saved car", function () {
63
67
 
64
68
  beforeEach(async function () {
65
69
  await sthis.start();
66
- store = await runtime(sthis).makeDataStore(await mockLoader(sthis, "test2"));
70
+ loader = await mockLoader(sthis, "test2");
71
+ store = await runtime(sthis).makeDataStore(loader);
67
72
  await store.start();
68
73
  car = {
69
74
  cid: "cid" as unknown as CID,
@@ -73,7 +78,7 @@ describe("DataStore with a saved car", function () {
73
78
  });
74
79
 
75
80
  it("should have a car", async function () {
76
- const data = (await store.realGateway.getPlain(sthis, store.url(), car.cid.toString())).Ok();
81
+ const data = (await store.realGateway.getPlain(loader, store.url(), car.cid.toString())).Ok();
77
82
  expect(sthis.txt.decode(data)).toEqual(sthis.txt.decode(car.bytes));
78
83
  });
79
84
 
@@ -93,8 +98,8 @@ describe("DataStore with a saved car", function () {
93
98
 
94
99
  describe("MetaStore", function () {
95
100
  let store: bs.MetaStore;
96
-
97
101
  const sthis = ensureSuperThis();
102
+ let loader: bs.StoreFactoryItem;
98
103
 
99
104
  afterEach(async () => {
100
105
  await store.close();
@@ -103,7 +108,8 @@ describe("MetaStore", function () {
103
108
 
104
109
  beforeEach(async function () {
105
110
  await sthis.start();
106
- store = await runtime(sthis).makeMetaStore(await mockLoader(sthis, "test"));
111
+ loader = await mockLoader(sthis, "test");
112
+ store = await runtime(sthis).makeMetaStore(loader);
107
113
  await store.start();
108
114
  });
109
115
 
@@ -118,7 +124,7 @@ describe("MetaStore", function () {
118
124
  // key: undefined,
119
125
  };
120
126
  await store.save(h);
121
- const file = await store.realGateway.getPlain(sthis, store.url(), "main");
127
+ const file = await store.realGateway.getPlain(loader, store.url(), "main");
122
128
  const blockMeta = (await rt.gw.fpDeserialize(sthis, store.url(), file)) as Result<bs.FPEnvelopeMeta>;
123
129
  expect(blockMeta.Ok()).toBeTruthy();
124
130
  expect(blockMeta.Ok().payload.length).toEqual(1);
@@ -133,6 +139,7 @@ describe("MetaStore with a saved header", function () {
133
139
  let store: bs.MetaStore;
134
140
  let cid: CID;
135
141
  const sthis = ensureSuperThis();
142
+ let loader: bs.StoreFactoryItem;
136
143
 
137
144
  afterEach(async () => {
138
145
  await store.close();
@@ -141,7 +148,8 @@ describe("MetaStore with a saved header", function () {
141
148
 
142
149
  beforeEach(async function () {
143
150
  await sthis.start();
144
- store = await runtime(sthis).makeMetaStore(await mockLoader(sthis, "test-saved-header"));
151
+ loader = await mockLoader(sthis, "test-saved-header");
152
+ store = await runtime(sthis).makeMetaStore(loader);
145
153
  await store.start();
146
154
  cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
147
155
  await store.save({ cars: [cid] /*, key: undefined */ });
@@ -154,7 +162,7 @@ describe("MetaStore with a saved header", function () {
154
162
  // });
155
163
 
156
164
  it("should have a header", async function () {
157
- const bytes = await store.realGateway.getPlain(sthis, store.url(), "main");
165
+ const bytes = await store.realGateway.getPlain(loader, store.url(), "main");
158
166
  const data = sthis.txt.decode(bytes.Ok());
159
167
  expect(data).toMatch(/parents/);
160
168
  const header = JSON.parse(data)[0];
@@ -41,6 +41,7 @@ describe("noop Gateway", function () {
41
41
  let fileGateway: bs.SerdeGateway;
42
42
  let walGateway: bs.SerdeGateway;
43
43
  const sthis = ensureSuperThis();
44
+ let ctx: { loader: bs.Loadable };
44
45
 
45
46
  afterEach(async function () {
46
47
  await db.close();
@@ -50,12 +51,13 @@ describe("noop Gateway", function () {
50
51
  db = LedgerFactory("test-gateway-" + sthis.nextId().str, {
51
52
  logger: sthis.logger,
52
53
  });
54
+ ctx = { loader: await db.crdt.blockstore.loader };
53
55
 
54
56
  // Extract stores from the loader
55
- carStore = (await db.crdt.blockstore.loader?.carStore()) as bs.DataStore;
56
- metaStore = (await db.crdt.blockstore.loader?.metaStore()) as bs.MetaStore;
57
- fileStore = (await db.crdt.blockstore.loader?.fileStore()) as bs.DataStore;
58
- walStore = (await db.crdt.blockstore.loader?.WALStore()) as bs.WALStore;
57
+ carStore = (await ctx.loader.carStore()) as bs.DataStore;
58
+ metaStore = (await ctx.loader.metaStore()) as bs.MetaStore;
59
+ fileStore = (await ctx.loader.fileStore()) as bs.DataStore;
60
+ walStore = (await ctx.loader.WALStore()) as bs.WALStore;
59
61
 
60
62
  // Extract and log gateways
61
63
  carGateway = carStore.realGateway;
@@ -112,19 +114,19 @@ describe("noop Gateway", function () {
112
114
 
113
115
  it("should build CAR Gateway URL", async function () {
114
116
  const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
115
- const carUrl = await carGateway.buildUrl(sthis, carStore.url(), testKey);
117
+ const carUrl = await carGateway.buildUrl(ctx, carStore.url(), testKey);
116
118
  expect(carUrl.Ok().hasParam("key")).toBeTruthy();
117
119
  });
118
120
 
119
121
  it("should start CAR Gateway", async function () {
120
- const url = await carGateway.start(sthis, carStore.url());
122
+ const url = await carGateway.start(ctx, carStore.url());
121
123
  expect(url.Ok().asObj()).toEqual(carStore.url().asObj());
122
124
  });
123
125
 
124
126
  it("should put data in CAR Gateway", async function () {
125
- const carUrl = await carGateway.buildUrl(sthis, carStore.url(), fileContent.cid);
126
- await carGateway.start(sthis, carStore.url());
127
- const carPutResult = await carGateway.put(sthis, carUrl.Ok(), {
127
+ const carUrl = await carGateway.buildUrl(ctx, carStore.url(), fileContent.cid);
128
+ await carGateway.start(ctx, carStore.url());
129
+ const carPutResult = await carGateway.put(ctx, carUrl.Ok(), {
128
130
  type: bs.FPEnvelopeType.CAR,
129
131
  payload: fileContent.block,
130
132
  });
@@ -132,59 +134,59 @@ describe("noop Gateway", function () {
132
134
  });
133
135
 
134
136
  it("should get data from CAR Gateway", async function () {
135
- const carUrl = await carGateway.buildUrl(sthis, carStore.url(), fileContent.cid);
136
- await carGateway.start(sthis, carStore.url());
137
- await carGateway.put(sthis, carUrl.Ok(), {
137
+ const carUrl = await carGateway.buildUrl(ctx, carStore.url(), fileContent.cid);
138
+ await carGateway.start(ctx, carStore.url());
139
+ await carGateway.put(ctx, carUrl.Ok(), {
138
140
  type: bs.FPEnvelopeType.CAR,
139
141
  payload: fileContent.block,
140
142
  });
141
- const carGetResult = await carGateway.get(sthis, carUrl.Ok());
143
+ const carGetResult = await carGateway.get(ctx, carUrl.Ok());
142
144
  expect(carGetResult.Ok().type).toEqual("car");
143
145
  expect(carGetResult.Ok().payload).toEqual(fileContent.block);
144
146
  // customExpect(carGetResult.Ok(), (v) => expect(v).toEqual(testData), "carGetResult should match testData");
145
147
  });
146
148
 
147
149
  it("should delete data from CAR Gateway", async function () {
148
- const carUrl = await carGateway.buildUrl(sthis, carStore.url(), fileContent.cid);
149
- await carGateway.start(sthis, carStore.url());
150
- await carGateway.put(sthis, carUrl.Ok(), {
150
+ const carUrl = await carGateway.buildUrl(ctx, carStore.url(), fileContent.cid);
151
+ await carGateway.start(ctx, carStore.url());
152
+ await carGateway.put(ctx, carUrl.Ok(), {
151
153
  type: bs.FPEnvelopeType.CAR,
152
154
  payload: fileContent.block,
153
155
  });
154
- const carDeleteResult = await carGateway.delete(sthis, carUrl.Ok());
156
+ const carDeleteResult = await carGateway.delete(ctx, carUrl.Ok());
155
157
  expect(carDeleteResult.isOk()).toBeTruthy();
156
158
  });
157
159
 
158
160
  it("should close CAR Gateway", async function () {
159
- await carGateway.close(sthis, carStore.url());
161
+ await carGateway.close(ctx, carStore.url());
160
162
  });
161
163
  it("should build Meta Gateway URL", async function () {
162
- const metaUrl = await metaGateway.buildUrl(sthis, metaStore.url(), "main");
164
+ const metaUrl = await metaGateway.buildUrl(ctx, metaStore.url(), "main");
163
165
  expect(metaUrl.Ok()).toBeTruthy();
164
166
  });
165
167
 
166
168
  it("should start Meta Gateway", async function () {
167
- await metaGateway.start(sthis, metaStore.url());
169
+ await metaGateway.start(ctx, metaStore.url());
168
170
  });
169
171
 
170
172
  it("should close Meta Gateway", async function () {
171
- await metaGateway.start(sthis, metaStore.url());
172
- await metaGateway.close(sthis, metaStore.url());
173
+ await metaGateway.start(ctx, metaStore.url());
174
+ await metaGateway.close(ctx, metaStore.url());
173
175
  });
174
176
 
175
177
  it("should build File Gateway URL", async function () {
176
- const fileUrl = await fileGateway.buildUrl(sthis, fileStore.url(), fileContent.cid);
178
+ const fileUrl = await fileGateway.buildUrl(ctx, fileStore.url(), fileContent.cid);
177
179
  expect(fileUrl.Ok()).toBeTruthy();
178
180
  });
179
181
 
180
182
  it("should start File Gateway", async function () {
181
- await fileGateway.start(sthis, fileStore.url());
183
+ await fileGateway.start(ctx, fileStore.url());
182
184
  });
183
185
 
184
186
  it("should put data to File Gateway", async function () {
185
- const fileUrl = await fileGateway.buildUrl(sthis, fileStore.url(), fileContent.cid);
186
- await fileGateway.start(sthis, fileStore.url());
187
- const filePutResult = await fileGateway.put(sthis, fileUrl.Ok(), {
187
+ const fileUrl = await fileGateway.buildUrl(ctx, fileStore.url(), fileContent.cid);
188
+ await fileGateway.start(ctx, fileStore.url());
189
+ const filePutResult = await fileGateway.put(ctx, fileUrl.Ok(), {
188
190
  type: bs.FPEnvelopeType.FILE,
189
191
  payload: fileContent.block,
190
192
  });
@@ -192,48 +194,48 @@ describe("noop Gateway", function () {
192
194
  });
193
195
 
194
196
  it("should get data from File Gateway", async function () {
195
- const fileUrl = await fileGateway.buildUrl(sthis, fileStore.url(), fileContent.cid);
196
- await fileGateway.start(sthis, fileStore.url());
197
- await fileGateway.put(sthis, fileUrl.Ok(), {
197
+ const fileUrl = await fileGateway.buildUrl(ctx, fileStore.url(), fileContent.cid);
198
+ await fileGateway.start(ctx, fileStore.url());
199
+ await fileGateway.put(ctx, fileUrl.Ok(), {
198
200
  type: bs.FPEnvelopeType.FILE,
199
201
  payload: fileContent.block,
200
202
  });
201
- const fileGetResult = await fileGateway.get(sthis, fileUrl.Ok());
203
+ const fileGetResult = await fileGateway.get(ctx, fileUrl.Ok());
202
204
  expect(fileGetResult.Ok().type).toEqual("file");
203
205
  expect(fileGetResult.Ok().payload).toEqual(fileContent.block);
204
206
  });
205
207
 
206
208
  it("should delete data from File Gateway", async function () {
207
- const fileUrl = await fileGateway.buildUrl(sthis, fileStore.url(), fileContent.cid);
208
- await fileGateway.start(sthis, fileStore.url());
209
- await fileGateway.put(sthis, fileUrl.Ok(), {
209
+ const fileUrl = await fileGateway.buildUrl(ctx, fileStore.url(), fileContent.cid);
210
+ await fileGateway.start(ctx, fileStore.url());
211
+ await fileGateway.put(ctx, fileUrl.Ok(), {
210
212
  type: bs.FPEnvelopeType.FILE,
211
213
  payload: fileContent.block,
212
214
  });
213
- const fileDeleteResult = await fileGateway.delete(sthis, fileUrl.Ok());
215
+ const fileDeleteResult = await fileGateway.delete(ctx, fileUrl.Ok());
214
216
  expect(fileDeleteResult.isOk()).toBeTruthy();
215
217
  });
216
218
 
217
219
  it("should close File Gateway", async function () {
218
- await fileGateway.close(sthis, fileStore.url());
220
+ await fileGateway.close(ctx, fileStore.url());
219
221
  });
220
222
  it("should build WAL Gateway URL", async function () {
221
223
  const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
222
- const walUrl = await walGateway.buildUrl(sthis, walStore.url(), testKey);
224
+ const walUrl = await walGateway.buildUrl(ctx, walStore.url(), testKey);
223
225
  expect(walUrl.Ok()).toBeTruthy();
224
226
  });
225
227
 
226
228
  it("should start WAL Gateway", async function () {
227
- await walGateway.start(sthis, walStore.url());
229
+ await walGateway.start(ctx, walStore.url());
228
230
  });
229
231
 
230
232
  it("should put data to WAL Gateway", async function () {
231
233
  const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
232
- const walUrl = await walGateway.buildUrl(sthis, walStore.url(), testKey);
233
- await walGateway.start(sthis, walStore.url());
234
+ const walUrl = await walGateway.buildUrl(ctx, walStore.url(), testKey);
235
+ await walGateway.start(ctx, walStore.url());
234
236
  // const walTestDataString = JSON.stringify();
235
237
  // const walTestData = sthis.txt.encode(walTestDataString);
236
- const walPutResult = await walGateway.put(sthis, walUrl.Ok(), {
238
+ const walPutResult = await walGateway.put(ctx, walUrl.Ok(), {
237
239
  type: bs.FPEnvelopeType.WAL,
238
240
  payload: {
239
241
  operations: [],
@@ -246,8 +248,8 @@ describe("noop Gateway", function () {
246
248
 
247
249
  it("should get data from WAL Gateway", async function () {
248
250
  const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
249
- const walUrl = await walGateway.buildUrl(sthis, walStore.url(), testKey);
250
- await walGateway.start(sthis, walStore.url());
251
+ const walUrl = await walGateway.buildUrl(ctx, walStore.url(), testKey);
252
+ await walGateway.start(ctx, walStore.url());
251
253
  const ref: bs.WALState = {
252
254
  operations: [
253
255
  {
@@ -272,11 +274,11 @@ describe("noop Gateway", function () {
272
274
  // fileOperations: [],
273
275
  // });
274
276
  // const walTestData = sthis.txt.encode(walTestDataString);
275
- await walGateway.put(sthis, walUrl.Ok(), {
277
+ await walGateway.put(ctx, walUrl.Ok(), {
276
278
  type: bs.FPEnvelopeType.WAL,
277
279
  payload: ref,
278
280
  });
279
- const walGetResult = await walGateway.get(sthis, walUrl.Ok());
281
+ const walGetResult = await walGateway.get(ctx, walUrl.Ok());
280
282
  expect(walGetResult.isOk()).toBeTruthy();
281
283
  // const okResult = walGetResult.Ok();
282
284
  // const decodedResult = sthis.txt.decode(okResult);
@@ -285,8 +287,8 @@ describe("noop Gateway", function () {
285
287
 
286
288
  it("should delete data from WAL Gateway", async function () {
287
289
  const testKey = "bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i";
288
- const walUrl = await walGateway.buildUrl(sthis, walStore.url(), testKey);
289
- await walGateway.start(sthis, walStore.url());
290
+ const walUrl = await walGateway.buildUrl(ctx, walStore.url(), testKey);
291
+ await walGateway.start(ctx, walStore.url());
290
292
  const ref: bs.WALState = {
291
293
  operations: [
292
294
  {
@@ -305,17 +307,17 @@ describe("noop Gateway", function () {
305
307
  },
306
308
  ],
307
309
  };
308
- await walGateway.put(sthis, walUrl.Ok(), {
310
+ await walGateway.put(ctx, walUrl.Ok(), {
309
311
  type: bs.FPEnvelopeType.WAL,
310
312
  payload: ref,
311
313
  });
312
- const walDeleteResult = await walGateway.delete(sthis, walUrl.Ok());
314
+ const walDeleteResult = await walGateway.delete(ctx, walUrl.Ok());
313
315
  expect(walDeleteResult.isOk()).toBeTruthy();
314
316
  });
315
317
 
316
318
  it("should close WAL Gateway", async function () {
317
- await walGateway.start(sthis, walStore.url());
318
- await walGateway.close(sthis, walStore.url());
319
+ await walGateway.start(ctx, walStore.url());
320
+ await walGateway.close(ctx, walStore.url());
319
321
  });
320
322
 
321
323
  // it("should have correct CAR Gateway properties", async function () {
@@ -370,6 +372,7 @@ describe("noop Gateway subscribe", function () {
370
372
 
371
373
  let metaGateway: bs.SerdeGateway;
372
374
  const sthis = ensureSuperThis();
375
+ let ctx: bs.SerdeGatewayCtx;
373
376
 
374
377
  afterEach(async function () {
375
378
  await db.close();
@@ -378,19 +381,20 @@ describe("noop Gateway subscribe", function () {
378
381
  beforeEach(async function () {
379
382
  db = fireproof("test-gateway-" + sthis.nextId().str);
380
383
 
384
+ ctx = { loader: db.ledger.crdt.blockstore.loader };
381
385
  // Extract stores from the loader
382
386
  metaStore = (await db.ledger.crdt.blockstore.loader?.metaStore()) as bs.MetaStore;
383
387
 
384
388
  metaGateway = metaStore.realGateway;
385
389
  });
386
390
  it("should subscribe to meta Gateway", async function () {
387
- const metaUrl = await metaGateway.buildUrl(sthis, metaStore.url(), "main");
388
- await metaGateway.start(sthis, metaStore.url());
391
+ const metaUrl = await metaGateway.buildUrl(ctx, metaStore.url(), "main");
392
+ await metaGateway.start(ctx, metaStore.url());
389
393
 
390
394
  let didCall = false;
391
395
  const p = new Future<void>();
392
396
 
393
- const metaSubscribeResult = (await metaGateway.subscribe(sthis, metaUrl.Ok(), async (data: bs.FPEnvelopeMeta) => {
397
+ const metaSubscribeResult = (await metaGateway.subscribe(ctx, metaUrl.Ok(), async (data: bs.FPEnvelopeMeta) => {
394
398
  // const decodedData = sthis.txt.decode(data);
395
399
  expect(Array.isArray(data.payload)).toBeTruthy();
396
400
  didCall = true;
@@ -417,12 +421,15 @@ describe("Gateway", function () {
417
421
  // let walGateway: ExtendedGateway;
418
422
  const sthis = ensureSuperThis();
419
423
 
424
+ let ctx: bs.SerdeGatewayCtx;
425
+
420
426
  afterEach(async function () {
421
427
  await db.close();
422
428
  await db.destroy();
423
429
  });
424
430
  beforeEach(async function () {
425
431
  db = fireproof("test-gateway-" + sthis.nextId().str);
432
+ ctx = { loader: db.ledger.crdt.blockstore.loader };
426
433
  const ok = await db.put({ _id: "test", foo: "bar" });
427
434
  expect(ok).toBeTruthy();
428
435
  expect(ok.id).toBe("test");
@@ -441,9 +448,9 @@ describe("Gateway", function () {
441
448
  });
442
449
 
443
450
  it("should get data from Meta Gateway", async function () {
444
- const metaUrl = await metaGateway.buildUrl(sthis, metaStore.url(), "main");
445
- await metaGateway.start(sthis, metaStore.url());
446
- const metaGetResult = await metaGateway.get(sthis, metaUrl.Ok());
451
+ const metaUrl = await metaGateway.buildUrl(ctx, metaStore.url(), "main");
452
+ await metaGateway.start(ctx, metaStore.url());
453
+ const metaGetResult = await metaGateway.get(ctx, metaUrl.Ok());
447
454
  expect(metaGetResult.isOk()).toBeTruthy();
448
455
  const meta = metaGetResult.Ok().payload as bs.DbMetaEvent[];
449
456
  // const metaGetResultOk = metaGetResult.Ok();
@@ -453,10 +460,10 @@ describe("Gateway", function () {
453
460
  });
454
461
 
455
462
  it("should delete data from Meta Gateway", async function () {
456
- const metaUrl = await metaGateway.buildUrl(sthis, metaStore.url(), "main");
457
- await metaGateway.start(sthis, metaStore.url());
463
+ const metaUrl = await metaGateway.buildUrl(ctx, metaStore.url(), "main");
464
+ await metaGateway.start(ctx, metaStore.url());
458
465
  // should we be testing .destroy() instead?
459
- const metaDeleteResult = await metaGateway.delete(sthis, metaUrl.Ok());
466
+ const metaDeleteResult = await metaGateway.delete(ctx, metaUrl.Ok());
460
467
  expect(metaDeleteResult.isOk()).toBeTruthy();
461
468
  });
462
469
  });