@fireproof/cloud
Version:
Fireproof Cloud gateway for Fireproof
1 lines • 30.3 kB
Source Map (JSON)
{"version":3,"sources":["../../src/cloud/index.ts","../../src/connection-from-store.ts","../../src/cloud/gateway.ts"],"sourcesContent":["import { BuildURI, CoerceURI, KeyedResolvOnce, runtimeFn, URI } from \"@adviser/cement\";\nimport { bs, Database, fireproof } from \"@fireproof/core\";\nimport { ConnectFunction, connectionFactory, makeKeyBagUrlExtractable } from \"../connection-from-store.js\";\nimport { registerFireproofCloudStoreProtocol } from \"./gateway.js\";\n\ninterface ConnectData {\n readonly remoteName: string;\n firstConnect: boolean;\n endpoint?: string;\n}\n\nconst SYNC_DB_NAME = \"fp_sync\";\n\n// Usage:\n//\n// import { useFireproof } from 'use-fireproof'\n// import { connect } from '@fireproof/cloud'\n//\n// const { db } = useFireproof('test')\n//\n// const cx = connect(db);\n\n// TODO need to set the keybag url automatically\n\n// if (!process.env.FP_KEYBAG_URL) {\n// process.env.FP_KEYBAG_URL = \"file://./dist/kb-dir-fireproof?fs=mem\";\n// }\n\nif (!runtimeFn().isBrowser) {\n const url = BuildURI.from(process.env.FP_KEYBAG_URL || \"file://./dist/kb-dir-FireproofCloud\");\n url.setParam(\"extractKey\", \"_deprecated_internal_api\");\n process.env.FP_KEYBAG_URL = url.toString();\n}\n\nregisterFireproofCloudStoreProtocol();\n\nconst connectionCache = new KeyedResolvOnce<bs.Connection>();\nexport const rawConnect: ConnectFunction = (\n db: Database,\n remoteDbName = \"\",\n url = \"fireproof://cloud.fireproof.direct\"\n) => {\n const { sthis, blockstore, name: dbName } = db;\n if (!dbName) {\n throw new Error(\"dbName is required\");\n }\n const urlObj = BuildURI.from(url);\n const existingName = urlObj.getParam(\"name\");\n urlObj.defParam(\"name\", remoteDbName || existingName || dbName);\n urlObj.defParam(\"localName\", dbName);\n urlObj.defParam(\"storekey\", `@${dbName}:data@`);\n urlObj.defParam(\"getBaseUrl\", \"https://storage.fireproof.direct/\");\n const fpUrl = urlObj\n .toString()\n .replace(/^http:\\/\\//, \"fireproof://\")\n .replace(/^https:\\/\\//, \"fireproof://\");\n // console.log(\"Config URL: \" + fpUrl);\n return connectionCache.get(fpUrl).once(() => {\n makeKeyBagUrlExtractable(sthis);\n const connection = connectionFactory(sthis, fpUrl);\n connection.connect_X(blockstore);\n return connection;\n });\n};\n\nasync function getOrCreateRemoteName(dbName: string, remoteName?: string) {\n const syncDb = fireproof(SYNC_DB_NAME);\n\n const result = await syncDb.query<string, ConnectData>(\"localName\", { key: dbName, includeDocs: true });\n if (result.rows.length === 0) {\n const doc = {\n remoteName: remoteName || syncDb.sthis.timeOrderedNextId().str,\n localName: dbName,\n firstConnect: !remoteName,\n } as ConnectData;\n const { id } = await syncDb.put(doc);\n return { ...doc, _id: id };\n }\n const doc = result.rows[0].doc;\n return doc;\n}\n\nexport function connect(\n db: Database,\n remoteName?: string,\n dashboardURI: CoerceURI = \"https://dashboard.fireproof.storage/\",\n remoteURI: CoerceURI = \"fireproof://cloud.fireproof.direct\"\n): Promise<bs.Connection> {\n const dbName = db.name as string;\n if (!dbName) {\n throw new Error(\"Database name is required for cloud connection\");\n }\n\n return getOrCreateRemoteName(dbName, remoteName).then(async (doc) => {\n if (!doc) {\n throw new Error(\"Failed to get or create remote name\");\n }\n doc.endpoint = URI.from(remoteURI).toString();\n const connection = rawConnect(db, doc.remoteName, URI.from(doc.endpoint).toString());\n const connectURI = URI.from(dashboardURI).build().pathname(\"/fp/databases/connect\");\n connectURI.defParam(\"localName\", dbName);\n connectURI.defParam(\"remoteName\", doc.remoteName);\n if (doc.endpoint) {\n connectURI.defParam(\"endpoint\", doc.endpoint);\n }\n // eslint-disable-next-line no-console\n console.log(\"Fireproof Cloud: \" + connectURI.toString());\n if (\n doc.firstConnect &&\n runtimeFn().isBrowser &&\n window.location.href.indexOf(URI.from(dashboardURI).toString()) === -1\n ) {\n // Set firstConnect to false after opening the window, so we don't constantly annoy with the dashboard\n const syncDb = fireproof(SYNC_DB_NAME);\n doc.firstConnect = false;\n await syncDb.put(doc);\n\n // window.open(connectURI.toString(), \"_blank\");\n }\n connection.dashboardUrl = URI.from(connectURI);\n return connection;\n });\n}\n","import { BuildURI, CoerceURI, runtimeFn, URI } from \"@adviser/cement\";\nimport { bs, Database, ensureLogger, SuperThis } from \"@fireproof/core\";\n\n// export interface StoreOptions {\n// readonly data: bs.DataStore;\n// readonly meta: bs.MetaStore;\n// readonly wal: bs.WALState;\n// }\n\nexport class ConnectionFromStore extends bs.ConnectionBase {\n stores?: {\n readonly data: bs.DataStore;\n readonly meta: bs.MetaStore;\n } = undefined;\n\n // readonly urlData: URI;\n // readonly urlMeta: URI;\n\n readonly sthis: SuperThis;\n constructor(sthis: SuperThis, url: URI) {\n const logger = ensureLogger(sthis, \"ConnectionFromStore\", {\n url: () => url.toString(),\n this: 1,\n log: 1,\n });\n super(url, logger);\n this.sthis = sthis;\n // this.urlData = url;\n // this.urlMeta = url;\n }\n async onConnect(): Promise<void> {\n this.logger.Debug().Msg(\"onConnect-start\");\n const stores = {\n base: this.url,\n // data: this.urlData,\n // meta: this.urlMeta,\n };\n const rName = this.url.getParamResult(\"name\");\n if (rName.isErr()) {\n throw this.logger.Error().Err(rName).Msg(\"missing Parameter\").AsError();\n }\n const storeRuntime = bs.toStoreRuntime({ stores }, this.sthis);\n const loader = {\n name: rName.Ok(),\n ebOpts: {\n logger: this.logger,\n store: { stores },\n storeRuntime,\n },\n sthis: this.sthis,\n } as bs.Loadable;\n\n this.stores = {\n data: await storeRuntime.makeDataStore(loader),\n meta: await storeRuntime.makeMetaStore(loader),\n };\n // await this.stores.data.start();\n // await this.stores.meta.start();\n this.logger.Debug().Msg(\"onConnect-done\");\n return;\n }\n}\n\nexport function connectionFactory(sthis: SuperThis, iurl: CoerceURI): bs.ConnectionBase {\n return new ConnectionFromStore(sthis, URI.from(iurl));\n}\n\nexport function makeKeyBagUrlExtractable(sthis: SuperThis) {\n let base = sthis.env.get(\"FP_KEYBAG_URL\");\n if (!base) {\n if (runtimeFn().isBrowser) {\n base = \"indexdb://fp-keybag\";\n } else {\n base = \"file://./dist/kb-dir-partykit\";\n }\n }\n const kbUrl = BuildURI.from(base);\n kbUrl.defParam(\"extractKey\", \"_deprecated_internal_api\");\n sthis.env.set(\"FP_KEYBAG_URL\", kbUrl.toString());\n sthis.logger.Debug().Url(kbUrl, \"keyBagUrl\").Msg(\"Make keybag url extractable\");\n}\n\nexport type ConnectFunction = (db: Database, name?: string, url?: string) => bs.Connection;\n","import { PartySocket, PartySocketOptions } from \"partysocket\";\nimport { Result, URI, BuildURI, KeyedResolvOnce, runtimeFn, exception2Result } from \"@adviser/cement\";\nimport { bs, ensureLogger, getStore, Logger, rt, SuperThis } from \"@fireproof/core\";\n\nexport class FireproofCloudGateway implements bs.Gateway {\n readonly logger: Logger;\n readonly sthis: SuperThis;\n readonly id: string;\n party?: PartySocket;\n url?: URI;\n\n constructor(sthis: SuperThis) {\n this.sthis = sthis;\n this.id = sthis.nextId().str;\n this.logger = ensureLogger(sthis, \"FireproofCloudGateway\", {\n url: () => this.url?.toString(),\n this: this.id,\n }); //.EnableLevel(Level.DEBUG);\n this.logger.Debug().Msg(\"constructor\");\n }\n\n async buildUrl(baseUrl: URI, key: string): Promise<Result<URI>> {\n return Result.Ok(baseUrl.build().setParam(\"key\", key).URI());\n }\n\n pso?: PartySocketOptions;\n async start(uri: URI): Promise<Result<URI>> {\n this.logger.Debug().Msg(\"Starting FireproofCloudGateway with URI: \" + uri.toString());\n\n await this.sthis.start();\n\n this.url = uri;\n const ret = uri.build().defParam(\"version\", \"v0.1-fireproof-cloud\");\n\n const rName = uri.getParamResult(\"name\");\n if (rName.isErr()) {\n return this.logger.Error().Err(rName).Msg(\"name not found\").ResultError();\n }\n let dbName = rName.Ok();\n if (this.url.hasParam(\"index\")) {\n dbName = dbName + \"-idx\";\n }\n ret.defParam(\"party\", \"fireproof\");\n ret.defParam(\"protocol\", \"wss\");\n // const party = uri.getParam(\"party\") || \"fireproof\";\n // const proto = uri.getParam(\"protocol\") || \"wss\";\n let possibleUndef: {\n protocol: \"wss\" | \"ws\" | undefined;\n protocols?: string[];\n prefix?: string;\n } = { protocol: ret.getParam(\"protocol\") as \"wss\" | \"ws\" };\n\n const protocolsStr = uri.getParam(\"protocols\");\n if (protocolsStr) {\n const ps = protocolsStr\n .split(\",\")\n .map((x) => x.trim())\n .filter((x) => x);\n if (ps.length > 0) {\n possibleUndef = { ...possibleUndef, protocols: ps };\n }\n }\n const prefixStr = uri.getParam(\"prefix\");\n if (prefixStr) {\n possibleUndef = { ...possibleUndef, prefix: prefixStr };\n }\n\n const query: PartySocketOptions[\"query\"] = {};\n\n const partySockOpts: PartySocketOptions = {\n id: this.id,\n host: this.url.host,\n room: dbName,\n party: ret.getParam(\"party\"),\n ...possibleUndef,\n query,\n path: this.url.pathname.replace(/^\\//, \"\"),\n };\n\n if (runtimeFn().isNodeIsh) {\n const { WebSocket } = await import(\"ws\");\n partySockOpts.WebSocket = WebSocket;\n }\n this.pso = partySockOpts;\n\n return Result.Ok(ret.URI());\n }\n\n async ready(): Promise<void> {\n this.logger.Debug().Msg(\"ready\");\n }\n\n async connectFireproofCloud() {\n const pkKeyThis = pkKey(this.pso);\n return pkSockets.get(pkKeyThis).once(async () => {\n if (!this.pso) {\n throw new Error(\"Party socket options not found\");\n }\n this.party = new PartySocket(this.pso);\n let exposedResolve: (value: boolean) => void;\n const openFn = () => {\n this.logger.Debug().Msg(\"party open\");\n this.party?.addEventListener(\"message\", async (event: MessageEvent<string>) => {\n this.logger.Debug().Msg(`got message: ${event.data}`);\n const mbin = this.sthis.txt.encode(event.data);\n this.notifySubscribers(mbin);\n });\n exposedResolve(true);\n };\n return await new Promise<boolean>((resolve) => {\n exposedResolve = resolve;\n this.party?.addEventListener(\"open\", openFn);\n });\n });\n }\n\n async close(): Promise<bs.VoidResult> {\n await this.ready();\n this.logger.Debug().Msg(\"close\");\n this.party?.close();\n return Result.Ok(undefined);\n }\n\n async put(uri: URI, body: Uint8Array): Promise<Result<void>> {\n await this.ready();\n const { store } = getStore(uri, this.sthis, (...args) => args.join(\"/\"));\n if (store === \"meta\") {\n const bodyRes = await bs.addCryptoKeyToGatewayMetaPayload(uri, this.sthis, body);\n if (bodyRes.isErr()) {\n this.logger.Error().Err(bodyRes.Err()).Msg(\"Error in addCryptoKeyToGatewayMetaPayload\");\n throw bodyRes.Err();\n }\n body = bodyRes.Ok();\n }\n const rkey = uri.getParamResult(\"key\");\n if (rkey.isErr()) return Result.Err(rkey.Err());\n const key = rkey.Ok();\n if (store === \"meta\") {\n const uploadUrl = pkMetaURL(uri, key);\n return exception2Result(async () => {\n const response = await fetch(uploadUrl.asURL(), { method: \"PUT\", body: body });\n if (response.status === 404) {\n throw this.logger.Error().Url(uploadUrl).Msg(`Failure in uploading ${store}!`).AsError();\n }\n });\n } else {\n const uploadUrl = pkURL(uri, key, \"car\");\n return exception2Result(async () => {\n const response = await fetch(uploadUrl.asURL(), { method: \"PUT\" });\n this.logger\n .Debug()\n .Url(uploadUrl)\n .Uint64(\"status\", response.status)\n .Str(\"status-text\", response.statusText)\n .Msg(\"put\");\n if (response.status === 404) {\n throw this.logger.Error().Url(uploadUrl).Msg(`Failure in uploading ${store}!`).AsError();\n }\n const url = (await response.json()).url;\n this.logger.Debug().Url(url).Msg(\"put\");\n const uploadResponse = await fetch(url, { method: \"PUT\", body: body });\n if (uploadResponse.status === 404) {\n throw this.logger.Error().Url(uploadUrl).Msg(`Failure in uploading ${store}!`).AsError();\n }\n });\n }\n }\n\n private readonly subscriberCallbacks = new Set<(data: Uint8Array) => void>();\n\n private notifySubscribers(data: Uint8Array): void {\n for (const callback of this.subscriberCallbacks) {\n try {\n callback(data);\n } catch (error) {\n this.logger.Error().Err(error).Msg(\"Error in subscriber callback execution\");\n }\n }\n }\n async subscribe(uri: URI, callback: (meta: Uint8Array) => void): Promise<bs.UnsubscribeResult> {\n await this.ready();\n await this.connectFireproofCloud();\n\n const store = uri.getParam(\"store\");\n if (store !== \"meta\") {\n return Result.Err(new Error(\"store must be meta\"));\n }\n\n this.subscriberCallbacks.add(callback);\n\n return Result.Ok(() => {\n this.subscriberCallbacks.delete(callback);\n });\n }\n\n async get(uri: URI): Promise<bs.GetResult> {\n await this.ready();\n return exception2Result(async () => {\n const { store } = getStore(uri, this.sthis, (...args) => args.join(\"/\"));\n const key = uri.getParam(\"key\");\n if (!key) throw new Error(\"key not found\");\n let downloadUrl;\n this.logger.Debug().Str(\"store\", store).Str(\"key\", key).Msg(\"get\");\n switch (store) {\n case \"meta\":\n downloadUrl = pkMetaURL(uri, key);\n break;\n case \"data\":\n downloadUrl = pkCarGetURL(uri, key);\n break;\n default:\n throw new Error(`Unsupported store: ${store}`);\n }\n const response = await fetch(downloadUrl.toString(), { method: \"GET\" });\n if (response.status === 404) {\n throw new Error(`Failure in downloading ${store}!`);\n }\n const body = new Uint8Array(await response.arrayBuffer());\n if (store === \"meta\") {\n const resKeyInfo = await bs.setCryptoKeyFromGatewayMetaPayload(uri, this.sthis, body);\n if (resKeyInfo.isErr()) {\n this.logger\n .Error()\n .Url(uri)\n .Err(resKeyInfo)\n .Any(\"body\", body)\n .Msg(\"Error in setCryptoKeyFromGatewayMetaPayload\");\n throw resKeyInfo.Err();\n }\n }\n return body;\n });\n }\n\n async delete(_uri: URI): Promise<bs.VoidResult> {\n await this.ready();\n // FIXME had to add this method back to make the compiler happy jchris\n throw new Error(\"no delete for fireproof cloud\");\n }\n\n async destroy(uri: URI): Promise<Result<void>> {\n await this.ready();\n return exception2Result(async () => {\n const deleteUrl = pkBaseURL(uri);\n const response = await fetch(deleteUrl.asURL(), { method: \"DELETE\" });\n if (response.status === 404) {\n throw new Error(\"Failure in deleting data!\");\n }\n return Result.Ok(undefined);\n });\n }\n}\n\nconst pkSockets = new KeyedResolvOnce<PartySocket>();\n\nfunction pkKey(set?: PartySocketOptions): string {\n const ret = JSON.stringify(\n Object.entries(set || {})\n .sort(([a], [b]) => a.localeCompare(b))\n .filter(([k]) => k !== \"id\")\n .map(([k, v]) => ({ [k]: v }))\n );\n return ret;\n}\n// ws://localhost:1999/parties/fireproof/test-public-api?_pk=zp9BXhS6u\n// partykit://localhost:1999/?name=test-public-api&protocol=ws&store=meta\nfunction pkURL(uri: URI, key: string, type: \"car\" | \"meta\"): URI {\n const host = uri.host;\n const name = uri.getParam(\"name\");\n const idx = uri.getParam(\"index\") || \"\";\n const protocol = uri.getParam(\"protocol\") === \"ws\" ? \"http\" : \"https\";\n // TODO extract url from uri\n const path = `/parties/fireproof/${name}${idx}`;\n return BuildURI.from(`${protocol}://${host}${path}`).setParam(type, key).URI();\n}\n\nfunction pkBaseURL(uri: URI): URI {\n const host = uri.host;\n const name = uri.getParam(\"name\");\n const idx = uri.getParam(\"index\") || \"\";\n const protocol = uri.getParam(\"protocol\") === \"ws\" ? \"http\" : \"https\";\n // TODO extract url from uri\n const path = `/parties/fireproof/${name}${idx}`;\n return BuildURI.from(`${protocol}://${host}${path}`).URI();\n}\n\nfunction pkCarGetURL(uri: URI, key: string): URI {\n const baseUrl = uri.getParam(\"getBaseUrl\");\n if (!baseUrl) {\n return pkURL(uri, key, \"car\");\n }\n const name = uri.getParam(\"name\");\n const idx = uri.getParam(\"index\") || \"\";\n const baseUri = URI.from(baseUrl).asURL();\n baseUri.pathname = `/${name}${idx}/${key}`;\n // console.log(\"pkCarGetURL\", baseUri.toString());\n return BuildURI.from(baseUri).URI();\n}\n\nfunction pkMetaURL(uri: URI, key: string): URI {\n return pkURL(uri, key, \"meta\");\n}\n\nexport class FireproofCloudTestStore implements bs.TestGateway {\n readonly logger: Logger;\n readonly sthis: SuperThis;\n readonly gateway: bs.Gateway;\n constructor(gw: bs.Gateway, sthis: SuperThis) {\n this.sthis = sthis;\n this.logger = ensureLogger(sthis, \"FireproofCloudTestStore\");\n this.gateway = gw;\n }\n async get(uri: URI, key: string): Promise<Uint8Array> {\n const url = uri.build().setParam(\"key\", key).URI();\n const dbFile = this.sthis.pathOps.join(rt.getPath(url, this.sthis), rt.getFileName(url, this.sthis));\n this.logger.Debug().Url(url).Str(\"dbFile\", dbFile).Msg(\"get\");\n const buffer = await this.gateway.get(url);\n this.logger.Debug().Url(url).Str(\"dbFile\", dbFile).Len(buffer).Msg(\"got\");\n return buffer.Ok();\n }\n}\n\nconst onceRegisterFireproofCloudStoreProtocol = new KeyedResolvOnce<() => void>();\nexport function registerFireproofCloudStoreProtocol(protocol = \"fireproof:\", overrideBaseURL?: string) {\n return onceRegisterFireproofCloudStoreProtocol.get(protocol).once(() => {\n URI.protocolHasHostpart(protocol);\n return bs.registerStoreProtocol({\n protocol,\n overrideBaseURL,\n gateway: async (sthis) => {\n return new FireproofCloudGateway(sthis);\n },\n test: async (sthis: SuperThis) => {\n const gateway = new FireproofCloudGateway(sthis);\n return new FireproofCloudTestStore(gateway, sthis);\n },\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,iBAAqE;AACrE,IAAAC,eAAwC;;;ACDxC,oBAAoD;AACpD,kBAAsD;AAQ/C,IAAM,sBAAN,cAAkC,eAAG,eAAe;AAAA,EAUzD,YAAY,OAAkB,KAAU;AACtC,UAAM,aAAS,0BAAa,OAAO,uBAAuB;AAAA,MACxD,KAAK,MAAM,IAAI,SAAS;AAAA,MACxB,MAAM;AAAA,MACN,KAAK;AAAA,IACP,CAAC;AACD,UAAM,KAAK,MAAM;AAfnB,kBAGI;AAaF,SAAK,QAAQ;AAAA,EAGf;AAAA,EACA,MAAM,YAA2B;AAC/B,SAAK,OAAO,MAAM,EAAE,IAAI,iBAAiB;AACzC,UAAM,SAAS;AAAA,MACb,MAAM,KAAK;AAAA;AAAA;AAAA,IAGb;AACA,UAAM,QAAQ,KAAK,IAAI,eAAe,MAAM;AAC5C,QAAI,MAAM,MAAM,GAAG;AACjB,YAAM,KAAK,OAAO,MAAM,EAAE,IAAI,KAAK,EAAE,IAAI,mBAAmB,EAAE,QAAQ;AAAA,I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