@fireproof/core-gateways-base 0.22.0-keybag → 0.23.1-dev-issue-1057

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.
@@ -1,75 +0,0 @@
1
- import { URI, Promisable, Result } from "@adviser/cement";
2
- import { PassThroughGateway } from "./interceptor-gateway.js";
3
- import {
4
- FPEnvelope,
5
- FPEnvelopeMeta,
6
- SerdeGatewayBuildUrlReturn,
7
- SerdeGatewayCloseReturn,
8
- SerdeGatewayCtx,
9
- SerdeGatewayDeleteReturn,
10
- SerdeGatewayDestroyReturn,
11
- SerdeGatewayGetReturn,
12
- SerdeGatewayPutReturn,
13
- SerdeGatewayStartReturn,
14
- SerdeGatewaySubscribeReturn,
15
- } from "@fireproof/core-types-blockstore";
16
-
17
- export type URIMapper = (uri: URI) => Promisable<URI>;
18
-
19
- export class URIInterceptor extends PassThroughGateway {
20
- static withMapper(mapper: URIMapper): URIInterceptor {
21
- return new URIInterceptor().addMapper(mapper);
22
- }
23
-
24
- readonly #uriMapper = new Set<URIMapper>();
25
-
26
- addMapper(mapper: URIMapper): URIInterceptor {
27
- this.#uriMapper.add(mapper);
28
- return this;
29
- }
30
-
31
- async #map(uri: URI): Promise<URI> {
32
- let ret = uri;
33
- for (const mapper of this.#uriMapper) {
34
- ret = await mapper(ret);
35
- }
36
- return ret;
37
- }
38
-
39
- async buildUrl(ctx: SerdeGatewayCtx, url: URI, key: string): Promise<Result<SerdeGatewayBuildUrlReturn>> {
40
- const ret = await super.buildUrl(ctx, await this.#map(url), key);
41
- return ret;
42
- }
43
- async start(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayStartReturn>> {
44
- const ret = await super.start(ctx, await this.#map(url));
45
- return ret;
46
- }
47
- async close(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayCloseReturn>> {
48
- const ret = await super.close(ctx, await this.#map(url));
49
- return ret;
50
- }
51
- async delete(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayDeleteReturn>> {
52
- const ret = await super.delete(ctx, await this.#map(url));
53
- return ret;
54
- }
55
- async destroy(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayDestroyReturn>> {
56
- const ret = await super.destroy(ctx, await this.#map(url));
57
- return ret;
58
- }
59
- async put<T>(ctx: SerdeGatewayCtx, url: URI, body: FPEnvelope<T>): Promise<Result<SerdeGatewayPutReturn<T>>> {
60
- const ret = await super.put<T>(ctx, await this.#map(url), body);
61
- return ret;
62
- }
63
- async get<S>(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayGetReturn<S>>> {
64
- const ret = await super.get<S>(ctx, await this.#map(url));
65
- return ret;
66
- }
67
- async subscribe(
68
- ctx: SerdeGatewayCtx,
69
- url: URI,
70
- callback: (meta: FPEnvelopeMeta) => Promise<void>,
71
- ): Promise<Result<SerdeGatewaySubscribeReturn>> {
72
- const ret = await super.subscribe(ctx, await this.#map(url), callback);
73
- return ret;
74
- }
75
- }
package/utils.ts DELETED
@@ -1,42 +0,0 @@
1
- import type { URI } from "@adviser/cement";
2
- import { SuperThis } from "@fireproof/core-types-base";
3
- import { getStore } from "@fireproof/core-runtime";
4
-
5
- export function getPath(url: URI, sthis: SuperThis): string {
6
- const basePath = url.pathname;
7
- // .toString()
8
- // .replace(new RegExp(`^${url.protocol}//`), "")
9
- // .replace(/\?.*$/, "");
10
- const name = url.getParam("name");
11
- if (name) {
12
- // const urlGen = url.getParam(PARAM.URL_GEN);
13
- // switch (urlGen) {
14
- // case "default":
15
- // case "fromEnv":
16
- // default:
17
- // break;
18
- // }
19
-
20
- // const version = url.getParam("version");
21
- // if (!version) throw sthis.logger.Error().Url(url).Msg(`version not found`).AsError();
22
- return sthis.pathOps.join(basePath, name);
23
- }
24
- return sthis.pathOps.join(basePath);
25
- }
26
-
27
- export function getFileName(url: URI, sthis: SuperThis): string {
28
- const key = url.getParam("key");
29
- if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
30
- const res = getStore(url, sthis, (...a: string[]) => a.join("-"));
31
- switch (res.fromUrl) {
32
- case "file":
33
- return sthis.pathOps.join(res.name, key);
34
- case "car":
35
- return sthis.pathOps.join(res.name, key + ".car");
36
- case "wal":
37
- case "meta":
38
- return sthis.pathOps.join(res.name, key + ".json");
39
- default:
40
- throw sthis.logger.Error().Url(url).Msg(`unsupported store type`).AsError();
41
- }
42
- }