mindoodb 0.0.74 → 0.0.76
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/dist/browser/index.mjs +7 -0
- package/dist/core/BaseMindooDB.d.ts +10 -0
- package/dist/core/BaseMindooDB.d.ts.map +1 -1
- package/dist/core/BaseMindooDB.js +105 -22
- package/dist/core/BaseMindooDB.js.map +1 -1
- package/dist/core/appendonlystores/migration/StoreMigration.d.ts +34 -0
- package/dist/core/appendonlystores/migration/StoreMigration.d.ts.map +1 -0
- package/dist/core/appendonlystores/migration/StoreMigration.js +70 -0
- package/dist/core/appendonlystores/migration/StoreMigration.js.map +1 -0
- package/dist/core/appendonlystores/rpc/RpcContentAddressedStore.d.ts +97 -0
- package/dist/core/appendonlystores/rpc/RpcContentAddressedStore.d.ts.map +1 -0
- package/dist/core/appendonlystores/rpc/RpcContentAddressedStore.js +128 -0
- package/dist/core/appendonlystores/rpc/RpcContentAddressedStore.js.map +1 -0
- package/dist/core/appendonlystores/rpc/StoreRpcServer.d.ts +24 -0
- package/dist/core/appendonlystores/rpc/StoreRpcServer.d.ts.map +1 -0
- package/dist/core/appendonlystores/rpc/StoreRpcServer.js +102 -0
- package/dist/core/appendonlystores/rpc/StoreRpcServer.js.map +1 -0
- package/dist/core/appendonlystores/rpc/storeRpcCodec.d.ts +15 -0
- package/dist/core/appendonlystores/rpc/storeRpcCodec.d.ts.map +1 -0
- package/dist/core/appendonlystores/rpc/storeRpcCodec.js +100 -0
- package/dist/core/appendonlystores/rpc/storeRpcCodec.js.map +1 -0
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.d.ts +3 -0
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.d.ts.map +1 -1
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.js +18 -11
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.js.map +1 -1
- package/dist/core/appendonlystores/sqlite/SqliteDriver.d.ts +13 -0
- package/dist/core/appendonlystores/sqlite/SqliteDriver.d.ts.map +1 -1
- package/dist/core/appendonlystores/sqlite/SqliteDriver.js +74 -0
- package/dist/core/appendonlystores/sqlite/SqliteDriver.js.map +1 -1
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +13 -2
- package/dist/core/index.js.map +1 -1
- package/dist/sqlite/index.d.ts +2 -0
- package/dist/sqlite/index.d.ts.map +1 -1
- package/dist/sqlite/index.js +8 -1
- package/dist/sqlite/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moving a store's data to a new storage backend, e.g. when Haven's native
|
|
3
|
+
* app switches from the WebView's IndexedDB to SQLite in the host app.
|
|
4
|
+
*
|
|
5
|
+
* {@link MigratingContentAddressedStoreFactory} hands out the target stores;
|
|
6
|
+
* the first call on a store copies all entries from the matching source store
|
|
7
|
+
* if the target is still empty. Copying is idempotent (putEntries skips ids
|
|
8
|
+
* already stored), so an interrupted copy resumes on the next start. The
|
|
9
|
+
* source keeps its data.
|
|
10
|
+
*/
|
|
11
|
+
import type { ContentAddressedStore, ContentAddressedStoreFactory, CreateStoreResult, OpenStoreOptions } from "../types";
|
|
12
|
+
export interface StoreMigrationOptions {
|
|
13
|
+
/** Entries per copy batch (default 100: up to ~25 MB with 256 KB attachment chunks). */
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
/** Called after a store was copied (not when there was nothing to copy). */
|
|
16
|
+
onMigrated?(info: {
|
|
17
|
+
dbId: string;
|
|
18
|
+
kind: string;
|
|
19
|
+
entries: number;
|
|
20
|
+
}): void;
|
|
21
|
+
}
|
|
22
|
+
/** Copies every entry of `source` into `target` unless `target` already has entries. Returns the count copied. */
|
|
23
|
+
export declare function migrateStoreEntries(source: ContentAddressedStore, target: ContentAddressedStore, batchSize?: number): Promise<number>;
|
|
24
|
+
/** `target`, but every async call first waits until `source` was copied into it. */
|
|
25
|
+
export declare function withStoreMigration(target: ContentAddressedStore, source: ContentAddressedStore, options?: StoreMigrationOptions): ContentAddressedStore;
|
|
26
|
+
/** Target stores that first take over the source's data (see {@link withStoreMigration}). */
|
|
27
|
+
export declare class MigratingContentAddressedStoreFactory implements ContentAddressedStoreFactory {
|
|
28
|
+
private readonly target;
|
|
29
|
+
private readonly source;
|
|
30
|
+
private readonly options;
|
|
31
|
+
constructor(target: ContentAddressedStoreFactory, source: ContentAddressedStoreFactory, options?: StoreMigrationOptions);
|
|
32
|
+
createStore(dbId: string, options?: OpenStoreOptions): CreateStoreResult;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=StoreMigration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StoreMigration.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/migration/StoreMigration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAKzH,MAAM,WAAW,qBAAqB;IACpC,wFAAwF;IACxF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,UAAU,CAAC,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CAC1E;AAED,kHAAkH;AAClH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,qBAAqB,EAC7B,MAAM,EAAE,qBAAqB,EAC7B,SAAS,SAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED,oFAAoF;AACpF,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,qBAAqB,EAC7B,MAAM,EAAE,qBAAqB,EAC7B,OAAO,GAAE,qBAA0B,GAClC,qBAAqB,CAwBvB;AAED,6FAA6F;AAC7F,qBAAa,qCAAsC,YAAW,4BAA4B;IAEtF,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAFP,MAAM,EAAE,4BAA4B,EACpC,MAAM,EAAE,4BAA4B,EACpC,OAAO,GAAE,qBAA0B;IAGtD,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,iBAAiB;CAQzE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MigratingContentAddressedStoreFactory = void 0;
|
|
4
|
+
exports.migrateStoreEntries = migrateStoreEntries;
|
|
5
|
+
exports.withStoreMigration = withStoreMigration;
|
|
6
|
+
/** Methods answered without waiting for the copy (they are synchronous). */
|
|
7
|
+
const SYNC_METHODS = new Set(["getId", "getStoreKind", "getIndexBuildStatus", "getCacheIdentity"]);
|
|
8
|
+
/** Copies every entry of `source` into `target` unless `target` already has entries. Returns the count copied. */
|
|
9
|
+
async function migrateStoreEntries(source, target, batchSize = 100) {
|
|
10
|
+
const targetHasData = target.getStoreHead
|
|
11
|
+
? (await target.getStoreHead()).maxReceiptOrder > 0
|
|
12
|
+
: (await target.getAllIds()).length > 0;
|
|
13
|
+
if (targetHasData) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
const ids = await source.getAllIds();
|
|
17
|
+
let copied = 0;
|
|
18
|
+
for (let i = 0; i < ids.length; i += batchSize) {
|
|
19
|
+
const entries = await source.getEntries(ids.slice(i, i + batchSize));
|
|
20
|
+
if (entries.length > 0) {
|
|
21
|
+
await target.putEntries(entries);
|
|
22
|
+
copied += entries.length;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return copied;
|
|
26
|
+
}
|
|
27
|
+
/** `target`, but every async call first waits until `source` was copied into it. */
|
|
28
|
+
function withStoreMigration(target, source, options = {}) {
|
|
29
|
+
let ready = null;
|
|
30
|
+
const migrate = () => {
|
|
31
|
+
if (!ready) {
|
|
32
|
+
ready = migrateStoreEntries(source, target, options.batchSize).then((entries) => {
|
|
33
|
+
if (entries > 0) {
|
|
34
|
+
options.onMigrated?.({ dbId: target.getId(), kind: target.getStoreKind(), entries });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return ready;
|
|
39
|
+
};
|
|
40
|
+
return new Proxy(target, {
|
|
41
|
+
get(store, property, receiver) {
|
|
42
|
+
const value = Reflect.get(store, property, receiver);
|
|
43
|
+
if (typeof value !== "function" || typeof property !== "string" || SYNC_METHODS.has(property)) {
|
|
44
|
+
return typeof value === "function" ? value.bind(store) : value;
|
|
45
|
+
}
|
|
46
|
+
return async (...args) => {
|
|
47
|
+
await migrate();
|
|
48
|
+
return value.apply(store, args);
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** Target stores that first take over the source's data (see {@link withStoreMigration}). */
|
|
54
|
+
class MigratingContentAddressedStoreFactory {
|
|
55
|
+
constructor(target, source, options = {}) {
|
|
56
|
+
this.target = target;
|
|
57
|
+
this.source = source;
|
|
58
|
+
this.options = options;
|
|
59
|
+
}
|
|
60
|
+
createStore(dbId, options) {
|
|
61
|
+
const target = this.target.createStore(dbId, options);
|
|
62
|
+
const source = this.source.createStore(dbId, options);
|
|
63
|
+
return {
|
|
64
|
+
docStore: withStoreMigration(target.docStore, source.docStore, this.options),
|
|
65
|
+
attachmentStore: withStoreMigration(target.attachmentStore, source.attachmentStore, this.options),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.MigratingContentAddressedStoreFactory = MigratingContentAddressedStoreFactory;
|
|
70
|
+
//# sourceMappingURL=StoreMigration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StoreMigration.js","sourceRoot":"","sources":["../../../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,WAAM,GAAN,MAAM,CAA8B;QACpC,WAAM,GAAN,MAAM,CAA8B;QACpC,YAAO,GAAP,OAAO,CAA4B;IACnD,CAAC;IAEJ,WAAW,CAAC,IAAY,EAAE,OAA0B;QAClD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACtD,OAAO;YACL,QAAQ,EAAE,kBAAkB,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC;YAC5E,eAAe,EAAE,kBAAkB,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC;SAClG,CAAC;IACJ,CAAC;CACF;AAfD,sFAeC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A {@link ContentAddressedStore} whose data lives somewhere else, reached by
|
|
3
|
+
* request/response messages: e.g. Haven's WebView talking to a SQLite store
|
|
4
|
+
* in the React Native host app. {@link StoreRpcServer} answers on the other
|
|
5
|
+
* side and keeps the real stores.
|
|
6
|
+
*
|
|
7
|
+
* Metadata and arguments travel as JSON ({@link encodeRpcValue}); entry
|
|
8
|
+
* payloads travel as one raw byte buffer per batch over the transport's
|
|
9
|
+
* binary channel, so large attachments are not base64-encoded.
|
|
10
|
+
*/
|
|
11
|
+
import type { StoreEntry, StoreEntryMetadata, StoreEntryType } from "../../types";
|
|
12
|
+
import type { AttachmentReadPlan, AttachmentReadPlanOptions, AwaitIndexReadyOptions, ContentAddressedStore, ContentAddressedStoreFactory, CreateStoreResult, DocumentMaterializationBatchPlan, DocumentMaterializationPlan, MaterializationPlanOptions, OpenStoreOptions, PutEntriesAck, StoreCompactionStatus, StoreHead, StoreIdBloomSummary, StoreIndexBuildStatus, StoreScanCursor, StoreScanFilters, StoreScanResult } from "../types";
|
|
13
|
+
import { StoreKind } from "../types";
|
|
14
|
+
/** Which store a request is about. The server opens it on first use. */
|
|
15
|
+
export interface StoreRpcTarget {
|
|
16
|
+
/** Groups stores like a factory instance does (e.g. one per Haven tenant namespace). */
|
|
17
|
+
scope: string;
|
|
18
|
+
dbId: string;
|
|
19
|
+
kind: StoreKind;
|
|
20
|
+
options?: OpenStoreOptions;
|
|
21
|
+
}
|
|
22
|
+
export interface StoreRpcRequest {
|
|
23
|
+
target: StoreRpcTarget;
|
|
24
|
+
method: string;
|
|
25
|
+
/** Arguments, encoded with {@link encodeRpcValue}. */
|
|
26
|
+
args: unknown[];
|
|
27
|
+
/** putEntries: id of the payload buffer already sent with `sendBytes`. */
|
|
28
|
+
blobId?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Response of `getEntries`: metadata here, payloads in one buffer to fetch. */
|
|
31
|
+
export interface StoreRpcGetEntriesResult {
|
|
32
|
+
blobId: string | null;
|
|
33
|
+
entries: Array<{
|
|
34
|
+
meta: unknown;
|
|
35
|
+
length: number;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
/** The client's way to reach the server. */
|
|
39
|
+
export interface StoreRpcClientTransport {
|
|
40
|
+
/** Sends a request and resolves with the server's (encoded) result. */
|
|
41
|
+
call(request: StoreRpcRequest): Promise<unknown>;
|
|
42
|
+
/** Hands `bytes` to the server side under `blobId` (before the call that uses them). */
|
|
43
|
+
sendBytes(blobId: string, bytes: Uint8Array): Promise<void>;
|
|
44
|
+
/** Fetches a buffer the server offered under `blobId` (once). */
|
|
45
|
+
receiveBytes(blobId: string): Promise<Uint8Array>;
|
|
46
|
+
}
|
|
47
|
+
/** Optional {@link ContentAddressedStore} methods the server's stores implement. */
|
|
48
|
+
export type StoreRpcOptionalMethod = "applyWitnessReceipts" | "planAttachmentReadByWalkingMetadata" | "scanEntriesSince" | "getIdBloomSummary" | "getStoreHead" | "deleteEntriesForAttachment" | "deleteEntriesById" | "clearAllLocalData" | "awaitIndexReady" | "getCompactionStatus";
|
|
49
|
+
/** What {@link SqliteContentAddressedStore} implements. */
|
|
50
|
+
export declare const SQLITE_STORE_RPC_METHODS: StoreRpcOptionalMethod[];
|
|
51
|
+
export interface RpcContentAddressedStoreFactoryOptions {
|
|
52
|
+
scope: string;
|
|
53
|
+
/** Optional methods to expose; defaults to {@link SQLITE_STORE_RPC_METHODS}. */
|
|
54
|
+
optionalMethods?: StoreRpcOptionalMethod[];
|
|
55
|
+
}
|
|
56
|
+
export declare class RpcContentAddressedStore implements ContentAddressedStore {
|
|
57
|
+
private readonly transport;
|
|
58
|
+
private readonly target;
|
|
59
|
+
private indexStatus;
|
|
60
|
+
applyWitnessReceipts?: (receipts: StoreEntryMetadata[]) => Promise<void>;
|
|
61
|
+
planAttachmentReadByWalkingMetadata?: (lastChunkId: string, attachmentSize: number, options: AttachmentReadPlanOptions) => Promise<AttachmentReadPlan>;
|
|
62
|
+
scanEntriesSince?: (cursor: StoreScanCursor | null, limit?: number, filters?: StoreScanFilters) => Promise<StoreScanResult>;
|
|
63
|
+
getIdBloomSummary?: () => Promise<StoreIdBloomSummary>;
|
|
64
|
+
getStoreHead?: () => Promise<StoreHead>;
|
|
65
|
+
deleteEntriesForAttachment?: (docId: string, attachmentId: string) => Promise<number>;
|
|
66
|
+
deleteEntriesById?: (entryIds: string[]) => Promise<number>;
|
|
67
|
+
clearAllLocalData?: () => Promise<void>;
|
|
68
|
+
awaitIndexReady?: (options?: AwaitIndexReadyOptions) => Promise<StoreIndexBuildStatus>;
|
|
69
|
+
getCompactionStatus?: () => Promise<StoreCompactionStatus>;
|
|
70
|
+
constructor(transport: StoreRpcClientTransport, target: StoreRpcTarget, optionalMethods: StoreRpcOptionalMethod[]);
|
|
71
|
+
private invoke;
|
|
72
|
+
getId(): string;
|
|
73
|
+
getStoreKind(): StoreKind;
|
|
74
|
+
getCacheIdentity(): string;
|
|
75
|
+
getIndexBuildStatus(): StoreIndexBuildStatus;
|
|
76
|
+
putEntries(entries: StoreEntry[]): Promise<void | StoreEntryMetadata[] | PutEntriesAck>;
|
|
77
|
+
getEntries(ids: string[]): Promise<StoreEntry[]>;
|
|
78
|
+
getEntryMetadata(id: string): Promise<StoreEntryMetadata | null>;
|
|
79
|
+
hasEntries(ids: string[]): Promise<string[]>;
|
|
80
|
+
findNewEntries(knownIds: string[]): Promise<StoreEntryMetadata[]>;
|
|
81
|
+
findNewEntriesForDoc(knownIds: string[], docId: string): Promise<StoreEntryMetadata[]>;
|
|
82
|
+
findEntries(type: StoreEntryType, creationDateFrom: number | null, creationDateUntil: number | null): Promise<StoreEntryMetadata[]>;
|
|
83
|
+
getAllIds(): Promise<string[]>;
|
|
84
|
+
planDocumentMaterialization(docId: string, options?: MaterializationPlanOptions): Promise<DocumentMaterializationPlan>;
|
|
85
|
+
planDocumentMaterializationBatch(docIds: string[], options?: MaterializationPlanOptions): Promise<DocumentMaterializationBatchPlan>;
|
|
86
|
+
resolveDependencies(startId: string, options?: Record<string, unknown>): Promise<string[]>;
|
|
87
|
+
purgeDocHistory(docId: string): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
/** Factory over a transport; `createStore` is synchronous, the server opens lazily. */
|
|
90
|
+
export declare class RpcContentAddressedStoreFactory implements ContentAddressedStoreFactory {
|
|
91
|
+
private readonly transport;
|
|
92
|
+
private readonly options;
|
|
93
|
+
private readonly optionalMethods;
|
|
94
|
+
constructor(transport: StoreRpcClientTransport, options: RpcContentAddressedStoreFactoryOptions);
|
|
95
|
+
createStore(dbId: string, options?: OpenStoreOptions): CreateStoreResult;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=RpcContentAddressedStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcContentAddressedStore.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/rpc/RpcContentAddressedStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAA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CAAC;IAIhC,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI9B,2BAA2B,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAItH,gCAAgC,CAC9B,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,gCAAgC,CAAC;IAI5C,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAIpF,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGpD;AAED,uFAAuF;AACvF,qBAAa,+BAAgC,YAAW,4BAA4B;IAIhF,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA2B;gBAGxC,SAAS,EAAE,uBAAuB,EAClC,OAAO,EAAE,sCAAsC;IAKlE,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,iBAAiB;CAOzE"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcContentAddressedStoreFactory = exports.RpcContentAddressedStore = exports.SQLITE_STORE_RPC_METHODS = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const idGeneration_1 = require("../../utils/idGeneration");
|
|
6
|
+
const storeRpcCodec_1 = require("./storeRpcCodec");
|
|
7
|
+
/** What {@link SqliteContentAddressedStore} implements. */
|
|
8
|
+
exports.SQLITE_STORE_RPC_METHODS = [
|
|
9
|
+
"applyWitnessReceipts",
|
|
10
|
+
"planAttachmentReadByWalkingMetadata",
|
|
11
|
+
"scanEntriesSince",
|
|
12
|
+
"getIdBloomSummary",
|
|
13
|
+
"getStoreHead",
|
|
14
|
+
"deleteEntriesById",
|
|
15
|
+
"clearAllLocalData",
|
|
16
|
+
"awaitIndexReady",
|
|
17
|
+
];
|
|
18
|
+
class RpcContentAddressedStore {
|
|
19
|
+
constructor(transport, target, optionalMethods) {
|
|
20
|
+
this.transport = transport;
|
|
21
|
+
this.target = target;
|
|
22
|
+
this.indexStatus = { phase: "ready", indexingEnabled: true, progress01: 1 };
|
|
23
|
+
for (const method of optionalMethods) {
|
|
24
|
+
// No async arrow with rest parameters here: React Native's Babel setup
|
|
25
|
+
// (Metro, Hermes profile) fails to compile one that uses `this`.
|
|
26
|
+
const forward = method === "awaitIndexReady"
|
|
27
|
+
? (...args) => this.invoke(method, args).then((status) => {
|
|
28
|
+
this.indexStatus = status;
|
|
29
|
+
return this.indexStatus;
|
|
30
|
+
})
|
|
31
|
+
: (...args) => this.invoke(method, args);
|
|
32
|
+
this[method] = forward;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async invoke(method, args, blobId) {
|
|
36
|
+
const result = await this.transport.call({
|
|
37
|
+
target: this.target,
|
|
38
|
+
method,
|
|
39
|
+
args: (0, storeRpcCodec_1.encodeRpcValue)(args),
|
|
40
|
+
blobId,
|
|
41
|
+
});
|
|
42
|
+
return (0, storeRpcCodec_1.decodeRpcValue)(result);
|
|
43
|
+
}
|
|
44
|
+
getId() {
|
|
45
|
+
return this.target.dbId;
|
|
46
|
+
}
|
|
47
|
+
getStoreKind() {
|
|
48
|
+
return this.target.kind;
|
|
49
|
+
}
|
|
50
|
+
getCacheIdentity() {
|
|
51
|
+
return `rpc:${this.target.scope}:${this.target.dbId}:${this.target.kind}`;
|
|
52
|
+
}
|
|
53
|
+
getIndexBuildStatus() {
|
|
54
|
+
return this.indexStatus;
|
|
55
|
+
}
|
|
56
|
+
async putEntries(entries) {
|
|
57
|
+
if (entries.length === 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const blobId = (0, idGeneration_1.generateRandomUuid)();
|
|
61
|
+
await this.transport.sendBytes(blobId, (0, storeRpcCodec_1.concatBytes)(entries.map((entry) => entry.encryptedData)));
|
|
62
|
+
const metas = entries.map(({ encryptedData, ...meta }) => ({ meta, length: encryptedData.byteLength }));
|
|
63
|
+
return (await this.invoke("putEntries", [metas], blobId));
|
|
64
|
+
}
|
|
65
|
+
async getEntries(ids) {
|
|
66
|
+
if (ids.length === 0) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const result = (await this.invoke("getEntries", [ids]));
|
|
70
|
+
if (!result.blobId || result.entries.length === 0) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const bytes = await this.transport.receiveBytes(result.blobId);
|
|
74
|
+
const payloads = (0, storeRpcCodec_1.splitBytes)(bytes, result.entries.map((entry) => entry.length));
|
|
75
|
+
return result.entries.map((entry, index) => ({
|
|
76
|
+
...entry.meta,
|
|
77
|
+
encryptedData: payloads[index],
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
getEntryMetadata(id) {
|
|
81
|
+
return this.invoke("getEntryMetadata", [id]);
|
|
82
|
+
}
|
|
83
|
+
hasEntries(ids) {
|
|
84
|
+
return this.invoke("hasEntries", [ids]);
|
|
85
|
+
}
|
|
86
|
+
findNewEntries(knownIds) {
|
|
87
|
+
return this.invoke("findNewEntries", [knownIds]);
|
|
88
|
+
}
|
|
89
|
+
findNewEntriesForDoc(knownIds, docId) {
|
|
90
|
+
return this.invoke("findNewEntriesForDoc", [knownIds, docId]);
|
|
91
|
+
}
|
|
92
|
+
findEntries(type, creationDateFrom, creationDateUntil) {
|
|
93
|
+
return this.invoke("findEntries", [type, creationDateFrom, creationDateUntil]);
|
|
94
|
+
}
|
|
95
|
+
getAllIds() {
|
|
96
|
+
return this.invoke("getAllIds", []);
|
|
97
|
+
}
|
|
98
|
+
planDocumentMaterialization(docId, options) {
|
|
99
|
+
return this.invoke("planDocumentMaterialization", [docId, options]);
|
|
100
|
+
}
|
|
101
|
+
planDocumentMaterializationBatch(docIds, options) {
|
|
102
|
+
return this.invoke("planDocumentMaterializationBatch", [docIds, options]);
|
|
103
|
+
}
|
|
104
|
+
resolveDependencies(startId, options) {
|
|
105
|
+
return this.invoke("resolveDependencies", [startId, options]);
|
|
106
|
+
}
|
|
107
|
+
async purgeDocHistory(docId) {
|
|
108
|
+
await this.invoke("purgeDocHistory", [docId]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.RpcContentAddressedStore = RpcContentAddressedStore;
|
|
112
|
+
/** Factory over a transport; `createStore` is synchronous, the server opens lazily. */
|
|
113
|
+
class RpcContentAddressedStoreFactory {
|
|
114
|
+
constructor(transport, options) {
|
|
115
|
+
this.transport = transport;
|
|
116
|
+
this.options = options;
|
|
117
|
+
this.optionalMethods = options.optionalMethods ?? exports.SQLITE_STORE_RPC_METHODS;
|
|
118
|
+
}
|
|
119
|
+
createStore(dbId, options) {
|
|
120
|
+
const target = (kind) => ({ scope: this.options.scope, dbId, kind, options });
|
|
121
|
+
return {
|
|
122
|
+
docStore: new RpcContentAddressedStore(this.transport, target(types_1.StoreKind.docs), this.optionalMethods),
|
|
123
|
+
attachmentStore: new RpcContentAddressedStore(this.transport, target(types_1.StoreKind.attachments), this.optionalMethods),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.RpcContentAddressedStoreFactory = RpcContentAddressedStoreFactory;
|
|
128
|
+
//# sourceMappingURL=RpcContentAddressedStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcContentAddressedStore.js","sourceRoot":"","sources":["../../../../src/core/appendonlystores/rpc/RpcContentAddressedStore.ts"],"names":[],"mappings":";;;AA+BA,oCAAqC;AACrC,2DAA8D;AAC9D,mDAA0F;AAiD1F,2DAA2D;AAC9C,QAAA,wBAAwB,GAA6B;IAChE,sBAAsB;IACt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AAE,IAAI,CAAC,eAAe,CAAC;YACpG,eAAe,EAAE,IAAI,wBAAwB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,iBAAS,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC;SACnH,CAAC;IACJ,CAAC;CACF;AAjBD,0EAiBC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ContentAddressedStoreFactory } from "../types";
|
|
2
|
+
import type { StoreRpcRequest } from "./RpcContentAddressedStore";
|
|
3
|
+
/** The server's side of the binary channel. */
|
|
4
|
+
export interface StoreRpcServerBytes {
|
|
5
|
+
/** Bytes the client sent under `blobId` (removed once taken). */
|
|
6
|
+
take(blobId: string): Promise<Uint8Array | null>;
|
|
7
|
+
/** Makes `bytes` fetchable by the client under `blobId` (once). */
|
|
8
|
+
offer(blobId: string, bytes: Uint8Array): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export interface StoreRpcServerOptions {
|
|
11
|
+
/** Store factory for a scope (e.g. one SQLite file set per Haven tenant namespace). */
|
|
12
|
+
createFactory(scope: string): ContentAddressedStoreFactory;
|
|
13
|
+
bytes: StoreRpcServerBytes;
|
|
14
|
+
}
|
|
15
|
+
export declare class StoreRpcServer {
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly factories;
|
|
18
|
+
private readonly stores;
|
|
19
|
+
constructor(options: StoreRpcServerOptions);
|
|
20
|
+
private store;
|
|
21
|
+
/** Handles one request; the result is encoded for the transport. */
|
|
22
|
+
handle(request: StoreRpcRequest): Promise<unknown>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=StoreRpcServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StoreRpcServer.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/rpc/StoreRpcServer.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAyB,4BAA4B,EAAqB,MAAM,UAAU,CAAC;AAGvG,OAAO,KAAK,EAA4B,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG5F,+CAA+C;AAC/C,MAAM,WAAW,mBAAmB;IAClC,iEAAiE;IACjE,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACjD,mEAAmE;IACnE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,qBAAqB;IACpC,uFAAuF;IACvF,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,4BAA4B,CAAC;IAC3D,KAAK,EAAE,mBAAmB,CAAC;CAC5B;AA+BD,qBAAa,cAAc;IAIb,OAAO,CAAC,QAAQ,CAAC,OAAO;IAHpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmD;IAC7E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;gBAElC,OAAO,EAAE,qBAAqB;IAE3D,OAAO,CAAC,KAAK;IAsBb,oEAAoE;IAC9D,MAAM,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;CAsCzD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StoreRpcServer = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const idGeneration_1 = require("../../utils/idGeneration");
|
|
6
|
+
const storeRpcCodec_1 = require("./storeRpcCodec");
|
|
7
|
+
/** Methods a client may call besides putEntries/getEntries (which need the binary channel). */
|
|
8
|
+
const FORWARDED_METHODS = new Set([
|
|
9
|
+
"getEntryMetadata",
|
|
10
|
+
"hasEntries",
|
|
11
|
+
"findNewEntries",
|
|
12
|
+
"findNewEntriesForDoc",
|
|
13
|
+
"findEntries",
|
|
14
|
+
"getAllIds",
|
|
15
|
+
"planDocumentMaterialization",
|
|
16
|
+
"planDocumentMaterializationBatch",
|
|
17
|
+
"resolveDependencies",
|
|
18
|
+
"purgeDocHistory",
|
|
19
|
+
"applyWitnessReceipts",
|
|
20
|
+
"planAttachmentReadByWalkingMetadata",
|
|
21
|
+
"scanEntriesSince",
|
|
22
|
+
"getIdBloomSummary",
|
|
23
|
+
"getStoreHead",
|
|
24
|
+
"deleteEntriesForAttachment",
|
|
25
|
+
"deleteEntriesById",
|
|
26
|
+
"clearAllLocalData",
|
|
27
|
+
"awaitIndexReady",
|
|
28
|
+
"getCompactionStatus",
|
|
29
|
+
]);
|
|
30
|
+
/** Scope and db id are opaque keys (hosts map them to files themselves); keep them sane. */
|
|
31
|
+
function isValidKey(value) {
|
|
32
|
+
return typeof value === "string" && value.length > 0 && value.length <= 500 && !/[\u0000-\u001f]/.test(value);
|
|
33
|
+
}
|
|
34
|
+
class StoreRpcServer {
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.options = options;
|
|
37
|
+
this.factories = new Map();
|
|
38
|
+
this.stores = new Map();
|
|
39
|
+
}
|
|
40
|
+
store(request) {
|
|
41
|
+
const { scope, dbId, kind, options } = request.target;
|
|
42
|
+
if (!isValidKey(scope) || !isValidKey(dbId)) {
|
|
43
|
+
throw new Error("Store RPC: invalid scope or database id");
|
|
44
|
+
}
|
|
45
|
+
if (kind !== types_1.StoreKind.docs && kind !== types_1.StoreKind.attachments) {
|
|
46
|
+
throw new Error("Store RPC: invalid store kind");
|
|
47
|
+
}
|
|
48
|
+
const key = `${scope}\u0000${dbId}`;
|
|
49
|
+
let pair = this.stores.get(key);
|
|
50
|
+
if (!pair) {
|
|
51
|
+
let factory = this.factories.get(scope);
|
|
52
|
+
if (!factory) {
|
|
53
|
+
factory = this.options.createFactory(scope);
|
|
54
|
+
this.factories.set(scope, factory);
|
|
55
|
+
}
|
|
56
|
+
pair = factory.createStore(dbId, options);
|
|
57
|
+
this.stores.set(key, pair);
|
|
58
|
+
}
|
|
59
|
+
return kind === types_1.StoreKind.docs ? pair.docStore : pair.attachmentStore;
|
|
60
|
+
}
|
|
61
|
+
/** Handles one request; the result is encoded for the transport. */
|
|
62
|
+
async handle(request) {
|
|
63
|
+
const store = this.store(request);
|
|
64
|
+
const args = (0, storeRpcCodec_1.decodeRpcValue)(request.args);
|
|
65
|
+
if (request.method === "putEntries") {
|
|
66
|
+
if (!request.blobId) {
|
|
67
|
+
throw new Error("Store RPC: putEntries without payload");
|
|
68
|
+
}
|
|
69
|
+
const bytes = await this.options.bytes.take(request.blobId);
|
|
70
|
+
if (!bytes) {
|
|
71
|
+
throw new Error("Store RPC: payload not found");
|
|
72
|
+
}
|
|
73
|
+
const metas = args[0];
|
|
74
|
+
const payloads = (0, storeRpcCodec_1.splitBytes)(bytes, metas.map((item) => item.length));
|
|
75
|
+
const entries = metas.map((item, index) => ({ ...item.meta, encryptedData: payloads[index] }));
|
|
76
|
+
return (0, storeRpcCodec_1.encodeRpcValue)(await store.putEntries(entries));
|
|
77
|
+
}
|
|
78
|
+
if (request.method === "getEntries") {
|
|
79
|
+
const entries = await store.getEntries(args[0]);
|
|
80
|
+
const result = { blobId: null, entries: [] };
|
|
81
|
+
if (entries.length > 0) {
|
|
82
|
+
result.blobId = (0, idGeneration_1.generateRandomUuid)();
|
|
83
|
+
await this.options.bytes.offer(result.blobId, (0, storeRpcCodec_1.concatBytes)(entries.map((entry) => entry.encryptedData)));
|
|
84
|
+
result.entries = entries.map(({ encryptedData, ...meta }) => ({
|
|
85
|
+
meta: (0, storeRpcCodec_1.encodeRpcValue)(meta),
|
|
86
|
+
length: encryptedData.byteLength,
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
if (!FORWARDED_METHODS.has(request.method)) {
|
|
92
|
+
throw new Error(`Store RPC: unknown method ${request.method}`);
|
|
93
|
+
}
|
|
94
|
+
const method = store[request.method];
|
|
95
|
+
if (typeof method !== "function") {
|
|
96
|
+
throw new Error(`Store RPC: ${request.method} is not supported by this store`);
|
|
97
|
+
}
|
|
98
|
+
return (0, storeRpcCodec_1.encodeRpcValue)(await method.apply(store, args));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.StoreRpcServer = StoreRpcServer;
|
|
102
|
+
//# sourceMappingURL=StoreRpcServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StoreRpcServer.js","sourceRoot":"","sources":["../../../../src/core/appendonlystores/rpc/StoreRpcServer.ts"],"names":[],"mappings":";;;AAOA,oCAAqC;AACrC,2DAA8D;AAE9D,mDAA0F;AAgB1F,+FAA+F;AAC/F,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,sBAAsB;IACtB,aAAa;IACb,WAAW;IACX,6BAA6B;IAC7B,kCAAkC;IAClC,qBAAqB;IACrB,iBAAiB;IACjB,sBAAsB;IACtB,qCAAqC;IACrC,kBAAkB;IAClB,mBAAmB;IACnB,cAAc;IACd,4BAA4B;IAC5B,mBAAmB;IACnB,mBAAmB;IACnB,iBAAiB;IACjB,qBAAqB;CACtB,CAAC,CAAC;AAEH,4FAA4F;AAC5F,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChH,CAAC;AAED,MAAa,cAAc;IAIzB,YAA6B,OAA8B;QAA9B,YAAO,GAAP,OAAO,CAAuB;QAH1C,cAAS,GAAG,IAAI,GAAG,EAAwC,CAAC;QAC5D,WAAM,GAAG,IAAI,GAAG,EAA6B,CAAC;IAED,CAAC;IAEvD,KAAK,CAAC,OAAwB;QACpC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;QACtD,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AC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAA,2BAAW,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;gBACxG,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC5D,IAAI,EAAE,IAAA,8BAAc,EAAC,IAAI,CAAC;oBAC1B,MAAM,EAAE,aAAa,CAAC,UAAU;iBACjC,CAAC,CAAC,CAAC;YACN,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACjE,CAAC;QACD,MAAM,MAAM,GAAI,KAA4C,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7E,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,cAAc,OAAO,CAAC,MAAM,iCAAiC,CAAC,CAAC;QACjF,CAAC;QACD,OAAO,IAAA,8BAAc,EAAC,MAAO,MAAgD,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IACpG,CAAC;CACF;AAnED,wCAmEC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-safe encoding for store RPC arguments and results: every Uint8Array
|
|
3
|
+
* (signatures, bloom bits, …) becomes `{ $bytes: "<base64>" }` and back.
|
|
4
|
+
* Entry payloads do not go through this codec; they travel as raw bytes over
|
|
5
|
+
* the transport's binary channel (see {@link StoreRpcClientTransport}).
|
|
6
|
+
*/
|
|
7
|
+
/** Deep copy of `value` with Uint8Arrays replaced by `{ $bytes }` objects. */
|
|
8
|
+
export declare function encodeRpcValue(value: unknown): unknown;
|
|
9
|
+
/** Inverse of {@link encodeRpcValue}. */
|
|
10
|
+
export declare function decodeRpcValue(value: unknown): unknown;
|
|
11
|
+
/** Concatenates entry payloads into one buffer for the binary channel. */
|
|
12
|
+
export declare function concatBytes(parts: Uint8Array[]): Uint8Array;
|
|
13
|
+
/** Splits a buffer produced by {@link concatBytes} again (views, no copies). */
|
|
14
|
+
export declare function splitBytes(bytes: Uint8Array, lengths: number[]): Uint8Array[];
|
|
15
|
+
//# sourceMappingURL=storeRpcCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storeRpcCodec.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/rpc/storeRpcCodec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA2BH,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAiBtD;AAED,yCAAyC;AACzC,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAiBtD;AAED,0EAA0E;AAC1E,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,CAY3D;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,CAW7E"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* JSON-safe encoding for store RPC arguments and results: every Uint8Array
|
|
4
|
+
* (signatures, bloom bits, …) becomes `{ $bytes: "<base64>" }` and back.
|
|
5
|
+
* Entry payloads do not go through this codec; they travel as raw bytes over
|
|
6
|
+
* the transport's binary channel (see {@link StoreRpcClientTransport}).
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.encodeRpcValue = encodeRpcValue;
|
|
10
|
+
exports.decodeRpcValue = decodeRpcValue;
|
|
11
|
+
exports.concatBytes = concatBytes;
|
|
12
|
+
exports.splitBytes = splitBytes;
|
|
13
|
+
const BYTES_KEY = "$bytes";
|
|
14
|
+
function bytesToBase64(bytes) {
|
|
15
|
+
if (typeof Buffer !== "undefined") {
|
|
16
|
+
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
17
|
+
}
|
|
18
|
+
let binary = "";
|
|
19
|
+
for (let i = 0; i < bytes.length; i += 0x8000) {
|
|
20
|
+
binary += String.fromCharCode.apply(null, Array.from(bytes.subarray(i, i + 0x8000)));
|
|
21
|
+
}
|
|
22
|
+
return btoa(binary);
|
|
23
|
+
}
|
|
24
|
+
function base64ToBytes(value) {
|
|
25
|
+
if (typeof Buffer !== "undefined") {
|
|
26
|
+
return new Uint8Array(Buffer.from(value, "base64"));
|
|
27
|
+
}
|
|
28
|
+
const binary = atob(value);
|
|
29
|
+
const out = new Uint8Array(binary.length);
|
|
30
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
31
|
+
out[i] = binary.charCodeAt(i);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/** Deep copy of `value` with Uint8Arrays replaced by `{ $bytes }` objects. */
|
|
36
|
+
function encodeRpcValue(value) {
|
|
37
|
+
if (value instanceof Uint8Array) {
|
|
38
|
+
return { [BYTES_KEY]: bytesToBase64(value) };
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(value)) {
|
|
41
|
+
return value.map(encodeRpcValue);
|
|
42
|
+
}
|
|
43
|
+
if (value && typeof value === "object") {
|
|
44
|
+
const out = {};
|
|
45
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
46
|
+
if (entry !== undefined) {
|
|
47
|
+
out[key] = encodeRpcValue(entry);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
/** Inverse of {@link encodeRpcValue}. */
|
|
55
|
+
function decodeRpcValue(value) {
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
return value.map(decodeRpcValue);
|
|
58
|
+
}
|
|
59
|
+
if (value && typeof value === "object") {
|
|
60
|
+
const record = value;
|
|
61
|
+
const keys = Object.keys(record);
|
|
62
|
+
if (keys.length === 1 && keys[0] === BYTES_KEY && typeof record[BYTES_KEY] === "string") {
|
|
63
|
+
return base64ToBytes(record[BYTES_KEY]);
|
|
64
|
+
}
|
|
65
|
+
const out = {};
|
|
66
|
+
for (const key of keys) {
|
|
67
|
+
out[key] = decodeRpcValue(record[key]);
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
/** Concatenates entry payloads into one buffer for the binary channel. */
|
|
74
|
+
function concatBytes(parts) {
|
|
75
|
+
let total = 0;
|
|
76
|
+
for (const part of parts) {
|
|
77
|
+
total += part.byteLength;
|
|
78
|
+
}
|
|
79
|
+
const out = new Uint8Array(total);
|
|
80
|
+
let offset = 0;
|
|
81
|
+
for (const part of parts) {
|
|
82
|
+
out.set(part, offset);
|
|
83
|
+
offset += part.byteLength;
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/** Splits a buffer produced by {@link concatBytes} again (views, no copies). */
|
|
88
|
+
function splitBytes(bytes, lengths) {
|
|
89
|
+
const out = [];
|
|
90
|
+
let offset = 0;
|
|
91
|
+
for (const length of lengths) {
|
|
92
|
+
out.push(bytes.subarray(offset, offset + length));
|
|
93
|
+
offset += length;
|
|
94
|
+
}
|
|
95
|
+
if (offset !== bytes.byteLength) {
|
|
96
|
+
throw new Error(`Store RPC: payload has ${bytes.byteLength} bytes, entries declare ${offset}`);
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=storeRpc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