refactor: remove Uuid and RoleName from @standardnotes/common in favour of @standardnotes/domain-core value objects (#2167)

This commit is contained in:
Karol Sójko
2023-01-19 16:17:59 +01:00
committed by GitHub
parent 2d63b7431a
commit 856a7e3500
108 changed files with 319 additions and 374 deletions

View File

@@ -1,11 +1,11 @@
import { extendArray, isObject, isString, UuidMap } from '@standardnotes/utils'
import { ContentType, Uuid } from '@standardnotes/common'
import { ContentType } from '@standardnotes/common'
import { remove } from 'lodash'
import { ItemContent } from '../../Abstract/Content/ItemContent'
import { ContentReference } from '../../Abstract/Item'
export interface CollectionElement {
uuid: Uuid
uuid: string
content_type: ContentType
dirty?: boolean
deleted?: boolean
@@ -32,17 +32,17 @@ export abstract class Collection<
Encrypted extends EncryptedCollectionElement,
Deleted extends DeletedCollectionElement,
> {
readonly map: Partial<Record<Uuid, Element>> = {}
readonly map: Partial<Record<string, Element>> = {}
readonly typedMap: Partial<Record<ContentType, Element[]>> = {}
/** An array of uuids of items that are dirty */
dirtyIndex: Set<Uuid> = new Set()
dirtyIndex: Set<string> = new Set()
/** An array of uuids of items that are not marked as deleted */
nondeletedIndex: Set<Uuid> = new Set()
nondeletedIndex: Set<string> = new Set()
/** An array of uuids of items that are errorDecrypting or waitingForKey */
invalidsIndex: Set<Uuid> = new Set()
invalidsIndex: Set<string> = new Set()
readonly referenceMap: UuidMap
@@ -73,7 +73,7 @@ export abstract class Collection<
constructor(
copy = false,
mapCopy?: Partial<Record<Uuid, Element>>,
mapCopy?: Partial<Record<string, Element>>,
typedMapCopy?: Partial<Record<ContentType, Element[]>>,
referenceMapCopy?: UuidMap,
conflictMapCopy?: UuidMap,
@@ -89,7 +89,7 @@ export abstract class Collection<
}
}
public uuids(): Uuid[] {
public uuids(): string[] {
return Object.keys(this.map)
}
@@ -105,7 +105,7 @@ export abstract class Collection<
return this.typedMap[contentType]?.slice() || []
}
} else {
return Object.keys(this.map).map((uuid: Uuid) => {
return Object.keys(this.map).map((uuid: string) => {
return this.map[uuid]
}) as Element[]
}
@@ -129,7 +129,7 @@ export abstract class Collection<
return this.findAll(uuids)
}
public findAll(uuids: Uuid[]): Element[] {
public findAll(uuids: string[]): Element[] {
const results: Element[] = []
for (const id of uuids) {
@@ -142,11 +142,11 @@ export abstract class Collection<
return results
}
public find(uuid: Uuid): Element | undefined {
public find(uuid: string): Element | undefined {
return this.map[uuid]
}
public has(uuid: Uuid): boolean {
public has(uuid: string): boolean {
return this.find(uuid) != undefined
}
@@ -154,7 +154,7 @@ export abstract class Collection<
* If an item is not found, an `undefined` element
* will be inserted into the array.
*/
public findAllIncludingBlanks<E extends Element>(uuids: Uuid[]): (E | Deleted | undefined)[] {
public findAllIncludingBlanks<E extends Element>(uuids: string[]): (E | Deleted | undefined)[] {
const results: (E | Deleted | undefined)[] = []
for (const id of uuids) {
@@ -219,11 +219,11 @@ export abstract class Collection<
}
}
public uuidReferencesForUuid(uuid: Uuid): Uuid[] {
public uuidReferencesForUuid(uuid: string): string[] {
return this.referenceMap.getDirectRelationships(uuid)
}
public uuidsThatReferenceUuid(uuid: Uuid): Uuid[] {
public uuidsThatReferenceUuid(uuid: string): string[] {
return this.referenceMap.getInverseRelationships(uuid)
}
@@ -232,7 +232,7 @@ export abstract class Collection<
return this.findAll(uuids)
}
public conflictsOf(uuid: Uuid): Element[] {
public conflictsOf(uuid: string): Element[] {
const uuids = this.conflictMap.getDirectRelationships(uuid)
return this.findAll(uuids)
}

View File

@@ -1,7 +1,7 @@
import { Uuid, ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/common'
export interface SortableItem {
uuid: Uuid
uuid: string
content_type: ContentType
created_at: Date
userModifiedDate: Date

View File

@@ -1,6 +1,6 @@
import { ItemContent } from './../../../Abstract/Content/ItemContent'
import { EncryptedItemInterface } from './../../../Abstract/Item/Interfaces/EncryptedItem'
import { ContentType, Uuid } from '@standardnotes/common'
import { ContentType } from '@standardnotes/common'
import { SNIndex } from '../../Index/SNIndex'
import { isDecryptedItem } from '../../../Abstract/Item/Interfaces/TypeCheck'
import { DecryptedItemInterface } from '../../../Abstract/Item/Interfaces/DecryptedItem'
@@ -24,7 +24,7 @@ export class ItemCollection
this.discard(delta.discarded)
}
public findDecrypted<T extends DecryptedItemInterface = DecryptedItemInterface>(uuid: Uuid): T | undefined {
public findDecrypted<T extends DecryptedItemInterface = DecryptedItemInterface>(uuid: string): T | undefined {
const result = this.find(uuid)
if (!result) {
@@ -34,12 +34,12 @@ export class ItemCollection
return isDecryptedItem(result) ? (result as T) : undefined
}
public findAllDecrypted<T extends DecryptedItemInterface = DecryptedItemInterface>(uuids: Uuid[]): T[] {
public findAllDecrypted<T extends DecryptedItemInterface = DecryptedItemInterface>(uuids: string[]): T[] {
return this.findAll(uuids).filter(isDecryptedItem) as T[]
}
public findAllDecryptedWithBlanks<C extends ItemContent = ItemContent>(
uuids: Uuid[],
uuids: string[],
): (DecryptedItemInterface<C> | undefined)[] {
const results = this.findAllIncludingBlanks(uuids)
const mapped = results.map((i) => {

View File

@@ -1,5 +1,5 @@
import { removeFromArray } from '@standardnotes/utils'
import { ContentType, Uuid } from '@standardnotes/common'
import { ContentType } from '@standardnotes/common'
import { isTag, SNTag } from '../../../Syncable/Tag/Tag'
import { SNIndex } from '../../Index/SNIndex'
import { ItemCollection } from './ItemCollection'
@@ -7,12 +7,12 @@ import { ItemDelta } from '../../Index/ItemDelta'
import { isDecryptedItem, ItemInterface } from '../../../Abstract/Item'
type AllNotesUuidSignifier = undefined
export type TagItemCountChangeObserver = (tagUuid: Uuid | AllNotesUuidSignifier) => void
export type TagItemCountChangeObserver = (tagUuid: string | AllNotesUuidSignifier) => void
export class TagItemsIndex implements SNIndex {
private tagToItemsMap: Partial<Record<Uuid, Set<Uuid>>> = {}
private allCountableItems = new Set<Uuid>()
private countableItemsByType = new Map<ContentType, Set<Uuid>>()
private tagToItemsMap: Partial<Record<string, Set<string>>> = {}
private allCountableItems = new Set<string>()
private countableItemsByType = new Map<ContentType, Set<string>>()
constructor(private collection: ItemCollection, public observers: TagItemCountChangeObserver[] = []) {}
@@ -32,7 +32,7 @@ export class TagItemsIndex implements SNIndex {
}
}
private notifyObservers(tagUuid: Uuid | undefined) {
private notifyObservers(tagUuid: string | undefined) {
for (const observer of this.observers) {
observer(tagUuid)
}
@@ -119,7 +119,7 @@ export class TagItemsIndex implements SNIndex {
}
}
private setForTag(uuid: Uuid): Set<Uuid> {
private setForTag(uuid: string): Set<string> {
let set = this.tagToItemsMap[uuid]
if (!set) {
set = new Set()

View File

@@ -2,7 +2,7 @@ import { ImmutablePayloadCollection } from './../Collection/Payload/ImmutablePay
import { ConflictDelta } from './Conflict'
import { isErrorDecryptingPayload, isDecryptedPayload } from '../../Abstract/Payload/Interfaces/TypeCheck'
import { FullyFormedPayloadInterface, PayloadEmitSource } from '../../Abstract/Payload'
import { ContentType, Uuid } from '@standardnotes/common'
import { ContentType } from '@standardnotes/common'
import { HistoryMap } from '../History'
import { ServerSyncPushContextualPayload } from '../../Abstract/Contextual/ServerSyncPush'
import { payloadByFinalizingSyncState } from './Utilities/ApplyDirtyState'
@@ -18,7 +18,7 @@ export class DeltaRemoteRetrieved implements SyncDeltaInterface {
readonly historyMap: HistoryMap,
) {}
private isUuidOfPayloadCurrentlySavingOrSaved(uuid: Uuid): boolean {
private isUuidOfPayloadCurrentlySavingOrSaved(uuid: string): boolean {
return this.itemsSavedOrSaving.find((i) => i.uuid === uuid) != undefined
}

View File

@@ -1,10 +1,9 @@
import { Uuid } from '@standardnotes/common'
import { DecryptedItemInterface } from '../../Abstract/Item'
import { SortableItem } from '../Collection/CollectionSort'
import { ItemCollection } from '../Collection/Item/ItemCollection'
export type DisplayControllerCustomFilter = (element: DisplayItem) => boolean
export type UuidToSortedPositionMap = Record<Uuid, number>
export type UuidToSortedPositionMap = Record<string, number>
export type DisplayItem = SortableItem & DecryptedItemInterface
export interface ReadonlyItemCollection {

View File

@@ -1,7 +1,6 @@
import { Uuid } from '@standardnotes/common'
import { HistoryEntry } from './HistoryEntry'
export type HistoryMap = Record<Uuid, HistoryEntry[]>
export type HistoryMap = Record<string, HistoryEntry[]>
export const historyMapFunctions = {
getNewestRevision: (history: HistoryEntry[]): HistoryEntry | undefined => {