|
@@ -38,6 +38,9 @@ import {
|
|
getDynamicBag,
|
|
getDynamicBag,
|
|
getDistributionBucketFamilyWithMetadata,
|
|
getDistributionBucketFamilyWithMetadata,
|
|
getDistributionBucketOperatorWithMetadata,
|
|
getDistributionBucketOperatorWithMetadata,
|
|
|
|
+ distributionBucketId,
|
|
|
|
+ distributionOperatorId,
|
|
|
|
+ distributionBucketIdByFamilyAndIndex,
|
|
} from './utils'
|
|
} from './utils'
|
|
|
|
|
|
// STORAGE BUCKETS
|
|
// STORAGE BUCKETS
|
|
@@ -201,7 +204,7 @@ export async function storage_DynamicBagCreated({ event, store }: EventContext &
|
|
owner: getDynamicBagOwner(bagId),
|
|
owner: getDynamicBagOwner(bagId),
|
|
storageBuckets: Array.from(storageBucketIdsSet).map((id) => new StorageBucket({ id: id.toString() })),
|
|
storageBuckets: Array.from(storageBucketIdsSet).map((id) => new StorageBucket({ id: id.toString() })),
|
|
distributionBuckets: Array.from(distributionBucketIdsSet).map(
|
|
distributionBuckets: Array.from(distributionBucketIdsSet).map(
|
|
- (id) => new DistributionBucket({ id: id.toString() })
|
|
|
|
|
|
+ (id) => new DistributionBucket({ id: distributionBucketId(id) })
|
|
),
|
|
),
|
|
})
|
|
})
|
|
await store.save<StorageBag>(storageBag)
|
|
await store.save<StorageBag>(storageBag)
|
|
@@ -295,7 +298,8 @@ export async function storage_DistributionBucketCreated({ event, store }: EventC
|
|
|
|
|
|
const family = await getById(store, DistributionBucketFamily, familyId.toString())
|
|
const family = await getById(store, DistributionBucketFamily, familyId.toString())
|
|
const bucket = new DistributionBucket({
|
|
const bucket = new DistributionBucket({
|
|
- id: bucketId.toString(),
|
|
|
|
|
|
+ id: distributionBucketId(bucketId),
|
|
|
|
+ bucketIndex: bucketId.distribution_bucket_index.toNumber(),
|
|
acceptingNewBags: acceptingNewBags.valueOf(),
|
|
acceptingNewBags: acceptingNewBags.valueOf(),
|
|
distributing: true, // Runtime default
|
|
distributing: true, // Runtime default
|
|
family,
|
|
family,
|
|
@@ -308,28 +312,30 @@ export async function storage_DistributionBucketStatusUpdated({
|
|
event,
|
|
event,
|
|
store,
|
|
store,
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
- const [, bucketId, acceptingNewBags] = new Storage.DistributionBucketStatusUpdatedEvent(event).params
|
|
|
|
|
|
+ const [bucketId, acceptingNewBags] = new Storage.DistributionBucketStatusUpdatedEvent(event).params
|
|
|
|
|
|
- const bucket = await getById(store, DistributionBucket, bucketId.toString())
|
|
|
|
|
|
+ const bucket = await getById(store, DistributionBucket, distributionBucketId(bucketId))
|
|
bucket.acceptingNewBags = acceptingNewBags.valueOf()
|
|
bucket.acceptingNewBags = acceptingNewBags.valueOf()
|
|
|
|
|
|
await store.save<DistributionBucket>(bucket)
|
|
await store.save<DistributionBucket>(bucket)
|
|
}
|
|
}
|
|
|
|
|
|
export async function storage_DistributionBucketDeleted({ event, store }: EventContext & StoreContext): Promise<void> {
|
|
export async function storage_DistributionBucketDeleted({ event, store }: EventContext & StoreContext): Promise<void> {
|
|
- const [, bucketId] = new Storage.DistributionBucketDeletedEvent(event).params
|
|
|
|
|
|
+ const [bucketId] = new Storage.DistributionBucketDeletedEvent(event).params
|
|
// TODO: Cascade remove on db level (would require changes in Hydra / comitting autogenerated files)
|
|
// TODO: Cascade remove on db level (would require changes in Hydra / comitting autogenerated files)
|
|
const distributionBucket = await store.get(DistributionBucket, {
|
|
const distributionBucket = await store.get(DistributionBucket, {
|
|
- where: { id: bucketId.toString() },
|
|
|
|
|
|
+ where: { id: distributionBucketId(bucketId) },
|
|
relations: ['bags', 'bags.distributionBuckets'],
|
|
relations: ['bags', 'bags.distributionBuckets'],
|
|
})
|
|
})
|
|
if (!distributionBucket) {
|
|
if (!distributionBucket) {
|
|
- inconsistentState(`Distribution bucket by id ${bucketId.toString()} not found!`)
|
|
|
|
|
|
+ inconsistentState(`Distribution bucket by id ${distributionBucketId(bucketId)} not found!`)
|
|
}
|
|
}
|
|
// Remove relations
|
|
// Remove relations
|
|
await Promise.all(
|
|
await Promise.all(
|
|
(distributionBucket.bags || []).map((bag) => {
|
|
(distributionBucket.bags || []).map((bag) => {
|
|
- bag.distributionBuckets = (bag.distributionBuckets || []).filter((bucket) => bucket.id !== bucketId.toString())
|
|
|
|
|
|
+ bag.distributionBuckets = (bag.distributionBuckets || []).filter(
|
|
|
|
+ (bucket) => bucket.id !== distributionBucketId(bucketId)
|
|
|
|
+ )
|
|
return store.save<StorageBag>(bag)
|
|
return store.save<StorageBag>(bag)
|
|
})
|
|
})
|
|
)
|
|
)
|
|
@@ -340,11 +346,20 @@ export async function storage_DistributionBucketsUpdatedForBag({
|
|
event,
|
|
event,
|
|
store,
|
|
store,
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
- const [bagId, , addedBucketsSet, removedBucketsSet] = new Storage.DistributionBucketsUpdatedForBagEvent(event).params
|
|
|
|
|
|
+ const [
|
|
|
|
+ bagId,
|
|
|
|
+ familyId,
|
|
|
|
+ addedBucketsIndices,
|
|
|
|
+ removedBucketsIndices,
|
|
|
|
+ ] = new Storage.DistributionBucketsUpdatedForBagEvent(event).params
|
|
// Get or create bag
|
|
// Get or create bag
|
|
const storageBag = await getBag(store, bagId, ['distributionBuckets'])
|
|
const storageBag = await getBag(store, bagId, ['distributionBuckets'])
|
|
- const removedBucketsIds = Array.from(removedBucketsSet).map((id) => id.toString())
|
|
|
|
- const addedBucketsIds = Array.from(addedBucketsSet).map((id) => id.toString())
|
|
|
|
|
|
+ const removedBucketsIds = Array.from(removedBucketsIndices).map((bucketIndex) =>
|
|
|
|
+ distributionBucketIdByFamilyAndIndex(familyId, bucketIndex)
|
|
|
|
+ )
|
|
|
|
+ const addedBucketsIds = Array.from(addedBucketsIndices).map((bucketIndex) =>
|
|
|
|
+ distributionBucketIdByFamilyAndIndex(familyId, bucketIndex)
|
|
|
|
+ )
|
|
storageBag.distributionBuckets = (storageBag.distributionBuckets || [])
|
|
storageBag.distributionBuckets = (storageBag.distributionBuckets || [])
|
|
.filter((bucket) => !removedBucketsIds.includes(bucket.id))
|
|
.filter((bucket) => !removedBucketsIds.includes(bucket.id))
|
|
.concat(addedBucketsIds.map((id) => new DistributionBucket({ id })))
|
|
.concat(addedBucketsIds.map((id) => new DistributionBucket({ id })))
|
|
@@ -355,9 +370,9 @@ export async function storage_DistributionBucketModeUpdated({
|
|
event,
|
|
event,
|
|
store,
|
|
store,
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
- const [, bucketId, distributing] = new Storage.DistributionBucketModeUpdatedEvent(event).params
|
|
|
|
|
|
+ const [bucketId, distributing] = new Storage.DistributionBucketModeUpdatedEvent(event).params
|
|
|
|
|
|
- const bucket = await getById(store, DistributionBucket, bucketId.toString())
|
|
|
|
|
|
+ const bucket = await getById(store, DistributionBucket, distributionBucketId(bucketId))
|
|
bucket.distributing = distributing.valueOf()
|
|
bucket.distributing = distributing.valueOf()
|
|
|
|
|
|
await store.save<DistributionBucket>(bucket)
|
|
await store.save<DistributionBucket>(bucket)
|
|
@@ -367,11 +382,11 @@ export async function storage_DistributionBucketOperatorInvited({
|
|
event,
|
|
event,
|
|
store,
|
|
store,
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
- const [, bucketId, workerId] = new Storage.DistributionBucketOperatorInvitedEvent(event).params
|
|
|
|
|
|
+ const [bucketId, workerId] = new Storage.DistributionBucketOperatorInvitedEvent(event).params
|
|
|
|
|
|
- const bucket = await getById(store, DistributionBucket, bucketId.toString())
|
|
|
|
|
|
+ const bucket = await getById(store, DistributionBucket, distributionBucketId(bucketId))
|
|
const invitedOperator = new DistributionBucketOperator({
|
|
const invitedOperator = new DistributionBucketOperator({
|
|
- id: `${bucketId}-${workerId}`,
|
|
|
|
|
|
+ id: distributionOperatorId(bucketId, workerId),
|
|
distributionBucket: bucket,
|
|
distributionBucket: bucket,
|
|
status: DistributionBucketOperatorStatus.INVITED,
|
|
status: DistributionBucketOperatorStatus.INVITED,
|
|
workerId: workerId.toNumber(),
|
|
workerId: workerId.toNumber(),
|
|
@@ -384,9 +399,9 @@ export async function storage_DistributionBucketInvitationCancelled({
|
|
event,
|
|
event,
|
|
store,
|
|
store,
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
- const [, bucketId, workerId] = new Storage.DistributionBucketOperatorInvitedEvent(event).params
|
|
|
|
|
|
+ const [bucketId, workerId] = new Storage.DistributionBucketOperatorInvitedEvent(event).params
|
|
|
|
|
|
- const invitedOperator = await getById(store, DistributionBucketOperator, `${bucketId}-${workerId}`)
|
|
|
|
|
|
+ const invitedOperator = await getById(store, DistributionBucketOperator, distributionOperatorId(bucketId, workerId))
|
|
|
|
|
|
await store.remove<DistributionBucketOperator>(invitedOperator)
|
|
await store.remove<DistributionBucketOperator>(invitedOperator)
|
|
}
|
|
}
|
|
@@ -395,9 +410,9 @@ export async function storage_DistributionBucketInvitationAccepted({
|
|
event,
|
|
event,
|
|
store,
|
|
store,
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
- const [workerId, , bucketId] = new Storage.DistributionBucketInvitationAcceptedEvent(event).params
|
|
|
|
|
|
+ const [workerId, bucketId] = new Storage.DistributionBucketInvitationAcceptedEvent(event).params
|
|
|
|
|
|
- const invitedOperator = await getById(store, DistributionBucketOperator, `${bucketId}-${workerId}`)
|
|
|
|
|
|
+ const invitedOperator = await getById(store, DistributionBucketOperator, distributionOperatorId(bucketId, workerId))
|
|
invitedOperator.status = DistributionBucketOperatorStatus.ACTIVE
|
|
invitedOperator.status = DistributionBucketOperatorStatus.ACTIVE
|
|
|
|
|
|
await store.save<DistributionBucketOperator>(invitedOperator)
|
|
await store.save<DistributionBucketOperator>(invitedOperator)
|
|
@@ -407,9 +422,9 @@ export async function storage_DistributionBucketMetadataSet({
|
|
event,
|
|
event,
|
|
store,
|
|
store,
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
- const [workerId, , bucketId, metadataBytes] = new Storage.DistributionBucketMetadataSetEvent(event).params
|
|
|
|
|
|
+ const [workerId, bucketId, metadataBytes] = new Storage.DistributionBucketMetadataSetEvent(event).params
|
|
|
|
|
|
- const operator = await getDistributionBucketOperatorWithMetadata(store, `${bucketId}-${workerId}`)
|
|
|
|
|
|
+ const operator = await getDistributionBucketOperatorWithMetadata(store, distributionOperatorId(bucketId, workerId))
|
|
operator.metadata = await processDistributionOperatorMetadata(store, operator.metadata, metadataBytes)
|
|
operator.metadata = await processDistributionOperatorMetadata(store, operator.metadata, metadataBytes)
|
|
|
|
|
|
await store.save<DistributionBucketOperator>(operator)
|
|
await store.save<DistributionBucketOperator>(operator)
|
|
@@ -419,11 +434,11 @@ export async function storage_DistributionBucketOperatorRemoved({
|
|
event,
|
|
event,
|
|
store,
|
|
store,
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
}: EventContext & StoreContext): Promise<void> {
|
|
- const [, bucketId, workerId] = new Storage.DistributionBucketOperatorRemovedEvent(event).params
|
|
|
|
|
|
+ const [bucketId, workerId] = new Storage.DistributionBucketOperatorRemovedEvent(event).params
|
|
|
|
|
|
// TODO: Cascade remove on db level (would require changes in Hydra / comitting autogenerated files)
|
|
// TODO: Cascade remove on db level (would require changes in Hydra / comitting autogenerated files)
|
|
|
|
|
|
- const operator = await getDistributionBucketOperatorWithMetadata(store, `${bucketId}-${workerId}`)
|
|
|
|
|
|
+ const operator = await getDistributionBucketOperatorWithMetadata(store, distributionOperatorId(bucketId, workerId))
|
|
await store.remove<DistributionBucketOperator>(operator)
|
|
await store.remove<DistributionBucketOperator>(operator)
|
|
if (operator.metadata) {
|
|
if (operator.metadata) {
|
|
await store.remove<DistributionBucketOperatorMetadata>(operator.metadata)
|
|
await store.remove<DistributionBucketOperatorMetadata>(operator.metadata)
|