Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"@aws-sdk/s3-request-presigner": "^3.750.0",
"@cloudflare/vitest-pool-workers": "^0.7.4",
"@cloudflare/workers-types": "^4.20250224.0",
"@fireproof/core": "0.20.0-dev-preview-50",
"@fireproof/core": "0.19.122",
"@fireproof/vendor": "~2.0.0",
"@ipld/dag-ucan": "^3.4.5",
"@jspm/core": "^2.1.0",
Expand Down
118 changes: 55 additions & 63 deletions src/connection-from-store.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,69 @@
import { BuildURI, runtimeFn } from "@adviser/cement";
import { bs, Database, SuperThis } from "@fireproof/core";
import { BuildURI, CoerceURI, runtimeFn, URI } from "@adviser/cement";
import { bs, Database, ensureLogger, SuperThis } from "@fireproof/core";

// export interface StoreOptions {
// readonly data: bs.DataStore;
// readonly meta: bs.MetaStore;
// readonly wal: bs.WALState;
// }

// export class ConnectionFromStore extends bs.ConnectionBase {
// stores?: {
// readonly data: bs.DataStore;
// readonly meta: bs.MetaStore;
// } = undefined;
export class ConnectionFromStore extends bs.ConnectionBase {
stores?: {
readonly data: bs.DataStore;
readonly meta: bs.MetaStore;
} = undefined;

// // readonly urlData: URI;
// // readonly urlMeta: URI;
// readonly urlData: URI;
// readonly urlMeta: URI;

// readonly sthis: SuperThis;
// constructor(sthis: SuperThis, url: URI) {
// const logger = ensureLogger(sthis, "ConnectionFromStore", {
// url: () => url.toString(),
// this: 1,
// log: 1,
// });
// super(url, logger);
// this.sthis = sthis;
// // this.urlData = url;
// // this.urlMeta = url;
// }
// async onConnect(): Promise<void> {
// this.logger.Debug().Msg("onConnect-start");
// // const stores = {
// // base: this.url,
// // // data: this.urlData,
// // // meta: this.urlMeta,
// // };
// const rName = this.url.getParamResult("name");
// if (rName.isErr()) {
// throw this.logger.Error().Err(rName).Msg("missing Parameter").AsError();
// }
// const storeRuntime = bs.toStoreRuntime(this.sthis);
// const loader: bs.StoreFactoryItem = {
// url: this.url,
// loader: {
// ebOpts: {
// logger: this.logger,
// storeUrls: {
// data: this.url,
// meta: this.url,
// file: this.url,
// wal: this.url,
// },
// // store: { stores },
// storeRuntime,
// } as bs.Loadable["ebOpts"],
// sthis: this.sthis,
// } as bs.Loadable,
// };
readonly sthis: SuperThis;
constructor(sthis: SuperThis, url: URI) {
const logger = ensureLogger(sthis, "ConnectionFromStore", {
url: () => url.toString(),
this: 1,
log: 1,
});
super(url, logger);
this.sthis = sthis;
// this.urlData = url;
// this.urlMeta = url;
}
async onConnect(): Promise<void> {
this.logger.Debug().Msg("onConnect-start");
const stores = {
base: this.url,
// data: this.urlData,
// meta: this.urlMeta,
};
const rName = this.url.getParamResult("name");
if (rName.isErr()) {
throw this.logger.Error().Err(rName).Msg("missing Parameter").AsError();
}
const storeRuntime = bs.toStoreRuntime({ stores }, this.sthis);
const loader = {
name: rName.Ok(),
ebOpts: {
logger: this.logger,
store: { stores },
storeRuntime,
},
sthis: this.sthis,
} as bs.Loadable;

// this.stores = {
// data: await storeRuntime.makeDataStore(loader),
// meta: await storeRuntime.makeMetaStore(loader),
// };
// // await this.stores.data.start();
// // await this.stores.meta.start();
// this.logger.Debug().Msg("onConnect-done");
// return;
// }
// }
this.stores = {
data: await storeRuntime.makeDataStore(loader),
meta: await storeRuntime.makeMetaStore(loader),
};
// await this.stores.data.start();
// await this.stores.meta.start();
this.logger.Debug().Msg("onConnect-done");
return;
}
}

// export function connectionFactory(sthis: SuperThis, iurl: CoerceURI): bs.ConnectionBase {
// return new ConnectionFromStore(sthis, URI.from(iurl));
// }
export function connectionFactory(sthis: SuperThis, iurl: CoerceURI): bs.ConnectionBase {
return new ConnectionFromStore(sthis, URI.from(iurl));
}

export function makeKeyBagUrlExtractable(sthis: SuperThis) {
let base = sthis.env.get("FP_KEYBAG_URL");
Expand Down
14 changes: 3 additions & 11 deletions src/drive/drive-gateway.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { fireproof } from "@fireproof/core";
import { registerGDriveStoreProtocol } from "./drive-gateway.js";
import { connect } from "./index.js";
import { describe, it } from "vitest";
import { smokeDB } from "../../tests/helper.js";

describe("store-register", () => {
it("should store and retrieve data", async () => {
const unreg = registerGDriveStoreProtocol("gdrive:");
const db = fireproof("my-database", {
store: {
stores: {
base: "gdrive://www.googleapis.com/?auth=testtoken",
},
},
});
const db = fireproof("my-database");
connect(db, "ya29.a0AeXRPp4bASF7IqO0gx7MYSjgV8zMixuMR3z4rWvuqYvNUKv9pDuPumJIvmaXzmNE7k-7xArIdN9-VRippEG5ByIoqinkRlyNxunGmLq9oGZvgAiQ6_zUxHBHm1XL2Nx2lBjILtZZkJlFRNc_02wE5GZJ2VkLQar_rS-BKOqPaCgYKAfcSAQ8SFQHGX2Mia-YkdQYWm7KsWLbfF2ZwOQ0175")
await smokeDB(db);
await db.destroy();
unreg();
});
});
Loading