@xyo-network/archivist-memory 2.111.2 → 3.0.0

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.
Files changed (48) hide show
  1. package/dist/neutral/index.d.ts +37 -2
  2. package/package.json +20 -40
  3. package/xy.config.ts +12 -0
  4. package/dist/browser/MemoryArchivist.d.cts +0 -35
  5. package/dist/browser/MemoryArchivist.d.cts.map +0 -1
  6. package/dist/browser/MemoryArchivist.d.mts +0 -35
  7. package/dist/browser/MemoryArchivist.d.mts.map +0 -1
  8. package/dist/browser/MemoryArchivist.d.ts +0 -35
  9. package/dist/browser/MemoryArchivist.d.ts.map +0 -1
  10. package/dist/browser/index.cjs +0 -165
  11. package/dist/browser/index.cjs.map +0 -1
  12. package/dist/browser/index.d.cts +0 -2
  13. package/dist/browser/index.d.cts.map +0 -1
  14. package/dist/browser/index.d.mts +0 -2
  15. package/dist/browser/index.d.mts.map +0 -1
  16. package/dist/browser/index.d.ts +0 -2
  17. package/dist/browser/index.d.ts.map +0 -1
  18. package/dist/browser/index.mjs +0 -144
  19. package/dist/browser/index.mjs.map +0 -1
  20. package/dist/neutral/MemoryArchivist.d.cts +0 -35
  21. package/dist/neutral/MemoryArchivist.d.cts.map +0 -1
  22. package/dist/neutral/MemoryArchivist.d.mts +0 -35
  23. package/dist/neutral/MemoryArchivist.d.mts.map +0 -1
  24. package/dist/neutral/MemoryArchivist.d.ts +0 -35
  25. package/dist/neutral/MemoryArchivist.d.ts.map +0 -1
  26. package/dist/neutral/index.cjs +0 -165
  27. package/dist/neutral/index.cjs.map +0 -1
  28. package/dist/neutral/index.d.cts +0 -2
  29. package/dist/neutral/index.d.cts.map +0 -1
  30. package/dist/neutral/index.d.mts +0 -2
  31. package/dist/neutral/index.d.mts.map +0 -1
  32. package/dist/neutral/index.d.ts.map +0 -1
  33. package/dist/node/MemoryArchivist.d.cts +0 -35
  34. package/dist/node/MemoryArchivist.d.cts.map +0 -1
  35. package/dist/node/MemoryArchivist.d.mts +0 -35
  36. package/dist/node/MemoryArchivist.d.mts.map +0 -1
  37. package/dist/node/MemoryArchivist.d.ts +0 -35
  38. package/dist/node/MemoryArchivist.d.ts.map +0 -1
  39. package/dist/node/index.cjs +0 -177
  40. package/dist/node/index.cjs.map +0 -1
  41. package/dist/node/index.d.cts +0 -2
  42. package/dist/node/index.d.cts.map +0 -1
  43. package/dist/node/index.d.mts +0 -2
  44. package/dist/node/index.d.mts.map +0 -1
  45. package/dist/node/index.d.ts +0 -2
  46. package/dist/node/index.d.ts.map +0 -1
  47. package/dist/node/index.mjs +0 -151
  48. package/dist/node/index.mjs.map +0 -1
