chore: fix ContentType usage (#2353)

* chore: fix ContentType usage

* chore: fix specs
This commit is contained in:
Karol Sójko
2023-07-12 13:53:29 +02:00
committed by GitHub
parent d057cdff84
commit 325737bfbd
247 changed files with 1092 additions and 1060 deletions

View File

@@ -7,7 +7,7 @@ import {
} from '@standardnotes/models'
import { PayloadManager } from './PayloadManager'
import { InternalEventBusInterface } from '@standardnotes/services'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
describe('payload manager', () => {
let payloadManager: PayloadManager
@@ -23,7 +23,7 @@ describe('payload manager', () => {
it('emitting a payload should emit as-is and not merge on top of existing payload', async () => {
const decrypted = new DecryptedPayload({
uuid: '123',
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: FillItemContent<ItemsKeyContent>({
itemsKey: 'secret',
}),
@@ -36,7 +36,7 @@ describe('payload manager', () => {
const nondirty = new DecryptedPayload({
uuid: '123',
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
...PayloadTimestampDefaults(),
updated_at_timestamp: 2,
content: FillItemContent<ItemsKeyContent>({

View File

@@ -1,4 +1,4 @@
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { PayloadsChangeObserver, QueueElement, PayloadsChangeObserverCallback, EmitQueue } from './Types'
import { removeFromArray, Uuids } from '@standardnotes/utils'
import {
@@ -74,7 +74,7 @@ export class PayloadManager extends AbstractService implements PayloadManagerInt
return this.collection.findAll([uuid])[0]
}
public all(contentType: ContentType): FullyFormedPayloadInterface[] {
public all(contentType: string): FullyFormedPayloadInterface[] {
return this.collection.all(contentType)
}
@@ -224,7 +224,7 @@ export class PayloadManager extends AbstractService implements PayloadManagerInt
* @param priority - The lower the priority, the earlier the function is called
* wrt to other observers
*/
public addObserver(types: ContentType | ContentType[], callback: PayloadsChangeObserverCallback, priority = 1) {
public addObserver(types: string | string[], callback: PayloadsChangeObserverCallback, priority = 1) {
if (!Array.isArray(types)) {
types = [types]
}
@@ -261,9 +261,9 @@ export class PayloadManager extends AbstractService implements PayloadManagerInt
const filter = <P extends FullyFormedPayloadInterface = FullyFormedPayloadInterface>(
payloads: P[],
types: ContentType[],
types: string[],
) => {
return types.includes(ContentType.Any)
return types.includes(ContentType.TYPES.Any)
? payloads.slice()
: payloads.slice().filter((payload) => {
return types.includes(payload.content_type)
@@ -304,7 +304,7 @@ export class PayloadManager extends AbstractService implements PayloadManagerInt
this.collection.discard(payload)
}
public erroredPayloadsForContentType(contentType: ContentType): EncryptedPayloadInterface[] {
public erroredPayloadsForContentType(contentType: string): EncryptedPayloadInterface[] {
return this.collection.invalidElements().filter((p) => p.content_type === contentType)
}

View File

@@ -1,4 +1,3 @@
import { ContentType } from '@standardnotes/common'
import {
DecryptedPayloadInterface,
DeletedPayloadInterface,
@@ -34,7 +33,7 @@ export type PayloadManagerChangeData = {
export type PayloadsChangeObserverCallback = (data: PayloadManagerChangeData) => void
export type PayloadsChangeObserver = {
types: ContentType[]
types: string[]
callback: PayloadsChangeObserverCallback
priority: number
}