@xyo-network/archivist-model 3.8.5 → 3.9.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 +36 -11
- package/dist/neutral/index.mjs +37 -0
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +10 -7
- package/src/Params.ts +14 -3
- package/src/PayloadArchivist.ts +16 -2
- package/src/index.ts +1 -0
- package/src/lib/HydratedBoundWitness.ts +4 -0
- package/src/lib/IdentityFunction.ts +1 -0
- package/src/lib/getBoundWitness.ts +24 -0
- package/src/lib/hydrateBoundWitness.ts +28 -0
- package/src/lib/index.ts +4 -0
package/dist/neutral/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import * as _xyo_network_account_model from '@xyo-network/account-model';
|
|
|
12
12
|
import { AccountInstance } from '@xyo-network/account-model';
|
|
13
13
|
import * as _xylabs_logger from '@xylabs/logger';
|
|
14
14
|
import { ObjectTypeShape } from '@xylabs/typeof';
|
|
15
|
+
import { BoundWitness } from '@xyo-network/boundwitness-model';
|
|
15
16
|
|
|
16
17
|
interface NextOptions<TId = Hex> {
|
|
17
18
|
cursor?: TId;
|
|
@@ -64,10 +65,14 @@ interface AllArchivist<TReadResponse extends Payload = Payload> extends AllArchi
|
|
|
64
65
|
}
|
|
65
66
|
interface ReadArchivist<TReadResponse extends Payload = Payload, TId = Hash> extends ReadArchivistFunctions<WithStorageMeta<TReadResponse>, TId> {
|
|
66
67
|
}
|
|
67
|
-
interface WriteArchivist<TReadResponse extends Payload = Payload, TWriteResponse = TReadResponse, TWrite = TReadResponse, TId = Hash> extends WriteArchivistFunctions<WithStorageMeta<TReadResponse>, TWriteResponse, TWrite, TId> {
|
|
68
|
+
interface WriteArchivist<TReadResponse extends Payload = Payload, TWriteResponse extends Payload = TReadResponse, TWrite extends Payload = TReadResponse, TId = Hash> extends WriteArchivistFunctions<WithStorageMeta<TReadResponse>, TWriteResponse, TWrite, TId> {
|
|
69
|
+
}
|
|
70
|
+
interface ReadWriteArchivist<TReadResponse extends Payload = Payload, TWriteResponse extends Payload = TReadResponse, TWrite extends Payload = TReadResponse, TId = Hash> extends WriteArchivist<TReadResponse, TWriteResponse, TWrite, TId>, ReadArchivist<TReadResponse, TId> {
|
|
68
71
|
}
|
|
69
72
|
interface StashArchivist<TWriteResponse extends Payload = Payload> extends StashArchivistFunctions<WithStorageMeta<TWriteResponse>> {
|
|
70
73
|
}
|
|
74
|
+
interface FullArchivist<TReadResponse extends Payload = Payload, TWriteResponse extends Payload = TReadResponse, TWrite extends Payload = TReadResponse, TId = Hash> extends ReadWriteArchivist<TReadResponse, TWriteResponse, TWrite, TId>, StashArchivist<TWriteResponse> {
|
|
75
|
+
}
|
|
71
76
|
interface Archivist<TReadResponse extends Payload = Payload, TWriteResponse extends Payload = Payload, TWrite extends Payload = TReadResponse & Payload, TId = Hash> extends ReadArchivist<WithStorageMeta<TReadResponse>, TId>, AllArchivist<WithStorageMeta<TReadResponse>>, WriteArchivist<WithStorageMeta<TReadResponse>, WithStorageMeta<TWriteResponse>, TWrite, TId>, StashArchivistFunctions<TWriteResponse> {
|
|
72
77
|
}
|
|
73
78
|
|
|
@@ -105,7 +110,15 @@ type ArchivistConfig<TConfig extends Payload | EmptyObject | void = void, TSchem
|
|
|
105
110
|
interface ArchivistModuleInstance<TParams extends ModuleParams<AnyConfigSchema<ArchivistConfig>> = ModuleParams<AnyConfigSchema<ArchivistConfig>>, TEventData extends ArchivistModuleEventData = ArchivistModuleEventData> extends Module<TParams, TEventData> {
|
|
106
111
|
}
|
|
107
112
|
|
|
108
|
-
|
|
113
|
+
interface ArchivistParentInstances {
|
|
114
|
+
commit?: ArchivistInstance[];
|
|
115
|
+
read?: ArchivistInstance[];
|
|
116
|
+
write?: ArchivistInstance[];
|
|
117
|
+
}
|
|
118
|
+
interface ArchivistParamFields {
|
|
119
|
+
parents?: ArchivistParentInstances;
|
|
120
|
+
}
|
|
121
|
+
type ArchivistParams<TConfig extends AnyConfigSchema<ArchivistConfig> = AnyConfigSchema<ArchivistConfig>, TAdditionalParams extends EmptyObject = EmptyObject> = ModuleParams<TConfig, WithAdditional<ArchivistParamFields & TAdditionalParams>>;
|
|
109
122
|
|
|
110
123
|
interface ArchivistRawQueryFunctions {
|
|
111
124
|
allQuery(account?: AccountInstance): Promisable<ModuleQueryResult>;
|
|
@@ -187,7 +200,7 @@ declare const asAttachableArchivistInstance: {
|
|
|
187
200
|
}>;
|
|
188
201
|
ephemeralQueryAccountEnabled?: boolean;
|
|
189
202
|
moduleIdentifierTransformers?: _xyo_network_module_model.ModuleIdentifierTransformer[];
|
|
190
|
-
}, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
203
|
+
} & ArchivistParamFields & object, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
191
204
|
schema: _xyo_network_payload_model.Schema;
|
|
192
205
|
}>>>(value: _xylabs_promise.AnyNonPromise, config?: _xylabs_object.TypeCheckConfig): TType | undefined;
|
|
193
206
|
<TType extends AttachableArchivistInstance<_xylabs_object.BaseParamsFields & {
|
|
@@ -250,7 +263,7 @@ declare const asAttachableArchivistInstance: {
|
|
|
250
263
|
}>;
|
|
251
264
|
ephemeralQueryAccountEnabled?: boolean;
|
|
252
265
|
moduleIdentifierTransformers?: _xyo_network_module_model.ModuleIdentifierTransformer[];
|
|
253
|
-
}, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
266
|
+
} & ArchivistParamFields & object, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
254
267
|
schema: _xyo_network_payload_model.Schema;
|
|
255
268
|
}>>>(value: _xylabs_promise.AnyNonPromise, assert: _xylabs_object.StringOrAlertFunction<AttachableArchivistInstance<_xylabs_object.BaseParamsFields & {
|
|
256
269
|
account?: _xyo_network_account_model.AccountInstance | "random";
|
|
@@ -312,7 +325,7 @@ declare const asAttachableArchivistInstance: {
|
|
|
312
325
|
}>;
|
|
313
326
|
ephemeralQueryAccountEnabled?: boolean;
|
|
314
327
|
moduleIdentifierTransformers?: _xyo_network_module_model.ModuleIdentifierTransformer[];
|
|
315
|
-
}, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
328
|
+
} & ArchivistParamFields & object, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
316
329
|
schema: _xyo_network_payload_model.Schema;
|
|
317
330
|
}>>>, config?: _xylabs_object.TypeCheckConfig): TType;
|
|
318
331
|
};
|
|
@@ -324,6 +337,18 @@ interface ArchivistLabels extends Labels {
|
|
|
324
337
|
'network.xyo.archivist.persistence.scope': 'memory' | 'thread' | 'process' | 'device' | 'network';
|
|
325
338
|
}
|
|
326
339
|
|
|
340
|
+
type IdentityFunction<T> = (value: unknown) => value is T;
|
|
341
|
+
|
|
342
|
+
declare const tryGetTypedBoundWitness: <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash, identity: IdentityFunction<WithStorageMeta<T>>) => Promise<WithStorageMeta<T> | undefined>;
|
|
343
|
+
declare const getTypedBoundWitness: <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash, identity: IdentityFunction<WithStorageMeta<T>>) => Promise<WithStorageMeta<T>>;
|
|
344
|
+
declare const getBoundWitness: (archivist: ReadArchivist, hash: Hash) => Promise<WithStorageMeta<BoundWitness>>;
|
|
345
|
+
|
|
346
|
+
type HydratedBoundWitness<T extends BoundWitness = BoundWitness, P extends Payload = Payload> = [WithStorageMeta<T>, WithStorageMeta<P>[]];
|
|
347
|
+
|
|
348
|
+
declare const tryHydrateTypedBoundWitness: <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>, identity: IdentityFunction<WithStorageMeta<T>>) => Promise<HydratedBoundWitness<T> | undefined>;
|
|
349
|
+
declare const hydrateTypedBoundWitness: <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>, identity: IdentityFunction<WithStorageMeta<T>>) => Promise<HydratedBoundWitness<T>>;
|
|
350
|
+
declare const hydrateBoundWitness: (archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<BoundWitness>) => Promise<HydratedBoundWitness<BoundWitness>>;
|
|
351
|
+
|
|
327
352
|
declare const ArchivistAllQuerySchema: "network.xyo.query.archivist.all";
|
|
328
353
|
type ArchivistAllQuerySchema = typeof ArchivistAllQuerySchema;
|
|
329
354
|
type ArchivistAllQuery = Query<{
|
|
@@ -429,7 +454,7 @@ declare const isArchivistInstance: _xylabs_object.TypeCheck<ArchivistInstance<_x
|
|
|
429
454
|
}>;
|
|
430
455
|
ephemeralQueryAccountEnabled?: boolean;
|
|
431
456
|
moduleIdentifierTransformers?: _xyo_network_module_model.ModuleIdentifierTransformer[];
|
|
432
|
-
}, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
457
|
+
} & ArchivistParamFields & object, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
433
458
|
schema: _xyo_network_payload_model.Schema;
|
|
434
459
|
}>>>;
|
|
435
460
|
declare const isArchivistModule: _xyo_network_module_model.ModuleTypeCheck<ArchivistModuleInstance<_xylabs_object.BaseParamsFields & {
|
|
@@ -738,7 +763,7 @@ declare const asArchivistInstance: {
|
|
|
738
763
|
}>;
|
|
739
764
|
ephemeralQueryAccountEnabled?: boolean;
|
|
740
765
|
moduleIdentifierTransformers?: _xyo_network_module_model.ModuleIdentifierTransformer[];
|
|
741
|
-
}, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
766
|
+
} & ArchivistParamFields & object, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
742
767
|
schema: _xyo_network_payload_model.Schema;
|
|
743
768
|
}>>>(value: _xylabs_promise.AnyNonPromise, config?: _xylabs_object.TypeCheckConfig): TType | undefined;
|
|
744
769
|
<TType extends ArchivistInstance<_xylabs_object.BaseParamsFields & {
|
|
@@ -801,7 +826,7 @@ declare const asArchivistInstance: {
|
|
|
801
826
|
}>;
|
|
802
827
|
ephemeralQueryAccountEnabled?: boolean;
|
|
803
828
|
moduleIdentifierTransformers?: _xyo_network_module_model.ModuleIdentifierTransformer[];
|
|
804
|
-
}, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
829
|
+
} & ArchivistParamFields & object, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
805
830
|
schema: _xyo_network_payload_model.Schema;
|
|
806
831
|
}>>>(value: _xylabs_promise.AnyNonPromise, assert: _xylabs_object.StringOrAlertFunction<ArchivistInstance<_xylabs_object.BaseParamsFields & {
|
|
807
832
|
account?: _xyo_network_account_model.AccountInstance | "random";
|
|
@@ -863,7 +888,7 @@ declare const asArchivistInstance: {
|
|
|
863
888
|
}>;
|
|
864
889
|
ephemeralQueryAccountEnabled?: boolean;
|
|
865
890
|
moduleIdentifierTransformers?: _xyo_network_module_model.ModuleIdentifierTransformer[];
|
|
866
|
-
}, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
891
|
+
} & ArchivistParamFields & object, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
867
892
|
schema: _xyo_network_payload_model.Schema;
|
|
868
893
|
}>>>, config?: _xylabs_object.TypeCheckConfig): TType;
|
|
869
894
|
};
|
|
@@ -988,8 +1013,8 @@ declare const withArchivistInstance: <R>(mod: any, closure: (mod: ArchivistInsta
|
|
|
988
1013
|
}>;
|
|
989
1014
|
ephemeralQueryAccountEnabled?: boolean;
|
|
990
1015
|
moduleIdentifierTransformers?: _xyo_network_module_model.ModuleIdentifierTransformer[];
|
|
991
|
-
}, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
1016
|
+
} & ArchivistParamFields & object, ArchivistModuleEventData, _xylabs_object.DeepRestrictToStringKeys<{
|
|
992
1017
|
schema: _xyo_network_payload_model.Schema;
|
|
993
1018
|
}>>) => R) => R | undefined;
|
|
994
1019
|
|
|
995
|
-
export { type AllArchivist, type AllArchivistFunctions, type Archivist, type ArchivistAllQuery, ArchivistAllQuerySchema, type ArchivistClearQuery, ArchivistClearQuerySchema, type ArchivistCommitQuery, ArchivistCommitQuerySchema, type ArchivistConfig, ArchivistConfigSchema, type ArchivistDeleteQuery, ArchivistDeleteQuerySchema, type ArchivistGetQuery, ArchivistGetQuerySchema, type ArchivistInsertQuery, ArchivistInsertQuerySchema, type ArchivistInstance, type ArchivistLabels, type ArchivistModuleEventData, type ArchivistModuleInstance, type ArchivistModuleQueries, type ArchivistNextOptions, type ArchivistNextQuery, ArchivistNextQuerySchema, type ArchivistParams, type ArchivistParents, type ArchivistQueries, type ArchivistRawQueryFunctions, type ArchivistStorage, type AttachableArchivistInstance, type AttachableArchivistInstanceTypeCheck, type IndexDescription, type IndexDirection, IndexSeparator, IsAttachableArchivistInstanceFactory, type NextOptions, type ReadArchivist, type ReadArchivistFunctions, type StashArchivist, type StashArchivistFunctions, type WriteArchivist, type WriteArchivistFunctions, asArchivistInstance, asArchivistModule, asAttachableArchivistInstance, buildStandardIndexName, isArchivistInstance, isArchivistModule, isAttachableArchivistInstance, requiredAttachableArchivistInstanceFunctions, withArchivistInstance, withArchivistModule };
|
|
1020
|
+
export { type AllArchivist, type AllArchivistFunctions, type Archivist, type ArchivistAllQuery, ArchivistAllQuerySchema, type ArchivistClearQuery, ArchivistClearQuerySchema, type ArchivistCommitQuery, ArchivistCommitQuerySchema, type ArchivistConfig, ArchivistConfigSchema, type ArchivistDeleteQuery, ArchivistDeleteQuerySchema, type ArchivistGetQuery, ArchivistGetQuerySchema, type ArchivistInsertQuery, ArchivistInsertQuerySchema, type ArchivistInstance, type ArchivistLabels, type ArchivistModuleEventData, type ArchivistModuleInstance, type ArchivistModuleQueries, type ArchivistNextOptions, type ArchivistNextQuery, ArchivistNextQuerySchema, type ArchivistParamFields, type ArchivistParams, type ArchivistParentInstances, type ArchivistParents, type ArchivistQueries, type ArchivistRawQueryFunctions, type ArchivistStorage, type AttachableArchivistInstance, type AttachableArchivistInstanceTypeCheck, type FullArchivist, type HydratedBoundWitness, type IdentityFunction, type IndexDescription, type IndexDirection, IndexSeparator, IsAttachableArchivistInstanceFactory, type NextOptions, type ReadArchivist, type ReadArchivistFunctions, type ReadWriteArchivist, type StashArchivist, type StashArchivistFunctions, type WriteArchivist, type WriteArchivistFunctions, asArchivistInstance, asArchivistModule, asAttachableArchivistInstance, buildStandardIndexName, getBoundWitness, getTypedBoundWitness, hydrateBoundWitness, hydrateTypedBoundWitness, isArchivistInstance, isArchivistModule, isAttachableArchivistInstance, requiredAttachableArchivistInstanceFunctions, tryGetTypedBoundWitness, tryHydrateTypedBoundWitness, withArchivistInstance, withArchivistModule };
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -70,6 +70,37 @@ var buildStandardIndexName = (index) => {
|
|
|
70
70
|
const indexKeys = Object.keys(key);
|
|
71
71
|
return `${prefix}_${indexKeys.join(IndexSeparator)}`;
|
|
72
72
|
};
|
|
73
|
+
|
|
74
|
+
// src/lib/getBoundWitness.ts
|
|
75
|
+
import { assertEx } from "@xylabs/assert";
|
|
76
|
+
import { isBoundWitnessWithStorageMeta } from "@xyo-network/boundwitness-model";
|
|
77
|
+
var tryGetTypedBoundWitness = async (archivist, hash, identity) => {
|
|
78
|
+
const payload = (await archivist.get([hash])).at(0);
|
|
79
|
+
return identity(payload) ? payload : void 0;
|
|
80
|
+
};
|
|
81
|
+
var getTypedBoundWitness = async (archivist, hash, identity) => {
|
|
82
|
+
const payload = assertEx((await archivist.get([hash])).at(0), () => `failed to locate bound witness: ${hash}`);
|
|
83
|
+
return assertEx(identity(payload) ? payload : void 0, () => `located payload failed identity check: ${hash}`);
|
|
84
|
+
};
|
|
85
|
+
var getBoundWitness = (archivist, hash) => {
|
|
86
|
+
return getTypedBoundWitness(archivist, hash, isBoundWitnessWithStorageMeta);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/lib/hydrateBoundWitness.ts
|
|
90
|
+
import { exists } from "@xylabs/exists";
|
|
91
|
+
import { isHash } from "@xylabs/hex";
|
|
92
|
+
import { isBoundWitnessWithStorageMeta as isBoundWitnessWithStorageMeta2 } from "@xyo-network/boundwitness-model";
|
|
93
|
+
var tryHydrateTypedBoundWitness = async (archivist, hashOrBw, identity) => {
|
|
94
|
+
const bw = isHash(hashOrBw) ? await tryGetTypedBoundWitness(archivist, hashOrBw, identity) : hashOrBw;
|
|
95
|
+
return bw ? [bw, (await archivist.get(bw?.payload_hashes)).filter(exists)] : void 0;
|
|
96
|
+
};
|
|
97
|
+
var hydrateTypedBoundWitness = async (archivist, hashOrBw, identity) => {
|
|
98
|
+
const bw = isHash(hashOrBw) ? await getTypedBoundWitness(archivist, hashOrBw, identity) : hashOrBw;
|
|
99
|
+
return [bw, (await archivist.get(bw?.payload_hashes)).filter(exists)];
|
|
100
|
+
};
|
|
101
|
+
var hydrateBoundWitness = (archivist, hashOrBw) => {
|
|
102
|
+
return hydrateTypedBoundWitness(archivist, hashOrBw, isBoundWitnessWithStorageMeta2);
|
|
103
|
+
};
|
|
73
104
|
export {
|
|
74
105
|
ArchivistAllQuerySchema,
|
|
75
106
|
ArchivistClearQuerySchema,
|
|
@@ -85,10 +116,16 @@ export {
|
|
|
85
116
|
asArchivistModule,
|
|
86
117
|
asAttachableArchivistInstance,
|
|
87
118
|
buildStandardIndexName,
|
|
119
|
+
getBoundWitness,
|
|
120
|
+
getTypedBoundWitness,
|
|
121
|
+
hydrateBoundWitness,
|
|
122
|
+
hydrateTypedBoundWitness,
|
|
88
123
|
isArchivistInstance,
|
|
89
124
|
isArchivistModule,
|
|
90
125
|
isAttachableArchivistInstance,
|
|
91
126
|
requiredAttachableArchivistInstanceFunctions,
|
|
127
|
+
tryGetTypedBoundWitness,
|
|
128
|
+
tryHydrateTypedBoundWitness,
|
|
92
129
|
withArchivistInstance,
|
|
93
130
|
withArchivistModule
|
|
94
131
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../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/attachable/AttachableInstance.ts","../../src/Config.ts","../../src/IndexDescription.ts"],"sourcesContent":["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 { 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 = new IsInstanceFactory<ArchivistInstance>().create({ get: 'function' }, [isModuleInstance])\nexport const isArchivistModule = 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 { 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 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 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"],"mappings":";AAAA,SAAS,mBAAAA,wBAAuB;;;ACChC,SAAS,uBAAuB;AAEhC,SAAS,kCAAkC;;;ACH3C,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EAAmB;AAAA,EAAiB;AAAA,EAAkB;AAAA,OACjD;;;ACDA,IAAM,0BAA0B;;;ACAhC,IAAM,4BAA4B;;;ACAlC,IAAM,6BAA6B;;;ACCnC,IAAM,6BAA6B;;;ACAnC,IAAM,0BAA0B;;;ACDhC,IAAM,6BAA6B;;;ACEnC,IAAM,2BAA2B;;;APKjC,IAAM,sBAAsB,IAAI,kBAAqC,EAAE,OAAO,EAAE,KAAK,WAAW,GAAG,CAAC,gBAAgB,CAAC;AACrH,IAAM,oBAAoB,IAAI,gBAAyC,EAAE,OAAO,CAAC,uBAAuB,CAAC;AAEzG,IAAM,oBAAoB,gBAAgB,OAAO,iBAAiB;AAClE,IAAM,sBAAsB,gBAAgB,OAAO,mBAAmB;AACtE,IAAM,sBAAsB,YAAY,OAAO,iBAAiB;AAChE,IAAM,wBAAwB,YAAY,OAAO,mBAAmB;;;ADPpE,IAAM,+CAAgE,CAAC;AAG9E,IAAM,UAAU,IAAI,gBAA6C;AAE1D,IAAM,gCAAwE,QAAQ,OAAO,8CAA8C;AAAA,EAChJ;AAAA,EACA;AACF,CAAC;;;ADZM,IAAM,gCAAgCC,iBAAgB,OAAO,6BAA6B;;;AUHjG,SAAS,mBAAAC,wBAAuB;AAmBzB,IAAM,uCAAN,cAAwHA,iBAAmB;AAAC;;;ACH5I,IAAM,wBAAwB;;;ACU9B,IAAM,iBAAiB;AAQvB,IAAM,yBAAyB,CAAC,UAA4B;AACjE,QAAM,EAAE,KAAK,OAAO,IAAI;AACxB,QAAM,SAAS,SAAS,OAAO;AAC/B,QAAM,YAAY,OAAO,KAAK,GAAG;AACjC,SAAO,GAAG,MAAM,IAAI,UAAU,KAAK,cAAc,CAAC;AACpD;","names":["AsObjectFactory","AsObjectFactory","IsObjectFactory"]}
|
|
1
|
+
{"version":3,"sources":["../../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/attachable/AttachableInstance.ts","../../src/Config.ts","../../src/IndexDescription.ts","../../src/lib/getBoundWitness.ts","../../src/lib/hydrateBoundWitness.ts"],"sourcesContent":["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 { 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 = new IsInstanceFactory<ArchivistInstance>().create({ get: 'function' }, [isModuleInstance])\nexport const isArchivistModule = 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 { 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 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 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 { 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 type { IdentityFunction } from './IdentityFunction.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, isHash } from '@xylabs/hex'\nimport { type BoundWitness, 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'\nimport type { IdentityFunction } from './IdentityFunction.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)).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 return [bw, (await archivist.get(bw?.payload_hashes)).filter(exists)]\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":";AAAA,SAAS,mBAAAA,wBAAuB;;;ACChC,SAAS,uBAAuB;AAEhC,SAAS,kCAAkC;;;ACH3C,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EAAmB;AAAA,EAAiB;AAAA,EAAkB;AAAA,OACjD;;;ACDA,IAAM,0BAA0B;;;ACAhC,IAAM,4BAA4B;;;ACAlC,IAAM,6BAA6B;;;ACCnC,IAAM,6BAA6B;;;ACAnC,IAAM,0BAA0B;;;ACDhC,IAAM,6BAA6B;;;ACEnC,IAAM,2BAA2B;;;APKjC,IAAM,sBAAsB,IAAI,kBAAqC,EAAE,OAAO,EAAE,KAAK,WAAW,GAAG,CAAC,gBAAgB,CAAC;AACrH,IAAM,oBAAoB,IAAI,gBAAyC,EAAE,OAAO,CAAC,uBAAuB,CAAC;AAEzG,IAAM,oBAAoB,gBAAgB,OAAO,iBAAiB;AAClE,IAAM,sBAAsB,gBAAgB,OAAO,mBAAmB;AACtE,IAAM,sBAAsB,YAAY,OAAO,iBAAiB;AAChE,IAAM,wBAAwB,YAAY,OAAO,mBAAmB;;;ADPpE,IAAM,+CAAgE,CAAC;AAG9E,IAAM,UAAU,IAAI,gBAA6C;AAE1D,IAAM,gCAAwE,QAAQ,OAAO,8CAA8C;AAAA,EAChJ;AAAA,EACA;AACF,CAAC;;;ADZM,IAAM,gCAAgCC,iBAAgB,OAAO,6BAA6B;;;AUHjG,SAAS,mBAAAC,wBAAuB;AAmBzB,IAAM,uCAAN,cAAwHA,iBAAmB;AAAC;;;ACH5I,IAAM,wBAAwB;;;ACU9B,IAAM,iBAAiB;AAQvB,IAAM,yBAAyB,CAAC,UAA4B;AACjE,QAAM,EAAE,KAAK,OAAO,IAAI;AACxB,QAAM,SAAS,SAAS,OAAO;AAC/B,QAAM,YAAY,OAAO,KAAK,GAAG;AACjC,SAAO,GAAG,MAAM,IAAI,UAAU,KAAK,cAAc,CAAC;AACpD;;;ACxCA,SAAS,gBAAgB;AAGzB,SAAS,qCAAqC;AAMvC,IAAM,0BAA0B,OAA+B,WAA0B,MAC9F,aAA4F;AAC5F,QAAM,WAAW,MAAM,UAAU,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;AAClD,SAAO,SAAS,OAAO,IAAI,UAAU;AACvC;AAEO,IAAM,uBAAuB,OAA+B,WAA0B,MAC3F,aAAgF;AAChF,QAAM,UAAU,UAAU,MAAM,UAAU,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,MAAM,mCAAmC,IAAI,EAAE;AAC7G,SAAO,SAAS,SAAS,OAAO,IAAI,UAAU,QAAW,MAAM,0CAA0C,IAAI,EAAE;AACjH;AAEO,IAAM,kBAAkB,CAAC,WAA0B,SAAuD;AAC/G,SAAO,qBAAmC,WAAW,MAAM,6BAA6B;AAC1F;;;ACvBA,SAAS,cAAc;AACvB,SAAoB,cAAc;AAClC,SAA4B,iCAAAC,sCAAqC;AAQ1D,IAAM,8BAA8B,OAA+B,WAA0B,UAClG,aAAiG;AACjG,QAAM,KAAK,OAAO,QAAQ,IAAI,MAAM,wBAAwB,WAAW,UAAU,QAAQ,IAAI;AAC7F,SAAO,KAAK,CAAC,KAAK,MAAM,UAAU,IAAI,IAAI,cAAc,GAAG,OAAO,MAAM,CAAC,IAAI;AAC/E;AAEO,IAAM,2BAA2B,OAA+B,WAA0B,UAC/F,aAAqF;AACrF,QAAM,KAAK,OAAO,QAAQ,IAAI,MAAM,qBAAqB,WAAW,UAAU,QAAQ,IAAI;AAC1F,SAAO,CAAC,KAAK,MAAM,UAAU,IAAI,IAAI,cAAc,GAAG,OAAO,MAAM,CAAC;AACtE;AAEO,IAAM,sBAAsB,CACjC,WACA,aACgD;AAChD,SAAO,yBAAuC,WAAW,UAAUC,8BAA6B;AAClG;","names":["AsObjectFactory","AsObjectFactory","IsObjectFactory","isBoundWitnessWithStorageMeta","isBoundWitnessWithStorageMeta"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/archivist-model",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.1",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -29,18 +29,21 @@
|
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@xylabs/assert": "^4.5.1",
|
|
33
|
+
"@xylabs/exists": "^4.5.1",
|
|
32
34
|
"@xylabs/hex": "^4.5.1",
|
|
33
35
|
"@xylabs/object": "^4.5.1",
|
|
34
36
|
"@xylabs/promise": "^4.5.1",
|
|
35
37
|
"@xylabs/typeof": "^4.5.1",
|
|
36
|
-
"@xyo-network/account-model": "^3.
|
|
37
|
-
"@xyo-network/
|
|
38
|
-
"@xyo-network/module-
|
|
39
|
-
"@xyo-network/
|
|
38
|
+
"@xyo-network/account-model": "^3.9.1",
|
|
39
|
+
"@xyo-network/boundwitness-model": "^3.9.1",
|
|
40
|
+
"@xyo-network/module-events": "^3.9.1",
|
|
41
|
+
"@xyo-network/module-model": "^3.9.1",
|
|
42
|
+
"@xyo-network/payload-model": "^3.9.1"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
|
42
|
-
"@xylabs/ts-scripts-yarn3": "^5.0.
|
|
43
|
-
"@xylabs/tsconfig": "^5.0.
|
|
45
|
+
"@xylabs/ts-scripts-yarn3": "^5.0.24",
|
|
46
|
+
"@xylabs/tsconfig": "^5.0.24",
|
|
44
47
|
"typescript": "^5.7.3"
|
|
45
48
|
},
|
|
46
49
|
"publishConfig": {
|
package/src/Params.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import type { EmptyObject } from '@xylabs/object'
|
|
1
|
+
import type { EmptyObject, WithAdditional } from '@xylabs/object'
|
|
2
2
|
import type { AnyConfigSchema, ModuleParams } from '@xyo-network/module-model'
|
|
3
3
|
|
|
4
4
|
import type { ArchivistConfig } from './Config.ts'
|
|
5
|
+
import type { ArchivistInstance } from './Instance.ts'
|
|
6
|
+
|
|
7
|
+
export interface ArchivistParentInstances {
|
|
8
|
+
commit?: ArchivistInstance[]
|
|
9
|
+
read?: ArchivistInstance[]
|
|
10
|
+
write?: ArchivistInstance[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ArchivistParamFields {
|
|
14
|
+
parents?: ArchivistParentInstances
|
|
15
|
+
}
|
|
5
16
|
|
|
6
17
|
export type ArchivistParams<
|
|
7
18
|
TConfig extends AnyConfigSchema<ArchivistConfig> = AnyConfigSchema<ArchivistConfig>,
|
|
8
|
-
TAdditionalParams extends EmptyObject
|
|
9
|
-
> = ModuleParams<TConfig, TAdditionalParams
|
|
19
|
+
TAdditionalParams extends EmptyObject = EmptyObject,
|
|
20
|
+
> = ModuleParams<TConfig, WithAdditional<ArchivistParamFields & TAdditionalParams>>
|
package/src/PayloadArchivist.ts
CHANGED
|
@@ -16,15 +16,29 @@ export interface ReadArchivist<
|
|
|
16
16
|
|
|
17
17
|
export interface WriteArchivist<
|
|
18
18
|
TReadResponse extends Payload = Payload,
|
|
19
|
-
TWriteResponse = TReadResponse,
|
|
20
|
-
TWrite = TReadResponse,
|
|
19
|
+
TWriteResponse extends Payload = TReadResponse,
|
|
20
|
+
TWrite extends Payload = TReadResponse,
|
|
21
21
|
TId = Hash,
|
|
22
22
|
> extends WriteArchivistFunctions<WithStorageMeta<TReadResponse>, TWriteResponse, TWrite, TId> {}
|
|
23
23
|
|
|
24
|
+
export interface ReadWriteArchivist<
|
|
25
|
+
TReadResponse extends Payload = Payload,
|
|
26
|
+
TWriteResponse extends Payload = TReadResponse,
|
|
27
|
+
TWrite extends Payload = TReadResponse,
|
|
28
|
+
TId = Hash,
|
|
29
|
+
> extends WriteArchivist<TReadResponse, TWriteResponse, TWrite, TId>, ReadArchivist<TReadResponse, TId> {}
|
|
30
|
+
|
|
24
31
|
export interface StashArchivist<
|
|
25
32
|
TWriteResponse extends Payload = Payload,
|
|
26
33
|
> extends StashArchivistFunctions<WithStorageMeta<TWriteResponse>> {}
|
|
27
34
|
|
|
35
|
+
export interface FullArchivist<
|
|
36
|
+
TReadResponse extends Payload = Payload,
|
|
37
|
+
TWriteResponse extends Payload = TReadResponse,
|
|
38
|
+
TWrite extends Payload = TReadResponse,
|
|
39
|
+
TId = Hash,
|
|
40
|
+
> extends ReadWriteArchivist<TReadResponse, TWriteResponse, TWrite, TId>, StashArchivist<TWriteResponse> {}
|
|
41
|
+
|
|
28
42
|
export interface Archivist<
|
|
29
43
|
TReadResponse extends Payload = Payload,
|
|
30
44
|
TWriteResponse extends Payload = Payload,
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './EventData.ts'
|
|
|
5
5
|
export * from './IndexDescription.ts'
|
|
6
6
|
export * from './Instance.ts'
|
|
7
7
|
export * from './Labels.ts'
|
|
8
|
+
export * from './lib/index.ts'
|
|
8
9
|
export * from './ModuleInstance.ts'
|
|
9
10
|
export * from './NextOptions.ts'
|
|
10
11
|
export * from './Params.ts'
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
2
|
+
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
3
|
+
|
|
4
|
+
export type HydratedBoundWitness<T extends BoundWitness = BoundWitness, P extends Payload = Payload> = [WithStorageMeta<T>, WithStorageMeta<P>[]]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type IdentityFunction<T> = (value: unknown) => value is T
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { Hash } from '@xylabs/hex'
|
|
3
|
+
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
4
|
+
import { isBoundWitnessWithStorageMeta } from '@xyo-network/boundwitness-model'
|
|
5
|
+
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
6
|
+
|
|
7
|
+
import type { ReadArchivist } from '../PayloadArchivist.ts'
|
|
8
|
+
import type { IdentityFunction } from './IdentityFunction.ts'
|
|
9
|
+
|
|
10
|
+
export const tryGetTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash,
|
|
11
|
+
identity: IdentityFunction<WithStorageMeta<T>>): Promise<WithStorageMeta<T> | undefined> => {
|
|
12
|
+
const payload = (await archivist.get([hash])).at(0)
|
|
13
|
+
return identity(payload) ? payload : undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const getTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hash: Hash,
|
|
17
|
+
identity: IdentityFunction<WithStorageMeta<T>>): Promise<WithStorageMeta<T>> => {
|
|
18
|
+
const payload = assertEx((await archivist.get([hash])).at(0), () => `failed to locate bound witness: ${hash}`)
|
|
19
|
+
return assertEx(identity(payload) ? payload : undefined, () => `located payload failed identity check: ${hash}`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const getBoundWitness = (archivist: ReadArchivist, hash: Hash): Promise<WithStorageMeta<BoundWitness>> => {
|
|
23
|
+
return getTypedBoundWitness<BoundWitness>(archivist, hash, isBoundWitnessWithStorageMeta)
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { exists } from '@xylabs/exists'
|
|
2
|
+
import { type Hash, isHash } from '@xylabs/hex'
|
|
3
|
+
import { type BoundWitness, isBoundWitnessWithStorageMeta } from '@xyo-network/boundwitness-model'
|
|
4
|
+
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
5
|
+
|
|
6
|
+
import type { ReadArchivist } from '../PayloadArchivist.ts'
|
|
7
|
+
import { getTypedBoundWitness, tryGetTypedBoundWitness } from './getBoundWitness.ts'
|
|
8
|
+
import type { HydratedBoundWitness } from './HydratedBoundWitness.ts'
|
|
9
|
+
import type { IdentityFunction } from './IdentityFunction.ts'
|
|
10
|
+
|
|
11
|
+
export const tryHydrateTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>,
|
|
12
|
+
identity: IdentityFunction<WithStorageMeta<T>>): Promise<HydratedBoundWitness<T> | undefined> => {
|
|
13
|
+
const bw = isHash(hashOrBw) ? await tryGetTypedBoundWitness(archivist, hashOrBw, identity) : hashOrBw
|
|
14
|
+
return bw ? [bw, (await archivist.get(bw?.payload_hashes)).filter(exists)] : undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const hydrateTypedBoundWitness = async <T extends BoundWitness>(archivist: ReadArchivist, hashOrBw: Hash | WithStorageMeta<T>,
|
|
18
|
+
identity: IdentityFunction<WithStorageMeta<T>>): Promise<HydratedBoundWitness<T>> => {
|
|
19
|
+
const bw = isHash(hashOrBw) ? await getTypedBoundWitness(archivist, hashOrBw, identity) : hashOrBw
|
|
20
|
+
return [bw, (await archivist.get(bw?.payload_hashes)).filter(exists)]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const hydrateBoundWitness = (
|
|
24
|
+
archivist: ReadArchivist,
|
|
25
|
+
hashOrBw: Hash | WithStorageMeta<BoundWitness>,
|
|
26
|
+
): Promise<HydratedBoundWitness<BoundWitness>> => {
|
|
27
|
+
return hydrateTypedBoundWitness<BoundWitness>(archivist, hashOrBw, isBoundWitnessWithStorageMeta)
|
|
28
|
+
}
|
package/src/lib/index.ts
ADDED