@@ -1,2 +1,37 @@
1
- export * from './MemoryArchivist.ts';
2
- //# sourceMappingURL=index.d.ts.map
1
+ import { Hash } from '@xylabs/hex';
2
+ import { EmptyObject, WithAdditional } from '@xylabs/object';
3
+ import { Promisable } from '@xylabs/promise';
4
+ import { AbstractArchivist, WithStorageMeta } from '@xyo-network/archivist-abstract';
5
+ import { ArchivistConfig, ArchivistModuleEventData, AttachableArchivistInstance, ArchivistNextOptions } from '@xyo-network/archivist-model';
6
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
7
+ import { AnyConfigSchema, ModuleParams, ModuleInstance } from '@xyo-network/module-model';
8
+ import { Payload, Schema, PayloadWithMeta, WithMeta } from '@xyo-network/payload-model';
9
+ import { LRUCache } from 'lru-cache';
10
+
11
+ type MemoryArchivistConfigSchema = 'network.xyo.archivist.memory.config';
12
+ declare const MemoryArchivistConfigSchema: MemoryArchivistConfigSchema;
13
+ type MemoryArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchema extends Schema | void = void> = ArchivistConfig<WithAdditional<{
14
+ max?: number;
15
+ }, TConfig>, TSchema extends Schema ? TSchema : MemoryArchivistConfigSchema | ArchivistConfig['schema']>;
16
+ type MemoryArchivistParams<TConfig extends AnyConfigSchema<MemoryArchivistConfig> = AnyConfigSchema<MemoryArchivistConfig>> = ModuleParams<TConfig>;
17
+ declare class MemoryArchivist<TParams extends MemoryArchivistParams<AnyConfigSchema<MemoryArchivistConfig>> = MemoryArchivistParams, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends AbstractArchivist<TParams, TEventData> implements AttachableArchivistInstance, ModuleInstance {
18
+ static readonly configSchemas: Schema[];
19
+ static readonly defaultConfigSchema: Schema;
20
+ private _cache?;
21
+ private _dataHashIndex?;
22
+ get queries(): string[];
23
+ protected get cache(): LRUCache<Lowercase<string>, WithStorageMeta<PayloadWithMeta>, unknown>;
24
+ protected get dataHashIndex(): LRUCache<Lowercase<string>, Lowercase<string>, unknown>;
25
+ protected get max(): number;
26
+ protected allHandler(): Promisable<PayloadWithMeta[]>;
27
+ protected clearHandler(): void | Promise<void>;
28
+ protected commitHandler(): Promise<WithMeta<BoundWitness>[]>;
29
+ protected deleteHandler(hashes: Hash[]): Promisable<Hash[]>;
30
+ protected getHandler(hashes: Hash[]): Promisable<PayloadWithMeta[]>;
31
+ protected insertHandler(payloads: Payload[]): Promise<PayloadWithMeta[]>;
32
+ protected nextHandler(options?: ArchivistNextOptions): Promise<PayloadWithMeta[]>;
33
+ private insertPayloadIntoCache;
34
+ private rebuildDataHashIndex;
35
+ }
36
+
37
+ export { MemoryArchivist, type MemoryArchivistConfig, MemoryArchivistConfigSchema, type MemoryArchivistParams };
package/package.json CHANGED
@@ -10,56 +10,36 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^3.6.8",
14
- "@xylabs/exists": "^3.6.8",
15
- "@xylabs/hex": "^3.6.8",
16
- "@xylabs/lodash": "^3.6.8",
17
- "@xylabs/object": "^3.6.8",
18
- "@xylabs/promise": "^3.6.8",
19
- "@xyo-network/archivist-abstract": "^2.111.2",
20
- "@xyo-network/archivist-model": "^2.111.2",
21
- "@xyo-network/boundwitness-model": "^2.111.2",
22
- "@xyo-network/module-model": "^2.111.2",
23
- "@xyo-network/payload-builder": "^2.111.2",
24
- "@xyo-network/payload-model": "^2.111.2",
13
+ "@xylabs/assert": "^3.6.12",
14
+ "@xylabs/exists": "^3.6.12",
15
+ "@xylabs/hex": "^3.6.12",
16
+ "@xylabs/lodash": "^3.6.12",
17
+ "@xylabs/object": "^3.6.12",
18
+ "@xylabs/promise": "^3.6.12",
19
+ "@xyo-network/archivist-abstract": "^3.0.0",
20
+ "@xyo-network/archivist-model": "^3.0.0",
21
+ "@xyo-network/boundwitness-model": "^3.0.0",
22
+ "@xyo-network/module-model": "^3.0.0",
23
+ "@xyo-network/payload-builder": "^3.0.0",
24
+ "@xyo-network/payload-model": "^3.0.0",
25
25
  "lru-cache": "^11.0.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@xylabs/ts-scripts-yarn3": "^3.15.13",
29
- "@xylabs/tsconfig": "^3.15.13",
30
- "@xyo-network/account": "^2.111.2",
31
- "tslib": "^2.6.3",
28
+ "@xylabs/ts-scripts-yarn3": "next",
29
+ "@xylabs/tsconfig": "next",
30
+ "@xyo-network/account": "^3.0.0",
32
31
  "typescript": "^5.5.4"
33
32
  },
34
33
  "description": "Primary SDK for using XYO Protocol 2.0",
35
- "types": "dist/node/index.d.ts",
34
+ "types": "dist/neutral/index.d.ts",
36
35
  "exports": {
37
36
  ".": {
38
- "browser": {
39
- "require": {
40
- "types": "./dist/browser/index.d.cts",
41
- "default": "./dist/browser/index.cjs"
42
- },
43
- "import": {
44
- "types": "./dist/browser/index.d.mts",
45
- "default": "./dist/browser/index.mjs"
46
- }
47
- },
48
- "node": {
49
- "require": {
50
- "types": "./dist/node/index.d.cts",
51
- "default": "./dist/node/index.cjs"
52
- },
53
- "import": {
54
- "types": "./dist/node/index.d.mts",
55
- "default": "./dist/node/index.mjs"
56
- }
57
- }
37
+ "types": "./dist/neutral/index.d.ts",
38
+ "default": "./dist/neutral/index.mjs"
58
39
  },
59
40
  "./package.json": "./package.json"
60
41
  },
61
- "main": "dist/node/index.cjs",
62
- "module": "dist/node/index.mjs",
42
+ "module": "dist/neutral/index.mjs",
63
43
  "homepage": "https://xyo.network",
64
44
  "license": "LGPL-3.0-only",
65
45
  "publishConfig": {
@@ -70,6 +50,6 @@
70
50
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
71
51
  },
72
52
  "sideEffects": false,
73
- "version": "2.111.2",
53
+ "version": "3.0.0",
74
54
  "type": "module"
75
55
  }
