@fireproof/core-gateways-base 0.0.0-smoke-1b31059-1752074105
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.
- package/LICENSE.md +232 -0
- package/def-serde-gateway.d.ts +15 -0
- package/def-serde-gateway.js +93 -0
- package/def-serde-gateway.js.map +1 -0
- package/def-serde-gateway.ts +138 -0
- package/fp-envelope-serialize.d.ts +8 -0
- package/fp-envelope-serialize.js +141 -0
- package/fp-envelope-serialize.js.map +1 -0
- package/fp-envelope-serialize.ts +208 -0
- package/index.d.ts +7 -0
- package/index.js +8 -0
- package/index.js.map +1 -0
- package/index.ts +7 -0
- package/indexeddb-version.d.ts +1 -0
- package/indexeddb-version.js +2 -0
- package/indexeddb-version.js.map +1 -0
- package/indexeddb-version.ts +1 -0
- package/interceptor-gateway.d.ts +27 -0
- package/interceptor-gateway.js +139 -0
- package/interceptor-gateway.js.map +1 -0
- package/interceptor-gateway.ts +174 -0
- package/meta-key-hack.d.ts +33 -0
- package/meta-key-hack.js +203 -0
- package/meta-key-hack.js.map +1 -0
- package/meta-key-hack.ts +260 -0
- package/package.json +45 -0
- package/tsconfig.json +18 -0
- package/uri-interceptor.d.ts +17 -0
- package/uri-interceptor.js +51 -0
- package/uri-interceptor.js.map +1 -0
- package/uri-interceptor.ts +75 -0
- package/utils.d.ts +4 -0
- package/utils.js +27 -0
- package/utils.js.map +1 -0
- package/utils.ts +42 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { exception2Result, Result, URI } from "@adviser/cement";
|
|
2
|
+
import type {
|
|
3
|
+
CarClockLink,
|
|
4
|
+
DbMeta,
|
|
5
|
+
DbMetaBinary,
|
|
6
|
+
DbMetaEvent,
|
|
7
|
+
FPDecoder,
|
|
8
|
+
FPEncoder,
|
|
9
|
+
LinkOrCid,
|
|
10
|
+
SerializedMeta,
|
|
11
|
+
SerializedWAL,
|
|
12
|
+
WALState,
|
|
13
|
+
} from "@fireproof/core-types-blockstore";
|
|
14
|
+
import {
|
|
15
|
+
FPEnvelope,
|
|
16
|
+
FPEnvelopeCar,
|
|
17
|
+
FPEnvelopeFile,
|
|
18
|
+
FPEnvelopeMeta,
|
|
19
|
+
FPEnvelopeType,
|
|
20
|
+
FPEnvelopeTypes,
|
|
21
|
+
FPEnvelopeWAL,
|
|
22
|
+
} from "@fireproof/core-types-blockstore";
|
|
23
|
+
import { PARAM, PromiseToUInt8, SuperThis } from "@fireproof/core-types-base";
|
|
24
|
+
import { decodeEventBlock, EventBlock } from "@web3-storage/pail/clock";
|
|
25
|
+
import { base64pad } from "multiformats/bases/base64";
|
|
26
|
+
import { CID, Link } from "multiformats";
|
|
27
|
+
import { fromJSON } from "multiformats/link";
|
|
28
|
+
import { format, parse } from "@ipld/dag-json";
|
|
29
|
+
import { EventView } from "@web3-storage/pail/clock/api";
|
|
30
|
+
import { coercePromiseIntoUint8 } from "@fireproof/core-runtime";
|
|
31
|
+
|
|
32
|
+
export async function dbMetaEvent2Serialized(
|
|
33
|
+
sthis: SuperThis,
|
|
34
|
+
dbEvents: Omit<DbMetaEvent, "eventCid">[],
|
|
35
|
+
): Promise<SerializedMeta[]> {
|
|
36
|
+
return await Promise.all(
|
|
37
|
+
dbEvents.map(async (dbEvent) => {
|
|
38
|
+
const event = await EventBlock.create<DbMetaBinary>(
|
|
39
|
+
{
|
|
40
|
+
dbMeta: sthis.txt.encode(format(dbEvent.dbMeta)),
|
|
41
|
+
},
|
|
42
|
+
dbEvent.parents as unknown as Link<EventView<DbMetaBinary>, number, number, 1>[],
|
|
43
|
+
);
|
|
44
|
+
return {
|
|
45
|
+
cid: event.cid.toString(),
|
|
46
|
+
parents: dbEvent.parents.map((i) => i.toString()),
|
|
47
|
+
data: base64pad.encode(event.bytes),
|
|
48
|
+
} satisfies SerializedMeta;
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function WALState2Serialized(sthis: SuperThis, wal: WALState): SerializedWAL {
|
|
54
|
+
const serializedWAL: SerializedWAL = {
|
|
55
|
+
fileOperations: wal.fileOperations.map((fop) => ({
|
|
56
|
+
cid: fop.cid.toString(),
|
|
57
|
+
public: fop.public,
|
|
58
|
+
})),
|
|
59
|
+
noLoaderOps: wal.noLoaderOps.map((nop) => ({
|
|
60
|
+
cars: nop.cars.map((i) => i.toString()),
|
|
61
|
+
})),
|
|
62
|
+
operations: wal.operations.map((op) => ({
|
|
63
|
+
cars: op.cars.map((i) => i.toString()),
|
|
64
|
+
})),
|
|
65
|
+
};
|
|
66
|
+
return serializedWAL;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const defaultEncoder: FPEncoder = {
|
|
70
|
+
car: async (sthis: SuperThis, payload: Uint8Array) => Result.Ok(payload),
|
|
71
|
+
file: async (sthis: SuperThis, payload: Uint8Array) => Result.Ok(payload),
|
|
72
|
+
meta: async (sthis: SuperThis, payload: SerializedMeta[]) => Result.Ok(sthis.txt.encode(JSON.stringify(payload))),
|
|
73
|
+
wal: async (sthis: SuperThis, payload: SerializedWAL) => Result.Ok(sthis.txt.encode(JSON.stringify(payload))),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export async function fpSerialize<T>(
|
|
77
|
+
sthis: SuperThis,
|
|
78
|
+
env: FPEnvelope<T>,
|
|
79
|
+
pencoder?: Partial<FPEncoder>,
|
|
80
|
+
): Promise<Result<Uint8Array>> {
|
|
81
|
+
const encoder = {
|
|
82
|
+
...defaultEncoder,
|
|
83
|
+
...pencoder,
|
|
84
|
+
};
|
|
85
|
+
switch (env.type) {
|
|
86
|
+
case FPEnvelopeTypes.FILE:
|
|
87
|
+
return encoder.file(sthis, (env as FPEnvelopeFile).payload);
|
|
88
|
+
case FPEnvelopeTypes.CAR:
|
|
89
|
+
return encoder.car(sthis, (env as FPEnvelopeCar).payload);
|
|
90
|
+
case FPEnvelopeTypes.WAL:
|
|
91
|
+
return encoder.wal(sthis, WALState2Serialized(sthis, (env as FPEnvelopeWAL).payload));
|
|
92
|
+
case FPEnvelopeTypes.META:
|
|
93
|
+
return encoder.meta(sthis, await dbMetaEvent2Serialized(sthis, (env as FPEnvelopeMeta).payload));
|
|
94
|
+
default:
|
|
95
|
+
throw sthis.logger.Error().Str("type", env.type).Msg("unsupported store").AsError();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function decode2DbMetaEvents(
|
|
100
|
+
sthis: SuperThis,
|
|
101
|
+
rserializedMeta: Result<SerializedMeta[]>,
|
|
102
|
+
): Promise<Result<DbMetaEvent[]>> {
|
|
103
|
+
if (rserializedMeta.isErr()) {
|
|
104
|
+
return Result.Err(rserializedMeta.Err());
|
|
105
|
+
}
|
|
106
|
+
const serializedMeta = rserializedMeta.unwrap();
|
|
107
|
+
if (!Array.isArray(serializedMeta)) {
|
|
108
|
+
return sthis.logger.Debug().Any("metaEntries", serializedMeta).Msg("No data in MetaEntries").ResultError();
|
|
109
|
+
}
|
|
110
|
+
// if (!serializedMeta.length) {
|
|
111
|
+
// return sthis.logger.Debug().Msg("No MetaEntries found").ResultError();
|
|
112
|
+
// }
|
|
113
|
+
return Result.Ok(
|
|
114
|
+
await Promise.all(
|
|
115
|
+
serializedMeta.map(async (metaEntry) => {
|
|
116
|
+
const eventBlock = await decodeEventBlock<DbMetaBinary>(base64pad.decode(metaEntry.data));
|
|
117
|
+
const dbMeta = parse<DbMeta>(sthis.txt.decode(eventBlock.value.data.dbMeta));
|
|
118
|
+
return {
|
|
119
|
+
eventCid: eventBlock.cid as CarClockLink,
|
|
120
|
+
parents: metaEntry.parents.map((i: string) => CID.parse(i)),
|
|
121
|
+
dbMeta,
|
|
122
|
+
} satisfies DbMetaEvent;
|
|
123
|
+
}),
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function toCid(sthis: SuperThis, link: LinkOrCid): CID {
|
|
129
|
+
if (typeof link === "string") {
|
|
130
|
+
return CID.parse(link);
|
|
131
|
+
}
|
|
132
|
+
return fromJSON(link);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function decode2WalState(sthis: SuperThis, rserializedWAL: Result<SerializedWAL>): Promise<Result<WALState>> {
|
|
136
|
+
if (rserializedWAL.isErr()) {
|
|
137
|
+
return Result.Err(rserializedWAL.Err());
|
|
138
|
+
}
|
|
139
|
+
const serializedWAL = rserializedWAL.unwrap();
|
|
140
|
+
return Result.Ok({
|
|
141
|
+
fileOperations: (serializedWAL.fileOperations || []).map((fop) => ({
|
|
142
|
+
cid: toCid(sthis, fop.cid),
|
|
143
|
+
public: fop.public,
|
|
144
|
+
})),
|
|
145
|
+
noLoaderOps: (serializedWAL.noLoaderOps || []).map((nop) => ({
|
|
146
|
+
cars: (nop.cars || []).map((i) => toCid(sthis, i)),
|
|
147
|
+
})),
|
|
148
|
+
operations: (serializedWAL.operations || []).map((op) => ({
|
|
149
|
+
cars: (op.cars || []).map((i) => toCid(sthis, i)),
|
|
150
|
+
})),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// export type CARDecodeEnvelopeBase = (sthis: SuperThis, payload: Uint8Array) => Promise<Result<Uint8Array>>;
|
|
154
|
+
// export type FILEDecodeEnvelopeBase = (sthis: SuperThis, payload: Uint8Array) => Promise<Result<Uint8Array>>;
|
|
155
|
+
// export type WALDecodeEnvelopeBase = (sthis: SuperThis, payload: SerializedWAL) => Promise<Result<SerializedWAL>>;
|
|
156
|
+
// export type METADecodeEnvelopeBase = (sthis: SuperThis, payload: SerializedMeta[]) => Promise<Result<SerializedMeta[]>>;
|
|
157
|
+
|
|
158
|
+
const defaultDecoder = {
|
|
159
|
+
car: async (sthis: SuperThis, payload: Uint8Array) => Result.Ok(payload),
|
|
160
|
+
file: async (sthis: SuperThis, payload: Uint8Array) => Result.Ok(payload),
|
|
161
|
+
meta: async (sthis: SuperThis, payload: Uint8Array) =>
|
|
162
|
+
exception2Result(() => JSON.parse(sthis.txt.decode(payload)) as SerializedMeta[]),
|
|
163
|
+
wal: async (sthis: SuperThis, payload: Uint8Array) =>
|
|
164
|
+
exception2Result(() => JSON.parse(sthis.txt.decode(payload)) as SerializedWAL),
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
function makeFPEnvelope<S>(type: FPEnvelopeType, payload: Result<S>): Result<FPEnvelope<S>> {
|
|
168
|
+
if (payload.isErr()) {
|
|
169
|
+
return Result.Err(payload.Err());
|
|
170
|
+
}
|
|
171
|
+
return Result.Ok({
|
|
172
|
+
type,
|
|
173
|
+
payload: payload.unwrap(),
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function fpDeserialize<S>(
|
|
178
|
+
sthis: SuperThis,
|
|
179
|
+
url: URI,
|
|
180
|
+
intoRaw: PromiseToUInt8,
|
|
181
|
+
pdecoder?: Partial<FPDecoder>,
|
|
182
|
+
): Promise<Result<FPEnvelope<S>>> {
|
|
183
|
+
const rraw = await coercePromiseIntoUint8(intoRaw);
|
|
184
|
+
if (rraw.isErr()) {
|
|
185
|
+
return Result.Err(rraw.Err());
|
|
186
|
+
}
|
|
187
|
+
const raw = rraw.unwrap();
|
|
188
|
+
const decoder = {
|
|
189
|
+
...defaultDecoder,
|
|
190
|
+
...pdecoder,
|
|
191
|
+
};
|
|
192
|
+
switch (url.getParam(PARAM.STORE)) {
|
|
193
|
+
case "car":
|
|
194
|
+
return makeFPEnvelope(FPEnvelopeTypes.CAR, await decoder.car(sthis, raw)) as Result<FPEnvelope<S>>;
|
|
195
|
+
case "file":
|
|
196
|
+
return makeFPEnvelope(FPEnvelopeTypes.FILE, await decoder.file(sthis, raw)) as Result<FPEnvelope<S>>;
|
|
197
|
+
case "wal":
|
|
198
|
+
return makeFPEnvelope(FPEnvelopeTypes.WAL, await decode2WalState(sthis, await decoder.wal(sthis, raw))) as Result<
|
|
199
|
+
FPEnvelope<S>
|
|
200
|
+
>;
|
|
201
|
+
case "meta":
|
|
202
|
+
return makeFPEnvelope(FPEnvelopeTypes.META, await decode2DbMetaEvents(sthis, await decoder.meta(sthis, raw))) as Result<
|
|
203
|
+
FPEnvelope<S>
|
|
204
|
+
>;
|
|
205
|
+
default:
|
|
206
|
+
return sthis.logger.Error().Str("store", url.getParam(PARAM.STORE)).Msg("unsupported store").ResultError();
|
|
207
|
+
}
|
|
208
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./fp-envelope-serialize.js";
|
|
2
|
+
export * from "./def-serde-gateway.js";
|
|
3
|
+
export * from "./interceptor-gateway.js";
|
|
4
|
+
export * from "./uri-interceptor.js";
|
|
5
|
+
export * from "./utils.js";
|
|
6
|
+
export * from "./indexeddb-version.js";
|
|
7
|
+
export * from "./meta-key-hack.js";
|
package/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./fp-envelope-serialize.js";
|
|
2
|
+
export * from "./def-serde-gateway.js";
|
|
3
|
+
export * from "./interceptor-gateway.js";
|
|
4
|
+
export * from "./uri-interceptor.js";
|
|
5
|
+
export * from "./utils.js";
|
|
6
|
+
export * from "./indexeddb-version.js";
|
|
7
|
+
export * from "./meta-key-hack.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC"}
|
package/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./fp-envelope-serialize.js";
|
|
2
|
+
export * from "./def-serde-gateway.js";
|
|
3
|
+
export * from "./interceptor-gateway.js";
|
|
4
|
+
export * from "./uri-interceptor.js";
|
|
5
|
+
export * from "./utils.js";
|
|
6
|
+
export * from "./indexeddb-version.js";
|
|
7
|
+
export * from "./meta-key-hack.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const INDEXEDDB_VERSION = "v0.19-indexeddb";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexeddb-version.js","sourceRoot":"","sources":["indexeddb-version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const INDEXEDDB_VERSION = "v0.19-indexeddb";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Result, URI } from "@adviser/cement";
|
|
2
|
+
import type { FPEnvelope, FPEnvelopeMeta, SerdeGateway, SerdeGatewayBuildUrlReturn, SerdeGatewayCloseReturn, SerdeGatewayCtx, SerdeGatewayDeleteReturn, SerdeGatewayDestroyReturn, SerdeGatewayGetReturn, SerdeGatewayInterceptor, SerdeGatewayPutReturn, SerdeGatewayStartReturn, SerdeGatewaySubscribeReturn, SerdeGetResult, UnsubscribeResult, VoidResult } from "@fireproof/core-types-blockstore";
|
|
3
|
+
import type { SuperThis } from "@fireproof/core-types-base";
|
|
4
|
+
export declare class PassThroughGateway implements SerdeGatewayInterceptor {
|
|
5
|
+
buildUrl(ctx: SerdeGatewayCtx, url: URI, key: string): Promise<Result<SerdeGatewayBuildUrlReturn>>;
|
|
6
|
+
start(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayStartReturn>>;
|
|
7
|
+
close(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayCloseReturn>>;
|
|
8
|
+
delete(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayDeleteReturn>>;
|
|
9
|
+
destroy(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayDestroyReturn>>;
|
|
10
|
+
put<T>(ctx: SerdeGatewayCtx, url: URI, body: FPEnvelope<T>): Promise<Result<SerdeGatewayPutReturn<T>>>;
|
|
11
|
+
get<S>(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayGetReturn<S>>>;
|
|
12
|
+
subscribe(ctx: SerdeGatewayCtx, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>): Promise<Result<SerdeGatewaySubscribeReturn>>;
|
|
13
|
+
}
|
|
14
|
+
export declare class InterceptorGateway implements SerdeGateway {
|
|
15
|
+
readonly innerGW: SerdeGateway;
|
|
16
|
+
readonly interceptor: SerdeGatewayInterceptor;
|
|
17
|
+
constructor(sthis: SuperThis, innerGW: SerdeGateway, interceptor: SerdeGatewayInterceptor | undefined);
|
|
18
|
+
buildUrl(ctx: SerdeGatewayCtx, baseUrl: URI, key: string): Promise<Result<URI>>;
|
|
19
|
+
destroy(ctx: SerdeGatewayCtx, iurl: URI): Promise<Result<void>>;
|
|
20
|
+
start(ctx: SerdeGatewayCtx, url: URI): Promise<Result<URI>>;
|
|
21
|
+
close(ctx: SerdeGatewayCtx, url: URI): Promise<VoidResult>;
|
|
22
|
+
put<T>(ctx: SerdeGatewayCtx, url: URI, fpEnv: FPEnvelope<T>): Promise<VoidResult>;
|
|
23
|
+
get<S>(ctx: SerdeGatewayCtx, url: URI): Promise<SerdeGetResult<S>>;
|
|
24
|
+
subscribe(ctx: SerdeGatewayCtx, url: URI, callback: (msg: FPEnvelopeMeta) => Promise<void>): Promise<UnsubscribeResult>;
|
|
25
|
+
delete(ctx: SerdeGatewayCtx, url: URI): Promise<VoidResult>;
|
|
26
|
+
getPlain(ctx: SerdeGatewayCtx, url: URI, key: string): Promise<Result<Uint8Array>>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Result } from "@adviser/cement";
|
|
2
|
+
export class PassThroughGateway {
|
|
3
|
+
async buildUrl(ctx, url, key) {
|
|
4
|
+
const op = { url, key };
|
|
5
|
+
return Result.Ok({ op });
|
|
6
|
+
}
|
|
7
|
+
async start(ctx, url) {
|
|
8
|
+
const op = { url };
|
|
9
|
+
return Result.Ok({ op });
|
|
10
|
+
}
|
|
11
|
+
async close(ctx, url) {
|
|
12
|
+
const op = { url };
|
|
13
|
+
return Result.Ok({ op });
|
|
14
|
+
}
|
|
15
|
+
async delete(ctx, url) {
|
|
16
|
+
const op = { url };
|
|
17
|
+
return Result.Ok({ op });
|
|
18
|
+
}
|
|
19
|
+
async destroy(ctx, url) {
|
|
20
|
+
const op = { url };
|
|
21
|
+
return Result.Ok({ op });
|
|
22
|
+
}
|
|
23
|
+
async put(ctx, url, body) {
|
|
24
|
+
const op = { url, body };
|
|
25
|
+
return Result.Ok({ op });
|
|
26
|
+
}
|
|
27
|
+
async get(ctx, url) {
|
|
28
|
+
const op = { url };
|
|
29
|
+
return Result.Ok({ op });
|
|
30
|
+
}
|
|
31
|
+
async subscribe(ctx, url, callback) {
|
|
32
|
+
const op = { url, callback };
|
|
33
|
+
return Result.Ok({ op });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const passThrougthGateway = new PassThroughGateway();
|
|
37
|
+
export class InterceptorGateway {
|
|
38
|
+
innerGW;
|
|
39
|
+
interceptor;
|
|
40
|
+
constructor(sthis, innerGW, interceptor) {
|
|
41
|
+
this.innerGW = innerGW;
|
|
42
|
+
this.interceptor = interceptor || passThrougthGateway;
|
|
43
|
+
}
|
|
44
|
+
async buildUrl(ctx, baseUrl, key) {
|
|
45
|
+
const rret = await this.interceptor.buildUrl(ctx, baseUrl, key);
|
|
46
|
+
if (rret.isErr()) {
|
|
47
|
+
return Result.Err(rret.Err());
|
|
48
|
+
}
|
|
49
|
+
const ret = rret.unwrap();
|
|
50
|
+
if (ret.stop && ret.value) {
|
|
51
|
+
return ret.value;
|
|
52
|
+
}
|
|
53
|
+
return this.innerGW.buildUrl(ctx, ret.op.url, ret.op.key);
|
|
54
|
+
}
|
|
55
|
+
async destroy(ctx, iurl) {
|
|
56
|
+
const rret = await this.interceptor.destroy(ctx, iurl);
|
|
57
|
+
if (rret.isErr()) {
|
|
58
|
+
return Result.Err(rret.Err());
|
|
59
|
+
}
|
|
60
|
+
const ret = rret.unwrap();
|
|
61
|
+
if (ret.stop && ret.value) {
|
|
62
|
+
return ret.value;
|
|
63
|
+
}
|
|
64
|
+
return this.innerGW.destroy(ctx, ret.op.url);
|
|
65
|
+
}
|
|
66
|
+
async start(ctx, url) {
|
|
67
|
+
const rret = await this.interceptor.start(ctx, url);
|
|
68
|
+
if (rret.isErr()) {
|
|
69
|
+
return Result.Err(rret.Err());
|
|
70
|
+
}
|
|
71
|
+
const ret = rret.unwrap();
|
|
72
|
+
if (ret.stop && ret.value) {
|
|
73
|
+
return ret.value;
|
|
74
|
+
}
|
|
75
|
+
return await this.innerGW.start(ctx, ret.op.url);
|
|
76
|
+
}
|
|
77
|
+
async close(ctx, url) {
|
|
78
|
+
const rret = await this.interceptor.close(ctx, url);
|
|
79
|
+
if (rret.isErr()) {
|
|
80
|
+
return Result.Err(rret.Err());
|
|
81
|
+
}
|
|
82
|
+
const ret = rret.unwrap();
|
|
83
|
+
if (ret.stop && ret.value) {
|
|
84
|
+
return ret.value;
|
|
85
|
+
}
|
|
86
|
+
return await this.innerGW.close(ctx, ret.op.url);
|
|
87
|
+
}
|
|
88
|
+
async put(ctx, url, fpEnv) {
|
|
89
|
+
const rret = await this.interceptor.put(ctx, url, fpEnv);
|
|
90
|
+
if (rret.isErr()) {
|
|
91
|
+
return Result.Err(rret.Err());
|
|
92
|
+
}
|
|
93
|
+
const ret = rret.unwrap();
|
|
94
|
+
if (ret.stop && ret.value) {
|
|
95
|
+
return ret.value;
|
|
96
|
+
}
|
|
97
|
+
return this.innerGW.put(ctx, ret.op.url, ret.op.body);
|
|
98
|
+
}
|
|
99
|
+
async get(ctx, url) {
|
|
100
|
+
const rret = await this.interceptor.get(ctx, url);
|
|
101
|
+
if (rret.isErr()) {
|
|
102
|
+
return Result.Err(rret.Err());
|
|
103
|
+
}
|
|
104
|
+
const ret = rret.unwrap();
|
|
105
|
+
if (ret.stop && ret.value) {
|
|
106
|
+
return ret.value;
|
|
107
|
+
}
|
|
108
|
+
return this.innerGW.get(ctx, ret.op.url);
|
|
109
|
+
}
|
|
110
|
+
async subscribe(ctx, url, callback) {
|
|
111
|
+
if (!this.innerGW.subscribe) {
|
|
112
|
+
return Result.Err(ctx.loader.sthis.logger.Error().Url(url).Msg("subscribe not supported").AsError());
|
|
113
|
+
}
|
|
114
|
+
const rret = await this.interceptor.subscribe(ctx, url, callback);
|
|
115
|
+
if (rret.isErr()) {
|
|
116
|
+
return Result.Err(rret.Err());
|
|
117
|
+
}
|
|
118
|
+
const ret = rret.unwrap();
|
|
119
|
+
if (ret.stop && ret.value) {
|
|
120
|
+
return ret.value;
|
|
121
|
+
}
|
|
122
|
+
return this.innerGW.subscribe(ctx, ret.op.url, ret.op.callback);
|
|
123
|
+
}
|
|
124
|
+
async delete(ctx, url) {
|
|
125
|
+
const rret = await this.interceptor.delete(ctx, url);
|
|
126
|
+
if (rret.isErr()) {
|
|
127
|
+
return Result.Err(rret.Err());
|
|
128
|
+
}
|
|
129
|
+
const ret = rret.unwrap();
|
|
130
|
+
if (ret.stop && ret.value) {
|
|
131
|
+
return ret.value;
|
|
132
|
+
}
|
|
133
|
+
return this.innerGW.delete(ctx, url);
|
|
134
|
+
}
|
|
135
|
+
async getPlain(ctx, url, key) {
|
|
136
|
+
return this.innerGW.getPlain(ctx, url, key);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=interceptor-gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor-gateway.js","sourceRoot":"","sources":["interceptor-gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAO,MAAM,iBAAiB,CAAC;AAqB9C,MAAM,OAAO,kBAAkB;IAC7B,KAAK,CAAC,QAAQ,CAAC,GAAoB,EAAE,GAAQ,EAAE,GAAW;QACxD,MAAM,EAAE,GAAG,EA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,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACrD,IAAI,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YACjB,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAChC,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1B,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;YAC1B,OAAO,GAAG,CAAC,KAAK,CAAC;QACnB,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,GAAoB,EAAE,GAAQ,EAAE,GAAW;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Result, URI } from "@adviser/cement";
|
|
2
|
+
import type {
|
|
3
|
+
FPEnvelope,
|
|
4
|
+
FPEnvelopeMeta,
|
|
5
|
+
SerdeGateway,
|
|
6
|
+
SerdeGatewayBuildUrlReturn,
|
|
7
|
+
SerdeGatewayCloseReturn,
|
|
8
|
+
SerdeGatewayCtx,
|
|
9
|
+
SerdeGatewayDeleteReturn,
|
|
10
|
+
SerdeGatewayDestroyReturn,
|
|
11
|
+
SerdeGatewayGetReturn,
|
|
12
|
+
SerdeGatewayInterceptor,
|
|
13
|
+
SerdeGatewayPutReturn,
|
|
14
|
+
SerdeGatewayStartReturn,
|
|
15
|
+
SerdeGatewaySubscribeReturn,
|
|
16
|
+
SerdeGetResult,
|
|
17
|
+
UnsubscribeResult,
|
|
18
|
+
VoidResult,
|
|
19
|
+
} from "@fireproof/core-types-blockstore";
|
|
20
|
+
import type { SuperThis } from "@fireproof/core-types-base";
|
|
21
|
+
|
|
22
|
+
export class PassThroughGateway implements SerdeGatewayInterceptor {
|
|
23
|
+
async buildUrl(ctx: SerdeGatewayCtx, url: URI, key: string): Promise<Result<SerdeGatewayBuildUrlReturn>> {
|
|
24
|
+
const op = { url, key };
|
|
25
|
+
return Result.Ok({ op });
|
|
26
|
+
}
|
|
27
|
+
async start(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayStartReturn>> {
|
|
28
|
+
const op = { url };
|
|
29
|
+
return Result.Ok({ op });
|
|
30
|
+
}
|
|
31
|
+
async close(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayCloseReturn>> {
|
|
32
|
+
const op = { url };
|
|
33
|
+
return Result.Ok({ op });
|
|
34
|
+
}
|
|
35
|
+
async delete(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayDeleteReturn>> {
|
|
36
|
+
const op = { url };
|
|
37
|
+
return Result.Ok({ op });
|
|
38
|
+
}
|
|
39
|
+
async destroy(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayDestroyReturn>> {
|
|
40
|
+
const op = { url };
|
|
41
|
+
return Result.Ok({ op });
|
|
42
|
+
}
|
|
43
|
+
async put<T>(ctx: SerdeGatewayCtx, url: URI, body: FPEnvelope<T>): Promise<Result<SerdeGatewayPutReturn<T>>> {
|
|
44
|
+
const op = { url, body };
|
|
45
|
+
return Result.Ok({ op });
|
|
46
|
+
}
|
|
47
|
+
async get<S>(ctx: SerdeGatewayCtx, url: URI): Promise<Result<SerdeGatewayGetReturn<S>>> {
|
|
48
|
+
const op = { url };
|
|
49
|
+
return Result.Ok({ op });
|
|
50
|
+
}
|
|
51
|
+
async subscribe(
|
|
52
|
+
ctx: SerdeGatewayCtx,
|
|
53
|
+
url: URI,
|
|
54
|
+
callback: (meta: FPEnvelopeMeta) => Promise<void>,
|
|
55
|
+
): Promise<Result<SerdeGatewaySubscribeReturn>> {
|
|
56
|
+
const op = { url, callback };
|
|
57
|
+
return Result.Ok({ op });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const passThrougthGateway = new PassThroughGateway();
|
|
62
|
+
|
|
63
|
+
export class InterceptorGateway implements SerdeGateway {
|
|
64
|
+
readonly innerGW: SerdeGateway;
|
|
65
|
+
readonly interceptor: SerdeGatewayInterceptor;
|
|
66
|
+
|
|
67
|
+
constructor(sthis: SuperThis, innerGW: SerdeGateway, interceptor: SerdeGatewayInterceptor | undefined) {
|
|
68
|
+
this.innerGW = innerGW;
|
|
69
|
+
this.interceptor = interceptor || passThrougthGateway;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async buildUrl(ctx: SerdeGatewayCtx, baseUrl: URI, key: string): Promise<Result<URI>> {
|
|
73
|
+
const rret = await this.interceptor.buildUrl(ctx, baseUrl, key);
|
|
74
|
+
if (rret.isErr()) {
|
|
75
|
+
return Result.Err(rret.Err());
|
|
76
|
+
}
|
|
77
|
+
const ret = rret.unwrap();
|
|
78
|
+
if (ret.stop && ret.value) {
|
|
79
|
+
return ret.value;
|
|
80
|
+
}
|
|
81
|
+
return this.innerGW.buildUrl(ctx, ret.op.url, ret.op.key);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async destroy(ctx: SerdeGatewayCtx, iurl: URI): Promise<Result<void>> {
|
|
85
|
+
const rret = await this.interceptor.destroy(ctx, iurl);
|
|
86
|
+
if (rret.isErr()) {
|
|
87
|
+
return Result.Err(rret.Err());
|
|
88
|
+
}
|
|
89
|
+
const ret = rret.unwrap();
|
|
90
|
+
if (ret.stop && ret.value) {
|
|
91
|
+
return ret.value;
|
|
92
|
+
}
|
|
93
|
+
return this.innerGW.destroy(ctx, ret.op.url);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async start(ctx: SerdeGatewayCtx, url: URI): Promise<Result<URI>> {
|
|
97
|
+
const rret = await this.interceptor.start(ctx, url);
|
|
98
|
+
if (rret.isErr()) {
|
|
99
|
+
return Result.Err(rret.Err());
|
|
100
|
+
}
|
|
101
|
+
const ret = rret.unwrap();
|
|
102
|
+
if (ret.stop && ret.value) {
|
|
103
|
+
return ret.value;
|
|
104
|
+
}
|
|
105
|
+
return await this.innerGW.start(ctx, ret.op.url);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async close(ctx: SerdeGatewayCtx, url: URI): Promise<VoidResult> {
|
|
109
|
+
const rret = await this.interceptor.close(ctx, url);
|
|
110
|
+
if (rret.isErr()) {
|
|
111
|
+
return Result.Err(rret.Err());
|
|
112
|
+
}
|
|
113
|
+
const ret = rret.unwrap();
|
|
114
|
+
if (ret.stop && ret.value) {
|
|
115
|
+
return ret.value;
|
|
116
|
+
}
|
|
117
|
+
return await this.innerGW.close(ctx, ret.op.url);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async put<T>(ctx: SerdeGatewayCtx, url: URI, fpEnv: FPEnvelope<T>): Promise<VoidResult> {
|
|
121
|
+
const rret = await this.interceptor.put(ctx, url, fpEnv);
|
|
122
|
+
if (rret.isErr()) {
|
|
123
|
+
return Result.Err(rret.Err());
|
|
124
|
+
}
|
|
125
|
+
const ret = rret.unwrap();
|
|
126
|
+
if (ret.stop && ret.value) {
|
|
127
|
+
return ret.value;
|
|
128
|
+
}
|
|
129
|
+
return this.innerGW.put(ctx, ret.op.url, ret.op.body);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async get<S>(ctx: SerdeGatewayCtx, url: URI): Promise<SerdeGetResult<S>> {
|
|
133
|
+
const rret = await this.interceptor.get<S>(ctx, url);
|
|
134
|
+
if (rret.isErr()) {
|
|
135
|
+
return Result.Err(rret.Err());
|
|
136
|
+
}
|
|
137
|
+
const ret = rret.unwrap();
|
|
138
|
+
if (ret.stop && ret.value) {
|
|
139
|
+
return ret.value;
|
|
140
|
+
}
|
|
141
|
+
return this.innerGW.get(ctx, ret.op.url);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async subscribe(ctx: SerdeGatewayCtx, url: URI, callback: (msg: FPEnvelopeMeta) => Promise<void>): Promise<UnsubscribeResult> {
|
|
145
|
+
if (!this.innerGW.subscribe) {
|
|
146
|
+
return Result.Err(ctx.loader.sthis.logger.Error().Url(url).Msg("subscribe not supported").AsError());
|
|
147
|
+
}
|
|
148
|
+
const rret = await this.interceptor.subscribe(ctx, url, callback);
|
|
149
|
+
if (rret.isErr()) {
|
|
150
|
+
return Result.Err(rret.Err());
|
|
151
|
+
}
|
|
152
|
+
const ret = rret.unwrap();
|
|
153
|
+
if (ret.stop && ret.value) {
|
|
154
|
+
return ret.value;
|
|
155
|
+
}
|
|
156
|
+
return this.innerGW.subscribe(ctx, ret.op.url, ret.op.callback);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async delete(ctx: SerdeGatewayCtx, url: URI): Promise<VoidResult> {
|
|
160
|
+
const rret = await this.interceptor.delete(ctx, url);
|
|
161
|
+
if (rret.isErr()) {
|
|
162
|
+
return Result.Err(rret.Err());
|
|
163
|
+
}
|
|
164
|
+
const ret = rret.unwrap();
|
|
165
|
+
if (ret.stop && ret.value) {
|
|
166
|
+
return ret.value;
|
|
167
|
+
}
|
|
168
|
+
return this.innerGW.delete(ctx, url);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async getPlain(ctx: SerdeGatewayCtx, url: URI, key: string): Promise<Result<Uint8Array>> {
|
|
172
|
+
return this.innerGW.getPlain(ctx, url, key);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Result, URI } from "@adviser/cement";
|
|
2
|
+
import { FPEnvelopeMeta, SerializedMeta, V2SerializedMetaKey, Gateway, Loadable, FPEnvelope, SerdeGateway, SerdeGatewayCtx } from "@fireproof/core-types-blockstore";
|
|
3
|
+
import { NotFoundError } from "@fireproof/core-types-base";
|
|
4
|
+
type V1SerializedMetaKey = SerializedMeta & {
|
|
5
|
+
readonly key?: string | string[];
|
|
6
|
+
readonly keys?: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare function V2SerializedMetaKeyExtractKey(ctx: SerdeGatewayCtx, v2: V2SerializedMetaKey): Promise<Result<SerializedMeta[]>>;
|
|
9
|
+
export declare function decodeAsToSerializedMeta(ctx: SerdeGatewayCtx, raw: Uint8Array): Promise<Result<V2SerializedMetaKey>>;
|
|
10
|
+
export declare function addKeyToDbMetaDecoder(ctx: SerdeGatewayCtx & {
|
|
11
|
+
readonly lastDecodedMetas?: V2SerializedMetaKey[];
|
|
12
|
+
}): SerdeGatewayCtx & {
|
|
13
|
+
lastDecodedMetas: V2SerializedMetaKey[];
|
|
14
|
+
};
|
|
15
|
+
export declare function encodeAsV1SerializedMetaKey(ctx: SerdeGatewayCtx, payload: SerializedMeta[]): Promise<Result<V1SerializedMetaKey[]>>;
|
|
16
|
+
export declare function encodeAsV2SerializedMetaKey(ctx: SerdeGatewayCtx, payload: SerializedMeta[]): Promise<Result<V2SerializedMetaKey>>;
|
|
17
|
+
export declare function addKeyToDbMetaEncoder(ctx: SerdeGatewayCtx, version: "v1" | "v2"): SerdeGatewayCtx;
|
|
18
|
+
export declare class AddKeyToDbMetaGateway implements SerdeGateway {
|
|
19
|
+
private readonly sdGw;
|
|
20
|
+
readonly version: "v1" | "v2";
|
|
21
|
+
constructor(gw: Gateway, version: "v1" | "v2");
|
|
22
|
+
buildUrl(ctx: SerdeGatewayCtx, baseUrl: URI, key: string): Promise<Result<URI>>;
|
|
23
|
+
start(ctx: SerdeGatewayCtx, baseUrl: URI): Promise<Result<URI>>;
|
|
24
|
+
close(ctx: SerdeGatewayCtx, baseUrl: URI): Promise<Result<void, Error>>;
|
|
25
|
+
put<T>(ctx: SerdeGatewayCtx, url: URI, body: FPEnvelope<T>): Promise<Result<void, Error>>;
|
|
26
|
+
get<S>(ctx: SerdeGatewayCtx, url: URI): Promise<Result<FPEnvelope<S>, Error | NotFoundError>>;
|
|
27
|
+
readonly lastDecodedMetas: V2SerializedMetaKey[];
|
|
28
|
+
delete(ctx: SerdeGatewayCtx, url: URI, loader?: Loadable): Promise<Result<void, Error>>;
|
|
29
|
+
subscribe(ctx: SerdeGatewayCtx, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>): Promise<Result<() => void, Error>>;
|
|
30
|
+
getPlain(ctx: SerdeGatewayCtx, url: URI, key: string): Promise<Result<Uint8Array>>;
|
|
31
|
+
destroy(ctx: SerdeGatewayCtx, baseUrl: URI): Promise<Result<void, Error>>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|