@xyo-network/archivist-model 5.2.5 → 5.2.7

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.
@@ -82,29 +82,31 @@ var buildStandardIndexName = (index) => {
82
82
 
83
83
  // src/lib/getBoundWitness.ts
84
84
  import { assertEx } from "@xylabs/assert";
85
- import { isBoundWitnessWithStorageMeta } from "@xyo-network/boundwitness-model";
86
- var tryGetTypedBoundWitness = async (archivist, hash, identity) => {
85
+ import { isBoundWitness } from "@xyo-network/boundwitness-model";
86
+ import { isStorageMeta } from "@xyo-network/payload-model";
87
+ var tryGetTypedBoundWitnessWithStorageMeta = async (archivist, hash, identity) => {
87
88
  const payload = (await archivist.get([hash])).at(0);
88
89
  return identity(payload) ? payload : void 0;
89
90
  };
90
- var getTypedBoundWitness = async (archivist, hash, identity) => {
91
+ var getTypedBoundWitnessWithStorageMeta = async (archivist, hash, identity) => {
91
92
  const payload = assertEx((await archivist.get([hash])).at(0), () => `failed to locate bound witness: ${hash}`);
92
93
  return assertEx(identity(payload) ? payload : void 0, () => `located payload failed identity check: ${hash}`);
93
94
  };
94
- var getBoundWitness = (archivist, hash) => {
95
- return getTypedBoundWitness(archivist, hash, isBoundWitnessWithStorageMeta);
95
+ var getBoundWitnessWithStorageMeta = (archivist, hash) => {
96
+ return getTypedBoundWitnessWithStorageMeta(archivist, hash, (x) => isStorageMeta(x) && isBoundWitness(x));
96
97
  };
97
98
 
98
99
  // src/lib/hydrateBoundWitness.ts
99
100
  import { exists } from "@xylabs/exists";
100
101
  import { isHash } from "@xylabs/hex";
101
- import { isBoundWitnessWithStorageMeta as isBoundWitnessWithStorageMeta2 } from "@xyo-network/boundwitness-model";
102
+ import { isBoundWitness as isBoundWitness2 } from "@xyo-network/boundwitness-model";
103
+ import { isStorageMeta as isStorageMeta2 } from "@xyo-network/payload-model";
102
104
  var tryHydrateTypedBoundWitness = async (archivist, hashOrBw, identity) => {
103
- const bw = isHash(hashOrBw) ? await tryGetTypedBoundWitness(archivist, hashOrBw, identity) : hashOrBw;
105
+ const bw = isHash(hashOrBw) ? await tryGetTypedBoundWitnessWithStorageMeta(archivist, hashOrBw, identity) : hashOrBw;
104
106
  return bw ? [bw, (await archivist.get(bw?.payload_hashes)).filter(exists)] : void 0;
105
107
  };
106
108
  var hydrateTypedBoundWitness = async (archivist, hashOrBw, identity) => {
107
- const bw = isHash(hashOrBw) ? await getTypedBoundWitness(archivist, hashOrBw, identity) : hashOrBw;
109
+ const bw = isHash(hashOrBw) ? await getTypedBoundWitnessWithStorageMeta(archivist, hashOrBw, identity) : hashOrBw;
108
110
  const payloads = (await archivist.get(bw?.payload_hashes)).filter(exists);
109
111
  if (payloads.length !== bw.payload_hashes.length) {
110
112
  throw new Error(`missing payloads for ${bw._hash}`);
@@ -112,7 +114,8 @@ var hydrateTypedBoundWitness = async (archivist, hashOrBw, identity) => {
112
114
  return [bw, payloads];
113
115
  };
114
116
  var hydrateBoundWitness = (archivist, hashOrBw) => {
115
- return hydrateTypedBoundWitness(archivist, hashOrBw, isBoundWitnessWithStorageMeta2);
117
+ const idFunction = (x) => isBoundWitness2(x) && isStorageMeta2(x);
118
+ return hydrateTypedBoundWitness(archivist, hashOrBw, idFunction);
116
119
  };
117
120
  export {
118
121
  ArchivistAllQuerySchema,
@@ -132,15 +135,15 @@ export {
132
135
  asArchivistModule,
133
136
  asAttachableArchivistInstance,
134
137
  buildStandardIndexName,
135
- getBoundWitness,
136
- getTypedBoundWitness,
138
+ getBoundWitnessWithStorageMeta,
139
+ getTypedBoundWitnessWithStorageMeta,
137
140
  hydrateBoundWitness,
138
141
  hydrateTypedBoundWitness,
139
142
  isArchivistInstance,
140
143
  isArchivistModule,
141
144
  isAttachableArchivistInstance,
142
145
  requiredAttachableArchivistInstanceFunctions,
143
- tryGetTypedBoundWitness,
146
+ tryGetTypedBoundWitnessWithStorageMeta,
144
147
  tryHydrateTypedBoundWitness,
145
148
  withArchivistInstance,
146
149
  withArchivistModule
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ArchivistSnapshot.ts","../../src/ArchivistStats.ts","../../src/attachable/asAttachableInstance.ts","../../src/attachable/isAttachableInstance.ts","../../src/typeChecks.ts","../../src/Queries/All.ts","../../src/Queries/Clear.ts","../../src/Queries/Commit.ts","../../src/Queries/Delete.ts","../../src/Queries/Get.ts","../../src/Queries/Insert.ts","../../src/Queries/Next.ts","../../src/Queries/Snapshot.ts","../../src/attachable/AttachableInstance.ts","../../src/Config.ts","../../src/IndexDescription.ts","../../src/lib/getBoundWitness.ts","../../src/lib/hydrateBoundWitness.ts"],"sourcesContent":["import type { Hash } from '@xylabs/hex'\nimport type { Payload, PayloadHashMap } from '@xyo-network/payload-model'\n\nexport const ArchivistSnapshotPayloadSchema = 'network.xyo.archivist.snapshot' as const\nexport type ArchivistSnapshotPayloadSchema = typeof ArchivistSnapshotPayloadSchema\n\nexport type ArchivistSnapshotPayload<TPayload extends Payload = Payload, TId extends string | number | symbol = Hash>\n = Payload<PayloadHashMap<TPayload, TId>, ArchivistSnapshotPayloadSchema>\n","import type { Payload } from '@xyo-network/payload-model'\n\nexport const ArchivistStatsPayloadSchema = 'network.xyo.archivist.stats' as const\nexport type ArchivistStatsPayloadSchema = typeof ArchivistStatsPayloadSchema\n\nexport type ArchivistStatsPayload\n = Payload<{ payloadCount: number }, ArchivistStatsPayloadSchema>\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isAttachableArchivistInstance } from './isAttachableInstance.ts'\n\nexport const asAttachableArchivistInstance = AsObjectFactory.create(isAttachableArchivistInstance)\n","import type { TypeCheck } from '@xylabs/object'\nimport { IsObjectFactory } from '@xylabs/object'\nimport type { ObjectTypeShape } from '@xylabs/typeof'\nimport { isAttachableModuleInstance } from '@xyo-network/module-model'\n\nimport { isArchivistInstance } from '../typeChecks.ts'\nimport type { AttachableArchivistInstance } from './AttachableInstance.ts'\n\nexport const requiredAttachableArchivistInstanceFunctions: ObjectTypeShape = {}\n\n// we do not use IsInstanceFactory here to prevent a cycle\nconst factory = new IsObjectFactory<AttachableArchivistInstance>()\n\nexport const isAttachableArchivistInstance: TypeCheck<AttachableArchivistInstance> = factory.create(requiredAttachableArchivistInstanceFunctions, [\n isArchivistInstance,\n isAttachableModuleInstance,\n])\n","import type { TypeCheck } from '@xylabs/object'\nimport { AsObjectFactory } from '@xylabs/object'\nimport {\n IsInstanceFactory, IsModuleFactory, isModuleInstance, WithFactory,\n} from '@xyo-network/module-model'\n\nimport type { ArchivistInstance } from './Instance.ts'\nimport type { ArchivistModuleInstance } from './ModuleInstance.ts'\nimport { ArchivistGetQuerySchema } from './Queries/index.ts'\n\nexport const isArchivistInstance: TypeCheck<ArchivistInstance> = new IsInstanceFactory<ArchivistInstance>().create({ get: 'function' }, [isModuleInstance])\nexport const isArchivistModule: TypeCheck<ArchivistModuleInstance> = new IsModuleFactory<ArchivistModuleInstance>().create([ArchivistGetQuerySchema])\n\nexport const asArchivistModule = AsObjectFactory.create(isArchivistModule)\nexport const asArchivistInstance = AsObjectFactory.create(isArchivistInstance)\nexport const withArchivistModule = WithFactory.create(isArchivistModule)\nexport const withArchivistInstance = WithFactory.create(isArchivistInstance)\n","import type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistAllQuerySchema = 'network.xyo.query.archivist.all' as const\nexport type ArchivistAllQuerySchema = typeof ArchivistAllQuerySchema\n\nexport type ArchivistAllQuery = Query<{\n schema: ArchivistAllQuerySchema\n}>\n","import type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistClearQuerySchema = 'network.xyo.query.archivist.clear' as const\nexport type ArchivistClearQuerySchema = typeof ArchivistClearQuerySchema\n\nexport type ArchivistClearQuery = Query<{\n schema: ArchivistClearQuerySchema\n}>\n","import type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistCommitQuerySchema = 'network.xyo.query.archivist.commit' as const\nexport type ArchivistCommitQuerySchema = typeof ArchivistCommitQuerySchema\n\nexport type ArchivistCommitQuery = Query<{\n schema: ArchivistCommitQuerySchema\n}>\n","import type { Hash } from '@xylabs/hex'\nimport type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistDeleteQuerySchema = 'network.xyo.query.archivist.delete' as const\nexport type ArchivistDeleteQuerySchema = typeof ArchivistDeleteQuerySchema\n\nexport type ArchivistDeleteQuery = Query<{\n hashes: Hash[]\n schema: ArchivistDeleteQuerySchema\n}>\n","import type { Hash } from '@xylabs/hex'\nimport type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistGetQuerySchema = 'network.xyo.query.archivist.get' as const\nexport type ArchivistGetQuerySchema = typeof ArchivistGetQuerySchema\n\nexport type ArchivistGetQuery = Query<{\n hashes: Hash[]\n schema: ArchivistGetQuerySchema\n}>\n","import type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistInsertQuerySchema = 'network.xyo.query.archivist.insert' as const\nexport type ArchivistInsertQuerySchema = typeof ArchivistInsertQuerySchema\n\nexport type ArchivistInsertQuery = Query<{\n schema: ArchivistInsertQuerySchema\n}>\n","import type { Query } from '@xyo-network/payload-model'\n\nimport type { ArchivistNextOptions } from '../NextOptions.ts'\n\nexport const ArchivistNextQuerySchema = 'network.xyo.query.archivist.next' as const\nexport type ArchivistNextQuerySchema = typeof ArchivistNextQuerySchema\n\nexport type ArchivistNextQuery = Query<ArchivistNextOptions, ArchivistNextQuerySchema>\n","import type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistSnapshotQuerySchema = 'network.xyo.query.archivist.snapshot' as const\nexport type ArchivistSnapshotQuerySchema = typeof ArchivistSnapshotQuerySchema\n\nexport type ArchivistSnapshotQuery = Query<{\n schema: ArchivistSnapshotQuerySchema\n}>\n","import type { TypeCheck } from '@xylabs/object'\nimport { IsObjectFactory } from '@xylabs/object'\nimport type { AttachableModuleInstance } from '@xyo-network/module-model'\nimport type { Payload } from '@xyo-network/payload-model'\n\nimport type { ArchivistModuleEventData } from '../EventData.ts'\nimport type { ArchivistInstance } from '../Instance.ts'\nimport type { ArchivistModuleInstance } from '../ModuleInstance.ts'\nimport type { ArchivistParams } from '../Params.ts'\n\nexport interface AttachableArchivistInstance<\n TParams extends ArchivistParams = ArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n TPayload extends Payload = Payload,\n> extends ArchivistModuleInstance<TParams, TEventData>,\n AttachableModuleInstance<TParams, TEventData>,\n ArchivistInstance<TParams, TEventData, TPayload> {}\n\nexport type AttachableArchivistInstanceTypeCheck<T extends AttachableArchivistInstance = AttachableArchivistInstance> = TypeCheck<T>\n\nexport class IsAttachableArchivistInstanceFactory<T extends AttachableArchivistInstance = AttachableArchivistInstance> extends IsObjectFactory<T> {}\n","import type { EmptyObject, WithAdditional } from '@xylabs/object'\nimport type { ModuleConfig, ModuleIdentifier } from '@xyo-network/module-model'\nimport type { Payload } from '@xyo-network/payload-model'\n\nimport type { IndexDescription } from './IndexDescription.ts'\n\nexport interface ArchivistParents {\n commit?: ModuleIdentifier[]\n read?: ModuleIdentifier[]\n write?: ModuleIdentifier[]\n}\n\nexport interface ArchivistStorage {\n /** The indexes to create on the object store */\n indexes?: IndexDescription[]\n}\n\nexport interface ArchivistGetCache {\n enabled?: boolean\n maxEntries?: number\n}\n\nexport const ArchivistConfigSchema = 'network.xyo.archivist.config' as const\nexport type ArchivistConfigSchema = typeof ArchivistConfigSchema\n\nexport type ArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchema extends string | void = void> = ModuleConfig<\n WithAdditional<\n {\n /** @field caching configuration for get calls */\n getCache?: ArchivistGetCache\n /** @field address of one or more parent archivists to read from */\n parents?: ArchivistParents\n /** @field fail if some parents can not be resolved (true if unspecified) */\n requireAllParents?: boolean\n schema: TConfig extends Payload ? TConfig['schema'] : ArchivistConfigSchema\n /** @field storage configuration */\n storage?: ArchivistStorage\n /** @field should child store all reads from parents? */\n storeParentReads?: boolean\n },\n TConfig\n >,\n TSchema\n>\n","/**\n * The index direction (1 for ascending, -1 for descending)\n */\nexport type IndexDirection = -1 | 1\n\n/**\n * Description of index(es) to be created on a store\n */\nexport type IndexDescription = {\n /**\n * The key(s) to index\n */\n key: Record<string, IndexDirection>\n /**\n * Is the indexed value an array\n */\n multiEntry?: boolean\n /**\n * The name of the index\n */\n name?: string\n /**\n * If true, the index must enforce uniqueness on the key\n */\n unique?: boolean\n}\n\nexport const IndexSeparator = '-'\n\n/**\n * Given an index description, this will build the index\n * name in standard form\n * @param index The index description\n * @returns The index name in standard form\n */\nexport const buildStandardIndexName = (index: IndexDescription) => {\n const { key, unique } = index\n const prefix = unique ? 'UX' : 'IX'\n const indexKeys = Object.keys(key)\n return `${prefix}_${indexKeys.join(IndexSeparator)}`\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { Hash } from '@xylabs/hex'\nimport type { IdentityFunction } from '@xylabs/typeof'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { isBoundWitnessWithStorageMeta } from '@xyo-network/boundwitness-model'\nimport type { WithStorageMeta } from '@xyo-network/payload-model'\n\nimport type { ReadArchivist } from '../PayloadArchivist.ts'\n\nexport const tryGetTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash,\n identity: IdentityFunction<WithStorageMeta<T>>): Promise<WithStorageMeta<T> | undefined> => {\n const payload = (await archivist.get([hash])).at(0)\n return identity(payload) ? payload : undefined\n}\n\nexport const getTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash,\n identity: IdentityFunction<WithStorageMeta<T>>): Promise<WithStorageMeta<T>> => {\n const payload = assertEx((await archivist.get([hash])).at(0), () => `failed to locate bound witness: ${hash}`)\n return assertEx(identity(payload) ? payload : undefined, () => `located payload failed identity check: ${hash}`)\n}\n\nexport const getBoundWitness = (archivist: ReadArchivist, hash: Hash): Promise<WithStorageMeta<BoundWitness>> => {\n return getTypedBoundWitness<BoundWitness>(archivist, hash, isBoundWitnessWithStorageMeta)\n}\n","import { exists } from '@xylabs/exists'\nimport type { Hash } from '@xylabs/hex'\nimport { isHash } from '@xylabs/hex'\nimport type { IdentityFunction } from '@xylabs/typeof'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { isBoundWitnessWithStorageMeta } from '@xyo-network/boundwitness-model'\nimport type { WithStorageMeta } from '@xyo-network/payload-model'\n\nimport type { ReadArchivist } from '../PayloadArchivist.ts'\nimport { getTypedBoundWitness, tryGetTypedBoundWitness } from './getBoundWitness.ts'\nimport type { HydratedBoundWitness } from './HydratedBoundWitness.ts'\n\nexport const tryHydrateTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>,\n identity: IdentityFunction<WithStorageMeta<T>>): Promise<HydratedBoundWitness<T> | undefined> => {\n const bw = isHash(hashOrBw) ? await tryGetTypedBoundWitness(archivist, hashOrBw, identity) : hashOrBw\n return bw ? [bw, (await archivist.get(bw?.payload_hashes as Hash[])).filter(exists)] : undefined\n}\n\nexport const hydrateTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>,\n identity: IdentityFunction<WithStorageMeta<T>>): Promise<HydratedBoundWitness<T>> => {\n const bw = isHash(hashOrBw) ? await getTypedBoundWitness(archivist, hashOrBw, identity) : hashOrBw\n const payloads = (await archivist.get(bw?.payload_hashes as Hash[])).filter(exists)\n if (payloads.length !== bw.payload_hashes.length) {\n throw new Error(`missing payloads for ${bw._hash}`)\n }\n return [bw, payloads]\n}\n\nexport const hydrateBoundWitness = (\n archivist: ReadArchivist,\n hashOrBw: Hash | WithStorageMeta<BoundWitness>,\n): Promise<HydratedBoundWitness<BoundWitness>> => {\n return hydrateTypedBoundWitness<BoundWitness>(archivist, hashOrBw, isBoundWitnessWithStorageMeta)\n}\n"],"mappings":";AAGO,IAAM,iCAAiC;;;ACDvC,IAAM,8BAA8B;;;ACF3C,SAAS,mBAAAA,wBAAuB;;;ACChC,SAAS,uBAAuB;AAEhC,SAAS,kCAAkC;;;ACF3C,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,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ts","../../src/ArchivistStats.ts","../../src/attachable/asAttachableInstance.ts","../../src/attachable/isAttachableInstance.ts","../../src/typeChecks.ts","../../src/Queries/All.ts","../../src/Queries/Clear.ts","../../src/Queries/Commit.ts","../../src/Queries/Delete.ts","../../src/Queries/Get.ts","../../src/Queries/Insert.ts","../../src/Queries/Next.ts","../../src/Queries/Snapshot.ts","../../src/attachable/AttachableInstance.ts","../../src/Config.ts","../../src/IndexDescription.ts","../../src/lib/getBoundWitness.ts","../../src/lib/hydrateBoundWitness.ts"],"sourcesContent":["import type { Hash } from '@xylabs/hex'\nimport type { Payload, PayloadHashMap } from '@xyo-network/payload-model'\n\nexport const ArchivistSnapshotPayloadSchema = 'network.xyo.archivist.snapshot' as const\nexport type ArchivistSnapshotPayloadSchema = typeof ArchivistSnapshotPayloadSchema\n\nexport type ArchivistSnapshotPayload<TPayload extends Payload = Payload, TId extends string | number | symbol = Hash>\n = Payload<PayloadHashMap<TPayload, TId>, ArchivistSnapshotPayloadSchema>\n","import type { Payload } from '@xyo-network/payload-model'\n\nexport const ArchivistStatsPayloadSchema = 'network.xyo.archivist.stats' as const\nexport type ArchivistStatsPayloadSchema = typeof ArchivistStatsPayloadSchema\n\nexport type ArchivistStatsPayload\n = Payload<{ payloadCount: number }, ArchivistStatsPayloadSchema>\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isAttachableArchivistInstance } from './isAttachableInstance.ts'\n\nexport const asAttachableArchivistInstance = AsObjectFactory.create(isAttachableArchivistInstance)\n","import type { TypeCheck } from '@xylabs/object'\nimport { IsObjectFactory } from '@xylabs/object'\nimport type { ObjectTypeShape } from '@xylabs/typeof'\nimport { isAttachableModuleInstance } from '@xyo-network/module-model'\n\nimport { isArchivistInstance } from '../typeChecks.ts'\nimport type { AttachableArchivistInstance } from './AttachableInstance.ts'\n\nexport const requiredAttachableArchivistInstanceFunctions: ObjectTypeShape = {}\n\n// we do not use IsInstanceFactory here to prevent a cycle\nconst factory = new IsObjectFactory<AttachableArchivistInstance>()\n\nexport const isAttachableArchivistInstance: TypeCheck<AttachableArchivistInstance> = factory.create(requiredAttachableArchivistInstanceFunctions, [\n isArchivistInstance,\n isAttachableModuleInstance,\n])\n","import type { TypeCheck } from '@xylabs/object'\nimport { AsObjectFactory } from '@xylabs/object'\nimport {\n IsInstanceFactory, IsModuleFactory, isModuleInstance, WithFactory,\n} from '@xyo-network/module-model'\n\nimport type { ArchivistInstance } from './Instance.ts'\nimport type { ArchivistModuleInstance } from './ModuleInstance.ts'\nimport { ArchivistGetQuerySchema } from './Queries/index.ts'\n\nexport const isArchivistInstance: TypeCheck<ArchivistInstance> = new IsInstanceFactory<ArchivistInstance>().create({ get: 'function' }, [isModuleInstance])\nexport const isArchivistModule: TypeCheck<ArchivistModuleInstance> = new IsModuleFactory<ArchivistModuleInstance>().create([ArchivistGetQuerySchema])\n\nexport const asArchivistModule = AsObjectFactory.create(isArchivistModule)\nexport const asArchivistInstance = AsObjectFactory.create(isArchivistInstance)\nexport const withArchivistModule = WithFactory.create(isArchivistModule)\nexport const withArchivistInstance = WithFactory.create(isArchivistInstance)\n","import type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistAllQuerySchema = 'network.xyo.query.archivist.all' as const\nexport type ArchivistAllQuerySchema = typeof ArchivistAllQuerySchema\n\nexport type ArchivistAllQuery = Query<{\n schema: ArchivistAllQuerySchema\n}>\n","import type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistClearQuerySchema = 'network.xyo.query.archivist.clear' as const\nexport type ArchivistClearQuerySchema = typeof ArchivistClearQuerySchema\n\nexport type ArchivistClearQuery = Query<{\n schema: ArchivistClearQuerySchema\n}>\n","import type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistCommitQuerySchema = 'network.xyo.query.archivist.commit' as const\nexport type ArchivistCommitQuerySchema = typeof ArchivistCommitQuerySchema\n\nexport type ArchivistCommitQuery = Query<{\n schema: ArchivistCommitQuerySchema\n}>\n","import type { Hash } from '@xylabs/hex'\nimport type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistDeleteQuerySchema = 'network.xyo.query.archivist.delete' as const\nexport type ArchivistDeleteQuerySchema = typeof ArchivistDeleteQuerySchema\n\nexport type ArchivistDeleteQuery = Query<{\n hashes: Hash[]\n schema: ArchivistDeleteQuerySchema\n}>\n","import type { Hash } from '@xylabs/hex'\nimport type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistGetQuerySchema = 'network.xyo.query.archivist.get' as const\nexport type ArchivistGetQuerySchema = typeof ArchivistGetQuerySchema\n\nexport type ArchivistGetQuery = Query<{\n hashes: Hash[]\n schema: ArchivistGetQuerySchema\n}>\n","import type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistInsertQuerySchema = 'network.xyo.query.archivist.insert' as const\nexport type ArchivistInsertQuerySchema = typeof ArchivistInsertQuerySchema\n\nexport type ArchivistInsertQuery = Query<{\n schema: ArchivistInsertQuerySchema\n}>\n","import type { Query } from '@xyo-network/payload-model'\n\nimport type { ArchivistNextOptions } from '../NextOptions.ts'\n\nexport const ArchivistNextQuerySchema = 'network.xyo.query.archivist.next' as const\nexport type ArchivistNextQuerySchema = typeof ArchivistNextQuerySchema\n\nexport type ArchivistNextQuery = Query<ArchivistNextOptions, ArchivistNextQuerySchema>\n","import type { Query } from '@xyo-network/payload-model'\n\nexport const ArchivistSnapshotQuerySchema = 'network.xyo.query.archivist.snapshot' as const\nexport type ArchivistSnapshotQuerySchema = typeof ArchivistSnapshotQuerySchema\n\nexport type ArchivistSnapshotQuery = Query<{\n schema: ArchivistSnapshotQuerySchema\n}>\n","import type { TypeCheck } from '@xylabs/object'\nimport { IsObjectFactory } from '@xylabs/object'\nimport type { AttachableModuleInstance } from '@xyo-network/module-model'\nimport type { Payload } from '@xyo-network/payload-model'\n\nimport type { ArchivistModuleEventData } from '../EventData.ts'\nimport type { ArchivistInstance } from '../Instance.ts'\nimport type { ArchivistModuleInstance } from '../ModuleInstance.ts'\nimport type { ArchivistParams } from '../Params.ts'\n\nexport interface AttachableArchivistInstance<\n TParams extends ArchivistParams = ArchivistParams,\n TEventData extends ArchivistModuleEventData = ArchivistModuleEventData,\n TPayload extends Payload = Payload,\n> extends ArchivistModuleInstance<TParams, TEventData>,\n AttachableModuleInstance<TParams, TEventData>,\n ArchivistInstance<TParams, TEventData, TPayload> {}\n\nexport type AttachableArchivistInstanceTypeCheck<T extends AttachableArchivistInstance = AttachableArchivistInstance> = TypeCheck<T>\n\nexport class IsAttachableArchivistInstanceFactory<T extends AttachableArchivistInstance = AttachableArchivistInstance> extends IsObjectFactory<T> {}\n","import type { EmptyObject, WithAdditional } from '@xylabs/object'\nimport type { ModuleConfig, ModuleIdentifier } from '@xyo-network/module-model'\nimport type { Payload } from '@xyo-network/payload-model'\n\nimport type { IndexDescription } from './IndexDescription.ts'\n\nexport interface ArchivistParents {\n commit?: ModuleIdentifier[]\n read?: ModuleIdentifier[]\n write?: ModuleIdentifier[]\n}\n\nexport interface ArchivistStorage {\n /** The indexes to create on the object store */\n indexes?: IndexDescription[]\n}\n\nexport interface ArchivistGetCache {\n enabled?: boolean\n maxEntries?: number\n}\n\nexport const ArchivistConfigSchema = 'network.xyo.archivist.config' as const\nexport type ArchivistConfigSchema = typeof ArchivistConfigSchema\n\nexport type ArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchema extends string | void = void> = ModuleConfig<\n WithAdditional<\n {\n /** @field caching configuration for get calls */\n getCache?: ArchivistGetCache\n /** @field address of one or more parent archivists to read from */\n parents?: ArchivistParents\n /** @field fail if some parents can not be resolved (true if unspecified) */\n requireAllParents?: boolean\n schema: TConfig extends Payload ? TConfig['schema'] : ArchivistConfigSchema\n /** @field storage configuration */\n storage?: ArchivistStorage\n /** @field should child store all reads from parents? */\n storeParentReads?: boolean\n },\n TConfig\n >,\n TSchema\n>\n","/**\n * The index direction (1 for ascending, -1 for descending)\n */\nexport type IndexDirection = -1 | 1\n\n/**\n * Description of index(es) to be created on a store\n */\nexport type IndexDescription = {\n /**\n * The key(s) to index\n */\n key: Record<string, IndexDirection>\n /**\n * Is the indexed value an array\n */\n multiEntry?: boolean\n /**\n * The name of the index\n */\n name?: string\n /**\n * If true, the index must enforce uniqueness on the key\n */\n unique?: boolean\n}\n\nexport const IndexSeparator = '-'\n\n/**\n * Given an index description, this will build the index\n * name in standard form\n * @param index The index description\n * @returns The index name in standard form\n */\nexport const buildStandardIndexName = (index: IndexDescription) => {\n const { key, unique } = index\n const prefix = unique ? 'UX' : 'IX'\n const indexKeys = Object.keys(key)\n return `${prefix}_${indexKeys.join(IndexSeparator)}`\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { Hash } from '@xylabs/hex'\nimport type { IdentityFunction } from '@xylabs/typeof'\nimport { type BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { isStorageMeta, type WithStorageMeta } from '@xyo-network/payload-model'\n\nimport type { ReadArchivist } from '../PayloadArchivist.ts'\n\nexport const tryGetTypedBoundWitnessWithStorageMeta = async <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash,\n identity: IdentityFunction<WithStorageMeta<T>>): Promise<WithStorageMeta<T> | undefined> => {\n const payload = (await archivist.get([hash])).at(0)\n return identity(payload) ? payload : undefined\n}\n\nexport const getTypedBoundWitnessWithStorageMeta = async <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash,\n identity: IdentityFunction<WithStorageMeta<T>>): Promise<WithStorageMeta<T>> => {\n const payload = assertEx((await archivist.get([hash])).at(0), () => `failed to locate bound witness: ${hash}`)\n return assertEx(identity(payload) ? payload : undefined, () => `located payload failed identity check: ${hash}`)\n}\n\nexport const getBoundWitnessWithStorageMeta = (archivist: ReadArchivist, hash: Hash): Promise<WithStorageMeta<BoundWitness>> => {\n return getTypedBoundWitnessWithStorageMeta<BoundWitness>(archivist, hash, x => isStorageMeta(x) && isBoundWitness(x))\n}\n","import { exists } from '@xylabs/exists'\nimport type { Hash } from '@xylabs/hex'\nimport { isHash } from '@xylabs/hex'\nimport type { IdentityFunction } from '@xylabs/typeof'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { isStorageMeta, type WithStorageMeta } from '@xyo-network/payload-model'\n\nimport type { ReadArchivist } from '../PayloadArchivist.ts'\nimport { getTypedBoundWitnessWithStorageMeta, tryGetTypedBoundWitnessWithStorageMeta } from './getBoundWitness.ts'\nimport type { HydratedBoundWitness } from './HydratedBoundWitness.ts'\n\nexport const tryHydrateTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>,\n identity: IdentityFunction<WithStorageMeta<T>>): Promise<HydratedBoundWitness<T> | undefined> => {\n const bw = isHash(hashOrBw) ? await tryGetTypedBoundWitnessWithStorageMeta(archivist, hashOrBw, identity) : hashOrBw\n return bw ? [bw, (await archivist.get(bw?.payload_hashes as Hash[])).filter(exists)] : undefined\n}\n\nexport const hydrateTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>,\n identity: IdentityFunction<WithStorageMeta<T>>): Promise<HydratedBoundWitness<T>> => {\n const bw = isHash(hashOrBw) ? await getTypedBoundWitnessWithStorageMeta(archivist, hashOrBw, identity) : hashOrBw\n const payloads = (await archivist.get(bw?.payload_hashes as Hash[])).filter(exists)\n if (payloads.length !== bw.payload_hashes.length) {\n throw new Error(`missing payloads for ${bw._hash}`)\n }\n return [bw, payloads]\n}\n\nexport const hydrateBoundWitness = (\n archivist: ReadArchivist,\n hashOrBw: Hash | WithStorageMeta<BoundWitness>,\n): Promise<HydratedBoundWitness<BoundWitness>> => {\n const idFunction: IdentityFunction<WithStorageMeta<BoundWitness>> = x => isBoundWitness(x) && isStorageMeta(x)\n return hydrateTypedBoundWitness<BoundWitness>(archivist, hashOrBw, idFunction)\n}\n"],"mappings":";AAGO,IAAM,iCAAiC;;;ACDvC,IAAM,8BAA8B;;;ACF3C,SAAS,mBAAAA,wBAAuB;;;ACChC,SAAS,uBAAuB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A8D,OAAKC,gBAAe,CAAC,KAAKC,eAAc,CAAC;AAC7G,SAAO,yBAAuC,WAAW,UAAU,UAAU;AAC/E;","names":["AsObjectFactory","AsObjectFactory","IsObjectFactory","isBoundWitness","isStorageMeta","isBoundWitness","isStorageMeta"]}
@@ -1,9 +1,9 @@
1
1
  import type { Hash } from '@xylabs/hex';
2
2
  import type { IdentityFunction } from '@xylabs/typeof';
3
- import type { BoundWitness } from '@xyo-network/boundwitness-model';
4
- import type { WithStorageMeta } from '@xyo-network/payload-model';
3
+ import { type BoundWitness } from '@xyo-network/boundwitness-model';
4
+ import { type WithStorageMeta } from '@xyo-network/payload-model';
5
5
  import type { ReadArchivist } from '../PayloadArchivist.ts';
6
- export declare const tryGetTypedBoundWitness: <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash, identity: IdentityFunction<WithStorageMeta<T>>) => Promise<WithStorageMeta<T> | undefined>;
7
- export declare const getTypedBoundWitness: <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash, identity: IdentityFunction<WithStorageMeta<T>>) => Promise<WithStorageMeta<T>>;
8
- export declare const getBoundWitness: (archivist: ReadArchivist, hash: Hash) => Promise<WithStorageMeta<BoundWitness>>;
6
+ export declare const tryGetTypedBoundWitnessWithStorageMeta: <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash, identity: IdentityFunction<WithStorageMeta<T>>) => Promise<WithStorageMeta<T> | undefined>;
7
+ export declare const getTypedBoundWitnessWithStorageMeta: <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash, identity: IdentityFunction<WithStorageMeta<T>>) => Promise<WithStorageMeta<T>>;
8
+ export declare const getBoundWitnessWithStorageMeta: (archivist: ReadArchivist, hash: Hash) => Promise<WithStorageMeta<BoundWitness>>;
9
9
  //# sourceMappingURL=getBoundWitness.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getBoundWitness.d.ts","sourceRoot":"","sources":["../../../src/lib/getBoundWitness.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,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,EAAE,MAAM,IAAI,EACvH,UAAU,gBAAgB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,CAGxF,CAAA;AAED,eAAO,MAAM,mCAAmC,GAAU,CAAC,SAAS,YAAY,EAAE,WAAW,aAAa,EAAE,MAAM,IAAI,EACpH,UAAU,gBAAgB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAG5E,CAAA;AAED,eAAO,MAAM,8BAA8B,GAAI,WAAW,aAAa,EAAE,MAAM,IAAI,KAAG,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAE1H,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import type { Hash } from '@xylabs/hex';
2
2
  import type { IdentityFunction } from '@xylabs/typeof';
3
3
  import type { BoundWitness } from '@xyo-network/boundwitness-model';
4
- import type { WithStorageMeta } from '@xyo-network/payload-model';
4
+ import { type WithStorageMeta } from '@xyo-network/payload-model';
5
5
  import type { ReadArchivist } from '../PayloadArchivist.ts';
6
6
  import type { HydratedBoundWitness } from './HydratedBoundWitness.ts';
7
7
  export declare const tryHydrateTypedBoundWitness: <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>, identity: IdentityFunction<WithStorageMeta<T>>) => Promise<HydratedBoundWitness<T> | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"hydrateBoundWitness.d.ts","sourceRoot":"","sources":["../../../src/lib/hydrateBoundWitness.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAEnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAEjE,OAAO,KA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AAa,EAAE,UAAU,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,EACrI,UAAU,gBAAgB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,GAAG,SAAS,CAG7F,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAU,CAAC,SAAS,YAAY,EAAE,WAAW,aAAa,EAAE,UAAU,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,EAClI,UAAU,gBAAgB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAOjF,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,WAAW,aAAa,EACxB,UAAU,IAAI,GAAG,eAAe,CAAC,YAAY,CAAC,KAC7C,OAAO,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAG5C,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/archivist-model",
3
- "version": "5.2.5",
3
+ "version": "5.2.7",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -36,17 +36,17 @@
36
36
  "!**/*.test.*"
37
37
  ],
38
38
  "dependencies": {
39
- "@xylabs/assert": "~5.0.39",
40
- "@xylabs/events": "~5.0.39",
41
- "@xylabs/exists": "~5.0.39",
42
- "@xylabs/hex": "~5.0.39",
43
- "@xylabs/object": "~5.0.39",
44
- "@xylabs/promise": "~5.0.39",
45
- "@xylabs/typeof": "~5.0.39",
46
- "@xyo-network/account-model": "~5.2.5",
47
- "@xyo-network/boundwitness-model": "~5.2.5",
48
- "@xyo-network/module-model": "~5.2.5",
49
- "@xyo-network/payload-model": "~5.2.5"
39
+ "@xylabs/assert": "~5.0.42",
40
+ "@xylabs/events": "~5.0.42",
41
+ "@xylabs/exists": "~5.0.42",
42
+ "@xylabs/hex": "~5.0.42",
43
+ "@xylabs/object": "~5.0.42",
44
+ "@xylabs/promise": "~5.0.42",
45
+ "@xylabs/typeof": "~5.0.42",
46
+ "@xyo-network/account-model": "~5.2.7",
47
+ "@xyo-network/boundwitness-model": "~5.2.7",
48
+ "@xyo-network/module-model": "~5.2.7",
49
+ "@xyo-network/payload-model": "~5.2.7"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@xylabs/ts-scripts-yarn3": "~7.2.8",
@@ -1,24 +1,23 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
2
  import type { Hash } from '@xylabs/hex'
3
3
  import type { IdentityFunction } from '@xylabs/typeof'
4
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
5
- import { isBoundWitnessWithStorageMeta } from '@xyo-network/boundwitness-model'
6
- import type { WithStorageMeta } from '@xyo-network/payload-model'
4
+ import { type BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'
5
+ import { isStorageMeta, type WithStorageMeta } from '@xyo-network/payload-model'
7
6
 
8
7
  import type { ReadArchivist } from '../PayloadArchivist.ts'
9
8
 
10
- export const tryGetTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash,
9
+ export const tryGetTypedBoundWitnessWithStorageMeta = async <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash,
11
10
  identity: IdentityFunction<WithStorageMeta<T>>): Promise<WithStorageMeta<T> | undefined> => {
12
11
  const payload = (await archivist.get([hash])).at(0)
13
12
  return identity(payload) ? payload : undefined
14
13
  }
15
14
 
16
- export const getTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash,
15
+ export const getTypedBoundWitnessWithStorageMeta = async <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash,
17
16
  identity: IdentityFunction<WithStorageMeta<T>>): Promise<WithStorageMeta<T>> => {
18
17
  const payload = assertEx((await archivist.get([hash])).at(0), () => `failed to locate bound witness: ${hash}`)
19
18
  return assertEx(identity(payload) ? payload : undefined, () => `located payload failed identity check: ${hash}`)
20
19
  }
21
20
 
22
- export const getBoundWitness = (archivist: ReadArchivist, hash: Hash): Promise<WithStorageMeta<BoundWitness>> => {
23
- return getTypedBoundWitness<BoundWitness>(archivist, hash, isBoundWitnessWithStorageMeta)
21
+ export const getBoundWitnessWithStorageMeta = (archivist: ReadArchivist, hash: Hash): Promise<WithStorageMeta<BoundWitness>> => {
22
+ return getTypedBoundWitnessWithStorageMeta<BoundWitness>(archivist, hash, x => isStorageMeta(x) && isBoundWitness(x))
24
23
  }
@@ -3,22 +3,22 @@ import type { Hash } from '@xylabs/hex'
3
3
  import { isHash } from '@xylabs/hex'
4
4
  import type { IdentityFunction } from '@xylabs/typeof'
5
5
  import type { BoundWitness } from '@xyo-network/boundwitness-model'
6
- import { isBoundWitnessWithStorageMeta } from '@xyo-network/boundwitness-model'
7
- import type { WithStorageMeta } from '@xyo-network/payload-model'
6
+ import { isBoundWitness } from '@xyo-network/boundwitness-model'
7
+ import { isStorageMeta, type WithStorageMeta } from '@xyo-network/payload-model'
8
8
 
9
9
  import type { ReadArchivist } from '../PayloadArchivist.ts'
10
- import { getTypedBoundWitness, tryGetTypedBoundWitness } from './getBoundWitness.ts'
10
+ import { getTypedBoundWitnessWithStorageMeta, tryGetTypedBoundWitnessWithStorageMeta } from './getBoundWitness.ts'
11
11
  import type { HydratedBoundWitness } from './HydratedBoundWitness.ts'
12
12
 
13
13
  export const tryHydrateTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>,
14
14
  identity: IdentityFunction<WithStorageMeta<T>>): Promise<HydratedBoundWitness<T> | undefined> => {
15
- const bw = isHash(hashOrBw) ? await tryGetTypedBoundWitness(archivist, hashOrBw, identity) : hashOrBw
15
+ const bw = isHash(hashOrBw) ? await tryGetTypedBoundWitnessWithStorageMeta(archivist, hashOrBw, identity) : hashOrBw
16
16
  return bw ? [bw, (await archivist.get(bw?.payload_hashes as Hash[])).filter(exists)] : undefined
17
17
  }
18
18
 
19
19
  export const hydrateTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>,
20
20
  identity: IdentityFunction<WithStorageMeta<T>>): Promise<HydratedBoundWitness<T>> => {
21
- const bw = isHash(hashOrBw) ? await getTypedBoundWitness(archivist, hashOrBw, identity) : hashOrBw
21
+ const bw = isHash(hashOrBw) ? await getTypedBoundWitnessWithStorageMeta(archivist, hashOrBw, identity) : hashOrBw
22
22
  const payloads = (await archivist.get(bw?.payload_hashes as Hash[])).filter(exists)
23
23
  if (payloads.length !== bw.payload_hashes.length) {
24
24
  throw new Error(`missing payloads for ${bw._hash}`)
@@ -30,5 +30,6 @@ export const hydrateBoundWitness = (
30
30
  archivist: ReadArchivist,
31
31
  hashOrBw: Hash | WithStorageMeta<BoundWitness>,
32
32
  ): Promise<HydratedBoundWitness<BoundWitness>> => {
33
- return hydrateTypedBoundWitness<BoundWitness>(archivist, hashOrBw, isBoundWitnessWithStorageMeta)
33
+ const idFunction: IdentityFunction<WithStorageMeta<BoundWitness>> = x => isBoundWitness(x) && isStorageMeta(x)
34
+ return hydrateTypedBoundWitness<BoundWitness>(archivist, hashOrBw, idFunction)
34
35
  }