package/xy.config.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
+ const config: XyTsupConfig = {
3
+ compile: {
4
+ browser: {},
5
+ neutral: {
6
+ src: true,
7
+ },
8
+ node: {},
9
+ },
10
+ }
11
+
12
+ export default config
@@ -1,35 +0,0 @@
1
- import { Hash } from '@xylabs/hex';
2
- import { EmptyObject, WithAdditional } from '@xylabs/object';
3
- import { Promisable } from '@xylabs/promise';
4
- import { AbstractArchivist, WithStorageMeta } from '@xyo-network/archivist-abstract';
5
- import { ArchivistConfig, ArchivistModuleEventData, ArchivistNextOptions, AttachableArchivistInstance } from '@xyo-network/archivist-model';
6
- import { BoundWitness } from '@xyo-network/boundwitness-model';
7
- import { AnyConfigSchema, ModuleInstance, ModuleParams } from '@xyo-network/module-model';
8
- import { Payload, PayloadWithMeta, Schema, WithMeta } from '@xyo-network/payload-model';
9
- import { LRUCache } from 'lru-cache';
10
- export type MemoryArchivistConfigSchema = 'network.xyo.archivist.memory.config';
11
- export declare const MemoryArchivistConfigSchema: MemoryArchivistConfigSchema;
12
- export type MemoryArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchema extends Schema | void = void> = ArchivistConfig<WithAdditional<{
13
- max?: number;
14
- }, TConfig>, TSchema extends Schema ? TSchema : MemoryArchivistConfigSchema | ArchivistConfig['schema']>;
15
- export type MemoryArchivistParams<TConfig extends AnyConfigSchema<MemoryArchivistConfig> = AnyConfigSchema<MemoryArchivistConfig>> = ModuleParams<TConfig>;
16
- export declare class MemoryArchivist<TParams extends MemoryArchivistParams<AnyConfigSchema<MemoryArchivistConfig>> = MemoryArchivistParams, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends AbstractArchivist<TParams, TEventData> implements AttachableArchivistInstance, ModuleInstance {
17
- static readonly configSchemas: Schema[];
18
- static readonly defaultConfigSchema: Schema;
19
- private _cache?;
20
- private _dataHashIndex?;
21
- get queries(): string[];
22
- protected get cache(): LRUCache<Lowercase<string>, WithStorageMeta<PayloadWithMeta>, unknown>;
23
- protected get dataHashIndex(): LRUCache<Lowercase<string>, Lowercase<string>, unknown>;
24
- protected get max(): number;
25
- protected allHandler(): Promisable<PayloadWithMeta[]>;
26
- protected clearHandler(): void | Promise<void>;
27
- protected commitHandler(): Promise<WithMeta<BoundWitness>[]>;
28
- protected deleteHandler(hashes: Hash[]): Promisable<Hash[]>;
29
- protected getHandler(hashes: Hash[]): Promisable<PayloadWithMeta[]>;
30
- protected insertHandler(payloads: Payload[]): Promise<PayloadWithMeta[]>;
31
- protected nextHandler(options?: ArchivistNextOptions): Promise<PayloadWithMeta[]>;
32
- private insertPayloadIntoCache;
33
- private rebuildDataHashIndex;
34
- }
35
- //# sourceMappingURL=MemoryArchivist.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MemoryArchivist.d.ts","sourceRoot":"","sources":["../../src/MemoryArchivist.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,EAAa,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAwD,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAC1I,OAAO,EAIL,eAAe,EAIf,wBAAwB,EACxB,oBAAoB,EAEpB,2BAA2B,EAC5B,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,EAAE,e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AK,GAAG,WAEhB;cAEkB,UAAU,IAAI,UAAU,CAAC,eAAe,EAAE,CAAC;cAK3C,YAAY,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;cAM9B,aAAa,IAAI,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;cAiBxD,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;cAcjD,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,eAAe,EAAE,CAAC;cAanD,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;cAS9D,WAAW,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAWhG,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,oBAAoB;CAO7B"}
@@ -1,35 +0,0 @@
1
- import { Hash } from '@xylabs/hex';
2
- import { EmptyObject, WithAdditional } from '@xylabs/object';
3
- import { Promisable } from '@xylabs/promise';
4
- import { AbstractArchivist, WithStorageMeta } from '@xyo-network/archivist-abstract';
5
- import { ArchivistConfig, ArchivistModuleEventData, ArchivistNextOptions, AttachableArchivistInstance } from '@xyo-network/archivist-model';
6
- import { BoundWitness } from '@xyo-network/boundwitness-model';
7
- import { AnyConfigSchema, ModuleInstance, ModuleParams } from '@xyo-network/module-model';
8
- import { Payload, PayloadWithMeta, Schema, WithMeta } from '@xyo-network/payload-model';
9
- import { LRUCache } from 'lru-cache';
10
- export type MemoryArchivistConfigSchema = 'network.xyo.archivist.memory.config';
11
- export declare const MemoryArchivistConfigSchema: MemoryArchivistConfigSchema;
12
- export type MemoryArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchema extends Schema | void = void> = ArchivistConfig<WithAdditional<{
13
- max?: number;
14
- }, TConfig>, TSchema extends Schema ? TSchema : MemoryArchivistConfigSchema | ArchivistConfig['schema']>;
15
- export type MemoryArchivistParams<TConfig extends AnyConfigSchema<MemoryArchivistConfig> = AnyConfigSchema<MemoryArchivistConfig>> = ModuleParams<TConfig>;
16
- export declare class MemoryArchivist<TParams extends MemoryArchivistParams<AnyConfigSchema<MemoryArchivistConfig>> = MemoryArchivistParams, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends AbstractArchivist<TParams, TEventData> implements AttachableArchivistInstance, ModuleInstance {
17
- static readonly configSchemas: Schema[];
18
- static readonly defaultConfigSchema: Schema;
19
- private _cache?;
20
- private _dataHashIndex?;
21
- get queries(): string[];
22
- protected get cache(): LRUCache<Lowercase<string>, WithStorageMeta<PayloadWithMeta>, unknown>;
23
- protected get dataHashIndex(): LRUCache<Lowercase<string>, Lowercase<string>, unknown>;
24
- protected get max(): number;
25
- protected allHandler(): Promisable<PayloadWithMeta[]>;
26
- protected clearHandler(): void | Promise<void>;
27
- protected commitHandler(): Promise<WithMeta<BoundWitness>[]>;
28
- protected deleteHandler(hashes: Hash[]): Promisable<Hash[]>;
29
- protected getHandler(hashes: Hash[]): Promisable<PayloadWithMeta[]>;
30
- protected insertHandler(payloads: Payload[]): Promise<PayloadWithMeta[]>;
31
- protected nextHandler(options?: ArchivistNextOptions): Promise<PayloadWithMeta[]>;
32
- private insertPayloadIntoCache;
33
- private rebuildDataHashIndex;
34
- }
35
- //# sourceMappingURL=MemoryArchivist.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MemoryArchivist.d.ts","sourceRoot":"","sources":["../../src/MemoryArchivist.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,EAAa,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAwD,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAC1I,OAAO,EAIL,eAAe,EAIf,wBAA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AAO,CAAC,cAAc,CAAC,CAAsB;IAE7C,IAAa,OAAO,aAUnB;IAED,SAAS,KAAK,KAAK,2EAGlB;IAED,SAAS,KAAK,aAAa,4DAG1B;IAED,SAAS,KAAK,GAAG,WAEhB;cAEkB,UAAU,IAAI,UAAU,CAAC,eAAe,EAAE,CAAC;cAK3C,YAAY,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;cAM9B,aAAa,IAAI,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;cAiBxD,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;cAcjD,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,eAAe,EAAE,CAAC;cAanD,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;cAS9D,WAAW,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAWhG,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,oBAAoB;CAO7B"}
@@ -1,35 +0,0 @@
1
- import { Hash } from '@xylabs/hex';
2
- import { EmptyObject, WithAdditional } from '@xylabs/object';
3
- import { Promisable } from '@xylabs/promise';
4
- import { AbstractArchivist, WithStorageMeta } from '@xyo-network/archivist-abstract';
5
- import { ArchivistConfig, ArchivistModuleEventData, ArchivistNextOptions, AttachableArchivistInstance } from '@xyo-network/archivist-model';
6
- import { BoundWitness } from '@xyo-network/boundwitness-model';
7
- import { AnyConfigSchema, ModuleInstance, ModuleParams } from '@xyo-network/module-model';
8
- import { Payload, PayloadWithMeta, Schema, WithMeta } from '@xyo-network/payload-model';
9
- import { LRUCache } from 'lru-cache';
10
- export type MemoryArchivistConfigSchema = 'network.xyo.archivist.memory.config';
11
- export declare const MemoryArchivistConfigSchema: MemoryArchivistConfigSchema;
12
- export type MemoryArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchema extends Schema | void = void> = ArchivistConfig<WithAdditional<{
13
- max?: number;
14
- }, TConfig>, TSchema extends Schema ? TSchema : MemoryArchivistConfigSchema | ArchivistConfig['schema']>;
15
- export type MemoryArchivistParams<TConfig extends AnyConfigSchema<MemoryArchivistConfig> = AnyConfigSchema<MemoryArchivistConfig>> = ModuleParams<TConfig>;
16
- export declare class MemoryArchivist<TParams extends MemoryArchivistParams<AnyConfigSchema<MemoryArchivistConfig>> = MemoryArchivistParams, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends AbstractArchivist<TParams, TEventData> implements AttachableArchivistInstance, ModuleInstance {
17
- static readonly configSchemas: Schema[];
18
- static readonly defaultConfigSchema: Schema;
19
- private _cache?;
20
- private _dataHashIndex?;
21
- get queries(): string[];
22
- protected get cache(): LRUCache<Lowercase<string>, WithStorageMeta<PayloadWithMeta>, unknown>;
23
- protected get dataHashIndex(): LRUCache<Lowercase<string>, Lowercase<string>, unknown>;
24
- protected get max(): number;
25
- protected allHandler(): Promisable<PayloadWithMeta[]>;
26
- protected clearHandler(): void | Promise<void>;
27
- protected commitHandler(): Promise<WithMeta<BoundWitness>[]>;
28
- protected deleteHandler(hashes: Hash[]): Promisable<Hash[]>;
29
- protected getHandler(hashes: Hash[]): Promisable<PayloadWithMeta[]>;
30
- protected insertHandler(payloads: Payload[]): Promise<PayloadWithMeta[]>;
31
- protected nextHandler(options?: ArchivistNextOptions): Promise<PayloadWithMeta[]>;
32
- private insertPayloadIntoCache;
33
- private rebuildDataHashIndex;
34
- }
35
- //# sourceMappingURL=MemoryArchivist.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MemoryArchivist.d.ts","sourceRoot":"","sources":["../../src/MemoryArchivist.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,EAAa,UA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IACtD,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAwD;IACxG,gBAAyB,mBAAmB,EAAE,MAAM,CAA8B;IAElF,OAAO,CAAC,MAAM,CAAC,CAAkD;IACjE,OAAO,CAAC,cAAc,CAAC,CAAsB;IAE7C,IAAa,OAAO,aAUnB;IAED,SAAS,KAAK,KAAK,2EAGlB;IAED,SAAS,KAAK,aAAa,4DAG1B;IAED,SAAS,KAAK,GAAG,WAEhB;cAEkB,UAAU,IAAI,UAAU,CAAC,eAAe,EAAE,CAAC;cAK3C,YAAY,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;cAM9B,aAAa,IAAI,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;cAiBxD,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;cAcjD,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,eAAe,EAAE,CAAC;cAanD,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;cAS9D,WAAW,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAWhG,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,oBAAoB;CAO7B"}
@@ -1,165 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/index.ts
22
- var src_exports = {};
23
- __export(src_exports, {
24
- MemoryArchivist: () => MemoryArchivist,
25
- MemoryArchivistConfigSchema: () => MemoryArchivistConfigSchema
26
- });
27
- module.exports = __toCommonJS(src_exports);
28
-
29
- // src/MemoryArchivist.ts
30
- var import_assert = require("@xylabs/assert");
31
- var import_exists = require("@xylabs/exists");
32
- var import_lodash = require("@xylabs/lodash");
33
- var import_promise = require("@xylabs/promise");
34
- var import_archivist_abstract = require("@xyo-network/archivist-abstract");
35
- var import_archivist_model = require("@xyo-network/archivist-model");
36
- var import_module_model = require("@xyo-network/module-model");
37
- var import_payload_builder = require("@xyo-network/payload-builder");
38
- var import_lru_cache = require("lru-cache");
39
- function _ts_decorate(decorators, target, key, desc) {
40
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
41
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
42
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
43
- return c > 3 && r && Object.defineProperty(target, key, r), r;
44
- }
45
- __name(_ts_decorate, "_ts_decorate");
46
- var MemoryArchivistConfigSchema = "network.xyo.archivist.memory.config";
47
- var MemoryArchivist = class extends import_archivist_abstract.AbstractArchivist {
48
- static {
49
- __name(this, "MemoryArchivist");
50
- }
51
- static configSchemas = [
52
- ...super.configSchemas,
53
- MemoryArchivistConfigSchema
54
- ];
55
- static defaultConfigSchema = MemoryArchivistConfigSchema;
56
- _cache;
57
- _dataHashIndex;
58
- get queries() {
59
- return [
60
- import_archivist_model.ArchivistAllQuerySchema,
61
- import_archivist_model.ArchivistDeleteQuerySchema,
62
- import_archivist_model.ArchivistClearQuerySchema,
63
- import_archivist_model.ArchivistInsertQuerySchema,
64
- import_archivist_model.ArchivistCommitQuerySchema,
65
- import_archivist_model.ArchivistNextQuerySchema,
66
- ...super.queries
67
- ];
68
- }
69
- get cache() {
70
- this._cache = this._cache ?? new import_lru_cache.LRUCache({
71
- max: this.max
72
- });
73
- return this._cache;
74
- }
75
- get dataHashIndex() {
76
- this._dataHashIndex = this._dataHashIndex ?? new import_lru_cache.LRUCache({
77
- max: this.max
78
- });
79
- return this._dataHashIndex;
80
- }
81
- get max() {
82
- return this.config?.max ?? 1e4;
83
- }
84
- allHandler() {
85
- const all = (0, import_lodash.compact)(this.cache.dump().map(([, item]) => item.value));
86
- return (0, import_archivist_abstract.sortByStorageMeta)(all).map((payload) => (0, import_archivist_abstract.removeStorageMeta)(payload));
87
- }
88
- clearHandler() {
89
- this.cache.clear();
90
- this.dataHashIndex.clear();
91
- return this.emit("cleared", {
92
- mod: this
93
- });
94
- }
95
- async commitHandler() {
96
- const payloads = (0, import_assert.assertEx)(await this.allHandler(), () => "Nothing to commit");
97
- const settled = await Promise.allSettled((0, import_lodash.compact)(Object.values((await this.parentArchivists()).commit ?? [])?.map(async (parent) => {
98
- const queryPayload = {
99
- schema: import_archivist_model.ArchivistInsertQuerySchema
100
- };
101
- const query = await this.bindQuery(queryPayload, payloads);
102
- return (await parent?.query(query[0], query[1]))?.[0];
103
- })));
104
- await this.clearHandler();
105
- return (0, import_lodash.compact)(settled.filter(import_promise.fulfilled).map((result) => result.value));
106
- }
107
- deleteHandler(hashes) {
108
- const deletedHashes = this.cache.dump().map(([key, item]) => {
109
- if (hashes.includes(key) || hashes.includes(item.value.$hash)) {
110
- this.cache.delete(key);
111
- return key;
112
- }
113
- }).filter(import_exists.exists);
114
- this.rebuildDataHashIndex();
115
- return deletedHashes;
116
- }
117
- getHandler(hashes) {
118
- return (0, import_lodash.compact)(hashes.map((hash) => {
119
- const resolvedHash = this.dataHashIndex.get(hash) ?? hash;
120
- const result = this.cache.get(resolvedHash);
121
- if (resolvedHash !== hash && !result) {
122
- throw new Error("Missing referenced payload");
123
- }
124
- return (0, import_archivist_abstract.removeStorageMeta)(result);
125
- }));
126
- }
127
- async insertHandler(payloads) {
128
- const pairs = await import_payload_builder.PayloadBuilder.hashPairs(payloads, {
129
- stamp: false
130
- });
131
- const insertedPayloads = pairs.map(([payload, hash], index) => {
132
- return this.cache.get(hash) ?? this.insertPayloadIntoCache(payload, hash, index);
133
- });
134
- return (0, import_archivist_abstract.removeStorageMeta)(insertedPayloads);
135
- }
136
- async nextHandler(options) {
137
- const { limit, offset, order } = options ?? {};
138
- let all = await this.allHandler();
139
- if (order === "desc") {
140
- all = all.reverse();
141
- }
142
- const allPairs = await import_payload_builder.PayloadBuilder.hashPairs(all);
143
- const startIndex = offset ? allPairs.findIndex(([, hash]) => hash === offset) + 1 : 0;
144
- return allPairs.slice(startIndex, limit ? startIndex + limit : void 0).map(([payload]) => payload);
145
- }
146
- insertPayloadIntoCache(payload, hash, index = 0) {
147
- const withMeta = (0, import_archivist_abstract.addStorageMeta)(payload, index);
148
- this.cache.set(hash, withMeta);
149
- this.dataHashIndex.set(withMeta.$hash, hash);
150
- return withMeta;
151
- }
152
- rebuildDataHashIndex() {
153
- this._dataHashIndex = new import_lru_cache.LRUCache({
154
- max: this.max
155
- });
156
- const pairs = this.cache.dump();
157
- for (const [hash, payload] of pairs) {
158
- this.dataHashIndex.set(payload.value.$hash, hash);
159
- }
160
- }
161
- };
162
- MemoryArchivist = _ts_decorate([
163
- (0, import_module_model.creatableModule)()
164
- ], MemoryArchivist);
165
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryArchivist.ts"],"sourcesContent":["export * from './MemoryArchivist.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Hash } from '@xylabs/hex'\nimport { compact } from '@xylabs/lodash'\nimport { EmptyObject, WithAdditional } from '@xylabs/object'\nimport { fulfilled, Promisable } from '@xylabs/promise'\nimport { AbstractArchivist, addStorageMeta, removeStorageMeta, sortByStorageMeta, WithStorageMeta } from '@xyo-network/archivist-abstract'\nimport {\n ArchivistAllQuerySchema,\n ArchivistClearQuerySchema,\n ArchivistCommitQuerySchema,\n ArchivistConfig,\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 { AnyConfigSchema, creatableModule, ModuleInstance, ModuleParams } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadWithMeta, Schema, WithMeta } from '@xyo-network/payload-model'\nimport { LRUCache } from 'lru-cache'\n\nexport type MemoryArchivistConfigSchema = 'network.xyo.archivist.memory.config'\nexport const MemoryArchivistConfigSchema: MemoryArchivistConfigSchema = 'network.xyo.archivist.memory.config'\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\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<PayloadWithMeta>>\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<PayloadWithMeta>>({ 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 protected override allHandler(): Promisable<PayloadWithMeta[]> {\n const all = compact(this.cache.dump().map(([, item]) => item.value))\n return sortByStorageMeta(all).map(payload => removeStorageMeta(payload))\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<WithMeta<BoundWitness>[]> {\n const payloads = assertEx(await this.allHandler(), () => 'Nothing to commit')\n const settled = await Promise.allSettled(\n compact(\n Object.values((await this.parentArchivists()).commit ?? [])?.map(async (parent) => {\n const queryPayload: ArchivistInsertQuery = {\n schema: ArchivistInsertQuerySchema,\n }\n const query = await this.bindQuery(queryPayload, payloads)\n return (await parent?.query(query[0], query[1]))?.[0]\n }),\n ),\n )\n await this.clearHandler()\n return compact(settled.filter(fulfilled).map(result => result.value))\n }\n\n protected override deleteHandler(hashes: Hash[]): Promisable<Hash[]> {\n const deletedHashes: Hash[] = this.cache\n .dump()\n .map(([key, item]) => {\n if (hashes.includes(key) || hashes.includes(item.value.$hash)) {\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<PayloadWithMeta[]> {\n return compact(\n 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 removeStorageMeta(result)\n }),\n )\n }\n\n protected override async insertHandler(payloads: Payload[]): Promise<PayloadWithMeta[]> {\n const pairs = await PayloadBuilder.hashPairs(payloads, { stamp: false })\n const insertedPayloads = pairs.map(([payload, hash], index) => {\n return this.cache.get(hash) ?? this.insertPayloadIntoCache(payload, hash, index)\n })\n\n return removeStorageMeta(insertedPayloads)\n }\n\n protected override async nextHandler(options?: ArchivistNextOptions): Promise<PayloadWithMeta[]> {\n const { limit, offset, order } = options ?? {}\n let all = await this.allHandler()\n if (order === 'desc') {\n all = all.reverse()\n }\n const allPairs = await PayloadBuilder.hashPairs(all)\n const startIndex = offset ? allPairs.findIndex(([, hash]) => hash === offset) + 1 : 0\n return allPairs.slice(startIndex, limit ? startIndex + limit : undefined).map(([payload]) => payload)\n }\n\n private insertPayloadIntoCache(payload: PayloadWithMeta, hash: Hash, index = 0): WithStorageMeta<PayloadWithMeta> {\n const withMeta = addStorageMeta(payload, index)\n this.cache.set(hash, withMeta)\n this.dataHashIndex.set(withMeta.$hash, hash)\n return withMeta\n }\n\n private rebuildDataHashIndex() {\n this._dataHashIndex = new LRUCache<Hash, Hash>({ max: this.max })\n const pairs = this.cache.dump()\n for (const [hash, payload] of pairs) {\n this.dataHashIndex.set(payload.value.$hash, hash)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AAEvB,oBAAwB;AAExB,qBAAsC;AACtC,gCAAyG;AACzG,6BAYO;AAEP,0BAA+E;AAC/E,6BAA+B;AAE/B,uBAAyB;;;;;;;;AAGlB,IAAMA,8BAA2D;AAejE,IAAMC,kBAAN,cAIGC,4CAAAA;SAAAA;;;EAER,OAAyBC,gBAA0B;OAAI,MAAMA;I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,MAAM,KAAKD,WAAU;AAC/B,QAAI0D,UAAU,QAAQ;AACpBzD,YAAMA,IAAI0D,QAAO;IACnB;AACA,UAAMC,WAAW,MAAMZ,sCAAeC,UAAUhD,GAAAA;AAChD,UAAM4D,aAAaJ,SAASG,SAASE,UAAU,CAAC,CAAA,EAAGpB,IAAAA,MAAUA,SAASe,MAAAA,IAAU,IAAI;AACpF,WAAOG,SAASG,MAAMF,YAAYL,QAAQK,aAAaL,QAAQQ,MAAAA,EAAW5D,IAAI,CAAC,CAACI,OAAAA,MAAaA,OAAAA;EAC/F;EAEQ6C,uBAAuB7C,SAA0BkC,MAAYU,QAAQ,GAAqC;AAChH,UAAMa,eAAWC,0CAAe1D,SAAS4C,KAAAA;AACzC,SAAKzD,MAAMwE,IAAIzB,MAAMuB,QAAAA;AACrB,SAAKnE,cAAcqE,IAAIF,SAAS5B,OAAOK,IAAAA;AACvC,WAAOuB;EACT;EAEQzB,uBAAuB;AAC7B,SAAKrD,iBAAiB,IAAIS,0BAAqB;MAAEC,KAAK,KAAKA;IAAI,CAAA;AAC/D,UAAMkD,QAAQ,KAAKpD,MAAMQ,KAAI;AAC7B,eAAW,CAACuC,MAAMlC,OAAAA,KAAYuC,OAAO;AACnC,WAAKjD,cAAcqE,IAAI3D,QAAQF,MAAM+B,OAAOK,IAAAA;IAC9C;EACF;AACF;;;;","names":["MemoryArchivistConfigSchema","MemoryArchivist","AbstractArchivist","configSchemas","defaultConfigSchema","_cache","_dataHashIndex","queries","ArchivistAllQuerySchema","ArchivistDeleteQuerySchema","ArchivistClearQuerySchema","ArchivistInsertQuerySchema","ArchivistCommitQuerySchema","ArchivistNextQuerySchema","cache","LRUCache","max","dataHashIndex","config","allHandler","all","compact","dump","map","item","value","sortByStorageMeta","payload","removeStorageMeta","clearHandler","clear","emit","mod","commitHandler","payloads","assertEx","settled","Promise","allSettled","Object","values","parentArchivists","commit","parent","queryPayload","schema","query","bindQuery","filter","fulfilled","result","deleteHandler","hashes","deletedHashes","key","includes","$hash","delete","exists","rebuildDataHashIndex","getHandler","hash","resolvedHash","get","Error","insertHandler","pairs","PayloadBuilder","hashPairs","stamp","insertedPayloads","index","insertPayloadIntoCache","nextHandler","options","limit","offset","order","reverse","allPairs","startIndex","findIndex","slice","undefined","withMeta","addStorageMeta","set"]}
@@ -1,2 +0,0 @@
1
- export * from './MemoryArchivist.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './MemoryArchivist.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './MemoryArchivist.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
@@ -1,144 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // src/MemoryArchivist.ts
5
- import { assertEx } from "@xylabs/assert";
6
- import { exists } from "@xylabs/exists";
7
- import { compact } from "@xylabs/lodash";
8
- import { fulfilled } from "@xylabs/promise";
9
- import { AbstractArchivist, addStorageMeta, removeStorageMeta, sortByStorageMeta } from "@xyo-network/archivist-abstract";
10
- import { ArchivistAllQuerySchema, ArchivistClearQuerySchema, ArchivistCommitQuerySchema, ArchivistDeleteQuerySchema, ArchivistInsertQuerySchema, ArchivistNextQuerySchema } from "@xyo-network/archivist-model";
11
- import { creatableModule } from "@xyo-network/module-model";
12
- import { PayloadBuilder } from "@xyo-network/payload-builder";
13
- import { LRUCache } from "lru-cache";
14
- function _ts_decorate(decorators, target, key, desc) {
15
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19
- }
20
- __name(_ts_decorate, "_ts_decorate");
21
- var MemoryArchivistConfigSchema = "network.xyo.archivist.memory.config";
22
- var MemoryArchivist = class extends AbstractArchivist {
23
- static {
24
- __name(this, "MemoryArchivist");
25
- }
26
- static configSchemas = [
27
- ...super.configSchemas,
28
- MemoryArchivistConfigSchema
29
- ];
30
- static defaultConfigSchema = MemoryArchivistConfigSchema;
31
- _cache;
32
- _dataHashIndex;
33
- get queries() {
34
- return [
35
- ArchivistAllQuerySchema,
36
- ArchivistDeleteQuerySchema,
37
- ArchivistClearQuerySchema,
38
- ArchivistInsertQuerySchema,
39
- ArchivistCommitQuerySchema,
40
- ArchivistNextQuerySchema,
41
- ...super.queries
42
- ];
43
- }
44
- get cache() {
45
- this._cache = this._cache ?? new LRUCache({
46
- max: this.max
47
- });
48
- return this._cache;
49
- }
50
- get dataHashIndex() {
51
- this._dataHashIndex = this._dataHashIndex ?? new LRUCache({
52
- max: this.max
53
- });
54
- return this._dataHashIndex;
55
- }
56
- get max() {
57
- return this.config?.max ?? 1e4;
58
- }
59
- allHandler() {
60
- const all = compact(this.cache.dump().map(([, item]) => item.value));
61
- return sortByStorageMeta(all).map((payload) => removeStorageMeta(payload));
62
- }
63
- clearHandler() {
64
- this.cache.clear();
65
- this.dataHashIndex.clear();
66
- return this.emit("cleared", {
67
- mod: this
68
- });
69
- }
70
- async commitHandler() {
71
- const payloads = assertEx(await this.allHandler(), () => "Nothing to commit");
72
- const settled = await Promise.allSettled(compact(Object.values((await this.parentArchivists()).commit ?? [])?.map(async (parent) => {
73
- const queryPayload = {
74
- schema: ArchivistInsertQuerySchema
75
- };
76
- const query = await this.bindQuery(queryPayload, payloads);
77
- return (await parent?.query(query[0], query[1]))?.[0];
78
- })));
79
- await this.clearHandler();
80
- return compact(settled.filter(fulfilled).map((result) => result.value));
81
- }
82
- deleteHandler(hashes) {
83
- const deletedHashes = this.cache.dump().map(([key, item]) => {
84
- if (hashes.includes(key) || hashes.includes(item.value.$hash)) {
85
- this.cache.delete(key);
86
- return key;
87
- }
88
- }).filter(exists);
89
- this.rebuildDataHashIndex();
90
- return deletedHashes;
91
- }
92
- getHandler(hashes) {
93
- return compact(hashes.map((hash) => {
94
- const resolvedHash = this.dataHashIndex.get(hash) ?? hash;
95
- const result = this.cache.get(resolvedHash);
96
- if (resolvedHash !== hash && !result) {
97
- throw new Error("Missing referenced payload");
98
- }
99
- return removeStorageMeta(result);
100
- }));
101
- }
102
- async insertHandler(payloads) {
103
- const pairs = await PayloadBuilder.hashPairs(payloads, {
104
- stamp: false
105
- });
106
- const insertedPayloads = pairs.map(([payload, hash], index) => {
107
- return this.cache.get(hash) ?? this.insertPayloadIntoCache(payload, hash, index);
108
- });
109
- return removeStorageMeta(insertedPayloads);
110
- }
111
- async nextHandler(options) {
112
- const { limit, offset, order } = options ?? {};
113
- let all = await this.allHandler();
114
- if (order === "desc") {
115
- all = all.reverse();
116
- }
117
- const allPairs = await PayloadBuilder.hashPairs(all);
118
- const startIndex = offset ? allPairs.findIndex(([, hash]) => hash === offset) + 1 : 0;
119
- return allPairs.slice(startIndex, limit ? startIndex + limit : void 0).map(([payload]) => payload);
120
- }
121
- insertPayloadIntoCache(payload, hash, index = 0) {
122
- const withMeta = addStorageMeta(payload, index);
123
- this.cache.set(hash, withMeta);
124
- this.dataHashIndex.set(withMeta.$hash, hash);
125
- return withMeta;
126
- }
127
- rebuildDataHashIndex() {
128
- this._dataHashIndex = new LRUCache({
129
- max: this.max
130
- });
131
- const pairs = this.cache.dump();
132
- for (const [hash, payload] of pairs) {
133
- this.dataHashIndex.set(payload.value.$hash, hash);
134
- }
135
- }
136
- };
137
- MemoryArchivist = _ts_decorate([
138
- creatableModule()
139
- ], MemoryArchivist);
140
- export {
141
- MemoryArchivist,
142
- MemoryArchivistConfigSchema
143
- };
144
- //# sourceMappingURL=index.mjs.map