@xyo-network/archivist 2.22.9 → 2.22.12
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/cjs/XyoArchivist.d.ts +0 -13
- package/dist/cjs/XyoArchivist.js +0 -20
- package/dist/cjs/XyoArchivist.js.map +1 -1
- package/dist/cjs/XyoArchivistConfig.d.ts +17 -0
- package/dist/cjs/XyoArchivistConfig.js +26 -0
- package/dist/cjs/XyoArchivistConfig.js.map +1 -0
- package/dist/cjs/XyoMemoryArchivist.d.ts +14 -6
- package/dist/cjs/XyoMemoryArchivist.js +12 -5
- package/dist/cjs/XyoMemoryArchivist.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/model/Archivist.d.ts +21 -6
- package/dist/esm/XyoArchivist.d.ts +0 -13
- package/dist/esm/XyoArchivist.js +1 -18
- package/dist/esm/XyoArchivist.js.map +1 -1
- package/dist/esm/XyoArchivistBase.d.ts +13 -0
- package/dist/esm/XyoArchivistBase.js +16 -0
- package/dist/esm/XyoArchivistBase.js.map +1 -0
- package/dist/esm/XyoArchivistConfig.d.ts +17 -0
- package/dist/esm/XyoArchivistConfig.js +18 -0
- package/dist/esm/XyoArchivistConfig.js.map +1 -0
- package/dist/esm/XyoMemoryArchivist.d.ts +14 -6
- package/dist/esm/XyoMemoryArchivist.js +11 -5
- package/dist/esm/XyoMemoryArchivist.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/model/Archivist.d.ts +21 -6
- package/package.json +5 -5
- package/src/XyoArchivist.ts +0 -26
- package/src/XyoArchivistConfig.ts +34 -0
- package/src/XyoMemoryArchivist.ts +28 -6
- package/src/index.ts +1 -0
- package/src/model/Archivist.ts +29 -6
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import { XyoAccount } from '@xyo-network/account';
|
|
2
1
|
import { XyoPayload } from '@xyo-network/payload';
|
|
3
2
|
import { Archivist } from './model';
|
|
4
3
|
import { XyoPayloadFindQuery } from './XyoPayloadFindFilter';
|
|
5
4
|
export declare type XyoArchivist<T extends XyoPayload = XyoPayload> = Archivist<T, T, T, T, XyoPayloadFindQuery>;
|
|
6
|
-
export declare abstract class XyoArchivistBase<T extends XyoPayload = XyoPayload> implements XyoArchivist<T> {
|
|
7
|
-
protected parent?: XyoArchivist<T>;
|
|
8
|
-
protected account?: XyoAccount;
|
|
9
|
-
constructor(parent?: XyoArchivist<T>, account?: XyoAccount);
|
|
10
|
-
abstract insert(payloads: T[]): T[] | Promise<T[]>;
|
|
11
|
-
abstract find<R extends T = T>(query: XyoPayloadFindQuery): R[] | Promise<R[]>;
|
|
12
|
-
abstract get(hash: string[]): (T | null)[] | Promise<(T | null)[]>;
|
|
13
|
-
all(): T[] | Promise<T[]>;
|
|
14
|
-
delete(_hashes: string[]): boolean[] | Promise<boolean[]>;
|
|
15
|
-
clear(): void | Promise<void>;
|
|
16
|
-
commit(): void;
|
|
17
|
-
}
|
package/dist/cjs/XyoArchivist.js
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XyoArchivistBase = void 0;
|
|
4
|
-
class XyoArchivistBase {
|
|
5
|
-
constructor(parent, account) {
|
|
6
|
-
this.parent = parent;
|
|
7
|
-
this.account = account;
|
|
8
|
-
}
|
|
9
|
-
all() {
|
|
10
|
-
throw Error('getAll not supported');
|
|
11
|
-
}
|
|
12
|
-
delete(_hashes) {
|
|
13
|
-
throw Error('delete not supported');
|
|
14
|
-
}
|
|
15
|
-
clear() {
|
|
16
|
-
throw Error('clear not supported');
|
|
17
|
-
}
|
|
18
|
-
commit() {
|
|
19
|
-
throw Error('commit not supported');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.XyoArchivistBase = XyoArchivistBase;
|
|
23
3
|
//# sourceMappingURL=XyoArchivist.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XyoArchivist.js","sourceRoot":"","sources":["../../src/XyoArchivist.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"XyoArchivist.js","sourceRoot":"","sources":["../../src/XyoArchivist.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { XyoAccount } from '@xyo-network/account';
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload';
|
|
3
|
+
import { XyoArchivist } from './XyoArchivist';
|
|
4
|
+
export interface XyoArchivistConfig<T extends XyoPayload = XyoPayload> {
|
|
5
|
+
parent?: XyoArchivist<T>;
|
|
6
|
+
account?: XyoAccount;
|
|
7
|
+
cacheParentReads?: boolean;
|
|
8
|
+
writeThrough?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class XyoArchivistConfigWrapper<T extends XyoPayload = XyoPayload, C extends XyoArchivistConfig<T> = XyoArchivistConfig<T>> {
|
|
11
|
+
protected config?: C;
|
|
12
|
+
constructor(config?: C);
|
|
13
|
+
get parent(): XyoArchivist<T> | undefined;
|
|
14
|
+
get account(): XyoAccount | undefined;
|
|
15
|
+
get writeThrough(): boolean | undefined;
|
|
16
|
+
get cacheParentReads(): boolean | undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XyoArchivistConfigWrapper = void 0;
|
|
4
|
+
class XyoArchivistConfigWrapper {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.config = config;
|
|
7
|
+
}
|
|
8
|
+
get parent() {
|
|
9
|
+
var _a;
|
|
10
|
+
return (_a = this.config) === null || _a === void 0 ? void 0 : _a.parent;
|
|
11
|
+
}
|
|
12
|
+
get account() {
|
|
13
|
+
var _a;
|
|
14
|
+
return (_a = this.config) === null || _a === void 0 ? void 0 : _a.account;
|
|
15
|
+
}
|
|
16
|
+
get writeThrough() {
|
|
17
|
+
var _a;
|
|
18
|
+
return (_a = this.config) === null || _a === void 0 ? void 0 : _a.writeThrough;
|
|
19
|
+
}
|
|
20
|
+
get cacheParentReads() {
|
|
21
|
+
var _a;
|
|
22
|
+
return (_a = this.config) === null || _a === void 0 ? void 0 : _a.cacheParentReads;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.XyoArchivistConfigWrapper = XyoArchivistConfigWrapper;
|
|
26
|
+
//# sourceMappingURL=XyoArchivistConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XyoArchivistConfig.js","sourceRoot":"","sources":["../../src/XyoArchivistConfig.ts"],"names":[],"mappings":";;;AAYA,MAAa,yBAAyB;IAEpC,YAAY,MAAU;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,IAAW,MAAM;;QACf,OAAO,MAAA,IAAI,CAAC,MAAM,0CAAE,MAAM,CAAA;IAC5B,CAAC;IAED,IAAW,OAAO;;QAChB,OAAO,MAAA,IAAI,CAAC,MAAM,0CAAE,OAAO,CAAA;IAC7B,CAAC;IAED,IAAW,YAAY;;QACrB,OAAO,MAAA,IAAI,CAAC,MAAM,0CAAE,YAAY,CAAA;IAClC,CAAC;IAED,IAAW,gBAAgB;;QACzB,OAAO,MAAA,IAAI,CAAC,MAAM,0CAAE,gBAAgB,CAAA;IACtC,CAAC;CACF;AArBD,8DAqBC"}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { XyoPayload } from '@xyo-network/payload';
|
|
2
|
-
import {
|
|
2
|
+
import { PromisableArray } from './model';
|
|
3
|
+
import { XyoArchivist } from './XyoArchivist';
|
|
4
|
+
import { XyoArchivistConfig, XyoArchivistConfigWrapper } from './XyoArchivistConfig';
|
|
3
5
|
import { XyoPayloadFindQuery } from './XyoPayloadFindFilter';
|
|
4
|
-
export
|
|
6
|
+
export interface XyoMemoryArchivistConfig<T extends XyoPayload = XyoPayload> extends XyoArchivistConfig<T> {
|
|
7
|
+
max?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class XyoMemoryArchivist<C extends XyoMemoryArchivistConfig<XyoPayload> = XyoMemoryArchivistConfig<XyoPayload>> extends XyoArchivistConfigWrapper<XyoPayload, C> implements XyoArchivist {
|
|
10
|
+
get max(): number;
|
|
5
11
|
private cache;
|
|
6
|
-
|
|
12
|
+
constructor(config?: C);
|
|
13
|
+
delete(hashes: string[]): PromisableArray<boolean>;
|
|
7
14
|
clear(): void | Promise<void>;
|
|
8
15
|
get(hashes: string[]): Promise<(XyoPayload | null)[]>;
|
|
9
|
-
insert(payloads: XyoPayload[]):
|
|
10
|
-
find<R extends XyoPayload = XyoPayload>(query: XyoPayloadFindQuery):
|
|
11
|
-
|
|
16
|
+
insert(payloads: XyoPayload[]): PromisableArray<XyoPayload>;
|
|
17
|
+
find<R extends XyoPayload = XyoPayload>(query: XyoPayloadFindQuery): PromisableArray<R>;
|
|
18
|
+
all(): Promise<XyoPayload[]> | XyoPayload[];
|
|
19
|
+
commit(): Promise<import("@xyo-network/payload").XyoPayloadBase[]>;
|
|
12
20
|
}
|
|
@@ -6,11 +6,15 @@ const sdk_js_1 = require("@xylabs/sdk-js");
|
|
|
6
6
|
const boundwitness_1 = require("@xyo-network/boundwitness");
|
|
7
7
|
const payload_1 = require("@xyo-network/payload");
|
|
8
8
|
const lru_cache_1 = tslib_1.__importDefault(require("lru-cache"));
|
|
9
|
-
const
|
|
10
|
-
class XyoMemoryArchivist extends
|
|
11
|
-
constructor() {
|
|
12
|
-
super(
|
|
13
|
-
this.cache = new lru_cache_1.default({ max:
|
|
9
|
+
const XyoArchivistConfig_1 = require("./XyoArchivistConfig");
|
|
10
|
+
class XyoMemoryArchivist extends XyoArchivistConfig_1.XyoArchivistConfigWrapper {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
super(config);
|
|
13
|
+
this.cache = new lru_cache_1.default({ max: this.max });
|
|
14
|
+
}
|
|
15
|
+
get max() {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
return (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.max) !== null && _b !== void 0 ? _b : 10000;
|
|
14
18
|
}
|
|
15
19
|
delete(hashes) {
|
|
16
20
|
return hashes.map((hash) => {
|
|
@@ -45,6 +49,9 @@ class XyoMemoryArchivist extends XyoArchivist_1.XyoArchivistBase {
|
|
|
45
49
|
});
|
|
46
50
|
return result;
|
|
47
51
|
}
|
|
52
|
+
all() {
|
|
53
|
+
return this.cache.dump().map((value) => value[1].value);
|
|
54
|
+
}
|
|
48
55
|
commit() {
|
|
49
56
|
var _a;
|
|
50
57
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XyoMemoryArchivist.js","sourceRoot":"","sources":["../../src/XyoMemoryArchivist.ts"],"names":[],"mappings":";;;;AAAA,2CAAyC;AACzC,4DAAmF;AACnF,kDAAoE;AACpE,kEAAgC;
|
|
1
|
+
{"version":3,"file":"XyoMemoryArchivist.js","sourceRoot":"","sources":["../../src/XyoMemoryArchivist.ts"],"names":[],"mappings":";;;;AAAA,2CAAyC;AACzC,4DAAmF;AACnF,kDAAoE;AACpE,kEAAgC;AAIhC,6DAAoF;AAOpF,MAAa,kBACX,SAAQ,8CAAwC;IAShD,YAAY,MAAU;QACpB,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,KAAK,GAAG,IAAI,mBAAQ,CAAqB,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IAClE,CAAC;IATD,IAAW,GAAG;;QACZ,OAAO,MAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,GAAG,mCAAI,KAAK,CAAA;IAClC,CAAC;IASM,MAAM,CAAC,MAAgB;QAC5B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE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,CAAC,CAAA;aACxB;QACH,CAAC,CAAC,CAAA;QACF,OAAO,MAAM,CAAA;IACf,CAAC;IAEM,GAAG;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IACzD,CAAC;IAEY,MAAM;;;YACjB,MAAM,MAAM,GAAG,IAAA,iBAAQ,EAAC,IAAI,CAAC,MAAM,EAAE,+BAA+B,CAAC,CAAA;YACrE,MAAM,OAAO,GAAG,IAAA,iBAAQ,EAAC,IAAI,CAAC,OAAO,EAAE,gCAAgC,CAAC,CAAA;YACxE,MAAM,QAAQ,GAAG,IAAA,iBAAQ,EAAC,MAAM,IAAI,CAAC,GAAG,EAAE,EAAE,mBAAmB,CAAC,CAAA;YAChE,MAAM,OAAO,GAAG,IAAI,qCAAsB,EAA+B,CAAA;YACzE,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAA;YACjE,MAAM,MAAM,GAAG,MAAM,CAAA,MAAA,MAAM,CAAC,MAAM,uDAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA,CAAA;YAC9D,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;YAClB,OAAO,MAAM,CAAA;;KACd;CACF;AAlED,gDAkEC"}
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./model"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./XyoArchivist"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./XyoArchivistConfig"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./XyoMemoryArchivist"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./XyoPayloadFindFilter"), exports);
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,kDAAuB;AACvB,yDAA8B;AAC9B,+DAAoC;AACpC,iEAAsC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,kDAAuB;AACvB,yDAA8B;AAC9B,+DAAoC;AACpC,+DAAoC;AACpC,iEAAsC"}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export declare type Promisable<T> = Promise<T> | T;
|
|
2
|
+
export declare type PromisableArray<T> = Promisable<T[]>;
|
|
3
|
+
export declare type OptionalPromisable<T> = Promisable<T | undefined>;
|
|
4
|
+
export declare type OptionalPromisableArray<T> = PromisableArray<T | undefined>;
|
|
5
|
+
export declare type NullablePromisable<T> = Promisable<T | null>;
|
|
6
|
+
export declare type NullablePromisableArray<T> = PromisableArray<T | null>;
|
|
7
|
+
export interface ReadArchivist<TReadResponse, TId = string> {
|
|
8
|
+
get(ids: TId[]): NullablePromisableArray<TReadResponse>;
|
|
9
|
+
all?(): PromisableArray<TReadResponse>;
|
|
10
|
+
}
|
|
11
|
+
export interface WriteArchivist<TReadResponse, TWriteResponse = TReadResponse, TWrite = TReadResponse, TId = string> {
|
|
12
|
+
insert(item: TWrite[]): PromisableArray<TWriteResponse>;
|
|
13
|
+
delete?(ids: TId[]): PromisableArray<boolean>;
|
|
7
14
|
clear?(): void;
|
|
8
15
|
}
|
|
16
|
+
export interface QueryArchivist<TReadResponse, TQueryResponse = TReadResponse, TQuery = unknown> {
|
|
17
|
+
find(query: TQuery): PromisableArray<TQueryResponse>;
|
|
18
|
+
}
|
|
19
|
+
export interface StashArchivist<TReadResponse> {
|
|
20
|
+
commit?(): PromisableArray<TReadResponse>;
|
|
21
|
+
}
|
|
22
|
+
export interface Archivist<TReadResponse, TWriteResponse = TReadResponse, TWrite = TReadResponse, TQueryResponse = TReadResponse, TQuery = unknown, TId = string> extends ReadArchivist<TReadResponse, TId>, QueryArchivist<TReadResponse, TQueryResponse, TQuery>, WriteArchivist<TReadResponse, TWriteResponse, TWrite, TId>, StashArchivist<TReadResponse> {
|
|
23
|
+
}
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import { XyoAccount } from '@xyo-network/account';
|
|
2
1
|
import { XyoPayload } from '@xyo-network/payload';
|
|
3
2
|
import { Archivist } from './model';
|
|
4
3
|
import { XyoPayloadFindQuery } from './XyoPayloadFindFilter';
|
|
5
4
|
export declare type XyoArchivist<T extends XyoPayload = XyoPayload> = Archivist<T, T, T, T, XyoPayloadFindQuery>;
|
|
6
|
-
export declare abstract class XyoArchivistBase<T extends XyoPayload = XyoPayload> implements XyoArchivist<T> {
|
|
7
|
-
protected parent?: XyoArchivist<T>;
|
|
8
|
-
protected account?: XyoAccount;
|
|
9
|
-
constructor(parent?: XyoArchivist<T>, account?: XyoAccount);
|
|
10
|
-
abstract insert(payloads: T[]): T[] | Promise<T[]>;
|
|
11
|
-
abstract find<R extends T = T>(query: XyoPayloadFindQuery): R[] | Promise<R[]>;
|
|
12
|
-
abstract get(hash: string[]): (T | null)[] | Promise<(T | null)[]>;
|
|
13
|
-
all(): T[] | Promise<T[]>;
|
|
14
|
-
delete(_hashes: string[]): boolean[] | Promise<boolean[]>;
|
|
15
|
-
clear(): void | Promise<void>;
|
|
16
|
-
commit(): void;
|
|
17
|
-
}
|
package/dist/esm/XyoArchivist.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
constructor(parent, account) {
|
|
3
|
-
this.parent = parent;
|
|
4
|
-
this.account = account;
|
|
5
|
-
}
|
|
6
|
-
all() {
|
|
7
|
-
throw Error('getAll not supported');
|
|
8
|
-
}
|
|
9
|
-
delete(_hashes) {
|
|
10
|
-
throw Error('delete not supported');
|
|
11
|
-
}
|
|
12
|
-
clear() {
|
|
13
|
-
throw Error('clear not supported');
|
|
14
|
-
}
|
|
15
|
-
commit() {
|
|
16
|
-
throw Error('commit not supported');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
export {};
|
|
19
2
|
//# sourceMappingURL=XyoArchivist.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XyoArchivist.js","sourceRoot":"","sources":["../../src/XyoArchivist.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"XyoArchivist.js","sourceRoot":"","sources":["../../src/XyoArchivist.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { XyoPayload } from '@xyo-network/payload';
|
|
2
|
+
import { XyoArchivist } from './XyoArchivist';
|
|
3
|
+
import { XyoArchivistConfigWrapper } from './XyoArchivistConfig';
|
|
4
|
+
import { XyoPayloadFindQuery } from './XyoPayloadFindFilter';
|
|
5
|
+
export declare abstract class XyoArchivistBase<T extends XyoPayload = XyoPayload> extends XyoArchivistConfigWrapper<T> implements XyoArchivist<T> {
|
|
6
|
+
abstract insert(payloads: T[]): T[] | Promise<T[]>;
|
|
7
|
+
abstract find<R extends T = T>(query: XyoPayloadFindQuery): R[] | Promise<R[]>;
|
|
8
|
+
abstract get(hash: string[]): (T | null)[] | Promise<(T | null)[]>;
|
|
9
|
+
all(): T[] | Promise<T[]>;
|
|
10
|
+
delete(_hashes: string[]): boolean[] | Promise<boolean[]>;
|
|
11
|
+
clear(): void | Promise<void>;
|
|
12
|
+
commit(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { XyoArchivistConfigWrapper } from './XyoArchivistConfig';
|
|
2
|
+
export class XyoArchivistBase extends XyoArchivistConfigWrapper {
|
|
3
|
+
all() {
|
|
4
|
+
throw Error('getAll not supported');
|
|
5
|
+
}
|
|
6
|
+
delete(_hashes) {
|
|
7
|
+
throw Error('delete not supported');
|
|
8
|
+
}
|
|
9
|
+
clear() {
|
|
10
|
+
throw Error('clear not supported');
|
|
11
|
+
}
|
|
12
|
+
commit() {
|
|
13
|
+
throw Error('commit not supported');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=XyoArchivistBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XyoArchivistBase.js","sourceRoot":"","sources":["../../src/XyoArchivistBase.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAGhE,MAAM,OAAgB,gBAAoD,SAAQ,yBAA4B;IAIrG,GAAG;QACR,MAAM,KAAK,CAAC,sBAAsB,CAAC,CAAA;IACrC,CAAC;IACM,MAAM,CAAC,OAAiB;QAC7B,MAAM,KAAK,CAAC,sBAAsB,CAAC,CAAA;IACrC,CAAC;IACM,KAAK;QACV,MAAM,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACpC,CAAC;IACM,MAAM;QACX,MAAM,KAAK,CAAC,sBAAsB,CAAC,CAAA;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { XyoAccount } from '@xyo-network/account';
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload';
|
|
3
|
+
import { XyoArchivist } from './XyoArchivist';
|
|
4
|
+
export interface XyoArchivistConfig<T extends XyoPayload = XyoPayload> {
|
|
5
|
+
parent?: XyoArchivist<T>;
|
|
6
|
+
account?: XyoAccount;
|
|
7
|
+
cacheParentReads?: boolean;
|
|
8
|
+
writeThrough?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class XyoArchivistConfigWrapper<T extends XyoPayload = XyoPayload, C extends XyoArchivistConfig<T> = XyoArchivistConfig<T>> {
|
|
11
|
+
protected config?: C;
|
|
12
|
+
constructor(config?: C);
|
|
13
|
+
get parent(): XyoArchivist<T> | undefined;
|
|
14
|
+
get account(): XyoAccount | undefined;
|
|
15
|
+
get writeThrough(): boolean | undefined;
|
|
16
|
+
get cacheParentReads(): boolean | undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class XyoArchivistConfigWrapper {
|
|
2
|
+
constructor(config) {
|
|
3
|
+
this.config = config;
|
|
4
|
+
}
|
|
5
|
+
get parent() {
|
|
6
|
+
return this.config?.parent;
|
|
7
|
+
}
|
|
8
|
+
get account() {
|
|
9
|
+
return this.config?.account;
|
|
10
|
+
}
|
|
11
|
+
get writeThrough() {
|
|
12
|
+
return this.config?.writeThrough;
|
|
13
|
+
}
|
|
14
|
+
get cacheParentReads() {
|
|
15
|
+
return this.config?.cacheParentReads;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=XyoArchivistConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XyoArchivistConfig.js","sourceRoot":"","sources":["../../src/XyoArchivistConfig.ts"],"names":[],"mappings":"AAYA,MAAM,OAAO,yBAAyB;IAEpC,YAAY,MAAU;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,MAAM,EAAE,MAAM,CAAA;IAC5B,CAAC;IAED,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,CAAA;IAC7B,CAAC;IAED,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,MAAM,EAAE,YAAY,CAAA;IAClC,CAAC;IAED,IAAW,gBAAgB;QACzB,OAAO,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAA;IACtC,CAAC;CACF"}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { XyoPayload } from '@xyo-network/payload';
|
|
2
|
-
import {
|
|
2
|
+
import { PromisableArray } from './model';
|
|
3
|
+
import { XyoArchivist } from './XyoArchivist';
|
|
4
|
+
import { XyoArchivistConfig, XyoArchivistConfigWrapper } from './XyoArchivistConfig';
|
|
3
5
|
import { XyoPayloadFindQuery } from './XyoPayloadFindFilter';
|
|
4
|
-
export
|
|
6
|
+
export interface XyoMemoryArchivistConfig<T extends XyoPayload = XyoPayload> extends XyoArchivistConfig<T> {
|
|
7
|
+
max?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class XyoMemoryArchivist<C extends XyoMemoryArchivistConfig<XyoPayload> = XyoMemoryArchivistConfig<XyoPayload>> extends XyoArchivistConfigWrapper<XyoPayload, C> implements XyoArchivist {
|
|
10
|
+
get max(): number;
|
|
5
11
|
private cache;
|
|
6
|
-
|
|
12
|
+
constructor(config?: C);
|
|
13
|
+
delete(hashes: string[]): PromisableArray<boolean>;
|
|
7
14
|
clear(): void | Promise<void>;
|
|
8
15
|
get(hashes: string[]): Promise<(XyoPayload | null)[]>;
|
|
9
|
-
insert(payloads: XyoPayload[]):
|
|
10
|
-
find<R extends XyoPayload = XyoPayload>(query: XyoPayloadFindQuery):
|
|
11
|
-
|
|
16
|
+
insert(payloads: XyoPayload[]): PromisableArray<XyoPayload>;
|
|
17
|
+
find<R extends XyoPayload = XyoPayload>(query: XyoPayloadFindQuery): PromisableArray<R>;
|
|
18
|
+
all(): Promise<XyoPayload[]> | XyoPayload[];
|
|
19
|
+
commit(): Promise<import("@xyo-network/payload").XyoPayloadBase[]>;
|
|
12
20
|
}
|
|
@@ -2,11 +2,14 @@ import { assertEx } from '@xylabs/sdk-js';
|
|
|
2
2
|
import { XyoBoundWitnessBuilder } from '@xyo-network/boundwitness';
|
|
3
3
|
import { XyoPayloadWrapper } from '@xyo-network/payload';
|
|
4
4
|
import LruCache from 'lru-cache';
|
|
5
|
-
import {
|
|
6
|
-
export class XyoMemoryArchivist extends
|
|
7
|
-
constructor() {
|
|
8
|
-
super(
|
|
9
|
-
this.cache = new LruCache({ max:
|
|
5
|
+
import { XyoArchivistConfigWrapper } from './XyoArchivistConfig';
|
|
6
|
+
export class XyoMemoryArchivist extends XyoArchivistConfigWrapper {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super(config);
|
|
9
|
+
this.cache = new LruCache({ max: this.max });
|
|
10
|
+
}
|
|
11
|
+
get max() {
|
|
12
|
+
return this.config?.max ?? 10000;
|
|
10
13
|
}
|
|
11
14
|
delete(hashes) {
|
|
12
15
|
return hashes.map((hash) => {
|
|
@@ -38,6 +41,9 @@ export class XyoMemoryArchivist extends XyoArchivistBase {
|
|
|
38
41
|
});
|
|
39
42
|
return result;
|
|
40
43
|
}
|
|
44
|
+
all() {
|
|
45
|
+
return this.cache.dump().map((value) => value[1].value);
|
|
46
|
+
}
|
|
41
47
|
async commit() {
|
|
42
48
|
const parent = assertEx(this.parent, 'Parent is required for commit');
|
|
43
49
|
const account = assertEx(this.account, 'Account is required for commit');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XyoMemoryArchivist.js","sourceRoot":"","sources":["../../src/XyoMemoryArchivist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAmB,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AACnF,OAAO,EAAc,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACpE,OAAO,QAAQ,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"XyoMemoryArchivist.js","sourceRoot":"","sources":["../../src/XyoMemoryArchivist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAmB,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AACnF,OAAO,EAAc,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACpE,OAAO,QAAQ,MAAM,WAAW,CAAA;AAIhC,OAAO,EAAsB,yBAAyB,EAAE,MAAM,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O,MAAM,CAAA;IACf,CAAC;CACF"}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA"}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export declare type Promisable<T> = Promise<T> | T;
|
|
2
|
+
export declare type PromisableArray<T> = Promisable<T[]>;
|
|
3
|
+
export declare type OptionalPromisable<T> = Promisable<T | undefined>;
|
|
4
|
+
export declare type OptionalPromisableArray<T> = PromisableArray<T | undefined>;
|
|
5
|
+
export declare type NullablePromisable<T> = Promisable<T | null>;
|
|
6
|
+
export declare type NullablePromisableArray<T> = PromisableArray<T | null>;
|
|
7
|
+
export interface ReadArchivist<TReadResponse, TId = string> {
|
|
8
|
+
get(ids: TId[]): NullablePromisableArray<TReadResponse>;
|
|
9
|
+
all?(): PromisableArray<TReadResponse>;
|
|
10
|
+
}
|
|
11
|
+
export interface WriteArchivist<TReadResponse, TWriteResponse = TReadResponse, TWrite = TReadResponse, TId = string> {
|
|
12
|
+
insert(item: TWrite[]): PromisableArray<TWriteResponse>;
|
|
13
|
+
delete?(ids: TId[]): PromisableArray<boolean>;
|
|
7
14
|
clear?(): void;
|
|
8
15
|
}
|
|
16
|
+
export interface QueryArchivist<TReadResponse, TQueryResponse = TReadResponse, TQuery = unknown> {
|
|
17
|
+
find(query: TQuery): PromisableArray<TQueryResponse>;
|
|
18
|
+
}
|
|
19
|
+
export interface StashArchivist<TReadResponse> {
|
|
20
|
+
commit?(): PromisableArray<TReadResponse>;
|
|
21
|
+
}
|
|
22
|
+
export interface Archivist<TReadResponse, TWriteResponse = TReadResponse, TWrite = TReadResponse, TQueryResponse = TReadResponse, TQuery = unknown, TId = string> extends ReadArchivist<TReadResponse, TId>, QueryArchivist<TReadResponse, TQueryResponse, TQuery>, WriteArchivist<TReadResponse, TWriteResponse, TWrite, TId>, StashArchivist<TReadResponse> {
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xylabs/sdk-js": "^2.6.2",
|
|
13
|
-
"@xyo-network/account": "^2.22.
|
|
14
|
-
"@xyo-network/boundwitness": "^2.22.
|
|
15
|
-
"@xyo-network/core": "^2.22.
|
|
16
|
-
"@xyo-network/payload": "^2.22.
|
|
13
|
+
"@xyo-network/account": "^2.22.12",
|
|
14
|
+
"@xyo-network/boundwitness": "^2.22.12",
|
|
15
|
+
"@xyo-network/core": "^2.22.12",
|
|
16
|
+
"@xyo-network/payload": "^2.22.12",
|
|
17
17
|
"axios": "^0.27.2",
|
|
18
18
|
"lru-cache": "^7.13.1",
|
|
19
19
|
"pako": "^2.0.4"
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
},
|
|
57
57
|
"sideEffects": true,
|
|
58
58
|
"types": "dist/esm/index.d.ts",
|
|
59
|
-
"version": "2.22.
|
|
59
|
+
"version": "2.22.12",
|
|
60
60
|
"packageManager": "yarn@3.1.1"
|
|
61
61
|
}
|
package/src/XyoArchivist.ts
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
import { XyoAccount } from '@xyo-network/account'
|
|
2
1
|
import { XyoPayload } from '@xyo-network/payload'
|
|
3
2
|
|
|
4
3
|
import { Archivist } from './model'
|
|
5
4
|
import { XyoPayloadFindQuery } from './XyoPayloadFindFilter'
|
|
6
5
|
|
|
7
6
|
export type XyoArchivist<T extends XyoPayload = XyoPayload> = Archivist<T, T, T, T, XyoPayloadFindQuery>
|
|
8
|
-
|
|
9
|
-
export abstract class XyoArchivistBase<T extends XyoPayload = XyoPayload> implements XyoArchivist<T> {
|
|
10
|
-
protected parent?: XyoArchivist<T>
|
|
11
|
-
protected account?: XyoAccount
|
|
12
|
-
constructor(parent?: XyoArchivist<T>, account?: XyoAccount) {
|
|
13
|
-
this.parent = parent
|
|
14
|
-
this.account = account
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
abstract insert(payloads: T[]): T[] | Promise<T[]>
|
|
18
|
-
abstract find<R extends T = T>(query: XyoPayloadFindQuery): R[] | Promise<R[]>
|
|
19
|
-
abstract get(hash: string[]): (T | null)[] | Promise<(T | null)[]>
|
|
20
|
-
public all(): T[] | Promise<T[]> {
|
|
21
|
-
throw Error('getAll not supported')
|
|
22
|
-
}
|
|
23
|
-
public delete(_hashes: string[]): boolean[] | Promise<boolean[]> {
|
|
24
|
-
throw Error('delete not supported')
|
|
25
|
-
}
|
|
26
|
-
public clear(): void | Promise<void> {
|
|
27
|
-
throw Error('clear not supported')
|
|
28
|
-
}
|
|
29
|
-
public commit() {
|
|
30
|
-
throw Error('commit not supported')
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { XyoAccount } from '@xyo-network/account'
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload'
|
|
3
|
+
|
|
4
|
+
import { XyoArchivist } from './XyoArchivist'
|
|
5
|
+
|
|
6
|
+
export interface XyoArchivistConfig<T extends XyoPayload = XyoPayload> {
|
|
7
|
+
parent?: XyoArchivist<T>
|
|
8
|
+
account?: XyoAccount
|
|
9
|
+
cacheParentReads?: boolean
|
|
10
|
+
writeThrough?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class XyoArchivistConfigWrapper<T extends XyoPayload = XyoPayload, C extends XyoArchivistConfig<T> = XyoArchivistConfig<T>> {
|
|
14
|
+
protected config?: C
|
|
15
|
+
constructor(config?: C) {
|
|
16
|
+
this.config = config
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public get parent() {
|
|
20
|
+
return this.config?.parent
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public get account() {
|
|
24
|
+
return this.config?.account
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public get writeThrough() {
|
|
28
|
+
return this.config?.writeThrough
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public get cacheParentReads() {
|
|
32
|
+
return this.config?.cacheParentReads
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -3,13 +3,31 @@ import { XyoBoundWitness, XyoBoundWitnessBuilder } from '@xyo-network/boundwitne
|
|
|
3
3
|
import { XyoPayload, XyoPayloadWrapper } from '@xyo-network/payload'
|
|
4
4
|
import LruCache from 'lru-cache'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { PromisableArray } from './model'
|
|
7
|
+
import { XyoArchivist } from './XyoArchivist'
|
|
8
|
+
import { XyoArchivistConfig, XyoArchivistConfigWrapper } from './XyoArchivistConfig'
|
|
7
9
|
import { XyoPayloadFindQuery } from './XyoPayloadFindFilter'
|
|
8
10
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
+
export interface XyoMemoryArchivistConfig<T extends XyoPayload = XyoPayload> extends XyoArchivistConfig<T> {
|
|
12
|
+
max?: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class XyoMemoryArchivist<C extends XyoMemoryArchivistConfig<XyoPayload> = XyoMemoryArchivistConfig<XyoPayload>>
|
|
16
|
+
extends XyoArchivistConfigWrapper<XyoPayload, C>
|
|
17
|
+
implements XyoArchivist
|
|
18
|
+
{
|
|
19
|
+
public get max() {
|
|
20
|
+
return this.config?.max ?? 10000
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private cache: LruCache<string, XyoPayload>
|
|
11
24
|
|
|
12
|
-
|
|
25
|
+
constructor(config?: C) {
|
|
26
|
+
super(config)
|
|
27
|
+
this.cache = new LruCache<string, XyoPayload>({ max: this.max })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public delete(hashes: string[]): PromisableArray<boolean> {
|
|
13
31
|
return hashes.map((hash) => {
|
|
14
32
|
return this.cache.delete(hash)
|
|
15
33
|
})
|
|
@@ -27,7 +45,7 @@ export class XyoMemoryArchivist extends XyoArchivistBase<XyoPayload> {
|
|
|
27
45
|
)
|
|
28
46
|
}
|
|
29
47
|
|
|
30
|
-
public insert(payloads: XyoPayload[]):
|
|
48
|
+
public insert(payloads: XyoPayload[]): PromisableArray<XyoPayload> {
|
|
31
49
|
return payloads.map((payload) => {
|
|
32
50
|
const wrapper = new XyoPayloadWrapper(payload)
|
|
33
51
|
const payloadWithmeta = { ...payload, _hash: wrapper.hash, _timestamp: Date.now() }
|
|
@@ -36,7 +54,7 @@ export class XyoMemoryArchivist extends XyoArchivistBase<XyoPayload> {
|
|
|
36
54
|
})
|
|
37
55
|
}
|
|
38
56
|
|
|
39
|
-
public find<R extends XyoPayload = XyoPayload>(query: XyoPayloadFindQuery):
|
|
57
|
+
public find<R extends XyoPayload = XyoPayload>(query: XyoPayloadFindQuery): PromisableArray<R> {
|
|
40
58
|
const result: R[] = []
|
|
41
59
|
this.cache.forEach((value) => {
|
|
42
60
|
if (value.schema === query.filter.schema) {
|
|
@@ -46,6 +64,10 @@ export class XyoMemoryArchivist extends XyoArchivistBase<XyoPayload> {
|
|
|
46
64
|
return result
|
|
47
65
|
}
|
|
48
66
|
|
|
67
|
+
public all(): Promise<XyoPayload[]> | XyoPayload[] {
|
|
68
|
+
return this.cache.dump().map((value) => value[1].value)
|
|
69
|
+
}
|
|
70
|
+
|
|
49
71
|
public async commit() {
|
|
50
72
|
const parent = assertEx(this.parent, 'Parent is required for commit')
|
|
51
73
|
const account = assertEx(this.account, 'Account is required for commit')
|
package/src/index.ts
CHANGED
package/src/model/Archivist.ts
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export type Promisable<T> = Promise<T> | T
|
|
2
|
+
export type PromisableArray<T> = Promisable<T[]>
|
|
3
|
+
export type OptionalPromisable<T> = Promisable<T | undefined>
|
|
4
|
+
export type OptionalPromisableArray<T> = PromisableArray<T | undefined>
|
|
5
|
+
export type NullablePromisable<T> = Promisable<T | null>
|
|
6
|
+
export type NullablePromisableArray<T> = PromisableArray<T | null>
|
|
7
|
+
|
|
8
|
+
export interface ReadArchivist<TReadResponse, TId = string> {
|
|
9
|
+
get(ids: TId[]): NullablePromisableArray<TReadResponse>
|
|
10
|
+
all?(): PromisableArray<TReadResponse>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface WriteArchivist<TReadResponse, TWriteResponse = TReadResponse, TWrite = TReadResponse, TId = string> {
|
|
14
|
+
insert(item: TWrite[]): PromisableArray<TWriteResponse>
|
|
15
|
+
delete?(ids: TId[]): PromisableArray<boolean>
|
|
7
16
|
clear?(): void
|
|
8
17
|
}
|
|
18
|
+
|
|
19
|
+
export interface QueryArchivist<TReadResponse, TQueryResponse = TReadResponse, TQuery = unknown> {
|
|
20
|
+
find(query: TQuery): PromisableArray<TQueryResponse>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface StashArchivist<TReadResponse> {
|
|
24
|
+
commit?(): PromisableArray<TReadResponse>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface Archivist<TReadResponse, TWriteResponse = TReadResponse, TWrite = TReadResponse, TQueryResponse = TReadResponse, TQuery = unknown, TId = string>
|
|
28
|
+
extends ReadArchivist<TReadResponse, TId>,
|
|
29
|
+
QueryArchivist<TReadResponse, TQueryResponse, TQuery>,
|
|
30
|
+
WriteArchivist<TReadResponse, TWriteResponse, TWrite, TId>,
|
|
31
|
+
StashArchivist<TReadResponse> {}
|