@xyo-network/archivist-memory 3.7.2 → 3.8.1
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/neutral/index.d.ts +42 -3
- package/dist/neutral/index.mjs +3 -3
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +13 -13
- package/src/Archivist.ts +3 -3
- package/dist/neutral/Archivist.d.ts +0 -33
- package/dist/neutral/Archivist.d.ts.map +0 -1
- package/dist/neutral/Config.d.ts +0 -9
- package/dist/neutral/Config.d.ts.map +0 -1
- package/dist/neutral/index.d.ts.map +0 -1
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as _xylabs_object from '@xylabs/object';
|
|
2
|
+
import { EmptyObject, WithAdditional } from '@xylabs/object';
|
|
3
|
+
import { Hash } from '@xylabs/hex';
|
|
4
|
+
import { Promisable } from '@xylabs/promise';
|
|
5
|
+
import { AbstractArchivist } from '@xyo-network/archivist-abstract';
|
|
6
|
+
import { ArchivistConfig, ArchivistModuleEventData, AttachableArchivistInstance, ArchivistNextOptions } from '@xyo-network/archivist-model';
|
|
7
|
+
import { BoundWitness } from '@xyo-network/boundwitness-model';
|
|
8
|
+
import { AnyConfigSchema, ModuleParams, ModuleInstance } from '@xyo-network/module-model';
|
|
9
|
+
import { Payload, Schema, WithStorageMeta } from '@xyo-network/payload-model';
|
|
10
|
+
import { LRUCache } from 'lru-cache';
|
|
11
|
+
|
|
12
|
+
declare const MemoryArchivistConfigSchema: "network.xyo.archivist.memory.config";
|
|
13
|
+
type MemoryArchivistConfigSchema = typeof MemoryArchivistConfigSchema;
|
|
14
|
+
type MemoryArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchema extends Schema | void = void> = ArchivistConfig<WithAdditional<{
|
|
15
|
+
max?: number;
|
|
16
|
+
}, TConfig>, TSchema extends Schema ? TSchema : MemoryArchivistConfigSchema | ArchivistConfig['schema']>;
|
|
17
|
+
|
|
18
|
+
type MemoryArchivistParams<TConfig extends AnyConfigSchema<MemoryArchivistConfig> = AnyConfigSchema<MemoryArchivistConfig>> = ModuleParams<TConfig>;
|
|
19
|
+
declare class MemoryArchivist<TParams extends MemoryArchivistParams<AnyConfigSchema<MemoryArchivistConfig>> = MemoryArchivistParams, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends AbstractArchivist<TParams, TEventData> implements AttachableArchivistInstance, ModuleInstance {
|
|
20
|
+
static readonly configSchemas: Schema[];
|
|
21
|
+
static readonly defaultConfigSchema: Schema;
|
|
22
|
+
private _cache?;
|
|
23
|
+
private _dataHashIndex?;
|
|
24
|
+
get queries(): string[];
|
|
25
|
+
protected get cache(): LRUCache<Lowercase<string>, WithStorageMeta<_xylabs_object.DeepRestrictToStringKeys<{
|
|
26
|
+
schema: Schema;
|
|
27
|
+
}>>, unknown>;
|
|
28
|
+
protected get dataHashIndex(): LRUCache<Lowercase<string>, Lowercase<string>, unknown>;
|
|
29
|
+
protected get max(): number;
|
|
30
|
+
private static findIndexFromCursor;
|
|
31
|
+
protected allHandler(): Promisable<WithStorageMeta<Payload>[]>;
|
|
32
|
+
protected clearHandler(): void | Promise<void>;
|
|
33
|
+
protected commitHandler(): Promise<BoundWitness[]>;
|
|
34
|
+
protected deleteHandler(hashes: Hash[]): Promise<Hash[]>;
|
|
35
|
+
protected getHandler(hashes: Hash[]): Promisable<WithStorageMeta<Payload>[]>;
|
|
36
|
+
protected insertHandler(payloads: WithStorageMeta<Payload>[]): WithStorageMeta<Payload>[];
|
|
37
|
+
protected nextHandler(options?: ArchivistNextOptions): Promise<WithStorageMeta<Payload>[]>;
|
|
38
|
+
private insertPayloadIntoCache;
|
|
39
|
+
private rebuildDataHashIndex;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { MemoryArchivist, type MemoryArchivistConfig, MemoryArchivistConfigSchema, type MemoryArchivistParams };
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -111,14 +111,14 @@ var MemoryArchivist = class extends AbstractArchivist {
|
|
|
111
111
|
}).filter(exists);
|
|
112
112
|
}
|
|
113
113
|
insertHandler(payloads) {
|
|
114
|
-
const payloadsWithMeta = payloads.
|
|
114
|
+
const payloadsWithMeta = payloads.toSorted(PayloadBuilder.compareStorageMeta);
|
|
115
115
|
return payloadsWithMeta.map((payload) => {
|
|
116
116
|
return this.insertPayloadIntoCache(payload);
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
async nextHandler(options) {
|
|
120
120
|
const {
|
|
121
|
-
limit,
|
|
121
|
+
limit = 100,
|
|
122
122
|
cursor,
|
|
123
123
|
order,
|
|
124
124
|
open
|
|
@@ -128,7 +128,7 @@ var MemoryArchivist = class extends AbstractArchivist {
|
|
|
128
128
|
all = all.reverse();
|
|
129
129
|
}
|
|
130
130
|
const startIndex = cursor ? MemoryArchivist.findIndexFromCursor(all, cursor) + (open ? 0 : 1) : 0;
|
|
131
|
-
const result = all.slice(startIndex,
|
|
131
|
+
const result = all.slice(startIndex, startIndex + limit);
|
|
132
132
|
return result;
|
|
133
133
|
}
|
|
134
134
|
insertPayloadIntoCache(payload) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Archivist.ts","../../src/Config.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Hash, Hex } from '@xylabs/hex'\nimport { fulfilled, Promisable } from '@xylabs/promise'\nimport { AbstractArchivist } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistCommitQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuery,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistNextOptions,\n ArchivistNextQuerySchema,\n AttachableArchivistInstance,\n} from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport {\n AnyConfigSchema, creatableModule, ModuleInstance, ModuleParams,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport {\n Payload, Schema, WithStorageMeta,\n} from '@xyo-network/payload-model'\nimport { LRUCache } from 'lru-cache'\n\nimport { MemoryArchivistConfig, MemoryArchivistConfigSchema } from './Config.ts'\n\nexport type MemoryArchivistParams<TConfig extends AnyConfigSchema<MemoryArchivistConfig> = AnyConfigSchema<MemoryArchivistConfig>> =\n ModuleParams<TConfig>\n@creatableModule()\nexport class MemoryArchivist<\n TParams extends MemoryArchivistParams<AnyConfigSchema<MemoryArchivistConfig>> = MemoryArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n>\n extends AbstractArchivist<TParams, TEventData>\n implements AttachableArchivistInstance, ModuleInstance {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, MemoryArchivistConfigSchema]\n static override readonly defaultConfigSchema: Schema = MemoryArchivistConfigSchema\n\n private _cache?: LRUCache<Hash, WithStorageMeta<Payload>>\n private _dataHashIndex?: LRUCache<Hash, Hash>\n\n override get queries() {\n return [\n ArchivistAllQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistCommitQuerySchema,\n ArchivistNextQuerySchema,\n ...super.queries,\n ]\n }\n\n protected get cache() {\n this._cache = this._cache ?? new LRUCache<Hash, WithStorageMeta<Payload>>({ max: this.max })\n return this._cache\n }\n\n protected get dataHashIndex() {\n this._dataHashIndex = this._dataHashIndex ?? new LRUCache<Hash, Hash>({ max: this.max })\n return this._dataHashIndex\n }\n\n protected get max() {\n return this.config?.max ?? 10_000\n }\n\n private static findIndexFromCursor(payloads: WithStorageMeta[], cursor: Hex) {\n const index = payloads.findIndex(({ _sequence }) => _sequence === cursor)\n if (index === -1) {\n return Infinity // move to the end\n }\n return index\n }\n\n protected override allHandler(): Promisable<WithStorageMeta<Payload>[]> {\n return [...this.cache.values()].filter(exists).sort(PayloadBuilder.compareStorageMeta)\n }\n\n protected override clearHandler(): void | Promise<void> {\n this.cache.clear()\n this.dataHashIndex.clear()\n return this.emit('cleared', { mod: this })\n }\n\n protected override async commitHandler(): Promise<BoundWitness[]> {\n const payloads = assertEx(await this.allHandler(), () => 'Nothing to commit')\n const settled = await Promise.allSettled(\n Object.values((await this.parentArchivists()).commit ?? [])?.map(async (parent) => {\n const queryPayload: ArchivistInsertQuery = { schema: ArchivistInsertQuerySchema }\n const query = await this.bindQuery(queryPayload, payloads)\n return (await parent?.query(query[0], query[1]))?.[0]\n }).filter(exists),\n )\n await this.clearHandler()\n return settled.filter(fulfilled).map(result => result.value).filter(exists)\n }\n\n protected override async deleteHandler(hashes: Hash[]): Promise<Hash[]> {\n const deletedHashes: Hash[] = (await Promise.all(this.cache\n .dump()\n .map(async ([key, item]) => {\n const itemValueDataHash = await PayloadBuilder.dataHash(item.value)\n if (hashes.includes(key) || hashes.includes(itemValueDataHash)) {\n this.cache.delete(key)\n return key\n }\n })))\n .filter(exists)\n this.rebuildDataHashIndex()\n return deletedHashes\n }\n\n protected override getHandler(hashes: Hash[]): Promisable<WithStorageMeta<Payload>[]> {\n return hashes.map((hash) => {\n const resolvedHash = this.dataHashIndex.get(hash) ?? hash\n const result = this.cache.get(resolvedHash)\n if (resolvedHash !== hash && !result) {\n throw new Error('Missing referenced payload')\n }\n return result\n }).filter(exists)\n }\n\n protected override insertHandler(payloads: WithStorageMeta<Payload>[]): WithStorageMeta<Payload>[] {\n const payloadsWithMeta = payloads.
|
|
1
|
+
{"version":3,"sources":["../../src/Archivist.ts","../../src/Config.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Hash, Hex } from '@xylabs/hex'\nimport { fulfilled, Promisable } from '@xylabs/promise'\nimport { AbstractArchivist } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistCommitQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistInsertQuery,\n ArchivistInsertQuerySchema,\n ArchivistModuleEventData,\n ArchivistNextOptions,\n ArchivistNextQuerySchema,\n AttachableArchivistInstance,\n} from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport {\n AnyConfigSchema, creatableModule, ModuleInstance, ModuleParams,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport {\n Payload, Schema, WithStorageMeta,\n} from '@xyo-network/payload-model'\nimport { LRUCache } from 'lru-cache'\n\nimport { MemoryArchivistConfig, MemoryArchivistConfigSchema } from './Config.ts'\n\nexport type MemoryArchivistParams<TConfig extends AnyConfigSchema<MemoryArchivistConfig> = AnyConfigSchema<MemoryArchivistConfig>> =\n ModuleParams<TConfig>\n@creatableModule()\nexport class MemoryArchivist<\n TParams extends MemoryArchivistParams<AnyConfigSchema<MemoryArchivistConfig>> = MemoryArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n>\n extends AbstractArchivist<TParams, TEventData>\n implements AttachableArchivistInstance, ModuleInstance {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, MemoryArchivistConfigSchema]\n static override readonly defaultConfigSchema: Schema = MemoryArchivistConfigSchema\n\n private _cache?: LRUCache<Hash, WithStorageMeta<Payload>>\n private _dataHashIndex?: LRUCache<Hash, Hash>\n\n override get queries() {\n return [\n ArchivistAllQuerySchema,\n ArchivistDeleteQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistInsertQuerySchema,\n ArchivistCommitQuerySchema,\n ArchivistNextQuerySchema,\n ...super.queries,\n ]\n }\n\n protected get cache() {\n this._cache = this._cache ?? new LRUCache<Hash, WithStorageMeta<Payload>>({ max: this.max })\n return this._cache\n }\n\n protected get dataHashIndex() {\n this._dataHashIndex = this._dataHashIndex ?? new LRUCache<Hash, Hash>({ max: this.max })\n return this._dataHashIndex\n }\n\n protected get max() {\n return this.config?.max ?? 10_000\n }\n\n private static findIndexFromCursor(payloads: WithStorageMeta[], cursor: Hex) {\n const index = payloads.findIndex(({ _sequence }) => _sequence === cursor)\n if (index === -1) {\n return Infinity // move to the end\n }\n return index\n }\n\n protected override allHandler(): Promisable<WithStorageMeta<Payload>[]> {\n return [...this.cache.values()].filter(exists).sort(PayloadBuilder.compareStorageMeta)\n }\n\n protected override clearHandler(): void | Promise<void> {\n this.cache.clear()\n this.dataHashIndex.clear()\n return this.emit('cleared', { mod: this })\n }\n\n protected override async commitHandler(): Promise<BoundWitness[]> {\n const payloads = assertEx(await this.allHandler(), () => 'Nothing to commit')\n const settled = await Promise.allSettled(\n Object.values((await this.parentArchivists()).commit ?? [])?.map(async (parent) => {\n const queryPayload: ArchivistInsertQuery = { schema: ArchivistInsertQuerySchema }\n const query = await this.bindQuery(queryPayload, payloads)\n return (await parent?.query(query[0], query[1]))?.[0]\n }).filter(exists),\n )\n await this.clearHandler()\n return settled.filter(fulfilled).map(result => result.value).filter(exists)\n }\n\n protected override async deleteHandler(hashes: Hash[]): Promise<Hash[]> {\n const deletedHashes: Hash[] = (await Promise.all(this.cache\n .dump()\n .map(async ([key, item]) => {\n const itemValueDataHash = await PayloadBuilder.dataHash(item.value)\n if (hashes.includes(key) || hashes.includes(itemValueDataHash)) {\n this.cache.delete(key)\n return key\n }\n })))\n .filter(exists)\n this.rebuildDataHashIndex()\n return deletedHashes\n }\n\n protected override getHandler(hashes: Hash[]): Promisable<WithStorageMeta<Payload>[]> {\n return hashes.map((hash) => {\n const resolvedHash = this.dataHashIndex.get(hash) ?? hash\n const result = this.cache.get(resolvedHash)\n if (resolvedHash !== hash && !result) {\n throw new Error('Missing referenced payload')\n }\n return result\n }).filter(exists)\n }\n\n protected override insertHandler(payloads: WithStorageMeta<Payload>[]): WithStorageMeta<Payload>[] {\n const payloadsWithMeta = payloads.toSorted(PayloadBuilder.compareStorageMeta)\n return payloadsWithMeta.map((payload) => {\n return this.insertPayloadIntoCache(payload)\n })\n }\n\n protected override async nextHandler(options?: ArchivistNextOptions): Promise<WithStorageMeta<Payload>[]> {\n const {\n limit = 100, cursor, order, open,\n } = options ?? {}\n let all = await this.allHandler()\n if (order === 'desc') {\n all = all.reverse()\n }\n const startIndex = cursor\n ? MemoryArchivist.findIndexFromCursor(all, cursor) + (open ? 0 : 1)\n : 0\n const result = all.slice(startIndex, startIndex + limit)\n return result\n }\n\n private insertPayloadIntoCache(payload: WithStorageMeta<Payload>): WithStorageMeta<Payload> {\n this.cache.set(payload._hash, payload)\n this.dataHashIndex.set(payload._dataHash, payload._hash)\n return payload\n }\n\n private rebuildDataHashIndex() {\n this._dataHashIndex = new LRUCache<Hash, Hash>({ max: this.max })\n const payloads = this.cache.dump().map(([, item]) => item.value)\n for (const payload of payloads) {\n this.dataHashIndex.set(payload._dataHash, payload._hash)\n }\n }\n}\n","import type { EmptyObject, WithAdditional } from '@xylabs/object'\nimport type { ArchivistConfig } from '@xyo-network/archivist-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\n\nexport const MemoryArchivistConfigSchema = 'network.xyo.archivist.memory.config' as const\nexport type MemoryArchivistConfigSchema = typeof MemoryArchivistConfigSchema\n\nexport type MemoryArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchema extends Schema | void = void> = ArchivistConfig<\n WithAdditional<\n {\n max?: number\n },\n TConfig\n >,\n TSchema extends Schema ? TSchema : MemoryArchivistConfigSchema | ArchivistConfig['schema']\n>\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEvB,SAAS,iBAA6B;AACtC,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAGA;AAAA,OAEK;AAEP;AAAA,EACmB;AAAA,OACZ;AACP,SAAS,sBAAsB;AAI/B,SAAS,gBAAgB;;;ACrBlB,IAAM,8BAA8B;;;AD4BpC,IAAM,kBAAN,cAIG,kBAC+C;AAAA,EAI/C;AAAA,EACA;AAAA,E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,MAAM,MAAM,KAAK,WAAW;AAChC,QAAI,UAAU,QAAQ;AACpB,YAAM,IAAI,QAAQ;AAAA,IACpB;AACA,UAAM,aAAa,SACf,gBAAgB,oBAAoB,KAAK,MAAM,KAAK,OAAO,IAAI,KAC/D;AACJ,UAAM,SAAS,IAAI,MAAM,YAAY,aAAa,KAAK;AACvD,WAAO;AAAA,EACT;AAAA,EAEQ,uBAAuB,SAA6D;AAC1F,SAAK,MAAM,IAAI,QAAQ,OAAO,OAAO;AACrC,SAAK,cAAc,IAAI,QAAQ,WAAW,QAAQ,KAAK;AACvD,WAAO;AAAA,EACT;AAAA,EAEQ,uBAAuB;AAC7B,SAAK,iBAAiB,IAAI,SAAqB,EAAE,KAAK,KAAK,IAAI,CAAC;AAChE,UAAM,WAAW,KAAK,MAAM,KAAK,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM,KAAK,KAAK;AAC/D,eAAW,WAAW,UAAU;AAC9B,WAAK,cAAc,IAAI,QAAQ,WAAW,QAAQ,KAAK;AAAA,IACzD;AAAA,EACF;AACF;AA5HE,cANW,iBAMc,iBAA0B,CAAC,GAAG,6CAAM,kBAAe,2BAA2B;AACvG,cAPW,iBAOc,uBAA8B;AAP5C,kBAAN;AAAA,EADN,gBAAgB;AAAA,GACJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/archivist-memory",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -34,24 +34,24 @@
|
|
|
34
34
|
"@xylabs/hex": "^4.5.1",
|
|
35
35
|
"@xylabs/object": "^4.5.1",
|
|
36
36
|
"@xylabs/promise": "^4.5.1",
|
|
37
|
-
"@xyo-network/archivist-abstract": "^3.
|
|
38
|
-
"@xyo-network/archivist-model": "^3.
|
|
39
|
-
"@xyo-network/boundwitness-model": "^3.
|
|
40
|
-
"@xyo-network/module-model": "^3.
|
|
41
|
-
"@xyo-network/payload-builder": "^3.
|
|
42
|
-
"@xyo-network/payload-model": "^3.
|
|
37
|
+
"@xyo-network/archivist-abstract": "^3.8.1",
|
|
38
|
+
"@xyo-network/archivist-model": "^3.8.1",
|
|
39
|
+
"@xyo-network/boundwitness-model": "^3.8.1",
|
|
40
|
+
"@xyo-network/module-model": "^3.8.1",
|
|
41
|
+
"@xyo-network/payload-builder": "^3.8.1",
|
|
42
|
+
"@xyo-network/payload-model": "^3.8.1",
|
|
43
43
|
"lru-cache": "^11.0.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@xylabs/delay": "^4.5.1",
|
|
47
|
-
"@xylabs/ts-scripts-yarn3": "^
|
|
48
|
-
"@xylabs/tsconfig": "^
|
|
47
|
+
"@xylabs/ts-scripts-yarn3": "^5.0.22",
|
|
48
|
+
"@xylabs/tsconfig": "^5.0.22",
|
|
49
49
|
"@xylabs/vitest-extended": "^4.5.1",
|
|
50
|
-
"@xyo-network/account": "^3.
|
|
51
|
-
"@xyo-network/id-payload-plugin": "^3.
|
|
52
|
-
"@xyo-network/payload-wrapper": "^3.
|
|
50
|
+
"@xyo-network/account": "^3.8.1",
|
|
51
|
+
"@xyo-network/id-payload-plugin": "^3.8.1",
|
|
52
|
+
"@xyo-network/payload-wrapper": "^3.8.1",
|
|
53
53
|
"typescript": "^5.7.3",
|
|
54
|
-
"vitest": "^3.0.
|
|
54
|
+
"vitest": "^3.0.5"
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
package/src/Archivist.ts
CHANGED
|
@@ -126,7 +126,7 @@ export class MemoryArchivist<
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
protected override insertHandler(payloads: WithStorageMeta<Payload>[]): WithStorageMeta<Payload>[] {
|
|
129
|
-
const payloadsWithMeta = payloads.
|
|
129
|
+
const payloadsWithMeta = payloads.toSorted(PayloadBuilder.compareStorageMeta)
|
|
130
130
|
return payloadsWithMeta.map((payload) => {
|
|
131
131
|
return this.insertPayloadIntoCache(payload)
|
|
132
132
|
})
|
|
@@ -134,7 +134,7 @@ export class MemoryArchivist<
|
|
|
134
134
|
|
|
135
135
|
protected override async nextHandler(options?: ArchivistNextOptions): Promise<WithStorageMeta<Payload>[]> {
|
|
136
136
|
const {
|
|
137
|
-
limit, cursor, order, open,
|
|
137
|
+
limit = 100, cursor, order, open,
|
|
138
138
|
} = options ?? {}
|
|
139
139
|
let all = await this.allHandler()
|
|
140
140
|
if (order === 'desc') {
|
|
@@ -143,7 +143,7 @@ export class MemoryArchivist<
|
|
|
143
143
|
const startIndex = cursor
|
|
144
144
|
? MemoryArchivist.findIndexFromCursor(all, cursor) + (open ? 0 : 1)
|
|
145
145
|
: 0
|
|
146
|
-
const result = all.slice(startIndex,
|
|
146
|
+
const result = all.slice(startIndex, startIndex + limit)
|
|
147
147
|
return result
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Hash } from '@xylabs/hex';
|
|
2
|
-
import { Promisable } from '@xylabs/promise';
|
|
3
|
-
import { AbstractArchivist } from '@xyo-network/archivist-abstract';
|
|
4
|
-
import { ArchivistModuleEventData, ArchivistNextOptions, AttachableArchivistInstance } from '@xyo-network/archivist-model';
|
|
5
|
-
import { BoundWitness } from '@xyo-network/boundwitness-model';
|
|
6
|
-
import { AnyConfigSchema, ModuleInstance, ModuleParams } from '@xyo-network/module-model';
|
|
7
|
-
import { Payload, Schema, WithStorageMeta } from '@xyo-network/payload-model';
|
|
8
|
-
import { LRUCache } from 'lru-cache';
|
|
9
|
-
import { MemoryArchivistConfig } from './Config.ts';
|
|
10
|
-
export type MemoryArchivistParams<TConfig extends AnyConfigSchema<MemoryArchivistConfig> = AnyConfigSchema<MemoryArchivistConfig>> = ModuleParams<TConfig>;
|
|
11
|
-
export declare class MemoryArchivist<TParams extends MemoryArchivistParams<AnyConfigSchema<MemoryArchivistConfig>> = MemoryArchivistParams, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends AbstractArchivist<TParams, TEventData> implements AttachableArchivistInstance, ModuleInstance {
|
|
12
|
-
static readonly configSchemas: Schema[];
|
|
13
|
-
static readonly defaultConfigSchema: Schema;
|
|
14
|
-
private _cache?;
|
|
15
|
-
private _dataHashIndex?;
|
|
16
|
-
get queries(): string[];
|
|
17
|
-
protected get cache(): LRUCache<Lowercase<string>, WithStorageMeta<import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
18
|
-
schema: Schema;
|
|
19
|
-
}>>, unknown>;
|
|
20
|
-
protected get dataHashIndex(): LRUCache<Lowercase<string>, Lowercase<string>, unknown>;
|
|
21
|
-
protected get max(): number;
|
|
22
|
-
private static findIndexFromCursor;
|
|
23
|
-
protected allHandler(): Promisable<WithStorageMeta<Payload>[]>;
|
|
24
|
-
protected clearHandler(): void | Promise<void>;
|
|
25
|
-
protected commitHandler(): Promise<BoundWitness[]>;
|
|
26
|
-
protected deleteHandler(hashes: Hash[]): Promise<Hash[]>;
|
|
27
|
-
protected getHandler(hashes: Hash[]): Promisable<WithStorageMeta<Payload>[]>;
|
|
28
|
-
protected insertHandler(payloads: WithStorageMeta<Payload>[]): WithStorageMeta<Payload>[];
|
|
29
|
-
protected nextHandler(options?: ArchivistNextOptions): Promise<WithStorageMeta<Payload>[]>;
|
|
30
|
-
private insertPayloadIntoCache;
|
|
31
|
-
private rebuildDataHashIndex;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=Archivist.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Archivist.d.ts","sourceRoot":"","sources":["../../src/Archivist.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAO,MAAM,aAAa,CAAA;AACvC,OAAO,EAAa,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACvD,OA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AC;cAM9B,aAAa,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;cAaxC,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cAepD,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;cAWlE,aAAa,CAAC,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,GAAG,eAAe,CAAC,OAAO,CAAC,EAAE;cAOzE,WAAW,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;IAezG,OAAO,CAAC,sBAAsB;IAM9B,OAAO,CAAC,oBAAoB;CAO7B"}
|
package/dist/neutral/Config.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { EmptyObject, WithAdditional } from '@xylabs/object';
|
|
2
|
-
import type { ArchivistConfig } from '@xyo-network/archivist-model';
|
|
3
|
-
import type { Payload, Schema } from '@xyo-network/payload-model';
|
|
4
|
-
export declare const MemoryArchivistConfigSchema: "network.xyo.archivist.memory.config";
|
|
5
|
-
export type MemoryArchivistConfigSchema = typeof MemoryArchivistConfigSchema;
|
|
6
|
-
export type MemoryArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchema extends Schema | void = void> = ArchivistConfig<WithAdditional<{
|
|
7
|
-
max?: number;
|
|
8
|
-
}, TConfig>, TSchema extends Schema ? TSchema : MemoryArchivistConfigSchema | ArchivistConfig['schema']>;
|
|
9
|
-
//# sourceMappingURL=Config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAEjE,eAAO,MAAM,2BAA2B,EAAG,qCAA8C,CAAA;AACzF,MAAM,MAAM,2BAA2B,GAAG,OAAO,2BAA2B,CAAA;AAE5E,MAAM,MAAM,qBAAqB,CAAC,OAAO,SAAS,OAAO,GAAG,WAAW,GAAG,IAAI,GAAG,IAAI,EAAE,OAAO,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,eAAe,CAC5I,cAAc,CACZ;IACE,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,EACD,OAAO,CACR,EACD,OAAO,SAAS,MAAM,GAAG,OAAO,GAAG,2BAA2B,GAAG,eAAe,CAAC,QAAQ,CAAC,CAC3F,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA"}
|